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