microsoft / angle

ANGLE: OpenGL ES to DirectX translation
Other
615 stars 166 forks source link

XAML SwapChainPanel does not resize properly #168

Closed AntonPetrov83 closed 4 years ago

AntonPetrov83 commented 4 years ago

Comparing default template projects for CoreWindow and XAML it is obvious that XAML implementation does not apply Display settings Scale properly. For my Surface Pro device when Scale 200% is specified XAML example looks pixelated.

This is because ANGLE SwapChainPanelNativeWindow implementation uses UIElement.RenderSize to get panel size which is not raw pixels but scaled units:

HRESULT GetSwapChainPanelSize(
    const ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> &swapChainPanel,
    const ComPtr<ICoreDispatcher> &dispatcher,
    Size *windowSize)
{
    ComPtr<IUIElement> uiElement;
    HRESULT result = swapChainPanel.As(&uiElement);
    if (SUCCEEDED(result))
    {
        result = RunOnUIThread(
            [uiElement, windowSize] { return uiElement->get_RenderSize(windowSize); }, dispatcher);
    }

    return result;
}

But CoreWindowNativeWindow implementation converts window size to physical pixels:

HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWindow> &coreWindow,
                                  Size *windowSize)
{
    ABI::Windows::Foundation::Rect bounds;
    HRESULT result = coreWindow->get_Bounds(&bounds);
    if (SUCCEEDED(result))
    {
        *windowSize = {ConvertDipsToPixels(bounds.Width), ConvertDipsToPixels(bounds.Height)};
    }

    return result;
}

Hence is the difference in behaviour.

Sorry, I have no capacity to pull-request and test it properly.

austinkinross commented 4 years ago

Hi there, thanks for reporting this. All UWP-related changes in this repository have been merged upstream, so this repo has generally been deprecated. I suggest using the master ANGLE repo going forward. Please see this page for more details: https://github.com/microsoft/angle

You may want to look into using an IPropertySet to set the swapchain size manually. See from this line onwards for details: https://github.com/google/angle/blob/e33c1582b4bc6da24c08f14aa2b74d1677c974dd/src/libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.cpp#L98

If you have further questions then I suggest emailing the master ANGLE project mailing list, or filing an bug on http://anglebug.com

Thanks again Austin