xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/gl/wgl/DisplayWGL.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2015 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 // DisplayWGL.h: WGL implementation of egl::Display
8 
9 #ifndef LIBANGLE_RENDERER_GL_WGL_DISPLAYWGL_H_
10 #define LIBANGLE_RENDERER_GL_WGL_DISPLAYWGL_H_
11 
12 #include <unordered_map>
13 
14 #include "libANGLE/renderer/gl/DisplayGL.h"
15 
16 #include <GL/wglext.h>
17 
18 namespace rx
19 {
20 
21 class FunctionsWGL;
22 class RendererWGL;
23 
24 class DisplayWGL : public DisplayGL
25 {
26   public:
27     DisplayWGL(const egl::DisplayState &state);
28     ~DisplayWGL() override;
29 
30     egl::Error initialize(egl::Display *display) override;
31     void terminate() override;
32 
33     // Surface creation
34     SurfaceImpl *createWindowSurface(const egl::SurfaceState &state,
35                                      EGLNativeWindowType window,
36                                      const egl::AttributeMap &attribs) override;
37     SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state,
38                                       const egl::AttributeMap &attribs) override;
39     SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state,
40                                                EGLenum buftype,
41                                                EGLClientBuffer clientBuffer,
42                                                const egl::AttributeMap &attribs) override;
43     SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state,
44                                      NativePixmapType nativePixmap,
45                                      const egl::AttributeMap &attribs) override;
46 
47     ContextImpl *createContext(const gl::State &state,
48                                gl::ErrorSet *errorSet,
49                                const egl::Config *configuration,
50                                const gl::Context *shareContext,
51                                const egl::AttributeMap &attribs) override;
52 
53     egl::ConfigSet generateConfigs() override;
54 
55     bool testDeviceLost() override;
56     egl::Error restoreLostDevice(const egl::Display *display) override;
57 
58     bool isValidNativeWindow(EGLNativeWindowType window) const override;
59     egl::Error validateClientBuffer(const egl::Config *configuration,
60                                     EGLenum buftype,
61                                     EGLClientBuffer clientBuffer,
62                                     const egl::AttributeMap &attribs) const override;
63 
64     egl::Error waitClient(const gl::Context *context) override;
65     egl::Error waitNative(const gl::Context *context, EGLint engine) override;
66 
67     egl::Error makeCurrent(egl::Display *display,
68                            egl::Surface *drawSurface,
69                            egl::Surface *readSurface,
70                            gl::Context *context) override;
71 
72     egl::Error registerD3DDevice(IUnknown *device, HANDLE *outHandle);
73     void releaseD3DDevice(HANDLE handle);
74 
75     gl::Version getMaxSupportedESVersion() const override;
76 
77     void destroyNativeContext(HGLRC context);
78 
79     void initializeFrontendFeatures(angle::FrontendFeatures *features) const override;
80 
81     void populateFeatureList(angle::FeatureList *features) override;
82 
83     RendererGL *getRenderer() const override;
84 
85   private:
86     egl::Error initializeImpl(egl::Display *display);
87     void destroy();
88 
89     egl::Error initializeD3DDevice();
90 
91     void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
92     void generateCaps(egl::Caps *outCaps) const override;
93 
94     egl::Error makeCurrentSurfaceless(gl::Context *context) override;
95 
96     HGLRC initializeContextAttribs(const egl::AttributeMap &eglAttributes) const;
97     HGLRC createContextAttribs(const gl::Version &version, int profileMask) const;
98 
99     egl::Error createRenderer(std::shared_ptr<RendererWGL> *outRenderer);
100 
101     std::shared_ptr<RendererWGL> mRenderer;
102 
103     struct CurrentNativeContext
104     {
105         HDC dc     = nullptr;
106         HGLRC glrc = nullptr;
107     };
108     angle::HashMap<uint64_t, CurrentNativeContext> mCurrentNativeContexts;
109 
110     HMODULE mOpenGLModule;
111 
112     FunctionsWGL *mFunctionsWGL;
113 
114     bool mHasWGLCreateContextRobustness;
115     bool mHasRobustness;
116 
117     egl::AttributeMap mDisplayAttributes;
118 
119     ATOM mWindowClass;
120     HWND mWindow;
121     HDC mDeviceContext;
122     int mPixelFormat;
123 
124     bool mUseDXGISwapChains;
125     bool mHasDXInterop;
126     HMODULE mDxgiModule;
127     HMODULE mD3d11Module;
128     HANDLE mD3D11DeviceHandle;
129     ID3D11Device *mD3D11Device;
130     ID3D11Device1 *mD3D11Device1;
131 
132     struct D3DObjectHandle
133     {
134         HANDLE handle;
135         size_t refCount;
136     };
137     std::map<IUnknown *, D3DObjectHandle> mRegisteredD3DDevices;
138 };
139 
140 }  // namespace rx
141 
142 #endif  // LIBANGLE_RENDERER_GL_WGL_DISPLAYWGL_H_
143