microsoft / Win2D

Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. It is available to C#, C++ and VB developers writing apps for the Windows Universal Platform (UWP). It utilizes the power of Direct2D, and integrates seamlessly with XAML and CoreWindow.
http://microsoft.github.io/Win2D
Other
1.82k stars 288 forks source link

Question on WinUI 3 Roadmap #858

Open chuckries opened 3 years ago

chuckries commented 3 years ago

I took a stab at getting CanvasAnimatedControl off the ground for WinUI 3. I was able to get it running, my branch is here and I am happy to clean it up and contribute it if there is interest.

The work left me with a primary question: Is there an expectation for Microsoft.Graphics.Win2D to support UWP in the future? Or should UWP always use Win2D.uwp?

This question focuses on the use of win32 API's within Win2D and the packaging expectation. The primary issues with CanvasAnimatedControl in WinUI is the lack of CoreDisptacher. WinUI has DisptacherQueue, but this requires a "bring your own message loop" solution currently. I was able to make this work by using a very simple win32 GetMessage/DispatchMessage loop, but these API's aren't available in UWP (at least through winuser.h, maybe I'm missing something). These API's can be used in MSIX packaged apps (like WinUI 3 Desktop Apps), but my understanding is that WinUI 3 will also be supported in UWP, in which case these API's are not available. I also don't know if WinUI 3 plans to offer a message loop solution over the top of DispatcherQueue, my understanding is that DispatcherQueue can at least interop with an existing win32 message loop (which CoreDispatcher can't).

Any thoughts? I'm just trying to understand the UWP vs WinUI space, and if MS.Graphics.Win2D is hoping to support WinUI within the scope of UWP or will only be WinUI Desktop.

I found it very interesting working on this and was really excited to get it working, I'd love to contribute something but I'm just not sure what the "right" thing is regarding an "abstract message loop runner" is for WinUI.

Thanks!

duncanmacmichael commented 3 years ago

Hi @chuckries,

First of all, this is awesome! We love your enthusiasm here and really appreciate your work here and thoughtful discussion.

  1. I honestly can't speak to future UWP support, sorry, but I'll reach out to someone on the WinAppSDK team to see what we can find out here.
  2. For your main questions about UWP vs WinUI and the whole message loop question in your main paragraph, we need to talk to the WinUI folks about this because it's a great question and I don't want to mis-represent their view about CoreDispatcher and their plans.

So, for the moment, I don't have any direct answers but again, thanks for your work here! I'm going to see who is the best person from those teams to ask about this and we'll get back to you. :)

juan- commented 2 years ago

@chuckries - We're ready to start working on this, if you are willing to contribute we would be thrilled. if not, we will continue to build on your contributions To answer your previous question, moving forward, the WinAppSDK Win2D branch will never be merged into the UWP Win2D codebase.

chuckries commented 2 years ago

@juan- unfortunately I don't have time to fix up my branch to actually submit as a PR, but you are more the welcome to use that branch as a start. It has the bulk of the changes needed to get CanvasAnimatedControl off of ICoreDispatcher and onto IDispatcherQueue. In addition, the message loop that runs on the game loop thread likely needs to be much more robust. I was hoping the WinAppSDK would provide some sort of default message loops for IDispatcherQueue (similar to CoreDispatcher), but I haven't looked at this in some time. My understanding of IDispatcherQueue was that it would work with both CoreDispatcher based apps and win32 message loop based apps, but I'm not really sure. IDispatcherQueue appears to just provide the queue, and you have to bring your own message loop to process the queue. The exact behavior of the existing ICoreDispatcher::ProcessEvents and what is required to mimic it with a win32 message loop is a little out of my depth.

The win32 message loop I used seems to be fine for win32 apps, but I wasn't sure if it was the right thing for all application types that the WinAppSDK version of Win2D would be pulled into. The distinctions in windows land are confusing to me.

If I can help in any way I'm happy to do so and I will enjoy following CanvasAnimatedControl coming up in WinAppSDK Win2D.