-
Notifications
You must be signed in to change notification settings - Fork 675
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
SwapChainPanel scales SwapChain content by DPI scale #8219
Comments
This is currently as designed. The thing is, when you tell a swap chain that you want 512x512 pixels, those are logical pixels, so when the swap chain is displayed on the screen, it is actually 768x768 physical pixels. But when you set window size, that is in physical pixels so if you set the window size to 532x586 (512x512 plus chrome - check out ResizeClient so you don't worry about this part), you are only getting a client area of 512x512 physical pixels which will truncate some of the768x768. So, you need to make sure that both the window and the swapchain are using the same number of pixels. You can do that by changing you window sizing call to account for the needed extra space OR you can (as done in the sample) scale the swapchain size to match the physical pixel size of the window. The latter provides a much better visual experience (since images are not being scaled), but the former is more honoring what the user has requested. It is up to the application to decide which approach is more appropriate. Note: There can be some discussion around whether these two api should be using different coordinate scales, but that would be a different discussion as one is part of the OS and the other is part of a UI framework. |
Hi @abenedik, as @JJBrychell noted the behavior is by design. The following MSDN Remark currently addresses this: In order to maintain crisp vector rendering, you should listen for the CompositionScaleChanged event and query the CompositionScaleX and CompositionScaleY property values to account for the current UI scale, and potentially render again from DirectX. Otherwise XAML layout might do the scaling and your visuals might be degraded. |
Describe the bug
When using SwapChainPanel with ISwapChainPanelNative then the SwapChain is scaled by the window's dpi scale even though the size of SwapChain perfectly matches the pixel size of the SwapChainPanel.
Steps to reproduce the bug
See the following sample (in c#): SwapChainPanelScaleProblem.zip
Steps:
Workaround:
Set Scale (or RenderTransform with ScaleTransform) on SwapChainPanel to 1 / dpiScale. Also set the Width and Height of the SwapChainPanel to the size of the texture (note: Width and Height are in device independent units, but because we scaled down the content, we need to scale up the size otherwise the SwapChainPanel would crop the SwapChain).
Expected behavior
Because the size of SwapChain is the same as the pixel size of the SwapChainPanel, the whole content of the SwapChain should be shown. Instead the SwapChain is scaled by dpi scale so the bottom right part is not visible - see screenshots below:
Screenshots
Screenshots from the attached application (there is button to apply the scale workaround in the middle of the screenshot)
Expected result or result when using no DPI scaling:
Using 125% scaling:
NuGet package version
WinUI 3 - Windows App SDK 1.2.3: 1.2.230118.102
Windows version
Windows 10 (21H2): Build 19044
Additional context
No response
The text was updated successfully, but these errors were encountered: