RALOVICH, Kristóf | 58b7210 | 2008-10-11 14:27:07 +0200 | [diff] [blame^] | 1 | /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2 | /* |
Adam Jackson | dc8058c | 2008-09-19 17:16:53 -0400 | [diff] [blame] | 3 | * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) |
| 4 | * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice including the dates of first publication and |
| 14 | * either this permission notice or a reference to |
| 15 | * http://oss.sgi.com/projects/FreeB/ |
| 16 | * shall be included in all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF |
| 23 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | * SOFTWARE. |
| 25 | * |
| 26 | * Except as contained in this notice, the name of Silicon Graphics, Inc. |
| 27 | * shall not be used in advertising or otherwise to promote the sale, use or |
| 28 | * other dealings in this Software without prior written authorization from |
| 29 | * Silicon Graphics, Inc. |
| 30 | */ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * \file glxcmds.c |
| 34 | * Client-side GLX interface. |
| 35 | */ |
| 36 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 37 | #include "glxclient.h" |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 38 | #include "glapi.h" |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 39 | #include "glxextensions.h" |
| 40 | #include "glcontextmodes.h" |
George Sapountzis | df04ffb | 2008-04-18 17:28:34 +0300 | [diff] [blame] | 41 | |
| 42 | #ifdef GLX_DIRECT_RENDERING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 43 | #include <sys/time.h> |
George Sapountzis | df04ffb | 2008-04-18 17:28:34 +0300 | [diff] [blame] | 44 | #include <X11/extensions/xf86vmode.h> |
| 45 | #include "xf86dri.h" |
| 46 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 47 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 48 | static const char __glXGLXClientVendorName[] = "SGI"; |
| 49 | static const char __glXGLXClientVersion[] = "1.4"; |
| 50 | |
| 51 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 52 | /****************************************************************************/ |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 53 | |
| 54 | #ifdef GLX_DIRECT_RENDERING |
| 55 | |
| 56 | static Bool windowExistsFlag; |
| 57 | static int windowExistsErrorHandler(Display *dpy, XErrorEvent *xerr) |
| 58 | { |
| 59 | if (xerr->error_code == BadWindow) { |
| 60 | windowExistsFlag = GL_FALSE; |
| 61 | } |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Find drawables in the local hash that have been destroyed on the |
| 67 | * server. |
| 68 | * |
| 69 | * \param dpy Display to destroy drawables for |
| 70 | * \param screen Screen number to destroy drawables for |
| 71 | */ |
Kristian Høgsberg | 9590ba9 | 2007-05-11 13:24:34 -0400 | [diff] [blame] | 72 | static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc) |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 73 | { |
Kristian Høgsberg | fa72013 | 2007-05-11 13:54:44 -0400 | [diff] [blame] | 74 | XID draw; |
Kristian Høgsberg | 20b9230 | 2008-03-08 21:02:23 -0500 | [diff] [blame] | 75 | __GLXDRIdrawable *pdraw; |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 76 | XWindowAttributes xwa; |
| 77 | int (*oldXErrorHandler)(Display *, XErrorEvent *); |
| 78 | |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 79 | /* Set no-op error handler so Xlib doesn't bail out if the windows |
| 80 | * has alreay been destroyed on the server. */ |
| 81 | XSync(dpy, GL_FALSE); |
| 82 | oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler); |
| 83 | |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 84 | if (__glxHashFirst(sc->drawHash, &draw, (void *)&pdraw) == 1) { |
| 85 | do { |
| 86 | windowExistsFlag = GL_TRUE; |
| 87 | XGetWindowAttributes(dpy, draw, &xwa); /* dummy request */ |
| 88 | if (!windowExistsFlag) { |
| 89 | /* Destroy the local drawable data, if the drawable no |
| 90 | longer exists in the Xserver */ |
Kristian Høgsberg | 9110425 | 2008-03-12 02:18:12 -0400 | [diff] [blame] | 91 | (*pdraw->destroyDrawable)(pdraw); |
WuNian | 16099c1 | 2007-11-27 18:22:42 -0700 | [diff] [blame] | 92 | __glxHashDelete(sc->drawHash, draw); |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 93 | } |
| 94 | } while (__glxHashNext(sc->drawHash, &draw, (void *)&pdraw) == 1); |
| 95 | } |
| 96 | |
Chris Rankin | 1421bff | 2007-10-29 14:37:32 -0400 | [diff] [blame] | 97 | XSync(dpy, GL_FALSE); |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 98 | XSetErrorHandler(oldXErrorHandler); |
| 99 | } |
| 100 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 101 | extern __GLXDRIdrawable * |
| 102 | GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num); |
| 103 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 104 | /** |
| 105 | * Get the __DRIdrawable for the drawable associated with a GLXContext |
| 106 | * |
| 107 | * \param dpy The display associated with \c drawable. |
| 108 | * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved. |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 109 | * \param scrn_num If non-NULL, the drawables screen is stored there |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 110 | * \returns A pointer to the context's __DRIdrawable on success, or NULL if |
| 111 | * the drawable is not associated with a direct-rendering context. |
| 112 | */ |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 113 | _X_HIDDEN __GLXDRIdrawable * |
| 114 | GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 115 | { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 116 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 117 | __GLXDRIdrawable *pdraw; |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 118 | const unsigned screen_count = ScreenCount(dpy); |
| 119 | unsigned i; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 120 | __GLXscreenConfigs *psc; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 121 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 122 | if (priv == NULL) |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 123 | return NULL; |
| 124 | |
| 125 | for (i = 0; i < screen_count; i++) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 126 | psc = &priv->screenConfigs[i]; |
| 127 | if (psc->drawHash == NULL) |
| 128 | continue; |
| 129 | |
| 130 | if (__glxHashLookup(psc->drawHash, drawable, (void *) &pdraw) == 0) { |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 131 | if (scrn_num != NULL) |
| 132 | *scrn_num = i; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 133 | return pdraw; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | return NULL; |
| 138 | } |
Kristian Høgsberg | 4a22ae8 | 2007-01-07 08:12:01 -0500 | [diff] [blame] | 139 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 140 | #endif |
| 141 | |
| 142 | |
| 143 | /** |
| 144 | * Get the GLX per-screen data structure associated with a GLX context. |
| 145 | * |
| 146 | * \param dpy Display for which the GLX per-screen information is to be |
| 147 | * retrieved. |
| 148 | * \param scrn Screen on \c dpy for which the GLX per-screen information is |
| 149 | * to be retrieved. |
| 150 | * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn |
| 151 | * specify a valid GLX screen, or NULL otherwise. |
| 152 | * |
| 153 | * \todo Should this function validate that \c scrn is within the screen |
| 154 | * number range for \c dpy? |
| 155 | */ |
| 156 | |
| 157 | static __GLXscreenConfigs * |
| 158 | GetGLXScreenConfigs(Display *dpy, int scrn) |
| 159 | { |
| 160 | __GLXdisplayPrivate * const priv = __glXInitialize(dpy); |
| 161 | |
| 162 | return (priv->screenConfigs != NULL) ? &priv->screenConfigs[scrn] : NULL; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | static int |
| 167 | GetGLXPrivScreenConfig( Display *dpy, int scrn, __GLXdisplayPrivate ** ppriv, |
| 168 | __GLXscreenConfigs ** ppsc ) |
| 169 | { |
| 170 | /* Initialize the extension, if needed . This has the added value |
| 171 | * of initializing/allocating the display private |
| 172 | */ |
| 173 | |
| 174 | if ( dpy == NULL ) { |
| 175 | return GLX_NO_EXTENSION; |
| 176 | } |
| 177 | |
| 178 | *ppriv = __glXInitialize(dpy); |
| 179 | if ( *ppriv == NULL ) { |
| 180 | return GLX_NO_EXTENSION; |
| 181 | } |
| 182 | |
| 183 | /* Check screen number to see if its valid */ |
| 184 | if ((scrn < 0) || (scrn >= ScreenCount(dpy))) { |
| 185 | return GLX_BAD_SCREEN; |
| 186 | } |
| 187 | |
| 188 | /* Check to see if the GL is supported on this screen */ |
| 189 | *ppsc = &((*ppriv)->screenConfigs[scrn]); |
| 190 | if ( (*ppsc)->configs == NULL ) { |
| 191 | /* No support for GL on this screen regardless of visual */ |
| 192 | return GLX_BAD_VISUAL; |
| 193 | } |
| 194 | |
| 195 | return Success; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | /** |
| 200 | * Determine if a \c GLXFBConfig supplied by the application is valid. |
| 201 | * |
| 202 | * \param dpy Application supplied \c Display pointer. |
| 203 | * \param config Application supplied \c GLXFBConfig. |
| 204 | * |
| 205 | * \returns If the \c GLXFBConfig is valid, the a pointer to the matching |
| 206 | * \c __GLcontextModes structure is returned. Otherwise, \c NULL |
| 207 | * is returned. |
| 208 | */ |
| 209 | static __GLcontextModes * |
| 210 | ValidateGLXFBConfig( Display * dpy, GLXFBConfig config ) |
| 211 | { |
| 212 | __GLXdisplayPrivate * const priv = __glXInitialize(dpy); |
| 213 | const unsigned num_screens = ScreenCount(dpy); |
| 214 | unsigned i; |
| 215 | const __GLcontextModes * modes; |
| 216 | |
| 217 | |
| 218 | if ( priv != NULL ) { |
| 219 | for ( i = 0 ; i < num_screens ; i++ ) { |
| 220 | for ( modes = priv->screenConfigs[i].configs |
| 221 | ; modes != NULL |
| 222 | ; modes = modes->next ) { |
| 223 | if ( modes == (__GLcontextModes *) config ) { |
| 224 | return (__GLcontextModes *) config; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return NULL; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | /** |
| 235 | * \todo It should be possible to move the allocate of \c client_state_private |
| 236 | * later in the function for direct-rendering contexts. Direct-rendering |
| 237 | * contexts don't need to track client state, so they don't need that memory |
| 238 | * at all. |
| 239 | * |
| 240 | * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new |
| 241 | * function called \c __glXAllocateClientState that allocates the memory and |
| 242 | * does all the initialization (including the pixel pack / unpack). |
| 243 | */ |
| 244 | static |
| 245 | GLXContext AllocateGLXContext( Display *dpy ) |
| 246 | { |
| 247 | GLXContext gc; |
| 248 | int bufSize; |
| 249 | CARD8 opcode; |
| 250 | __GLXattribute *state; |
| 251 | |
| 252 | if (!dpy) |
| 253 | return NULL; |
| 254 | |
| 255 | opcode = __glXSetupForCommand(dpy); |
| 256 | if (!opcode) { |
| 257 | return NULL; |
| 258 | } |
| 259 | |
| 260 | /* Allocate our context record */ |
| 261 | gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec)); |
| 262 | if (!gc) { |
| 263 | /* Out of memory */ |
| 264 | return NULL; |
| 265 | } |
| 266 | memset(gc, 0, sizeof(struct __GLXcontextRec)); |
| 267 | |
| 268 | state = Xmalloc(sizeof(struct __GLXattributeRec)); |
| 269 | if (state == NULL) { |
| 270 | /* Out of memory */ |
| 271 | Xfree(gc); |
| 272 | return NULL; |
| 273 | } |
| 274 | gc->client_state_private = state; |
| 275 | memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec)); |
| 276 | state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL); |
| 277 | |
| 278 | /* |
| 279 | ** Create a temporary buffer to hold GLX rendering commands. The size |
| 280 | ** of the buffer is selected so that the maximum number of GLX rendering |
| 281 | ** commands can fit in a single X packet and still have room in the X |
| 282 | ** packet for the GLXRenderReq header. |
| 283 | */ |
| 284 | |
| 285 | bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq; |
| 286 | gc->buf = (GLubyte *) Xmalloc(bufSize); |
| 287 | if (!gc->buf) { |
| 288 | Xfree(gc->client_state_private); |
| 289 | Xfree(gc); |
| 290 | return NULL; |
| 291 | } |
| 292 | gc->bufSize = bufSize; |
| 293 | |
| 294 | /* Fill in the new context */ |
| 295 | gc->renderMode = GL_RENDER; |
| 296 | |
| 297 | state->storePack.alignment = 4; |
| 298 | state->storeUnpack.alignment = 4; |
| 299 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 300 | gc->attributes.stackPointer = &gc->attributes.stack[0]; |
| 301 | |
| 302 | /* |
| 303 | ** PERFORMANCE NOTE: A mode dependent fill image can speed things up. |
| 304 | ** Other code uses the fastImageUnpack bit, but it is never set |
| 305 | ** to GL_TRUE. |
| 306 | */ |
| 307 | gc->fastImageUnpack = GL_FALSE; |
| 308 | gc->fillImage = __glFillImage; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 309 | gc->pc = gc->buf; |
| 310 | gc->bufEnd = gc->buf + bufSize; |
Xiang, Haihao | ae2c31e | 2008-03-18 15:02:57 +0800 | [diff] [blame] | 311 | gc->isDirect = GL_FALSE; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 312 | if (__glXDebug) { |
| 313 | /* |
| 314 | ** Set limit register so that there will be one command per packet |
| 315 | */ |
| 316 | gc->limit = gc->buf; |
| 317 | } else { |
| 318 | gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE; |
| 319 | } |
| 320 | gc->createDpy = dpy; |
| 321 | gc->majorOpcode = opcode; |
| 322 | |
| 323 | /* |
| 324 | ** Constrain the maximum drawing command size allowed to be |
| 325 | ** transfered using the X_GLXRender protocol request. First |
| 326 | ** constrain by a software limit, then constrain by the protocl |
| 327 | ** limit. |
| 328 | */ |
| 329 | if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) { |
| 330 | bufSize = __GLX_RENDER_CMD_SIZE_LIMIT; |
| 331 | } |
| 332 | if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) { |
| 333 | bufSize = __GLX_MAX_RENDER_CMD_SIZE; |
| 334 | } |
| 335 | gc->maxSmallRenderCommandSize = bufSize; |
| 336 | return gc; |
| 337 | } |
| 338 | |
| 339 | |
| 340 | /** |
| 341 | * Create a new context. Exactly one of \c vis and \c fbconfig should be |
| 342 | * non-NULL. |
| 343 | * |
| 344 | * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or |
| 345 | * SGIX_fbconfig protocol be used? |
| 346 | * \param renderType For FBConfigs, what is the rendering type? |
| 347 | */ |
| 348 | |
| 349 | static GLXContext |
| 350 | CreateContext(Display *dpy, XVisualInfo *vis, |
| 351 | const __GLcontextModes * const fbconfig, |
| 352 | GLXContext shareList, |
| 353 | Bool allowDirect, GLXContextID contextID, |
| 354 | Bool use_glx_1_3, int renderType) |
| 355 | { |
| 356 | GLXContext gc; |
Kristian Høgsberg | 3731159 | 2008-03-10 17:59:46 -0400 | [diff] [blame] | 357 | #ifdef GLX_DIRECT_RENDERING |
| 358 | int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen; |
| 359 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); |
| 360 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 361 | |
| 362 | if ( dpy == NULL ) |
| 363 | return NULL; |
| 364 | |
| 365 | gc = AllocateGLXContext(dpy); |
| 366 | if (!gc) |
| 367 | return NULL; |
| 368 | |
| 369 | if (None == contextID) { |
| 370 | if ( (vis == NULL) && (fbconfig == NULL) ) |
| 371 | return NULL; |
| 372 | |
| 373 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 3731159 | 2008-03-10 17:59:46 -0400 | [diff] [blame] | 374 | if (allowDirect && psc->driScreen) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 375 | const __GLcontextModes * mode; |
Kristian Høgsberg | 8e66c3d | 2007-11-05 17:02:03 -0500 | [diff] [blame] | 376 | |
| 377 | if (fbconfig == NULL) { |
| 378 | mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid); |
| 379 | if (mode == NULL) { |
| 380 | xError error; |
| 381 | |
| 382 | error.errorCode = BadValue; |
| 383 | error.resourceID = vis->visualid; |
| 384 | error.sequenceNumber = dpy->request; |
| 385 | error.type = X_Error; |
| 386 | error.majorCode = gc->majorOpcode; |
| 387 | error.minorCode = X_GLXCreateContext; |
| 388 | _XError(dpy, &error); |
| 389 | return None; |
| 390 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 391 | } |
| 392 | else { |
| 393 | mode = fbconfig; |
| 394 | } |
| 395 | |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 396 | gc->driContext = psc->driScreen->createContext(psc, mode, gc, |
| 397 | shareList, |
| 398 | renderType); |
| 399 | if (gc->driContext != NULL) { |
| 400 | gc->screen = mode->screen; |
| 401 | gc->psc = psc; |
| 402 | gc->mode = mode; |
Xiang, Haihao | ae2c31e | 2008-03-18 15:02:57 +0800 | [diff] [blame] | 403 | gc->isDirect = GL_TRUE; |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 404 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 405 | } |
| 406 | #endif |
| 407 | |
| 408 | LockDisplay(dpy); |
| 409 | if ( fbconfig == NULL ) { |
| 410 | xGLXCreateContextReq *req; |
| 411 | |
| 412 | /* Send the glXCreateContext request */ |
| 413 | GetReq(GLXCreateContext,req); |
| 414 | req->reqType = gc->majorOpcode; |
| 415 | req->glxCode = X_GLXCreateContext; |
| 416 | req->context = gc->xid = XAllocID(dpy); |
| 417 | req->visual = vis->visualid; |
| 418 | req->screen = vis->screen; |
| 419 | req->shareList = shareList ? shareList->xid : None; |
Jeremy Huddleston | 919ec22 | 2008-08-08 02:52:10 -0700 | [diff] [blame] | 420 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 421 | req->isDirect = gc->driContext != NULL; |
Jeremy Huddleston | 919ec22 | 2008-08-08 02:52:10 -0700 | [diff] [blame] | 422 | #else |
| 423 | req->isDirect = 0; |
| 424 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 425 | } |
| 426 | else if ( use_glx_1_3 ) { |
| 427 | xGLXCreateNewContextReq *req; |
| 428 | |
| 429 | /* Send the glXCreateNewContext request */ |
| 430 | GetReq(GLXCreateNewContext,req); |
| 431 | req->reqType = gc->majorOpcode; |
| 432 | req->glxCode = X_GLXCreateNewContext; |
| 433 | req->context = gc->xid = XAllocID(dpy); |
| 434 | req->fbconfig = fbconfig->fbconfigID; |
| 435 | req->screen = fbconfig->screen; |
| 436 | req->renderType = renderType; |
| 437 | req->shareList = shareList ? shareList->xid : None; |
Jeremy Huddleston | 919ec22 | 2008-08-08 02:52:10 -0700 | [diff] [blame] | 438 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 439 | req->isDirect = gc->driContext != NULL; |
Jeremy Huddleston | 919ec22 | 2008-08-08 02:52:10 -0700 | [diff] [blame] | 440 | #else |
| 441 | req->isDirect = 0; |
| 442 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 443 | } |
| 444 | else { |
| 445 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 446 | xGLXCreateContextWithConfigSGIXReq *req; |
| 447 | |
| 448 | /* Send the glXCreateNewContext request */ |
| 449 | GetReqExtra(GLXVendorPrivateWithReply, |
| 450 | sz_xGLXCreateContextWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq); |
| 451 | req = (xGLXCreateContextWithConfigSGIXReq *)vpreq; |
| 452 | req->reqType = gc->majorOpcode; |
| 453 | req->glxCode = X_GLXVendorPrivateWithReply; |
| 454 | req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX; |
| 455 | req->context = gc->xid = XAllocID(dpy); |
| 456 | req->fbconfig = fbconfig->fbconfigID; |
| 457 | req->screen = fbconfig->screen; |
| 458 | req->renderType = renderType; |
| 459 | req->shareList = shareList ? shareList->xid : None; |
Jeremy Huddleston | 919ec22 | 2008-08-08 02:52:10 -0700 | [diff] [blame] | 460 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 461 | req->isDirect = gc->driContext != NULL; |
Jeremy Huddleston | 919ec22 | 2008-08-08 02:52:10 -0700 | [diff] [blame] | 462 | #else |
| 463 | req->isDirect = 0; |
| 464 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | UnlockDisplay(dpy); |
| 468 | SyncHandle(); |
| 469 | gc->imported = GL_FALSE; |
| 470 | } |
| 471 | else { |
| 472 | gc->xid = contextID; |
| 473 | gc->imported = GL_TRUE; |
| 474 | } |
| 475 | |
| 476 | return gc; |
| 477 | } |
| 478 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 479 | PUBLIC GLXContext glXCreateContext(Display *dpy, XVisualInfo *vis, |
| 480 | GLXContext shareList, Bool allowDirect) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 481 | { |
| 482 | return CreateContext(dpy, vis, NULL, shareList, allowDirect, None, |
| 483 | False, 0); |
| 484 | } |
| 485 | |
Kristian Høgsberg | 3d28a26 | 2008-03-08 22:28:01 -0500 | [diff] [blame] | 486 | _X_HIDDEN void __glXFreeContext(__GLXcontext *gc) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 487 | { |
| 488 | if (gc->vendor) XFree((char *) gc->vendor); |
| 489 | if (gc->renderer) XFree((char *) gc->renderer); |
| 490 | if (gc->version) XFree((char *) gc->version); |
| 491 | if (gc->extensions) XFree((char *) gc->extensions); |
| 492 | __glFreeAttributeState(gc); |
| 493 | XFree((char *) gc->buf); |
| 494 | Xfree((char *) gc->client_state_private); |
| 495 | XFree((char *) gc); |
| 496 | |
| 497 | } |
| 498 | |
| 499 | /* |
| 500 | ** Destroy the named context |
| 501 | */ |
| 502 | static void |
| 503 | DestroyContext(Display *dpy, GLXContext gc) |
| 504 | { |
| 505 | xGLXDestroyContextReq *req; |
| 506 | GLXContextID xid; |
| 507 | CARD8 opcode; |
| 508 | GLboolean imported; |
| 509 | |
| 510 | opcode = __glXSetupForCommand(dpy); |
| 511 | if (!opcode || !gc) { |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | __glXLock(); |
| 516 | xid = gc->xid; |
| 517 | imported = gc->imported; |
| 518 | gc->xid = None; |
| 519 | |
| 520 | #ifdef GLX_DIRECT_RENDERING |
| 521 | /* Destroy the direct rendering context */ |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 522 | if (gc->driContext) { |
| 523 | (*gc->driContext->destroyContext)(gc->driContext, gc->psc, dpy); |
| 524 | gc->driContext = NULL; |
Kristian Høgsberg | 9590ba9 | 2007-05-11 13:24:34 -0400 | [diff] [blame] | 525 | GarbageCollectDRIDrawables(dpy, gc->psc); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 526 | } |
| 527 | #endif |
| 528 | |
Kristof Ralovich | e206034 | 2008-08-20 15:18:38 -0600 | [diff] [blame] | 529 | __glXFreeVertexArrayState(gc); |
| 530 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 531 | if (gc->currentDpy) { |
| 532 | /* Have to free later cuz it's in use now */ |
| 533 | __glXUnlock(); |
| 534 | } else { |
| 535 | /* Destroy the handle if not current to anybody */ |
| 536 | __glXUnlock(); |
| 537 | __glXFreeContext(gc); |
| 538 | } |
| 539 | |
| 540 | if (!imported) { |
| 541 | /* |
| 542 | ** This dpy also created the server side part of the context. |
| 543 | ** Send the glXDestroyContext request. |
| 544 | */ |
| 545 | LockDisplay(dpy); |
| 546 | GetReq(GLXDestroyContext,req); |
| 547 | req->reqType = opcode; |
| 548 | req->glxCode = X_GLXDestroyContext; |
| 549 | req->context = xid; |
| 550 | UnlockDisplay(dpy); |
| 551 | SyncHandle(); |
| 552 | } |
| 553 | } |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 554 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 555 | PUBLIC void glXDestroyContext(Display *dpy, GLXContext gc) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 556 | { |
| 557 | DestroyContext(dpy, gc); |
| 558 | } |
| 559 | |
| 560 | /* |
| 561 | ** Return the major and minor version #s for the GLX extension |
| 562 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 563 | PUBLIC Bool glXQueryVersion(Display *dpy, int *major, int *minor) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 564 | { |
| 565 | __GLXdisplayPrivate *priv; |
| 566 | |
| 567 | /* Init the extension. This fetches the major and minor version. */ |
| 568 | priv = __glXInitialize(dpy); |
| 569 | if (!priv) return GL_FALSE; |
| 570 | |
| 571 | if (major) *major = priv->majorVersion; |
| 572 | if (minor) *minor = priv->minorVersion; |
| 573 | return GL_TRUE; |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | ** Query the existance of the GLX extension |
| 578 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 579 | PUBLIC Bool glXQueryExtension(Display *dpy, int *errorBase, int *eventBase) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 580 | { |
| 581 | int major_op, erb, evb; |
| 582 | Bool rv; |
| 583 | |
| 584 | rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb); |
| 585 | if (rv) { |
| 586 | if (errorBase) *errorBase = erb; |
| 587 | if (eventBase) *eventBase = evb; |
| 588 | } |
| 589 | return rv; |
| 590 | } |
| 591 | |
| 592 | /* |
| 593 | ** Put a barrier in the token stream that forces the GL to finish its |
| 594 | ** work before X can proceed. |
| 595 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 596 | PUBLIC void glXWaitGL(void) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 597 | { |
| 598 | xGLXWaitGLReq *req; |
| 599 | GLXContext gc = __glXGetCurrentContext(); |
| 600 | Display *dpy = gc->currentDpy; |
| 601 | |
| 602 | if (!dpy) return; |
| 603 | |
| 604 | /* Flush any pending commands out */ |
| 605 | __glXFlushRenderBuffer(gc, gc->pc); |
| 606 | |
| 607 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 608 | if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 609 | /* This bit of ugliness unwraps the glFinish function */ |
| 610 | #ifdef glFinish |
| 611 | #undef glFinish |
| 612 | #endif |
| 613 | glFinish(); |
| 614 | return; |
| 615 | } |
| 616 | #endif |
| 617 | |
| 618 | /* Send the glXWaitGL request */ |
| 619 | LockDisplay(dpy); |
| 620 | GetReq(GLXWaitGL,req); |
| 621 | req->reqType = gc->majorOpcode; |
| 622 | req->glxCode = X_GLXWaitGL; |
| 623 | req->contextTag = gc->currentContextTag; |
| 624 | UnlockDisplay(dpy); |
| 625 | SyncHandle(); |
| 626 | } |
| 627 | |
| 628 | /* |
| 629 | ** Put a barrier in the token stream that forces X to finish its |
| 630 | ** work before GL can proceed. |
| 631 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 632 | PUBLIC void glXWaitX(void) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 633 | { |
| 634 | xGLXWaitXReq *req; |
| 635 | GLXContext gc = __glXGetCurrentContext(); |
| 636 | Display *dpy = gc->currentDpy; |
| 637 | |
| 638 | if (!dpy) return; |
| 639 | |
| 640 | /* Flush any pending commands out */ |
| 641 | __glXFlushRenderBuffer(gc, gc->pc); |
| 642 | |
| 643 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 644 | if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 645 | XSync(dpy, False); |
| 646 | return; |
| 647 | } |
| 648 | #endif |
| 649 | |
| 650 | /* |
| 651 | ** Send the glXWaitX request. |
| 652 | */ |
| 653 | LockDisplay(dpy); |
| 654 | GetReq(GLXWaitX,req); |
| 655 | req->reqType = gc->majorOpcode; |
| 656 | req->glxCode = X_GLXWaitX; |
| 657 | req->contextTag = gc->currentContextTag; |
| 658 | UnlockDisplay(dpy); |
| 659 | SyncHandle(); |
| 660 | } |
| 661 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 662 | PUBLIC void glXUseXFont(Font font, int first, int count, int listBase) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 663 | { |
| 664 | xGLXUseXFontReq *req; |
| 665 | GLXContext gc = __glXGetCurrentContext(); |
| 666 | Display *dpy = gc->currentDpy; |
| 667 | |
| 668 | if (!dpy) return; |
| 669 | |
| 670 | /* Flush any pending commands out */ |
| 671 | (void) __glXFlushRenderBuffer(gc, gc->pc); |
| 672 | |
| 673 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 674 | if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 675 | DRI_glXUseXFont(font, first, count, listBase); |
| 676 | return; |
| 677 | } |
| 678 | #endif |
| 679 | |
| 680 | /* Send the glXUseFont request */ |
| 681 | LockDisplay(dpy); |
| 682 | GetReq(GLXUseXFont,req); |
| 683 | req->reqType = gc->majorOpcode; |
| 684 | req->glxCode = X_GLXUseXFont; |
| 685 | req->contextTag = gc->currentContextTag; |
| 686 | req->font = font; |
| 687 | req->first = first; |
| 688 | req->count = count; |
| 689 | req->listBase = listBase; |
| 690 | UnlockDisplay(dpy); |
| 691 | SyncHandle(); |
| 692 | } |
| 693 | |
| 694 | /************************************************************************/ |
| 695 | |
| 696 | /* |
| 697 | ** Copy the source context to the destination context using the |
| 698 | ** attribute "mask". |
| 699 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 700 | PUBLIC void glXCopyContext(Display *dpy, GLXContext source, |
| 701 | GLXContext dest, unsigned long mask) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 702 | { |
| 703 | xGLXCopyContextReq *req; |
| 704 | GLXContext gc = __glXGetCurrentContext(); |
| 705 | GLXContextTag tag; |
| 706 | CARD8 opcode; |
| 707 | |
| 708 | opcode = __glXSetupForCommand(dpy); |
| 709 | if (!opcode) { |
| 710 | return; |
| 711 | } |
| 712 | |
| 713 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 714 | if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 715 | /* NOT_DONE: This does not work yet */ |
| 716 | } |
| 717 | #endif |
| 718 | |
| 719 | /* |
| 720 | ** If the source is the current context, send its tag so that the context |
| 721 | ** can be flushed before the copy. |
| 722 | */ |
| 723 | if (source == gc && dpy == gc->currentDpy) { |
| 724 | tag = gc->currentContextTag; |
| 725 | } else { |
| 726 | tag = 0; |
| 727 | } |
| 728 | |
| 729 | /* Send the glXCopyContext request */ |
| 730 | LockDisplay(dpy); |
| 731 | GetReq(GLXCopyContext,req); |
| 732 | req->reqType = opcode; |
| 733 | req->glxCode = X_GLXCopyContext; |
| 734 | req->source = source ? source->xid : None; |
| 735 | req->dest = dest ? dest->xid : None; |
| 736 | req->mask = mask; |
| 737 | req->contextTag = tag; |
| 738 | UnlockDisplay(dpy); |
| 739 | SyncHandle(); |
| 740 | } |
| 741 | |
| 742 | |
| 743 | /** |
| 744 | * Determine if a context uses direct rendering. |
| 745 | * |
| 746 | * \param dpy Display where the context was created. |
| 747 | * \param contextID ID of the context to be tested. |
| 748 | * |
| 749 | * \returns \c GL_TRUE if the context is direct rendering or not. |
| 750 | */ |
| 751 | static Bool __glXIsDirect(Display *dpy, GLXContextID contextID) |
| 752 | { |
| 753 | xGLXIsDirectReq *req; |
| 754 | xGLXIsDirectReply reply; |
| 755 | CARD8 opcode; |
| 756 | |
| 757 | opcode = __glXSetupForCommand(dpy); |
| 758 | if (!opcode) { |
| 759 | return GL_FALSE; |
| 760 | } |
| 761 | |
| 762 | /* Send the glXIsDirect request */ |
| 763 | LockDisplay(dpy); |
| 764 | GetReq(GLXIsDirect,req); |
| 765 | req->reqType = opcode; |
| 766 | req->glxCode = X_GLXIsDirect; |
| 767 | req->context = contextID; |
| 768 | _XReply(dpy, (xReply*) &reply, 0, False); |
| 769 | UnlockDisplay(dpy); |
| 770 | SyncHandle(); |
| 771 | |
| 772 | return reply.isDirect; |
| 773 | } |
| 774 | |
Ian Romanick | c39bf5e | 2005-07-24 06:29:14 +0000 | [diff] [blame] | 775 | /** |
| 776 | * \todo |
| 777 | * Shouldn't this function \b always return \c GL_FALSE when |
| 778 | * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with |
| 779 | * the GLX protocol here at all? |
| 780 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 781 | PUBLIC Bool glXIsDirect(Display *dpy, GLXContext gc) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 782 | { |
| 783 | if (!gc) { |
| 784 | return GL_FALSE; |
| 785 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 786 | } else if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 787 | return GL_TRUE; |
| 788 | #endif |
| 789 | } |
| 790 | return __glXIsDirect(dpy, gc->xid); |
| 791 | } |
| 792 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 793 | PUBLIC GLXPixmap glXCreateGLXPixmap(Display *dpy, XVisualInfo *vis, |
| 794 | Pixmap pixmap) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 795 | { |
| 796 | xGLXCreateGLXPixmapReq *req; |
| 797 | GLXPixmap xid; |
| 798 | CARD8 opcode; |
| 799 | |
| 800 | opcode = __glXSetupForCommand(dpy); |
| 801 | if (!opcode) { |
| 802 | return None; |
| 803 | } |
| 804 | |
| 805 | /* Send the glXCreateGLXPixmap request */ |
| 806 | LockDisplay(dpy); |
| 807 | GetReq(GLXCreateGLXPixmap,req); |
| 808 | req->reqType = opcode; |
| 809 | req->glxCode = X_GLXCreateGLXPixmap; |
| 810 | req->screen = vis->screen; |
| 811 | req->visual = vis->visualid; |
| 812 | req->pixmap = pixmap; |
| 813 | req->glxpixmap = xid = XAllocID(dpy); |
| 814 | UnlockDisplay(dpy); |
| 815 | SyncHandle(); |
| 816 | return xid; |
| 817 | } |
| 818 | |
| 819 | /* |
| 820 | ** Destroy the named pixmap |
| 821 | */ |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 822 | PUBLIC void glXDestroyGLXPixmap(Display *dpy, GLXPixmap glxpixmap) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 823 | { |
| 824 | xGLXDestroyGLXPixmapReq *req; |
| 825 | CARD8 opcode; |
| 826 | |
| 827 | opcode = __glXSetupForCommand(dpy); |
| 828 | if (!opcode) { |
| 829 | return; |
| 830 | } |
| 831 | |
| 832 | /* Send the glXDestroyGLXPixmap request */ |
| 833 | LockDisplay(dpy); |
| 834 | GetReq(GLXDestroyGLXPixmap,req); |
| 835 | req->reqType = opcode; |
| 836 | req->glxCode = X_GLXDestroyGLXPixmap; |
| 837 | req->glxpixmap = glxpixmap; |
| 838 | UnlockDisplay(dpy); |
| 839 | SyncHandle(); |
| 840 | } |
| 841 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 842 | PUBLIC void glXSwapBuffers(Display *dpy, GLXDrawable drawable) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 843 | { |
| 844 | xGLXSwapBuffersReq *req; |
| 845 | GLXContext gc; |
| 846 | GLXContextTag tag; |
| 847 | CARD8 opcode; |
| 848 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 849 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 850 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 851 | if (pdraw != NULL) { |
Kristian Høgsberg | f56b569 | 2008-08-13 11:46:25 -0400 | [diff] [blame] | 852 | glFlush(); |
| 853 | (*pdraw->psc->driScreen->swapBuffers)(pdraw); |
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; |
Kristian Høgsberg | 6c533ea | 2007-10-16 16:07:47 -0400 | [diff] [blame] | 897 | __GLcontextModes *modes; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 898 | int status; |
| 899 | |
| 900 | status = GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ); |
| 901 | if ( status == Success ) { |
Kristian Høgsberg | 6c533ea | 2007-10-16 16:07:47 -0400 | [diff] [blame] | 902 | modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 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 | */ |
Kristian Høgsberg | 6c533ea | 2007-10-16 16:07:47 -0400 | [diff] [blame] | 1280 | for ( modes = psc->visuals ; modes != NULL ; modes = modes->next ) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 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 |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1325 | (psc->driScreen != 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: |
Kristian Høgsberg | 001de0a | 2007-11-06 13:32:04 -0500 | [diff] [blame] | 1504 | ctx->mode = |
| 1505 | _gl_context_modes_find_visual(ctx->psc->visuals, *pProp++); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1506 | break; |
| 1507 | case GLX_SCREEN: |
| 1508 | ctx->screen = *pProp++; |
| 1509 | break; |
| 1510 | case GLX_FBCONFIG_ID: |
Kristian Høgsberg | 001de0a | 2007-11-06 13:32:04 -0500 | [diff] [blame] | 1511 | ctx->mode = |
| 1512 | _gl_context_modes_find_fbconfig(ctx->psc->configs, *pProp++); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1513 | break; |
| 1514 | case GLX_RENDER_TYPE: |
| 1515 | ctx->renderType = *pProp++; |
| 1516 | break; |
| 1517 | default: |
| 1518 | pProp++; |
| 1519 | continue; |
| 1520 | } |
| 1521 | } |
| 1522 | Xfree((char *)propList); |
| 1523 | retval = Success; |
| 1524 | } |
| 1525 | } |
| 1526 | UnlockDisplay(dpy); |
| 1527 | SyncHandle(); |
| 1528 | return retval; |
| 1529 | } |
| 1530 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1531 | PUBLIC int |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1532 | glXQueryContext(Display *dpy, GLXContext ctx, int attribute, int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1533 | { |
| 1534 | int retVal; |
| 1535 | |
| 1536 | /* get the information from the server if we don't have it already */ |
Jeremy Huddleston | 919ec22 | 2008-08-08 02:52:10 -0700 | [diff] [blame] | 1537 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1538 | if (!ctx->driContext && (ctx->mode == NULL)) { |
Jeremy Huddleston | 919ec22 | 2008-08-08 02:52:10 -0700 | [diff] [blame] | 1539 | #else |
| 1540 | if (ctx->mode == NULL) { |
| 1541 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1542 | retVal = __glXQueryContextInfo(dpy, ctx); |
| 1543 | if (Success != retVal) return retVal; |
| 1544 | } |
| 1545 | switch (attribute) { |
| 1546 | case GLX_SHARE_CONTEXT_EXT: |
| 1547 | *value = (int)(ctx->share_xid); |
| 1548 | break; |
| 1549 | case GLX_VISUAL_ID_EXT: |
Kristian Høgsberg | 001de0a | 2007-11-06 13:32:04 -0500 | [diff] [blame] | 1550 | *value = ctx->mode ? ctx->mode->visualID : None; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1551 | break; |
| 1552 | case GLX_SCREEN: |
| 1553 | *value = (int)(ctx->screen); |
| 1554 | break; |
| 1555 | case GLX_FBCONFIG_ID: |
Kristian Høgsberg | 001de0a | 2007-11-06 13:32:04 -0500 | [diff] [blame] | 1556 | *value = ctx->mode ? ctx->mode->fbconfigID : None; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1557 | break; |
| 1558 | case GLX_RENDER_TYPE: |
| 1559 | *value = (int)(ctx->renderType); |
| 1560 | break; |
| 1561 | default: |
| 1562 | return GLX_BAD_ATTRIBUTE; |
| 1563 | } |
| 1564 | return Success; |
| 1565 | } |
| 1566 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1567 | PUBLIC GLX_ALIAS( int, glXQueryContextInfoEXT, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1568 | (Display *dpy, GLXContext ctx, int attribute, int *value), |
| 1569 | (dpy, ctx, attribute, value), |
| 1570 | glXQueryContext ) |
| 1571 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 1572 | PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1573 | { |
| 1574 | return ctx->xid; |
| 1575 | } |
| 1576 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1577 | PUBLIC GLXContext glXImportContextEXT(Display *dpy, GLXContextID contextID) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1578 | { |
| 1579 | GLXContext ctx; |
| 1580 | |
| 1581 | if (contextID == None) { |
| 1582 | return NULL; |
| 1583 | } |
| 1584 | if (__glXIsDirect(dpy, contextID)) { |
| 1585 | return NULL; |
| 1586 | } |
| 1587 | |
| 1588 | ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0); |
| 1589 | if (NULL != ctx) { |
| 1590 | if (Success != __glXQueryContextInfo(dpy, ctx)) { |
| 1591 | return NULL; |
| 1592 | } |
| 1593 | } |
| 1594 | return ctx; |
| 1595 | } |
| 1596 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1597 | PUBLIC void glXFreeContextEXT(Display *dpy, GLXContext ctx) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1598 | { |
| 1599 | DestroyContext(dpy, ctx); |
| 1600 | } |
| 1601 | |
| 1602 | |
| 1603 | |
| 1604 | /* |
| 1605 | * GLX 1.3 functions - these are just stubs for now! |
| 1606 | */ |
| 1607 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1608 | PUBLIC GLXFBConfig *glXChooseFBConfig(Display *dpy, int screen, |
| 1609 | const int *attribList, int *nitems) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1610 | { |
| 1611 | __GLcontextModes ** config_list; |
| 1612 | int list_size; |
| 1613 | |
| 1614 | |
| 1615 | config_list = (__GLcontextModes **) |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1616 | glXGetFBConfigs( dpy, screen, & list_size ); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1617 | |
Ian Romanick | c51ed8c | 2005-04-07 00:05:55 +0000 | [diff] [blame] | 1618 | if ( (config_list != NULL) && (list_size > 0) && (attribList != NULL) ) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1619 | list_size = choose_visual( config_list, list_size, attribList, |
| 1620 | GL_TRUE ); |
| 1621 | if ( list_size == 0 ) { |
| 1622 | XFree( config_list ); |
| 1623 | config_list = NULL; |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | *nitems = list_size; |
| 1628 | return (GLXFBConfig *) config_list; |
| 1629 | } |
| 1630 | |
| 1631 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1632 | PUBLIC GLXContext glXCreateNewContext(Display *dpy, GLXFBConfig config, |
| 1633 | int renderType, GLXContext shareList, |
| 1634 | Bool allowDirect) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1635 | { |
| 1636 | return CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList, |
| 1637 | allowDirect, None, True, renderType ); |
| 1638 | } |
| 1639 | |
| 1640 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1641 | PUBLIC GLXDrawable glXGetCurrentReadDrawable(void) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1642 | { |
| 1643 | GLXContext gc = __glXGetCurrentContext(); |
| 1644 | return gc->currentReadable; |
| 1645 | } |
| 1646 | |
| 1647 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1648 | PUBLIC GLXFBConfig *glXGetFBConfigs(Display *dpy, int screen, int *nelements) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1649 | { |
| 1650 | __GLXdisplayPrivate *priv = __glXInitialize(dpy); |
| 1651 | __GLcontextModes ** config = NULL; |
| 1652 | int i; |
| 1653 | |
Kristian Høgsberg | 6c533ea | 2007-10-16 16:07:47 -0400 | [diff] [blame] | 1654 | *nelements = 0; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1655 | if ( (priv->screenConfigs != NULL) |
| 1656 | && (screen >= 0) && (screen <= ScreenCount(dpy)) |
| 1657 | && (priv->screenConfigs[screen].configs != NULL) |
| 1658 | && (priv->screenConfigs[screen].configs->fbconfigID != GLX_DONT_CARE) ) { |
| 1659 | unsigned num_configs = 0; |
| 1660 | __GLcontextModes * modes; |
| 1661 | |
| 1662 | |
| 1663 | for ( modes = priv->screenConfigs[screen].configs |
| 1664 | ; modes != NULL |
| 1665 | ; modes = modes->next ) { |
| 1666 | if ( modes->fbconfigID != GLX_DONT_CARE ) { |
| 1667 | num_configs++; |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | config = (__GLcontextModes **) Xmalloc( sizeof(__GLcontextModes *) |
| 1672 | * num_configs ); |
| 1673 | if ( config != NULL ) { |
| 1674 | *nelements = num_configs; |
| 1675 | i = 0; |
| 1676 | for ( modes = priv->screenConfigs[screen].configs |
| 1677 | ; modes != NULL |
| 1678 | ; modes = modes->next ) { |
Kristian Høgsberg | a87e9a3 | 2007-08-30 13:05:59 -0400 | [diff] [blame] | 1679 | if ( modes->fbconfigID != GLX_DONT_CARE ) { |
| 1680 | config[i] = modes; |
| 1681 | i++; |
| 1682 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | } |
| 1686 | return (GLXFBConfig *) config; |
| 1687 | } |
| 1688 | |
| 1689 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1690 | PUBLIC int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, |
| 1691 | int attribute, int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1692 | { |
| 1693 | __GLcontextModes * const modes = ValidateGLXFBConfig( dpy, config ); |
| 1694 | |
| 1695 | return (modes != NULL) |
| 1696 | ? _gl_get_context_mode_data( modes, attribute, value ) |
| 1697 | : GLXBadFBConfig; |
| 1698 | } |
| 1699 | |
| 1700 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 1701 | PUBLIC XVisualInfo *glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1702 | { |
| 1703 | XVisualInfo visualTemplate; |
| 1704 | __GLcontextModes * fbconfig = (__GLcontextModes *) config; |
| 1705 | int count; |
| 1706 | |
| 1707 | /* |
| 1708 | ** Get a list of all visuals, return if list is empty |
| 1709 | */ |
| 1710 | visualTemplate.visualid = fbconfig->visualID; |
| 1711 | return XGetVisualInfo(dpy,VisualIDMask,&visualTemplate,&count); |
| 1712 | } |
| 1713 | |
| 1714 | |
| 1715 | /* |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1716 | ** GLX_SGI_swap_control |
| 1717 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1718 | static int __glXSwapIntervalSGI(int interval) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1719 | { |
| 1720 | xGLXVendorPrivateReq *req; |
| 1721 | GLXContext gc = __glXGetCurrentContext(); |
| 1722 | Display * dpy; |
| 1723 | CARD32 * interval_ptr; |
| 1724 | CARD8 opcode; |
| 1725 | |
| 1726 | if ( gc == NULL ) { |
| 1727 | return GLX_BAD_CONTEXT; |
| 1728 | } |
| 1729 | |
| 1730 | if ( interval <= 0 ) { |
| 1731 | return GLX_BAD_VALUE; |
| 1732 | } |
| 1733 | |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1734 | #ifdef __DRI_SWAP_CONTROL |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1735 | if (gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1736 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, |
| 1737 | gc->screen ); |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1738 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(gc->currentDpy, |
| 1739 | gc->currentDrawable, |
| 1740 | NULL); |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1741 | if (psc->swapControl != NULL && pdraw != NULL) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1742 | psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1743 | return 0; |
| 1744 | } |
| 1745 | else { |
| 1746 | return GLX_BAD_CONTEXT; |
| 1747 | } |
| 1748 | } |
| 1749 | #endif |
| 1750 | dpy = gc->currentDpy; |
| 1751 | opcode = __glXSetupForCommand(dpy); |
| 1752 | if (!opcode) { |
| 1753 | return 0; |
| 1754 | } |
| 1755 | |
| 1756 | /* Send the glXSwapIntervalSGI request */ |
| 1757 | LockDisplay(dpy); |
| 1758 | GetReqExtra(GLXVendorPrivate,sizeof(CARD32),req); |
| 1759 | req->reqType = opcode; |
| 1760 | req->glxCode = X_GLXVendorPrivate; |
| 1761 | req->vendorCode = X_GLXvop_SwapIntervalSGI; |
| 1762 | req->contextTag = gc->currentContextTag; |
| 1763 | |
Ian Romanick | a70d564 | 2006-08-30 23:15:02 +0000 | [diff] [blame] | 1764 | interval_ptr = (CARD32 *) (req + 1); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1765 | *interval_ptr = interval; |
| 1766 | |
| 1767 | UnlockDisplay(dpy); |
| 1768 | SyncHandle(); |
| 1769 | XFlush(dpy); |
| 1770 | |
| 1771 | return 0; |
| 1772 | } |
| 1773 | |
| 1774 | |
| 1775 | /* |
| 1776 | ** GLX_MESA_swap_control |
| 1777 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1778 | static int __glXSwapIntervalMESA(unsigned int interval) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1779 | { |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1780 | #ifdef __DRI_SWAP_CONTROL |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1781 | GLXContext gc = __glXGetCurrentContext(); |
| 1782 | |
| 1783 | if ( interval < 0 ) { |
| 1784 | return GLX_BAD_VALUE; |
| 1785 | } |
| 1786 | |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1787 | if (gc != NULL && gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1788 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, |
| 1789 | gc->screen ); |
| 1790 | |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1791 | if ( (psc != NULL) && (psc->driScreen != NULL) ) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1792 | __GLXDRIdrawable *pdraw = |
| 1793 | GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1794 | if (psc->swapControl != NULL && pdraw != NULL) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1795 | psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1796 | return 0; |
| 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | #else |
| 1801 | (void) interval; |
| 1802 | #endif |
| 1803 | |
| 1804 | return GLX_BAD_CONTEXT; |
| 1805 | } |
| 1806 | |
Brian Paul | 841a823 | 2006-03-09 16:25:46 +0000 | [diff] [blame] | 1807 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1808 | static int __glXGetSwapIntervalMESA(void) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1809 | { |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1810 | #ifdef __DRI_SWAP_CONTROL |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1811 | GLXContext gc = __glXGetCurrentContext(); |
| 1812 | |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1813 | if (gc != NULL && gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1814 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, |
| 1815 | gc->screen ); |
| 1816 | |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1817 | if ( (psc != NULL) && (psc->driScreen != NULL) ) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1818 | __GLXDRIdrawable *pdraw = |
| 1819 | GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); |
Kristian Høgsberg | efaf90b | 2007-05-15 16:09:44 -0400 | [diff] [blame] | 1820 | if (psc->swapControl != NULL && pdraw != NULL) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1821 | return psc->swapControl->getSwapInterval(pdraw->driDrawable); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1822 | } |
| 1823 | } |
| 1824 | } |
| 1825 | #endif |
| 1826 | |
| 1827 | return 0; |
| 1828 | } |
| 1829 | |
| 1830 | |
| 1831 | /* |
| 1832 | ** GLX_MESA_swap_frame_usage |
| 1833 | */ |
| 1834 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1835 | static GLint __glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1836 | { |
| 1837 | int status = GLX_BAD_CONTEXT; |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1838 | #ifdef __DRI_FRAME_TRACKING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1839 | int screen; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1840 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1841 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); |
| 1842 | |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1843 | if (pdraw != NULL && psc->frameTracking != NULL) |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1844 | status = psc->frameTracking->frameTracking(pdraw->driDrawable, GL_TRUE); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1845 | #else |
| 1846 | (void) dpy; |
| 1847 | (void) drawable; |
| 1848 | #endif |
| 1849 | return status; |
| 1850 | } |
| 1851 | |
| 1852 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1853 | static GLint __glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1854 | { |
| 1855 | int status = GLX_BAD_CONTEXT; |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1856 | #ifdef __DRI_FRAME_TRACKING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1857 | int screen; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1858 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen); |
| 1859 | __GLXscreenConfigs *psc = GetGLXScreenConfigs(dpy, screen); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1860 | |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1861 | if (pdraw != NULL && psc->frameTracking != NULL) |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1862 | status = psc->frameTracking->frameTracking(pdraw->driDrawable, |
| 1863 | GL_FALSE); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1864 | #else |
| 1865 | (void) dpy; |
| 1866 | (void) drawable; |
| 1867 | #endif |
| 1868 | return status; |
| 1869 | } |
| 1870 | |
| 1871 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1872 | static GLint __glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable, |
| 1873 | GLfloat *usage) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1874 | { |
| 1875 | int status = GLX_BAD_CONTEXT; |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1876 | #ifdef __DRI_FRAME_TRACKING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1877 | int screen; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1878 | __GLXDRIdrawable * const pdraw = GetGLXDRIDrawable(dpy, drawable, & screen); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1879 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); |
| 1880 | |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1881 | if (pdraw != NULL && psc->frameTracking != NULL) { |
| 1882 | int64_t sbc, missedFrames; |
| 1883 | float lastMissedUsage; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1884 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1885 | status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable, |
| 1886 | &sbc, |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1887 | &missedFrames, |
| 1888 | &lastMissedUsage, |
| 1889 | usage); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1890 | } |
| 1891 | #else |
| 1892 | (void) dpy; |
| 1893 | (void) drawable; |
| 1894 | (void) usage; |
| 1895 | #endif |
| 1896 | return status; |
| 1897 | } |
| 1898 | |
| 1899 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1900 | static GLint __glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable, |
| 1901 | int64_t *sbc, int64_t *missedFrames, |
| 1902 | GLfloat *lastMissedUsage) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1903 | { |
| 1904 | int status = GLX_BAD_CONTEXT; |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1905 | #ifdef __DRI_FRAME_TRACKING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1906 | int screen; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1907 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1908 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); |
| 1909 | |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1910 | if (pdraw != NULL && psc->frameTracking != NULL) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1911 | float usage; |
| 1912 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1913 | status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable, |
| 1914 | sbc, missedFrames, |
Kristian Høgsberg | a7a0a2b | 2007-05-16 15:50:40 -0400 | [diff] [blame] | 1915 | lastMissedUsage, &usage); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1916 | } |
| 1917 | #else |
| 1918 | (void) dpy; |
| 1919 | (void) drawable; |
| 1920 | (void) sbc; |
| 1921 | (void) missedFrames; |
| 1922 | (void) lastMissedUsage; |
| 1923 | #endif |
| 1924 | return status; |
| 1925 | } |
| 1926 | |
| 1927 | |
| 1928 | /* |
| 1929 | ** GLX_SGI_video_sync |
| 1930 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1931 | static int __glXGetVideoSyncSGI(unsigned int *count) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1932 | { |
| 1933 | /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry, |
| 1934 | * FIXME: there should be a GLX encoding for this call. I can find no |
| 1935 | * FIXME: documentation for the GLX encoding. |
| 1936 | */ |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 1937 | #ifdef __DRI_MEDIA_STREAM_COUNTER |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1938 | GLXContext gc = __glXGetCurrentContext(); |
| 1939 | |
| 1940 | |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1941 | if (gc != NULL && gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1942 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, |
| 1943 | gc->screen ); |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1944 | if ( psc->msc && psc->driScreen ) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1945 | __GLXDRIdrawable *pdraw = |
| 1946 | GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); |
Jesse Barnes | 38fdb47 | 2007-10-29 11:56:31 -0700 | [diff] [blame] | 1947 | int64_t temp; |
| 1948 | int ret; |
| 1949 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1950 | ret = (*psc->msc->getDrawableMSC)(psc->__driScreen, |
| 1951 | pdraw->driDrawable, &temp); |
Jesse Barnes | 38fdb47 | 2007-10-29 11:56:31 -0700 | [diff] [blame] | 1952 | *count = (unsigned) temp; |
Kristian Høgsberg | 6e8d21d | 2008-02-25 16:14:37 -0500 | [diff] [blame] | 1953 | |
Jesse Barnes | 38fdb47 | 2007-10-29 11:56:31 -0700 | [diff] [blame] | 1954 | return (ret == 0) ? 0 : GLX_BAD_CONTEXT; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1955 | } |
| 1956 | } |
| 1957 | #else |
| 1958 | (void) count; |
| 1959 | #endif |
| 1960 | return GLX_BAD_CONTEXT; |
| 1961 | } |
| 1962 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 1963 | static int __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1964 | { |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 1965 | #ifdef __DRI_MEDIA_STREAM_COUNTER |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1966 | GLXContext gc = __glXGetCurrentContext(); |
| 1967 | |
| 1968 | if ( divisor <= 0 || remainder < 0 ) |
| 1969 | return GLX_BAD_VALUE; |
| 1970 | |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 1971 | if (gc != NULL && gc->driContext) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1972 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, |
| 1973 | gc->screen ); |
Kristian Høgsberg | 92d2a78 | 2008-03-08 20:34:24 -0500 | [diff] [blame] | 1974 | if (psc->msc != NULL && psc->driScreen ) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1975 | __GLXDRIdrawable *pdraw = |
| 1976 | GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); |
Jesse Barnes | 38fdb47 | 2007-10-29 11:56:31 -0700 | [diff] [blame] | 1977 | int ret; |
| 1978 | int64_t msc; |
| 1979 | int64_t sbc; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1980 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 1981 | ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, 0, |
| 1982 | divisor, remainder, &msc, &sbc); |
Jesse Barnes | 38fdb47 | 2007-10-29 11:56:31 -0700 | [diff] [blame] | 1983 | *count = (unsigned) msc; |
| 1984 | return (ret == 0) ? 0 : GLX_BAD_CONTEXT; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1985 | } |
| 1986 | } |
| 1987 | #else |
| 1988 | (void) count; |
| 1989 | #endif |
| 1990 | return GLX_BAD_CONTEXT; |
| 1991 | } |
| 1992 | |
| 1993 | |
| 1994 | /* |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1995 | ** GLX_SGIX_fbconfig |
| 1996 | ** Many of these functions are aliased to GLX 1.3 entry points in the |
| 1997 | ** GLX_functions table. |
| 1998 | */ |
| 1999 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 2000 | PUBLIC GLX_ALIAS(int, glXGetFBConfigAttribSGIX, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2001 | (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value), |
| 2002 | (dpy, config, attribute, value), |
| 2003 | glXGetFBConfigAttrib) |
| 2004 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 2005 | PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2006 | (Display *dpy, int screen, int *attrib_list, int *nelements), |
| 2007 | (dpy, screen, attrib_list, nelements), |
| 2008 | glXChooseFBConfig) |
| 2009 | |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 2010 | PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX, |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2011 | (Display * dpy, GLXFBConfigSGIX config), |
| 2012 | (dpy, config), |
| 2013 | glXGetVisualFromFBConfig) |
| 2014 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2015 | PUBLIC GLXPixmap glXCreateGLXPixmapWithConfigSGIX(Display *dpy, |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 2016 | GLXFBConfigSGIX config, Pixmap pixmap) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2017 | { |
| 2018 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 2019 | xGLXCreateGLXPixmapWithConfigSGIXReq *req; |
| 2020 | GLXPixmap xid = None; |
| 2021 | CARD8 opcode; |
| 2022 | const __GLcontextModes * const fbconfig = (__GLcontextModes *) config; |
| 2023 | __GLXscreenConfigs * psc; |
| 2024 | |
| 2025 | |
| 2026 | if ( (dpy == NULL) || (config == NULL) ) { |
| 2027 | return None; |
| 2028 | } |
| 2029 | |
| 2030 | psc = GetGLXScreenConfigs( dpy, fbconfig->screen ); |
| 2031 | if ( (psc != NULL) |
| 2032 | && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) { |
| 2033 | opcode = __glXSetupForCommand(dpy); |
| 2034 | if (!opcode) { |
| 2035 | return None; |
| 2036 | } |
| 2037 | |
| 2038 | /* Send the glXCreateGLXPixmapWithConfigSGIX request */ |
| 2039 | LockDisplay(dpy); |
| 2040 | GetReqExtra(GLXVendorPrivateWithReply, |
| 2041 | sz_xGLXCreateGLXPixmapWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq); |
| 2042 | req = (xGLXCreateGLXPixmapWithConfigSGIXReq *)vpreq; |
| 2043 | req->reqType = opcode; |
| 2044 | req->glxCode = X_GLXVendorPrivateWithReply; |
| 2045 | req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX; |
| 2046 | req->screen = fbconfig->screen; |
| 2047 | req->fbconfig = fbconfig->fbconfigID; |
| 2048 | req->pixmap = pixmap; |
| 2049 | req->glxpixmap = xid = XAllocID(dpy); |
| 2050 | UnlockDisplay(dpy); |
| 2051 | SyncHandle(); |
| 2052 | } |
| 2053 | |
| 2054 | return xid; |
| 2055 | } |
| 2056 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2057 | PUBLIC GLXContext glXCreateContextWithConfigSGIX(Display *dpy, |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 2058 | GLXFBConfigSGIX config, int renderType, |
| 2059 | GLXContext shareList, Bool allowDirect) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2060 | { |
| 2061 | GLXContext gc = NULL; |
| 2062 | const __GLcontextModes * const fbconfig = (__GLcontextModes *) config; |
| 2063 | __GLXscreenConfigs * psc; |
| 2064 | |
| 2065 | |
| 2066 | if ( (dpy == NULL) || (config == NULL) ) { |
| 2067 | return None; |
| 2068 | } |
| 2069 | |
| 2070 | psc = GetGLXScreenConfigs( dpy, fbconfig->screen ); |
| 2071 | if ( (psc != NULL) |
| 2072 | && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) { |
| 2073 | gc = CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList, |
| 2074 | allowDirect, None, False, renderType ); |
| 2075 | } |
| 2076 | |
| 2077 | return gc; |
| 2078 | } |
| 2079 | |
| 2080 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2081 | PUBLIC GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX(Display *dpy, |
| 2082 | XVisualInfo *vis) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2083 | { |
| 2084 | __GLXdisplayPrivate *priv; |
| 2085 | __GLXscreenConfigs *psc; |
| 2086 | |
| 2087 | if ( (GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ) != Success) |
| 2088 | && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) |
| 2089 | && (psc->configs->fbconfigID != GLX_DONT_CARE) ) { |
| 2090 | return (GLXFBConfigSGIX) _gl_context_modes_find_visual( psc->configs, |
| 2091 | vis->visualid ); |
| 2092 | } |
| 2093 | |
| 2094 | return NULL; |
| 2095 | } |
| 2096 | |
| 2097 | |
| 2098 | /* |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2099 | ** GLX_SGIX_swap_group |
| 2100 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2101 | static void __glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, |
| 2102 | GLXDrawable member) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2103 | { |
| 2104 | (void) dpy; |
| 2105 | (void) drawable; |
| 2106 | (void) member; |
| 2107 | } |
| 2108 | |
| 2109 | |
| 2110 | /* |
| 2111 | ** GLX_SGIX_swap_barrier |
| 2112 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2113 | static void __glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, |
| 2114 | int barrier) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2115 | { |
| 2116 | (void) dpy; |
| 2117 | (void) drawable; |
| 2118 | (void) barrier; |
| 2119 | } |
| 2120 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2121 | static Bool __glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2122 | { |
| 2123 | (void) dpy; |
| 2124 | (void) screen; |
| 2125 | (void) max; |
| 2126 | return False; |
| 2127 | } |
| 2128 | |
| 2129 | |
| 2130 | /* |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2131 | ** GLX_OML_sync_control |
| 2132 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2133 | static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable, |
| 2134 | int64_t *ust, int64_t *msc, int64_t *sbc) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2135 | { |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2136 | #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2137 | __GLXdisplayPrivate * const priv = __glXInitialize(dpy); |
| 2138 | |
| 2139 | if ( priv != NULL ) { |
| 2140 | int i; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2141 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &i); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2142 | __GLXscreenConfigs * const psc = &priv->screenConfigs[i]; |
| 2143 | |
| 2144 | assert( (pdraw == NULL) || (i != -1) ); |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2145 | return ( (pdraw && psc->sbc && psc->msc) |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2146 | && ((*psc->msc->getMSC)(psc->driScreen, msc) == 0) |
| 2147 | && ((*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0) |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2148 | && (__glXGetUST(ust) == 0) ); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2149 | } |
| 2150 | #else |
| 2151 | (void) dpy; |
| 2152 | (void) drawable; |
| 2153 | (void) ust; |
| 2154 | (void) msc; |
| 2155 | (void) sbc; |
| 2156 | #endif |
| 2157 | return False; |
| 2158 | } |
| 2159 | |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2160 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 3d28a26 | 2008-03-08 22:28:01 -0500 | [diff] [blame] | 2161 | _X_HIDDEN GLboolean |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2162 | __driGetMscRateOML(__DRIdrawable *draw, |
| 2163 | int32_t *numerator, int32_t *denominator, void *private) |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2164 | { |
| 2165 | #ifdef XF86VIDMODE |
| 2166 | __GLXscreenConfigs *psc; |
| 2167 | XF86VidModeModeLine mode_line; |
| 2168 | int dot_clock; |
| 2169 | int i; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2170 | __GLXDRIdrawable *glxDraw = private; |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2171 | |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2172 | psc = glxDraw->psc; |
| 2173 | if (XF86VidModeQueryVersion(psc->dpy, &i, &i) && |
| 2174 | XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line) ) { |
| 2175 | unsigned n = dot_clock * 1000; |
| 2176 | unsigned d = mode_line.vtotal * mode_line.htotal; |
| 2177 | |
| 2178 | # define V_INTERLACE 0x010 |
| 2179 | # define V_DBLSCAN 0x020 |
| 2180 | |
| 2181 | if (mode_line.flags & V_INTERLACE) |
| 2182 | n *= 2; |
| 2183 | else if (mode_line.flags & V_DBLSCAN) |
| 2184 | d *= 2; |
| 2185 | |
| 2186 | /* The OML_sync_control spec requires that if the refresh rate is a |
| 2187 | * whole number, that the returned numerator be equal to the refresh |
| 2188 | * rate and the denominator be 1. |
| 2189 | */ |
| 2190 | |
| 2191 | if (n % d == 0) { |
| 2192 | n /= d; |
| 2193 | d = 1; |
| 2194 | } |
| 2195 | else { |
| 2196 | static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 }; |
| 2197 | |
| 2198 | /* This is a poor man's way to reduce a fraction. It's far from |
| 2199 | * perfect, but it will work well enough for this situation. |
| 2200 | */ |
| 2201 | |
| 2202 | for (i = 0; f[i] != 0; i++) { |
| 2203 | while (n % f[i] == 0 && d % f[i] == 0) { |
| 2204 | d /= f[i]; |
| 2205 | n /= f[i]; |
| 2206 | } |
| 2207 | } |
| 2208 | } |
| 2209 | |
| 2210 | *numerator = n; |
| 2211 | *denominator = d; |
| 2212 | |
| 2213 | return True; |
| 2214 | } |
| 2215 | else |
| 2216 | return False; |
| 2217 | #else |
| 2218 | return False; |
| 2219 | #endif |
| 2220 | } |
| 2221 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2222 | |
| 2223 | /** |
| 2224 | * Determine the refresh rate of the specified drawable and display. |
| 2225 | * |
| 2226 | * \param dpy Display whose refresh rate is to be determined. |
| 2227 | * \param drawable Drawable whose refresh rate is to be determined. |
| 2228 | * \param numerator Numerator of the refresh rate. |
| 2229 | * \param demoninator Denominator of the refresh rate. |
| 2230 | * \return If the refresh rate for the specified display and drawable could |
| 2231 | * be calculated, True is returned. Otherwise False is returned. |
| 2232 | * |
| 2233 | * \note This function is implemented entirely client-side. A lot of other |
| 2234 | * functionality is required to export GLX_OML_sync_control, so on |
| 2235 | * XFree86 this function can be called for direct-rendering contexts |
| 2236 | * when GLX_OML_sync_control appears in the client extension string. |
| 2237 | */ |
| 2238 | |
Kristian Høgsberg | 3d28a26 | 2008-03-08 22:28:01 -0500 | [diff] [blame] | 2239 | _X_HIDDEN GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, |
| 2240 | int32_t * numerator, |
| 2241 | int32_t * denominator) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2242 | { |
| 2243 | #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE ) |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2244 | __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable, NULL); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2245 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2246 | if (draw == NULL) |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2247 | return False; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2248 | |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2249 | return __driGetMscRateOML(draw->driDrawable, numerator, denominator, draw); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2250 | #else |
Kristian Høgsberg | 286ce27 | 2007-11-06 14:34:15 -0500 | [diff] [blame] | 2251 | (void) dpy; |
| 2252 | (void) drawable; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2253 | (void) numerator; |
| 2254 | (void) denominator; |
| 2255 | #endif |
| 2256 | return False; |
| 2257 | } |
| 2258 | |
| 2259 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2260 | static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable, |
| 2261 | int64_t target_msc, int64_t divisor, |
| 2262 | int64_t remainder) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2263 | { |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2264 | #ifdef __DRI_SWAP_BUFFER_COUNTER |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2265 | int screen; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2266 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2267 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); |
| 2268 | |
| 2269 | /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE |
| 2270 | * error", but it also says "It [glXSwapBuffersMscOML] will return a value |
| 2271 | * of -1 if the function failed because of errors detected in the input |
| 2272 | * parameters" |
| 2273 | */ |
| 2274 | if ( divisor < 0 || remainder < 0 || target_msc < 0 ) |
| 2275 | return -1; |
| 2276 | if ( divisor > 0 && remainder >= divisor ) |
| 2277 | return -1; |
| 2278 | |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2279 | if (pdraw != NULL && psc->counters != NULL) |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2280 | return (*psc->sbc->swapBuffersMSC)(pdraw->driDrawable, target_msc, |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2281 | divisor, remainder); |
| 2282 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2283 | #else |
| 2284 | (void) dpy; |
| 2285 | (void) drawable; |
| 2286 | (void) target_msc; |
| 2287 | (void) divisor; |
| 2288 | (void) remainder; |
| 2289 | #endif |
| 2290 | return 0; |
| 2291 | } |
| 2292 | |
| 2293 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2294 | static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable, |
| 2295 | int64_t target_msc, int64_t divisor, |
| 2296 | int64_t remainder, int64_t *ust, |
| 2297 | int64_t *msc, int64_t *sbc) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2298 | { |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2299 | #ifdef __DRI_MEDIA_STREAM_COUNTER |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2300 | int screen; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2301 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2302 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); |
| 2303 | int ret; |
| 2304 | |
| 2305 | /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE |
| 2306 | * error", but the return type in the spec is Bool. |
| 2307 | */ |
| 2308 | if ( divisor < 0 || remainder < 0 || target_msc < 0 ) |
| 2309 | return False; |
| 2310 | if ( divisor > 0 && remainder >= divisor ) |
| 2311 | return False; |
| 2312 | |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2313 | if (pdraw != NULL && psc->msc != NULL) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2314 | ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, target_msc, |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2315 | divisor, remainder, msc, sbc); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2316 | |
| 2317 | /* __glXGetUST returns zero on success and non-zero on failure. |
| 2318 | * This function returns True on success and False on failure. |
| 2319 | */ |
| 2320 | return ( (ret == 0) && (__glXGetUST( ust ) == 0) ); |
| 2321 | } |
| 2322 | #else |
| 2323 | (void) dpy; |
| 2324 | (void) drawable; |
| 2325 | (void) target_msc; |
| 2326 | (void) divisor; |
| 2327 | (void) remainder; |
| 2328 | (void) ust; |
| 2329 | (void) msc; |
| 2330 | (void) sbc; |
| 2331 | #endif |
| 2332 | return False; |
| 2333 | } |
| 2334 | |
| 2335 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2336 | static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable, |
| 2337 | int64_t target_sbc, int64_t *ust, |
| 2338 | int64_t *msc, int64_t *sbc ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2339 | { |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2340 | #ifdef __DRI_SWAP_BUFFER_COUNTER |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2341 | int screen; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2342 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2343 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); |
| 2344 | int ret; |
| 2345 | |
| 2346 | /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE |
| 2347 | * error", but the return type in the spec is Bool. |
| 2348 | */ |
| 2349 | if ( target_sbc < 0 ) |
| 2350 | return False; |
| 2351 | |
Kristian Høgsberg | 106a6f2 | 2007-05-16 18:13:41 -0400 | [diff] [blame] | 2352 | if (pdraw != NULL && psc->sbc != NULL) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2353 | ret = (*psc->sbc->waitForSBC)(pdraw->driDrawable, target_sbc, msc, sbc); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2354 | |
| 2355 | /* __glXGetUST returns zero on success and non-zero on failure. |
| 2356 | * This function returns True on success and False on failure. |
| 2357 | */ |
| 2358 | return( (ret == 0) && (__glXGetUST( ust ) == 0) ); |
| 2359 | } |
| 2360 | #else |
| 2361 | (void) dpy; |
| 2362 | (void) drawable; |
| 2363 | (void) target_sbc; |
| 2364 | (void) ust; |
| 2365 | (void) msc; |
| 2366 | (void) sbc; |
| 2367 | #endif |
| 2368 | return False; |
| 2369 | } |
| 2370 | |
| 2371 | |
| 2372 | /** |
| 2373 | * GLX_MESA_allocate_memory |
| 2374 | */ |
| 2375 | /*@{*/ |
| 2376 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2377 | PUBLIC void *glXAllocateMemoryMESA(Display *dpy, int scrn, |
| 2378 | size_t size, float readFreq, |
| 2379 | float writeFreq, float priority) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2380 | { |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2381 | #ifdef __DRI_ALLOCATE |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2382 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); |
| 2383 | |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2384 | if (psc && psc->allocate) |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2385 | return (*psc->allocate->allocateMemory)(psc->__driScreen, size, |
| 2386 | readFreq, writeFreq, priority); |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2387 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2388 | #else |
| 2389 | (void) dpy; |
| 2390 | (void) scrn; |
| 2391 | (void) size; |
| 2392 | (void) readFreq; |
| 2393 | (void) writeFreq; |
| 2394 | (void) priority; |
| 2395 | #endif /* GLX_DIRECT_RENDERING */ |
| 2396 | |
| 2397 | return NULL; |
| 2398 | } |
| 2399 | |
| 2400 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2401 | PUBLIC void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2402 | { |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2403 | #ifdef __DRI_ALLOCATE |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2404 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); |
| 2405 | |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2406 | if (psc && psc->allocate) |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2407 | (*psc->allocate->freeMemory)(psc->__driScreen, pointer); |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2408 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2409 | #else |
| 2410 | (void) dpy; |
| 2411 | (void) scrn; |
| 2412 | (void) pointer; |
| 2413 | #endif /* GLX_DIRECT_RENDERING */ |
| 2414 | } |
| 2415 | |
| 2416 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2417 | PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn, |
| 2418 | const void *pointer ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2419 | { |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2420 | #ifdef __DRI_ALLOCATE |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2421 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); |
| 2422 | |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2423 | if (psc && psc->allocate) |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2424 | return (*psc->allocate->memoryOffset)(psc->__driScreen, pointer); |
Kristian Høgsberg | 78a6aa5 | 2007-05-16 14:10:29 -0400 | [diff] [blame] | 2425 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2426 | #else |
| 2427 | (void) dpy; |
| 2428 | (void) scrn; |
| 2429 | (void) pointer; |
| 2430 | #endif /* GLX_DIRECT_RENDERING */ |
| 2431 | |
| 2432 | return ~0L; |
| 2433 | } |
| 2434 | /*@}*/ |
| 2435 | |
| 2436 | |
| 2437 | /** |
| 2438 | * Mesa extension stubs. These will help reduce portability problems. |
| 2439 | */ |
| 2440 | /*@{*/ |
| 2441 | |
| 2442 | /** |
| 2443 | * Release all buffers associated with the specified GLX drawable. |
| 2444 | * |
| 2445 | * \todo |
| 2446 | * This function was intended for stand-alone Mesa. The issue there is that |
| 2447 | * the library doesn't get any notification when a window is closed. In |
| 2448 | * DRI there is a similar but slightly different issue. When GLX 1.3 is |
| 2449 | * supported, there are 3 different functions to destroy a drawable. It |
| 2450 | * should be possible to create GLX protocol (or have it determine which |
| 2451 | * protocol to use based on the type of the drawable) to have one function |
| 2452 | * do the work of 3. For the direct-rendering case, this function could |
| 2453 | * just call the driver's \c __DRIdrawableRec::destroyDrawable function. |
| 2454 | * This would reduce the frequency with which \c __driGarbageCollectDrawables |
| 2455 | * would need to be used. This really should be done as part of the new DRI |
| 2456 | * interface work. |
| 2457 | * |
| 2458 | * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt |
| 2459 | * __driGarbageCollectDrawables |
| 2460 | * glXDestroyGLXPixmap |
| 2461 | * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow |
| 2462 | * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX |
| 2463 | */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2464 | static Bool __glXReleaseBuffersMESA( Display *dpy, GLXDrawable d ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2465 | { |
| 2466 | (void) dpy; |
| 2467 | (void) d; |
| 2468 | return False; |
| 2469 | } |
| 2470 | |
| 2471 | |
Ian Romanick | ab7c6ff | 2005-07-26 22:53:38 +0000 | [diff] [blame] | 2472 | PUBLIC GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual, |
| 2473 | Pixmap pixmap, Colormap cmap ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2474 | { |
| 2475 | (void) dpy; |
| 2476 | (void) visual; |
| 2477 | (void) pixmap; |
| 2478 | (void) cmap; |
| 2479 | return 0; |
| 2480 | } |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2481 | /*@}*/ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2482 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2483 | |
| 2484 | /** |
| 2485 | * GLX_MESA_copy_sub_buffer |
| 2486 | */ |
Brian Paul | f2ad1b6 | 2006-03-31 15:48:04 +0000 | [diff] [blame] | 2487 | #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2488 | static void __glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable, |
| 2489 | int x, int y, int width, int height) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2490 | { |
Brian Paul | f2ad1b6 | 2006-03-31 15:48:04 +0000 | [diff] [blame] | 2491 | xGLXVendorPrivateReq *req; |
| 2492 | GLXContext gc; |
| 2493 | GLXContextTag tag; |
| 2494 | CARD32 *drawable_ptr; |
| 2495 | INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr; |
| 2496 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2497 | |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 2498 | #ifdef __DRI_COPY_SUB_BUFFER |
Brian Paul | f2ad1b6 | 2006-03-31 15:48:04 +0000 | [diff] [blame] | 2499 | int screen; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2500 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); |
Brian Paul | f2ad1b6 | 2006-03-31 15:48:04 +0000 | [diff] [blame] | 2501 | if ( pdraw != NULL ) { |
| 2502 | __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); |
Kristian Høgsberg | ac3e838 | 2007-05-15 15:17:30 -0400 | [diff] [blame] | 2503 | if (psc->copySubBuffer != NULL) { |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2504 | (*psc->copySubBuffer->copySubBuffer)(pdraw->driDrawable, |
| 2505 | x, y, width, height); |
Brian Paul | f2ad1b6 | 2006-03-31 15:48:04 +0000 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | return; |
| 2509 | } |
| 2510 | #endif |
| 2511 | |
| 2512 | opcode = __glXSetupForCommand(dpy); |
| 2513 | if (!opcode) |
| 2514 | return; |
| 2515 | |
| 2516 | /* |
| 2517 | ** The calling thread may or may not have a current context. If it |
| 2518 | ** does, send the context tag so the server can do a flush. |
| 2519 | */ |
| 2520 | gc = __glXGetCurrentContext(); |
| 2521 | if ((gc != NULL) && (dpy == gc->currentDpy) && |
| 2522 | ((drawable == gc->currentDrawable) || |
| 2523 | (drawable == gc->currentReadable)) ) { |
| 2524 | tag = gc->currentContextTag; |
| 2525 | } else { |
| 2526 | tag = 0; |
| 2527 | } |
| 2528 | |
| 2529 | LockDisplay(dpy); |
| 2530 | GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4,req); |
| 2531 | req->reqType = opcode; |
| 2532 | req->glxCode = X_GLXVendorPrivate; |
| 2533 | req->vendorCode = X_GLXvop_CopySubBufferMESA; |
| 2534 | req->contextTag = tag; |
| 2535 | |
| 2536 | drawable_ptr = (CARD32 *) (req + 1); |
| 2537 | x_ptr = (INT32 *) (drawable_ptr + 1); |
| 2538 | y_ptr = (INT32 *) (drawable_ptr + 2); |
| 2539 | w_ptr = (INT32 *) (drawable_ptr + 3); |
| 2540 | h_ptr = (INT32 *) (drawable_ptr + 4); |
| 2541 | |
| 2542 | *drawable_ptr = drawable; |
| 2543 | *x_ptr = x; |
| 2544 | *y_ptr = y; |
| 2545 | *w_ptr = width; |
| 2546 | *h_ptr = height; |
| 2547 | |
| 2548 | UnlockDisplay(dpy); |
| 2549 | SyncHandle(); |
| 2550 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2551 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2552 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2553 | /** |
| 2554 | * GLX_EXT_texture_from_pixmap |
| 2555 | */ |
| 2556 | /*@{*/ |
| 2557 | static void __glXBindTexImageEXT(Display *dpy, |
| 2558 | GLXDrawable drawable, |
| 2559 | int buffer, |
| 2560 | const int *attrib_list) |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2561 | { |
| 2562 | xGLXVendorPrivateReq *req; |
| 2563 | GLXContext gc = __glXGetCurrentContext(); |
| 2564 | CARD32 *drawable_ptr; |
| 2565 | INT32 *buffer_ptr; |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2566 | CARD32 *num_attrib_ptr; |
| 2567 | CARD32 *attrib_ptr; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2568 | CARD8 opcode; |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2569 | unsigned int i; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2570 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2571 | if (gc == NULL) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2572 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2573 | |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2574 | i = 0; |
| 2575 | if (attrib_list) { |
| 2576 | while (attrib_list[i * 2] != None) |
| 2577 | i++; |
| 2578 | } |
| 2579 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2580 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2581 | if (gc->driContext) { |
| 2582 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); |
| 2583 | |
| 2584 | if (pdraw != NULL) |
| 2585 | (*pdraw->psc->texBuffer->setTexBuffer)(gc->__driContext, |
| 2586 | pdraw->textureTarget, |
| 2587 | pdraw->driDrawable); |
| 2588 | |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2589 | return; |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 2590 | } |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2591 | #endif |
| 2592 | |
| 2593 | opcode = __glXSetupForCommand(dpy); |
| 2594 | if (!opcode) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2595 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2596 | |
| 2597 | LockDisplay(dpy); |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2598 | GetReqExtra(GLXVendorPrivate, 12 + 8 * i,req); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2599 | req->reqType = opcode; |
| 2600 | req->glxCode = X_GLXVendorPrivate; |
| 2601 | req->vendorCode = X_GLXvop_BindTexImageEXT; |
| 2602 | req->contextTag = gc->currentContextTag; |
| 2603 | |
| 2604 | drawable_ptr = (CARD32 *) (req + 1); |
| 2605 | buffer_ptr = (INT32 *) (drawable_ptr + 1); |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2606 | num_attrib_ptr = (CARD32 *) (buffer_ptr + 1); |
| 2607 | attrib_ptr = (CARD32 *) (num_attrib_ptr + 1); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2608 | |
| 2609 | *drawable_ptr = drawable; |
| 2610 | *buffer_ptr = buffer; |
David Reveman | c6f8ae1 | 2006-04-11 12:12:13 +0000 | [diff] [blame] | 2611 | *num_attrib_ptr = (CARD32) i; |
| 2612 | |
| 2613 | i = 0; |
| 2614 | if (attrib_list) { |
| 2615 | while (attrib_list[i * 2] != None) |
| 2616 | { |
| 2617 | *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0]; |
| 2618 | *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1]; |
| 2619 | i++; |
| 2620 | } |
| 2621 | } |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2622 | |
| 2623 | UnlockDisplay(dpy); |
| 2624 | SyncHandle(); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2627 | static void __glXReleaseTexImageEXT(Display *dpy, |
| 2628 | GLXDrawable drawable, |
| 2629 | int buffer) |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2630 | { |
| 2631 | xGLXVendorPrivateReq *req; |
| 2632 | GLXContext gc = __glXGetCurrentContext(); |
| 2633 | CARD32 *drawable_ptr; |
| 2634 | INT32 *buffer_ptr; |
| 2635 | CARD8 opcode; |
| 2636 | |
| 2637 | if (gc == NULL) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2638 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2639 | |
| 2640 | #ifdef GLX_DIRECT_RENDERING |
Kristian Høgsberg | 020c64b | 2008-03-08 21:57:29 -0500 | [diff] [blame] | 2641 | if (gc->driContext) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2642 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2643 | #endif |
| 2644 | |
| 2645 | opcode = __glXSetupForCommand(dpy); |
| 2646 | if (!opcode) |
Adam Jackson | 0157624 | 2006-05-01 22:25:18 +0000 | [diff] [blame] | 2647 | return; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2648 | |
| 2649 | LockDisplay(dpy); |
| 2650 | GetReqExtra(GLXVendorPrivate, sizeof(CARD32)+sizeof(INT32),req); |
| 2651 | req->reqType = opcode; |
| 2652 | req->glxCode = X_GLXVendorPrivate; |
| 2653 | req->vendorCode = X_GLXvop_ReleaseTexImageEXT; |
| 2654 | req->contextTag = gc->currentContextTag; |
| 2655 | |
| 2656 | drawable_ptr = (CARD32 *) (req + 1); |
| 2657 | buffer_ptr = (INT32 *) (drawable_ptr + 1); |
| 2658 | |
| 2659 | *drawable_ptr = drawable; |
| 2660 | *buffer_ptr = buffer; |
| 2661 | |
| 2662 | UnlockDisplay(dpy); |
| 2663 | SyncHandle(); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2664 | } |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2665 | /*@}*/ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2666 | |
| 2667 | /** |
| 2668 | * \c strdup is actually not a standard ANSI C or POSIX routine. |
| 2669 | * Irix will not define it if ANSI mode is in effect. |
| 2670 | * |
| 2671 | * \sa strdup |
| 2672 | */ |
Kristian Høgsberg | 3d28a26 | 2008-03-08 22:28:01 -0500 | [diff] [blame] | 2673 | _X_HIDDEN char * |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2674 | __glXstrdup(const char *str) |
| 2675 | { |
| 2676 | char *copy; |
| 2677 | copy = (char *) Xmalloc(strlen(str) + 1); |
| 2678 | if (!copy) |
| 2679 | return NULL; |
| 2680 | strcpy(copy, str); |
| 2681 | return copy; |
| 2682 | } |
| 2683 | |
| 2684 | /* |
| 2685 | ** glXGetProcAddress support |
| 2686 | */ |
| 2687 | |
| 2688 | struct name_address_pair { |
| 2689 | const char *Name; |
| 2690 | GLvoid *Address; |
| 2691 | }; |
| 2692 | |
| 2693 | #define GLX_FUNCTION(f) { # f, (GLvoid *) f } |
| 2694 | #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f } |
| 2695 | |
| 2696 | static const struct name_address_pair GLX_functions[] = { |
| 2697 | /*** GLX_VERSION_1_0 ***/ |
| 2698 | GLX_FUNCTION( glXChooseVisual ), |
| 2699 | GLX_FUNCTION( glXCopyContext ), |
| 2700 | GLX_FUNCTION( glXCreateContext ), |
| 2701 | GLX_FUNCTION( glXCreateGLXPixmap ), |
| 2702 | GLX_FUNCTION( glXDestroyContext ), |
| 2703 | GLX_FUNCTION( glXDestroyGLXPixmap ), |
| 2704 | GLX_FUNCTION( glXGetConfig ), |
| 2705 | GLX_FUNCTION( glXGetCurrentContext ), |
| 2706 | GLX_FUNCTION( glXGetCurrentDrawable ), |
| 2707 | GLX_FUNCTION( glXIsDirect ), |
| 2708 | GLX_FUNCTION( glXMakeCurrent ), |
| 2709 | GLX_FUNCTION( glXQueryExtension ), |
| 2710 | GLX_FUNCTION( glXQueryVersion ), |
| 2711 | GLX_FUNCTION( glXSwapBuffers ), |
| 2712 | GLX_FUNCTION( glXUseXFont ), |
| 2713 | GLX_FUNCTION( glXWaitGL ), |
| 2714 | GLX_FUNCTION( glXWaitX ), |
| 2715 | |
| 2716 | /*** GLX_VERSION_1_1 ***/ |
| 2717 | GLX_FUNCTION( glXGetClientString ), |
| 2718 | GLX_FUNCTION( glXQueryExtensionsString ), |
| 2719 | GLX_FUNCTION( glXQueryServerString ), |
| 2720 | |
| 2721 | /*** GLX_VERSION_1_2 ***/ |
| 2722 | GLX_FUNCTION( glXGetCurrentDisplay ), |
| 2723 | |
| 2724 | /*** GLX_VERSION_1_3 ***/ |
| 2725 | GLX_FUNCTION( glXChooseFBConfig ), |
| 2726 | GLX_FUNCTION( glXCreateNewContext ), |
| 2727 | GLX_FUNCTION( glXCreatePbuffer ), |
| 2728 | GLX_FUNCTION( glXCreatePixmap ), |
| 2729 | GLX_FUNCTION( glXCreateWindow ), |
| 2730 | GLX_FUNCTION( glXDestroyPbuffer ), |
| 2731 | GLX_FUNCTION( glXDestroyPixmap ), |
| 2732 | GLX_FUNCTION( glXDestroyWindow ), |
| 2733 | GLX_FUNCTION( glXGetCurrentReadDrawable ), |
| 2734 | GLX_FUNCTION( glXGetFBConfigAttrib ), |
| 2735 | GLX_FUNCTION( glXGetFBConfigs ), |
| 2736 | GLX_FUNCTION( glXGetSelectedEvent ), |
| 2737 | GLX_FUNCTION( glXGetVisualFromFBConfig ), |
| 2738 | GLX_FUNCTION( glXMakeContextCurrent ), |
| 2739 | GLX_FUNCTION( glXQueryContext ), |
| 2740 | GLX_FUNCTION( glXQueryDrawable ), |
| 2741 | GLX_FUNCTION( glXSelectEvent ), |
| 2742 | |
| 2743 | /*** GLX_SGI_swap_control ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2744 | GLX_FUNCTION2( glXSwapIntervalSGI, __glXSwapIntervalSGI ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2745 | |
| 2746 | /*** GLX_SGI_video_sync ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2747 | GLX_FUNCTION2( glXGetVideoSyncSGI, __glXGetVideoSyncSGI ), |
| 2748 | GLX_FUNCTION2( glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2749 | |
| 2750 | /*** GLX_SGI_make_current_read ***/ |
| 2751 | GLX_FUNCTION2( glXMakeCurrentReadSGI, glXMakeContextCurrent ), |
| 2752 | GLX_FUNCTION2( glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable ), |
| 2753 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2754 | /*** GLX_EXT_import_context ***/ |
| 2755 | GLX_FUNCTION( glXFreeContextEXT ), |
| 2756 | GLX_FUNCTION( glXGetContextIDEXT ), |
| 2757 | GLX_FUNCTION2( glXGetCurrentDisplayEXT, glXGetCurrentDisplay ), |
| 2758 | GLX_FUNCTION( glXImportContextEXT ), |
| 2759 | GLX_FUNCTION2( glXQueryContextInfoEXT, glXQueryContext ), |
| 2760 | |
| 2761 | /*** GLX_SGIX_fbconfig ***/ |
| 2762 | GLX_FUNCTION2( glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib ), |
| 2763 | GLX_FUNCTION2( glXChooseFBConfigSGIX, glXChooseFBConfig ), |
| 2764 | GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX ), |
| 2765 | GLX_FUNCTION( glXCreateContextWithConfigSGIX ), |
| 2766 | GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig ), |
| 2767 | GLX_FUNCTION( glXGetFBConfigFromVisualSGIX ), |
| 2768 | |
| 2769 | /*** GLX_SGIX_pbuffer ***/ |
| 2770 | GLX_FUNCTION( glXCreateGLXPbufferSGIX ), |
| 2771 | GLX_FUNCTION( glXDestroyGLXPbufferSGIX ), |
| 2772 | GLX_FUNCTION( glXQueryGLXPbufferSGIX ), |
| 2773 | GLX_FUNCTION( glXSelectEventSGIX ), |
| 2774 | GLX_FUNCTION( glXGetSelectedEventSGIX ), |
| 2775 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2776 | /*** GLX_SGIX_swap_group ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2777 | GLX_FUNCTION2( glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2778 | |
| 2779 | /*** GLX_SGIX_swap_barrier ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2780 | GLX_FUNCTION2( glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX ), |
| 2781 | GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2782 | |
| 2783 | /*** GLX_MESA_allocate_memory ***/ |
| 2784 | GLX_FUNCTION( glXAllocateMemoryMESA ), |
| 2785 | GLX_FUNCTION( glXFreeMemoryMESA ), |
| 2786 | GLX_FUNCTION( glXGetMemoryOffsetMESA ), |
| 2787 | |
| 2788 | /*** GLX_MESA_copy_sub_buffer ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2789 | GLX_FUNCTION2( glXCopySubBufferMESA, __glXCopySubBufferMESA ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2790 | |
| 2791 | /*** GLX_MESA_pixmap_colormap ***/ |
| 2792 | GLX_FUNCTION( glXCreateGLXPixmapMESA ), |
| 2793 | |
| 2794 | /*** GLX_MESA_release_buffers ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2795 | GLX_FUNCTION2( glXReleaseBuffersMESA, __glXReleaseBuffersMESA ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2796 | |
| 2797 | /*** GLX_MESA_swap_control ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2798 | GLX_FUNCTION2( glXSwapIntervalMESA, __glXSwapIntervalMESA ), |
| 2799 | GLX_FUNCTION2( glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2800 | |
| 2801 | /*** GLX_MESA_swap_frame_usage ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2802 | GLX_FUNCTION2( glXBeginFrameTrackingMESA, __glXBeginFrameTrackingMESA ), |
| 2803 | GLX_FUNCTION2( glXEndFrameTrackingMESA, __glXEndFrameTrackingMESA ), |
| 2804 | GLX_FUNCTION2( glXGetFrameUsageMESA, __glXGetFrameUsageMESA ), |
| 2805 | GLX_FUNCTION2( glXQueryFrameTrackingMESA, __glXQueryFrameTrackingMESA ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2806 | |
| 2807 | /*** GLX_ARB_get_proc_address ***/ |
| 2808 | GLX_FUNCTION( glXGetProcAddressARB ), |
| 2809 | |
| 2810 | /*** GLX 1.4 ***/ |
| 2811 | GLX_FUNCTION2( glXGetProcAddress, glXGetProcAddressARB ), |
| 2812 | |
| 2813 | /*** GLX_OML_sync_control ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2814 | GLX_FUNCTION2( glXWaitForSbcOML, __glXWaitForSbcOML ), |
| 2815 | GLX_FUNCTION2( glXWaitForMscOML, __glXWaitForMscOML ), |
| 2816 | GLX_FUNCTION2( glXSwapBuffersMscOML, __glXSwapBuffersMscOML ), |
| 2817 | GLX_FUNCTION2( glXGetMscRateOML, __glXGetMscRateOML ), |
| 2818 | GLX_FUNCTION2( glXGetSyncValuesOML, __glXGetSyncValuesOML ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2819 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2820 | /*** GLX_EXT_texture_from_pixmap ***/ |
Ian Romanick | fc5b57b | 2006-08-29 15:38:19 +0000 | [diff] [blame] | 2821 | GLX_FUNCTION2( glXBindTexImageEXT, __glXBindTexImageEXT ), |
| 2822 | GLX_FUNCTION2( glXReleaseTexImageEXT, __glXReleaseTexImageEXT ), |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 2823 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2824 | #ifdef GLX_DIRECT_RENDERING |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2825 | /*** DRI configuration ***/ |
| 2826 | GLX_FUNCTION( glXGetScreenDriver ), |
| 2827 | GLX_FUNCTION( glXGetDriverConfig ), |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2828 | #endif |
| 2829 | |
| 2830 | { NULL, NULL } /* end of list */ |
| 2831 | }; |
| 2832 | |
| 2833 | |
| 2834 | static const GLvoid * |
| 2835 | get_glx_proc_address(const char *funcName) |
| 2836 | { |
| 2837 | GLuint i; |
| 2838 | |
| 2839 | /* try static functions */ |
| 2840 | for (i = 0; GLX_functions[i].Name; i++) { |
| 2841 | if (strcmp(GLX_functions[i].Name, funcName) == 0) |
| 2842 | return GLX_functions[i].Address; |
| 2843 | } |
| 2844 | |
| 2845 | return NULL; |
| 2846 | } |
| 2847 | |
| 2848 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2849 | /** |
| 2850 | * Get the address of a named GL function. This is the pre-GLX 1.4 name for |
| 2851 | * \c glXGetProcAddress. |
| 2852 | * |
| 2853 | * \param procName Name of a GL or GLX function. |
| 2854 | * \returns A pointer to the named function |
| 2855 | * |
| 2856 | * \sa glXGetProcAddress |
| 2857 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 2858 | PUBLIC void (*glXGetProcAddressARB(const GLubyte *procName))( void ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2859 | { |
| 2860 | typedef void (*gl_function)( void ); |
| 2861 | gl_function f; |
| 2862 | |
| 2863 | |
| 2864 | /* Search the table of GLX and internal functions first. If that |
| 2865 | * fails and the supplied name could be a valid core GL name, try |
| 2866 | * searching the core GL function table. This check is done to prevent |
| 2867 | * DRI based drivers from searching the core GL function table for |
| 2868 | * internal API functions. |
| 2869 | */ |
| 2870 | |
| 2871 | f = (gl_function) get_glx_proc_address((const char *) procName); |
| 2872 | if ( (f == NULL) && (procName[0] == 'g') && (procName[1] == 'l') |
| 2873 | && (procName[2] != 'X') ) { |
| 2874 | f = (gl_function) _glapi_get_proc_address((const char *) procName); |
| 2875 | } |
| 2876 | |
| 2877 | return f; |
| 2878 | } |
| 2879 | |
| 2880 | /** |
| 2881 | * Get the address of a named GL function. This is the GLX 1.4 name for |
| 2882 | * \c glXGetProcAddressARB. |
| 2883 | * |
| 2884 | * \param procName Name of a GL or GLX function. |
| 2885 | * \returns A pointer to the named function |
| 2886 | * |
| 2887 | * \sa glXGetProcAddressARB |
| 2888 | */ |
Adam Jackson | 489ccef | 2004-12-15 17:18:06 +0000 | [diff] [blame] | 2889 | PUBLIC void (*glXGetProcAddress(const GLubyte *procName))( void ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2890 | #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED) |
| 2891 | __attribute__ ((alias ("glXGetProcAddressARB"))); |
| 2892 | #else |
| 2893 | { |
| 2894 | return glXGetProcAddressARB(procName); |
| 2895 | } |
| 2896 | #endif /* __GNUC__ */ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2897 | |
| 2898 | |
| 2899 | #ifdef GLX_DIRECT_RENDERING |
| 2900 | /** |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2901 | * Get the unadjusted system time (UST). Currently, the UST is measured in |
| 2902 | * microseconds since Epoc. The actual resolution of the UST may vary from |
| 2903 | * system to system, and the units may vary from release to release. |
| 2904 | * Drivers should not call this function directly. They should instead use |
| 2905 | * \c glXGetProcAddress to obtain a pointer to the function. |
| 2906 | * |
| 2907 | * \param ust Location to store the 64-bit UST |
| 2908 | * \returns Zero on success or a negative errno value on failure. |
| 2909 | * |
| 2910 | * \sa glXGetProcAddress, PFNGLXGETUSTPROC |
| 2911 | * |
| 2912 | * \since Internal API version 20030317. |
| 2913 | */ |
Kristian Høgsberg | 3d28a26 | 2008-03-08 22:28:01 -0500 | [diff] [blame] | 2914 | _X_HIDDEN int __glXGetUST( int64_t * ust ) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 2915 | { |
| 2916 | struct timeval tv; |
| 2917 | |
| 2918 | if ( ust == NULL ) { |
| 2919 | return -EFAULT; |
| 2920 | } |
| 2921 | |
| 2922 | if ( gettimeofday( & tv, NULL ) == 0 ) { |
| 2923 | ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec; |
| 2924 | return 0; |
| 2925 | } else { |
| 2926 | return -errno; |
| 2927 | } |
| 2928 | } |
| 2929 | #endif /* GLX_DIRECT_RENDERING */ |