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