blob: 04d8db16096768eaa086f2d68fc53958efafaa33 [file] [log] [blame]
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001/*
Adam Jacksondc8058c2008-09-19 17:16:53 -04002 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
29 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +000030
31/**
32 * \file glxcmds.c
33 * Client-side GLX interface.
34 */
35
Adam Jacksoncb3610e2004-10-25 21:09:16 +000036#include "glxclient.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000037#include "glapi.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000038#include "glxextensions.h"
Chia-I Wue8c7d752010-12-26 18:24:13 +080039#include "indirect.h"
Ian Romanicked4a65c2011-12-07 16:13:02 -080040#include "glx_error.h"
George Sapountzisdf04ffb2008-04-18 17:28:34 +030041
42#ifdef GLX_DIRECT_RENDERING
Jeremy Huddlestonad503c42010-04-01 11:01:31 -070043#ifdef GLX_USE_APPLEGL
Jon TURNEY5a459a02014-05-12 10:47:07 +010044#include "apple/apple_glx_context.h"
45#include "apple/apple_glx.h"
Jeremy Huddlestonad503c42010-04-01 11:01:31 -070046#else
Adam Jacksoncb3610e2004-10-25 21:09:16 +000047#include <sys/time.h>
Jon TURNEY2b9dac32010-04-21 12:58:54 +010048#ifdef XF86VIDMODE
George Sapountzisdf04ffb2008-04-18 17:28:34 +030049#include <X11/extensions/xf86vmode.h>
Jon TURNEY2b9dac32010-04-21 12:58:54 +010050#endif
Jeremy Huddleston80b280d2010-04-02 01:35:19 -070051#endif
George Sapountzisdf04ffb2008-04-18 17:28:34 +030052#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +000053
RALOVICH, Kristóf9c7aaa72008-11-04 10:59:39 +010054#include <X11/Xlib-xcb.h>
55#include <xcb/xcb.h>
56#include <xcb/glx.h>
RALOVICH, Kristóf9c7aaa72008-11-04 10:59:39 +010057
Ian Romanick26d2ce02009-11-06 14:52:49 -080058static const char __glXGLXClientVendorName[] = "Mesa Project and SGI";
Adam Jacksoncb3610e2004-10-25 21:09:16 +000059static const char __glXGLXClientVersion[] = "1.4";
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050060
Jeremy Huddleston80b280d2010-04-02 01:35:19 -070061#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050062
Adam Jacksoncb3610e2004-10-25 21:09:16 +000063/**
64 * Get the __DRIdrawable for the drawable associated with a GLXContext
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020065 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +000066 * \param dpy The display associated with \c drawable.
67 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050068 * \param scrn_num If non-NULL, the drawables screen is stored there
Adam Jacksoncb3610e2004-10-25 21:09:16 +000069 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
70 * the drawable is not associated with a direct-rendering context.
71 */
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -040072_X_HIDDEN __GLXDRIdrawable *
Kristian Høgsbergeeaab202010-07-22 22:36:37 -040073GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000074{
Kristian Høgsbergc356f582010-07-28 11:16:00 -040075 struct glx_display *priv = __glXInitialize(dpy);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020076 __GLXDRIdrawable *pdraw;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000077
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020078 if (priv == NULL)
79 return NULL;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -040080
Kristian Høgsbergeeaab202010-07-22 22:36:37 -040081 if (__glxHashLookup(priv->drawHash, drawable, (void *) &pdraw) == 0)
Kristian Høgsberge3e81962010-07-19 21:15:50 -040082 return pdraw;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020083
84 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000085}
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050086
Adam Jacksoncb3610e2004-10-25 21:09:16 +000087#endif
88
Jesse Barnes4df13762011-05-06 10:31:24 -070089_X_HIDDEN struct glx_drawable *
90GetGLXDrawable(Display *dpy, GLXDrawable drawable)
91{
92 struct glx_display *priv = __glXInitialize(dpy);
93 struct glx_drawable *glxDraw;
94
95 if (priv == NULL)
96 return NULL;
97
98 if (__glxHashLookup(priv->glXDrawHash, drawable, (void *) &glxDraw) == 0)
99 return glxDraw;
100
101 return NULL;
102}
103
104_X_HIDDEN int
105InitGLXDrawable(Display *dpy, struct glx_drawable *glxDraw, XID xDrawable,
106 GLXDrawable drawable)
107{
108 struct glx_display *priv = __glXInitialize(dpy);
109
110 if (!priv)
111 return -1;
112
113 glxDraw->xDrawable = xDrawable;
114 glxDraw->drawable = drawable;
115 glxDraw->lastEventSbc = 0;
116 glxDraw->eventSbcWrap = 0;
117
118 return __glxHashInsert(priv->glXDrawHash, drawable, glxDraw);
119}
120
121_X_HIDDEN void
122DestroyGLXDrawable(Display *dpy, GLXDrawable drawable)
123{
124 struct glx_display *priv = __glXInitialize(dpy);
125 struct glx_drawable *glxDraw;
126
127 if (!priv)
128 return;
129
130 glxDraw = GetGLXDrawable(dpy, drawable);
131 __glxHashDelete(priv->glXDrawHash, drawable);
132 free(glxDraw);
133}
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000134
135/**
136 * Get the GLX per-screen data structure associated with a GLX context.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200137 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000138 * \param dpy Display for which the GLX per-screen information is to be
139 * retrieved.
140 * \param scrn Screen on \c dpy for which the GLX per-screen information is
141 * to be retrieved.
142 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
143 * specify a valid GLX screen, or NULL otherwise.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200144 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000145 * \todo Should this function validate that \c scrn is within the screen
146 * number range for \c dpy?
147 */
148
Ian Romanick588042a2011-11-30 10:33:37 -0800149_X_HIDDEN struct glx_screen *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200150GetGLXScreenConfigs(Display * dpy, int scrn)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000151{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400152 struct glx_display *const priv = __glXInitialize(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000153
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200154 return (priv
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400155 && priv->screens !=
156 NULL) ? priv->screens[scrn] : NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000157}
158
159
160static int
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400161GetGLXPrivScreenConfig(Display * dpy, int scrn, struct glx_display ** ppriv,
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400162 struct glx_screen ** ppsc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000163{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200164 /* Initialize the extension, if needed . This has the added value
165 * of initializing/allocating the display private
166 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000167
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200168 if (dpy == NULL) {
169 return GLX_NO_EXTENSION;
170 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000171
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200172 *ppriv = __glXInitialize(dpy);
173 if (*ppriv == NULL) {
174 return GLX_NO_EXTENSION;
175 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000176
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200177 /* Check screen number to see if its valid */
178 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
179 return GLX_BAD_SCREEN;
180 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000181
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200182 /* Check to see if the GL is supported on this screen */
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400183 *ppsc = (*ppriv)->screens[scrn];
Dave Airlieb01a3a92013-11-18 17:34:52 +1000184 if ((*ppsc)->configs == NULL && (*ppsc)->visuals == NULL) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200185 /* No support for GL on this screen regardless of visual */
186 return GLX_BAD_VISUAL;
187 }
188
189 return Success;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000190}
191
192
193/**
194 * Determine if a \c GLXFBConfig supplied by the application is valid.
195 *
196 * \param dpy Application supplied \c Display pointer.
197 * \param config Application supplied \c GLXFBConfig.
198 *
199 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400200 * \c struct glx_config structure is returned. Otherwise, \c NULL
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000201 * is returned.
202 */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400203static struct glx_config *
204ValidateGLXFBConfig(Display * dpy, GLXFBConfig fbconfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000205{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400206 struct glx_display *const priv = __glXInitialize(dpy);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400207 int num_screens = ScreenCount(dpy);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200208 unsigned i;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400209 struct glx_config *config;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000210
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200211 if (priv != NULL) {
212 for (i = 0; i < num_screens; i++) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400213 for (config = priv->screens[i]->configs; config != NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400214 config = config->next) {
215 if (config == (struct glx_config *) fbconfig) {
216 return config;
217 }
218 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200219 }
220 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000221
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200222 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000223}
224
Tomasz Lis2eed9ff2013-07-18 14:19:38 -0700225/**
226 * Verifies context's GLX_RENDER_TYPE value with config.
227 *
228 * \param config GLX FBConfig which will support the returned renderType.
229 * \param renderType The context render type to be verified.
230 * \return True if the value of context renderType was approved, or 0 if no
231 * valid value was found.
232 */
233Bool
234validate_renderType_against_config(const struct glx_config *config,
235 int renderType)
236{
237 switch (renderType) {
238 case GLX_RGBA_TYPE:
239 return (config->renderType & GLX_RGBA_BIT) != 0;
240 case GLX_COLOR_INDEX_TYPE:
241 return (config->renderType & GLX_COLOR_INDEX_BIT) != 0;
242 case GLX_RGBA_FLOAT_TYPE_ARB:
243 return (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) != 0;
244 case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT:
245 return (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) != 0;
246 default:
247 break;
248 }
249 return 0;
250}
251
Kristian Høgsberg31819832010-07-22 21:24:14 -0400252_X_HIDDEN Bool
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400253glx_context_init(struct glx_context *gc,
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400254 struct glx_screen *psc, struct glx_config *config)
Kristian Høgsberg31819832010-07-22 21:24:14 -0400255{
256 gc->majorOpcode = __glXSetupForCommand(psc->display->dpy);
257 if (!gc->majorOpcode)
Brian Paul482c43a2013-06-26 13:42:51 -0600258 return False;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400259
260 gc->screen = psc->scr;
261 gc->psc = psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400262 gc->config = config;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400263 gc->isDirect = GL_TRUE;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400264 gc->currentContextTag = -1;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400265
Brian Paul482c43a2013-06-26 13:42:51 -0600266 return True;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400267}
268
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000269
270/**
Adam Jackson3869be72011-04-29 16:30:50 -0400271 * Create a new context.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200272 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000273 * \param renderType For FBConfigs, what is the rendering type?
274 */
275
276static GLXContext
Adam Jackson3869be72011-04-29 16:30:50 -0400277CreateContext(Display *dpy, int generic_id, struct glx_config *config,
278 GLXContext shareList_user, Bool allowDirect,
Ian Romanick7bcfb662010-02-04 16:37:59 -0800279 unsigned code, int renderType, int screen)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000280{
nobledb5dc4072010-08-19 14:06:21 -0400281 struct glx_context *gc;
282 struct glx_screen *psc;
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400283 struct glx_context *shareList = (struct glx_context *) shareList_user;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200284 if (dpy == NULL)
285 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000286
nobledb5dc4072010-08-19 14:06:21 -0400287 psc = GetGLXScreenConfigs(dpy, screen);
288 if (psc == NULL)
289 return NULL;
290
Ian Romanickd46d30f2010-02-04 17:06:18 -0800291 if (generic_id == None)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200292 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000293
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -0400294 gc = NULL;
Jeremy Huddleston1885cf22011-06-05 18:50:55 -0400295#ifdef GLX_USE_APPLEGL
296 gc = applegl_create_context(psc, config, shareList, renderType);
297#else
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -0400298 if (allowDirect && psc->vtable->create_context)
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400299 gc = psc->vtable->create_context(psc, config, shareList, renderType);
Kristian Høgsberg31819832010-07-22 21:24:14 -0400300 if (!gc)
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400301 gc = indirect_create_context(psc, config, shareList, renderType);
Jeremy Huddleston1885cf22011-06-05 18:50:55 -0400302#endif
Kristian Høgsberg31819832010-07-22 21:24:14 -0400303 if (!gc)
304 return NULL;
Kristian Høgsberg643b2af2010-05-21 10:36:56 -0400305
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800306 LockDisplay(dpy);
307 switch (code) {
308 case X_GLXCreateContext: {
309 xGLXCreateContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000310
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800311 /* Send the glXCreateContext request */
312 GetReq(GLXCreateContext, req);
313 req->reqType = gc->majorOpcode;
314 req->glxCode = X_GLXCreateContext;
315 req->context = gc->xid = XAllocID(dpy);
Ian Romanickd46d30f2010-02-04 17:06:18 -0800316 req->visual = generic_id;
Ian Romanickc3db1d62010-02-04 17:01:42 -0800317 req->screen = screen;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800318 req->shareList = shareList ? shareList->xid : None;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400319 req->isDirect = gc->isDirect;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800320 break;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200321 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000322
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800323 case X_GLXCreateNewContext: {
324 xGLXCreateNewContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000325
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800326 /* Send the glXCreateNewContext request */
327 GetReq(GLXCreateNewContext, req);
328 req->reqType = gc->majorOpcode;
329 req->glxCode = X_GLXCreateNewContext;
330 req->context = gc->xid = XAllocID(dpy);
Ian Romanickd46d30f2010-02-04 17:06:18 -0800331 req->fbconfig = generic_id;
Ian Romanickc3db1d62010-02-04 17:01:42 -0800332 req->screen = screen;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800333 req->renderType = renderType;
334 req->shareList = shareList ? shareList->xid : None;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400335 req->isDirect = gc->isDirect;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800336 break;
337 }
Ian Romanick8bffadb2010-02-04 16:28:52 -0800338
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800339 case X_GLXvop_CreateContextWithConfigSGIX: {
340 xGLXVendorPrivateWithReplyReq *vpreq;
341 xGLXCreateContextWithConfigSGIXReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000342
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800343 /* Send the glXCreateNewContext request */
344 GetReqExtra(GLXVendorPrivateWithReply,
345 sz_xGLXCreateContextWithConfigSGIXReq -
346 sz_xGLXVendorPrivateWithReplyReq, vpreq);
347 req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
348 req->reqType = gc->majorOpcode;
349 req->glxCode = X_GLXVendorPrivateWithReply;
350 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
351 req->context = gc->xid = XAllocID(dpy);
Ian Romanickd46d30f2010-02-04 17:06:18 -0800352 req->fbconfig = generic_id;
Ian Romanickc3db1d62010-02-04 17:01:42 -0800353 req->screen = screen;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800354 req->renderType = renderType;
355 req->shareList = shareList ? shareList->xid : None;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400356 req->isDirect = gc->isDirect;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800357 break;
358 }
Ian Romanick8bffadb2010-02-04 16:28:52 -0800359
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800360 default:
361 /* What to do here? This case is the sign of an internal error. It
362 * should never be reachable.
363 */
364 break;
365 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000366
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800367 UnlockDisplay(dpy);
368 SyncHandle();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000369
Ian Romanicka832aa52011-12-08 15:03:19 -0800370 gc->share_xid = shareList ? shareList->xid : None;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800371 gc->imported = GL_FALSE;
Brian Paul521e4b92009-09-29 10:24:27 -0600372
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400373 return (GLXContext) gc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000374}
375
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400376_X_EXPORT GLXContext
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200377glXCreateContext(Display * dpy, XVisualInfo * vis,
378 GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000379{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400380 struct glx_config *config = NULL;
Tomasz Lis36259a12013-07-17 13:49:14 +0200381 int renderType = GLX_RGBA_TYPE;
Ian Romanick52cf8db2010-02-04 16:59:10 -0800382
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700383#if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400384 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, vis->screen);
Ian Romanick52cf8db2010-02-04 16:59:10 -0800385
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +0200386 if (psc)
387 config = glx_config_find_visual(psc->visuals, vis->visualid);
388
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400389 if (config == NULL) {
Ian Romanick52cf8db2010-02-04 16:59:10 -0800390 xError error;
391
392 error.errorCode = BadValue;
393 error.resourceID = vis->visualid;
394 error.sequenceNumber = dpy->request;
395 error.type = X_Error;
396 error.majorCode = __glXSetupForCommand(dpy);
397 error.minorCode = X_GLXCreateContext;
398 _XError(dpy, &error);
399 return None;
400 }
401
Tomasz Lis1c748df2013-07-17 13:49:17 +0200402 /* Choose the context render type based on DRI config values. It is
403 * unusual to set this type from config, but we have no other choice, as
404 * this old API does not provide renderType parameter.
405 */
406 if (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) {
407 renderType = GLX_RGBA_FLOAT_TYPE_ARB;
408 } else if (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) {
409 renderType = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
410 } else if (config->renderType & GLX_RGBA_BIT) {
411 renderType = GLX_RGBA_TYPE;
412 } else if (config->renderType & GLX_COLOR_INDEX_BIT) {
413 renderType = GLX_COLOR_INDEX_TYPE;
414 } else if (config->rgbMode) {
415 /* If we're here, then renderType is not set correctly. Let's use a
416 * safeguard - any TrueColor or DirectColor mode is RGB mode. Such
417 * default value is needed by old DRI drivers, which didn't set
418 * renderType correctly as the value was just ignored.
419 */
420 renderType = GLX_RGBA_TYPE;
421 } else {
422 /* Safeguard - only one option left, all non-RGB modes are indexed
423 * modes. Again, this allows drivers with invalid renderType to work
424 * properly.
425 */
426 renderType = GLX_COLOR_INDEX_TYPE;
427 }
Ian Romanick52cf8db2010-02-04 16:59:10 -0800428#endif
429
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400430 return CreateContext(dpy, vis->visualid, config, shareList, allowDirect,
Ian Romanick52cf8db2010-02-04 16:59:10 -0800431 X_GLXCreateContext, renderType, vis->screen);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000432}
433
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800434static void
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400435glx_send_destroy_context(Display *dpy, XID xid)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000436{
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400437 CARD8 opcode = __glXSetupForCommand(dpy);
438 xGLXDestroyContextReq *req;
439
440 LockDisplay(dpy);
441 GetReq(GLXDestroyContext, req);
442 req->reqType = opcode;
443 req->glxCode = X_GLXDestroyContext;
444 req->context = xid;
445 UnlockDisplay(dpy);
446 SyncHandle();
447}
448
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000449/*
450** Destroy the named context
451*/
Adam Jackson9e2bc5d2011-06-02 16:29:59 -0400452
453_X_EXPORT void
454glXDestroyContext(Display * dpy, GLXContext ctx)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000455{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400456 struct glx_context *gc = (struct glx_context *) ctx;
457
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800458 if (gc == NULL || gc->xid == None)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200459 return;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000460
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200461 __glXLock();
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800462 if (!gc->imported)
463 glx_send_destroy_context(dpy, gc->xid);
464
Brian Paul5e6a6a22009-10-22 18:19:01 -0600465 if (gc->currentDpy) {
466 /* This context is bound to some thread. According to the man page,
467 * we should not actually delete the context until it's unbound.
468 * Note that we set gc->xid = None above. In MakeContextCurrent()
469 * we check for that and delete the context there.
470 */
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400471 gc->xid = None;
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800472 } else {
473 gc->vtable->destroy(gc);
Brian Paul5e6a6a22009-10-22 18:19:01 -0600474 }
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400475 __glXUnlock();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000476}
Adam Jackson489ccef2004-12-15 17:18:06 +0000477
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000478/*
479** Return the major and minor version #s for the GLX extension
480*/
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400481_X_EXPORT Bool
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200482glXQueryVersion(Display * dpy, int *major, int *minor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000483{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400484 struct glx_display *priv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000485
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200486 /* Init the extension. This fetches the major and minor version. */
487 priv = __glXInitialize(dpy);
488 if (!priv)
Brian Paul482c43a2013-06-26 13:42:51 -0600489 return False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000490
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200491 if (major)
492 *major = priv->majorVersion;
493 if (minor)
494 *minor = priv->minorVersion;
Brian Paul482c43a2013-06-26 13:42:51 -0600495 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000496}
497
498/*
499** Query the existance of the GLX extension
500*/
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400501_X_EXPORT Bool
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200502glXQueryExtension(Display * dpy, int *errorBase, int *eventBase)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000503{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200504 int major_op, erb, evb;
505 Bool rv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000506
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200507 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
508 if (rv) {
509 if (errorBase)
510 *errorBase = erb;
511 if (eventBase)
512 *eventBase = evb;
513 }
514 return rv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000515}
516
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400517/*
518** Put a barrier in the token stream that forces the GL to finish its
519** work before X can proceed.
520*/
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400521_X_EXPORT void
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400522glXWaitGL(void)
523{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400524 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400525
Kristian Høgsberg3ea3f5e2010-09-07 14:32:28 -0400526 if (gc && gc->vtable->wait_gl)
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400527 gc->vtable->wait_gl(gc);
528}
529
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000530/*
531** Put a barrier in the token stream that forces X to finish its
532** work before GL can proceed.
533*/
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400534_X_EXPORT void
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200535glXWaitX(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000536{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400537 struct glx_context *gc = __glXGetCurrentContext();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000538
Kristian Høgsberg3ea3f5e2010-09-07 14:32:28 -0400539 if (gc && gc->vtable->wait_x)
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400540 gc->vtable->wait_x(gc);
541}
542
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400543_X_EXPORT void
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400544glXUseXFont(Font font, int first, int count, int listBase)
545{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400546 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400547
Kristian Høgsberg3ea3f5e2010-09-07 14:32:28 -0400548 if (gc && gc->vtable->use_x_font)
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400549 gc->vtable->use_x_font(gc, font, first, count, listBase);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000550}
551
552/************************************************************************/
553
554/*
555** Copy the source context to the destination context using the
556** attribute "mask".
557*/
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400558_X_EXPORT void
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400559glXCopyContext(Display * dpy, GLXContext source_user,
560 GLXContext dest_user, unsigned long mask)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000561{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400562 struct glx_context *source = (struct glx_context *) source_user;
563 struct glx_context *dest = (struct glx_context *) dest_user;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700564#ifdef GLX_USE_APPLEGL
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400565 struct glx_context *gc = __glXGetCurrentContext();
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700566 int errorcode;
567 bool x11error;
568
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700569 if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext,
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700570 mask, &errorcode, &x11error)) {
571 __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
572 }
573
574#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200575 xGLXCopyContextReq *req;
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400576 struct glx_context *gc = __glXGetCurrentContext();
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200577 GLXContextTag tag;
578 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000579
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200580 opcode = __glXSetupForCommand(dpy);
581 if (!opcode) {
582 return;
583 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000584
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700585#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400586 if (gc->isDirect) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200587 /* NOT_DONE: This does not work yet */
588 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000589#endif
590
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200591 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000592 ** If the source is the current context, send its tag so that the context
593 ** can be flushed before the copy.
594 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200595 if (source == gc && dpy == gc->currentDpy) {
596 tag = gc->currentContextTag;
597 }
598 else {
599 tag = 0;
600 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000601
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200602 /* Send the glXCopyContext request */
603 LockDisplay(dpy);
604 GetReq(GLXCopyContext, req);
605 req->reqType = opcode;
606 req->glxCode = X_GLXCopyContext;
607 req->source = source ? source->xid : None;
608 req->dest = dest ? dest->xid : None;
609 req->mask = mask;
610 req->contextTag = tag;
611 UnlockDisplay(dpy);
612 SyncHandle();
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700613#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000614}
615
616
617/**
618 * Determine if a context uses direct rendering.
619 *
620 * \param dpy Display where the context was created.
621 * \param contextID ID of the context to be tested.
622 *
Brian Paul482c43a2013-06-26 13:42:51 -0600623 * \returns \c True if the context is direct rendering or not.
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000624 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200625static Bool
626__glXIsDirect(Display * dpy, GLXContextID contextID)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000627{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200628 CARD8 opcode;
Brian Pauld171bc92013-06-26 13:38:18 -0600629 xcb_connection_t *c;
630 xcb_generic_error_t *err;
631 xcb_glx_is_direct_reply_t *reply;
632 Bool is_direct;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000633
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200634 opcode = __glXSetupForCommand(dpy);
635 if (!opcode) {
Brian Paul482c43a2013-06-26 13:42:51 -0600636 return False;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200637 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000638
Brian Pauld171bc92013-06-26 13:38:18 -0600639 c = XGetXCBConnection(dpy);
640 reply = xcb_glx_is_direct_reply(c, xcb_glx_is_direct(c, contextID), &err);
641 is_direct = (reply != NULL && reply->is_direct) ? True : False;
Ian Romanicked4a65c2011-12-07 16:13:02 -0800642
643 if (err != NULL) {
644 __glXSendErrorForXcb(dpy, err);
645 free(err);
646 }
647
RALOVICH, Kristóf9c7aaa72008-11-04 10:59:39 +0100648 free(reply);
649
650 return is_direct;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000651}
652
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000653/**
654 * \todo
Brian Paul482c43a2013-06-26 13:42:51 -0600655 * Shouldn't this function \b always return \c False when
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000656 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
657 * the GLX protocol here at all?
658 */
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400659_X_EXPORT Bool
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400660glXIsDirect(Display * dpy, GLXContext gc_user)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000661{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400662 struct glx_context *gc = (struct glx_context *) gc_user;
663
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200664 if (!gc) {
Brian Paul482c43a2013-06-26 13:42:51 -0600665 return False;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200666 }
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400667 else if (gc->isDirect) {
Brian Paul482c43a2013-06-26 13:42:51 -0600668 return True;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200669 }
Jeremy Huddlestona18702f2010-05-01 13:59:30 -0700670#ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
Brian Paul482c43a2013-06-26 13:42:51 -0600671 return False;
Jeremy Huddlestona18702f2010-05-01 13:59:30 -0700672#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200673 return __glXIsDirect(dpy, gc->xid);
Jeremy Huddlestona18702f2010-05-01 13:59:30 -0700674#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000675}
676
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400677_X_EXPORT GLXPixmap
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200678glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000679{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700680#ifdef GLX_USE_APPLEGL
681 int screen = vis->screen;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400682 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, screen);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400683 const struct glx_config *config;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700684
Jeremy Huddlestonb7f0ed82011-06-05 18:19:59 -0400685 config = glx_config_find_visual(psc->visuals, vis->visualid);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700686
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400687 if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, config))
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700688 return None;
689
690 return pixmap;
691#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200692 xGLXCreateGLXPixmapReq *req;
Jesse Barnes4df13762011-05-06 10:31:24 -0700693 struct glx_drawable *glxDraw;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200694 GLXPixmap xid;
695 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000696
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +0200697#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
698 struct glx_display *const priv = __glXInitialize(dpy);
699
700 if (priv == NULL)
701 return None;
702#endif
703
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200704 opcode = __glXSetupForCommand(dpy);
705 if (!opcode) {
706 return None;
707 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000708
Matt Turner7c7b7b02012-09-04 22:52:36 -0700709 glxDraw = malloc(sizeof(*glxDraw));
Jesse Barnes4df13762011-05-06 10:31:24 -0700710 if (!glxDraw)
711 return None;
712
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200713 /* Send the glXCreateGLXPixmap request */
714 LockDisplay(dpy);
715 GetReq(GLXCreateGLXPixmap, req);
716 req->reqType = opcode;
717 req->glxCode = X_GLXCreateGLXPixmap;
718 req->screen = vis->screen;
719 req->visual = vis->visualid;
720 req->pixmap = pixmap;
721 req->glxpixmap = xid = XAllocID(dpy);
722 UnlockDisplay(dpy);
723 SyncHandle();
Michel Dänzeredb11782009-08-30 12:43:37 +0200724
Jesse Barnes4df13762011-05-06 10:31:24 -0700725 if (InitGLXDrawable(dpy, glxDraw, pixmap, req->glxpixmap)) {
726 free(glxDraw);
727 return None;
728 }
729
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700730#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Michel Dänzer9053bb02009-08-30 13:06:18 +0200731 do {
732 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
733 * is actually bound to a context... */
Michel Dänzeredb11782009-08-30 12:43:37 +0200734
Michel Dänzer9053bb02009-08-30 13:06:18 +0200735 __GLXDRIdrawable *pdraw;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400736 struct glx_screen *psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400737 struct glx_config *config;
Michel Dänzeredb11782009-08-30 12:43:37 +0200738
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400739 psc = priv->screens[vis->screen];
Michel Dänzer9053bb02009-08-30 13:06:18 +0200740 if (psc->driScreen == NULL)
Adam Jackson48331042011-03-31 20:43:57 +0000741 return xid;
742
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400743 config = glx_config_find_visual(psc->visuals, vis->visualid);
Adam Jackson776a2a52011-06-01 11:33:48 -0400744 pdraw = psc->driScreen->createDrawable(psc, pixmap, xid, config);
Michel Dänzer9053bb02009-08-30 13:06:18 +0200745 if (pdraw == NULL) {
746 fprintf(stderr, "failed to create pixmap\n");
Adam Jackson48331042011-03-31 20:43:57 +0000747 xid = None;
Michel Dänzer9053bb02009-08-30 13:06:18 +0200748 break;
749 }
Michel Dänzeredb11782009-08-30 12:43:37 +0200750
Adam Jackson776a2a52011-06-01 11:33:48 -0400751 if (__glxHashInsert(priv->drawHash, xid, pdraw)) {
Michel Dänzer9053bb02009-08-30 13:06:18 +0200752 (*pdraw->destroyDrawable) (pdraw);
Adam Jackson48331042011-03-31 20:43:57 +0000753 xid = None;
754 break;
Michel Dänzer9053bb02009-08-30 13:06:18 +0200755 }
756 } while (0);
Adam Jackson48331042011-03-31 20:43:57 +0000757
758 if (xid == None) {
759 xGLXDestroyGLXPixmapReq *dreq;
760 LockDisplay(dpy);
761 GetReq(GLXDestroyGLXPixmap, dreq);
762 dreq->reqType = opcode;
763 dreq->glxCode = X_GLXDestroyGLXPixmap;
764 dreq->glxpixmap = xid;
765 UnlockDisplay(dpy);
766 SyncHandle();
767 }
Michel Dänzeredb11782009-08-30 12:43:37 +0200768#endif
769
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200770 return xid;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700771#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000772}
773
774/*
775** Destroy the named pixmap
776*/
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400777_X_EXPORT void
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200778glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000779{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700780#ifdef GLX_USE_APPLEGL
781 if(apple_glx_pixmap_destroy(dpy, glxpixmap))
782 __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false);
783#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200784 xGLXDestroyGLXPixmapReq *req;
785 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000786
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200787 opcode = __glXSetupForCommand(dpy);
788 if (!opcode) {
789 return;
790 }
791
792 /* Send the glXDestroyGLXPixmap request */
793 LockDisplay(dpy);
794 GetReq(GLXDestroyGLXPixmap, req);
795 req->reqType = opcode;
796 req->glxCode = X_GLXDestroyGLXPixmap;
797 req->glxpixmap = glxpixmap;
798 UnlockDisplay(dpy);
799 SyncHandle();
Michel Dänzer9dfce362009-06-19 11:19:07 +0200800
Jesse Barnes4df13762011-05-06 10:31:24 -0700801 DestroyGLXDrawable(dpy, glxpixmap);
802
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700803#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200804 {
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400805 struct glx_display *const priv = __glXInitialize(dpy);
Kristian Høgsbergeeaab202010-07-22 22:36:37 -0400806 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap);
Michel Dänzer9dfce362009-06-19 11:19:07 +0200807
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +0200808 if (priv != NULL && pdraw != NULL) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200809 (*pdraw->destroyDrawable) (pdraw);
Kristian Høgsberge3e81962010-07-19 21:15:50 -0400810 __glxHashDelete(priv->drawHash, glxpixmap);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200811 }
812 }
Michel Dänzer9dfce362009-06-19 11:19:07 +0200813#endif
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700814#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000815}
816
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400817_X_EXPORT void
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200818glXSwapBuffers(Display * dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000819{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700820#ifdef GLX_USE_APPLEGL
Jeremy Huddleston279e4712011-06-05 18:22:47 -0400821 struct glx_context * gc = __glXGetCurrentContext();
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700822 if(gc && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) {
823 apple_glx_swap_buffers(gc->driContext);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700824 } else {
825 __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
826 }
827#else
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400828 struct glx_context *gc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200829 GLXContextTag tag;
830 CARD8 opcode;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200831 xcb_connection_t *c;
Brian Paulb7f802e2009-01-18 09:59:07 -0700832
Eric Anholt4d01bea2011-02-14 18:38:33 -0800833 gc = __glXGetCurrentContext();
834
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700835#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Brian Paule975e182011-08-19 08:36:22 -0600836 {
837 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000838
Brian Paule975e182011-08-19 08:36:22 -0600839 if (pdraw != NULL) {
Marek Olšák5b7e9b72012-11-13 17:06:37 +0100840 Bool flush = gc && drawable == gc->currentDrawable;
Brian Paule975e182011-08-19 08:36:22 -0600841
Marek Olšák5b7e9b72012-11-13 17:06:37 +0100842 (*pdraw->psc->driScreen->swapBuffers)(pdraw, 0, 0, 0, flush);
Brian Paule975e182011-08-19 08:36:22 -0600843 return;
Eric Anholt4d01bea2011-02-14 18:38:33 -0800844 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200845 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000846#endif
847
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200848 opcode = __glXSetupForCommand(dpy);
849 if (!opcode) {
850 return;
851 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000852
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200853 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000854 ** The calling thread may or may not have a current context. If it
855 ** does, send the context tag so the server can do a flush.
856 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200857 if ((gc != NULL) && (dpy == gc->currentDpy) &&
858 ((drawable == gc->currentDrawable)
859 || (drawable == gc->currentReadable))) {
860 tag = gc->currentContextTag;
861 }
862 else {
863 tag = 0;
864 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000865
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200866 c = XGetXCBConnection(dpy);
867 xcb_glx_swap_buffers(c, tag, drawable);
868 xcb_flush(c);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700869#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000870}
871
872
873/*
874** Return configuration information for the given display, screen and
875** visual combination.
876*/
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400877_X_EXPORT int
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200878glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute,
879 int *value_return)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000880{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400881 struct glx_display *priv;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400882 struct glx_screen *psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400883 struct glx_config *config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200884 int status;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000885
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200886 status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc);
887 if (status == Success) {
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400888 config = glx_config_find_visual(psc->visuals, vis->visualid);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000889
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200890 /* Lookup attribute after first finding a match on the visual */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400891 if (config != NULL) {
892 return glx_config_get(config, attribute, value_return);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200893 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000894
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200895 status = GLX_BAD_VISUAL;
896 }
897
898 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000899 ** If we can't find the config for this visual, this visual is not
900 ** supported by the OpenGL implementation on the server.
901 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200902 if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) {
Brian Paul482c43a2013-06-26 13:42:51 -0600903 *value_return = False;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200904 status = Success;
905 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000906
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200907 return status;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000908}
909
910/************************************************************************/
911
912static void
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400913init_fbconfig_for_chooser(struct glx_config * config,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200914 GLboolean fbconfig_style_tags)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000915{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400916 memset(config, 0, sizeof(struct glx_config));
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200917 config->visualID = (XID) GLX_DONT_CARE;
918 config->visualType = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000919
Tomasz Lis4473af72013-07-17 13:49:20 +0200920 /* glXChooseFBConfig specifies different defaults for these properties than
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200921 * glXChooseVisual.
922 */
923 if (fbconfig_style_tags) {
924 config->rgbMode = GL_TRUE;
925 config->doubleBufferMode = GLX_DONT_CARE;
Fredrik Höglundf41c2f62014-02-13 21:07:09 +0100926 config->renderType = GLX_RGBA_BIT;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200927 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000928
Fredrik Höglundf41c2f62014-02-13 21:07:09 +0100929 config->drawableType = GLX_WINDOW_BIT;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200930 config->visualRating = GLX_DONT_CARE;
931 config->transparentPixel = GLX_NONE;
932 config->transparentRed = GLX_DONT_CARE;
933 config->transparentGreen = GLX_DONT_CARE;
934 config->transparentBlue = GLX_DONT_CARE;
935 config->transparentAlpha = GLX_DONT_CARE;
936 config->transparentIndex = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000937
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200938 config->xRenderable = GLX_DONT_CARE;
939 config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000940
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200941 config->swapMethod = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000942}
943
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200944#define MATCH_DONT_CARE( param ) \
945 do { \
Ian Romanick71a6fb12010-02-04 15:59:51 -0800946 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200947 && (a-> param != b-> param) ) { \
948 return False; \
949 } \
950 } while ( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000951
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200952#define MATCH_MINIMUM( param ) \
953 do { \
Ian Romanick71a6fb12010-02-04 15:59:51 -0800954 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200955 && (a-> param > b-> param) ) { \
956 return False; \
957 } \
958 } while ( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000959
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200960#define MATCH_EXACT( param ) \
961 do { \
962 if ( a-> param != b-> param) { \
963 return False; \
964 } \
965 } while ( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000966
Kristian Høgsbergedb52532010-04-08 22:09:11 -0400967/* Test that all bits from a are contained in b */
968#define MATCH_MASK(param) \
969 do { \
Alexander Monakov9cda3562013-04-02 01:38:27 +0400970 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
971 && ((a->param & ~b->param) != 0) ) { \
Kristian Høgsbergedb52532010-04-08 22:09:11 -0400972 return False; \
Alexander Monakov9cda3562013-04-02 01:38:27 +0400973 } \
Kristian Høgsbergedb52532010-04-08 22:09:11 -0400974 } while (0);
975
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000976/**
977 * Determine if two GLXFBConfigs are compatible.
978 *
979 * \param a Application specified config to test.
980 * \param b Server specified config to test against \c a.
981 */
982static Bool
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400983fbconfigs_compatible(const struct glx_config * const a,
984 const struct glx_config * const b)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000985{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200986 MATCH_DONT_CARE(doubleBufferMode);
987 MATCH_DONT_CARE(visualType);
988 MATCH_DONT_CARE(visualRating);
989 MATCH_DONT_CARE(xRenderable);
990 MATCH_DONT_CARE(fbconfigID);
991 MATCH_DONT_CARE(swapMethod);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000992
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200993 MATCH_MINIMUM(rgbBits);
994 MATCH_MINIMUM(numAuxBuffers);
995 MATCH_MINIMUM(redBits);
996 MATCH_MINIMUM(greenBits);
997 MATCH_MINIMUM(blueBits);
998 MATCH_MINIMUM(alphaBits);
999 MATCH_MINIMUM(depthBits);
1000 MATCH_MINIMUM(stencilBits);
1001 MATCH_MINIMUM(accumRedBits);
1002 MATCH_MINIMUM(accumGreenBits);
1003 MATCH_MINIMUM(accumBlueBits);
1004 MATCH_MINIMUM(accumAlphaBits);
1005 MATCH_MINIMUM(sampleBuffers);
1006 MATCH_MINIMUM(maxPbufferWidth);
1007 MATCH_MINIMUM(maxPbufferHeight);
1008 MATCH_MINIMUM(maxPbufferPixels);
1009 MATCH_MINIMUM(samples);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001010
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001011 MATCH_DONT_CARE(stereoMode);
1012 MATCH_EXACT(level);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001013
Kristian Høgsbergedb52532010-04-08 22:09:11 -04001014 MATCH_MASK(drawableType);
1015 MATCH_MASK(renderType);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001016
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001017 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1018 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1019 * Technically speaking, it is a bug in the DDX driver, but there is
1020 * enough of an installed base to work around the problem here. In any
1021 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1022 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1023 * 0 from the server to be a match to maintain backward compatibility with
1024 * the (broken) drivers.
1025 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001026
Ian Romanick71a6fb12010-02-04 15:59:51 -08001027 if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001028 if (a->transparentPixel == GLX_NONE) {
1029 if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0)
1030 return False;
1031 }
1032 else {
1033 MATCH_EXACT(transparentPixel);
1034 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001035
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001036 switch (a->transparentPixel) {
1037 case GLX_TRANSPARENT_RGB:
1038 MATCH_DONT_CARE(transparentRed);
1039 MATCH_DONT_CARE(transparentGreen);
1040 MATCH_DONT_CARE(transparentBlue);
1041 MATCH_DONT_CARE(transparentAlpha);
1042 break;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001043
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001044 case GLX_TRANSPARENT_INDEX:
1045 MATCH_DONT_CARE(transparentIndex);
1046 break;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001047
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001048 default:
1049 break;
1050 }
1051 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001052
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001053 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001054}
1055
1056
1057/* There's some trickly language in the GLX spec about how this is supposed
1058 * to work. Basically, if a given component size is either not specified
1059 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1060 * Well, that's really hard to do with the code as-is. This behavior is
1061 * closer to correct, but still not technically right.
1062 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001063#define PREFER_LARGER_OR_ZERO(comp) \
1064 do { \
1065 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1066 if ( ((*a)-> comp) == 0 ) { \
1067 return -1; \
1068 } \
1069 else if ( ((*b)-> comp) == 0 ) { \
1070 return 1; \
1071 } \
1072 else { \
1073 return ((*b)-> comp) - ((*a)-> comp) ; \
1074 } \
1075 } \
1076 } while( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001077
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001078#define PREFER_LARGER(comp) \
1079 do { \
1080 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1081 return ((*b)-> comp) - ((*a)-> comp) ; \
1082 } \
1083 } while( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001084
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001085#define PREFER_SMALLER(comp) \
1086 do { \
1087 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1088 return ((*a)-> comp) - ((*b)-> comp) ; \
1089 } \
1090 } while( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001091
1092/**
1093 * Compare two GLXFBConfigs. This function is intended to be used as the
1094 * compare function passed in to qsort.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001095 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001096 * \returns If \c a is a "better" config, according to the specification of
1097 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1098 * better, then a number greater than zero is return. If both are
1099 * equal, zero is returned.
1100 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1101 */
1102static int
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001103fbconfig_compare(struct glx_config **a, struct glx_config **b)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001104{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001105 /* The order of these comparisons must NOT change. It is defined by
Fredrik Höglund3616e862014-02-15 18:48:40 +01001106 * the GLX 1.4 specification.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001107 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001108
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001109 PREFER_SMALLER(visualSelectGroup);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001110
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001111 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1112 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1113 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1114 */
1115 PREFER_SMALLER(visualRating);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001116
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001117 /* This isn't quite right. It is supposed to compare the sum of the
1118 * components the user specifically set minimums for.
1119 */
1120 PREFER_LARGER_OR_ZERO(redBits);
1121 PREFER_LARGER_OR_ZERO(greenBits);
1122 PREFER_LARGER_OR_ZERO(blueBits);
1123 PREFER_LARGER_OR_ZERO(alphaBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001124
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001125 PREFER_SMALLER(rgbBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001126
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001127 if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) {
1128 /* Prefer single-buffer.
1129 */
1130 return (!(*a)->doubleBufferMode) ? -1 : 1;
1131 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001132
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001133 PREFER_SMALLER(numAuxBuffers);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001134
Fredrik Höglund3616e862014-02-15 18:48:40 +01001135 PREFER_SMALLER(sampleBuffers);
1136 PREFER_SMALLER(samples);
1137
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001138 PREFER_LARGER_OR_ZERO(depthBits);
1139 PREFER_SMALLER(stencilBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001140
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001141 /* This isn't quite right. It is supposed to compare the sum of the
1142 * components the user specifically set minimums for.
1143 */
1144 PREFER_LARGER_OR_ZERO(accumRedBits);
1145 PREFER_LARGER_OR_ZERO(accumGreenBits);
1146 PREFER_LARGER_OR_ZERO(accumBlueBits);
1147 PREFER_LARGER_OR_ZERO(accumAlphaBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001148
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001149 PREFER_SMALLER(visualType);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001150
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001151 /* None of the pbuffer or fbconfig specs say that this comparison needs
1152 * to happen at all, but it seems like it should.
1153 */
1154 PREFER_LARGER(maxPbufferWidth);
1155 PREFER_LARGER(maxPbufferHeight);
1156 PREFER_LARGER(maxPbufferPixels);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001157
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001158 return 0;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001159}
1160
1161
1162/**
1163 * Selects and sorts a subset of the supplied configs based on the attributes.
1164 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1165 * and \c glXChooseFBConfigSGIX.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001166 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001167 * \param configs Array of pointers to possible configs. The elements of
1168 * this array that do not meet the criteria will be set to
1169 * NULL. The remaining elements will be sorted according to
1170 * the various visual / FBConfig selection rules.
1171 * \param num_configs Number of elements in the \c configs array.
1172 * \param attribList Attributes used select from \c configs. This array is
1173 * terminated by a \c None tag. The array can either take
1174 * the form expected by \c glXChooseVisual (where boolean
1175 * tags do not have a value) or by \c glXChooseFBConfig
1176 * (where every tag has a value).
1177 * \param fbconfig_style_tags Selects whether \c attribList is in
1178 * \c glXChooseVisual style or
1179 * \c glXChooseFBConfig style.
1180 * \returns The number of valid elements left in \c configs.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001181 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001182 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1183 */
1184static int
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001185choose_visual(struct glx_config ** configs, int num_configs,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001186 const int *attribList, GLboolean fbconfig_style_tags)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001187{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001188 struct glx_config test_config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001189 int base;
1190 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001191
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001192 /* This is a fairly direct implementation of the selection method
1193 * described by GLX_SGIX_fbconfig. Start by culling out all the
1194 * configs that are not compatible with the selected parameter
1195 * list.
1196 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001197
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001198 init_fbconfig_for_chooser(&test_config, fbconfig_style_tags);
1199 __glXInitializeVisualConfigFromTags(&test_config, 512,
1200 (const INT32 *) attribList,
1201 GL_TRUE, fbconfig_style_tags);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001202
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001203 base = 0;
1204 for (i = 0; i < num_configs; i++) {
1205 if (fbconfigs_compatible(&test_config, configs[i])) {
1206 configs[base] = configs[i];
1207 base++;
1208 }
1209 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001210
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001211 if (base == 0) {
1212 return 0;
1213 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001214
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001215 if (base < num_configs) {
1216 (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base));
1217 }
1218
1219 /* After the incompatible configs are removed, the resulting
1220 * list is sorted according to the rules set out in the various
1221 * specifications.
1222 */
1223
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001224 qsort(configs, base, sizeof(struct glx_config *),
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001225 (int (*)(const void *, const void *)) fbconfig_compare);
1226 return base;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001227}
1228
1229
1230
1231
1232/*
1233** Return the visual that best matches the template. Return None if no
1234** visual matches the template.
1235*/
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001236_X_EXPORT XVisualInfo *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001237glXChooseVisual(Display * dpy, int screen, int *attribList)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001238{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001239 XVisualInfo *visualList = NULL;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001240 struct glx_display *priv;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001241 struct glx_screen *psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001242 struct glx_config test_config;
1243 struct glx_config *config;
1244 struct glx_config *best_config = NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001245
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001246 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001247 ** Get a list of all visuals, return if list is empty
1248 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001249 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1250 return None;
1251 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001252
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001253
1254 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001255 ** Build a template from the defaults and the attribute list
1256 ** Free visual list and return if an unexpected token is encountered
1257 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001258 init_fbconfig_for_chooser(&test_config, GL_FALSE);
1259 __glXInitializeVisualConfigFromTags(&test_config, 512,
1260 (const INT32 *) attribList,
1261 GL_TRUE, GL_FALSE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001262
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001263 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001264 ** Eliminate visuals that don't meet minimum requirements
1265 ** Compute a score for those that do
1266 ** Remember which visual, if any, got the highest score
Michel Dänzer46b81b02009-05-12 08:01:22 +02001267 ** If no visual is acceptable, return None
1268 ** Otherwise, create an XVisualInfo list with just the selected X visual
1269 ** and return this.
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001270 */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001271 for (config = psc->visuals; config != NULL; config = config->next) {
1272 if (fbconfigs_compatible(&test_config, config)
1273 && ((best_config == NULL) ||
1274 (fbconfig_compare (&config, &best_config) < 0))) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001275 XVisualInfo visualTemplate;
1276 XVisualInfo *newList;
1277 int i;
Michel Dänzer46b81b02009-05-12 08:01:22 +02001278
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001279 visualTemplate.screen = screen;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001280 visualTemplate.visualid = config->visualID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001281 newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask,
1282 &visualTemplate, &i);
Michel Dänzer46b81b02009-05-12 08:01:22 +02001283
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001284 if (newList) {
Matt Turner7c7b7b02012-09-04 22:52:36 -07001285 free(visualList);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001286 visualList = newList;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001287 best_config = config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001288 }
1289 }
1290 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001291
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001292#ifdef GLX_USE_APPLEGL
1293 if(visualList && getenv("LIBGL_DUMP_VISUALID")) {
1294 printf("visualid 0x%lx\n", visualList[0].visualid);
1295 }
1296#endif
1297
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001298 return visualList;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001299}
1300
1301
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001302_X_EXPORT const char *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001303glXQueryExtensionsString(Display * dpy, int screen)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001304{
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001305 struct glx_screen *psc;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001306 struct glx_display *priv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001307
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001308 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1309 return NULL;
1310 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001311
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001312 if (!psc->effectiveGLXexts) {
1313 if (!psc->serverGLXexts) {
1314 psc->serverGLXexts =
1315 __glXQueryServerString(dpy, priv->majorOpcode, screen,
1316 GLX_EXTENSIONS);
1317 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001318
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001319 __glXCalculateUsableExtensions(psc,
Jeremy Huddleston80b280d2010-04-02 01:35:19 -07001320#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001321 (psc->driScreen != NULL),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001322#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001323 GL_FALSE,
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001324#endif
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001325 priv->minorVersion);
1326 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001327
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001328 return psc->effectiveGLXexts;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001329}
1330
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001331_X_EXPORT const char *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001332glXGetClientString(Display * dpy, int name)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001333{
Ian Romanick26b2bee2010-02-04 15:47:54 -08001334 (void) dpy;
1335
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001336 switch (name) {
1337 case GLX_VENDOR:
1338 return (__glXGLXClientVendorName);
1339 case GLX_VERSION:
1340 return (__glXGLXClientVersion);
1341 case GLX_EXTENSIONS:
1342 return (__glXGetClientExtensions());
1343 default:
1344 return NULL;
1345 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001346}
1347
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001348_X_EXPORT const char *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001349glXQueryServerString(Display * dpy, int screen, int name)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001350{
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001351 struct glx_screen *psc;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001352 struct glx_display *priv;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001353 const char **str;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001354
1355
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001356 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1357 return NULL;
1358 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001359
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001360 switch (name) {
1361 case GLX_VENDOR:
1362 str = &priv->serverGLXvendor;
1363 break;
1364 case GLX_VERSION:
1365 str = &priv->serverGLXversion;
1366 break;
1367 case GLX_EXTENSIONS:
1368 str = &psc->serverGLXexts;
1369 break;
1370 default:
1371 return NULL;
1372 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001373
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001374 if (*str == NULL) {
1375 *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name);
1376 }
1377
1378 return *str;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001379}
1380
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001381
1382/*
1383** EXT_import_context
1384*/
1385
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001386_X_EXPORT Display *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001387glXGetCurrentDisplay(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001388{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001389 struct glx_context *gc = __glXGetCurrentContext();
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001390 if (NULL == gc)
1391 return NULL;
1392 return gc->currentDpy;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001393}
1394
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001395_X_EXPORT
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001396GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1397 glXGetCurrentDisplay)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001398
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001399#ifndef GLX_USE_APPLEGL
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001400_X_EXPORT GLXContext
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001401glXImportContextEXT(Display *dpy, GLXContextID contextID)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001402{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001403 struct glx_display *priv = __glXInitialize(dpy);
Ian Romanick5a849e82011-12-07 11:15:14 -08001404 struct glx_screen *psc = NULL;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001405 xGLXQueryContextReply reply;
1406 CARD8 opcode;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001407 struct glx_context *ctx;
Ian Romanick5a849e82011-12-07 11:15:14 -08001408
1409 /* This GLX implementation knows about 5 different properties, so
1410 * allow the server to send us one of each.
1411 */
1412 int propList[5 * 2], *pProp, nPropListBytes;
1413 int numProps;
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001414 int i, renderType;
1415 XID share;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001416 struct glx_config *mode;
Ian Romanick5a849e82011-12-07 11:15:14 -08001417 uint32_t fbconfigID = 0;
1418 uint32_t visualID = 0;
Brian Paul622b1fc2013-03-13 08:35:21 -06001419 uint32_t screen = 0;
Ian Romanick5a849e82011-12-07 11:15:14 -08001420 Bool got_screen = False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001421
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001422 if (priv == NULL)
1423 return NULL;
1424
Ian Romanicked4a65c2011-12-07 16:13:02 -08001425 /* The GLX_EXT_import_context spec says:
1426 *
1427 * "If <contextID> does not refer to a valid context, then a BadContext
1428 * error is generated; if <contextID> refers to direct rendering
1429 * context then no error is generated but glXImportContextEXT returns
1430 * NULL."
1431 *
1432 * If contextID is None, generate BadContext on the client-side. Other
1433 * sorts of invalid contexts will be detected by the server in the
1434 * __glXIsDirect call.
1435 */
1436 if (contextID == None) {
1437 __glXSendError(dpy, GLXBadContext, contextID, X_GLXIsDirect, false);
1438 return NULL;
1439 }
1440
1441 if (__glXIsDirect(dpy, contextID))
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001442 return NULL;
1443
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001444 opcode = __glXSetupForCommand(dpy);
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001445 if (!opcode)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001446 return 0;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001447
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001448 /* Send the glXQueryContextInfoEXT request */
1449 LockDisplay(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001450
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001451 if (priv->majorVersion > 1 || priv->minorVersion >= 3) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001452 xGLXQueryContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001453
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001454 GetReq(GLXQueryContext, req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001455
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001456 req->reqType = opcode;
1457 req->glxCode = X_GLXQueryContext;
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001458 req->context = contextID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001459 }
1460 else {
1461 xGLXVendorPrivateReq *vpreq;
1462 xGLXQueryContextInfoEXTReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001463
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001464 GetReqExtra(GLXVendorPrivate,
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001465 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1466 vpreq);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001467 req = (xGLXQueryContextInfoEXTReq *) vpreq;
1468 req->reqType = opcode;
1469 req->glxCode = X_GLXVendorPrivateWithReply;
1470 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001471 req->context = contextID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001472 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001473
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001474 _XReply(dpy, (xReply *) & reply, 0, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001475
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001476 if (reply.n <= __GLX_MAX_CONTEXT_PROPS)
1477 nPropListBytes = reply.n * 2 * sizeof propList[0];
1478 else
1479 nPropListBytes = 0;
1480 _XRead(dpy, (char *) propList, nPropListBytes);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001481 UnlockDisplay(dpy);
1482 SyncHandle();
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001483
Ian Romanick5a849e82011-12-07 11:15:14 -08001484 numProps = nPropListBytes / (2 * sizeof(propList[0]));
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001485 share = None;
1486 mode = NULL;
Tomasz Lis36259a12013-07-17 13:49:14 +02001487 renderType = GLX_RGBA_TYPE; /* By default, assume RGBA context */
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001488 pProp = propList;
1489
Ian Romanick5a849e82011-12-07 11:15:14 -08001490 for (i = 0, pProp = propList; i < numProps; i++, pProp += 2)
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001491 switch (pProp[0]) {
Ian Romanick5a849e82011-12-07 11:15:14 -08001492 case GLX_SCREEN:
1493 screen = pProp[1];
1494 got_screen = True;
1495 break;
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001496 case GLX_SHARE_CONTEXT_EXT:
1497 share = pProp[1];
1498 break;
1499 case GLX_VISUAL_ID_EXT:
Ian Romanick5a849e82011-12-07 11:15:14 -08001500 visualID = pProp[1];
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001501 break;
1502 case GLX_FBCONFIG_ID:
Ian Romanick5a849e82011-12-07 11:15:14 -08001503 fbconfigID = pProp[1];
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001504 break;
1505 case GLX_RENDER_TYPE:
1506 renderType = pProp[1];
1507 break;
1508 }
1509
Ian Romanick5a849e82011-12-07 11:15:14 -08001510 if (!got_screen)
1511 return NULL;
1512
1513 psc = GetGLXScreenConfigs(dpy, screen);
1514 if (psc == NULL)
1515 return NULL;
1516
1517 if (fbconfigID != 0) {
1518 mode = glx_config_find_fbconfig(psc->configs, fbconfigID);
1519 } else if (visualID != 0) {
1520 mode = glx_config_find_visual(psc->visuals, visualID);
1521 }
1522
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001523 if (mode == NULL)
1524 return NULL;
1525
1526 ctx = indirect_create_context(psc, mode, NULL, renderType);
1527 if (ctx == NULL)
1528 return NULL;
1529
1530 ctx->xid = contextID;
1531 ctx->imported = GL_TRUE;
1532 ctx->share_xid = share;
1533
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001534 return (GLXContext) ctx;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001535}
1536
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001537#endif
1538
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001539_X_EXPORT int
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001540glXQueryContext(Display * dpy, GLXContext ctx_user, int attribute, int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001541{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001542 struct glx_context *ctx = (struct glx_context *) ctx_user;
1543
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001544 switch (attribute) {
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001545 case GLX_SHARE_CONTEXT_EXT:
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001546 *value = ctx->share_xid;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001547 break;
1548 case GLX_VISUAL_ID_EXT:
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001549 *value = ctx->config ? ctx->config->visualID : None;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001550 break;
1551 case GLX_SCREEN:
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001552 *value = ctx->screen;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001553 break;
1554 case GLX_FBCONFIG_ID:
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001555 *value = ctx->config ? ctx->config->fbconfigID : None;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001556 break;
1557 case GLX_RENDER_TYPE:
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001558 *value = ctx->renderType;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001559 break;
1560 default:
1561 return GLX_BAD_ATTRIBUTE;
1562 }
1563 return Success;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001564}
1565
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001566_X_EXPORT
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001567GLX_ALIAS(int, glXQueryContextInfoEXT,
1568 (Display * dpy, GLXContext ctx, int attribute, int *value),
1569 (dpy, ctx, attribute, value), glXQueryContext)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001570
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001571_X_EXPORT GLXContextID glXGetContextIDEXT(const GLXContext ctx_user)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001572{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001573 struct glx_context *ctx = (struct glx_context *) ctx_user;
1574
Ian Romanick3b9b4222011-12-07 11:37:01 -08001575 return (ctx == NULL) ? None : ctx->xid;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001576}
1577
Ian Romanick4dbd13c2011-12-07 13:31:27 -08001578_X_EXPORT void
1579glXFreeContextEXT(Display *dpy, GLXContext ctx)
1580{
1581 struct glx_context *gc = (struct glx_context *) ctx;
1582
1583 if (gc == NULL || gc->xid == None)
1584 return;
1585
1586 /* The GLX_EXT_import_context spec says:
1587 *
1588 * "glXFreeContext does not free the server-side context information or
1589 * the XID associated with the server-side context."
1590 *
1591 * Don't send any protocol. Just destroy the client-side tracking of the
1592 * context. Also, only release the context structure if it's not current.
1593 */
1594 __glXLock();
1595 if (gc->currentDpy) {
1596 gc->xid = None;
1597 } else {
1598 gc->vtable->destroy(gc);
1599 }
1600 __glXUnlock();
1601}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001602
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001603_X_EXPORT GLXFBConfig *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001604glXChooseFBConfig(Display * dpy, int screen,
1605 const int *attribList, int *nitems)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001606{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001607 struct glx_config **config_list;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001608 int list_size;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001609
1610
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001611 config_list = (struct glx_config **)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001612 glXGetFBConfigs(dpy, screen, &list_size);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001613
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001614 if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) {
1615 list_size = choose_visual(config_list, list_size, attribList, GL_TRUE);
1616 if (list_size == 0) {
Matt Turner7c7b7b02012-09-04 22:52:36 -07001617 free(config_list);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001618 config_list = NULL;
1619 }
1620 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001621
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001622 *nitems = list_size;
1623 return (GLXFBConfig *) config_list;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001624}
1625
1626
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001627_X_EXPORT GLXContext
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001628glXCreateNewContext(Display * dpy, GLXFBConfig fbconfig,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001629 int renderType, GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001630{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001631 struct glx_config *config = (struct glx_config *) fbconfig;
Ian Romanick7bcfb662010-02-04 16:37:59 -08001632
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001633 return CreateContext(dpy, config->fbconfigID, config, shareList,
1634 allowDirect, X_GLXCreateNewContext, renderType,
1635 config->screen);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001636}
1637
1638
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001639_X_EXPORT GLXDrawable
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001640glXGetCurrentReadDrawable(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001641{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001642 struct glx_context *gc = __glXGetCurrentContext();
1643
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001644 return gc->currentReadable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001645}
1646
1647
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001648_X_EXPORT GLXFBConfig *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001649glXGetFBConfigs(Display * dpy, int screen, int *nelements)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001650{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001651 struct glx_display *priv = __glXInitialize(dpy);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001652 struct glx_config **config_list = NULL;
1653 struct glx_config *config;
1654 unsigned num_configs = 0;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001655 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001656
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001657 *nelements = 0;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001658 if (priv && (priv->screens != NULL)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001659 && (screen >= 0) && (screen <= ScreenCount(dpy))
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001660 && (priv->screens[screen]->configs != NULL)
1661 && (priv->screens[screen]->configs->fbconfigID
Ian Romanick71a6fb12010-02-04 15:59:51 -08001662 != (int) GLX_DONT_CARE)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001663
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001664 for (config = priv->screens[screen]->configs; config != NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001665 config = config->next) {
1666 if (config->fbconfigID != (int) GLX_DONT_CARE) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001667 num_configs++;
1668 }
1669 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001670
Matt Turner7c7b7b02012-09-04 22:52:36 -07001671 config_list = malloc(num_configs * sizeof *config_list);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001672 if (config_list != NULL) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001673 *nelements = num_configs;
1674 i = 0;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001675 for (config = priv->screens[screen]->configs; config != NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001676 config = config->next) {
1677 if (config->fbconfigID != (int) GLX_DONT_CARE) {
1678 config_list[i] = config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001679 i++;
1680 }
1681 }
1682 }
1683 }
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001684
1685 return (GLXFBConfig *) config_list;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001686}
1687
1688
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001689_X_EXPORT int
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001690glXGetFBConfigAttrib(Display * dpy, GLXFBConfig fbconfig,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001691 int attribute, int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001692{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001693 struct glx_config *config = ValidateGLXFBConfig(dpy, fbconfig);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001694
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001695 if (config == NULL)
1696 return GLXBadFBConfig;
1697
1698 return glx_config_get(config, attribute, value);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001699}
1700
1701
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001702_X_EXPORT XVisualInfo *
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001703glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig fbconfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001704{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001705 XVisualInfo visualTemplate;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001706 struct glx_config *config = (struct glx_config *) fbconfig;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001707 int count;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001708
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001709 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001710 ** Get a list of all visuals, return if list is empty
1711 */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001712 visualTemplate.visualid = config->visualID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001713 return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001714}
1715
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001716#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001717/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001718** GLX_SGI_swap_control
1719*/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001720static int
1721__glXSwapIntervalSGI(int interval)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001722{
1723 xGLXVendorPrivateReq *req;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001724 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001725 struct glx_screen *psc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001726 Display *dpy;
1727 CARD32 *interval_ptr;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001728 CARD8 opcode;
1729
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001730 if (gc == NULL) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001731 return GLX_BAD_CONTEXT;
1732 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001733
1734 if (interval <= 0) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001735 return GLX_BAD_VALUE;
1736 }
1737
Jesse Barnesefc82e72009-11-10 13:28:01 -08001738 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1739
Vinson Lee16f568a2010-04-01 00:10:28 -07001740#ifdef GLX_DIRECT_RENDERING
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001741 if (gc->isDirect && psc && psc->driScreen &&
1742 psc->driScreen->setSwapInterval) {
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001743 __GLXDRIdrawable *pdraw =
1744 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Jesse Barnesefc82e72009-11-10 13:28:01 -08001745 psc->driScreen->setSwapInterval(pdraw, interval);
1746 return 0;
1747 }
Vinson Lee16f568a2010-04-01 00:10:28 -07001748#endif
Jesse Barnesefc82e72009-11-10 13:28:01 -08001749
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001750 dpy = gc->currentDpy;
1751 opcode = __glXSetupForCommand(dpy);
1752 if (!opcode) {
1753 return 0;
1754 }
1755
1756 /* Send the glXSwapIntervalSGI request */
1757 LockDisplay(dpy);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001758 GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001759 req->reqType = opcode;
1760 req->glxCode = X_GLXVendorPrivate;
1761 req->vendorCode = X_GLXvop_SwapIntervalSGI;
1762 req->contextTag = gc->currentContextTag;
1763
Ian Romanicka70d5642006-08-30 23:15:02 +00001764 interval_ptr = (CARD32 *) (req + 1);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001765 *interval_ptr = interval;
1766
1767 UnlockDisplay(dpy);
1768 SyncHandle();
1769 XFlush(dpy);
1770
1771 return 0;
1772}
1773
1774
1775/*
1776** GLX_MESA_swap_control
1777*/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001778static int
1779__glXSwapIntervalMESA(unsigned int interval)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001780{
Kristian Høgsberg089fc372010-07-19 16:39:53 -04001781#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001782 struct glx_context *gc = __glXGetCurrentContext();
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001783
Kristian Høgsbergc491e582010-07-28 15:33:09 -04001784 if (gc != NULL && gc->isDirect) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001785 struct glx_screen *psc;
Jesse Barnesefc82e72009-11-10 13:28:01 -08001786
1787 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001788 if (psc && psc->driScreen && psc->driScreen->setSwapInterval) {
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001789 __GLXDRIdrawable *pdraw =
1790 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Kristian Høgsberg089fc372010-07-19 16:39:53 -04001791 return psc->driScreen->setSwapInterval(pdraw, interval);
Jesse Barnesefc82e72009-11-10 13:28:01 -08001792 }
1793 }
Vinson Lee16f568a2010-04-01 00:10:28 -07001794#endif
Jesse Barnesefc82e72009-11-10 13:28:01 -08001795
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001796 return GLX_BAD_CONTEXT;
1797}
Brian Paul841a8232006-03-09 16:25:46 +00001798
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001799
1800static int
1801__glXGetSwapIntervalMESA(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001802{
Kristian Høgsberg089fc372010-07-19 16:39:53 -04001803#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001804 struct glx_context *gc = __glXGetCurrentContext();
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001805
Kristian Høgsbergc491e582010-07-28 15:33:09 -04001806 if (gc != NULL && gc->isDirect) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001807 struct glx_screen *psc;
Jesse Barnesefc82e72009-11-10 13:28:01 -08001808
1809 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001810 if (psc && psc->driScreen && psc->driScreen->getSwapInterval) {
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001811 __GLXDRIdrawable *pdraw =
1812 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Jesse Barnesefc82e72009-11-10 13:28:01 -08001813 return psc->driScreen->getSwapInterval(pdraw);
1814 }
1815 }
Vinson Lee67776f62010-04-02 00:12:59 -07001816#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001817
1818 return 0;
1819}
1820
1821
1822/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001823** GLX_SGI_video_sync
1824*/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001825static int
1826__glXGetVideoSyncSGI(unsigned int *count)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001827{
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001828 int64_t ust, msc, sbc;
1829 int ret;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001830 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001831 struct glx_screen *psc;
Vinson Lee67776f62010-04-02 00:12:59 -07001832#ifdef GLX_DIRECT_RENDERING
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001833 __GLXDRIdrawable *pdraw;
Vinson Lee67776f62010-04-02 00:12:59 -07001834#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001835
Vinson Lee16f568a2010-04-01 00:10:28 -07001836 if (!gc)
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001837 return GLX_BAD_CONTEXT;
1838
Vinson Lee16f568a2010-04-01 00:10:28 -07001839#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc491e582010-07-28 15:33:09 -04001840 if (!gc->isDirect)
Vinson Lee16f568a2010-04-01 00:10:28 -07001841 return GLX_BAD_CONTEXT;
1842#endif
1843
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001844 psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen);
Vinson Lee67776f62010-04-02 00:12:59 -07001845#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001846 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Vinson Lee67776f62010-04-02 00:12:59 -07001847#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001848
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001849 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1850 * FIXME: there should be a GLX encoding for this call. I can find no
1851 * FIXME: documentation for the GLX encoding.
1852 */
Vinson Lee67776f62010-04-02 00:12:59 -07001853#ifdef GLX_DIRECT_RENDERING
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001854 if (psc && psc->driScreen && psc->driScreen->getDrawableMSC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001855 ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc);
1856 *count = (unsigned) msc;
1857 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1858 }
Vinson Lee67776f62010-04-02 00:12:59 -07001859#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001860
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001861 return GLX_BAD_CONTEXT;
1862}
1863
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001864static int
1865__glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001866{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001867 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001868 struct glx_screen *psc;
Vinson Lee67776f62010-04-02 00:12:59 -07001869#ifdef GLX_DIRECT_RENDERING
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001870 __GLXDRIdrawable *pdraw;
Vinson Lee67776f62010-04-02 00:12:59 -07001871#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001872 int64_t ust, msc, sbc;
1873 int ret;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001874
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001875 if (divisor <= 0 || remainder < 0)
1876 return GLX_BAD_VALUE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001877
Vinson Lee16f568a2010-04-01 00:10:28 -07001878 if (!gc)
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001879 return GLX_BAD_CONTEXT;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001880
Vinson Lee16f568a2010-04-01 00:10:28 -07001881#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc491e582010-07-28 15:33:09 -04001882 if (!gc->isDirect)
Vinson Lee16f568a2010-04-01 00:10:28 -07001883 return GLX_BAD_CONTEXT;
1884#endif
1885
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001886 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
Vinson Lee67776f62010-04-02 00:12:59 -07001887#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001888 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Vinson Lee67776f62010-04-02 00:12:59 -07001889#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001890
Vinson Lee67776f62010-04-02 00:12:59 -07001891#ifdef GLX_DIRECT_RENDERING
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001892 if (psc && psc->driScreen && psc->driScreen->waitForMSC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001893 ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc,
1894 &sbc);
1895 *count = (unsigned) msc;
1896 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1897 }
Vinson Lee67776f62010-04-02 00:12:59 -07001898#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001899
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001900 return GLX_BAD_CONTEXT;
1901}
1902
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001903#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001904
1905/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001906** GLX_SGIX_fbconfig
1907** Many of these functions are aliased to GLX 1.3 entry points in the
1908** GLX_functions table.
1909*/
1910
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001911_X_EXPORT
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001912GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
1913 (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value),
1914 (dpy, config, attribute, value), glXGetFBConfigAttrib)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001915
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001916_X_EXPORT GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
Brian Paulef9cd842009-09-29 09:58:47 -06001917 (Display * dpy, int screen, int *attrib_list,
1918 int *nelements), (dpy, screen, attrib_list, nelements),
1919 glXChooseFBConfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001920
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001921_X_EXPORT GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
Brian Paulef9cd842009-09-29 09:58:47 -06001922 (Display * dpy, GLXFBConfigSGIX config),
1923 (dpy, config), glXGetVisualFromFBConfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001924
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001925_X_EXPORT GLXPixmap
Brian Paulef9cd842009-09-29 09:58:47 -06001926glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001927 GLXFBConfigSGIX fbconfig,
Brian Paulef9cd842009-09-29 09:58:47 -06001928 Pixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001929{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001930#ifndef GLX_USE_APPLEGL
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001931 xGLXVendorPrivateWithReplyReq *vpreq;
1932 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
1933 GLXPixmap xid = None;
1934 CARD8 opcode;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001935 struct glx_screen *psc;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001936#endif
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001937 struct glx_config *config = (struct glx_config *) fbconfig;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001938
1939
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001940 if ((dpy == NULL) || (config == NULL)) {
1941 return None;
1942 }
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001943#ifdef GLX_USE_APPLEGL
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001944 if(apple_glx_pixmap_create(dpy, config->screen, pixmap, config))
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001945 return None;
1946 return pixmap;
1947#else
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001948
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001949 psc = GetGLXScreenConfigs(dpy, config->screen);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001950 if ((psc != NULL)
1951 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
1952 opcode = __glXSetupForCommand(dpy);
1953 if (!opcode) {
1954 return None;
1955 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001956
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001957 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1958 LockDisplay(dpy);
1959 GetReqExtra(GLXVendorPrivateWithReply,
1960 sz_xGLXCreateGLXPixmapWithConfigSGIXReq -
1961 sz_xGLXVendorPrivateWithReplyReq, vpreq);
1962 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq;
1963 req->reqType = opcode;
1964 req->glxCode = X_GLXVendorPrivateWithReply;
1965 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001966 req->screen = config->screen;
1967 req->fbconfig = config->fbconfigID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001968 req->pixmap = pixmap;
1969 req->glxpixmap = xid = XAllocID(dpy);
1970 UnlockDisplay(dpy);
1971 SyncHandle();
1972 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001973
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001974 return xid;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001975#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001976}
1977
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04001978_X_EXPORT GLXContext
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001979glXCreateContextWithConfigSGIX(Display * dpy,
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001980 GLXFBConfigSGIX fbconfig, int renderType,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001981 GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001982{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001983 GLXContext gc = NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001984 struct glx_config *config = (struct glx_config *) fbconfig;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001985 struct glx_screen *psc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001986
1987
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001988 if ((dpy == NULL) || (config == NULL)) {
1989 return None;
1990 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001991
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001992 psc = GetGLXScreenConfigs(dpy, config->screen);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001993 if ((psc != NULL)
1994 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001995 gc = CreateContext(dpy, config->fbconfigID, config, shareList,
Ian Romanick22430292010-02-04 16:43:46 -08001996 allowDirect,
Ian Romanick7bcfb662010-02-04 16:37:59 -08001997 X_GLXvop_CreateContextWithConfigSGIX, renderType,
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001998 config->screen);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001999 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002000
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002001 return gc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002002}
2003
2004
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04002005_X_EXPORT GLXFBConfigSGIX
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002006glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002007{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002008 struct glx_display *priv;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002009 struct glx_screen *psc = NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002010
Stéphane Marchesinfc48de42011-05-26 17:19:03 -07002011 if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) == Success)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002012 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)
Ian Romanick71a6fb12010-02-04 15:59:51 -08002013 && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) {
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002014 return (GLXFBConfigSGIX) glx_config_find_visual(psc->configs,
2015 vis->visualid);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002016 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002017
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002018 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002019}
2020
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002021#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002022/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002023** GLX_SGIX_swap_group
2024*/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002025static void
2026__glXJoinSwapGroupSGIX(Display * dpy, GLXDrawable drawable,
2027 GLXDrawable member)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002028{
2029 (void) dpy;
2030 (void) drawable;
2031 (void) member;
2032}
2033
2034
2035/*
2036** GLX_SGIX_swap_barrier
2037*/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002038static void
2039__glXBindSwapBarrierSGIX(Display * dpy, GLXDrawable drawable, int barrier)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002040{
2041 (void) dpy;
2042 (void) drawable;
2043 (void) barrier;
2044}
2045
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002046static Bool
2047__glXQueryMaxSwapBarriersSGIX(Display * dpy, int screen, int *max)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002048{
2049 (void) dpy;
2050 (void) screen;
2051 (void) max;
2052 return False;
2053}
2054
2055
2056/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002057** GLX_OML_sync_control
2058*/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002059static Bool
2060__glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
2061 int64_t * ust, int64_t * msc, int64_t * sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002062{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002063 struct glx_display * const priv = __glXInitialize(dpy);
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002064 int ret;
Vinson Lee67776f62010-04-02 00:12:59 -07002065#ifdef GLX_DIRECT_RENDERING
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002066 __GLXDRIdrawable *pdraw;
Vinson Lee67776f62010-04-02 00:12:59 -07002067#endif
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002068 struct glx_screen *psc;
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002069
2070 if (!priv)
2071 return False;
2072
Vinson Lee67776f62010-04-02 00:12:59 -07002073#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002074 pdraw = GetGLXDRIDrawable(dpy, drawable);
2075 psc = pdraw ? pdraw->psc : NULL;
2076 if (pdraw && psc->driScreen->getDrawableMSC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002077 ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc);
2078 return ret;
2079 }
Vinson Lee67776f62010-04-02 00:12:59 -07002080#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002081
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002082 return False;
2083}
2084
Jeremy Huddleston80b280d2010-04-02 01:35:19 -07002085#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsberg3d28a262008-03-08 22:28:01 -05002086_X_HIDDEN GLboolean
Lauri Kasanenfe2079c2013-12-15 12:37:55 +02002087__glxGetMscRate(struct glx_screen *psc,
Kristian Høgsberg7a66e542010-07-21 14:09:49 -04002088 int32_t * numerator, int32_t * denominator)
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002089{
2090#ifdef XF86VIDMODE
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002091 XF86VidModeModeLine mode_line;
2092 int dot_clock;
2093 int i;
Ian Romanick26b2bee2010-02-04 15:47:54 -08002094
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002095 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2096 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) {
2097 unsigned n = dot_clock * 1000;
2098 unsigned d = mode_line.vtotal * mode_line.htotal;
2099
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002100# define V_INTERLACE 0x010
2101# define V_DBLSCAN 0x020
2102
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002103 if (mode_line.flags & V_INTERLACE)
2104 n *= 2;
2105 else if (mode_line.flags & V_DBLSCAN)
2106 d *= 2;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002107
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002108 /* The OML_sync_control spec requires that if the refresh rate is a
2109 * whole number, that the returned numerator be equal to the refresh
2110 * rate and the denominator be 1.
2111 */
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002112
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002113 if (n % d == 0) {
2114 n /= d;
2115 d = 1;
2116 }
2117 else {
2118 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002119
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002120 /* This is a poor man's way to reduce a fraction. It's far from
2121 * perfect, but it will work well enough for this situation.
2122 */
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002123
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002124 for (i = 0; f[i] != 0; i++) {
2125 while (n % f[i] == 0 && d % f[i] == 0) {
2126 d /= f[i];
2127 n /= f[i];
2128 }
2129 }
2130 }
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002131
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002132 *numerator = n;
2133 *denominator = d;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002134
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002135 return True;
2136 }
2137 else
Kristian Høgsberg57d3f712010-09-07 14:23:00 -04002138#endif
Ian Romanick26b2bee2010-02-04 15:47:54 -08002139
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002140 return False;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002141}
2142#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002143
2144/**
2145 * Determine the refresh rate of the specified drawable and display.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002146 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002147 * \param dpy Display whose refresh rate is to be determined.
2148 * \param drawable Drawable whose refresh rate is to be determined.
2149 * \param numerator Numerator of the refresh rate.
2150 * \param demoninator Denominator of the refresh rate.
2151 * \return If the refresh rate for the specified display and drawable could
2152 * be calculated, True is returned. Otherwise False is returned.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002153 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002154 * \note This function is implemented entirely client-side. A lot of other
2155 * functionality is required to export GLX_OML_sync_control, so on
2156 * XFree86 this function can be called for direct-rendering contexts
2157 * when GLX_OML_sync_control appears in the client extension string.
2158 */
2159
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002160_X_HIDDEN GLboolean
2161__glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2162 int32_t * numerator, int32_t * denominator)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002163{
2164#if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002165 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002166
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002167 if (draw == NULL)
2168 return False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002169
Lauri Kasanenfe2079c2013-12-15 12:37:55 +02002170 return __glxGetMscRate(draw->psc, numerator, denominator);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002171#else
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002172 (void) dpy;
2173 (void) drawable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002174 (void) numerator;
2175 (void) denominator;
2176#endif
2177 return False;
2178}
2179
2180
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002181static int64_t
2182__glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
2183 int64_t target_msc, int64_t divisor, int64_t remainder)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002184{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002185 struct glx_context *gc = __glXGetCurrentContext();
Vinson Lee67776f62010-04-02 00:12:59 -07002186#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002187 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002188 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
Vinson Lee67776f62010-04-02 00:12:59 -07002189#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002190
Vinson Lee67776f62010-04-02 00:12:59 -07002191 if (!gc) /* no GLX for this */
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002192 return -1;
2193
Vinson Lee16f568a2010-04-01 00:10:28 -07002194#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc491e582010-07-28 15:33:09 -04002195 if (!pdraw || !gc->isDirect)
Vinson Lee16f568a2010-04-01 00:10:28 -07002196 return -1;
2197#endif
2198
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002199 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2200 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2201 * of -1 if the function failed because of errors detected in the input
2202 * parameters"
2203 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002204 if (divisor < 0 || remainder < 0 || target_msc < 0)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002205 return -1;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002206 if (divisor > 0 && remainder >= divisor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002207 return -1;
2208
Jesse Barnes8f4f2a02010-03-22 16:39:11 -07002209 if (target_msc == 0 && divisor == 0 && remainder == 0)
2210 remainder = 1;
2211
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002212#ifdef GLX_DIRECT_RENDERING
2213 if (psc->driScreen && psc->driScreen->swapBuffers)
2214 return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor,
Marek Olšák5b7e9b72012-11-13 17:06:37 +01002215 remainder, False);
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002216#endif
2217
2218 return -1;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002219}
2220
2221
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002222static Bool
2223__glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2224 int64_t target_msc, int64_t divisor,
2225 int64_t remainder, int64_t * ust,
2226 int64_t * msc, int64_t * sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002227{
Vinson Lee67776f62010-04-02 00:12:59 -07002228#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002229 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002230 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002231 int ret;
Jon TURNEYae9487c2010-08-09 14:47:26 +01002232#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002233
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002234
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002235 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2236 * error", but the return type in the spec is Bool.
2237 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002238 if (divisor < 0 || remainder < 0 || target_msc < 0)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002239 return False;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002240 if (divisor > 0 && remainder >= divisor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002241 return False;
2242
Vinson Lee67776f62010-04-02 00:12:59 -07002243#ifdef GLX_DIRECT_RENDERING
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002244 if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
2245 ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder,
2246 ust, msc, sbc);
2247 return ret;
2248 }
Vinson Lee67776f62010-04-02 00:12:59 -07002249#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002250
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002251 return False;
2252}
2253
2254
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002255static Bool
2256__glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2257 int64_t target_sbc, int64_t * ust,
2258 int64_t * msc, int64_t * sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002259{
Vinson Lee67776f62010-04-02 00:12:59 -07002260#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002261 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002262 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002263 int ret;
Jon TURNEYae9487c2010-08-09 14:47:26 +01002264#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002265
2266 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2267 * error", but the return type in the spec is Bool.
2268 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002269 if (target_sbc < 0)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002270 return False;
Vinson Lee67776f62010-04-02 00:12:59 -07002271
2272#ifdef GLX_DIRECT_RENDERING
kleinerm251bf292010-02-19 12:28:26 -08002273 if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002274 ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
2275 return ret;
2276 }
Vinson Lee67776f62010-04-02 00:12:59 -07002277#endif
2278
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002279 return False;
2280}
2281
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002282/*@}*/
2283
2284
2285/**
2286 * Mesa extension stubs. These will help reduce portability problems.
2287 */
2288/*@{*/
2289
2290/**
2291 * Release all buffers associated with the specified GLX drawable.
2292 *
2293 * \todo
2294 * This function was intended for stand-alone Mesa. The issue there is that
2295 * the library doesn't get any notification when a window is closed. In
2296 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2297 * supported, there are 3 different functions to destroy a drawable. It
2298 * should be possible to create GLX protocol (or have it determine which
2299 * protocol to use based on the type of the drawable) to have one function
2300 * do the work of 3. For the direct-rendering case, this function could
2301 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2302 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2303 * would need to be used. This really should be done as part of the new DRI
2304 * interface work.
2305 *
2306 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2307 * __driGarbageCollectDrawables
2308 * glXDestroyGLXPixmap
2309 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2310 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2311 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002312static Bool
2313__glXReleaseBuffersMESA(Display * dpy, GLXDrawable d)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002314{
2315 (void) dpy;
2316 (void) d;
2317 return False;
2318}
2319
2320
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04002321_X_EXPORT GLXPixmap
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002322glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual,
2323 Pixmap pixmap, Colormap cmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002324{
2325 (void) dpy;
2326 (void) visual;
2327 (void) pixmap;
2328 (void) cmap;
2329 return 0;
2330}
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002331
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002332/*@}*/
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002333
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002334
2335/**
2336 * GLX_MESA_copy_sub_buffer
2337 */
Brian Paulf2ad1b62006-03-31 15:48:04 +00002338#define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002339static void
2340__glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable,
2341 int x, int y, int width, int height)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002342{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002343 xGLXVendorPrivateReq *req;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002344 struct glx_context *gc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002345 GLXContextTag tag;
2346 CARD32 *drawable_ptr;
2347 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2348 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002349
Kristian Høgsberg2235b1c2010-07-26 15:50:02 -04002350#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002351 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002352 if (pdraw != NULL) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002353 struct glx_screen *psc = pdraw->psc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002354 if (psc->driScreen->copySubBuffer != NULL) {
Marek Olšák5b7e9b72012-11-13 17:06:37 +01002355 (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height, True);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002356 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002357
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002358 return;
2359 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002360#endif
2361
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002362 opcode = __glXSetupForCommand(dpy);
2363 if (!opcode)
2364 return;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002365
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002366 /*
Brian Paulf2ad1b62006-03-31 15:48:04 +00002367 ** The calling thread may or may not have a current context. If it
2368 ** does, send the context tag so the server can do a flush.
2369 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002370 gc = __glXGetCurrentContext();
2371 if ((gc != NULL) && (dpy == gc->currentDpy) &&
2372 ((drawable == gc->currentDrawable) ||
2373 (drawable == gc->currentReadable))) {
2374 tag = gc->currentContextTag;
2375 }
2376 else {
2377 tag = 0;
2378 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002379
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002380 LockDisplay(dpy);
2381 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req);
2382 req->reqType = opcode;
2383 req->glxCode = X_GLXVendorPrivate;
2384 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2385 req->contextTag = tag;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002386
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002387 drawable_ptr = (CARD32 *) (req + 1);
2388 x_ptr = (INT32 *) (drawable_ptr + 1);
2389 y_ptr = (INT32 *) (drawable_ptr + 2);
2390 w_ptr = (INT32 *) (drawable_ptr + 3);
2391 h_ptr = (INT32 *) (drawable_ptr + 4);
Brian Paulf2ad1b62006-03-31 15:48:04 +00002392
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002393 *drawable_ptr = drawable;
2394 *x_ptr = x;
2395 *y_ptr = y;
2396 *w_ptr = width;
2397 *h_ptr = height;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002398
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002399 UnlockDisplay(dpy);
2400 SyncHandle();
Brian Paulf2ad1b62006-03-31 15:48:04 +00002401}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002402
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002403/*@{*/
2404static void
2405__glXBindTexImageEXT(Display * dpy,
2406 GLXDrawable drawable, int buffer, const int *attrib_list)
2407{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002408 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002409
Kristian Høgsberg3ea3f5e2010-09-07 14:32:28 -04002410 if (gc == NULL || gc->vtable->bind_tex_image == NULL)
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002411 return;
2412
2413 gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list);
2414}
2415
2416static void
2417__glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
2418{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002419 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002420
Kristian Høgsberg3ea3f5e2010-09-07 14:32:28 -04002421 if (gc == NULL || gc->vtable->release_tex_image == NULL)
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002422 return;
2423
2424 gc->vtable->release_tex_image(dpy, drawable, buffer);
2425}
2426
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002427/*@}*/
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002428
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002429#endif /* GLX_USE_APPLEGL */
2430
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002431/**
2432 * \c strdup is actually not a standard ANSI C or POSIX routine.
2433 * Irix will not define it if ANSI mode is in effect.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002434 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002435 * \sa strdup
2436 */
Kristian Høgsberg3d28a262008-03-08 22:28:01 -05002437_X_HIDDEN char *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002438__glXstrdup(const char *str)
2439{
2440 char *copy;
Matt Turner2b7a9722012-09-03 19:44:00 -07002441 copy = malloc(strlen(str) + 1);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002442 if (!copy)
2443 return NULL;
2444 strcpy(copy, str);
2445 return copy;
2446}
2447
2448/*
2449** glXGetProcAddress support
2450*/
2451
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002452struct name_address_pair
2453{
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002454 const char *Name;
2455 GLvoid *Address;
2456};
2457
2458#define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2459#define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2460
2461static const struct name_address_pair GLX_functions[] = {
2462 /*** GLX_VERSION_1_0 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002463 GLX_FUNCTION(glXChooseVisual),
2464 GLX_FUNCTION(glXCopyContext),
2465 GLX_FUNCTION(glXCreateContext),
2466 GLX_FUNCTION(glXCreateGLXPixmap),
2467 GLX_FUNCTION(glXDestroyContext),
2468 GLX_FUNCTION(glXDestroyGLXPixmap),
2469 GLX_FUNCTION(glXGetConfig),
2470 GLX_FUNCTION(glXGetCurrentContext),
2471 GLX_FUNCTION(glXGetCurrentDrawable),
2472 GLX_FUNCTION(glXIsDirect),
2473 GLX_FUNCTION(glXMakeCurrent),
2474 GLX_FUNCTION(glXQueryExtension),
2475 GLX_FUNCTION(glXQueryVersion),
2476 GLX_FUNCTION(glXSwapBuffers),
2477 GLX_FUNCTION(glXUseXFont),
2478 GLX_FUNCTION(glXWaitGL),
2479 GLX_FUNCTION(glXWaitX),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002480
2481 /*** GLX_VERSION_1_1 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002482 GLX_FUNCTION(glXGetClientString),
2483 GLX_FUNCTION(glXQueryExtensionsString),
2484 GLX_FUNCTION(glXQueryServerString),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002485
2486 /*** GLX_VERSION_1_2 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002487 GLX_FUNCTION(glXGetCurrentDisplay),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002488
2489 /*** GLX_VERSION_1_3 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002490 GLX_FUNCTION(glXChooseFBConfig),
2491 GLX_FUNCTION(glXCreateNewContext),
2492 GLX_FUNCTION(glXCreatePbuffer),
2493 GLX_FUNCTION(glXCreatePixmap),
2494 GLX_FUNCTION(glXCreateWindow),
2495 GLX_FUNCTION(glXDestroyPbuffer),
2496 GLX_FUNCTION(glXDestroyPixmap),
2497 GLX_FUNCTION(glXDestroyWindow),
2498 GLX_FUNCTION(glXGetCurrentReadDrawable),
2499 GLX_FUNCTION(glXGetFBConfigAttrib),
2500 GLX_FUNCTION(glXGetFBConfigs),
2501 GLX_FUNCTION(glXGetSelectedEvent),
2502 GLX_FUNCTION(glXGetVisualFromFBConfig),
2503 GLX_FUNCTION(glXMakeContextCurrent),
2504 GLX_FUNCTION(glXQueryContext),
2505 GLX_FUNCTION(glXQueryDrawable),
2506 GLX_FUNCTION(glXSelectEvent),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002507
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002508#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002509 /*** GLX_SGI_swap_control ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002510 GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002511
2512 /*** GLX_SGI_video_sync ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002513 GLX_FUNCTION2(glXGetVideoSyncSGI, __glXGetVideoSyncSGI),
2514 GLX_FUNCTION2(glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002515
2516 /*** GLX_SGI_make_current_read ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002517 GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent),
2518 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002519
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002520 /*** GLX_EXT_import_context ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002521 GLX_FUNCTION(glXFreeContextEXT),
2522 GLX_FUNCTION(glXGetContextIDEXT),
2523 GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay),
2524 GLX_FUNCTION(glXImportContextEXT),
2525 GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext),
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002526#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002527
2528 /*** GLX_SGIX_fbconfig ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002529 GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib),
2530 GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig),
2531 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX),
2532 GLX_FUNCTION(glXCreateContextWithConfigSGIX),
2533 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig),
2534 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002535
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002536#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002537 /*** GLX_SGIX_pbuffer ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002538 GLX_FUNCTION(glXCreateGLXPbufferSGIX),
2539 GLX_FUNCTION(glXDestroyGLXPbufferSGIX),
2540 GLX_FUNCTION(glXQueryGLXPbufferSGIX),
2541 GLX_FUNCTION(glXSelectEventSGIX),
2542 GLX_FUNCTION(glXGetSelectedEventSGIX),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002543
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002544 /*** GLX_SGIX_swap_group ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002545 GLX_FUNCTION2(glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002546
2547 /*** GLX_SGIX_swap_barrier ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002548 GLX_FUNCTION2(glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX),
2549 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002550
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002551 /*** GLX_MESA_copy_sub_buffer ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002552 GLX_FUNCTION2(glXCopySubBufferMESA, __glXCopySubBufferMESA),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002553
2554 /*** GLX_MESA_pixmap_colormap ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002555 GLX_FUNCTION(glXCreateGLXPixmapMESA),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002556
2557 /*** GLX_MESA_release_buffers ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002558 GLX_FUNCTION2(glXReleaseBuffersMESA, __glXReleaseBuffersMESA),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002559
2560 /*** GLX_MESA_swap_control ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002561 GLX_FUNCTION2(glXSwapIntervalMESA, __glXSwapIntervalMESA),
2562 GLX_FUNCTION2(glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA),
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002563#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002564
2565 /*** GLX_ARB_get_proc_address ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002566 GLX_FUNCTION(glXGetProcAddressARB),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002567
2568 /*** GLX 1.4 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002569 GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002570
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002571#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002572 /*** GLX_OML_sync_control ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002573 GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML),
2574 GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML),
2575 GLX_FUNCTION2(glXSwapBuffersMscOML, __glXSwapBuffersMscOML),
2576 GLX_FUNCTION2(glXGetMscRateOML, __glXGetMscRateOML),
2577 GLX_FUNCTION2(glXGetSyncValuesOML, __glXGetSyncValuesOML),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002578
Brian Paul42725d62006-02-07 00:39:56 +00002579 /*** GLX_EXT_texture_from_pixmap ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002580 GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT),
2581 GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT),
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002582#endif
Brian Paul42725d62006-02-07 00:39:56 +00002583
Jon TURNEYf647a722014-06-02 18:52:15 +01002584#if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_DRM)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002585 /*** DRI configuration ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002586 GLX_FUNCTION(glXGetScreenDriver),
2587 GLX_FUNCTION(glXGetDriverConfig),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002588#endif
2589
Ian Romanick78aa71a2011-11-30 11:12:49 -08002590 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2591 GLX_FUNCTION(glXCreateContextAttribsARB),
2592
Ian Romanick6c28c032013-02-15 22:35:24 -08002593 /*** GLX_MESA_query_renderer ***/
2594 GLX_FUNCTION(glXQueryRendererIntegerMESA),
2595 GLX_FUNCTION(glXQueryRendererStringMESA),
2596 GLX_FUNCTION(glXQueryCurrentRendererIntegerMESA),
2597 GLX_FUNCTION(glXQueryCurrentRendererStringMESA),
2598
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002599 {NULL, NULL} /* end of list */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002600};
2601
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002602static const GLvoid *
2603get_glx_proc_address(const char *funcName)
2604{
2605 GLuint i;
2606
2607 /* try static functions */
2608 for (i = 0; GLX_functions[i].Name; i++) {
2609 if (strcmp(GLX_functions[i].Name, funcName) == 0)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002610 return GLX_functions[i].Address;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002611 }
2612
2613 return NULL;
2614}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002615
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002616/**
2617 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2618 * \c glXGetProcAddress.
2619 *
2620 * \param procName Name of a GL or GLX function.
2621 * \returns A pointer to the named function
2622 *
2623 * \sa glXGetProcAddress
2624 */
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04002625_X_EXPORT void (*glXGetProcAddressARB(const GLubyte * procName)) (void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002626{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002627 typedef void (*gl_function) (void);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002628 gl_function f;
2629
2630
2631 /* Search the table of GLX and internal functions first. If that
2632 * fails and the supplied name could be a valid core GL name, try
2633 * searching the core GL function table. This check is done to prevent
2634 * DRI based drivers from searching the core GL function table for
2635 * internal API functions.
2636 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002637 f = (gl_function) get_glx_proc_address((const char *) procName);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002638 if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2639 && (procName[2] != 'X')) {
Matt Turner027ce0c2012-01-24 11:34:42 -05002640#ifdef GLX_SHARED_GLAPI
Chia-I Wue8c7d752010-12-26 18:24:13 +08002641 f = (gl_function) __indirect_get_proc_address((const char *) procName);
Matt Turner027ce0c2012-01-24 11:34:42 -05002642#endif
Chia-I Wue8c7d752010-12-26 18:24:13 +08002643 if (!f)
2644 f = (gl_function) _glapi_get_proc_address((const char *) procName);
Jeremy Huddleston559e4f82011-06-15 00:27:55 -07002645 if (!f) {
2646 struct glx_context *gc = __glXGetCurrentContext();
2647
2648 if (gc != NULL && gc->vtable->get_proc_address != NULL)
2649 f = gc->vtable->get_proc_address((const char *) procName);
2650 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002651 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002652 return f;
2653}
2654
2655/**
2656 * Get the address of a named GL function. This is the GLX 1.4 name for
2657 * \c glXGetProcAddressARB.
2658 *
2659 * \param procName Name of a GL or GLX function.
2660 * \returns A pointer to the named function
2661 *
2662 * \sa glXGetProcAddressARB
2663 */
Kristian Høgsberg38c51a72010-07-28 10:20:41 -04002664_X_EXPORT void (*glXGetProcAddress(const GLubyte * procName)) (void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002665#if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002666 __attribute__ ((alias("glXGetProcAddressARB")));
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002667#else
2668{
2669 return glXGetProcAddressARB(procName);
2670}
2671#endif /* __GNUC__ */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002672
2673
Jeremy Huddleston80b280d2010-04-02 01:35:19 -07002674#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002675/**
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002676 * Get the unadjusted system time (UST). Currently, the UST is measured in
2677 * microseconds since Epoc. The actual resolution of the UST may vary from
2678 * system to system, and the units may vary from release to release.
2679 * Drivers should not call this function directly. They should instead use
2680 * \c glXGetProcAddress to obtain a pointer to the function.
2681 *
2682 * \param ust Location to store the 64-bit UST
2683 * \returns Zero on success or a negative errno value on failure.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002684 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002685 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2686 *
2687 * \since Internal API version 20030317.
2688 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002689_X_HIDDEN int
2690__glXGetUST(int64_t * ust)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002691{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002692 struct timeval tv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002693
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002694 if (ust == NULL) {
2695 return -EFAULT;
2696 }
2697
2698 if (gettimeofday(&tv, NULL) == 0) {
2699 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
2700 return 0;
2701 }
2702 else {
2703 return -errno;
2704 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002705}
2706#endif /* GLX_DIRECT_RENDERING */