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