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"
14 typedef realGLboolean GLboolean
;
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
36 class GLXLibrary final
{
38 bool EnsureInitialized(Display
* aDisplay
);
41 class WrapperScope final
{
42 const GLXLibrary
& mGlx
;
43 const char* const mFuncName
;
44 Display
* const mDisplay
;
47 WrapperScope(const GLXLibrary
& glx
, const char* const funcName
,
54 # define DECL_WRAPPER_SCOPE(display) \
55 const WrapperScope wrapperScope(*this, __func__, display);
57 # define DECL_WRAPPER_SCOPE(display)
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
,
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
,
103 DECL_WRAPPER_SCOPE(display
)
104 return mSymbols
.fCreateNewContext(display
, config
, render_type
, share_list
,
108 int fGetFBConfigAttrib(Display
* display
, GLXFBConfig config
, int attribute
,
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
,
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
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();
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,
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
,
246 GLXPixmap(GLAPIENTRY
* fCreateGLXPixmapWithConfig
)(Display
*, GLXFBConfig
,
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
,
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*);
263 bool mInitialized
= false;
264 bool mTriedInitializing
= false;
266 bool mHasRobustness
= false;
267 bool mHasVideoMemoryPurge
= false;
268 bool mHasCreateContextAttribs
= false;
269 bool mHasVideoSync
= false;
270 bool mHasBufferAge
= 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
;
283 } /* namespace mozilla */
284 #endif /* GFX_GLXLIBRARY_H */