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