Hash :
b0a53105
Author :
Date :
2016-04-01T11:43:54
Add a NativeWindowD3D abstract class to handle native window interactions. The previous NativeWindow class included D3D11 headers while being included in all D3D backds and had platform-dependent includes and members. This turns it into an abstract class that only implements the minimal functionality for each renderer. BUG=angleproject:1345 Change-Id: I8f20339dd6bba719e574a1dcb3ec859897c9228f Reviewed-on: https://chromium-review.googlesource.com/336780 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindow11WinRT.cpp: NativeWindow base class for managing IInspectable native window types.
#include "libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.h"
#include "libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h"
#include "libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.h"
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
namespace rx
{
NativeWindow11WinRT::NativeWindow11WinRT(EGLNativeWindowType window, bool hasAlpha)
: NativeWindow11(window), mHasAlpha(hasAlpha)
{
}
bool NativeWindow11WinRT::initialize()
{
EGLNativeWindowType window = getNativeWindow();
// If the native window type is a IPropertySet, extract the
// EGLNativeWindowType (IInspectable) and initialize the
// proper host with this IPropertySet.
ComPtr<ABI::Windows::Foundation::Collections::IPropertySet> propertySet;
ComPtr<IInspectable> eglNativeWindow;
if (IsEGLConfiguredPropertySet(window, &propertySet, &eglNativeWindow))
{
// A property set was found and the EGLNativeWindowType was
// retrieved. The mWindow member of the host to must be updated
// to use the EGLNativeWindowType specified in the property set.
// mWindow is treated as a raw pointer not an AddRef'd interface, so
// the old mWindow does not need a Release() before this assignment.
window = eglNativeWindow.Get();
}
ComPtr<ABI::Windows::UI::Core::ICoreWindow> coreWindow;
ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> swapChainPanel;
if (IsCoreWindow(window, &coreWindow))
{
mImpl = std::make_shared<CoreWindowNativeWindow>();
if (mImpl)
{
return mImpl->initialize(window, propertySet.Get());
}
}
else if (IsSwapChainPanel(window, &swapChainPanel))
{
mImpl = std::make_shared<SwapChainPanelNativeWindow>();
if (mImpl)
{
return mImpl->initialize(window, propertySet.Get());
}
}
else
{
ERR(
"Invalid IInspectable EGLNativeWindowType detected. Valid IInspectables include "
"ICoreWindow, ISwapChainPanel and IPropertySet");
}
return false;
}
bool NativeWindow11WinRT::getClientRect(LPRECT rect) const
{
if (mImpl)
{
return mImpl->getClientRect(rect);
}
return false;
}
bool NativeWindow11WinRT::isIconic() const
{
return false;
}
HRESULT NativeWindow11WinRT::createSwapChain(ID3D11Device *device,
IDXGIFactory *factory,
DXGI_FORMAT format,
UINT width,
UINT height,
IDXGISwapChain **swapChain)
{
if (mImpl)
{
IDXGIFactory2 *factory2 = d3d11::DynamicCastComObject<IDXGIFactory2>(factory);
IDXGISwapChain1 *swapChain1 = nullptr;
HRESULT result =
mImpl->createSwapChain(device, factory2, format, width, height, mHasAlpha, &swapChain1);
SafeRelease(factory2);
*swapChain = static_cast<IDXGISwapChain *>(swapChain1);
return result;
}
return E_UNEXPECTED;
}
void NativeWindow11WinRT::commitChange()
{
}
// static
bool NativeWindow11WinRT::IsValidNativeWindow(EGLNativeWindowType window)
{
// A Valid EGLNativeWindowType IInspectable can only be:
//
// ICoreWindow
// ISwapChainPanel
// IPropertySet
//
// Anything else will be rejected as an invalid IInspectable.
return IsCoreWindow(window) || IsSwapChainPanel(window) || IsEGLConfiguredPropertySet(window);
}
} // namespace rx