xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/gl/glx/DisplayGLX.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 
19 #include "libANGLE/renderer/gl/glx/FunctionsGLX.h"
20 
21 namespace rx
22 {
23 
24 class FunctionsGLX;
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     void initializeFrontendFeatures(angle::FrontendFeatures *features) const override;
95 
96     void populateFeatureList(angle::FeatureList *features) override;
97 
98     RendererGL *getRenderer() const override;
99 
100     angle::NativeWindowSystem getWindowSystem() const override;
101 
102   private:
103     egl::Error initializeContext(glx::FBConfig config,
104                                  const egl::AttributeMap &eglAttributes,
105                                  glx::Context *context);
106 
107     void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
108     void generateCaps(egl::Caps *outCaps) const override;
109 
110     egl::Error makeCurrentSurfaceless(gl::Context *context) override;
111 
112     int getGLXFBConfigAttrib(glx::FBConfig config, int attrib) const;
113     egl::Error createContextAttribs(glx::FBConfig,
114                                     const Optional<gl::Version> &version,
115                                     int profileMask,
116                                     glx::Context *context) const;
117 
118     std::shared_ptr<RendererGL> mRenderer;
119 
120     std::map<int, glx::FBConfig> configIdToGLXConfig;
121 
122     EGLint mRequestedVisual;
123     glx::FBConfig mContextConfig;
124     glx::Context mContext;
125     angle::HashMap<uint64_t, glx::Context> mCurrentNativeContexts;
126 
127     // A pbuffer the context is current on during ANGLE initialization
128     glx::Pbuffer mInitPbuffer;
129 
130     bool mUsesNewXDisplay;
131     bool mIsMesa;
132     bool mHasMultisample;
133     bool mHasARBCreateContext;
134     bool mHasARBCreateContextProfile;
135     bool mHasARBCreateContextRobustness;
136     bool mHasEXTCreateContextES2Profile;
137     bool mHasNVRobustnessVideoMemoryPurge;
138 
139     enum class SwapControl
140     {
141         Absent,
142         EXT,
143         Mesa,
144         SGI,
145     };
146     SwapControl mSwapControl;
147     int mMinSwapInterval;
148     int mMaxSwapInterval;
149     int mCurrentSwapInterval;
150 
151     glx::Drawable mCurrentDrawable;
152 
153     FunctionsGLX mGLX;
154     Display *mXDisplay;
155     egl::Display *mEGLDisplay;
156 };
157 
158 }  // namespace rx
159 
160 #endif  // LIBANGLE_RENDERER_GL_GLX_DISPLAYGLX_H_
161