Bug 1836072 [wpt PR 40324] - Fix scrollbar-width repaint issues on non viewports...
[gecko.git] / gfx / gl / GLXLibrary.h
blob7a004762ff500e5d8a4b0f2d89274cf5edc66a79
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_GLXLIBRARY_H
7 #define GFX_GLXLIBRARY_H
9 #include "GLContextTypes.h"
10 #include "mozilla/Assertions.h"
11 #include "mozilla/DataMutex.h"
12 #include "mozilla/gfx/XlibDisplay.h"
13 #include "prlink.h"
14 typedef realGLboolean GLboolean;
16 // stuff from glx.h
17 #include "X11/Xlib.h"
18 #include "X11/Xutil.h" // for XVisualInfo
19 #include "X11UndefineNone.h"
20 typedef struct __GLXcontextRec* GLXContext;
21 typedef XID GLXPixmap;
22 typedef XID GLXDrawable;
23 /* GLX 1.3 and later */
24 typedef struct __GLXFBConfigRec* GLXFBConfig;
25 // end of stuff from glx.h
26 #include "prenv.h"
28 struct PRLibrary;
29 class gfxASurface;
31 namespace mozilla {
32 namespace gl {
34 class GLContextGLX;
36 class GLXLibrary final {
37 public:
38 bool EnsureInitialized(Display* aDisplay);
40 private:
41 class WrapperScope final {
42 const GLXLibrary& mGlx;
43 const char* const mFuncName;
44 Display* const mDisplay;
46 public:
47 WrapperScope(const GLXLibrary& glx, const char* const funcName,
48 Display* aDisplay);
49 ~WrapperScope();
52 public:
53 #ifdef DEBUG
54 # define DECL_WRAPPER_SCOPE(display) \
55 const WrapperScope wrapperScope(*this, __func__, display);
56 #else
57 # define DECL_WRAPPER_SCOPE(display)
58 #endif
60 void fDestroyContext(Display* display, GLXContext context) const {
61 DECL_WRAPPER_SCOPE(display)
62 return mSymbols.fDestroyContext(display, context);
65 Bool fMakeCurrent(Display* display, GLXDrawable drawable,
66 GLXContext context) const {
67 DECL_WRAPPER_SCOPE(display)
68 return mSymbols.fMakeCurrent(display, drawable, context);
71 XVisualInfo* fGetConfig(Display* display, XVisualInfo* info, int attrib,
72 int* value) const {
73 DECL_WRAPPER_SCOPE(display)
74 return mSymbols.fGetConfig(display, info, attrib, value);
77 GLXContext fGetCurrentContext() const {
78 DECL_WRAPPER_SCOPE(nullptr)
79 return mSymbols.fGetCurrentContext();
82 GLXFBConfig* fChooseFBConfig(Display* display, int screen,
83 const int* attrib_list, int* nelements) const {
84 DECL_WRAPPER_SCOPE(display)
85 return mSymbols.fChooseFBConfig(display, screen, attrib_list, nelements);
88 XVisualInfo* fChooseVisual(Display* display, int screen,
89 int* attrib_list) const {
90 DECL_WRAPPER_SCOPE(display)
91 return mSymbols.fChooseVisual(display, screen, attrib_list);
94 GLXFBConfig* fGetFBConfigs(Display* display, int screen,
95 int* nelements) const {
96 DECL_WRAPPER_SCOPE(display)
97 return mSymbols.fGetFBConfigs(display, screen, nelements);
100 GLXContext fCreateNewContext(Display* display, GLXFBConfig config,
101 int render_type, GLXContext share_list,
102 Bool direct) const {
103 DECL_WRAPPER_SCOPE(display)
104 return mSymbols.fCreateNewContext(display, config, render_type, share_list,
105 direct);
108 int fGetFBConfigAttrib(Display* display, GLXFBConfig config, int attribute,
109 int* value) const {
110 DECL_WRAPPER_SCOPE(display)
111 return mSymbols.fGetFBConfigAttrib(display, config, attribute, value);
114 void fSwapBuffers(Display* display, GLXDrawable drawable) const {
115 DECL_WRAPPER_SCOPE(display)
116 return mSymbols.fSwapBuffers(display, drawable);
119 const char* fQueryExtensionsString(Display* display, int screen) const {
120 DECL_WRAPPER_SCOPE(display)
121 return mSymbols.fQueryExtensionsString(display, screen);
124 const char* fGetClientString(Display* display, int screen) const {
125 DECL_WRAPPER_SCOPE(display)
126 return mSymbols.fGetClientString(display, screen);
129 const char* fQueryServerString(Display* display, int screen, int name) const {
130 DECL_WRAPPER_SCOPE(display)
131 return mSymbols.fQueryServerString(display, screen, name);
134 GLXPixmap fCreatePixmap(Display* display, GLXFBConfig config, Pixmap pixmap,
135 const int* attrib_list) const {
136 DECL_WRAPPER_SCOPE(display)
137 return mSymbols.fCreatePixmap(display, config, pixmap, attrib_list);
140 GLXPixmap fCreateGLXPixmapWithConfig(Display* display, GLXFBConfig config,
141 Pixmap pixmap) const {
142 DECL_WRAPPER_SCOPE(display)
143 return mSymbols.fCreateGLXPixmapWithConfig(display, config, pixmap);
146 void fDestroyPixmap(Display* display, GLXPixmap pixmap) const {
147 DECL_WRAPPER_SCOPE(display)
148 return mSymbols.fDestroyPixmap(display, pixmap);
151 Bool fQueryVersion(Display* display, int* major, int* minor) const {
152 DECL_WRAPPER_SCOPE(display)
153 return mSymbols.fQueryVersion(display, major, minor);
156 void fBindTexImage(Display* display, GLXDrawable drawable, int buffer,
157 const int* attrib_list) const {
158 DECL_WRAPPER_SCOPE(display)
159 return mSymbols.fBindTexImageEXT(display, drawable, buffer, attrib_list);
162 void fReleaseTexImage(Display* display, GLXDrawable drawable,
163 int buffer) const {
164 DECL_WRAPPER_SCOPE(display)
165 return mSymbols.fReleaseTexImageEXT(display, drawable, buffer);
168 void fWaitGL() const {
169 DECL_WRAPPER_SCOPE(nullptr)
170 return mSymbols.fWaitGL();
173 void fWaitX() const {
174 DECL_WRAPPER_SCOPE(nullptr)
175 return mSymbols.fWaitX();
178 GLXContext fCreateContextAttribs(Display* display, GLXFBConfig config,
179 GLXContext share_list, Bool direct,
180 const int* attrib_list) const {
181 DECL_WRAPPER_SCOPE(display)
182 return mSymbols.fCreateContextAttribsARB(display, config, share_list,
183 direct, attrib_list);
186 int fGetVideoSync(unsigned int* count) const {
187 DECL_WRAPPER_SCOPE(nullptr)
188 return mSymbols.fGetVideoSyncSGI(count);
191 int fWaitVideoSync(int divisor, int remainder, unsigned int* count) const {
192 DECL_WRAPPER_SCOPE(nullptr)
193 return mSymbols.fWaitVideoSyncSGI(divisor, remainder, count);
196 void fSwapInterval(Display* dpy, GLXDrawable drawable, int interval) const {
197 DECL_WRAPPER_SCOPE(dpy)
198 return mSymbols.fSwapIntervalEXT(dpy, drawable, interval);
201 int fQueryDrawable(Display* dpy, GLXDrawable drawable, int attribute,
202 unsigned int* value) const {
203 DECL_WRAPPER_SCOPE(dpy)
204 return mSymbols.fQueryDrawable(dpy, drawable, attribute, value);
206 #undef DECL_WRAPPER_SCOPE
208 ////
210 bool HasRobustness() { return mHasRobustness; }
211 bool HasVideoMemoryPurge() { return mHasVideoMemoryPurge; }
212 bool HasCreateContextAttribs() { return mHasCreateContextAttribs; }
213 bool SupportsTextureFromPixmap(gfxASurface* aSurface);
214 bool SupportsVideoSync(Display* aDisplay);
215 bool SupportsSwapControl() const { return bool(mSymbols.fSwapIntervalEXT); }
216 bool SupportsBufferAge() const {
217 MOZ_ASSERT(mInitialized);
218 return mHasBufferAge;
220 bool IsATI() { return mIsATI; }
221 bool IsMesa() { return mClientIsMesa; }
223 auto GetGetProcAddress() const { return mSymbols.fGetProcAddress; }
225 std::shared_ptr<gfx::XlibDisplay> GetDisplay();
227 private:
228 struct {
229 void(GLAPIENTRY* fDestroyContext)(Display*, GLXContext);
230 Bool(GLAPIENTRY* fMakeCurrent)(Display*, GLXDrawable, GLXContext);
231 XVisualInfo*(GLAPIENTRY* fGetConfig)(Display*, XVisualInfo*, int, int*);
232 GLXContext(GLAPIENTRY* fGetCurrentContext)();
233 void*(GLAPIENTRY* fGetProcAddress)(const char*);
234 GLXFBConfig*(GLAPIENTRY* fChooseFBConfig)(Display*, int, const int*, int*);
235 XVisualInfo*(GLAPIENTRY* fChooseVisual)(Display*, int, const int*);
236 GLXFBConfig*(GLAPIENTRY* fGetFBConfigs)(Display*, int, int*);
237 GLXContext(GLAPIENTRY* fCreateNewContext)(Display*, GLXFBConfig, int,
238 GLXContext, Bool);
239 int(GLAPIENTRY* fGetFBConfigAttrib)(Display*, GLXFBConfig, int, int*);
240 void(GLAPIENTRY* fSwapBuffers)(Display*, GLXDrawable);
241 const char*(GLAPIENTRY* fQueryExtensionsString)(Display*, int);
242 const char*(GLAPIENTRY* fGetClientString)(Display*, int);
243 const char*(GLAPIENTRY* fQueryServerString)(Display*, int, int);
244 GLXPixmap(GLAPIENTRY* fCreatePixmap)(Display*, GLXFBConfig, Pixmap,
245 const int*);
246 GLXPixmap(GLAPIENTRY* fCreateGLXPixmapWithConfig)(Display*, GLXFBConfig,
247 Pixmap);
248 void(GLAPIENTRY* fDestroyPixmap)(Display*, GLXPixmap);
249 Bool(GLAPIENTRY* fQueryVersion)(Display*, int*, int*);
250 void(GLAPIENTRY* fWaitGL)();
251 void(GLAPIENTRY* fWaitX)();
252 void(GLAPIENTRY* fBindTexImageEXT)(Display*, GLXDrawable, int, const int*);
253 void(GLAPIENTRY* fReleaseTexImageEXT)(Display*, GLXDrawable, int);
254 GLXContext(GLAPIENTRY* fCreateContextAttribsARB)(Display*, GLXFBConfig,
255 GLXContext, Bool,
256 const int*);
257 int(GLAPIENTRY* fGetVideoSyncSGI)(unsigned int*);
258 int(GLAPIENTRY* fWaitVideoSyncSGI)(int, int, unsigned int*);
259 void(GLAPIENTRY* fSwapIntervalEXT)(Display*, GLXDrawable, int);
260 int(GLAPIENTRY* fQueryDrawable)(Display*, GLXDrawable, int, unsigned int*);
261 } mSymbols = {};
263 bool mInitialized = false;
264 bool mTriedInitializing = false;
265 bool mDebug = false;
266 bool mHasRobustness = false;
267 bool mHasVideoMemoryPurge = false;
268 bool mHasCreateContextAttribs = false;
269 bool mHasVideoSync = false;
270 bool mHasBufferAge = false;
271 bool mIsATI = false;
272 bool mIsNVIDIA = false;
273 bool mClientIsMesa = false;
274 PRLibrary* mOGLLibrary = nullptr;
275 StaticDataMutex<std::weak_ptr<gfx::XlibDisplay>> mOwnDisplay{
276 "GLXLibrary::mOwnDisplay"};
279 // a global GLXLibrary instance
280 extern GLXLibrary sGLXLibrary;
282 } /* namespace gl */
283 } /* namespace mozilla */
284 #endif /* GFX_GLXLIBRARY_H */