CompositorNativeWindow11.h (4187B)
1 // 2 // Copyright 2018 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 // CompositorNativeWindow11.h: Implementation of NativeWindow11 using Windows.UI.Composition APIs 8 // which work in both Win32 and WinRT contexts. 9 10 #ifndef LIBANGLE_RENDERER_D3D_D3D11_CONVERGED_COMPOSITORNATIVEWINDOW11_H_ 11 #define LIBANGLE_RENDERER_D3D_D3D11_CONVERGED_COMPOSITORNATIVEWINDOW11_H_ 12 13 #include "libANGLE/renderer/d3d/d3d11/NativeWindow11.h" 14 15 #include <dispatcherqueue.h> 16 #include <versionhelpers.h> 17 #include <windows.foundation.metadata.h> 18 #include <windows.ui.composition.h> 19 #include <windows.ui.composition.interop.h> 20 #include <wrl.h> 21 22 namespace rx 23 { 24 25 class RoHelper 26 { 27 public: 28 RoHelper(); 29 ~RoHelper(); 30 bool WinRtAvailable() const; 31 bool SupportedWindowsRelease(); 32 HRESULT GetStringReference(PCWSTR source, HSTRING *act, HSTRING_HEADER *header); 33 HRESULT GetActivationFactory(const HSTRING act, const IID &interfaceId, void **fac); 34 HRESULT WindowsCompareStringOrdinal(HSTRING one, HSTRING two, int *result); 35 HRESULT CreateDispatcherQueueController( 36 DispatcherQueueOptions options, 37 ABI::Windows::System::IDispatcherQueueController **dispatcherQueueController); 38 HRESULT WindowsDeleteString(HSTRING one); 39 HRESULT RoInitialize(RO_INIT_TYPE type); 40 void RoUninitialize(); 41 42 private: 43 using WindowsCreateStringReference_ = HRESULT __stdcall(PCWSTR, 44 UINT32, 45 HSTRING_HEADER *, 46 HSTRING *); 47 48 using GetActivationFactory_ = HRESULT __stdcall(HSTRING, REFIID, void **); 49 50 using WindowsCompareStringOrginal_ = HRESULT __stdcall(HSTRING, HSTRING, int *); 51 52 using WindowsDeleteString_ = HRESULT __stdcall(HSTRING); 53 54 using CreateDispatcherQueueController_ = 55 HRESULT __stdcall(DispatcherQueueOptions, 56 ABI::Windows::System::IDispatcherQueueController **); 57 58 using RoInitialize_ = HRESULT __stdcall(RO_INIT_TYPE); 59 using RoUninitialize_ = void __stdcall(); 60 61 WindowsCreateStringReference_ *mFpWindowsCreateStringReference; 62 GetActivationFactory_ *mFpGetActivationFactory; 63 WindowsCompareStringOrginal_ *mFpWindowsCompareStringOrdinal; 64 CreateDispatcherQueueController_ *mFpCreateDispatcherQueueController; 65 WindowsDeleteString_ *mFpWindowsDeleteString; 66 RoInitialize_ *mFpRoInitialize; 67 RoUninitialize_ *mFpRoUninitialize; 68 69 bool mWinRtAvailable; 70 bool mWinRtInitialized; 71 72 HMODULE mComBaseModule; 73 HMODULE mCoreMessagingModule; 74 }; 75 76 class CompositorNativeWindow11 : public NativeWindow11 77 { 78 public: 79 CompositorNativeWindow11(EGLNativeWindowType window, bool hasAlpha); 80 ~CompositorNativeWindow11() override; 81 82 bool initialize() override; 83 bool getClientRect(LPRECT rect) const override; 84 bool isIconic() const override; 85 86 HRESULT createSwapChain(ID3D11Device *device, 87 IDXGIFactory *factory, 88 DXGI_FORMAT format, 89 UINT width, 90 UINT height, 91 UINT samples, 92 IDXGISwapChain **swapChain) override; 93 94 void commitChange() override; 95 96 static bool IsValidNativeWindow(EGLNativeWindowType window); 97 98 static bool IsSupportedWinRelease(); 99 100 private: 101 static bool IsSpriteVisual(EGLNativeWindowType window); 102 103 bool mHasAlpha; 104 105 RoHelper mRoHelper; 106 107 // Namespace prefix required here for some reason despite using namespace 108 Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ISpriteVisual> mHostVisual; 109 Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ICompositionBrush> mCompositionBrush; 110 Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ICompositionSurface> mSurface; 111 Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ICompositionSurfaceBrush> mSurfaceBrush; 112 }; 113 114 } // namespace rx 115 116 #endif // LIBANGLE_RENDERER_D3D_D3D11_CONVERGED_COMPOSITORNATIVEWINDOW11_H_