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