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