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