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 egl::Error waitClient(const gl::Context *context) override; 67 egl::Error waitNative(const gl::Context *context, EGLint engine) override; 68 69 egl::Error makeCurrent(egl::Display *display, 70 egl::Surface *drawSurface, 71 egl::Surface *readSurface, 72 gl::Context *context) override; 73 74 egl::Error registerD3DDevice(IUnknown *device, HANDLE *outHandle); 75 void releaseD3DDevice(HANDLE handle); 76 77 gl::Version getMaxSupportedESVersion() const override; 78 79 void destroyNativeContext(HGLRC context); 80 81 WorkerContext *createWorkerContext(std::string *infoLog, 82 HGLRC sharedContext, 83 const std::vector<int> &workerContextAttribs); 84 85 void initializeFrontendFeatures(angle::FrontendFeatures *features) const override; 86 87 void populateFeatureList(angle::FeatureList *features) override; 88 89 RendererGL *getRenderer() const override; 90 91 private: 92 egl::Error initializeImpl(egl::Display *display); 93 void destroy(); 94 95 egl::Error initializeD3DDevice(); 96 97 void generateExtensions(egl::DisplayExtensions *outExtensions) const override; 98 void generateCaps(egl::Caps *outCaps) const override; 99 100 egl::Error makeCurrentSurfaceless(gl::Context *context) override; 101 102 HGLRC initializeContextAttribs(const egl::AttributeMap &eglAttributes, 103 HGLRC &sharedContext, 104 bool &useARBShare, 105 std::vector<int> &workerContextAttribs) const; 106 HGLRC createContextAttribs(const gl::Version &version, 107 int profileMask, 108 HGLRC &sharedContext, 109 bool &useARBShare, 110 std::vector<int> &workerContextAttribs) const; 111 112 egl::Error createRenderer(std::shared_ptr<RendererWGL> *outRenderer); 113 114 std::shared_ptr<RendererWGL> mRenderer; 115 116 struct CurrentNativeContext 117 { 118 HDC dc = nullptr; 119 HGLRC glrc = nullptr; 120 }; 121 angle::HashMap<std::thread::id, CurrentNativeContext> mCurrentNativeContexts; 122 123 HMODULE mOpenGLModule; 124 125 FunctionsWGL *mFunctionsWGL; 126 127 bool mHasWGLCreateContextRobustness; 128 bool mHasRobustness; 129 130 egl::AttributeMap mDisplayAttributes; 131 132 ATOM mWindowClass; 133 HWND mWindow; 134 HDC mDeviceContext; 135 int mPixelFormat; 136 137 bool mUseDXGISwapChains; 138 bool mHasDXInterop; 139 HMODULE mDxgiModule; 140 HMODULE mD3d11Module; 141 HANDLE mD3D11DeviceHandle; 142 ID3D11Device *mD3D11Device; 143 144 struct D3DObjectHandle 145 { 146 HANDLE handle; 147 size_t refCount; 148 }; 149 std::map<IUnknown *, D3DObjectHandle> mRegisteredD3DDevices; 150 151 bool mUseARBShare; 152 }; 153 154 } // namespace rx 155 156 #endif // LIBANGLE_RENDERER_GL_WGL_DISPLAYWGL_H_ 157