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 // DisplayGLX.h: GLX implementation of egl::Display 8 9 #ifndef LIBANGLE_RENDERER_GL_GLX_DISPLAYGLX_H_ 10 #define LIBANGLE_RENDERER_GL_GLX_DISPLAYGLX_H_ 11 12 #include <string> 13 #include <thread> 14 #include <vector> 15 16 #include "common/Optional.h" 17 #include "libANGLE/renderer/gl/DisplayGL.h" 18 #include "libANGLE/renderer/gl/RendererGL.h" 19 #include "libANGLE/renderer/gl/glx/FunctionsGLX.h" 20 21 namespace rx 22 { 23 24 class FunctionsGLX; 25 class WorkerContext; 26 27 struct SwapControlData; 28 29 class DisplayGLX : public DisplayGL 30 { 31 public: 32 DisplayGLX(const egl::DisplayState &state); 33 ~DisplayGLX() override; 34 35 egl::Error initialize(egl::Display *display) override; 36 void terminate() override; 37 38 egl::Error makeCurrent(egl::Display *display, 39 egl::Surface *drawSurface, 40 egl::Surface *readSurface, 41 gl::Context *context) override; 42 43 SurfaceImpl *createWindowSurface(const egl::SurfaceState &state, 44 EGLNativeWindowType window, 45 const egl::AttributeMap &attribs) override; 46 SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state, 47 const egl::AttributeMap &attribs) override; 48 SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state, 49 EGLenum buftype, 50 EGLClientBuffer clientBuffer, 51 const egl::AttributeMap &attribs) override; 52 SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state, 53 NativePixmapType nativePixmap, 54 const egl::AttributeMap &attribs) override; 55 56 egl::Error validatePixmap(const egl::Config *config, 57 EGLNativePixmapType pixmap, 58 const egl::AttributeMap &attributes) const override; 59 60 ContextImpl *createContext(const gl::State &state, 61 gl::ErrorSet *errorSet, 62 const egl::Config *configuration, 63 const gl::Context *shareContext, 64 const egl::AttributeMap &attribs) override; 65 66 egl::ConfigSet generateConfigs() override; 67 68 bool testDeviceLost() override; 69 egl::Error restoreLostDevice(const egl::Display *display) override; 70 71 bool isValidNativeWindow(EGLNativeWindowType window) const override; 72 73 egl::Error waitClient(const gl::Context *context) override; 74 egl::Error waitNative(const gl::Context *context, EGLint engine) override; 75 76 gl::Version getMaxSupportedESVersion() const override; 77 78 // Synchronizes with the X server. 79 // Calling this is required at the end of every functions that does buffered 80 // X calls (not for glX calls) otherwise there might be race conditions 81 // between the application's display and ANGLE's one. 82 // Calling this only syncs if ANGLE opened the display, or if alwaysSync 83 // is true. 84 void syncXCommands(bool alwaysSync) const; 85 86 // Depending on the supported GLX extension, swap interval can be set 87 // globally or per drawable. This function will make sure the drawable's 88 // swap interval is the one required so that the subsequent swapBuffers 89 // acts as expected. 90 void setSwapInterval(glx::Drawable drawable, SwapControlData *data); 91 92 bool isWindowVisualIdSpecified() const; 93 bool isMatchingWindowVisualId(unsigned long visualId) const; 94 95 WorkerContext *createWorkerContext(std::string *infoLog); 96 97 void initializeFrontendFeatures(angle::FrontendFeatures *features) const override; 98 99 void populateFeatureList(angle::FeatureList *features) override; 100 101 RendererGL *getRenderer() const override; 102 103 private: 104 egl::Error initializeContext(glx::FBConfig config, 105 const egl::AttributeMap &eglAttributes, 106 glx::Context *context); 107 108 void generateExtensions(egl::DisplayExtensions *outExtensions) const override; 109 void generateCaps(egl::Caps *outCaps) const override; 110 111 egl::Error makeCurrentSurfaceless(gl::Context *context) override; 112 113 int getGLXFBConfigAttrib(glx::FBConfig config, int attrib) const; 114 egl::Error createContextAttribs(glx::FBConfig, 115 const Optional<gl::Version> &version, 116 int profileMask, 117 glx::Context *context); 118 119 std::shared_ptr<RendererGL> mRenderer; 120 121 std::map<int, glx::FBConfig> configIdToGLXConfig; 122 123 EGLint mRequestedVisual; 124 glx::FBConfig mContextConfig; 125 std::vector<int> mAttribs; 126 XVisualInfo *mVisuals; 127 glx::Context mContext; 128 glx::Context mSharedContext; 129 angle::HashMap<std::thread::id, glx::Context> mCurrentNativeContexts; 130 131 // A pbuffer the context is current on during ANGLE initialization 132 glx::Pbuffer mInitPbuffer; 133 134 std::vector<glx::Pbuffer> mWorkerPbufferPool; 135 136 bool mUsesNewXDisplay; 137 bool mIsMesa; 138 bool mHasMultisample; 139 bool mHasARBCreateContext; 140 bool mHasARBCreateContextProfile; 141 bool mHasARBCreateContextRobustness; 142 bool mHasEXTCreateContextES2Profile; 143 bool mHasNVRobustnessVideoMemoryPurge; 144 145 enum class SwapControl 146 { 147 Absent, 148 EXT, 149 Mesa, 150 SGI, 151 }; 152 SwapControl mSwapControl; 153 int mMinSwapInterval; 154 int mMaxSwapInterval; 155 int mCurrentSwapInterval; 156 157 glx::Drawable mCurrentDrawable; 158 159 FunctionsGLX mGLX; 160 Display *mXDisplay; 161 egl::Display *mEGLDisplay; 162 }; 163 164 } // namespace rx 165 166 #endif // LIBANGLE_RENDERER_GL_GLX_DISPLAYGLX_H_ 167