Commit 027cda63 by Nickolay Artamonov Committed by Commit Bot

Fix rounding problem for SwapChainPanel size.

BUG=angleproject:1421 Change-Id: I08f0fa5f178c8d25cd2b02e75cf92759254aa918 Reviewed-on: https://chromium-review.googlesource.com/355020Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent afcec834
# This is the official list of The ANGLE Project Authors # This is the official list of The ANGLE Project Authors
# for copyright purposes. # for copyright purposes.
# This file is distinct from the CONTRIBUTORS files. # This file is distinct from the CONTRIBUTORS files.
# See the latter for an explanation. # See the latter for an explanation.
...@@ -45,3 +45,4 @@ Maks Naumov ...@@ -45,3 +45,4 @@ Maks Naumov
Jinyoung Hur Jinyoung Hur
Sebastian Bergstein Sebastian Bergstein
James Ross-Gowan James Ross-Gowan
Nickolay Artamonov
...@@ -88,12 +88,12 @@ bool CoreWindowNativeWindow::initialize(EGLNativeWindowType window, IPropertySet ...@@ -88,12 +88,12 @@ bool CoreWindowNativeWindow::initialize(EGLNativeWindowType window, IPropertySet
} }
else else
{ {
SIZE coreWindowSize; Size coreWindowSize;
result = GetCoreWindowSizeInPixels(mCoreWindow, &coreWindowSize); result = GetCoreWindowSizeInPixels(mCoreWindow, &coreWindowSize);
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
mClientRect = { 0, 0, static_cast<long>(coreWindowSize.cx * mSwapChainScale), static_cast<long>(coreWindowSize.cy * mSwapChainScale) }; mClientRect = clientRect(coreWindowSize);
} }
} }
} }
...@@ -194,14 +194,16 @@ HRESULT CoreWindowNativeWindow::createSwapChain(ID3D11Device *device, ...@@ -194,14 +194,16 @@ HRESULT CoreWindowNativeWindow::createSwapChain(ID3D11Device *device,
return result; return result;
} }
inline HRESULT CoreWindowNativeWindow::scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) inline HRESULT CoreWindowNativeWindow::scaleSwapChain(const Size &windowSize,
const RECT &clientRect)
{ {
// We don't need to do any additional work to scale CoreWindow swapchains. // We don't need to do any additional work to scale CoreWindow swapchains.
// Using DXGI_SCALING_STRETCH to create the swapchain above does all the necessary work. // Using DXGI_SCALING_STRETCH to create the swapchain above does all the necessary work.
return S_OK; return S_OK;
} }
HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWindow>& coreWindow, SIZE *windowSize) HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWindow> &coreWindow,
Size *windowSize)
{ {
ABI::Windows::Foundation::Rect bounds; ABI::Windows::Foundation::Rect bounds;
HRESULT result = coreWindow->get_Bounds(&bounds); HRESULT result = coreWindow->get_Bounds(&bounds);
...@@ -230,9 +232,9 @@ static float GetLogicalDpi() ...@@ -230,9 +232,9 @@ static float GetLogicalDpi()
return 96.0f; return 96.0f;
} }
long ConvertDipsToPixels(float dips) float ConvertDipsToPixels(float dips)
{ {
static const float dipsPerInch = 96.0f; static const float dipsPerInch = 96.0f;
return lround((dips * GetLogicalDpi() / dipsPerInch)); return dips * GetLogicalDpi() / dipsPerInch;
} }
} }
...@@ -19,7 +19,7 @@ typedef ABI::Windows::Foundation::__FITypedEventHandler_2_Windows__CUI__CCore__C ...@@ -19,7 +19,7 @@ typedef ABI::Windows::Foundation::__FITypedEventHandler_2_Windows__CUI__CCore__C
namespace rx namespace rx
{ {
long ConvertDipsToPixels(float dips); float ConvertDipsToPixels(float dips);
class CoreWindowNativeWindow : public InspectableNativeWindow, public std::enable_shared_from_this<CoreWindowNativeWindow> class CoreWindowNativeWindow : public InspectableNativeWindow, public std::enable_shared_from_this<CoreWindowNativeWindow>
{ {
...@@ -36,7 +36,7 @@ class CoreWindowNativeWindow : public InspectableNativeWindow, public std::enabl ...@@ -36,7 +36,7 @@ class CoreWindowNativeWindow : public InspectableNativeWindow, public std::enabl
IDXGISwapChain1 **swapChain) override; IDXGISwapChain1 **swapChain) override;
protected: protected:
HRESULT scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) override; HRESULT scaleSwapChain(const Size &windowSize, const RECT &clientRect) override;
bool registerForSizeChangeEvents(); bool registerForSizeChangeEvents();
void unregisterForSizeChangeEvents(); void unregisterForSizeChangeEvents();
...@@ -72,7 +72,8 @@ class CoreWindowSizeChangedHandler : ...@@ -72,7 +72,8 @@ class CoreWindowSizeChangedHandler :
ABI::Windows::Foundation::Size windowSize; ABI::Windows::Foundation::Size windowSize;
if (SUCCEEDED(sizeChangedEventArgs->get_Size(&windowSize))) if (SUCCEEDED(sizeChangedEventArgs->get_Size(&windowSize)))
{ {
SIZE windowSizeInPixels = { ConvertDipsToPixels(windowSize.Width), ConvertDipsToPixels(windowSize.Height) }; Size windowSizeInPixels = {ConvertDipsToPixels(windowSize.Width),
ConvertDipsToPixels(windowSize.Height)};
host->setNewClientSize(windowSizeInPixels); host->setNewClientSize(windowSizeInPixels);
} }
} }
...@@ -84,7 +85,8 @@ class CoreWindowSizeChangedHandler : ...@@ -84,7 +85,8 @@ class CoreWindowSizeChangedHandler :
std::weak_ptr<InspectableNativeWindow> mHost; std::weak_ptr<InspectableNativeWindow> mHost;
}; };
HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWindow>& coreWindow, SIZE *windowSize); HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWindow> &coreWindow,
Size *windowSize);
} }
#endif // LIBANGLE_RENDERER_D3D_D3D11_WINRT_COREWINDOWNATIVEWINDOW_H_ #endif // LIBANGLE_RENDERER_D3D_D3D11_WINRT_COREWINDOWNATIVEWINDOW_H_
...@@ -267,4 +267,10 @@ HRESULT GetOptionalSinglePropertyValue(const ComPtr<ABI::Windows::Foundation::Co ...@@ -267,4 +267,10 @@ HRESULT GetOptionalSinglePropertyValue(const ComPtr<ABI::Windows::Foundation::Co
return result; return result;
} }
RECT InspectableNativeWindow::clientRect(const Size &size)
{
// We don't have to check if a swapchain scale was specified here; the default value is 1.0f
// which will have no effect.
return {0, 0, lround(size.Width * mSwapChainScale), lround(size.Height * mSwapChainScale)};
}
} }
...@@ -68,7 +68,7 @@ class InspectableNativeWindow ...@@ -68,7 +68,7 @@ class InspectableNativeWindow
} }
// setNewClientSize is used by the WinRT size change handler. It isn't used by the rest of ANGLE. // setNewClientSize is used by the WinRT size change handler. It isn't used by the rest of ANGLE.
void setNewClientSize(const SIZE &newWindowSize) void setNewClientSize(const Size &newWindowSize)
{ {
// If the client doesn't support swapchain resizing then we should have already unregistered from size change handler // If the client doesn't support swapchain resizing then we should have already unregistered from size change handler
ASSERT(mSupportsSwapChainResize); ASSERT(mSupportsSwapChainResize);
...@@ -78,8 +78,7 @@ class InspectableNativeWindow ...@@ -78,8 +78,7 @@ class InspectableNativeWindow
// If the swapchain size was specified then we should ignore this call too // If the swapchain size was specified then we should ignore this call too
if (!mSwapChainSizeSpecified) if (!mSwapChainSizeSpecified)
{ {
// We don't have to check if a swapchain scale was specified here; the default value is 1.0f which will have no effect. mNewClientRect = clientRect(newWindowSize);
mNewClientRect = { 0, 0, static_cast<long>(newWindowSize.cx * mSwapChainScale), static_cast<long>(newWindowSize.cy * mSwapChainScale) };
mClientRectChanged = true; mClientRectChanged = true;
// If a scale was specified, then now is the time to apply the scale matrix for the new swapchain size and window size // If a scale was specified, then now is the time to apply the scale matrix for the new swapchain size and window size
...@@ -99,7 +98,8 @@ class InspectableNativeWindow ...@@ -99,7 +98,8 @@ class InspectableNativeWindow
} }
protected: protected:
virtual HRESULT scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) = 0; virtual HRESULT scaleSwapChain(const Size &windowSize, const RECT &clientRect) = 0;
RECT clientRect(const Size &size);
bool mSupportsSwapChainResize; // Support for IDXGISwapChain::ResizeBuffers method bool mSupportsSwapChainResize; // Support for IDXGISwapChain::ResizeBuffers method
bool mSwapChainSizeSpecified; // If an EGLRenderSurfaceSizeProperty was specified bool mSwapChainSizeSpecified; // If an EGLRenderSurfaceSizeProperty was specified
......
...@@ -169,14 +169,14 @@ bool SwapChainPanelNativeWindow::initialize(EGLNativeWindowType window, IPropert ...@@ -169,14 +169,14 @@ bool SwapChainPanelNativeWindow::initialize(EGLNativeWindowType window, IPropert
} }
else else
{ {
SIZE swapChainPanelSize; Size swapChainPanelSize;
result = GetSwapChainPanelSize(mSwapChainPanel, mSwapChainPanelDispatcher, result = GetSwapChainPanelSize(mSwapChainPanel, mSwapChainPanelDispatcher,
&swapChainPanelSize); &swapChainPanelSize);
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
// Update the client rect to account for any swapchain scale factor // Update the client rect to account for any swapchain scale factor
mClientRect = { 0, 0, static_cast<long>(swapChainPanelSize.cx * mSwapChainScale), static_cast<long>(swapChainPanelSize.cy * mSwapChainScale) }; mClientRect = clientRect(swapChainPanelSize);
} }
} }
} }
...@@ -269,7 +269,7 @@ HRESULT SwapChainPanelNativeWindow::createSwapChain(ID3D11Device *device, ...@@ -269,7 +269,7 @@ HRESULT SwapChainPanelNativeWindow::createSwapChain(ID3D11Device *device,
ComPtr<IDXGISwapChain1> newSwapChain; ComPtr<IDXGISwapChain1> newSwapChain;
ComPtr<ISwapChainPanelNative> swapChainPanelNative; ComPtr<ISwapChainPanelNative> swapChainPanelNative;
SIZE currentPanelSize = {}; Size currentPanelSize = {};
HRESULT result = factory->CreateSwapChainForComposition(device, &swapChainDesc, nullptr, newSwapChain.ReleaseAndGetAddressOf()); HRESULT result = factory->CreateSwapChainForComposition(device, &swapChainDesc, nullptr, newSwapChain.ReleaseAndGetAddressOf());
...@@ -318,10 +318,10 @@ HRESULT SwapChainPanelNativeWindow::createSwapChain(ID3D11Device *device, ...@@ -318,10 +318,10 @@ HRESULT SwapChainPanelNativeWindow::createSwapChain(ID3D11Device *device,
return result; return result;
} }
HRESULT SwapChainPanelNativeWindow::scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) HRESULT SwapChainPanelNativeWindow::scaleSwapChain(const Size &windowSize, const RECT &clientRect)
{ {
Size renderScale = {(float)windowSize.cx / (float)clientRect.right, Size renderScale = {windowSize.Width / (float)clientRect.right,
(float)windowSize.cy / (float)clientRect.bottom}; windowSize.Height / (float)clientRect.bottom};
// Setup a scale matrix for the swap chain // Setup a scale matrix for the swap chain
DXGI_MATRIX_3X2_F scaleMatrix = {}; DXGI_MATRIX_3X2_F scaleMatrix = {};
scaleMatrix._11 = renderScale.Width; scaleMatrix._11 = renderScale.Width;
...@@ -340,24 +340,14 @@ HRESULT SwapChainPanelNativeWindow::scaleSwapChain(const SIZE &windowSize, const ...@@ -340,24 +340,14 @@ HRESULT SwapChainPanelNativeWindow::scaleSwapChain(const SIZE &windowSize, const
HRESULT GetSwapChainPanelSize( HRESULT GetSwapChainPanelSize(
const ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> &swapChainPanel, const ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> &swapChainPanel,
const ComPtr<ICoreDispatcher> &dispatcher, const ComPtr<ICoreDispatcher> &dispatcher,
SIZE *windowSize) Size *windowSize)
{ {
ComPtr<IUIElement> uiElement; ComPtr<IUIElement> uiElement;
Size renderSize = {0, 0};
HRESULT result = swapChainPanel.As(&uiElement); HRESULT result = swapChainPanel.As(&uiElement);
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
result = RunOnUIThread( result = RunOnUIThread(
[uiElement, &renderSize] [uiElement, windowSize] { return uiElement->get_RenderSize(windowSize); }, dispatcher);
{
return uiElement->get_RenderSize(&renderSize);
},
dispatcher);
}
if (SUCCEEDED(result))
{
*windowSize = { lround(renderSize.Width), lround(renderSize.Height) };
} }
return result; return result;
......
...@@ -30,7 +30,7 @@ class SwapChainPanelNativeWindow : public InspectableNativeWindow, public std::e ...@@ -30,7 +30,7 @@ class SwapChainPanelNativeWindow : public InspectableNativeWindow, public std::e
IDXGISwapChain1 **swapChain) override; IDXGISwapChain1 **swapChain) override;
protected: protected:
HRESULT scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) override; HRESULT scaleSwapChain(const Size &windowSize, const RECT &clientRect) override;
bool registerForSizeChangeEvents(); bool registerForSizeChangeEvents();
void unregisterForSizeChangeEvents(); void unregisterForSizeChangeEvents();
...@@ -74,8 +74,7 @@ class SwapChainPanelSizeChangedHandler : ...@@ -74,8 +74,7 @@ class SwapChainPanelSizeChangedHandler :
HRESULT result = sizeChangedEventArgs->get_NewSize(&newSize); HRESULT result = sizeChangedEventArgs->get_NewSize(&newSize);
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
SIZE windowSize = { lround(newSize.Width), lround(newSize.Height) }; host->setNewClientSize(newSize);
host->setNewClientSize(windowSize);
} }
} }
...@@ -89,6 +88,6 @@ class SwapChainPanelSizeChangedHandler : ...@@ -89,6 +88,6 @@ class SwapChainPanelSizeChangedHandler :
HRESULT GetSwapChainPanelSize( HRESULT GetSwapChainPanelSize(
const ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> &swapChainPanel, const ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> &swapChainPanel,
const ComPtr<ABI::Windows::UI::Core::ICoreDispatcher> &dispatcher, const ComPtr<ABI::Windows::UI::Core::ICoreDispatcher> &dispatcher,
SIZE *windowSize); Size *windowSize);
} }
#endif // LIBANGLE_RENDERER_D3D_D3D11_WINRT_SWAPCHAINPANELNATIVEWINDOW_H_ #endif // LIBANGLE_RENDERER_D3D_D3D11_WINRT_SWAPCHAINPANELNATIVEWINDOW_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment