Replies: 14 comments 1 reply
-
Does the call to CreateDispatcherQueueController actually work? The documentation for DispatcherQueueOptions states that you shouldn't do what you are doing. "This field is relevant only if threadType is DQTYPE_THREAD_DEDICATED. Use DQTAT_COM_NONE when DispatcherQueueOptions.threadType is DQTYPE_THREAD_CURRENT." |
Beta Was this translation helpful? Give feedback.
-
@DarranRowe I found this code in winui3 gallery. Using any other value results the same |
Beta Was this translation helpful? Give feedback.
-
Then there are three things that I can think of.
They are listed in the order that I think is most likely. For the first two, think of Xaml Islands. Also, remember that system Xaml isn't related to WinUI 3 Xaml, so WinUI 3 wouldn't initialise the Xaml under the Windows root namespace. --Edit-- |
Beta Was this translation helpful? Give feedback.
-
How did you get |
Beta Was this translation helpful? Give feedback.
-
Right, when the project is set up for a Windows Store type project, like WinUI 3 projects are, C++/WinRT doesn't generate the entire set of contracts. The use of
This is because Visual Studio is hard coded to only look in Program Files (x86). So as an example, I actually have the Windows SDK installed on a separate drive, along with Visual Studio and some other applications. So I have to add this directory to the paths that Visual Studio will look for. But as I mentioned, this is only needed if the Windows SDK is not installed in the default location. |
Beta Was this translation helpful? Give feedback.
-
This feels like an XY problem. Why are you trying to use WUX.Media.LoadedImageSurface in a WinUI 3 project? |
Beta Was this translation helpful? Give feedback.
-
It's because the system backdrops truely do use WU.Composition.CompositionBrush.
This is the IDL generated from the 1.5 metadata for ICompositionSupportsSystemBackdrop as one example. WUX.Media.LoadedImageSurface probably just gave the easiest way of loading an image into a composition brush. |
Beta Was this translation helpful? Give feedback.
-
Are there non-XAML ways to get an image into a composition brush then? |
Beta Was this translation helpful? Give feedback.
-
@DarranRowe Your method is unreasonably complicated. WASDK team better enable use of |
Beta Was this translation helpful? Give feedback.
-
My method isn't unreasonably complicated, it was only telling you how to use the runtime class that you wanted to use. That response also served to indicate that this wasn't a Windows App SDK issue since the System Xaml is where your problem was, and initialising System Xaml using the hosting API resolved your initial problem completely. If you want to use runtime classes under Windows.UI.Xaml without using the hosting interfaces to initialise it, then you really should submit a feature request for Microsoft.UI.Xaml.Application.Start to initialise Windows.UI.Xaml too. |
Beta Was this translation helpful? Give feedback.
-
@DarranRowe Don't get me wrong, I really appreciate your solution. As it happens many times before, I just want them to either: document the usage with winui3 clearly so nobody gets wasting their time (since |
Beta Was this translation helpful? Give feedback.
-
As I stated though, Windows.UI.Composition is fully usable regardless. In this case, it is a System Xaml helper which is the issue. The biggest thing I always assume when working with System Xaml is that anything under Windows.UI.Xaml is unusable until either Windows.UI.Xaml.Application.Start has been called, or Windows.UI.Xaml.Hosting.WindowsXamlManager.InitializeForCurrentThread has been called. The only surprising thing I know of is that Windows.UI.Color.ColorHelper.ToDisplayName calls into Windows.UI.Xaml.dll.
Once you have the CompositionGraphicsDevice, then you can use one of the surface creation members to create a surface. Once you have the surface, you can then use ICompositionSurfaceInterop to control the drawing.
Once you have finished drawing to the surface, then you must call EndDraw.
There is some quirkiness here, but it is easy to explain the behaviour when you understand that the desktop targetted version of Windows.UI.Composition uses the underlying DirectComposition. Anyway, the things to note using this. If you pass in a ID3D11Device, then you can only get a IDXGISurface/ID3D11Texture2D from BeginDraw. If you pass in a ID2D1Device, it does the equivalent of ID2D1Device::CreateDeviceContext, ID2D1DeviceContext::CreateBitmapFromDxgiSurface, sets the newly created bitmap as the target for the ID2D1DeviceContext using ID2D1DeviceContext::SetTarget and then returns the ID2D1DeviceContext. Using System Xaml does allow for some shortcuts, because it needs to use Direct2D and Windows.UI.Composition to draw. So it has its own compositor and Direct2D device. However, if you use Direct2D and your own compositor instance, then you don't need to initialise System Xaml and thus you don't have to edit the .vcxproj file manually. This is why I personally consider this outside of the scope of the Windows App SDK, since it uses the inbuilt system functionality, and you can do what you want without editing anything. It is just the shortcut under the Windows.UI.Xaml namespace that doesn't work unless System Xaml is initialised. |
Beta Was this translation helpful? Give feedback.
-
@DarranRowe I got
when I do auto m_manager = winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread(); Additional context: |
Beta Was this translation helpful? Give feedback.
-
In regards to the additional context. 2024-06-20.11-59-47.mp42024-06-20.12-02-06.mp4As I have previously stated in this thread, I do not use the default installation locations for the Windows SDK and Visual Studio, and Visual Studio hard codes the Extension SDK path. That is why I have to override the SDKExtensionDirectoryRoot property if I want to use any of this. You can see this for yourself in the Microsoft.Cpp.AppContainerApplication.props file in that is part of MSBuild/Visual Studio.
Anyway, for that error, that is doubly curious and problematic. It also pushes the goal post further. I'm going to have to work out what I missed with my test. However, at the very least it means that it is going to require an application (something derived from Windows.UI.Xaml.Application) active on the thread. Because this also means that there are multiple frameworks active, then it also means that System Xaml really should go onto a separate thread. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
I wanted to use an image as a
Windows.UI.Composition.ICompositionSurface
as an input to some win2d effect, and output aWindows.UI.Composition.CompositionBrush
used inMicorsoft.UI.Xaml.Window
'sSystemBackdrop
brush.But I got exceptions in using
Windows.UI.Xaml.Media.LoadedImageSurface.StartLoadFromUri
, even after I created aDispatcherQueueController
on the winui3's ui thread.Steps to reproduce the bug
DispatcherQueueController
in the ui threadExpected behavior
No response
Screenshots
No response
NuGet package version
Windows App SDK 1.5.3: 1.5.240428000
Packaging type
Packaged (MSIX)
Windows version
Windows 11 version 22H2 (22621, 2022 Update)
IDE
Visual Studio 2022
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions