Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1 | /* $XFree86: xc/lib/GL/glx/glxcmds.c,v 1.30 2004/01/30 20:33:06 alanh Exp $ */ |
| 2 | /* |
| 3 | ** License Applicability. Except to the extent portions of this file are |
| 4 | ** made subject to an alternative license as permitted in the SGI Free |
| 5 | ** Software License B, Version 1.1 (the "License"), the contents of this |
| 6 | ** file are subject only to the provisions of the License. You may not use |
| 7 | ** this file except in compliance with the License. You may obtain a copy |
| 8 | ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 |
| 9 | ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: |
| 10 | ** |
| 11 | ** http://oss.sgi.com/projects/FreeB |
| 12 | ** |
| 13 | ** Note that, as provided in the License, the Software is distributed on an |
| 14 | ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS |
| 15 | ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND |
| 16 | ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A |
| 17 | ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. |
| 18 | ** |
| 19 | ** Original Code. The Original Code is: OpenGL Sample Implementation, |
| 20 | ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, |
| 21 | ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. |
| 22 | ** Copyright in any portions created by third parties is as indicated |
| 23 | ** elsewhere herein. All Rights Reserved. |
| 24 | ** |
| 25 | ** Additional Notice Provisions: The application programming interfaces |
| 26 | ** established by SGI in conjunction with the Original Code are The |
| 27 | ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released |
| 28 | ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version |
| 29 | ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X |
| 30 | ** Window System(R) (Version 1.3), released October 19, 1998. This software |
| 31 | ** was created using the OpenGL(R) version 1.2.1 Sample Implementation |
| 32 | ** published by SGI, but has not been independently verified as being |
| 33 | ** compliant with the OpenGL(R) version 1.2.1 Specification. |
| 34 | ** |
| 35 | */ |
| 36 | |
| 37 | /** |
| 38 | * \file glxcmds.c |
| 39 | * Client-side GLX interface. |
| 40 | */ |
| 41 | |
| 42 | #include <inttypes.h> |
| 43 | #include "glxclient.h" |
Brian Paul | 82dfd4b | 2005-08-11 14:18:53 +0000 | [diff] [blame] | 44 | #include <X11/extensions/extutil.h> |
| 45 | #include <X11/extensions/Xext.h> |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 46 | #include <assert.h> |
| 47 | #include <string.h> |
| 48 | #include "glapi.h" |
| 49 | #ifdef GLX_DIRECT_RENDERING |
| 50 | #include "indirect_init.h" |
Brian Paul | 82dfd4b | 2005-08-11 14:18:53 +0000 | [diff] [blame] | 51 | #include <X11/extensions/xf86vmode.h> |
Ian Romanick | 5f1ba3e | 2005-07-26 02:44:01 +0000 | [diff] [blame] | 52 | #include "xf86dri.h" |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 53 | #endif |
| 54 | #include "glxextensions.h" |
| 55 | #include "glcontextmodes.h" |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 56 | #include "glheader.h" |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 57 | #include <sys/time.h> |
| 58 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 59 | static const char __glXGLXClientVendorName[] = "SGI"; |
| 60 | static const char __glXGLXClientVersion[] = "1.4"; |
| 61 | |
| 62 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 63 | /****************************************************************************/ |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 64 | |
| 65 | #ifdef GLX_DIRECT_RENDERING |
| 66 | |
| 67 | static Bool windowExistsFlag; |
| 68 | static int windowExistsErrorHandler(Display *dpy, XErrorEvent *xerr) |
| 69 | { |
| 70 | if (xerr->error_code == BadWindow) { |
| 71 | windowExistsFlag = GL_FALSE; |
| 72 | } |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Find drawables in the local hash that have been destroyed on the |
| 78 | * server. |
| 79 | * |
| 80 | * \param dpy Display to destroy drawables for |
| 81 | * \param screen Screen number to destroy drawables for |
| 82 | */ |
Kristian Høgsberg | 9590ba9 | 2007-05-11 13:24:34 -0400 | [diff] [blame] | 83 | static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc) |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 84 | { |
Kristian Høgsberg | fa72013 | 2007-05-11 13:54:44 -0400 | [diff] [blame] | 85 | XID draw; |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 86 | __GLXDRIdrawable *pdraw; |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 87 | XWindowAttributes xwa; |
| 88 | int (*oldXErrorHandler)(Display *, XErrorEvent *); |
| 89 | |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 90 | /* Set no-op error handler so Xlib doesn't bail out if the windows |
| 91 | * has alreay been destroyed on the server. */ |
| 92 | XSync(dpy, GL_FALSE); |
| 93 | oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler); |
| 94 | |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 95 | if (__glxHashFirst(sc->drawHash, &draw, (void *)&pdraw) == 1) { |
| 96 | do { |
| 97 | windowExistsFlag = GL_TRUE; |
| 98 | XGetWindowAttributes(dpy, draw, &xwa); /* dummy request */ |
| 99 | if (!windowExistsFlag) { |
| 100 | /* Destroy the local drawable data, if the drawable no |
| 101 | longer exists in the Xserver */ |
Kristian Høgsberg | 9110425 | 2008-03-12 02:18:12 -0400 | [diff] [blame] | 102 | (*pdraw->destroyDrawable)(pdraw); |
WuNian | 16099c1 | 2007-11-27 18:22:42 -0700 | [diff] [blame] | 103 | __glxHashDelete(sc->drawHash, draw); |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 104 | } |
| 105 | } while (__glxHashNext(sc->drawHash, &draw, (void *)&pdraw) == 1); |
| 106 | } |
| 107 | |
Chris Rankin | 1421bff | 2007-10-29 14:37:32 -0400 | [diff] [blame] | 108 | XSync(dpy, GL_FALSE); |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 109 | XSetErrorHandler(oldXErrorHandler); |
| 110 | } |
| 111 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 112 | /** |
| 113 | * Get the __DRIdrawable for the drawable associated with a GLXContext |
| 114 | * |
| 115 | * \param dpy The display associated with \c drawable. |
| 116 | * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved. |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 117 | * \param scrn_num If non-NULL, the drawables screen is stored there |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 118 | * \returns A pointer to the context's __DRIdrawable on success, or NULL if |
| 119 | * the drawable is not associated with a direct-rendering context. |
| 120 | */ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 121 | static __DRIdrawable * |
| 122 | GetDRIDrawable( Display *dpy, GLXDrawable drawable, int * const scrn_num ) |
| 123 | { |
| 124 | __GLXdisplayPrivate * const priv = __glXInitialize(dpy); |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 125 | __GLXDRIdrawable * const pdraw; |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 126 | const unsigned screen_count = ScreenCount(dpy); |
| 127 | unsigned i; |
| 128 | __GLXscreenConfigs *sc; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 129 | |
Kristian Høgsberg | 425f9ed | 2008-03-08 19:02:10 -0500 | [diff] [blame] | 130 | if (priv == NULL || priv->driDisplay == NULL) |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 131 | return NULL; |
| 132 | |
| 133 | for (i = 0; i < screen_count; i++) { |
| 134 | sc = &priv->screenConfigs[i]; |
| 135 | if (__glxHashLookup(sc->drawHash, drawable, (void *) &pdraw) == 0) { |
| 136 | if (scrn_num != NULL) |
| 137 | *scrn_num = i; |
Kristian Høgsberg | aceccda | 2007-05-10 15:52:22 -0400 | [diff] [blame] | 138 | return &pdraw->driDrawable; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
| 142 | return NULL; |
| 143 | } |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 144 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 145 | #endif |
| 146 | |
| 147 | |
| 148 | /** |
| 149 | * Get the GLX per-screen data structure associated with a GLX context. |
| 150 | * |
| 151 | * \param dpy Display for which the GLX per-screen information is to be |
| 152 | * retrieved. |
| 153 | * \param scrn Screen on \c dpy for which the GLX per-screen information is |
| 154 | * to be retrieved. |
| 155 | * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn |
| 156 | * specify a valid GLX screen, or NULL otherwise. |
| 157 | * |
| 158 | * \todo Should this function validate that \c scrn is within the screen |
| 159 | * number range for \c dpy? |
| 160 | */ |
| 161 | |
| 162 | static __GLXscreenConfigs * |
| 163 | GetGLXScreenConfigs(Display *dpy, int scrn) |
| 164 | { |
| 165 | __GLXdisplayPrivate * const priv = __glXInitialize(dpy); |
| 166 | |
| 167 | return (priv->screenConfigs != NULL) ? &priv->screenConfigs[scrn] : NULL; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | static int |
| 172 | GetGLXPrivScreenConfig( Display *dpy, int scrn, __GLXdisplayPrivate ** ppriv, |
| 173 | __GLXscreenConfigs ** ppsc ) |
| 174 | { |
| 175 | /* Initialize the extension, if needed . This has the added value |
| 176 | * of initializing/allocating the display private |
| 177 | */ |
| 178 | |
| 179 | if ( dpy == NULL ) { |
| 180 | return GLX_NO_EXTENSION; |
| 181 | } |
| 182 | |
| 183 | *ppriv = __glXInitialize(dpy); |
| 184 | if ( *ppriv == NULL ) { |
| 185 | return GLX_NO_EXTENSION; |
| 186 | } |
| 187 | |
| 188 | /* Check screen number to see if its valid */ |
| 189 | if ((scrn < 0) || (scrn >= ScreenCount(dpy))) { |
| 190 | return GLX_BAD_SCREEN; |
| 191 | } |
| 192 | |
| 193 | /* Check to see if the GL is supported on this screen */ |
| 194 | *ppsc = &((*ppriv)->screenConfigs[scrn]); |
| 195 | if ( (*ppsc)->configs == NULL ) { |
| 196 | /* No support for GL on this screen regardless of visual */ |
| 197 | return GLX_BAD_VISUAL; |
| 198 | } |
| 199 | |
| 200 | return Success; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | /** |
| 205 | * Determine if a \c GLXFBConfig supplied by the application is valid. |
| 206 | * |
| 207 | * \param dpy Application supplied \c Display pointer. |
| 208 | * \param config Application supplied \c GLXFBConfig. |
| 209 | * |
| 210 | * \returns If the \c GLXFBConfig is valid, the a pointer to the matching |
| 211 | * \c __GLcontextModes structure is returned. Otherwise, \c NULL |
| 212 | * is returned. |
| 213 | */ |
| 214 | static __GLcontextModes * |
| 215 | ValidateGLXFBConfig( Display * dpy, GLXFBConfig config ) |
| 216 | { |
| 217 | __GLXdisplayPrivate * const priv = __glXInitialize(dpy); |
| 218 | const unsigned num_screens = ScreenCount(dpy); |
| 219 | unsigned i; |
| 220 | const __GLcontextModes * modes; |
| 221 | |
| 222 | |
| 223 | if ( priv != NULL ) { |
| 224 | for ( i = 0 ; i < num_screens ; i++ ) { |
| 225 | for ( modes = priv->screenConfigs[i].configs |
| 226 | ; modes != NULL |
| 227 | ; modes = modes->next ) { |
| 228 | if ( modes == (__GLcontextModes *) config ) { |
| 229 | return (__GLcontextModes *) config; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | return NULL; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /** |
| 240 | * \todo It should be possible to move the allocate of \c client_state_private |
| 241 | * later in the function for direct-rendering contexts. Direct-rendering |
| 242 | * contexts don't need to track client state, so they don't need that memory |
| 243 | * at all. |
| 244 | * |
| 245 | * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new |
| 246 | * function called \c __glXAllocateClientState that allocates the memory and |
| 247 | * does all the initialization (including the pixel pack / unpack). |
| 248 | */ |
| 249 | static |
| 250 | GLXContext AllocateGLXContext( Display *dpy ) |
| 251 | { |
| 252 | GLXContext gc; |
| 253 | int bufSize; |
| 254 | CARD8 opcode; |
| 255 | __GLXattribute *state; |
| 256 | |
| 257 | if (!dpy) |
| 258 | return NULL; |
| 259 | |
| 260 | opcode = __glXSetupForCommand(dpy); |
| 261 | if (!opcode) { |
| 262 | return NULL; |
| 263 | } |
| 264 | |
| 265 | /* Allocate our context record */ |
| 266 | gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec)); |
| 267 | if (!gc) { |
| 268 | /* Out of memory */ |
| 269 | return NULL; |
| 270 | } |
| 271 | memset(gc, 0, sizeof(struct __GLXcontextRec)); |
| 272 | |
| 273 | state = Xmalloc(sizeof(struct __GLXattributeRec)); |
| 274 | if (state == NULL) { |
| 275 | /* Out of memory */ |
| 276 | Xfree(gc); |
| 277 | return NULL; |
| 278 | } |
| 279 | gc->client_state_private = state; |
| 280 | memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec)); |
| 281 | state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL); |
| 282 | |
| 283 | /* |
| 284 | ** Create a temporary buffer to hold GLX rendering commands. The size |
| 285 | ** of the buffer is selected so that the maximum number of GLX rendering |
| 286 | ** commands can fit in a single X packet and still have room in the X |
| 287 | ** packet for the GLXRenderReq header. |
| 288 | */ |
| 289 | |
| 290 | bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq; |
| 291 | gc->buf = (GLubyte *) Xmalloc(bufSize); |
| 292 | if (!gc->buf) { |
| 293 | Xfree(gc->client_state_private); |
| 294 | Xfree(gc); |
| 295 | return NULL; |
| 296 | } |
| 297 | gc->bufSize = bufSize; |
| 298 | |
| 299 | /* Fill in the new context */ |
| 300 | gc->renderMode = GL_RENDER; |
| 301 | |
| 302 | state->storePack.alignment = 4; |
| 303 | state->storeUnpack.alignment = 4; |
| 304 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 305 | gc->attributes.stackPointer = &gc->attributes.stack[0]; |
| 306 | |
| 307 | /* |
| 308 | ** PERFORMANCE NOTE: A mode dependent fill image can speed things up. |
| 309 | ** Other code uses the fastImageUnpack bit, but it is never set |
| 310 | ** to GL_TRUE. |
| 311 | */ |
| 312 | gc->fastImageUnpack = GL_FALSE; |
| 313 | gc->fillImage = __glFillImage; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 314 | gc->pc = gc->buf; |
| 315 | gc->bufEnd = gc->buf + bufSize; |
Xiang, Haihao | ae2c31e | 2008-03-18 15:02:57 +0800 | [diff] [blame^] | 316 | gc->isDirect = GL_FALSE; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 317 | if (__glXDebug) { |
| 318 | /* |
| 319 | ** Set limit register so that there will be one command per packet |
| 320 | */ |
| 321 | gc->limit = gc->buf; |
| 322 | } else { |
| 323 | gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE; |
| 324 | } |
| 325 | gc->createDpy = dpy; |
| 326 | gc->majorOpcode = opcode; |
| 327 | |
| 328 | /* |
| 329 | ** Constrain the maximum drawing command size allowed to be |
| 330 | ** transfered using the X_GLXRender protocol request. First |
| 331 | ** constrain by a software limit, then constrain by the protocl |
| 332 | ** limit. |
| 333 | */ |
| 334 | if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) { |
| 335 | bufSize = __GLX_RENDER_CMD_SIZE_LIMIT; |
| 336 | } |
| 337 | if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) { |
| 338 | bufSize = __GLX_MAX_RENDER_CMD_SIZE; |
| 339 | } |
| 340 | gc->maxSmallRenderCommandSize = bufSize; |
| 341 | return gc; |
| 342 | } |
| 343 | |
| 344 | |
| 345 | /** |
| 346 | * Create a new context. Exactly one of \c vis and \c fbconfig should be |
| 347 | * non-NULL. |
| 348 | * |
| 349 | * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or |
| 350 | * SGIX_fbconfig protocol be used? |
| 351 | * \param renderType For FBConfigs, what is the rendering type? |
| 352 | */ |
| 353 | |
| 354 | static GLXContext |
| 355 | CreateContext(Display *dpy, XVisualInfo *vis, |
| 356 | const __GLcontextModes * const fbconfig, |
| 357 | GLXContext shareList, |
| 358 | Bool allowDirect, GLXContextID contextID, |
| 359 | Bool use_glx_1_3, int renderType) |
| 360 | { |
| 361 | GLXContext gc; |
Kristian Høgsberg | 3731159 | 2008-03-10 17:59:46 -0400 | [diff] [blame] | 362 | #ifdef GLX_DIRECT_RENDERING |
| 363 | int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen; |
| 364 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); |
| 365 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 366 | |
| 367 | if ( dpy == NULL ) |
| 368 | return NULL; |
| 369 | |
| 370 | gc = AllocateGLXContext(dpy); |
| 371 | if (!gc) |
| 372 | return NULL; |
| 373 | |
| 374 | if (None == contextID) { |
| 375 | if ( (vis == NULL) && (fbconfig == NULL) ) |
| 376 | return NULL; |
| 377 | |
| 378 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 3731159 | 2008-03-10 17:59:46 -0400 | [diff] [blame] | 379 | if (allowDirect && psc->driScreen) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 380 | const __GLcontextModes * mode; |
Kristian Høgsberg | 8e66c3d | 2007-11-05 17:02:03 -0500 | [diff] [blame] | 381 | |
| 382 | if (fbconfig == NULL) { |
| 383 | mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid); |
| 384 | if (mode == NULL) { |
| 385 | xError error; |
| 386 | |
| 387 | error.errorCode = BadValue; |
| 388 | error.resourceID = vis->visualid; |
| 389 | error.sequenceNumber = dpy->request; |
| 390 | error.type = X_Error; |
| 391 | error.majorCode = gc->majorOpcode; |
| 392 | error.minorCode = X_GLXCreateContext; |
| 393 | _XError(dpy, &error); |
| 394 | return None; |
| 395 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 396 | } |
| 397 | else { |
| 398 | mode = fbconfig; |
| 399 | } |
| 400 | |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 401 | gc->driContext = psc->driScreen->createContext(psc, mode, gc, |
| 402 | shareList, |
| 403 | renderType); |
| 404 | if (gc->driContext != NULL) { |
| 405 | gc->screen = mode->screen; |
| 406 | gc->psc = psc; |
| 407 | gc->mode = mode; |
Xiang, Haihao | ae2c31e | 2008-03-18 15:02:57 +0800 | [diff] [blame^] | 408 | gc->isDirect = GL_TRUE; |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 409 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 410 | } |
| 411 | #endif |
| 412 | |
| 413 | LockDisplay(dpy); |
| 414 | if ( fbconfig == NULL ) { |
| 415 | xGLXCreateContextReq *req; |
| 416 | |
| 417 | /* Send the glXCreateContext request */ |
| 418 | GetReq(GLXCreateContext,req); |
| 419 | req->reqType = gc->majorOpcode; |
| 420 | req->glxCode = X_GLXCreateContext; |
| 421 | req->context = gc->xid = XAllocID(dpy); |
| 422 | req->visual = vis->visualid; |
| 423 | req->screen = vis->screen; |
| 424 | req->shareList = shareList ? shareList->xid : None; |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 425 | req->isDirect = gc->driContext != NULL; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 426 | } |
| 427 | else if ( use_glx_1_3 ) { |
| 428 | xGLXCreateNewContextReq *req; |
| 429 | |
| 430 | /* Send the glXCreateNewContext request */ |
| 431 | GetReq(GLXCreateNewContext,req); |
| 432 | req->reqType = gc->majorOpcode; |
| 433 | req->glxCode = X_GLXCreateNewContext; |
| 434 | req->context = gc->xid = XAllocID(dpy); |
| 435 | req->fbconfig = fbconfig->fbconfigID; |
| 436 | req->screen = fbconfig->screen; |
| 437 | req->renderType = renderType; |
| 438 | req->shareList = shareList ? shareList->xid : None; |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 439 | req->isDirect = gc->driContext != NULL; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 440 | } |
| 441 | else { |
| 442 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 443 | xGLXCreateContextWithConfigSGIXReq *req; |
| 444 | |
| 445 | /* Send the glXCreateNewContext request */ |
| 446 | GetReqExtra(GLXVendorPrivateWithReply, |
| 447 | sz_xGLXCreateContextWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq); |
| 448 | req = (xGLXCreateContextWithConfigSGIXReq *)vpreq; |
| 449 | req->reqType = gc->majorOpcode; |
| 450 | req->glxCode = X_GLXVendorPrivateWithReply; |
| 451 | req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX; |
| 452 | req->context = gc->xid = XAllocID(dpy); |
| 453 | req->fbconfig = fbconfig->fbconfigID; |
| 454 | req->screen = fbconfig->screen; |
| 455 | req->renderType = renderType; |
| 456 | req->shareList = shareList ? shareList->xid : None; |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 457 | req->isDirect = gc->driContext != NULL; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | UnlockDisplay(dpy); |
| 461 | SyncHandle(); |
| 462 | gc->imported = GL_FALSE; |
| 463 | } |
| 464 | else { |
| 465 | gc->xid = contextID; |
| 466 | gc->imported = GL_TRUE; |
| 467 | } |
| 468 | |
| 469 | return gc; |
| 470 | } |
| 471 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 472 | PUBLIC GLXContext glXCreateContext(Display *dpy, XVisualInfo *vis, |
| 473 | GLXContext shareList, Bool allowDirect) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 474 | { |
| 475 | return CreateContext(dpy, vis, NULL, shareList, allowDirect, None, |
| 476 | False, 0); |
| 477 | } |
| 478 | |
Kristian Høgsberg | 3d28a26 | 2008-03-08 22:28:01 -0500 | [diff] [blame] | 479 | _X_HIDDEN void __glXFreeContext(__GLXcontext *gc) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 480 | { |
| 481 | if (gc->vendor) XFree((char *) gc->vendor); |
| 482 | if (gc->renderer) XFree((char *) gc->renderer); |
| 483 | if (gc->version) XFree((char *) gc->version); |
| 484 | if (gc->extensions) XFree((char *) gc->extensions); |
| 485 | __glFreeAttributeState(gc); |
| 486 | XFree((char *) gc->buf); |
| 487 | Xfree((char *) gc->client_state_private); |
| 488 | XFree((char *) gc); |
| 489 | |
| 490 | } |
| 491 | |
| 492 | /* |
| 493 | ** Destroy the named context |
| 494 | */ |
| 495 | static void |
| 496 | DestroyContext(Display *dpy, GLXContext gc) |
| 497 | { |
| 498 | xGLXDestroyContextReq *req; |
| 499 | GLXContextID xid; |
| 500 | CARD8 opcode; |
| 501 | GLboolean imported; |
| 502 | |
| 503 | opcode = __glXSetupForCommand(dpy); |
| 504 | if (!opcode || !gc) { |
| 505 | return; |
| 506 | } |
| 507 | |
| 508 | __glXLock(); |
| 509 | xid = gc->xid; |
| 510 | imported = gc->imported; |
| 511 | gc->xid = None; |
| 512 | |
| 513 | #ifdef GLX_DIRECT_RENDERING |
| 514 | /* Destroy the direct rendering context */ |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 515 | if (gc->driContext) { |
| 516 | (*gc->driContext->destroyContext)(gc->driContext, gc->psc, dpy); |
| 517 | gc->driContext = NULL; |
Kristian Høgsberg | 9590ba9 | 2007-05-11 13:24:34 -0400 | [diff] [blame] | 518 | GarbageCollectDRIDrawables(dpy, gc->psc); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 519 | } |
| 520 | #endif |
| 521 | |
| 522 | if (gc->currentDpy) { |
| 523 | /* Have to free later cuz it's in use now */ |
| 524 | __glXUnlock(); |
| 525 | } else { |
| 526 | /* Destroy the handle if not current to anybody */ |
| 527 | __glXUnlock(); |
| 528 | __glXFreeContext(gc); |
| 529 | } |
| 530 | |
| 531 | if (!imported) { |
| 532 | /* |
| 533 | ** This dpy also created the server side part of the context. |
| 534 | ** Send the glXDestroyContext request. |
| 535 | */ |
| 536 | LockDisplay(dpy); |
| 537 | GetReq(GLXDestroyContext,req); |
| 538 | req->reqType = opcode; |
| 539 | req->glxCode = X_GLXDestroyContext; |
| 540 | req->context = xid; |
| 541 | UnlockDisplay(dpy); |
| 542 | SyncHandle(); |
| 543 | } |
| 544 | } |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 545 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 546 | PUBLIC void glXDestroyContext(Display *dpy, GLXContext gc) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 547 | { |
| 548 | DestroyContext(dpy, gc); |
| 549 | } |
| 550 | |
| 551 | /* |
| 552 | ** Return the major and minor version #s for the GLX extension |
| 553 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 554 | PUBLIC Bool glXQueryVersion(Display *dpy, int *major, int *minor) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 555 | { |
| 556 | __GLXdisplayPrivate *priv; |
| 557 | |
| 558 | /* Init the extension. This fetches the major and minor version. */ |
| 559 | priv = __glXInitialize(dpy); |
| 560 | if (!priv) return GL_FALSE; |
| 561 | |
| 562 | if (major) *major = priv->majorVersion; |
| 563 | if (minor) *minor = priv->minorVersion; |
| 564 | return GL_TRUE; |
| 565 | } |
| 566 | |
| 567 | /* |
| 568 | ** Query the existance of the GLX extension |
| 569 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 570 | PUBLIC Bool glXQueryExtension(Display *dpy, int *errorBase, int *eventBase) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 571 | { |
| 572 | int major_op, erb, evb; |
| 573 | Bool rv; |
| 574 | |
| 575 | rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb); |
| 576 | if (rv) { |
| 577 | if (errorBase) *errorBase = erb; |
| 578 | if (eventBase) *eventBase = evb; |
| 579 | } |
| 580 | return rv; |
| 581 | } |
| 582 | |
| 583 | /* |
| 584 | ** Put a barrier in the token stream that forces the GL to finish its |
| 585 | ** work before X can proceed. |
| 586 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 587 | PUBLIC void glXWaitGL(void) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 588 | { |
| 589 | xGLXWaitGLReq *req; |
| 590 | GLXContext gc = __glXGetCurrentContext(); |
| 591 | Display *dpy = gc->currentDpy; |
| 592 | |
| 593 | if (!dpy) return; |
| 594 | |
| 595 | /* Flush any pending commands out */ |
| 596 | __glXFlushRenderBuffer(gc, gc->pc); |
| 597 | |
| 598 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 599 | if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 600 | /* This bit of ugliness unwraps the glFinish function */ |
| 601 | #ifdef glFinish |
| 602 | #undef glFinish |
| 603 | #endif |
| 604 | glFinish(); |
| 605 | return; |
| 606 | } |
| 607 | #endif |
| 608 | |
| 609 | /* Send the glXWaitGL request */ |
| 610 | LockDisplay(dpy); |
| 611 | GetReq(GLXWaitGL,req); |
| 612 | req->reqType = gc->majorOpcode; |
| 613 | req->glxCode = X_GLXWaitGL; |
| 614 | req->contextTag = gc->currentContextTag; |
| 615 | UnlockDisplay(dpy); |
| 616 | SyncHandle(); |
| 617 | } |
| 618 | |
| 619 | /* |
| 620 | ** Put a barrier in the token stream that forces X to finish its |
| 621 | ** work before GL can proceed. |
| 622 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 623 | PUBLIC void glXWaitX(void) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 624 | { |
| 625 | xGLXWaitXReq *req; |
| 626 | GLXContext gc = __glXGetCurrentContext(); |
| 627 | Display *dpy = gc->currentDpy; |
| 628 | |
| 629 | if (!dpy) return; |
| 630 | |
| 631 | /* Flush any pending commands out */ |
| 632 | __glXFlushRenderBuffer(gc, gc->pc); |
| 633 | |
| 634 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 635 | if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 636 | XSync(dpy, False); |
| 637 | return; |
| 638 | } |
| 639 | #endif |
| 640 | |
| 641 | /* |
| 642 | ** Send the glXWaitX request. |
| 643 | */ |
| 644 | LockDisplay(dpy); |
| 645 | GetReq(GLXWaitX,req); |
| 646 | req->reqType = gc->majorOpcode; |
| 647 | req->glxCode = X_GLXWaitX; |
| 648 | req->contextTag = gc->currentContextTag; |
| 649 | UnlockDisplay(dpy); |
| 650 | SyncHandle(); |
| 651 | } |
| 652 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 653 | PUBLIC void glXUseXFont(Font font, int first, int count, int listBase) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 654 | { |
| 655 | xGLXUseXFontReq *req; |
| 656 | GLXContext gc = __glXGetCurrentContext(); |
| 657 | Display *dpy = gc->currentDpy; |
| 658 | |
| 659 | if (!dpy) return; |
| 660 | |
| 661 | /* Flush any pending commands out */ |
| 662 | (void) __glXFlushRenderBuffer(gc, gc->pc); |
| 663 | |
| 664 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 665 | if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 666 | DRI_glXUseXFont(font, first, count, listBase); |
| 667 | return; |
| 668 | } |
| 669 | #endif |
| 670 | |
| 671 | /* Send the glXUseFont request */ |
| 672 | LockDisplay(dpy); |
| 673 | GetReq(GLXUseXFont,req); |
| 674 | req->reqType = gc->majorOpcode; |
| 675 | req->glxCode = X_GLXUseXFont; |
| 676 | req->contextTag = gc->currentContextTag; |
| 677 | req->font = font; |
| 678 | req->first = first; |
| 679 | req->count = count; |
| 680 | req->listBase = listBase; |
| 681 | UnlockDisplay(dpy); |
| 682 | SyncHandle(); |
| 683 | } |
| 684 | |
| 685 | /************************************************************************/ |
| 686 | |
| 687 | /* |
| 688 | ** Copy the source context to the destination context using the |
| 689 | ** attribute "mask". |
| 690 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 691 | PUBLIC void glXCopyContext(Display *dpy, GLXContext source, |
| 692 | GLXContext dest, unsigned long mask) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 693 | { |
| 694 | xGLXCopyContextReq *req; |
| 695 | GLXContext gc = __glXGetCurrentContext(); |
| 696 | GLXContextTag tag; |
| 697 | CARD8 opcode; |
| 698 | |
| 699 | opcode = __glXSetupForCommand(dpy); |
| 700 | if (!opcode) { |
| 701 | return; |
| 702 | } |
| 703 | |
| 704 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 705 | if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 706 | /* NOT_DONE: This does not work yet */ |
| 707 | } |
| 708 | #endif |
| 709 | |
| 710 | /* |
| 711 | ** If the source is the current context, send its tag so that the context |
| 712 | ** can be flushed before the copy. |
| 713 | */ |
| 714 | if (source == gc && dpy == gc->currentDpy) { |
| 715 | tag = gc->currentContextTag; |
| 716 | } else { |
| 717 | tag = 0; |
| 718 | } |
| 719 | |
| 720 | /* Send the glXCopyContext request */ |
| 721 | LockDisplay(dpy); |
| 722 | GetReq(GLXCopyContext,req); |
| 723 | req->reqType = opcode; |
| 724 | req->glxCode = X_GLXCopyContext; |
| 725 | req->source = source ? source->xid : None; |
| 726 | req->dest = dest ? dest->xid : None; |
| 727 | req->mask = mask; |
| 728 | req->contextTag = tag; |
| 729 | UnlockDisplay(dpy); |
| 730 | SyncHandle(); |
| 731 | } |
| 732 | |
| 733 | |
| 734 | /** |
| 735 | * Determine if a context uses direct rendering. |
| 736 | * |
| 737 | * \param dpy Display where the context was created. |
| 738 | * \param contextID ID of the context to be tested. |
| 739 | * |
| 740 | * \returns \c GL_TRUE if the context is direct rendering or not. |
| 741 | */ |
| 742 | static Bool __glXIsDirect(Display *dpy, GLXContextID contextID) |
| 743 | { |
| 744 | xGLXIsDirectReq *req; |
| 745 | xGLXIsDirectReply reply; |
| 746 | CARD8 opcode; |
| 747 | |
| 748 | opcode = __glXSetupForCommand(dpy); |
| 749 | if (!opcode) { |
| 750 | return GL_FALSE; |
| 751 | } |
| 752 | |
| 753 | /* Send the glXIsDirect request */ |
| 754 | LockDisplay(dpy); |
| 755 | GetReq(GLXIsDirect,req); |
| 756 | req->reqType = opcode; |
| 757 | req->glxCode = X_GLXIsDirect; |
| 758 | req->context = contextID; |
| 759 | _XReply(dpy, (xReply*) &reply, 0, False); |
| 760 | UnlockDisplay(dpy); |
| 761 | SyncHandle(); |
| 762 | |
| 763 | return reply.isDirect; |
| 764 | } |
| 765 | |
Ian Romanick | c39bf5e | 2005-07-24 06:29:14 +0000 | [diff] [blame] | 766 | /** |
| 767 | * \todo |
| 768 | * Shouldn't this function \b always return \c GL_FALSE when |
| 769 | * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with |
| 770 | * the GLX protocol here at all? |
| 771 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 772 | PUBLIC Bool glXIsDirect(Display *dpy, GLXContext gc) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 773 | { |
| 774 | if (!gc) { |
| 775 | return GL_FALSE; |
| 776 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 777 | } else if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 778 | return GL_TRUE; |
| 779 | #endif |
| 780 | } |
| 781 | return __glXIsDirect(dpy, gc->xid); |
| 782 | } |
| 783 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 784 | PUBLIC GLXPixmap glXCreateGLXPixmap(Display *dpy, XVisualInfo *vis, |
| 785 | Pixmap pixmap) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 786 | { |
| 787 | xGLXCreateGLXPixmapReq *req; |
| 788 | GLXPixmap xid; |
| 789 | CARD8 opcode; |
| 790 | |
| 791 | opcode = __glXSetupForCommand(dpy); |
| 792 | if (!opcode) { |
| 793 | return None; |
| 794 | } |
| 795 | |
| 796 | /* Send the glXCreateGLXPixmap request */ |
| 797 | LockDisplay(dpy); |
| 798 | GetReq(GLXCreateGLXPixmap,req); |
| 799 | req->reqType = opcode; |
| 800 | req->glxCode = X_GLXCreateGLXPixmap; |
| 801 | req->screen = vis->screen; |
| 802 | req->visual = vis->visualid; |
| 803 | req->pixmap = pixmap; |
| 804 | req->glxpixmap = xid = XAllocID(dpy); |
| 805 | UnlockDisplay(dpy); |
| 806 | SyncHandle(); |
| 807 | return xid; |
| 808 | } |
| 809 | |
| 810 | /* |
| 811 | ** Destroy the named pixmap |
| 812 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 813 | PUBLIC void glXDestroyGLXPixmap(Display *dpy, GLXPixmap glxpixmap) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 814 | { |
| 815 | xGLXDestroyGLXPixmapReq *req; |
| 816 | CARD8 opcode; |
| 817 | |
| 818 | opcode = __glXSetupForCommand(dpy); |
| 819 | if (!opcode) { |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | /* Send the glXDestroyGLXPixmap request */ |
| 824 | LockDisplay(dpy); |
| 825 | GetReq(GLXDestroyGLXPixmap,req); |
| 826 | req->reqType = opcode; |
| 827 | req->glxCode = X_GLXDestroyGLXPixmap; |
| 828 | req->glxpixmap = glxpixmap; |
| 829 | UnlockDisplay(dpy); |
| 830 | SyncHandle(); |
| 831 | } |
| 832 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 833 | PUBLIC void glXSwapBuffers(Display *dpy, GLXDrawable drawable) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 834 | { |
| 835 | xGLXSwapBuffersReq *req; |
| 836 | GLXContext gc; |
| 837 | GLXContextTag tag; |
| 838 | CARD8 opcode; |
| 839 | #ifdef GLX_DIRECT_RENDERING |
| 840 | __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, NULL ); |
| 841 | |
| 842 | if ( pdraw != NULL ) { |
Kristian Høgsberg | 5987a03 | 2007-05-11 16:43:20 -0400 | [diff] [blame] | 843 | (*pdraw->swapBuffers)(pdraw); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 844 | return; |
| 845 | } |
| 846 | #endif |
| 847 | |
| 848 | opcode = __glXSetupForCommand(dpy); |
| 849 | if (!opcode) { |
| 850 | return; |
| 851 | } |
| 852 | |
| 853 | /* |
| 854 | ** 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 | */ |
| 857 | gc = __glXGetCurrentContext(); |
| 858 | if ((gc != NULL) && (dpy == gc->currentDpy) && |
| 859 | ((drawable == gc->currentDrawable) || (drawable == gc->currentReadable)) ) { |
| 860 | tag = gc->currentContextTag; |
| 861 | } else { |
| 862 | tag = 0; |
| 863 | } |
| 864 | |
| 865 | /* Send the glXSwapBuffers request */ |
| 866 | LockDisplay(dpy); |
| 867 | GetReq(GLXSwapBuffers,req); |
| 868 | req->reqType = opcode; |
| 869 | req->glxCode = X_GLXSwapBuffers; |
| 870 | req->drawable = drawable; |
| 871 | req->contextTag = tag; |
| 872 | UnlockDisplay(dpy); |
| 873 | SyncHandle(); |
| 874 | XFlush(dpy); |
| 875 | } |
| 876 | |
| 877 | |
| 878 | /* |
| 879 | ** Return configuration information for the given display, screen and |
| 880 | ** visual combination. |
| 881 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 882 | PUBLIC int glXGetConfig(Display *dpy, XVisualInfo *vis, int attribute, |
| 883 | int *value_return) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 884 | { |
| 885 | __GLXdisplayPrivate *priv; |
| 886 | __GLXscreenConfigs *psc; |
Kristian Høgsberg | 6c533ea | 2007-10-16 16:07:47 -0400 | [diff] [blame] | 887 | __GLcontextModes *modes; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 888 | int status; |
| 889 | |
| 890 | status = GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ); |
| 891 | if ( status == Success ) { |
Kristian Høgsberg | 6c533ea | 2007-10-16 16:07:47 -0400 | [diff] [blame] | 892 | modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 893 | |
| 894 | /* Lookup attribute after first finding a match on the visual */ |
| 895 | if ( modes != NULL ) { |
| 896 | return _gl_get_context_mode_data( modes, attribute, value_return ); |
| 897 | } |
| 898 | |
| 899 | status = GLX_BAD_VISUAL; |
| 900 | } |
| 901 | |
| 902 | /* |
| 903 | ** If we can't find the config for this visual, this visual is not |
| 904 | ** supported by the OpenGL implementation on the server. |
| 905 | */ |
| 906 | if ( (status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL) ) { |
| 907 | *value_return = GL_FALSE; |
| 908 | status = Success; |
| 909 | } |
| 910 | |
| 911 | return status; |
| 912 | } |
| 913 | |
| 914 | /************************************************************************/ |
| 915 | |
| 916 | static void |
| 917 | init_fbconfig_for_chooser( __GLcontextModes * config, |
| 918 | GLboolean fbconfig_style_tags ) |
| 919 | { |
| 920 | memset( config, 0, sizeof( __GLcontextModes ) ); |
| 921 | config->visualID = (XID) GLX_DONT_CARE; |
| 922 | config->visualType = GLX_DONT_CARE; |
| 923 | |
| 924 | /* glXChooseFBConfig specifies different defaults for these two than |
| 925 | * glXChooseVisual. |
| 926 | */ |
| 927 | if ( fbconfig_style_tags ) { |
| 928 | config->rgbMode = GL_TRUE; |
| 929 | config->doubleBufferMode = GLX_DONT_CARE; |
| 930 | } |
| 931 | |
| 932 | config->visualRating = GLX_DONT_CARE; |
| 933 | config->transparentPixel = GLX_NONE; |
| 934 | config->transparentRed = GLX_DONT_CARE; |
| 935 | config->transparentGreen = GLX_DONT_CARE; |
| 936 | config->transparentBlue = GLX_DONT_CARE; |
| 937 | config->transparentAlpha = GLX_DONT_CARE; |
| 938 | config->transparentIndex = GLX_DONT_CARE; |
| 939 | |
| 940 | config->drawableType = GLX_WINDOW_BIT; |
| 941 | config->renderType = (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT; |
| 942 | config->xRenderable = GLX_DONT_CARE; |
| 943 | config->fbconfigID = (GLXFBConfigID)(GLX_DONT_CARE); |
| 944 | |
| 945 | config->swapMethod = GLX_DONT_CARE; |
| 946 | } |
| 947 | |
| 948 | #define MATCH_DONT_CARE( param ) \ |
| 949 | do { \ |
| 950 | if ( (a-> param != GLX_DONT_CARE) \ |
| 951 | && (a-> param != b-> param) ) { \ |
| 952 | return False; \ |
| 953 | } \ |
| 954 | } while ( 0 ) |
| 955 | |
| 956 | #define MATCH_MINIMUM( param ) \ |
| 957 | do { \ |
| 958 | if ( (a-> param != GLX_DONT_CARE) \ |
| 959 | && (a-> param > b-> param) ) { \ |
| 960 | return False; \ |
| 961 | } \ |
| 962 | } while ( 0 ) |
| 963 | |
| 964 | #define MATCH_EXACT( param ) \ |
| 965 | do { \ |
| 966 | if ( a-> param != b-> param) { \ |
| 967 | return False; \ |
| 968 | } \ |
| 969 | } while ( 0 ) |
| 970 | |
| 971 | /** |
| 972 | * Determine if two GLXFBConfigs are compatible. |
| 973 | * |
| 974 | * \param a Application specified config to test. |
| 975 | * \param b Server specified config to test against \c a. |
| 976 | */ |
| 977 | static Bool |
| 978 | fbconfigs_compatible( const __GLcontextModes * const a, |
| 979 | const __GLcontextModes * const b ) |
| 980 | { |
| 981 | MATCH_DONT_CARE( doubleBufferMode ); |
| 982 | MATCH_DONT_CARE( visualType ); |
| 983 | MATCH_DONT_CARE( visualRating ); |
| 984 | MATCH_DONT_CARE( xRenderable ); |
| 985 | MATCH_DONT_CARE( fbconfigID ); |
| 986 | MATCH_DONT_CARE( swapMethod ); |
| 987 | |
| 988 | MATCH_MINIMUM( rgbBits ); |
| 989 | MATCH_MINIMUM( numAuxBuffers ); |
| 990 | MATCH_MINIMUM( redBits ); |
| 991 | MATCH_MINIMUM( greenBits ); |
| 992 | MATCH_MINIMUM( blueBits ); |
| 993 | MATCH_MINIMUM( alphaBits ); |
| 994 | MATCH_MINIMUM( depthBits ); |
| 995 | MATCH_MINIMUM( stencilBits ); |
| 996 | MATCH_MINIMUM( accumRedBits ); |
| 997 | MATCH_MINIMUM( accumGreenBits ); |
| 998 | MATCH_MINIMUM( accumBlueBits ); |
| 999 | MATCH_MINIMUM( accumAlphaBits ); |
| 1000 | MATCH_MINIMUM( sampleBuffers ); |
| 1001 | MATCH_MINIMUM( maxPbufferWidth ); |
| 1002 | MATCH_MINIMUM( maxPbufferHeight ); |
| 1003 | MATCH_MINIMUM( maxPbufferPixels ); |
| 1004 | MATCH_MINIMUM( samples ); |
| 1005 | |
| 1006 | MATCH_DONT_CARE( stereoMode ); |
| 1007 | MATCH_EXACT( level ); |
| 1008 | |
| 1009 | if ( ((a->drawableType & b->drawableType) == 0) |
| 1010 | || ((a->renderType & b->renderType) == 0) ) { |
| 1011 | return False; |
| 1012 | } |
| 1013 | |
| 1014 | |
| 1015 | /* There is a bug in a few of the XFree86 DDX drivers. They contain |
| 1016 | * visuals with a "transparent type" of 0 when they really mean GLX_NONE. |
| 1017 | * Technically speaking, it is a bug in the DDX driver, but there is |
| 1018 | * enough of an installed base to work around the problem here. In any |
| 1019 | * case, 0 is not a valid value of the transparent type, so we'll treat 0 |
| 1020 | * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and |
| 1021 | * 0 from the server to be a match to maintain backward compatibility with |
| 1022 | * the (broken) drivers. |
| 1023 | */ |
| 1024 | |
| 1025 | if ( a->transparentPixel != GLX_DONT_CARE |
| 1026 | && a->transparentPixel != 0 ) { |
| 1027 | if ( a->transparentPixel == GLX_NONE ) { |
| 1028 | if ( b->transparentPixel != GLX_NONE && b->transparentPixel != 0 ) |
| 1029 | return False; |
| 1030 | } else { |
| 1031 | MATCH_EXACT( transparentPixel ); |
| 1032 | } |
| 1033 | |
| 1034 | switch ( a->transparentPixel ) { |
| 1035 | case GLX_TRANSPARENT_RGB: |
| 1036 | MATCH_DONT_CARE( transparentRed ); |
| 1037 | MATCH_DONT_CARE( transparentGreen ); |
| 1038 | MATCH_DONT_CARE( transparentBlue ); |
| 1039 | MATCH_DONT_CARE( transparentAlpha ); |
| 1040 | break; |
| 1041 | |
| 1042 | case GLX_TRANSPARENT_INDEX: |
| 1043 | MATCH_DONT_CARE( transparentIndex ); |
| 1044 | break; |
| 1045 | |
| 1046 | default: |
| 1047 | break; |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | return True; |
| 1052 | } |
| 1053 | |
| 1054 | |
| 1055 | /* There's some trickly language in the GLX spec about how this is supposed |
| 1056 | * to work. Basically, if a given component size is either not specified |
| 1057 | * or the requested size is zero, it is supposed to act like PERFER_SMALLER. |
| 1058 | * Well, that's really hard to do with the code as-is. This behavior is |
| 1059 | * closer to correct, but still not technically right. |
| 1060 | */ |
| 1061 | #define PREFER_LARGER_OR_ZERO(comp) \ |
| 1062 | do { \ |
| 1063 | if ( ((*a)-> comp) != ((*b)-> comp) ) { \ |
| 1064 | if ( ((*a)-> comp) == 0 ) { \ |
| 1065 | return -1; \ |
| 1066 | } \ |
| 1067 | else if ( ((*b)-> comp) == 0 ) { \ |
| 1068 | return 1; \ |
| 1069 | } \ |
| 1070 | else { \ |
| 1071 | return ((*b)-> comp) - ((*a)-> comp) ; \ |
| 1072 | } \ |
| 1073 | } \ |
| 1074 | } while( 0 ) |
| 1075 | |
| 1076 | #define PREFER_LARGER(comp) \ |
| 1077 | do { \ |
| 1078 | if ( ((*a)-> comp) != ((*b)-> comp) ) { \ |
| 1079 | return ((*b)-> comp) - ((*a)-> comp) ; \ |
| 1080 | } \ |
| 1081 | } while( 0 ) |
| 1082 | |
| 1083 | #define PREFER_SMALLER(comp) \ |
| 1084 | do { \ |
| 1085 | if ( ((*a)-> comp) != ((*b)-> comp) ) { \ |
| 1086 | return ((*a)-> comp) - ((*b)-> comp) ; \ |
| 1087 | } \ |
| 1088 | } while( 0 ) |
| 1089 | |
| 1090 | /** |
| 1091 | * Compare two GLXFBConfigs. This function is intended to be used as the |
| 1092 | * compare function passed in to qsort. |
| 1093 | * |
| 1094 | * \returns If \c a is a "better" config, according to the specification of |
| 1095 | * SGIX_fbconfig, a number less than zero is returned. If \c b is |
| 1096 | * better, then a number greater than zero is return. If both are |
| 1097 | * equal, zero is returned. |
| 1098 | * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX |
| 1099 | */ |
| 1100 | static int |
| 1101 | fbconfig_compare( const __GLcontextModes * const * const a, |
| 1102 | const __GLcontextModes * const * const b ) |
| 1103 | { |
| 1104 | /* The order of these comparisons must NOT change. It is defined by |
| 1105 | * the GLX 1.3 spec and ARB_multisample. |
| 1106 | */ |
| 1107 | |
| 1108 | PREFER_SMALLER( visualSelectGroup ); |
| 1109 | |
| 1110 | /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and |
| 1111 | * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the |
| 1112 | * numerical sort order of the enums (0x8000, 0x8001, and 0x800D). |
| 1113 | */ |
| 1114 | PREFER_SMALLER( visualRating ); |
| 1115 | |
| 1116 | /* This isn't quite right. It is supposed to compare the sum of the |
| 1117 | * components the user specifically set minimums for. |
| 1118 | */ |
| 1119 | PREFER_LARGER_OR_ZERO( redBits ); |
| 1120 | PREFER_LARGER_OR_ZERO( greenBits ); |
| 1121 | PREFER_LARGER_OR_ZERO( blueBits ); |
| 1122 | PREFER_LARGER_OR_ZERO( alphaBits ); |
| 1123 | |
| 1124 | PREFER_SMALLER( rgbBits ); |
| 1125 | |
| 1126 | if ( ((*a)->doubleBufferMode != (*b)->doubleBufferMode) ) { |
| 1127 | /* Prefer single-buffer. |
| 1128 | */ |
| 1129 | return ( !(*a)->doubleBufferMode ) ? -1 : 1; |
| 1130 | } |
| 1131 | |
| 1132 | PREFER_SMALLER( numAuxBuffers ); |
| 1133 | |
| 1134 | PREFER_LARGER_OR_ZERO( depthBits ); |
| 1135 | PREFER_SMALLER( stencilBits ); |
| 1136 | |
| 1137 | /* This isn't quite right. It is supposed to compare the sum of the |
| 1138 | * components the user specifically set minimums for. |
| 1139 | */ |
| 1140 | PREFER_LARGER_OR_ZERO( accumRedBits ); |
| 1141 | PREFER_LARGER_OR_ZERO( accumGreenBits ); |
| 1142 | PREFER_LARGER_OR_ZERO( accumBlueBits ); |
| 1143 | PREFER_LARGER_OR_ZERO( accumAlphaBits ); |
| 1144 | |
| 1145 | PREFER_SMALLER( visualType ); |
| 1146 | |
| 1147 | /* None of the multisample specs say where this comparison should happen, |
| 1148 | * so I put it near the end. |
| 1149 | */ |
| 1150 | PREFER_SMALLER( sampleBuffers ); |
| 1151 | PREFER_SMALLER( samples ); |
| 1152 | |
| 1153 | /* None of the pbuffer or fbconfig specs say that this comparison needs |
| 1154 | * to happen at all, but it seems like it should. |
| 1155 | */ |
| 1156 | PREFER_LARGER( maxPbufferWidth ); |
| 1157 | PREFER_LARGER( maxPbufferHeight ); |
| 1158 | PREFER_LARGER( maxPbufferPixels ); |
| 1159 | |
| 1160 | return 0; |
| 1161 | } |
| 1162 | |
| 1163 | |
| 1164 | /** |
| 1165 | * Selects and sorts a subset of the supplied configs based on the attributes. |
| 1166 | * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig, |
| 1167 | * and \c glXChooseFBConfigSGIX. |
| 1168 | * |
| 1169 | * \param configs Array of pointers to possible configs. The elements of |
| 1170 | * this array that do not meet the criteria will be set to |
| 1171 | * NULL. The remaining elements will be sorted according to |
| 1172 | * the various visual / FBConfig selection rules. |
| 1173 | * \param num_configs Number of elements in the \c configs array. |
| 1174 | * \param attribList Attributes used select from \c configs. This array is |
| 1175 | * terminated by a \c None tag. The array can either take |
| 1176 | * the form expected by \c glXChooseVisual (where boolean |
| 1177 | * tags do not have a value) or by \c glXChooseFBConfig |
| 1178 | * (where every tag has a value). |
| 1179 | * \param fbconfig_style_tags Selects whether \c attribList is in |
| 1180 | * \c glXChooseVisual style or |
| 1181 | * \c glXChooseFBConfig style. |
| 1182 | * \returns The number of valid elements left in \c configs. |
| 1183 | * |
| 1184 | * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX |
| 1185 | */ |
| 1186 | static int |
| 1187 | choose_visual( __GLcontextModes ** configs, int num_configs, |
| 1188 | const int *attribList, GLboolean fbconfig_style_tags ) |
| 1189 | { |
| 1190 | __GLcontextModes test_config; |
| 1191 | int base; |
| 1192 | int i; |
| 1193 | |
| 1194 | /* This is a fairly direct implementation of the selection method |
| 1195 | * described by GLX_SGIX_fbconfig. Start by culling out all the |
| 1196 | * configs that are not compatible with the selected parameter |
| 1197 | * list. |
| 1198 | */ |
| 1199 | |
| 1200 | init_fbconfig_for_chooser( & test_config, fbconfig_style_tags ); |
| 1201 | __glXInitializeVisualConfigFromTags( & test_config, 512, |
| 1202 | (const INT32 *) attribList, |
| 1203 | GL_TRUE, fbconfig_style_tags ); |
| 1204 | |
| 1205 | base = 0; |
| 1206 | for ( i = 0 ; i < num_configs ; i++ ) { |
| 1207 | if ( fbconfigs_compatible( & test_config, configs[i] ) ) { |
| 1208 | configs[ base ] = configs[ i ]; |
| 1209 | base++; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | if ( base == 0 ) { |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | if ( base < num_configs ) { |
| 1218 | (void) memset( & configs[ base ], 0, |
| 1219 | sizeof( void * ) * (num_configs - base) ); |
| 1220 | } |
| 1221 | |
| 1222 | /* After the incompatible configs are removed, the resulting |
| 1223 | * list is sorted according to the rules set out in the various |
| 1224 | * specifications. |
| 1225 | */ |
| 1226 | |
| 1227 | qsort( configs, base, sizeof( __GLcontextModes * ), |
| 1228 | (int (*)(const void*, const void*)) fbconfig_compare ); |
| 1229 | return base; |
| 1230 | } |
| 1231 | |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | /* |
| 1236 | ** Return the visual that best matches the template. Return None if no |
| 1237 | ** visual matches the template. |
| 1238 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1239 | PUBLIC XVisualInfo *glXChooseVisual(Display *dpy, int screen, int *attribList) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1240 | { |
| 1241 | XVisualInfo *visualList = NULL; |
| 1242 | __GLXdisplayPrivate *priv; |
| 1243 | __GLXscreenConfigs *psc; |
| 1244 | __GLcontextModes test_config; |
| 1245 | __GLcontextModes *modes; |
| 1246 | const __GLcontextModes *best_config = NULL; |
| 1247 | |
| 1248 | /* |
| 1249 | ** Get a list of all visuals, return if list is empty |
| 1250 | */ |
| 1251 | if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) { |
| 1252 | return None; |
| 1253 | } |
| 1254 | |
| 1255 | |
| 1256 | /* |
| 1257 | ** Build a template from the defaults and the attribute list |
| 1258 | ** Free visual list and return if an unexpected token is encountered |
| 1259 | */ |
| 1260 | init_fbconfig_for_chooser( & test_config, GL_FALSE ); |
| 1261 | __glXInitializeVisualConfigFromTags( & test_config, 512, |
| 1262 | (const INT32 *) attribList, |
| 1263 | GL_TRUE, GL_FALSE ); |
| 1264 | |
| 1265 | /* |
| 1266 | ** Eliminate visuals that don't meet minimum requirements |
| 1267 | ** Compute a score for those that do |
| 1268 | ** Remember which visual, if any, got the highest score |
| 1269 | */ |
Kristian Høgsberg | 6c533ea | 2007-10-16 16:07:47 -0400 | [diff] [blame] | 1270 | for ( modes = psc->visuals ; modes != NULL ; modes = modes->next ) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1271 | if ( fbconfigs_compatible( & test_config, modes ) |
| 1272 | && ((best_config == NULL) |
| 1273 | || (fbconfig_compare( (const __GLcontextModes * const * const)&modes, &best_config ) < 0)) ) { |
| 1274 | best_config = modes; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | /* |
| 1279 | ** If no visual is acceptable, return None |
| 1280 | ** Otherwise, create an XVisualInfo list with just the selected X visual |
| 1281 | ** and return this. |
| 1282 | */ |
| 1283 | if (best_config != NULL) { |
| 1284 | XVisualInfo visualTemplate; |
| 1285 | int i; |
| 1286 | |
| 1287 | visualTemplate.screen = screen; |
| 1288 | visualTemplate.visualid = best_config->visualID; |
| 1289 | visualList = XGetVisualInfo( dpy, VisualScreenMask|VisualIDMask, |
| 1290 | &visualTemplate, &i ); |
| 1291 | } |
| 1292 | |
| 1293 | return visualList; |
| 1294 | } |
| 1295 | |
| 1296 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1297 | PUBLIC const char *glXQueryExtensionsString( Display *dpy, int screen ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1298 | { |
| 1299 | __GLXscreenConfigs *psc; |
| 1300 | __GLXdisplayPrivate *priv; |
| 1301 | |
| 1302 | if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) { |
| 1303 | return NULL; |
| 1304 | } |
| 1305 | |
| 1306 | if (!psc->effectiveGLXexts) { |
| 1307 | if (!psc->serverGLXexts) { |
| 1308 | psc->serverGLXexts = __glXGetStringFromServer(dpy, priv->majorOpcode, |
| 1309 | X_GLXQueryServerString, |
| 1310 | screen, GLX_EXTENSIONS); |
| 1311 | } |
| 1312 | |
| 1313 | __glXCalculateUsableExtensions(psc, |
| 1314 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1315 | (psc->driScreen != NULL), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1316 | #else |
| 1317 | GL_FALSE, |
| 1318 | #endif |
| 1319 | priv->minorVersion); |
| 1320 | } |
| 1321 | |
| 1322 | return psc->effectiveGLXexts; |
| 1323 | } |
| 1324 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1325 | PUBLIC const char *glXGetClientString( Display *dpy, int name ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1326 | { |
| 1327 | switch(name) { |
| 1328 | case GLX_VENDOR: |
| 1329 | return (__glXGLXClientVendorName); |
| 1330 | case GLX_VERSION: |
| 1331 | return (__glXGLXClientVersion); |
| 1332 | case GLX_EXTENSIONS: |
| 1333 | return (__glXGetClientExtensions()); |
| 1334 | default: |
| 1335 | return NULL; |
| 1336 | } |
| 1337 | } |
| 1338 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1339 | PUBLIC const char *glXQueryServerString( Display *dpy, int screen, int name ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1340 | { |
| 1341 | __GLXscreenConfigs *psc; |
| 1342 | __GLXdisplayPrivate *priv; |
| 1343 | const char ** str; |
| 1344 | |
| 1345 | |
| 1346 | if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) { |
| 1347 | return NULL; |
| 1348 | } |
| 1349 | |
| 1350 | switch(name) { |
| 1351 | case GLX_VENDOR: |
| 1352 | str = & priv->serverGLXvendor; |
| 1353 | break; |
| 1354 | case GLX_VERSION: |
| 1355 | str = & priv->serverGLXversion; |
| 1356 | break; |
| 1357 | case GLX_EXTENSIONS: |
| 1358 | str = & psc->serverGLXexts; |
| 1359 | break; |
| 1360 | default: |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | |
| 1364 | if ( *str == NULL ) { |
| 1365 | *str = __glXGetStringFromServer(dpy, priv->majorOpcode, |
| 1366 | X_GLXQueryServerString, screen, name); |
| 1367 | } |
| 1368 | |
| 1369 | return *str; |
| 1370 | } |
| 1371 | |
| 1372 | void __glXClientInfo ( Display *dpy, int opcode ) |
| 1373 | { |
| 1374 | xGLXClientInfoReq *req; |
| 1375 | int size; |
| 1376 | char * ext_str = __glXGetClientGLExtensionString(); |
| 1377 | |
| 1378 | /* Send the glXClientInfo request */ |
| 1379 | LockDisplay(dpy); |
| 1380 | GetReq(GLXClientInfo,req); |
| 1381 | req->reqType = opcode; |
| 1382 | req->glxCode = X_GLXClientInfo; |
| 1383 | req->major = GLX_MAJOR_VERSION; |
| 1384 | req->minor = GLX_MINOR_VERSION; |
| 1385 | |
| 1386 | size = strlen( ext_str ) + 1; |
| 1387 | req->length += (size + 3) >> 2; |
| 1388 | req->numbytes = size; |
| 1389 | Data(dpy, ext_str, size); |
| 1390 | |
| 1391 | UnlockDisplay(dpy); |
| 1392 | SyncHandle(); |
| 1393 | |
| 1394 | Xfree( ext_str ); |
| 1395 | } |
| 1396 | |
| 1397 | |
| 1398 | /* |
| 1399 | ** EXT_import_context |
| 1400 | */ |
| 1401 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1402 | PUBLIC Display *glXGetCurrentDisplay(void) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1403 | { |
| 1404 | GLXContext gc = __glXGetCurrentContext(); |
| 1405 | if (NULL == gc) return NULL; |
| 1406 | return gc->currentDpy; |
| 1407 | } |
| 1408 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1409 | PUBLIC GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1410 | glXGetCurrentDisplay) |
| 1411 | |
| 1412 | /** |
| 1413 | * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests |
| 1414 | * to the X-server. |
| 1415 | * |
| 1416 | * \param dpy Display where \c ctx was created. |
| 1417 | * \param ctx Context to query. |
| 1418 | * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid, |
| 1419 | * or zero if the request failed due to internal problems (i.e., |
| 1420 | * unable to allocate temporary memory, etc.) |
| 1421 | * |
| 1422 | * \note |
| 1423 | * This function dynamically determines whether to use the EXT_import_context |
| 1424 | * version of the protocol or the GLX 1.3 version of the protocol. |
| 1425 | */ |
| 1426 | static int __glXQueryContextInfo(Display *dpy, GLXContext ctx) |
| 1427 | { |
| 1428 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 1429 | xGLXQueryContextReply reply; |
| 1430 | CARD8 opcode; |
| 1431 | GLuint numValues; |
| 1432 | int retval; |
| 1433 | |
| 1434 | if (ctx == NULL) { |
| 1435 | return GLX_BAD_CONTEXT; |
| 1436 | } |
| 1437 | opcode = __glXSetupForCommand(dpy); |
| 1438 | if (!opcode) { |
| 1439 | return 0; |
| 1440 | } |
| 1441 | |
| 1442 | /* Send the glXQueryContextInfoEXT request */ |
| 1443 | LockDisplay(dpy); |
| 1444 | |
| 1445 | if ( (priv->majorVersion > 1) || (priv->minorVersion >= 3) ) { |
| 1446 | xGLXQueryContextReq *req; |
| 1447 | |
| 1448 | GetReq(GLXQueryContext, req); |
| 1449 | |
| 1450 | req->reqType = opcode; |
| 1451 | req->glxCode = X_GLXQueryContext; |
| 1452 | req->context = (unsigned int)(ctx->xid); |
| 1453 | } |
| 1454 | else { |
| 1455 | xGLXVendorPrivateReq *vpreq; |
| 1456 | xGLXQueryContextInfoEXTReq *req; |
| 1457 | |
| 1458 | GetReqExtra( GLXVendorPrivate, |
| 1459 | sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq, |
| 1460 | vpreq ); |
| 1461 | req = (xGLXQueryContextInfoEXTReq *)vpreq; |
| 1462 | req->reqType = opcode; |
| 1463 | req->glxCode = X_GLXVendorPrivateWithReply; |
| 1464 | req->vendorCode = X_GLXvop_QueryContextInfoEXT; |
| 1465 | req->context = (unsigned int)(ctx->xid); |
| 1466 | } |
| 1467 | |
| 1468 | _XReply(dpy, (xReply*) &reply, 0, False); |
| 1469 | |
| 1470 | numValues = reply.n; |
| 1471 | if (numValues == 0) |
| 1472 | retval = Success; |
| 1473 | else if (numValues > __GLX_MAX_CONTEXT_PROPS) |
| 1474 | retval = 0; |
| 1475 | else |
| 1476 | { |
| 1477 | int *propList, *pProp; |
| 1478 | int nPropListBytes; |
| 1479 | int i; |
| 1480 | |
| 1481 | nPropListBytes = numValues << 3; |
| 1482 | propList = (int *) Xmalloc(nPropListBytes); |
| 1483 | if (NULL == propList) { |
| 1484 | retval = 0; |
| 1485 | } else { |
| 1486 | _XRead(dpy, (char *)propList, nPropListBytes); |
| 1487 | pProp = propList; |
| 1488 | for (i=0; i < numValues; i++) { |
| 1489 | switch (*pProp++) { |
| 1490 | case GLX_SHARE_CONTEXT_EXT: |
| 1491 | ctx->share_xid = *pProp++; |
| 1492 | break; |
| 1493 | case GLX_VISUAL_ID_EXT: |
Kristian Høgsberg | 001de0a | 2007-11-06 13:32:04 -0500 | [diff] [blame] | 1494 | ctx->mode = |
| 1495 | _gl_context_modes_find_visual(ctx->psc->visuals, *pProp++); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1496 | break; |
| 1497 | case GLX_SCREEN: |
| 1498 | ctx->screen = *pProp++; |
| 1499 | break; |
| 1500 | case GLX_FBCONFIG_ID: |
Kristian Høgsberg | 001de0a | 2007-11-06 13:32:04 -0500 | [diff] [blame] | 1501 | ctx->mode = |
| 1502 | _gl_context_modes_find_fbconfig(ctx->psc->configs, *pProp++); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1503 | break; |
| 1504 | case GLX_RENDER_TYPE: |
| 1505 | ctx->renderType = *pProp++; |
| 1506 | break; |
| 1507 | default: |
| 1508 | pProp++; |
| 1509 | continue; |
| 1510 | } |
| 1511 | } |
| 1512 | Xfree((char *)propList); |
| 1513 | retval = Success; |
| 1514 | } |
| 1515 | } |
| 1516 | UnlockDisplay(dpy); |
| 1517 | SyncHandle(); |
| 1518 | return retval; |
| 1519 | } |
| 1520 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1521 | PUBLIC int |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1522 | glXQueryContext(Display *dpy, GLXContext ctx, int attribute, int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1523 | { |
| 1524 | int retVal; |
| 1525 | |
| 1526 | /* get the information from the server if we don't have it already */ |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1527 | if (!ctx->driContext && (ctx->mode == NULL)) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1528 | retVal = __glXQueryContextInfo(dpy, ctx); |
| 1529 | if (Success != retVal) return retVal; |
| 1530 | } |
| 1531 | switch (attribute) { |
| 1532 | case GLX_SHARE_CONTEXT_EXT: |
| 1533 | *value = (int)(ctx->share_xid); |
| 1534 | break; |
| 1535 | case GLX_VISUAL_ID_EXT: |
Kristian Høgsberg | 001de0a | 2007-11-06 13:32:04 -0500 | [diff] [blame] | 1536 | *value = ctx->mode ? ctx->mode->visualID : None; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1537 | break; |
| 1538 | case GLX_SCREEN: |
| 1539 | *value = (int)(ctx->screen); |
| 1540 | break; |
| 1541 | case GLX_FBCONFIG_ID: |
Kristian Høgsberg | 001de0a | 2007-11-06 13:32:04 -0500 | [diff] [blame] | 1542 | *value = ctx->mode ? ctx->mode->fbconfigID : None; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1543 | break; |
| 1544 | case GLX_RENDER_TYPE: |
| 1545 | *value = (int)(ctx->renderType); |
| 1546 | break; |
| 1547 | default: |
| 1548 | return GLX_BAD_ATTRIBUTE; |
| 1549 | } |
| 1550 | return Success; |
| 1551 | } |
| 1552 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1553 | PUBLIC GLX_ALIAS( int, glXQueryContextInfoEXT, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1554 | (Display *dpy, GLXContext ctx, int attribute, int *value), |
| 1555 | (dpy, ctx, attribute, value), |
| 1556 | glXQueryContext ) |
| 1557 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1558 | PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1559 | { |
| 1560 | return ctx->xid; |
| 1561 | } |
| 1562 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1563 | PUBLIC GLXContext glXImportContextEXT(Display *dpy, GLXContextID contextID) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1564 | { |
| 1565 | GLXContext ctx; |
| 1566 | |
| 1567 | if (contextID == None) { |
| 1568 | return NULL; |
| 1569 | } |
| 1570 | if (__glXIsDirect(dpy, contextID)) { |
| 1571 | return NULL; |
| 1572 | } |
| 1573 | |
| 1574 | ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0); |
| 1575 | if (NULL != ctx) { |
| 1576 | if (Success != __glXQueryContextInfo(dpy, ctx)) { |
| 1577 | return NULL; |
| 1578 | } |
| 1579 | } |
| 1580 | return ctx; |
| 1581 | } |
| 1582 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1583 | PUBLIC void glXFreeContextEXT(Display *dpy, GLXContext ctx) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1584 | { |
| 1585 | DestroyContext(dpy, ctx); |
| 1586 | } |
| 1587 | |
| 1588 | |
| 1589 | |
| 1590 | /* |
| 1591 | * GLX 1.3 functions - these are just stubs for now! |
| 1592 | */ |
| 1593 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1594 | PUBLIC GLXFBConfig *glXChooseFBConfig(Display *dpy, int screen, |
| 1595 | const int *attribList, int *nitems) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1596 | { |
| 1597 | __GLcontextModes ** config_list; |
| 1598 | int list_size; |
| 1599 | |
| 1600 | |
| 1601 | config_list = (__GLcontextModes **) |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1602 | glXGetFBConfigs( dpy, screen, & list_size ); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1603 | |
Ian Romanick | c51ed8c | 2005-04-07 00:05:55 +0000 | [diff] [blame] | 1604 | if ( (config_list != NULL) && (list_size > 0) && (attribList != NULL) ) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1605 | list_size = choose_visual( config_list, list_size, attribList, |
| 1606 | GL_TRUE ); |
| 1607 | if ( list_size == 0 ) { |
| 1608 | XFree( config_list ); |
| 1609 | config_list = NULL; |
| 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | *nitems = list_size; |
| 1614 | return (GLXFBConfig *) config_list; |
| 1615 | } |
| 1616 | |
| 1617 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1618 | PUBLIC GLXContext glXCreateNewContext(Display *dpy, GLXFBConfig config, |
| 1619 | int renderType, GLXContext shareList, |
| 1620 | Bool allowDirect) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1621 | { |
| 1622 | return CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList, |
| 1623 | allowDirect, None, True, renderType ); |
| 1624 | } |
| 1625 | |
| 1626 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1627 | PUBLIC GLXDrawable glXGetCurrentReadDrawable(void) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1628 | { |
| 1629 | GLXContext gc = __glXGetCurrentContext(); |
| 1630 | return gc->currentReadable; |
| 1631 | } |
| 1632 | |
| 1633 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1634 | PUBLIC GLXFBConfig *glXGetFBConfigs(Display *dpy, int screen, int *nelements) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1635 | { |
| 1636 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 1637 | __GLcontextModes ** config = NULL; |
| 1638 | int i; |
| 1639 | |
Kristian Høgsberg | 6c533ea | 2007-10-16 16:07:47 -0400 | [diff] [blame] | 1640 | *nelements = 0; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1641 | if ( (priv->screenConfigs != NULL) |
| 1642 | && (screen >= 0) && (screen <= ScreenCount(dpy)) |
| 1643 | && (priv->screenConfigs[screen].configs != NULL) |
| 1644 | && (priv->screenConfigs[screen].configs->fbconfigID != GLX_DONT_CARE) ) { |
| 1645 | unsigned num_configs = 0; |
| 1646 | __GLcontextModes * modes; |
| 1647 | |
| 1648 | |
| 1649 | for ( modes = priv->screenConfigs[screen].configs |
| 1650 | ; modes != NULL |
| 1651 | ; modes = modes->next ) { |
| 1652 | if ( modes->fbconfigID != GLX_DONT_CARE ) { |
| 1653 | num_configs++; |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | config = (__GLcontextModes **) Xmalloc( sizeof(__GLcontextModes *) |
| 1658 | * num_configs ); |
| 1659 | if ( config != NULL ) { |
| 1660 | *nelements = num_configs; |
| 1661 | i = 0; |
| 1662 | for ( modes = priv->screenConfigs[screen].configs |
| 1663 | ; modes != NULL |
| 1664 | ; modes = modes->next ) { |
Kristian Høgsberg | a87e9a3 | 2007-08-30 13:05:59 -0400 | [diff] [blame] | 1665 | if ( modes->fbconfigID != GLX_DONT_CARE ) { |
| 1666 | config[i] = modes; |
| 1667 | i++; |
| 1668 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | return (GLXFBConfig *) config; |
| 1673 | } |
| 1674 | |
| 1675 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1676 | PUBLIC int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, |
| 1677 | int attribute, int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1678 | { |
| 1679 | __GLcontextModes * const modes = ValidateGLXFBConfig( dpy, config ); |
| 1680 | |
| 1681 | return (modes != NULL) |
| 1682 | ? _gl_get_context_mode_data( modes, attribute, value ) |
| 1683 | : GLXBadFBConfig; |
| 1684 | } |
| 1685 | |
| 1686 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1687 | PUBLIC XVisualInfo *glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1688 | { |
| 1689 | XVisualInfo visualTemplate; |
| 1690 | __GLcontextModes * fbconfig = (__GLcontextModes *) config; |
| 1691 | int count; |
| 1692 | |
| 1693 | /* |
| 1694 | ** Get a list of all visuals, return if list is empty |
| 1695 | */ |
| 1696 | visualTemplate.visualid = fbconfig->visualID; |
| 1697 | return XGetVisualInfo(dpy,VisualIDMask,&visualTemplate,&count); |
| 1698 | } |
| 1699 | |
| 1700 | |
| 1701 | /* |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1702 | ** GLX_SGI_swap_control |
| 1703 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1704 | static int __glXSwapIntervalSGI(int interval) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1705 | { |
| 1706 | xGLXVendorPrivateReq *req; |
| 1707 | GLXContext gc = __glXGetCurrentContext(); |
| 1708 | Display * dpy; |
| 1709 | CARD32 * interval_ptr; |
| 1710 | CARD8 opcode; |
| 1711 | |
| 1712 | if ( gc == NULL ) { |
| 1713 | return GLX_BAD_CONTEXT; |
| 1714 | } |
| 1715 | |
| 1716 | if ( interval <= 0 ) { |
| 1717 | return GLX_BAD_VALUE; |
| 1718 | } |
| 1719 | |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1720 | #ifdef __DRI_SWAP_CONTROL |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1721 | if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1722 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, |
| 1723 | gc->screen ); |
| 1724 | __DRIdrawable * const pdraw = GetDRIDrawable( gc->currentDpy, |
| 1725 | gc->currentDrawable, |
| 1726 | NULL ); |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1727 | if (psc->swapControl != NULL && pdraw != NULL) { |
| 1728 | psc->swapControl->setSwapInterval(pdraw, interval); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1729 | return 0; |
| 1730 | } |
| 1731 | else { |
| 1732 | return GLX_BAD_CONTEXT; |
| 1733 | } |
| 1734 | } |
| 1735 | #endif |
| 1736 | dpy = gc->currentDpy; |
| 1737 | opcode = __glXSetupForCommand(dpy); |
| 1738 | if (!opcode) { |
| 1739 | return 0; |
| 1740 | } |
| 1741 | |
| 1742 | /* Send the glXSwapIntervalSGI request */ |
| 1743 | LockDisplay(dpy); |
| 1744 | GetReqExtra(GLXVendorPrivate,sizeof(CARD32),req); |
| 1745 | req->reqType = opcode; |
| 1746 | req->glxCode = X_GLXVendorPrivate; |
| 1747 | req->vendorCode = X_GLXvop_SwapIntervalSGI; |
| 1748 | req->contextTag = gc->currentContextTag; |
| 1749 | |
Ian Romanick | a70d564 | 2006-08-30 23:15:02 +0000 | [diff] [blame] | 1750 | interval_ptr = (CARD32 *) (req + 1); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1751 | *interval_ptr = interval; |
| 1752 | |
| 1753 | UnlockDisplay(dpy); |
| 1754 | SyncHandle(); |
| 1755 | XFlush(dpy); |
| 1756 | |
| 1757 | return 0; |
| 1758 | } |
| 1759 | |
| 1760 | |
| 1761 | /* |
| 1762 | ** GLX_MESA_swap_control |
| 1763 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1764 | static int __glXSwapIntervalMESA(unsigned int interval) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1765 | { |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1766 | #ifdef __DRI_SWAP_CONTROL |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1767 | GLXContext gc = __glXGetCurrentContext(); |
| 1768 | |
| 1769 | if ( interval < 0 ) { |
| 1770 | return GLX_BAD_VALUE; |
| 1771 | } |
| 1772 | |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1773 | if (gc != NULL && gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1774 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, |
| 1775 | gc->screen ); |
| 1776 | |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1777 | if ( (psc != NULL) && (psc->driScreen != NULL) ) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1778 | __DRIdrawable * const pdraw = |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 1779 | GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1780 | if (psc->swapControl != NULL && pdraw != NULL) { |
| 1781 | psc->swapControl->setSwapInterval(pdraw, interval); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1782 | return 0; |
| 1783 | } |
| 1784 | } |
| 1785 | } |
| 1786 | #else |
| 1787 | (void) interval; |
| 1788 | #endif |
| 1789 | |
| 1790 | return GLX_BAD_CONTEXT; |
| 1791 | } |
| 1792 | |
Brian Paul | 841a823 | 2006-03-09 16:25:46 +0000 | [diff] [blame] | 1793 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1794 | static int __glXGetSwapIntervalMESA(void) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1795 | { |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1796 | #ifdef __DRI_SWAP_CONTROL |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1797 | GLXContext gc = __glXGetCurrentContext(); |
| 1798 | |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1799 | if (gc != NULL && gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1800 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, |
| 1801 | gc->screen ); |
| 1802 | |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1803 | if ( (psc != NULL) && (psc->driScreen != NULL) ) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1804 | __DRIdrawable * const pdraw = |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 1805 | GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1806 | if (psc->swapControl != NULL && pdraw != NULL) { |
| 1807 | return psc->swapControl->getSwapInterval(pdraw); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1808 | } |
| 1809 | } |
| 1810 | } |
| 1811 | #endif |
| 1812 | |
| 1813 | return 0; |
| 1814 | } |
| 1815 | |
| 1816 | |
| 1817 | /* |
| 1818 | ** GLX_MESA_swap_frame_usage |
| 1819 | */ |
| 1820 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1821 | static GLint __glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1822 | { |
| 1823 | int status = GLX_BAD_CONTEXT; |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1824 | #ifdef __DRI_FRAME_TRACKING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1825 | int screen; |
| 1826 | __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen); |
| 1827 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); |
| 1828 | |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1829 | if (pdraw != NULL && psc->frameTracking != NULL) |
| 1830 | status = psc->frameTracking->frameTracking(pdraw, GL_TRUE); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1831 | #else |
| 1832 | (void) dpy; |
| 1833 | (void) drawable; |
| 1834 | #endif |
| 1835 | return status; |
| 1836 | } |
| 1837 | |
| 1838 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1839 | static GLint __glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1840 | { |
| 1841 | int status = GLX_BAD_CONTEXT; |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1842 | #ifdef __DRI_FRAME_TRACKING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1843 | int screen; |
| 1844 | __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen); |
| 1845 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); |
| 1846 | |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1847 | if (pdraw != NULL && psc->frameTracking != NULL) |
| 1848 | status = psc->frameTracking->frameTracking(pdraw, GL_FALSE); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1849 | #else |
| 1850 | (void) dpy; |
| 1851 | (void) drawable; |
| 1852 | #endif |
| 1853 | return status; |
| 1854 | } |
| 1855 | |
| 1856 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1857 | static GLint __glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable, |
| 1858 | GLfloat *usage) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1859 | { |
| 1860 | int status = GLX_BAD_CONTEXT; |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1861 | #ifdef __DRI_FRAME_TRACKING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1862 | int screen; |
| 1863 | __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen); |
| 1864 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); |
| 1865 | |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1866 | if (pdraw != NULL && psc->frameTracking != NULL) { |
| 1867 | int64_t sbc, missedFrames; |
| 1868 | float lastMissedUsage; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1869 | |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1870 | status = psc->frameTracking->queryFrameTracking(pdraw, &sbc, |
| 1871 | &missedFrames, |
| 1872 | &lastMissedUsage, |
| 1873 | usage); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1874 | } |
| 1875 | #else |
| 1876 | (void) dpy; |
| 1877 | (void) drawable; |
| 1878 | (void) usage; |
| 1879 | #endif |
| 1880 | return status; |
| 1881 | } |
| 1882 | |
| 1883 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1884 | static GLint __glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable, |
| 1885 | int64_t *sbc, int64_t *missedFrames, |
| 1886 | GLfloat *lastMissedUsage) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1887 | { |
| 1888 | int status = GLX_BAD_CONTEXT; |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1889 | #ifdef __DRI_FRAME_TRACKING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1890 | int screen; |
| 1891 | __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen); |
| 1892 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); |
| 1893 | |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1894 | if (pdraw != NULL && psc->frameTracking != NULL) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1895 | float usage; |
| 1896 | |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1897 | status = psc->frameTracking->queryFrameTracking(pdraw, sbc, missedFrames, |
| 1898 | lastMissedUsage, &usage); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1899 | } |
| 1900 | #else |
| 1901 | (void) dpy; |
| 1902 | (void) drawable; |
| 1903 | (void) sbc; |
| 1904 | (void) missedFrames; |
| 1905 | (void) lastMissedUsage; |
| 1906 | #endif |
| 1907 | return status; |
| 1908 | } |
| 1909 | |
| 1910 | |
| 1911 | /* |
| 1912 | ** GLX_SGI_video_sync |
| 1913 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1914 | static int __glXGetVideoSyncSGI(unsigned int *count) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1915 | { |
| 1916 | /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry, |
| 1917 | * FIXME: there should be a GLX encoding for this call. I can find no |
| 1918 | * FIXME: documentation for the GLX encoding. |
| 1919 | */ |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 1920 | #ifdef __DRI_MEDIA_STREAM_COUNTER |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1921 | GLXContext gc = __glXGetCurrentContext(); |
| 1922 | |
| 1923 | |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1924 | if (gc != NULL && gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1925 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, |
| 1926 | gc->screen ); |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1927 | if ( psc->msc && psc->driScreen ) { |
Jesse Barnes | 38fdb47 | 2007-10-29 11:56:31 -0700 | [diff] [blame] | 1928 | __DRIdrawable * const pdraw = |
| 1929 | GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); |
| 1930 | int64_t temp; |
| 1931 | int ret; |
| 1932 | |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1933 | ret = (*psc->msc->getDrawableMSC)(&psc->__driScreen, pdraw, &temp); |
Jesse Barnes | 38fdb47 | 2007-10-29 11:56:31 -0700 | [diff] [blame] | 1934 | *count = (unsigned) temp; |
Kristian Høgsberg | 6e8d21d | 2008-02-25 16:14:37 -0500 | [diff] [blame] | 1935 | |
Jesse Barnes | 38fdb47 | 2007-10-29 11:56:31 -0700 | [diff] [blame] | 1936 | return (ret == 0) ? 0 : GLX_BAD_CONTEXT; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1937 | } |
| 1938 | } |
| 1939 | #else |
| 1940 | (void) count; |
| 1941 | #endif |
| 1942 | return GLX_BAD_CONTEXT; |
| 1943 | } |
| 1944 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1945 | static int __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1946 | { |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 1947 | #ifdef __DRI_MEDIA_STREAM_COUNTER |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1948 | GLXContext gc = __glXGetCurrentContext(); |
| 1949 | |
| 1950 | if ( divisor <= 0 || remainder < 0 ) |
| 1951 | return GLX_BAD_VALUE; |
| 1952 | |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1953 | if (gc != NULL && gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1954 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, |
| 1955 | gc->screen ); |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1956 | if (psc->msc != NULL && psc->driScreen ) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1957 | __DRIdrawable * const pdraw = |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 1958 | GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); |
Jesse Barnes | 38fdb47 | 2007-10-29 11:56:31 -0700 | [diff] [blame] | 1959 | int ret; |
| 1960 | int64_t msc; |
| 1961 | int64_t sbc; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1962 | |
Jesse Barnes | 38fdb47 | 2007-10-29 11:56:31 -0700 | [diff] [blame] | 1963 | ret = (*psc->msc->waitForMSC)(pdraw, 0, divisor, remainder, &msc, |
| 1964 | &sbc); |
| 1965 | *count = (unsigned) msc; |
| 1966 | return (ret == 0) ? 0 : GLX_BAD_CONTEXT; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1967 | } |
| 1968 | } |
| 1969 | #else |
| 1970 | (void) count; |
| 1971 | #endif |
| 1972 | return GLX_BAD_CONTEXT; |
| 1973 | } |
| 1974 | |
| 1975 | |
| 1976 | /* |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1977 | ** GLX_SGIX_fbconfig |
| 1978 | ** Many of these functions are aliased to GLX 1.3 entry points in the |
| 1979 | ** GLX_functions table. |
| 1980 | */ |
| 1981 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1982 | PUBLIC GLX_ALIAS(int, glXGetFBConfigAttribSGIX, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1983 | (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value), |
| 1984 | (dpy, config, attribute, value), |
| 1985 | glXGetFBConfigAttrib) |
| 1986 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1987 | PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1988 | (Display *dpy, int screen, int *attrib_list, int *nelements), |
| 1989 | (dpy, screen, attrib_list, nelements), |
| 1990 | glXChooseFBConfig) |
| 1991 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1992 | PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1993 | (Display * dpy, GLXFBConfigSGIX config), |
| 1994 | (dpy, config), |
| 1995 | glXGetVisualFromFBConfig) |
| 1996 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1997 | PUBLIC GLXPixmap glXCreateGLXPixmapWithConfigSGIX(Display *dpy, |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1998 | GLXFBConfigSGIX config, Pixmap pixmap) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1999 | { |
| 2000 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 2001 | xGLXCreateGLXPixmapWithConfigSGIXReq *req; |
| 2002 | GLXPixmap xid = None; |
| 2003 | CARD8 opcode; |
| 2004 | const __GLcontextModes * const fbconfig = (__GLcontextModes *) config; |
| 2005 | __GLXscreenConfigs * psc; |
| 2006 | |
| 2007 | |
| 2008 | if ( (dpy == NULL) || (config == NULL) ) { |
| 2009 | return None; |
| 2010 | } |
| 2011 | |
| 2012 | psc = GetGLXScreenConfigs( dpy, fbconfig->screen ); |
| 2013 | if ( (psc != NULL) |
| 2014 | && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) { |
| 2015 | opcode = __glXSetupForCommand(dpy); |
| 2016 | if (!opcode) { |
| 2017 | return None; |
| 2018 | } |
| 2019 | |
| 2020 | /* Send the glXCreateGLXPixmapWithConfigSGIX request */ |
| 2021 | LockDisplay(dpy); |
| 2022 | GetReqExtra(GLXVendorPrivateWithReply, |
| 2023 | sz_xGLXCreateGLXPixmapWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq); |
| 2024 | req = (xGLXCreateGLXPixmapWithConfigSGIXReq *)vpreq; |
| 2025 | req->reqType = opcode; |
| 2026 | req->glxCode = X_GLXVendorPrivateWithReply; |
| 2027 | req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX; |
| 2028 | req->screen = fbconfig->screen; |
| 2029 | req->fbconfig = fbconfig->fbconfigID; |
| 2030 | req->pixmap = pixmap; |
| 2031 | req->glxpixmap = xid = XAllocID(dpy); |
| 2032 | UnlockDisplay(dpy); |
| 2033 | SyncHandle(); |
| 2034 | } |
| 2035 | |
| 2036 | return xid; |
| 2037 | } |
| 2038 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2039 | PUBLIC GLXContext glXCreateContextWithConfigSGIX(Display *dpy, |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 2040 | GLXFBConfigSGIX config, int renderType, |
| 2041 | GLXContext shareList, Bool allowDirect) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2042 | { |
| 2043 | GLXContext gc = NULL; |
| 2044 | const __GLcontextModes * const fbconfig = (__GLcontextModes *) config; |
| 2045 | __GLXscreenConfigs * psc; |
| 2046 | |
| 2047 | |
| 2048 | if ( (dpy == NULL) || (config == NULL) ) { |
| 2049 | return None; |
| 2050 | } |
| 2051 | |
| 2052 | psc = GetGLXScreenConfigs( dpy, fbconfig->screen ); |
| 2053 | if ( (psc != NULL) |
| 2054 | && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) { |
| 2055 | gc = CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList, |
| 2056 | allowDirect, None, False, renderType ); |
| 2057 | } |
| 2058 | |
| 2059 | return gc; |
| 2060 | } |
| 2061 | |
| 2062 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2063 | PUBLIC GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX(Display *dpy, |
| 2064 | XVisualInfo *vis) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2065 | { |
| 2066 | __GLXdisplayPrivate *priv; |
| 2067 | __GLXscreenConfigs *psc; |
| 2068 | |
| 2069 | if ( (GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ) != Success) |
| 2070 | && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) |
| 2071 | && (psc->configs->fbconfigID != GLX_DONT_CARE) ) { |
| 2072 | return (GLXFBConfigSGIX) _gl_context_modes_find_visual( psc->configs, |
| 2073 | vis->visualid ); |
| 2074 | } |
| 2075 | |
| 2076 | return NULL; |
| 2077 | } |
| 2078 | |
| 2079 | |
| 2080 | /* |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2081 | ** GLX_SGIX_swap_group |
| 2082 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2083 | static void __glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, |
| 2084 | GLXDrawable member) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2085 | { |
| 2086 | (void) dpy; |
| 2087 | (void) drawable; |
| 2088 | (void) member; |
| 2089 | } |
| 2090 | |
| 2091 | |
| 2092 | /* |
| 2093 | ** GLX_SGIX_swap_barrier |
| 2094 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2095 | static void __glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, |
| 2096 | int barrier) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2097 | { |
| 2098 | (void) dpy; |
| 2099 | (void) drawable; |
| 2100 | (void) barrier; |
| 2101 | } |
| 2102 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2103 | static Bool __glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2104 | { |
| 2105 | (void) dpy; |
| 2106 | (void) screen; |
| 2107 | (void) max; |
| 2108 | return False; |
| 2109 | } |
| 2110 | |
| 2111 | |
| 2112 | /* |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2113 | ** GLX_OML_sync_control |
| 2114 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2115 | static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable, |
| 2116 | int64_t *ust, int64_t *msc, int64_t *sbc) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2117 | { |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2118 | #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2119 | __GLXdisplayPrivate * const priv = __glXInitialize(dpy); |
| 2120 | |
| 2121 | if ( priv != NULL ) { |
| 2122 | int i; |
| 2123 | __DRIdrawable * const pdraw = GetDRIDrawable( dpy, drawable, & i ); |
| 2124 | __GLXscreenConfigs * const psc = &priv->screenConfigs[i]; |
| 2125 | |
| 2126 | assert( (pdraw == NULL) || (i != -1) ); |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2127 | return ( (pdraw && psc->sbc && psc->msc) |
| 2128 | && ((*psc->msc->getMSC)(&psc->driScreen, msc) == 0) |
| 2129 | && ((*psc->sbc->getSBC)(pdraw, sbc) == 0) |
| 2130 | && (__glXGetUST(ust) == 0) ); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2131 | } |
| 2132 | #else |
| 2133 | (void) dpy; |
| 2134 | (void) drawable; |
| 2135 | (void) ust; |
| 2136 | (void) msc; |
| 2137 | (void) sbc; |
| 2138 | #endif |
| 2139 | return False; |
| 2140 | } |
| 2141 | |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2142 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 3d28a26 | 2008-03-08 22:28:01 -0500 | [diff] [blame] | 2143 | _X_HIDDEN GLboolean |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2144 | __driGetMscRateOML(__DRIdrawable *draw, int32_t *numerator, int32_t *denominator) |
| 2145 | { |
| 2146 | #ifdef XF86VIDMODE |
| 2147 | __GLXscreenConfigs *psc; |
| 2148 | XF86VidModeModeLine mode_line; |
| 2149 | int dot_clock; |
| 2150 | int i; |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 2151 | __GLXDRIdrawable *glxDraw; |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2152 | |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 2153 | glxDraw = containerOf(draw, __GLXDRIdrawable, driDrawable); |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2154 | psc = glxDraw->psc; |
| 2155 | if (XF86VidModeQueryVersion(psc->dpy, &i, &i) && |
| 2156 | XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line) ) { |
| 2157 | unsigned n = dot_clock * 1000; |
| 2158 | unsigned d = mode_line.vtotal * mode_line.htotal; |
| 2159 | |
| 2160 | # define V_INTERLACE 0x010 |
| 2161 | # define V_DBLSCAN 0x020 |
| 2162 | |
| 2163 | if (mode_line.flags & V_INTERLACE) |
| 2164 | n *= 2; |
| 2165 | else if (mode_line.flags & V_DBLSCAN) |
| 2166 | d *= 2; |
| 2167 | |
| 2168 | /* The OML_sync_control spec requires that if the refresh rate is a |
| 2169 | * whole number, that the returned numerator be equal to the refresh |
| 2170 | * rate and the denominator be 1. |
| 2171 | */ |
| 2172 | |
| 2173 | if (n % d == 0) { |
| 2174 | n /= d; |
| 2175 | d = 1; |
| 2176 | } |
| 2177 | else { |
| 2178 | static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 }; |
| 2179 | |
| 2180 | /* This is a poor man's way to reduce a fraction. It's far from |
| 2181 | * perfect, but it will work well enough for this situation. |
| 2182 | */ |
| 2183 | |
| 2184 | for (i = 0; f[i] != 0; i++) { |
| 2185 | while (n % f[i] == 0 && d % f[i] == 0) { |
| 2186 | d /= f[i]; |
| 2187 | n /= f[i]; |
| 2188 | } |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | *numerator = n; |
| 2193 | *denominator = d; |
| 2194 | |
| 2195 | return True; |
| 2196 | } |
| 2197 | else |
| 2198 | return False; |
| 2199 | #else |
| 2200 | return False; |
| 2201 | #endif |
| 2202 | } |
| 2203 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2204 | |
| 2205 | /** |
| 2206 | * Determine the refresh rate of the specified drawable and display. |
| 2207 | * |
| 2208 | * \param dpy Display whose refresh rate is to be determined. |
| 2209 | * \param drawable Drawable whose refresh rate is to be determined. |
| 2210 | * \param numerator Numerator of the refresh rate. |
| 2211 | * \param demoninator Denominator of the refresh rate. |
| 2212 | * \return If the refresh rate for the specified display and drawable could |
| 2213 | * be calculated, True is returned. Otherwise False is returned. |
| 2214 | * |
| 2215 | * \note This function is implemented entirely client-side. A lot of other |
| 2216 | * functionality is required to export GLX_OML_sync_control, so on |
| 2217 | * XFree86 this function can be called for direct-rendering contexts |
| 2218 | * when GLX_OML_sync_control appears in the client extension string. |
| 2219 | */ |
| 2220 | |
Kristian Høgsberg | 3d28a26 | 2008-03-08 22:28:01 -0500 | [diff] [blame] | 2221 | _X_HIDDEN GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, |
| 2222 | int32_t * numerator, |
| 2223 | int32_t * denominator) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2224 | { |
| 2225 | #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE ) |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2226 | __DRIdrawable *driDraw = GetDRIDrawable(dpy, drawable, NULL); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2227 | |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2228 | if (driDraw == NULL) |
| 2229 | return False; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2230 | |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2231 | return __driGetMscRateOML(driDraw, numerator, denominator); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2232 | #else |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2233 | (void) dpy; |
| 2234 | (void) drawable; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2235 | (void) numerator; |
| 2236 | (void) denominator; |
| 2237 | #endif |
| 2238 | return False; |
| 2239 | } |
| 2240 | |
| 2241 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2242 | static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable, |
| 2243 | int64_t target_msc, int64_t divisor, |
| 2244 | int64_t remainder) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2245 | { |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2246 | #ifdef __DRI_SWAP_BUFFER_COUNTER |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2247 | int screen; |
| 2248 | __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen ); |
| 2249 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); |
| 2250 | |
| 2251 | /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE |
| 2252 | * error", but it also says "It [glXSwapBuffersMscOML] will return a value |
| 2253 | * of -1 if the function failed because of errors detected in the input |
| 2254 | * parameters" |
| 2255 | */ |
| 2256 | if ( divisor < 0 || remainder < 0 || target_msc < 0 ) |
| 2257 | return -1; |
| 2258 | if ( divisor > 0 && remainder >= divisor ) |
| 2259 | return -1; |
| 2260 | |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2261 | if (pdraw != NULL && psc->counters != NULL) |
| 2262 | return (*psc->sbc->swapBuffersMSC)(pdraw, target_msc, |
| 2263 | divisor, remainder); |
| 2264 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2265 | #else |
| 2266 | (void) dpy; |
| 2267 | (void) drawable; |
| 2268 | (void) target_msc; |
| 2269 | (void) divisor; |
| 2270 | (void) remainder; |
| 2271 | #endif |
| 2272 | return 0; |
| 2273 | } |
| 2274 | |
| 2275 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2276 | static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable, |
| 2277 | int64_t target_msc, int64_t divisor, |
| 2278 | int64_t remainder, int64_t *ust, |
| 2279 | int64_t *msc, int64_t *sbc) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2280 | { |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2281 | #ifdef __DRI_MEDIA_STREAM_COUNTER |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2282 | int screen; |
| 2283 | __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen ); |
| 2284 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); |
| 2285 | int ret; |
| 2286 | |
| 2287 | /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE |
| 2288 | * error", but the return type in the spec is Bool. |
| 2289 | */ |
| 2290 | if ( divisor < 0 || remainder < 0 || target_msc < 0 ) |
| 2291 | return False; |
| 2292 | if ( divisor > 0 && remainder >= divisor ) |
| 2293 | return False; |
| 2294 | |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2295 | if (pdraw != NULL && psc->msc != NULL) { |
| 2296 | ret = (*psc->msc->waitForMSC)(pdraw, target_msc, |
| 2297 | divisor, remainder, msc, sbc); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2298 | |
| 2299 | /* __glXGetUST returns zero on success and non-zero on failure. |
| 2300 | * This function returns True on success and False on failure. |
| 2301 | */ |
| 2302 | return ( (ret == 0) && (__glXGetUST( ust ) == 0) ); |
| 2303 | } |
| 2304 | #else |
| 2305 | (void) dpy; |
| 2306 | (void) drawable; |
| 2307 | (void) target_msc; |
| 2308 | (void) divisor; |
| 2309 | (void) remainder; |
| 2310 | (void) ust; |
| 2311 | (void) msc; |
| 2312 | (void) sbc; |
| 2313 | #endif |
| 2314 | return False; |
| 2315 | } |
| 2316 | |
| 2317 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2318 | static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable, |
| 2319 | int64_t target_sbc, int64_t *ust, |
| 2320 | int64_t *msc, int64_t *sbc ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2321 | { |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2322 | #ifdef __DRI_SWAP_BUFFER_COUNTER |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2323 | int screen; |
| 2324 | __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen ); |
| 2325 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); |
| 2326 | int ret; |
| 2327 | |
| 2328 | /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE |
| 2329 | * error", but the return type in the spec is Bool. |
| 2330 | */ |
| 2331 | if ( target_sbc < 0 ) |
| 2332 | return False; |
| 2333 | |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2334 | if (pdraw != NULL && psc->sbc != NULL) { |
| 2335 | ret = (*psc->sbc->waitForSBC)(pdraw, target_sbc, msc, sbc); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2336 | |
| 2337 | /* __glXGetUST returns zero on success and non-zero on failure. |
| 2338 | * This function returns True on success and False on failure. |
| 2339 | */ |
| 2340 | return( (ret == 0) && (__glXGetUST( ust ) == 0) ); |
| 2341 | } |
| 2342 | #else |
| 2343 | (void) dpy; |
| 2344 | (void) drawable; |
| 2345 | (void) target_sbc; |
| 2346 | (void) ust; |
| 2347 | (void) msc; |
| 2348 | (void) sbc; |
| 2349 | #endif |
| 2350 | return False; |
| 2351 | } |
| 2352 | |
| 2353 | |
| 2354 | /** |
| 2355 | * GLX_MESA_allocate_memory |
| 2356 | */ |
| 2357 | /*@{*/ |
| 2358 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2359 | PUBLIC void *glXAllocateMemoryMESA(Display *dpy, int scrn, |
| 2360 | size_t size, float readFreq, |
| 2361 | float writeFreq, float priority) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2362 | { |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2363 | #ifdef __DRI_ALLOCATE |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2364 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); |
| 2365 | |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2366 | if (psc && psc->allocate) |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 2367 | return (*psc->allocate->allocateMemory)( &psc->__driScreen, size, |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2368 | readFreq, writeFreq, |
| 2369 | priority ); |
| 2370 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2371 | #else |
| 2372 | (void) dpy; |
| 2373 | (void) scrn; |
| 2374 | (void) size; |
| 2375 | (void) readFreq; |
| 2376 | (void) writeFreq; |
| 2377 | (void) priority; |
| 2378 | #endif /* GLX_DIRECT_RENDERING */ |
| 2379 | |
| 2380 | return NULL; |
| 2381 | } |
| 2382 | |
| 2383 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2384 | PUBLIC void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2385 | { |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2386 | #ifdef __DRI_ALLOCATE |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2387 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); |
| 2388 | |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2389 | if (psc && psc->allocate) |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 2390 | (*psc->allocate->freeMemory)( &psc->__driScreen, pointer ); |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2391 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2392 | #else |
| 2393 | (void) dpy; |
| 2394 | (void) scrn; |
| 2395 | (void) pointer; |
| 2396 | #endif /* GLX_DIRECT_RENDERING */ |
| 2397 | } |
| 2398 | |
| 2399 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2400 | PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn, |
| 2401 | const void *pointer ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2402 | { |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2403 | #ifdef __DRI_ALLOCATE |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2404 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); |
| 2405 | |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2406 | if (psc && psc->allocate) |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 2407 | return (*psc->allocate->memoryOffset)( &psc->__driScreen, pointer ); |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2408 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2409 | #else |
| 2410 | (void) dpy; |
| 2411 | (void) scrn; |
| 2412 | (void) pointer; |
| 2413 | #endif /* GLX_DIRECT_RENDERING */ |
| 2414 | |
| 2415 | return ~0L; |
| 2416 | } |
| 2417 | /*@}*/ |
| 2418 | |
| 2419 | |
| 2420 | /** |
| 2421 | * Mesa extension stubs. These will help reduce portability problems. |
| 2422 | */ |
| 2423 | /*@{*/ |
| 2424 | |
| 2425 | /** |
| 2426 | * Release all buffers associated with the specified GLX drawable. |
| 2427 | * |
| 2428 | * \todo |
| 2429 | * This function was intended for stand-alone Mesa. The issue there is that |
| 2430 | * the library doesn't get any notification when a window is closed. In |
| 2431 | * DRI there is a similar but slightly different issue. When GLX 1.3 is |
| 2432 | * supported, there are 3 different functions to destroy a drawable. It |
| 2433 | * should be possible to create GLX protocol (or have it determine which |
| 2434 | * protocol to use based on the type of the drawable) to have one function |
| 2435 | * do the work of 3. For the direct-rendering case, this function could |
| 2436 | * just call the driver's \c __DRIdrawableRec::destroyDrawable function. |
| 2437 | * This would reduce the frequency with which \c __driGarbageCollectDrawables |
| 2438 | * would need to be used. This really should be done as part of the new DRI |
| 2439 | * interface work. |
| 2440 | * |
| 2441 | * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt |
| 2442 | * __driGarbageCollectDrawables |
| 2443 | * glXDestroyGLXPixmap |
| 2444 | * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow |
| 2445 | * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX |
| 2446 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2447 | static Bool __glXReleaseBuffersMESA( Display *dpy, GLXDrawable d ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2448 | { |
| 2449 | (void) dpy; |
| 2450 | (void) d; |
| 2451 | return False; |
| 2452 | } |
| 2453 | |
| 2454 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2455 | PUBLIC GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual, |
| 2456 | Pixmap pixmap, Colormap cmap ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2457 | { |
| 2458 | (void) dpy; |
| 2459 | (void) visual; |
| 2460 | (void) pixmap; |
| 2461 | (void) cmap; |
| 2462 | return 0; |
| 2463 | } |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2464 | /*@}*/ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2465 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2466 | |
| 2467 | /** |
| 2468 | * GLX_MESA_copy_sub_buffer |
| 2469 | */ |
Brian Paul | f2ad1b6 | 2006-03-31 15:48:04 +0000 | [diff] [blame] | 2470 | #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2471 | static void __glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable, |
| 2472 | int x, int y, int width, int height) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2473 | { |
Brian Paul | f2ad1b6 | 2006-03-31 15:48:04 +0000 | [diff] [blame] | 2474 | xGLXVendorPrivateReq *req; |
| 2475 | GLXContext gc; |
| 2476 | GLXContextTag tag; |
| 2477 | CARD32 *drawable_ptr; |
| 2478 | INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr; |
| 2479 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2480 | |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 2481 | #ifdef __DRI_COPY_SUB_BUFFER |
Brian Paul | f2ad1b6 | 2006-03-31 15:48:04 +0000 | [diff] [blame] | 2482 | int screen; |
| 2483 | __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen ); |
| 2484 | if ( pdraw != NULL ) { |
| 2485 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 2486 | if (psc->copySubBuffer != NULL) { |
| 2487 | (*psc->copySubBuffer->copySubBuffer)(pdraw, x, y, width, height); |
Brian Paul | f2ad1b6 | 2006-03-31 15:48:04 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | return; |
| 2491 | } |
| 2492 | #endif |
| 2493 | |
| 2494 | opcode = __glXSetupForCommand(dpy); |
| 2495 | if (!opcode) |
| 2496 | return; |
| 2497 | |
| 2498 | /* |
| 2499 | ** The calling thread may or may not have a current context. If it |
| 2500 | ** does, send the context tag so the server can do a flush. |
| 2501 | */ |
| 2502 | gc = __glXGetCurrentContext(); |
| 2503 | if ((gc != NULL) && (dpy == gc->currentDpy) && |
| 2504 | ((drawable == gc->currentDrawable) || |
| 2505 | (drawable == gc->currentReadable)) ) { |
| 2506 | tag = gc->currentContextTag; |
| 2507 | } else { |
| 2508 | tag = 0; |
| 2509 | } |
| 2510 | |
| 2511 | LockDisplay(dpy); |
| 2512 | GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4,req); |
| 2513 | req->reqType = opcode; |
| 2514 | req->glxCode = X_GLXVendorPrivate; |
| 2515 | req->vendorCode = X_GLXvop_CopySubBufferMESA; |
| 2516 | req->contextTag = tag; |
| 2517 | |
| 2518 | drawable_ptr = (CARD32 *) (req + 1); |
| 2519 | x_ptr = (INT32 *) (drawable_ptr + 1); |
| 2520 | y_ptr = (INT32 *) (drawable_ptr + 2); |
| 2521 | w_ptr = (INT32 *) (drawable_ptr + 3); |
| 2522 | h_ptr = (INT32 *) (drawable_ptr + 4); |
| 2523 | |
| 2524 | *drawable_ptr = drawable; |
| 2525 | *x_ptr = x; |
| 2526 | *y_ptr = y; |
| 2527 | *w_ptr = width; |
| 2528 | *h_ptr = height; |
| 2529 | |
| 2530 | UnlockDisplay(dpy); |
| 2531 | SyncHandle(); |
| 2532 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2533 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2534 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2535 | /** |
| 2536 | * GLX_EXT_texture_from_pixmap |
| 2537 | */ |
| 2538 | /*@{*/ |
| 2539 | static void __glXBindTexImageEXT(Display *dpy, |
| 2540 | GLXDrawable drawable, |
| 2541 | int buffer, |
| 2542 | const int *attrib_list) |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2543 | { |
| 2544 | xGLXVendorPrivateReq *req; |
| 2545 | GLXContext gc = __glXGetCurrentContext(); |
| 2546 | CARD32 *drawable_ptr; |
| 2547 | INT32 *buffer_ptr; |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2548 | CARD32 *num_attrib_ptr; |
| 2549 | CARD32 *attrib_ptr; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2550 | CARD8 opcode; |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2551 | unsigned int i; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2552 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2553 | if (gc == NULL) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2554 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2555 | |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2556 | i = 0; |
| 2557 | if (attrib_list) { |
| 2558 | while (attrib_list[i * 2] != None) |
| 2559 | i++; |
| 2560 | } |
| 2561 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2562 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 2563 | if (gc->driContext) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2564 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2565 | #endif |
| 2566 | |
| 2567 | opcode = __glXSetupForCommand(dpy); |
| 2568 | if (!opcode) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2569 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2570 | |
| 2571 | LockDisplay(dpy); |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2572 | GetReqExtra(GLXVendorPrivate, 12 + 8 * i,req); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2573 | req->reqType = opcode; |
| 2574 | req->glxCode = X_GLXVendorPrivate; |
| 2575 | req->vendorCode = X_GLXvop_BindTexImageEXT; |
| 2576 | req->contextTag = gc->currentContextTag; |
| 2577 | |
| 2578 | drawable_ptr = (CARD32 *) (req + 1); |
| 2579 | buffer_ptr = (INT32 *) (drawable_ptr + 1); |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2580 | num_attrib_ptr = (CARD32 *) (buffer_ptr + 1); |
| 2581 | attrib_ptr = (CARD32 *) (num_attrib_ptr + 1); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2582 | |
| 2583 | *drawable_ptr = drawable; |
| 2584 | *buffer_ptr = buffer; |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2585 | *num_attrib_ptr = (CARD32) i; |
| 2586 | |
| 2587 | i = 0; |
| 2588 | if (attrib_list) { |
| 2589 | while (attrib_list[i * 2] != None) |
| 2590 | { |
| 2591 | *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0]; |
| 2592 | *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1]; |
| 2593 | i++; |
| 2594 | } |
| 2595 | } |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2596 | |
| 2597 | UnlockDisplay(dpy); |
| 2598 | SyncHandle(); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2599 | } |
| 2600 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2601 | static void __glXReleaseTexImageEXT(Display *dpy, |
| 2602 | GLXDrawable drawable, |
| 2603 | int buffer) |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2604 | { |
| 2605 | xGLXVendorPrivateReq *req; |
| 2606 | GLXContext gc = __glXGetCurrentContext(); |
| 2607 | CARD32 *drawable_ptr; |
| 2608 | INT32 *buffer_ptr; |
| 2609 | CARD8 opcode; |
| 2610 | |
| 2611 | if (gc == NULL) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2612 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2613 | |
| 2614 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 2615 | if (gc->driContext) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2616 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2617 | #endif |
| 2618 | |
| 2619 | opcode = __glXSetupForCommand(dpy); |
| 2620 | if (!opcode) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2621 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2622 | |
| 2623 | LockDisplay(dpy); |
| 2624 | GetReqExtra(GLXVendorPrivate, sizeof(CARD32)+sizeof(INT32),req); |
| 2625 | req->reqType = opcode; |
| 2626 | req->glxCode = X_GLXVendorPrivate; |
| 2627 | req->vendorCode = X_GLXvop_ReleaseTexImageEXT; |
| 2628 | req->contextTag = gc->currentContextTag; |
| 2629 | |
| 2630 | drawable_ptr = (CARD32 *) (req + 1); |
| 2631 | buffer_ptr = (INT32 *) (drawable_ptr + 1); |
| 2632 | |
| 2633 | *drawable_ptr = drawable; |
| 2634 | *buffer_ptr = buffer; |
| 2635 | |
| 2636 | UnlockDisplay(dpy); |
| 2637 | SyncHandle(); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2638 | } |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2639 | /*@}*/ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2640 | |
| 2641 | /** |
| 2642 | * \c strdup is actually not a standard ANSI C or POSIX routine. |
| 2643 | * Irix will not define it if ANSI mode is in effect. |
| 2644 | * |
| 2645 | * \sa strdup |
| 2646 | */ |
Kristian Høgsberg | 3d28a26 | 2008-03-08 22:28:01 -0500 | [diff] [blame] | 2647 | _X_HIDDEN char * |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2648 | __glXstrdup(const char *str) |
| 2649 | { |
| 2650 | char *copy; |
| 2651 | copy = (char *) Xmalloc(strlen(str) + 1); |
| 2652 | if (!copy) |
| 2653 | return NULL; |
| 2654 | strcpy(copy, str); |
| 2655 | return copy; |
| 2656 | } |
| 2657 | |
| 2658 | /* |
| 2659 | ** glXGetProcAddress support |
| 2660 | */ |
| 2661 | |
| 2662 | struct name_address_pair { |
| 2663 | const char *Name; |
| 2664 | GLvoid *Address; |
| 2665 | }; |
| 2666 | |
| 2667 | #define GLX_FUNCTION(f) { # f, (GLvoid *) f } |
| 2668 | #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f } |
| 2669 | |
| 2670 | static const struct name_address_pair GLX_functions[] = { |
| 2671 | /*** GLX_VERSION_1_0 ***/ |
| 2672 | GLX_FUNCTION( glXChooseVisual ), |
| 2673 | GLX_FUNCTION( glXCopyContext ), |
| 2674 | GLX_FUNCTION( glXCreateContext ), |
| 2675 | GLX_FUNCTION( glXCreateGLXPixmap ), |
| 2676 | GLX_FUNCTION( glXDestroyContext ), |
| 2677 | GLX_FUNCTION( glXDestroyGLXPixmap ), |
| 2678 | GLX_FUNCTION( glXGetConfig ), |
| 2679 | GLX_FUNCTION( glXGetCurrentContext ), |
| 2680 | GLX_FUNCTION( glXGetCurrentDrawable ), |
| 2681 | GLX_FUNCTION( glXIsDirect ), |
| 2682 | GLX_FUNCTION( glXMakeCurrent ), |
| 2683 | GLX_FUNCTION( glXQueryExtension ), |
| 2684 | GLX_FUNCTION( glXQueryVersion ), |
| 2685 | GLX_FUNCTION( glXSwapBuffers ), |
| 2686 | GLX_FUNCTION( glXUseXFont ), |
| 2687 | GLX_FUNCTION( glXWaitGL ), |
| 2688 | GLX_FUNCTION( glXWaitX ), |
| 2689 | |
| 2690 | /*** GLX_VERSION_1_1 ***/ |
| 2691 | GLX_FUNCTION( glXGetClientString ), |
| 2692 | GLX_FUNCTION( glXQueryExtensionsString ), |
| 2693 | GLX_FUNCTION( glXQueryServerString ), |
| 2694 | |
| 2695 | /*** GLX_VERSION_1_2 ***/ |
| 2696 | GLX_FUNCTION( glXGetCurrentDisplay ), |
| 2697 | |
| 2698 | /*** GLX_VERSION_1_3 ***/ |
| 2699 | GLX_FUNCTION( glXChooseFBConfig ), |
| 2700 | GLX_FUNCTION( glXCreateNewContext ), |
| 2701 | GLX_FUNCTION( glXCreatePbuffer ), |
| 2702 | GLX_FUNCTION( glXCreatePixmap ), |
| 2703 | GLX_FUNCTION( glXCreateWindow ), |
| 2704 | GLX_FUNCTION( glXDestroyPbuffer ), |
| 2705 | GLX_FUNCTION( glXDestroyPixmap ), |
| 2706 | GLX_FUNCTION( glXDestroyWindow ), |
| 2707 | GLX_FUNCTION( glXGetCurrentReadDrawable ), |
| 2708 | GLX_FUNCTION( glXGetFBConfigAttrib ), |
| 2709 | GLX_FUNCTION( glXGetFBConfigs ), |
| 2710 | GLX_FUNCTION( glXGetSelectedEvent ), |
| 2711 | GLX_FUNCTION( glXGetVisualFromFBConfig ), |
| 2712 | GLX_FUNCTION( glXMakeContextCurrent ), |
| 2713 | GLX_FUNCTION( glXQueryContext ), |
| 2714 | GLX_FUNCTION( glXQueryDrawable ), |
| 2715 | GLX_FUNCTION( glXSelectEvent ), |
| 2716 | |
| 2717 | /*** GLX_SGI_swap_control ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2718 | GLX_FUNCTION2( glXSwapIntervalSGI, __glXSwapIntervalSGI ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2719 | |
| 2720 | /*** GLX_SGI_video_sync ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2721 | GLX_FUNCTION2( glXGetVideoSyncSGI, __glXGetVideoSyncSGI ), |
| 2722 | GLX_FUNCTION2( glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2723 | |
| 2724 | /*** GLX_SGI_make_current_read ***/ |
| 2725 | GLX_FUNCTION2( glXMakeCurrentReadSGI, glXMakeContextCurrent ), |
| 2726 | GLX_FUNCTION2( glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable ), |
| 2727 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2728 | /*** GLX_EXT_import_context ***/ |
| 2729 | GLX_FUNCTION( glXFreeContextEXT ), |
| 2730 | GLX_FUNCTION( glXGetContextIDEXT ), |
| 2731 | GLX_FUNCTION2( glXGetCurrentDisplayEXT, glXGetCurrentDisplay ), |
| 2732 | GLX_FUNCTION( glXImportContextEXT ), |
| 2733 | GLX_FUNCTION2( glXQueryContextInfoEXT, glXQueryContext ), |
| 2734 | |
| 2735 | /*** GLX_SGIX_fbconfig ***/ |
| 2736 | GLX_FUNCTION2( glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib ), |
| 2737 | GLX_FUNCTION2( glXChooseFBConfigSGIX, glXChooseFBConfig ), |
| 2738 | GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX ), |
| 2739 | GLX_FUNCTION( glXCreateContextWithConfigSGIX ), |
| 2740 | GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig ), |
| 2741 | GLX_FUNCTION( glXGetFBConfigFromVisualSGIX ), |
| 2742 | |
| 2743 | /*** GLX_SGIX_pbuffer ***/ |
| 2744 | GLX_FUNCTION( glXCreateGLXPbufferSGIX ), |
| 2745 | GLX_FUNCTION( glXDestroyGLXPbufferSGIX ), |
| 2746 | GLX_FUNCTION( glXQueryGLXPbufferSGIX ), |
| 2747 | GLX_FUNCTION( glXSelectEventSGIX ), |
| 2748 | GLX_FUNCTION( glXGetSelectedEventSGIX ), |
| 2749 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2750 | /*** GLX_SGIX_swap_group ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2751 | GLX_FUNCTION2( glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2752 | |
| 2753 | /*** GLX_SGIX_swap_barrier ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2754 | GLX_FUNCTION2( glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX ), |
| 2755 | GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2756 | |
| 2757 | /*** GLX_MESA_allocate_memory ***/ |
| 2758 | GLX_FUNCTION( glXAllocateMemoryMESA ), |
| 2759 | GLX_FUNCTION( glXFreeMemoryMESA ), |
| 2760 | GLX_FUNCTION( glXGetMemoryOffsetMESA ), |
| 2761 | |
| 2762 | /*** GLX_MESA_copy_sub_buffer ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2763 | GLX_FUNCTION2( glXCopySubBufferMESA, __glXCopySubBufferMESA ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2764 | |
| 2765 | /*** GLX_MESA_pixmap_colormap ***/ |
| 2766 | GLX_FUNCTION( glXCreateGLXPixmapMESA ), |
| 2767 | |
| 2768 | /*** GLX_MESA_release_buffers ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2769 | GLX_FUNCTION2( glXReleaseBuffersMESA, __glXReleaseBuffersMESA ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2770 | |
| 2771 | /*** GLX_MESA_swap_control ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2772 | GLX_FUNCTION2( glXSwapIntervalMESA, __glXSwapIntervalMESA ), |
| 2773 | GLX_FUNCTION2( glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2774 | |
| 2775 | /*** GLX_MESA_swap_frame_usage ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2776 | GLX_FUNCTION2( glXBeginFrameTrackingMESA, __glXBeginFrameTrackingMESA ), |
| 2777 | GLX_FUNCTION2( glXEndFrameTrackingMESA, __glXEndFrameTrackingMESA ), |
| 2778 | GLX_FUNCTION2( glXGetFrameUsageMESA, __glXGetFrameUsageMESA ), |
| 2779 | GLX_FUNCTION2( glXQueryFrameTrackingMESA, __glXQueryFrameTrackingMESA ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2780 | |
| 2781 | /*** GLX_ARB_get_proc_address ***/ |
| 2782 | GLX_FUNCTION( glXGetProcAddressARB ), |
| 2783 | |
| 2784 | /*** GLX 1.4 ***/ |
| 2785 | GLX_FUNCTION2( glXGetProcAddress, glXGetProcAddressARB ), |
| 2786 | |
| 2787 | /*** GLX_OML_sync_control ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2788 | GLX_FUNCTION2( glXWaitForSbcOML, __glXWaitForSbcOML ), |
| 2789 | GLX_FUNCTION2( glXWaitForMscOML, __glXWaitForMscOML ), |
| 2790 | GLX_FUNCTION2( glXSwapBuffersMscOML, __glXSwapBuffersMscOML ), |
| 2791 | GLX_FUNCTION2( glXGetMscRateOML, __glXGetMscRateOML ), |
| 2792 | GLX_FUNCTION2( glXGetSyncValuesOML, __glXGetSyncValuesOML ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2793 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2794 | /*** GLX_EXT_texture_from_pixmap ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2795 | GLX_FUNCTION2( glXBindTexImageEXT, __glXBindTexImageEXT ), |
| 2796 | GLX_FUNCTION2( glXReleaseTexImageEXT, __glXReleaseTexImageEXT ), |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2797 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2798 | #ifdef GLX_DIRECT_RENDERING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2799 | /*** DRI configuration ***/ |
| 2800 | GLX_FUNCTION( glXGetScreenDriver ), |
| 2801 | GLX_FUNCTION( glXGetDriverConfig ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2802 | #endif |
| 2803 | |
| 2804 | { NULL, NULL } /* end of list */ |
| 2805 | }; |
| 2806 | |
| 2807 | |
| 2808 | static const GLvoid * |
| 2809 | get_glx_proc_address(const char *funcName) |
| 2810 | { |
| 2811 | GLuint i; |
| 2812 | |
| 2813 | /* try static functions */ |
| 2814 | for (i = 0; GLX_functions[i].Name; i++) { |
| 2815 | if (strcmp(GLX_functions[i].Name, funcName) == 0) |
| 2816 | return GLX_functions[i].Address; |
| 2817 | } |
| 2818 | |
| 2819 | return NULL; |
| 2820 | } |
| 2821 | |
| 2822 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2823 | /** |
| 2824 | * Get the address of a named GL function. This is the pre-GLX 1.4 name for |
| 2825 | * \c glXGetProcAddress. |
| 2826 | * |
| 2827 | * \param procName Name of a GL or GLX function. |
| 2828 | * \returns A pointer to the named function |
| 2829 | * |
| 2830 | * \sa glXGetProcAddress |
| 2831 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 2832 | PUBLIC void (*glXGetProcAddressARB(const GLubyte *procName))( void ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2833 | { |
| 2834 | typedef void (*gl_function)( void ); |
| 2835 | gl_function f; |
| 2836 | |
| 2837 | |
| 2838 | /* Search the table of GLX and internal functions first. If that |
| 2839 | * fails and the supplied name could be a valid core GL name, try |
| 2840 | * searching the core GL function table. This check is done to prevent |
| 2841 | * DRI based drivers from searching the core GL function table for |
| 2842 | * internal API functions. |
| 2843 | */ |
| 2844 | |
| 2845 | f = (gl_function) get_glx_proc_address((const char *) procName); |
| 2846 | if ( (f == NULL) && (procName[0] == 'g') && (procName[1] == 'l') |
| 2847 | && (procName[2] != 'X') ) { |
| 2848 | f = (gl_function) _glapi_get_proc_address((const char *) procName); |
| 2849 | } |
| 2850 | |
| 2851 | return f; |
| 2852 | } |
| 2853 | |
| 2854 | /** |
| 2855 | * Get the address of a named GL function. This is the GLX 1.4 name for |
| 2856 | * \c glXGetProcAddressARB. |
| 2857 | * |
| 2858 | * \param procName Name of a GL or GLX function. |
| 2859 | * \returns A pointer to the named function |
| 2860 | * |
| 2861 | * \sa glXGetProcAddressARB |
| 2862 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 2863 | PUBLIC void (*glXGetProcAddress(const GLubyte *procName))( void ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2864 | #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED) |
| 2865 | __attribute__ ((alias ("glXGetProcAddressARB"))); |
| 2866 | #else |
| 2867 | { |
| 2868 | return glXGetProcAddressARB(procName); |
| 2869 | } |
| 2870 | #endif /* __GNUC__ */ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2871 | |
| 2872 | |
| 2873 | #ifdef GLX_DIRECT_RENDERING |
| 2874 | /** |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2875 | * Get the unadjusted system time (UST). Currently, the UST is measured in |
| 2876 | * microseconds since Epoc. The actual resolution of the UST may vary from |
| 2877 | * system to system, and the units may vary from release to release. |
| 2878 | * Drivers should not call this function directly. They should instead use |
| 2879 | * \c glXGetProcAddress to obtain a pointer to the function. |
| 2880 | * |
| 2881 | * \param ust Location to store the 64-bit UST |
| 2882 | * \returns Zero on success or a negative errno value on failure. |
| 2883 | * |
| 2884 | * \sa glXGetProcAddress, PFNGLXGETUSTPROC |
| 2885 | * |
| 2886 | * \since Internal API version 20030317. |
| 2887 | */ |
Kristian Høgsberg | 3d28a26 | 2008-03-08 22:28:01 -0500 | [diff] [blame] | 2888 | _X_HIDDEN int __glXGetUST( int64_t * ust ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2889 | { |
| 2890 | struct timeval tv; |
| 2891 | |
| 2892 | if ( ust == NULL ) { |
| 2893 | return -EFAULT; |
| 2894 | } |
| 2895 | |
| 2896 | if ( gettimeofday( & tv, NULL ) == 0 ) { |
| 2897 | ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec; |
| 2898 | return 0; |
| 2899 | } else { |
| 2900 | return -errno; |
| 2901 | } |
| 2902 | } |
| 2903 | #endif /* GLX_DIRECT_RENDERING */ |