Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using Win2D with WinUI #707

Open
jtorjo opened this issue Jun 22, 2019 · 28 comments
Open

Support using Win2D with WinUI #707

jtorjo opened this issue Jun 22, 2019 · 28 comments

Comments

@jtorjo
Copy link

jtorjo commented Jun 22, 2019

In light of WinUI roadmap, the Windows.UI.Composition will become independent of UWP.

Would this mean we could actually uncouple win2d from UWP? Assuming we could use c++/WinRT from a non-UWP app, could the library be made useable from UWP/WPF alike?

Quote from microsoft/microsoft-ui-xaml#888
We know that using WinUI in desktop apps is the most interesting scenario for lots of Windows app developers. The goal is to enable using Xaml markup + WinRT APIs (via .NET or C++) as the UI for a win32/desktop app (instead of a UWP app), without needing to use Xaml Islands.

@Gavin-Williams
Copy link

This will have to happen, because although UWP will continue, UWP.UI will be deprecated and we will be using WinUI.

@jtorjo
Copy link
Author

jtorjo commented Nov 8, 2019

@Gavin-Williams I truly hope so, because UWP is giving me nightmares

@jasonwurzel
Copy link

Any news on this? We are in the process of deciding the roadmap for our application and this is a crucial point: Will we be able to use Win2D in a WinUI 3 project? What would be the necessary changes to make in Win2D (I guess only replacing some namespaces would not be sufficient).

@jtorjo
Copy link
Author

jtorjo commented Nov 24, 2019

@jasonwurzel I certainly can't speak on MS's name - I only speak for myself, I've been following WinUI3 talks, and asked a few questions.
Having said that, it may happen, but my take is - don't expect this to happen before mid summer next year.

I'm not putting that much hope into it, because UWP and WPF are sooo different (for one WPF - on top of Directx9, UWP on top of Directx11). I'm not sure they'll redo WPF on Directx11 (even though that would be incredibly cool), so using win2d from WPF might end up being too much work.

Assuming you have a WPF app, and you really really need win2d (such as in my case), you're likely choice is to port it to UWP. In that case, do expect a really bumpy ride.

@jasonwurzel
Copy link

Oh, we're already on the bumpy ride :-/ I should have clarified the status quo in my first post: We have a UWP app, to be more precise, we have a WPF Core app that hosts one XamlIsland that hosts our UWP app. Did I mention "bumpy ride" yet? ;-)
Anyway, as WinUI 3 points to the future (in .Net 5 direction) I expect Win2D to be available for sure, the question is just, when (I concur with you on your assesment of summer next year) and what has to be done in Win2D to make it available in WinUI 3 (just out interest, and of course one could help).

@jtorjo
Copy link
Author

jtorjo commented Nov 24, 2019

Oh wow - good luck!
So you basically need to publish your app in the MS store, and then somehow use it from WPF?
Good times...

About using win2d from a WinUI 3 project - i'm really curious how they will reconcile the pathetic StorageFile/Folder API they must be using in UWP, with WPF. We'll have to wait and see :)

@rucoder
Copy link

rucoder commented Dec 11, 2019

Here is community talk on WinUI 3.0. https://onedrive.live.com/?authkey=%21ADasoGSDRbpnShA&cid=9C95F4380C440E2C&id=9C95F4380C440E2C%2132156&parId=9C95F4380C440E2C%2132155&o=OneUp

At around 19:00 they discuss a question "Can you use Win2D with WinUI 3.0?" and the answer was "Sure, you just need to recompile Win2D against WinUI 3.0" I personally have the same problem: I need to decide which technology to use for our new Windows application and I also need a performance and features of DirectX. This would be the perfect choice: WinUI 3.0 + Win2D

So My question to Win2D team: is there any plan to release a separate NuGet package compiled against WinUI 3.0 ?

@shawnhar shawnhar changed the title future of win2d? Support using Win2D with WinUI Dec 12, 2019
@rucoder
Copy link

rucoder commented May 19, 2020

It seems initial version of toolkit for WinUI 3.0 exists now
CommunityToolkit/WindowsCommunityToolkit#3146

@lhak
Copy link

lhak commented May 24, 2020

I have managed to compile win2d for winui (see https://github.com/lhak/Win2D/tree/winui3). Most of the changes are rather trivial but there are also some hacks:

  • The winui header and idl files were manually created from the winui .winmd file and copied to the project. I had to edit them later to remove code that caused compilation to fail (e.g. experimental flags and some double definitions). This generation needs to somehow happen automatically (and correctly) or the files should be supplied directly by the winui team in the winui package. Unfortunately, I do not really have any experience in this field.
  • Composition support is disabled because some of the required classes do not seem to be currently present in winui
  • Some code in CanvasAnimatedControl is also disabled because the swapchain class lacks a certain method
  • CanvasBitmap derives from DependencyObject in the current codebase. I had to remove this because when it derives from the winui version there is a crash in the cswinrt code when a CanvasBitmap object is created.
  • I added some code from the cswinrt website to generate projections for c# desktop apps in the bin\cswinrt folder

So far the included SimpleSample app seems to work. I have also successfully tested CanvasControl and CanvasSwapChain in a c# desktop app by adding the projection files to project and copying the win2d dll to the output folder.

@michael-hawker
Copy link

@rucoder thanks for linking to the Toolkit. We have preview bits available that work on Preview 1 here. However, they don't support anything that uses Win2D yet as Win2D doesn't yet support WinUI. We've been talking to the Win2D team about this.

@lhak that's a great investigation! 🎉🎉🎉 Thanks for driving the discussion by taking such a detailed look at the problems!

@lhak
Copy link

lhak commented Jul 16, 2020

I have updated the code to work with preview 2. The generated nuget package now also includes the projection for c# desktop projects. The other issues listed above still remain unchanged.

@jtorjo
Copy link
Author

jtorjo commented Jul 16, 2020

@lhak Are you saying that win2d would work on c# desktop?

Wholy macarony, that would be insaaaaaaaaaaaaaaaaneeeeeeeeeeeee

@lhak
Copy link

lhak commented Jul 17, 2020

@jtorjo win2d is definitely usable in XAML islands today and has been for quite some time. This is just an (incomplete) port to winui 3 (win32 and UWP).

@jtorjo
Copy link
Author

jtorjo commented Jul 17, 2020

@lhak Using it from XAML islands is useless to me. I have insanely complicated code, and testing is very very complicated from within UWP as is, so using it from XAML islands is a complete NONO for me.

So long story short, i need this to work natively.

@jschroedl
Copy link

Not sure what to add other than +1 for updating Win2D to work with WinUI for Desktop (Win32) apps. This would be monumentally-useful for our application.

@jtorjo
Copy link
Author

jtorjo commented Sep 25, 2020

@shawnhar What is the roadmap for this? I really really need this - and I'm sure I'm far from the only one.

Also, I would assume when we'll be able to use win2d with WinUI, automatically we'll also be able to use it on Desktop.

@shawnhar
Copy link
Member

We're working on this, but don't have an ETA yet.

@jtorjo
Copy link
Author

jtorjo commented Sep 25, 2020

@shawnhar Thanks! Even if you don't have an ETA, do you think it would be ready within a 6-9 months timeframe?

@shawnhar
Copy link
Member

Please don't take this as a solid commitment, but I would expect it to be ready in that timeframe.

@jtorjo
Copy link
Author

jtorjo commented Sep 25, 2020

@shawnhar Thanks! Looking really really forward to it!

@Gavin-Williams
Copy link

@lhak "I have managed to compile win2d for winui" - that is really awesome!

@wjk
Copy link
Contributor

wjk commented Dec 8, 2020

Just to throw my hat in: Building on @lhak's wonderful work, I have created an unofficial NuGet package containing a WinUI 3-compatible build of Win2D. It’s named Sunburst.Win2D.WinUI. The source code’s here. I have tested it with the default WinUI 3 app template, and it draws exactly as expected. Enjoy!

@watsonwelch
Copy link

I know that CanvasAnimatedControl is currently unsupported in the official Win2D for Project Reunion/WinUI 3, but is there any guidance as to whether it's planned to be supported in the future?

I know that @lhak you mentioned the following in your earlier port:

  • Some code in CanvasAnimatedControl is also disabled because the swapchain class lacks a certain method

Any chance you can clarify what the missing method was, and whether you think Project Reunion will resolve this in the future?

@jtorjo
Copy link
Author

jtorjo commented Jul 2, 2021

@getrou As per latest WinUI community call, UWP support is pretty much dropped. I can't say I'm surprised.

However, I, and I'm sure I'm not alone - would really love to know if there's an ETA for when we could use win2d in WinUI3 Desktop -- basically without support for win2d, I can't port my app.

Can we hope for an ETA? 😎

@wjk
Copy link
Contributor

wjk commented Jul 2, 2021

Can we hope for an ETA?

I believe we’ve already passed it. Look here.

@jtorjo
Copy link
Author

jtorjo commented Jul 2, 2021

@wjk Thanks. I have to check it out.

Do you know what's supported and what not?

Because the docs (which are probably outdated) state that a LOT of the important classes (such as, CanvasBitmap, CanvasAnimatedControl etc) are not there yet.

@wjk
Copy link
Contributor

wjk commented Jul 2, 2021

Do you know what's supported and what not?

No clue, I’m afraid. I just know it exists. 😦

@jtorjo
Copy link
Author

jtorjo commented Jul 2, 2021

No clue, I’m afraid. I just know it exists. 😦

Hehe, I was aware of it for a while, but I just know it's incomplete. I'll have to test it out at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants