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