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