Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright IBM Corporation 2004 |
| 3 | * 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 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
| 9 | * license, and/or sell copies of the Software, and to permit persons to whom |
| 10 | * the Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 19 | * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * \file glx_pbuffer.c |
| 27 | * Implementation of pbuffer related functions. |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 28 | * |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 29 | * \author Ian Romanick <idr@us.ibm.com> |
| 30 | */ |
| 31 | |
| 32 | #include <inttypes.h> |
| 33 | #include "glxclient.h" |
Brian Paul | 82dfd4b | 2005-08-11 14:18:53 +0000 | [diff] [blame] | 34 | #include <X11/extensions/extutil.h> |
| 35 | #include <X11/extensions/Xext.h> |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 36 | #include <assert.h> |
| 37 | #include <string.h> |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 38 | #include "glxextensions.h" |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 39 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 40 | #ifdef GLX_USE_APPLEGL |
| 41 | #include <pthread.h> |
Jon TURNEY | 5a459a0 | 2014-05-12 10:47:07 +0100 | [diff] [blame] | 42 | #include "apple/apple_glx_drawable.h" |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 43 | #endif |
| 44 | |
Ian Romanick | d5aee17 | 2013-08-08 18:17:24 -0700 | [diff] [blame] | 45 | #include "glx_error.h" |
| 46 | |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 47 | #define WARN_ONCE_GLX_1_3(a, b) { \ |
| 48 | static int warned=1; \ |
| 49 | if(warned) { \ |
| 50 | warn_GLX_1_3((a), b ); \ |
| 51 | warned=0; \ |
| 52 | } \ |
| 53 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 54 | |
| 55 | /** |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 56 | * Emit a warning when clients use GLX 1.3 functions on pre-1.3 systems. |
| 57 | */ |
| 58 | static void |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 59 | warn_GLX_1_3(Display * dpy, const char *function_name) |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 60 | { |
Kristian Høgsberg | c356f58 | 2010-07-28 11:16:00 -0400 | [diff] [blame] | 61 | struct glx_display *priv = __glXInitialize(dpy); |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 62 | |
Juha-Pekka Heikkila | e503609 | 2014-02-07 14:44:00 +0200 | [diff] [blame] | 63 | if (priv && priv->minorVersion < 3) { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 64 | fprintf(stderr, |
| 65 | "WARNING: Application calling GLX 1.3 function \"%s\" " |
| 66 | "when GLX 1.3 is not supported! This is an application bug!\n", |
| 67 | function_name); |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 71 | #ifndef GLX_USE_APPLEGL |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 72 | /** |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 73 | * Change a drawable's attribute. |
| 74 | * |
| 75 | * This function is used to implement \c glXSelectEvent and |
| 76 | * \c glXSelectEventSGIX. |
| 77 | * |
| 78 | * \note |
| 79 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 80 | * version of the protocol or the GLX 1.3 version of the protocol. |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 81 | */ |
| 82 | static void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 83 | ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable, |
| 84 | const CARD32 * attribs, size_t num_attribs) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 85 | { |
Kristian Høgsberg | c356f58 | 2010-07-28 11:16:00 -0400 | [diff] [blame] | 86 | struct glx_display *priv = __glXInitialize(dpy); |
Jon TURNEY | ae9487c | 2010-08-09 14:47:26 +0100 | [diff] [blame] | 87 | #ifdef GLX_DIRECT_RENDERING |
Vinson Lee | 5c9e54f | 2010-07-15 00:20:41 -0700 | [diff] [blame] | 88 | __GLXDRIdrawable *pdraw; |
Jon TURNEY | ae9487c | 2010-08-09 14:47:26 +0100 | [diff] [blame] | 89 | #endif |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 90 | CARD32 *output; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 91 | CARD8 opcode; |
Nick Bowler | f8d81c3 | 2010-07-14 12:01:49 -0400 | [diff] [blame] | 92 | int i; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 93 | |
Juha-Pekka Heikkila | e503609 | 2014-02-07 14:44:00 +0200 | [diff] [blame] | 94 | if ((priv == NULL) || (dpy == NULL) || (drawable == 0)) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 95 | return; |
| 96 | } |
| 97 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 98 | opcode = __glXSetupForCommand(dpy); |
| 99 | if (!opcode) |
| 100 | return; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 101 | |
| 102 | LockDisplay(dpy); |
| 103 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 104 | if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 105 | xGLXChangeDrawableAttributesReq *req; |
| 106 | |
Julien Cristau | 4324d6f | 2011-01-23 08:26:35 -0800 | [diff] [blame] | 107 | GetReqExtra(GLXChangeDrawableAttributes, 8 * num_attribs, req); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 108 | output = (CARD32 *) (req + 1); |
| 109 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 110 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 111 | req->glxCode = X_GLXChangeDrawableAttributes; |
| 112 | req->drawable = drawable; |
| 113 | req->numAttribs = (CARD32) num_attribs; |
| 114 | } |
| 115 | else { |
| 116 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 117 | |
Julien Cristau | e27913f | 2011-01-26 04:03:16 -0800 | [diff] [blame] | 118 | GetReqExtra(GLXVendorPrivateWithReply, 8 + (8 * num_attribs), vpreq); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 119 | output = (CARD32 *) (vpreq + 1); |
| 120 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 121 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 122 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 123 | vpreq->vendorCode = X_GLXvop_ChangeDrawableAttributesSGIX; |
| 124 | |
| 125 | output[0] = (CARD32) drawable; |
Julien Cristau | e27913f | 2011-01-26 04:03:16 -0800 | [diff] [blame] | 126 | output[1] = num_attribs; |
| 127 | output += 2; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 128 | } |
| 129 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 130 | (void) memcpy(output, attribs, sizeof(CARD32) * 2 * num_attribs); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 131 | |
| 132 | UnlockDisplay(dpy); |
| 133 | SyncHandle(); |
| 134 | |
Jon TURNEY | ae9487c | 2010-08-09 14:47:26 +0100 | [diff] [blame] | 135 | #ifdef GLX_DIRECT_RENDERING |
| 136 | pdraw = GetGLXDRIDrawable(dpy, drawable); |
| 137 | |
Jesse Barnes | 6ae9e8c | 2011-05-03 10:20:14 -0700 | [diff] [blame] | 138 | if (!pdraw) |
| 139 | return; |
| 140 | |
Nick Bowler | f8d81c3 | 2010-07-14 12:01:49 -0400 | [diff] [blame] | 141 | for (i = 0; i < num_attribs; i++) { |
| 142 | switch(attribs[i * 2]) { |
| 143 | case GLX_EVENT_MASK: |
| 144 | /* Keep a local copy for masking out DRI2 proto events as needed */ |
| 145 | pdraw->eventMask = attribs[i * 2 + 1]; |
| 146 | break; |
| 147 | } |
| 148 | } |
Jon TURNEY | ae9487c | 2010-08-09 14:47:26 +0100 | [diff] [blame] | 149 | #endif |
Nick Bowler | f8d81c3 | 2010-07-14 12:01:49 -0400 | [diff] [blame] | 150 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 151 | return; |
| 152 | } |
| 153 | |
| 154 | |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 155 | #ifdef GLX_DIRECT_RENDERING |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 156 | static GLenum |
| 157 | determineTextureTarget(const int *attribs, int numAttribs) |
| 158 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 159 | GLenum target = 0; |
| 160 | int i; |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 161 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 162 | for (i = 0; i < numAttribs; i++) { |
| 163 | if (attribs[2 * i] == GLX_TEXTURE_TARGET_EXT) { |
| 164 | switch (attribs[2 * i + 1]) { |
| 165 | case GLX_TEXTURE_2D_EXT: |
| 166 | target = GL_TEXTURE_2D; |
| 167 | break; |
| 168 | case GLX_TEXTURE_RECTANGLE_EXT: |
| 169 | target = GL_TEXTURE_RECTANGLE_ARB; |
| 170 | break; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | return target; |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 176 | } |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 177 | |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 178 | static GLenum |
| 179 | determineTextureFormat(const int *attribs, int numAttribs) |
| 180 | { |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 181 | int i; |
| 182 | |
| 183 | for (i = 0; i < numAttribs; i++) { |
| 184 | if (attribs[2 * i] == GLX_TEXTURE_FORMAT_EXT) |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 185 | return attribs[2 * i + 1]; |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | return 0; |
| 189 | } |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 190 | |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 191 | static GLboolean |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 192 | CreateDRIDrawable(Display *dpy, struct glx_config *config, |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 193 | XID drawable, XID glxdrawable, |
| 194 | const int *attrib_list, size_t num_attribs) |
| 195 | { |
Kristian Høgsberg | c356f58 | 2010-07-28 11:16:00 -0400 | [diff] [blame] | 196 | struct glx_display *const priv = __glXInitialize(dpy); |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 197 | __GLXDRIdrawable *pdraw; |
Kristian Høgsberg | 66fc35c | 2010-07-28 10:28:43 -0400 | [diff] [blame] | 198 | struct glx_screen *psc; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 199 | |
Juha-Pekka Heikkila | e503609 | 2014-02-07 14:44:00 +0200 | [diff] [blame] | 200 | if (priv == NULL) { |
| 201 | fprintf(stderr, "failed to create drawable\n"); |
| 202 | return GL_FALSE; |
| 203 | } |
| 204 | |
Kristian Høgsberg | 66fc35c | 2010-07-28 10:28:43 -0400 | [diff] [blame] | 205 | psc = priv->screens[config->screen]; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 206 | if (psc->driScreen == NULL) |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 207 | return GL_TRUE; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 208 | |
| 209 | pdraw = psc->driScreen->createDrawable(psc, drawable, |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 210 | glxdrawable, config); |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 211 | if (pdraw == NULL) { |
| 212 | fprintf(stderr, "failed to create drawable\n"); |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 213 | return GL_FALSE; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 214 | } |
| 215 | |
Kristian Høgsberg | e3e8196 | 2010-07-19 21:15:50 -0400 | [diff] [blame] | 216 | if (__glxHashInsert(priv->drawHash, glxdrawable, pdraw)) { |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 217 | (*pdraw->destroyDrawable) (pdraw); |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 218 | return GL_FALSE; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | pdraw->textureTarget = determineTextureTarget(attrib_list, num_attribs); |
| 222 | pdraw->textureFormat = determineTextureFormat(attrib_list, num_attribs); |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 223 | |
| 224 | return GL_TRUE; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | static void |
| 228 | DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable) |
| 229 | { |
Kristian Høgsberg | c356f58 | 2010-07-28 11:16:00 -0400 | [diff] [blame] | 230 | struct glx_display *const priv = __glXInitialize(dpy); |
Kristian Høgsberg | eeaab20 | 2010-07-22 22:36:37 -0400 | [diff] [blame] | 231 | __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); |
Kristian Høgsberg | 80e48dd | 2010-09-09 08:06:40 -0400 | [diff] [blame] | 232 | XID xid; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 233 | |
Juha-Pekka Heikkila | e503609 | 2014-02-07 14:44:00 +0200 | [diff] [blame] | 234 | if (priv != NULL && pdraw != NULL) { |
Kristian Høgsberg | 80e48dd | 2010-09-09 08:06:40 -0400 | [diff] [blame] | 235 | xid = pdraw->xDrawable; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 236 | (*pdraw->destroyDrawable) (pdraw); |
Kristian Høgsberg | e3e8196 | 2010-07-19 21:15:50 -0400 | [diff] [blame] | 237 | __glxHashDelete(priv->drawHash, drawable); |
Kristian Høgsberg | d8ab9aa | 2010-09-08 20:55:02 -0400 | [diff] [blame] | 238 | if (destroy_xdrawable) |
Kristian Høgsberg | 80e48dd | 2010-09-09 08:06:40 -0400 | [diff] [blame] | 239 | XFreePixmap(priv->dpy, xid); |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | #else |
| 244 | |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 245 | static GLboolean |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 246 | CreateDRIDrawable(Display *dpy, const struct glx_config * fbconfig, |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 247 | XID drawable, XID glxdrawable, |
| 248 | const int *attrib_list, size_t num_attribs) |
| 249 | { |
Jon TURNEY | f816a9f | 2013-02-26 15:47:44 +0000 | [diff] [blame] | 250 | return GL_TRUE; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | static void |
| 254 | DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable) |
| 255 | { |
| 256 | } |
| 257 | |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 258 | #endif |
| 259 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 260 | /** |
| 261 | * Get a drawable's attribute. |
| 262 | * |
| 263 | * This function is used to implement \c glXGetSelectedEvent and |
| 264 | * \c glXGetSelectedEventSGIX. |
| 265 | * |
| 266 | * \note |
| 267 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 268 | * version of the protocol or the GLX 1.3 version of the protocol. |
| 269 | * |
| 270 | * \todo |
| 271 | * The number of attributes returned is likely to be small, probably less than |
| 272 | * 10. Given that, this routine should try to use an array on the stack to |
| 273 | * capture the reply rather than always calling Xmalloc. |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 274 | */ |
| 275 | static int |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 276 | GetDrawableAttribute(Display * dpy, GLXDrawable drawable, |
| 277 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 278 | { |
Kristian Høgsberg | c356f58 | 2010-07-28 11:16:00 -0400 | [diff] [blame] | 279 | struct glx_display *priv; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 280 | xGLXGetDrawableAttributesReply reply; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 281 | CARD32 *data; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 282 | CARD8 opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 283 | unsigned int length; |
| 284 | unsigned int i; |
| 285 | unsigned int num_attributes; |
Owain G. Ainsworth | b4866f8 | 2009-01-11 20:40:07 +0000 | [diff] [blame] | 286 | GLboolean use_glx_1_3; |
Adam Jackson | d25ad50 | 2006-04-07 00:05:50 +0000 | [diff] [blame] | 287 | |
Adel Gadllah | a69fabc | 2014-02-24 20:44:42 +0100 | [diff] [blame] | 288 | #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) |
| 289 | __GLXDRIdrawable *pdraw; |
| 290 | #endif |
| 291 | |
Ian Romanick | d5aee17 | 2013-08-08 18:17:24 -0700 | [diff] [blame] | 292 | if (dpy == NULL) |
| 293 | return 0; |
| 294 | |
| 295 | /* Page 38 (page 52 of the PDF) of glxencode1.3.pdf says: |
| 296 | * |
| 297 | * "If drawable is not a valid GLX drawable, a GLXBadDrawable error is |
| 298 | * generated." |
| 299 | */ |
| 300 | if (drawable == 0) { |
| 301 | __glXSendError(dpy, GLXBadDrawable, 0, X_GLXGetDrawableAttributes, false); |
Adam Jackson | d25ad50 | 2006-04-07 00:05:50 +0000 | [diff] [blame] | 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | priv = __glXInitialize(dpy); |
Juha-Pekka Heikkila | e503609 | 2014-02-07 14:44:00 +0200 | [diff] [blame] | 306 | if (priv == NULL) |
| 307 | return 0; |
| 308 | |
Owain G. Ainsworth | b4866f8 | 2009-01-11 20:40:07 +0000 | [diff] [blame] | 309 | use_glx_1_3 = ((priv->majorVersion > 1) || (priv->minorVersion >= 3)); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 310 | |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 311 | *value = 0; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 312 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 313 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 314 | opcode = __glXSetupForCommand(dpy); |
| 315 | if (!opcode) |
| 316 | return 0; |
| 317 | |
Adel Gadllah | a69fabc | 2014-02-24 20:44:42 +0100 | [diff] [blame] | 318 | #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) |
| 319 | pdraw = GetGLXDRIDrawable(dpy, drawable); |
| 320 | |
| 321 | if (attribute == GLX_BACK_BUFFER_AGE_EXT) { |
Adel Gadllah | a69fabc | 2014-02-24 20:44:42 +0100 | [diff] [blame] | 322 | struct glx_context *gc = __glXGetCurrentContext(); |
Juha-Pekka Heikkila | 2670d0f | 2014-04-25 11:16:50 +0300 | [diff] [blame] | 323 | struct glx_screen *psc; |
Adel Gadllah | a69fabc | 2014-02-24 20:44:42 +0100 | [diff] [blame] | 324 | |
| 325 | /* The GLX_EXT_buffer_age spec says: |
| 326 | * |
| 327 | * "If querying GLX_BACK_BUFFER_AGE_EXT and <draw> is not bound to |
| 328 | * the calling thread's current context a GLXBadDrawable error is |
| 329 | * generated." |
| 330 | */ |
Juha-Pekka Heikkila | 2670d0f | 2014-04-25 11:16:50 +0300 | [diff] [blame] | 331 | if (pdraw == NULL || gc == NULL || gc->currentDpy != dpy || |
| 332 | (gc->currentDrawable != drawable && |
| 333 | gc->currentReadable != drawable)) { |
| 334 | __glXSendError(dpy, GLXBadDrawable, drawable, |
| 335 | X_GLXGetDrawableAttributes, false); |
Adel Gadllah | a69fabc | 2014-02-24 20:44:42 +0100 | [diff] [blame] | 336 | return 0; |
| 337 | } |
| 338 | |
Juha-Pekka Heikkila | 2670d0f | 2014-04-25 11:16:50 +0300 | [diff] [blame] | 339 | psc = pdraw->psc; |
| 340 | |
Adel Gadllah | a69fabc | 2014-02-24 20:44:42 +0100 | [diff] [blame] | 341 | if (psc->driScreen->getBufferAge != NULL) |
| 342 | *value = psc->driScreen->getBufferAge(pdraw); |
| 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | #endif |
| 347 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 348 | LockDisplay(dpy); |
| 349 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 350 | if (use_glx_1_3) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 351 | xGLXGetDrawableAttributesReq *req; |
| 352 | |
Julien Cristau | 4324d6f | 2011-01-23 08:26:35 -0800 | [diff] [blame] | 353 | GetReq(GLXGetDrawableAttributes, req); |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 354 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 355 | req->glxCode = X_GLXGetDrawableAttributes; |
| 356 | req->drawable = drawable; |
| 357 | } |
| 358 | else { |
| 359 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 360 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 361 | GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 362 | data = (CARD32 *) (vpreq + 1); |
| 363 | data[0] = (CARD32) drawable; |
| 364 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 365 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 366 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 367 | vpreq->vendorCode = X_GLXvop_GetDrawableAttributesSGIX; |
| 368 | } |
| 369 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 370 | _XReply(dpy, (xReply *) & reply, 0, False); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 371 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 372 | if (reply.type == X_Error) { |
| 373 | UnlockDisplay(dpy); |
| 374 | SyncHandle(); |
| 375 | return 0; |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 378 | length = reply.length; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 379 | if (length) { |
| 380 | num_attributes = (use_glx_1_3) ? reply.numAttribs : length / 2; |
Matt Turner | 2b7a972 | 2012-09-03 19:44:00 -0700 | [diff] [blame] | 381 | data = malloc(length * sizeof(CARD32)); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 382 | if (data == NULL) { |
| 383 | /* Throw data on the floor */ |
| 384 | _XEatData(dpy, length); |
| 385 | } |
| 386 | else { |
| 387 | _XRead(dpy, (char *) data, length * sizeof(CARD32)); |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 388 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 389 | /* Search the set of returned attributes for the attribute requested by |
| 390 | * the caller. |
| 391 | */ |
| 392 | for (i = 0; i < num_attributes; i++) { |
| 393 | if (data[i * 2] == attribute) { |
| 394 | *value = data[(i * 2) + 1]; |
| 395 | break; |
| 396 | } |
| 397 | } |
Brian Paul | 42725d6 | 2006-02-07 00:39:56 +0000 | [diff] [blame] | 398 | |
Jeremy Huddleston | 80b280d | 2010-04-02 01:35:19 -0700 | [diff] [blame] | 399 | #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) |
Adel Gadllah | b972e55 | 2014-02-24 20:44:41 +0100 | [diff] [blame] | 400 | if (pdraw != NULL) { |
| 401 | if (!pdraw->textureTarget) |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 402 | pdraw->textureTarget = |
| 403 | determineTextureTarget((const int *) data, num_attributes); |
Adel Gadllah | b972e55 | 2014-02-24 20:44:41 +0100 | [diff] [blame] | 404 | if (!pdraw->textureFormat) |
Eric Anholt | 66175aa | 2009-03-18 12:07:09 -0700 | [diff] [blame] | 405 | pdraw->textureFormat = |
| 406 | determineTextureFormat((const int *) data, num_attributes); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 407 | } |
Michel Dänzer | 23635510 | 2008-04-10 15:45:52 -0400 | [diff] [blame] | 408 | #endif |
| 409 | |
Matt Turner | 7c7b7b0 | 2012-09-04 22:52:36 -0700 | [diff] [blame] | 410 | free(data); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 411 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | UnlockDisplay(dpy); |
| 415 | SyncHandle(); |
| 416 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 417 | return 0; |
| 418 | } |
| 419 | |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 420 | static void |
| 421 | protocolDestroyDrawable(Display *dpy, GLXDrawable drawable, CARD32 glxCode) |
| 422 | { |
| 423 | xGLXDestroyPbufferReq *req; |
| 424 | CARD8 opcode; |
| 425 | |
| 426 | opcode = __glXSetupForCommand(dpy); |
| 427 | if (!opcode) |
| 428 | return; |
| 429 | |
| 430 | LockDisplay(dpy); |
| 431 | |
| 432 | GetReq(GLXDestroyPbuffer, req); |
| 433 | req->reqType = opcode; |
| 434 | req->glxCode = glxCode; |
| 435 | req->pbuffer = (GLXPbuffer) drawable; |
| 436 | |
| 437 | UnlockDisplay(dpy); |
| 438 | SyncHandle(); |
| 439 | } |
| 440 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 441 | /** |
| 442 | * Create a non-pbuffer GLX drawable. |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 443 | */ |
| 444 | static GLXDrawable |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 445 | CreateDrawable(Display *dpy, struct glx_config *config, |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 446 | Drawable drawable, const int *attrib_list, CARD8 glxCode) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 447 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 448 | xGLXCreateWindowReq *req; |
Jesse Barnes | 4df1376 | 2011-05-06 10:31:24 -0700 | [diff] [blame] | 449 | struct glx_drawable *glxDraw; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 450 | CARD32 *data; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 451 | unsigned int i; |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 452 | CARD8 opcode; |
Adam Jackson | a95ec18 | 2011-05-25 06:11:20 -0400 | [diff] [blame] | 453 | GLXDrawable xid; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 454 | |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 455 | i = 0; |
| 456 | if (attrib_list) { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 457 | while (attrib_list[i * 2] != None) |
| 458 | i++; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 459 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 460 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 461 | opcode = __glXSetupForCommand(dpy); |
| 462 | if (!opcode) |
| 463 | return None; |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 464 | |
Matt Turner | 7c7b7b0 | 2012-09-04 22:52:36 -0700 | [diff] [blame] | 465 | glxDraw = malloc(sizeof(*glxDraw)); |
Jesse Barnes | 4df1376 | 2011-05-06 10:31:24 -0700 | [diff] [blame] | 466 | if (!glxDraw) |
| 467 | return None; |
| 468 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 469 | LockDisplay(dpy); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 470 | GetReqExtra(GLXCreateWindow, 8 * i, req); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 471 | data = (CARD32 *) (req + 1); |
| 472 | |
David Reveman | 342d1de | 2006-04-11 12:07:41 +0000 | [diff] [blame] | 473 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 474 | req->glxCode = glxCode; |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 475 | req->screen = config->screen; |
| 476 | req->fbconfig = config->fbconfigID; |
| 477 | req->window = drawable; |
Adam Jackson | a95ec18 | 2011-05-25 06:11:20 -0400 | [diff] [blame] | 478 | req->glxwindow = xid = XAllocID(dpy); |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 479 | req->numAttribs = i; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 480 | |
Brian Paul | 5f40a7a | 2010-03-02 07:34:29 -0700 | [diff] [blame] | 481 | if (attrib_list) |
| 482 | memcpy(data, attrib_list, 8 * i); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 483 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 484 | UnlockDisplay(dpy); |
| 485 | SyncHandle(); |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 486 | |
Jesse Barnes | 4df1376 | 2011-05-06 10:31:24 -0700 | [diff] [blame] | 487 | if (InitGLXDrawable(dpy, glxDraw, drawable, xid)) { |
| 488 | free(glxDraw); |
| 489 | return None; |
| 490 | } |
| 491 | |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 492 | if (!CreateDRIDrawable(dpy, config, drawable, xid, attrib_list, i)) { |
| 493 | if (glxCode == X_GLXCreatePixmap) |
| 494 | glxCode = X_GLXDestroyPixmap; |
| 495 | else |
| 496 | glxCode = X_GLXDestroyWindow; |
| 497 | protocolDestroyDrawable(dpy, xid, glxCode); |
| 498 | xid = None; |
| 499 | } |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 500 | |
Adam Jackson | a95ec18 | 2011-05-25 06:11:20 -0400 | [diff] [blame] | 501 | return xid; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | |
| 505 | /** |
| 506 | * Destroy a non-pbuffer GLX drawable. |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 507 | */ |
| 508 | static void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 509 | DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 510 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 511 | if ((dpy == NULL) || (drawable == 0)) { |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 512 | return; |
| 513 | } |
| 514 | |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 515 | protocolDestroyDrawable(dpy, drawable, glxCode); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 516 | |
Jesse Barnes | 4df1376 | 2011-05-06 10:31:24 -0700 | [diff] [blame] | 517 | DestroyGLXDrawable(dpy, drawable); |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 518 | DestroyDRIDrawable(dpy, drawable, GL_FALSE); |
Kristian Høgsberg | e82dd8c | 2008-03-26 19:26:59 -0400 | [diff] [blame] | 519 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 520 | return; |
| 521 | } |
| 522 | |
| 523 | |
| 524 | /** |
| 525 | * Create a pbuffer. |
| 526 | * |
| 527 | * This function is used to implement \c glXCreatePbuffer and |
| 528 | * \c glXCreateGLXPbufferSGIX. |
| 529 | * |
| 530 | * \note |
| 531 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 532 | * version of the protocol or the GLX 1.3 version of the protocol. |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 533 | */ |
| 534 | static GLXDrawable |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 535 | CreatePbuffer(Display * dpy, struct glx_config *config, |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 536 | unsigned int width, unsigned int height, |
| 537 | const int *attrib_list, GLboolean size_in_attribs) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 538 | { |
Kristian Høgsberg | c356f58 | 2010-07-28 11:16:00 -0400 | [diff] [blame] | 539 | struct glx_display *priv = __glXInitialize(dpy); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 540 | GLXDrawable id = 0; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 541 | CARD32 *data; |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 542 | CARD8 opcode; |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 543 | unsigned int i; |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 544 | Pixmap pixmap; |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 545 | GLboolean glx_1_3 = GL_FALSE; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 546 | |
Juha-Pekka Heikkila | e503609 | 2014-02-07 14:44:00 +0200 | [diff] [blame] | 547 | if (priv == NULL) |
| 548 | return None; |
| 549 | |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 550 | i = 0; |
| 551 | if (attrib_list) { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 552 | while (attrib_list[i * 2]) |
| 553 | i++; |
Ian Romanick | b47731f | 2005-03-04 17:53:24 +0000 | [diff] [blame] | 554 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 555 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 556 | opcode = __glXSetupForCommand(dpy); |
| 557 | if (!opcode) |
| 558 | return None; |
| 559 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 560 | LockDisplay(dpy); |
| 561 | id = XAllocID(dpy); |
| 562 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 563 | if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { |
| 564 | xGLXCreatePbufferReq *req; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 565 | unsigned int extra = (size_in_attribs) ? 0 : 2; |
| 566 | |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 567 | glx_1_3 = GL_TRUE; |
| 568 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 569 | GetReqExtra(GLXCreatePbuffer, (8 * (i + extra)), req); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 570 | data = (CARD32 *) (req + 1); |
| 571 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 572 | req->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 573 | req->glxCode = X_GLXCreatePbuffer; |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 574 | req->screen = config->screen; |
| 575 | req->fbconfig = config->fbconfigID; |
| 576 | req->pbuffer = id; |
| 577 | req->numAttribs = i + extra; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 578 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 579 | if (!size_in_attribs) { |
| 580 | data[(2 * i) + 0] = GLX_PBUFFER_WIDTH; |
| 581 | data[(2 * i) + 1] = width; |
| 582 | data[(2 * i) + 2] = GLX_PBUFFER_HEIGHT; |
| 583 | data[(2 * i) + 3] = height; |
| 584 | data += 4; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | else { |
| 588 | xGLXVendorPrivateReq *vpreq; |
| 589 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 590 | GetReqExtra(GLXVendorPrivate, 20 + (8 * i), vpreq); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 591 | data = (CARD32 *) (vpreq + 1); |
| 592 | |
Kristian Høgsberg | c25eb99 | 2006-06-13 01:41:18 +0000 | [diff] [blame] | 593 | vpreq->reqType = opcode; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 594 | vpreq->glxCode = X_GLXVendorPrivate; |
| 595 | vpreq->vendorCode = X_GLXvop_CreateGLXPbufferSGIX; |
| 596 | |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 597 | data[0] = config->screen; |
| 598 | data[1] = config->fbconfigID; |
| 599 | data[2] = id; |
| 600 | data[3] = width; |
| 601 | data[4] = height; |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 602 | data += 5; |
| 603 | } |
| 604 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 605 | (void) memcpy(data, attrib_list, sizeof(CARD32) * 2 * i); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 606 | |
| 607 | UnlockDisplay(dpy); |
| 608 | SyncHandle(); |
| 609 | |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 610 | pixmap = XCreatePixmap(dpy, RootWindow(dpy, config->screen), |
| 611 | width, height, config->rgbBits); |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 612 | |
Adam Jackson | 4833104 | 2011-03-31 20:43:57 +0000 | [diff] [blame] | 613 | if (!CreateDRIDrawable(dpy, config, pixmap, id, attrib_list, i)) { |
| 614 | CARD32 o = glx_1_3 ? X_GLXDestroyPbuffer : X_GLXvop_DestroyGLXPbufferSGIX; |
| 615 | XFreePixmap(dpy, pixmap); |
| 616 | protocolDestroyDrawable(dpy, id, o); |
| 617 | id = None; |
| 618 | } |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 619 | |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 620 | return id; |
| 621 | } |
| 622 | |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 623 | /** |
| 624 | * Destroy a pbuffer. |
| 625 | * |
| 626 | * This function is used to implement \c glXDestroyPbuffer and |
| 627 | * \c glXDestroyGLXPbufferSGIX. |
| 628 | * |
| 629 | * \note |
| 630 | * This function dynamically determines whether to use the SGIX_pbuffer |
| 631 | * version of the protocol or the GLX 1.3 version of the protocol. |
| 632 | */ |
| 633 | static void |
| 634 | DestroyPbuffer(Display * dpy, GLXDrawable drawable) |
| 635 | { |
Kristian Høgsberg | c356f58 | 2010-07-28 11:16:00 -0400 | [diff] [blame] | 636 | struct glx_display *priv = __glXInitialize(dpy); |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 637 | CARD8 opcode; |
| 638 | |
Juha-Pekka Heikkila | e503609 | 2014-02-07 14:44:00 +0200 | [diff] [blame] | 639 | if ((priv == NULL) || (dpy == NULL) || (drawable == 0)) { |
Kristian Høgsberg | 5a43dba | 2010-04-09 17:16:33 -0400 | [diff] [blame] | 640 | return; |
| 641 | } |
| 642 | |
| 643 | opcode = __glXSetupForCommand(dpy); |
| 644 | if (!opcode) |
| 645 | return; |
| 646 | |
| 647 | LockDisplay(dpy); |
| 648 | |
| 649 | if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { |
| 650 | xGLXDestroyPbufferReq *req; |
| 651 | |
| 652 | GetReq(GLXDestroyPbuffer, req); |
| 653 | req->reqType = opcode; |
| 654 | req->glxCode = X_GLXDestroyPbuffer; |
| 655 | req->pbuffer = (GLXPbuffer) drawable; |
| 656 | } |
| 657 | else { |
| 658 | xGLXVendorPrivateWithReplyReq *vpreq; |
| 659 | CARD32 *data; |
| 660 | |
| 661 | GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq); |
| 662 | data = (CARD32 *) (vpreq + 1); |
| 663 | |
| 664 | data[0] = (CARD32) drawable; |
| 665 | |
| 666 | vpreq->reqType = opcode; |
| 667 | vpreq->glxCode = X_GLXVendorPrivateWithReply; |
| 668 | vpreq->vendorCode = X_GLXvop_DestroyGLXPbufferSGIX; |
| 669 | } |
| 670 | |
| 671 | UnlockDisplay(dpy); |
| 672 | SyncHandle(); |
| 673 | |
| 674 | DestroyDRIDrawable(dpy, drawable, GL_TRUE); |
| 675 | |
| 676 | return; |
| 677 | } |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 678 | |
| 679 | /** |
| 680 | * Create a new pbuffer. |
| 681 | */ |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 682 | _X_EXPORT GLXPbufferSGIX |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 683 | glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config, |
| 684 | unsigned int width, unsigned int height, |
| 685 | int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 686 | { |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 687 | return (GLXPbufferSGIX) CreatePbuffer(dpy, (struct glx_config *) config, |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 688 | width, height, |
| 689 | attrib_list, GL_FALSE); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 692 | #endif /* GLX_USE_APPLEGL */ |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 693 | |
| 694 | /** |
| 695 | * Create a new pbuffer. |
| 696 | */ |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 697 | _X_EXPORT GLXPbuffer |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 698 | glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 699 | { |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 700 | int i, width, height; |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 701 | #ifdef GLX_USE_APPLEGL |
| 702 | GLXPbuffer result; |
| 703 | int errorcode; |
| 704 | #endif |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 705 | |
| 706 | width = 0; |
| 707 | height = 0; |
| 708 | |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 709 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 710 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 711 | #ifdef GLX_USE_APPLEGL |
| 712 | for (i = 0; attrib_list[i]; ++i) { |
| 713 | switch (attrib_list[i]) { |
| 714 | case GLX_PBUFFER_WIDTH: |
| 715 | width = attrib_list[i + 1]; |
| 716 | ++i; |
| 717 | break; |
| 718 | |
| 719 | case GLX_PBUFFER_HEIGHT: |
| 720 | height = attrib_list[i + 1]; |
| 721 | ++i; |
| 722 | break; |
| 723 | |
| 724 | case GLX_LARGEST_PBUFFER: |
| 725 | /* This is a hint we should probably handle, but how? */ |
| 726 | ++i; |
| 727 | break; |
| 728 | |
| 729 | case GLX_PRESERVED_CONTENTS: |
| 730 | /* The contents are always preserved with AppleSGLX with CGL. */ |
| 731 | ++i; |
| 732 | break; |
| 733 | |
| 734 | default: |
| 735 | return None; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | if (apple_glx_pbuffer_create(dpy, config, width, height, &errorcode, |
| 740 | &result)) { |
| 741 | /* |
| 742 | * apple_glx_pbuffer_create only sets the errorcode to core X11 |
| 743 | * errors. |
| 744 | */ |
| 745 | __glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true); |
| 746 | |
| 747 | return None; |
| 748 | } |
| 749 | |
| 750 | return result; |
| 751 | #else |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 752 | for (i = 0; attrib_list[i * 2]; i++) { |
| 753 | switch (attrib_list[i * 2]) { |
| 754 | case GLX_PBUFFER_WIDTH: |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 755 | width = attrib_list[i * 2 + 1]; |
| 756 | break; |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 757 | case GLX_PBUFFER_HEIGHT: |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 758 | height = attrib_list[i * 2 + 1]; |
| 759 | break; |
Kristian Høgsberg | 8b20411 | 2007-08-27 14:16:30 -0400 | [diff] [blame] | 760 | } |
| 761 | } |
| 762 | |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 763 | return (GLXPbuffer) CreatePbuffer(dpy, (struct glx_config *) config, |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 764 | width, height, attrib_list, GL_TRUE); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 765 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | |
| 769 | /** |
| 770 | * Destroy an existing pbuffer. |
| 771 | */ |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 772 | _X_EXPORT void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 773 | glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 774 | { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 775 | #ifdef GLX_USE_APPLEGL |
| 776 | if (apple_glx_pbuffer_destroy(dpy, pbuf)) { |
| 777 | __glXSendError(dpy, GLXBadPbuffer, pbuf, X_GLXDestroyPbuffer, false); |
| 778 | } |
| 779 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 780 | DestroyPbuffer(dpy, pbuf); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 781 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | |
| 785 | /** |
| 786 | * Query an attribute of a drawable. |
| 787 | */ |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 788 | _X_EXPORT void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 789 | glXQueryDrawable(Display * dpy, GLXDrawable drawable, |
| 790 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 791 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 792 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 793 | #ifdef GLX_USE_APPLEGL |
| 794 | Window root; |
| 795 | int x, y; |
| 796 | unsigned int width, height, bd, depth; |
| 797 | |
| 798 | if (apple_glx_pixmap_query(drawable, attribute, value)) |
| 799 | return; /*done */ |
| 800 | |
| 801 | if (apple_glx_pbuffer_query(drawable, attribute, value)) |
| 802 | return; /*done */ |
| 803 | |
| 804 | /* |
| 805 | * The OpenGL spec states that we should report GLXBadDrawable if |
| 806 | * the drawable is invalid, however doing so would require that we |
| 807 | * use XSetErrorHandler(), which is known to not be thread safe. |
| 808 | * If we use a round-trip call to validate the drawable, there could |
| 809 | * be a race, so instead we just opt in favor of letting the |
| 810 | * XGetGeometry request fail with a GetGeometry request X error |
| 811 | * rather than GLXBadDrawable, in what is hoped to be a rare |
| 812 | * case of an invalid drawable. In practice most and possibly all |
| 813 | * X11 apps using GLX shouldn't notice a difference. |
| 814 | */ |
| 815 | if (XGetGeometry |
| 816 | (dpy, drawable, &root, &x, &y, &width, &height, &bd, &depth)) { |
| 817 | switch (attribute) { |
| 818 | case GLX_WIDTH: |
| 819 | *value = width; |
| 820 | break; |
| 821 | |
| 822 | case GLX_HEIGHT: |
| 823 | *value = height; |
| 824 | break; |
| 825 | } |
| 826 | } |
| 827 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 828 | GetDrawableAttribute(dpy, drawable, attribute, value); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 829 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 833 | #ifndef GLX_USE_APPLEGL |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 834 | /** |
| 835 | * Query an attribute of a pbuffer. |
| 836 | */ |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 837 | _X_EXPORT int |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 838 | glXQueryGLXPbufferSGIX(Display * dpy, GLXPbufferSGIX drawable, |
| 839 | int attribute, unsigned int *value) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 840 | { |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 841 | return GetDrawableAttribute(dpy, drawable, attribute, value); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 842 | } |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 843 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 844 | |
| 845 | /** |
| 846 | * Select the event mask for a drawable. |
| 847 | */ |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 848 | _X_EXPORT void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 849 | glXSelectEvent(Display * dpy, GLXDrawable drawable, unsigned long mask) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 850 | { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 851 | #ifdef GLX_USE_APPLEGL |
| 852 | XWindowAttributes xwattr; |
| 853 | |
| 854 | if (apple_glx_pbuffer_set_event_mask(drawable, mask)) |
| 855 | return; /*done */ |
| 856 | |
| 857 | /* |
| 858 | * The spec allows a window, but currently there are no valid |
| 859 | * events for a window, so do nothing. |
| 860 | */ |
| 861 | if (XGetWindowAttributes(dpy, drawable, &xwattr)) |
| 862 | return; /*done */ |
| 863 | /* The drawable seems to be invalid. Report an error. */ |
| 864 | |
| 865 | __glXSendError(dpy, GLXBadDrawable, drawable, |
| 866 | X_GLXChangeDrawableAttributes, false); |
| 867 | #else |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 868 | CARD32 attribs[2]; |
| 869 | |
| 870 | attribs[0] = (CARD32) GLX_EVENT_MASK; |
| 871 | attribs[1] = (CARD32) mask; |
| 872 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 873 | ChangeDrawableAttribute(dpy, drawable, attribs, 1); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 874 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | |
| 878 | /** |
| 879 | * Get the selected event mask for a drawable. |
| 880 | */ |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 881 | _X_EXPORT void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 882 | glXGetSelectedEvent(Display * dpy, GLXDrawable drawable, unsigned long *mask) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 883 | { |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 884 | #ifdef GLX_USE_APPLEGL |
| 885 | XWindowAttributes xwattr; |
| 886 | |
| 887 | if (apple_glx_pbuffer_get_event_mask(drawable, mask)) |
| 888 | return; /*done */ |
| 889 | |
| 890 | /* |
| 891 | * The spec allows a window, but currently there are no valid |
| 892 | * events for a window, so do nothing, but set the mask to 0. |
| 893 | */ |
| 894 | if (XGetWindowAttributes(dpy, drawable, &xwattr)) { |
| 895 | /* The window is valid, so set the mask to 0. */ |
| 896 | *mask = 0; |
| 897 | return; /*done */ |
| 898 | } |
| 899 | /* The drawable seems to be invalid. Report an error. */ |
| 900 | |
| 901 | __glXSendError(dpy, GLXBadDrawable, drawable, X_GLXGetDrawableAttributes, |
| 902 | true); |
| 903 | #else |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 904 | unsigned int value; |
| 905 | |
| 906 | |
| 907 | /* The non-sense with value is required because on LP64 platforms |
| 908 | * sizeof(unsigned int) != sizeof(unsigned long). On little-endian |
| 909 | * we could just type-cast the pointer, but why? |
| 910 | */ |
| 911 | |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 912 | GetDrawableAttribute(dpy, drawable, GLX_EVENT_MASK_SGIX, &value); |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 913 | *mask = value; |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 914 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 918 | _X_EXPORT GLXPixmap |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 919 | glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap, |
| 920 | const int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 921 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 922 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 923 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 924 | #ifdef GLX_USE_APPLEGL |
Jeremy Huddleston | bb621cb | 2011-06-05 17:02:33 -0400 | [diff] [blame] | 925 | const struct glx_config *modes = (const struct glx_config *) config; |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 926 | |
| 927 | if (apple_glx_pixmap_create(dpy, modes->screen, pixmap, modes)) |
| 928 | return None; |
| 929 | |
| 930 | return pixmap; |
| 931 | #else |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 932 | return CreateDrawable(dpy, (struct glx_config *) config, |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 933 | (Drawable) pixmap, attrib_list, X_GLXCreatePixmap); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 934 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 938 | _X_EXPORT GLXWindow |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 939 | glXCreateWindow(Display * dpy, GLXFBConfig config, Window win, |
| 940 | const int *attrib_list) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 941 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 942 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 943 | #ifdef GLX_USE_APPLEGL |
| 944 | XWindowAttributes xwattr; |
| 945 | XVisualInfo *visinfo; |
Ian Romanick | 1f309c4 | 2009-09-15 13:12:22 -0700 | [diff] [blame] | 946 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 947 | (void) attrib_list; /*unused according to GLX 1.4 */ |
| 948 | |
| 949 | XGetWindowAttributes(dpy, win, &xwattr); |
| 950 | |
| 951 | visinfo = glXGetVisualFromFBConfig(dpy, config); |
| 952 | |
| 953 | if (NULL == visinfo) { |
| 954 | __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateWindow, false); |
| 955 | return None; |
| 956 | } |
| 957 | |
| 958 | if (visinfo->visualid != XVisualIDFromVisual(xwattr.visual)) { |
| 959 | __glXSendError(dpy, BadMatch, 0, X_GLXCreateWindow, true); |
| 960 | return None; |
| 961 | } |
| 962 | |
Matt Turner | 7c7b7b0 | 2012-09-04 22:52:36 -0700 | [diff] [blame] | 963 | free(visinfo); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 964 | |
| 965 | return win; |
| 966 | #else |
Kristian Høgsberg | 6ddf66e | 2010-07-28 10:07:52 -0400 | [diff] [blame] | 967 | return CreateDrawable(dpy, (struct glx_config *) config, |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 968 | (Drawable) win, attrib_list, X_GLXCreateWindow); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 969 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 973 | _X_EXPORT void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 974 | glXDestroyPixmap(Display * dpy, GLXPixmap pixmap) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 975 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 976 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 977 | #ifdef GLX_USE_APPLEGL |
| 978 | if (apple_glx_pixmap_destroy(dpy, pixmap)) |
| 979 | __glXSendError(dpy, GLXBadPixmap, pixmap, X_GLXDestroyPixmap, false); |
| 980 | #else |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 981 | DestroyDrawable(dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 982 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 986 | _X_EXPORT void |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 987 | glXDestroyWindow(Display * dpy, GLXWindow win) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 988 | { |
Tormod Volden | e857303 | 2009-09-20 20:20:01 +0200 | [diff] [blame] | 989 | WARN_ONCE_GLX_1_3(dpy, __func__); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 990 | #ifndef GLX_USE_APPLEGL |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 991 | DestroyDrawable(dpy, (GLXDrawable) win, X_GLXDestroyWindow); |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 992 | #endif |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 995 | #ifndef GLX_USE_APPLEGL |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 996 | _X_EXPORT |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 997 | GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX, |
| 998 | (Display * dpy, GLXPbufferSGIX pbuf), |
| 999 | (dpy, pbuf), glXDestroyPbuffer) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1000 | |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 1001 | _X_EXPORT |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 1002 | GLX_ALIAS_VOID(glXSelectEventSGIX, |
| 1003 | (Display * dpy, GLXDrawable drawable, |
RALOVICH, Kristóf | 0896268 | 2009-08-12 12:41:22 +0200 | [diff] [blame] | 1004 | unsigned long mask), (dpy, drawable, mask), glXSelectEvent) |
Adam Jackson | cb3610e | 2004-10-25 21:09:16 +0000 | [diff] [blame] | 1005 | |
Kristian Høgsberg | 38c51a7 | 2010-07-28 10:20:41 -0400 | [diff] [blame] | 1006 | _X_EXPORT |
RALOVICH, Kristóf | 2d4c26b | 2008-10-13 14:12:02 +0200 | [diff] [blame] | 1007 | GLX_ALIAS_VOID(glXGetSelectedEventSGIX, |
| 1008 | (Display * dpy, GLXDrawable drawable, |
| 1009 | unsigned long *mask), (dpy, drawable, mask), |
| 1010 | glXGetSelectedEvent) |
Jeremy Huddleston | ad503c4 | 2010-04-01 11:01:31 -0700 | [diff] [blame] | 1011 | #endif |