-
Notifications
You must be signed in to change notification settings - Fork 290
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
Expose WindowId-based WinRT API to create CanvasSwapChain-s for HWNDs #924
Comments
Notes from API review
public sealed class CanvasSwapChain
{
public static CanvasSwapChain CreateForWindowId(
WindowId windowId,
uint width,
uint height,
float dpi);
public static CanvasSwapChain CreateForWindowId(
WindowId windowId,
uint width,
uint height,
float dpi,
DirectXPixelFormat format,
int bufferCount);
}
|
Closing as completed. Implemented in the internal repo, will be available in the next preview for WinAppSDK (for now). |
getrou
pushed a commit
that referenced
this issue
Aug 13, 2024
### Closes #924 ### Overview This PR introduces the following new APIs for `CanvasSwapChain`: ```cpp [overload("CreateForWindowId")] HRESULT CreateForWindowIdWithDpi( [in] ICanvasResourceCreator* resourceCreator, [in] Microsoft.UI.WindowId windowId, [in] float width, [in] float height, [in] float dpi, [out, retval] CanvasSwapChain** swapChain); [overload("CreateForWindowId")] HRESULT CreateForWindowIdWithAllOptions( [in] ICanvasResourceCreator* resourceCreator, [in] Microsoft.UI.WindowId windowId, [in] float width, [in] float height, [in] float dpi, [in] DIRECTX_PIXEL_FORMAT format, [in] INT32 bufferCount, [out, retval] CanvasSwapChain** swapChain); ``` > **NOTE:** we can add a simpler overload with no size/DPI in a follow up.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the new
HWND
interop API, it is now much easier to create aCanvasSwapChain
object from a givenHWND
owned by a developer. Specifically for C# developers, however, using this API means that there's still a good amount of extra work needed to perform the actual interop operations to access the API. The previously approved API included an additional extension method in the .NET projection assembly to expose theHWND
API in a more convenient way. But we can do better 🙂There is a new WinRT type,
WindowId
, which is basically a thin wrapper forHWND
. On WinAppSDK, there are built-in APIs to easily convert to-fromHWND
-s, and most importantly, APIs likeAppWindow
directly expose aWindowId
property. If we added built-in support for this in Win2D, we'd basically allow developers to create a new window + swapchain with 0 interop needed 🎉API proposal
The shape mostly follows that already approved from the previous proposal, but adapted to use
WindowId
.I've only included a new overload with also the explicit DPI value, but not the format or the buffer count.
Example use
This is all that will be needed to get an
HWND
swapchain running in a blank WinAppSDK app:Additional notes
At least for now, these new APIs would only be for WinAppSDK, not UWP. The reason being that on WinAppSDK,
AppWindow
returns aWindowId
value which can be used by Win2D to create anHWND
swapchain directly (as there's documented helpers to get anHWND
from aWindowId
value). This is not the case on UWP (plus the UWPAppWindow
is not just a thinHWND
wrapper like on WinAppSDK). So until we find a way to expose this as nicely on UWP as well, we can keep these APIs just on the other branch.To make these available on UWP, we'd need:
HWND
<->WindowId
(this would at least allow devs to use their ownHWND
s)WindowId
value from UWP'sAppWindow
type, and direct DirectX content being allowed for such windows. Currently, the docs specifically say thatAppWindow
can only host XAML content (on UWP).UPDATE: UWP now also has a documented way to convert
HWND
<->WindowId
, inWindows.UI.Interop.h
🎉The text was updated successfully, but these errors were encountered: