summaryrefslogtreecommitdiffstats
path: root/gfx/angle/checkout/src/libANGLE/renderer/d3d/d3d11/converged/CompositorNativeWindow11.h
blob: 82857322e002549a1871735a029f3e2a42ff83b3 (plain)
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
//
// Copyright 2018 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.
//

// CompositorNativeWindow11.h: Implementation of NativeWindow11 using Windows.UI.Composition APIs
// which work in both Win32 and WinRT contexts.

#ifndef LIBANGLE_RENDERER_D3D_D3D11_CONVERGED_COMPOSITORNATIVEWINDOW11_H_
#define LIBANGLE_RENDERER_D3D_D3D11_CONVERGED_COMPOSITORNATIVEWINDOW11_H_

#include "libANGLE/renderer/d3d/d3d11/NativeWindow11.h"

#include <dispatcherqueue.h>
#include <versionhelpers.h>
#include <windows.foundation.metadata.h>
#include <windows.ui.composition.h>
#include <windows.ui.composition.interop.h>
#include <wrl.h>

namespace rx
{

class RoHelper
{
  public:
    RoHelper();
    ~RoHelper();
    bool WinRtAvailable() const;
    bool SupportedWindowsRelease();
    HRESULT GetStringReference(PCWSTR source, HSTRING *act, HSTRING_HEADER *header);
    HRESULT GetActivationFactory(const HSTRING act, const IID &interfaceId, void **fac);
    HRESULT WindowsCompareStringOrdinal(HSTRING one, HSTRING two, int *result);
    HRESULT CreateDispatcherQueueController(
        DispatcherQueueOptions options,
        ABI::Windows::System::IDispatcherQueueController **dispatcherQueueController);
    HRESULT WindowsDeleteString(HSTRING one);
    HRESULT RoInitialize(RO_INIT_TYPE type);
    void RoUninitialize();

  private:
    using WindowsCreateStringReference_ = HRESULT __stdcall(PCWSTR,
                                                            UINT32,
                                                            HSTRING_HEADER *,
                                                            HSTRING *);

    using GetActivationFactory_ = HRESULT __stdcall(HSTRING, REFIID, void **);

    using WindowsCompareStringOrginal_ = HRESULT __stdcall(HSTRING, HSTRING, int *);

    using WindowsDeleteString_ = HRESULT __stdcall(HSTRING);

    using CreateDispatcherQueueController_ =
        HRESULT __stdcall(DispatcherQueueOptions,
                          ABI::Windows::System::IDispatcherQueueController **);

    using RoInitialize_   = HRESULT __stdcall(RO_INIT_TYPE);
    using RoUninitialize_ = void __stdcall();

    WindowsCreateStringReference_ *mFpWindowsCreateStringReference;
    GetActivationFactory_ *mFpGetActivationFactory;
    WindowsCompareStringOrginal_ *mFpWindowsCompareStringOrdinal;
    CreateDispatcherQueueController_ *mFpCreateDispatcherQueueController;
    WindowsDeleteString_ *mFpWindowsDeleteString;
    RoInitialize_ *mFpRoInitialize;
    RoUninitialize_ *mFpRoUninitialize;

    bool mWinRtAvailable;
    bool mWinRtInitialized;

    HMODULE mComBaseModule;
    HMODULE mCoreMessagingModule;
};

class CompositorNativeWindow11 : public NativeWindow11
{
  public:
    CompositorNativeWindow11(EGLNativeWindowType window, bool hasAlpha);
    ~CompositorNativeWindow11() override;

    bool initialize() override;
    bool getClientRect(LPRECT rect) const override;
    bool isIconic() const override;

    HRESULT createSwapChain(ID3D11Device *device,
                            IDXGIFactory *factory,
                            DXGI_FORMAT format,
                            UINT width,
                            UINT height,
                            UINT samples,
                            IDXGISwapChain **swapChain) override;

    void commitChange() override;

    static bool IsValidNativeWindow(EGLNativeWindowType window);

    static bool IsSupportedWinRelease();

  private:
    static bool IsSpriteVisual(EGLNativeWindowType window);

    bool mHasAlpha;

    RoHelper mRoHelper;

    // Namespace prefix required here for some reason despite using namespace
    Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ISpriteVisual> mHostVisual;
    Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ICompositionBrush> mCompositionBrush;
    Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ICompositionSurface> mSurface;
    Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ICompositionSurfaceBrush> mSurfaceBrush;
};

}  // namespace rx

#endif  // LIBANGLE_RENDERER_D3D_D3D11_CONVERGED_COMPOSITORNATIVEWINDOW11_H_