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.
# This file is distinct from the CONTRIBUTORS files.
# See the latter for an explanation.
......@@ -45,3 +45,4 @@ Maks Naumov
Jinyoung Hur
Sebastian Bergstein
James Ross-Gowan
Nickolay Artamonov
......@@ -88,12 +88,12 @@ bool CoreWindowNativeWindow::initialize(EGLNativeWindowType window, IPropertySet
}
else
{
SIZE coreWindowSize;
Size coreWindowSize;
result = GetCoreWindowSizeInPixels(mCoreWindow, &coreWindowSize);
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,
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.
// Using DXGI_SCALING_STRETCH to create the swapchain above does all the necessary work.
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;
HRESULT result = coreWindow->get_Bounds(&bounds);
......@@ -230,9 +232,9 @@ static float GetLogicalDpi()
return 96.0f;
}
long ConvertDipsToPixels(float dips)
float ConvertDipsToPixels(float dips)
{
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
namespace rx
{
long ConvertDipsToPixels(float dips);
float ConvertDipsToPixels(float dips);
class CoreWindowNativeWindow : public InspectableNativeWindow, public std::enable_shared_from_this<CoreWindowNativeWindow>
{
......@@ -36,7 +36,7 @@ class CoreWindowNativeWindow : public InspectableNativeWindow, public std::enabl
IDXGISwapChain1 **swapChain) override;
protected:
HRESULT scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) override;
HRESULT scaleSwapChain(const Size &windowSize, const RECT &clientRect) override;
bool registerForSizeChangeEvents();
void unregisterForSizeChangeEvents();
......@@ -72,7 +72,8 @@ class CoreWindowSizeChangedHandler :
ABI::Windows::Foundation::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);
}
}
......@@ -84,7 +85,8 @@ class CoreWindowSizeChangedHandler :
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_
......@@ -267,4 +267,10 @@ HRESULT GetOptionalSinglePropertyValue(const ComPtr<ABI::Windows::Foundation::Co
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
}
// 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
ASSERT(mSupportsSwapChainResize);
......@@ -78,8 +78,7 @@ class InspectableNativeWindow
// If the swapchain size was specified then we should ignore this call too
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 = { 0, 0, static_cast<long>(newWindowSize.cx * mSwapChainScale), static_cast<long>(newWindowSize.cy * mSwapChainScale) };
mNewClientRect = clientRect(newWindowSize);
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
......@@ -99,7 +98,8 @@ class InspectableNativeWindow
}
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 mSwapChainSizeSpecified; // If an EGLRenderSurfaceSizeProperty was specified
......
......@@ -169,14 +169,14 @@ bool SwapChainPanelNativeWindow::initialize(EGLNativeWindowType window, IPropert
}
else
{
SIZE swapChainPanelSize;
Size swapChainPanelSize;
result = GetSwapChainPanelSize(mSwapChainPanel, mSwapChainPanelDispatcher,
&swapChainPanelSize);
if (SUCCEEDED(result))
{
// 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,
ComPtr<IDXGISwapChain1> newSwapChain;
ComPtr<ISwapChainPanelNative> swapChainPanelNative;
SIZE currentPanelSize = {};
Size currentPanelSize = {};
HRESULT result = factory->CreateSwapChainForComposition(device, &swapChainDesc, nullptr, newSwapChain.ReleaseAndGetAddressOf());
......@@ -318,10 +318,10 @@ HRESULT SwapChainPanelNativeWindow::createSwapChain(ID3D11Device *device,
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,
(float)windowSize.cy / (float)clientRect.bottom};
Size renderScale = {windowSize.Width / (float)clientRect.right,
windowSize.Height / (float)clientRect.bottom};
// Setup a scale matrix for the swap chain
DXGI_MATRIX_3X2_F scaleMatrix = {};
scaleMatrix._11 = renderScale.Width;
......@@ -340,24 +340,14 @@ HRESULT SwapChainPanelNativeWindow::scaleSwapChain(const SIZE &windowSize, const
HRESULT GetSwapChainPanelSize(
const ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> &swapChainPanel,
const ComPtr<ICoreDispatcher> &dispatcher,
SIZE *windowSize)
Size *windowSize)
{
ComPtr<IUIElement> uiElement;
Size renderSize = {0, 0};
HRESULT result = swapChainPanel.As(&uiElement);
if (SUCCEEDED(result))
{
result = RunOnUIThread(
[uiElement, &renderSize]
{
return uiElement->get_RenderSize(&renderSize);
},
dispatcher);
}
if (SUCCEEDED(result))
{
*windowSize = { lround(renderSize.Width), lround(renderSize.Height) };
[uiElement, windowSize] { return uiElement->get_RenderSize(windowSize); }, dispatcher);
}
return result;
......
......@@ -30,7 +30,7 @@ class SwapChainPanelNativeWindow : public InspectableNativeWindow, public std::e
IDXGISwapChain1 **swapChain) override;
protected:
HRESULT scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) override;
HRESULT scaleSwapChain(const Size &windowSize, const RECT &clientRect) override;
bool registerForSizeChangeEvents();
void unregisterForSizeChangeEvents();
......@@ -74,8 +74,7 @@ class SwapChainPanelSizeChangedHandler :
HRESULT result = sizeChangedEventArgs->get_NewSize(&newSize);
if (SUCCEEDED(result))
{
SIZE windowSize = { lround(newSize.Width), lround(newSize.Height) };
host->setNewClientSize(windowSize);
host->setNewClientSize(newSize);
}
}
......@@ -89,6 +88,6 @@ class SwapChainPanelSizeChangedHandler :
HRESULT GetSwapChainPanelSize(
const ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> &swapChainPanel,
const ComPtr<ABI::Windows::UI::Core::ICoreDispatcher> &dispatcher,
SIZE *windowSize);
Size *windowSize);
}
#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