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