blob: 34892e8b1a2bcb34573dbfbc1651254a30c05066 [file] [log] [blame]
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001/*
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óf08962682009-08-12 12:41:22 +020028 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +000029 * \author Ian Romanick <idr@us.ibm.com>
30 */
31
32#include <inttypes.h>
33#include "glxclient.h"
Brian Paul82dfd4b2005-08-11 14:18:53 +000034#include <X11/extensions/extutil.h>
35#include <X11/extensions/Xext.h>
Adam Jacksoncb3610e2004-10-25 21:09:16 +000036#include <assert.h>
37#include <string.h>
Adam Jacksoncb3610e2004-10-25 21:09:16 +000038#include "glxextensions.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000039
Jeremy Huddlestonad503c42010-04-01 11:01:31 -070040#ifdef GLX_USE_APPLEGL
41#include <pthread.h>
42#include "apple_glx_drawable.h"
43#include "glx_error.h"
44#endif
45
Tormod Voldene8573032009-09-20 20:20:01 +020046#define WARN_ONCE_GLX_1_3(a, b) { \
47 static int warned=1; \
48 if(warned) { \
49 warn_GLX_1_3((a), b ); \
50 warned=0; \
51 } \
52 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +000053
54/**
Ian Romanick1f309c42009-09-15 13:12:22 -070055 * Emit a warning when clients use GLX 1.3 functions on pre-1.3 systems.
56 */
57static void
Jeremy Huddlestonad503c42010-04-01 11:01:31 -070058warn_GLX_1_3(Display * dpy, const char *function_name)
Ian Romanick1f309c42009-09-15 13:12:22 -070059{
Kristian Høgsbergc356f582010-07-28 11:16:00 -040060 struct glx_display *priv = __glXInitialize(dpy);
Ian Romanick1f309c42009-09-15 13:12:22 -070061
62 if (priv->minorVersion < 3) {
Jeremy Huddlestonad503c42010-04-01 11:01:31 -070063 fprintf(stderr,
64 "WARNING: Application calling GLX 1.3 function \"%s\" "
65 "when GLX 1.3 is not supported! This is an application bug!\n",
66 function_name);
Ian Romanick1f309c42009-09-15 13:12:22 -070067 }
68}
69
Jeremy Huddlestonad503c42010-04-01 11:01:31 -070070#ifndef GLX_USE_APPLEGL
Ian Romanick1f309c42009-09-15 13:12:22 -070071/**
Adam Jacksoncb3610e2004-10-25 21:09:16 +000072 * Change a drawable's attribute.
73 *
74 * This function is used to implement \c glXSelectEvent and
75 * \c glXSelectEventSGIX.
76 *
77 * \note
78 * This function dynamically determines whether to use the SGIX_pbuffer
79 * version of the protocol or the GLX 1.3 version of the protocol.
80 *
81 * \todo
82 * This function needs to be modified to work with direct-rendering drivers.
83 */
84static void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +020085ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
86 const CARD32 * attribs, size_t num_attribs)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000087{
Kristian Høgsbergc356f582010-07-28 11:16:00 -040088 struct glx_display *priv = __glXInitialize(dpy);
Jon TURNEYae9487c2010-08-09 14:47:26 +010089#ifdef GLX_DIRECT_RENDERING
Vinson Lee5c9e54f2010-07-15 00:20:41 -070090 __GLXDRIdrawable *pdraw;
Jon TURNEYae9487c2010-08-09 14:47:26 +010091#endif
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +020092 CARD32 *output;
Kristian Høgsbergc25eb992006-06-13 01:41:18 +000093 CARD8 opcode;
Nick Bowlerf8d81c32010-07-14 12:01:49 -040094 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000095
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +020096 if ((dpy == NULL) || (drawable == 0)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +000097 return;
98 }
99
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000100 opcode = __glXSetupForCommand(dpy);
101 if (!opcode)
102 return;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000103
104 LockDisplay(dpy);
105
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200106 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000107 xGLXChangeDrawableAttributesReq *req;
108
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200109 GetReqExtra(GLXChangeDrawableAttributes, 8 + (8 * num_attribs), req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000110 output = (CARD32 *) (req + 1);
111
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000112 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000113 req->glxCode = X_GLXChangeDrawableAttributes;
114 req->drawable = drawable;
115 req->numAttribs = (CARD32) num_attribs;
116 }
117 else {
118 xGLXVendorPrivateWithReplyReq *vpreq;
119
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200120 GetReqExtra(GLXVendorPrivateWithReply, 4 + (8 * num_attribs), vpreq);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000121 output = (CARD32 *) (vpreq + 1);
122
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000123 vpreq->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000124 vpreq->glxCode = X_GLXVendorPrivateWithReply;
125 vpreq->vendorCode = X_GLXvop_ChangeDrawableAttributesSGIX;
126
127 output[0] = (CARD32) drawable;
128 output++;
129 }
130
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200131 (void) memcpy(output, attribs, sizeof(CARD32) * 2 * num_attribs);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000132
133 UnlockDisplay(dpy);
134 SyncHandle();
135
Jon TURNEYae9487c2010-08-09 14:47:26 +0100136#ifdef GLX_DIRECT_RENDERING
137 pdraw = GetGLXDRIDrawable(dpy, drawable);
138
Nick Bowlerf8d81c32010-07-14 12:01:49 -0400139 for (i = 0; i < num_attribs; i++) {
140 switch(attribs[i * 2]) {
141 case GLX_EVENT_MASK:
142 /* Keep a local copy for masking out DRI2 proto events as needed */
143 pdraw->eventMask = attribs[i * 2 + 1];
144 break;
145 }
146 }
Jon TURNEYae9487c2010-08-09 14:47:26 +0100147#endif
Nick Bowlerf8d81c32010-07-14 12:01:49 -0400148
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000149 return;
150}
151
152
Michel Dänzer236355102008-04-10 15:45:52 -0400153#ifdef GLX_DIRECT_RENDERING
Michel Dänzer236355102008-04-10 15:45:52 -0400154static GLenum
155determineTextureTarget(const int *attribs, int numAttribs)
156{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200157 GLenum target = 0;
158 int i;
Michel Dänzer236355102008-04-10 15:45:52 -0400159
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200160 for (i = 0; i < numAttribs; i++) {
161 if (attribs[2 * i] == GLX_TEXTURE_TARGET_EXT) {
162 switch (attribs[2 * i + 1]) {
163 case GLX_TEXTURE_2D_EXT:
164 target = GL_TEXTURE_2D;
165 break;
166 case GLX_TEXTURE_RECTANGLE_EXT:
167 target = GL_TEXTURE_RECTANGLE_ARB;
168 break;
169 }
170 }
171 }
172
173 return target;
Michel Dänzer236355102008-04-10 15:45:52 -0400174}
Eric Anholt66175aa2009-03-18 12:07:09 -0700175
Eric Anholt66175aa2009-03-18 12:07:09 -0700176static GLenum
177determineTextureFormat(const int *attribs, int numAttribs)
178{
Eric Anholt66175aa2009-03-18 12:07:09 -0700179 int i;
180
181 for (i = 0; i < numAttribs; i++) {
182 if (attribs[2 * i] == GLX_TEXTURE_FORMAT_EXT)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200183 return attribs[2 * i + 1];
Eric Anholt66175aa2009-03-18 12:07:09 -0700184 }
185
186 return 0;
187}
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400188
189static void
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400190CreateDRIDrawable(Display *dpy, struct glx_config *config,
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400191 XID drawable, XID glxdrawable,
192 const int *attrib_list, size_t num_attribs)
193{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400194 struct glx_display *const priv = __glXInitialize(dpy);
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400195 __GLXDRIdrawable *pdraw;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400196 struct glx_screen *psc;
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400197
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400198 psc = priv->screens[config->screen];
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400199 if (psc->driScreen == NULL)
200 return;
201
202 pdraw = psc->driScreen->createDrawable(psc, drawable,
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400203 glxdrawable, config);
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400204 if (pdraw == NULL) {
205 fprintf(stderr, "failed to create drawable\n");
206 return;
207 }
208
Kristian Høgsberge3e81962010-07-19 21:15:50 -0400209 if (__glxHashInsert(priv->drawHash, glxdrawable, pdraw)) {
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400210 (*pdraw->destroyDrawable) (pdraw);
211 return; /* FIXME: Check what we're supposed to do here... */
212 }
213
214 pdraw->textureTarget = determineTextureTarget(attrib_list, num_attribs);
215 pdraw->textureFormat = determineTextureFormat(attrib_list, num_attribs);
216}
217
218static void
219DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable)
220{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400221 struct glx_display *const priv = __glXInitialize(dpy);
Kristian Høgsbergeeaab202010-07-22 22:36:37 -0400222 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Kristian Høgsberg80e48dd2010-09-09 08:06:40 -0400223 XID xid;
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400224
225 if (pdraw != NULL) {
Kristian Høgsberg80e48dd2010-09-09 08:06:40 -0400226 xid = pdraw->xDrawable;
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400227 (*pdraw->destroyDrawable) (pdraw);
Kristian Høgsberge3e81962010-07-19 21:15:50 -0400228 __glxHashDelete(priv->drawHash, drawable);
Kristian Høgsbergd8ab9aa2010-09-08 20:55:02 -0400229 if (destroy_xdrawable)
Kristian Høgsberg80e48dd2010-09-09 08:06:40 -0400230 XFreePixmap(priv->dpy, xid);
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400231 }
232}
233
234#else
235
236static void
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400237CreateDRIDrawable(Display *dpy, const struct glx_config * fbconfig,
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400238 XID drawable, XID glxdrawable,
239 const int *attrib_list, size_t num_attribs)
240{
241}
242
243static void
244DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable)
245{
246}
247
Michel Dänzer236355102008-04-10 15:45:52 -0400248#endif
249
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000250/**
251 * Get a drawable's attribute.
252 *
253 * This function is used to implement \c glXGetSelectedEvent and
254 * \c glXGetSelectedEventSGIX.
255 *
256 * \note
257 * This function dynamically determines whether to use the SGIX_pbuffer
258 * version of the protocol or the GLX 1.3 version of the protocol.
259 *
260 * \todo
261 * The number of attributes returned is likely to be small, probably less than
262 * 10. Given that, this routine should try to use an array on the stack to
263 * capture the reply rather than always calling Xmalloc.
264 *
265 * \todo
266 * This function needs to be modified to work with direct-rendering drivers.
267 */
268static int
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200269GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
270 int attribute, unsigned int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000271{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400272 struct glx_display *priv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000273 xGLXGetDrawableAttributesReply reply;
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200274 CARD32 *data;
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000275 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000276 unsigned int length;
277 unsigned int i;
278 unsigned int num_attributes;
Owain G. Ainsworthb4866f82009-01-11 20:40:07 +0000279 GLboolean use_glx_1_3;
Adam Jacksond25ad502006-04-07 00:05:50 +0000280
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200281 if ((dpy == NULL) || (drawable == 0)) {
Adam Jacksond25ad502006-04-07 00:05:50 +0000282 return 0;
283 }
284
285 priv = __glXInitialize(dpy);
Owain G. Ainsworthb4866f82009-01-11 20:40:07 +0000286 use_glx_1_3 = ((priv->majorVersion > 1) || (priv->minorVersion >= 3));
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000287
Brian Paul42725d62006-02-07 00:39:56 +0000288 *value = 0;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000289
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000290
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000291 opcode = __glXSetupForCommand(dpy);
292 if (!opcode)
293 return 0;
294
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000295 LockDisplay(dpy);
296
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200297 if (use_glx_1_3) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000298 xGLXGetDrawableAttributesReq *req;
299
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200300 GetReqExtra(GLXGetDrawableAttributes, 4, req);
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000301 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000302 req->glxCode = X_GLXGetDrawableAttributes;
303 req->drawable = drawable;
304 }
305 else {
306 xGLXVendorPrivateWithReplyReq *vpreq;
307
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200308 GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000309 data = (CARD32 *) (vpreq + 1);
310 data[0] = (CARD32) drawable;
311
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000312 vpreq->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000313 vpreq->glxCode = X_GLXVendorPrivateWithReply;
314 vpreq->vendorCode = X_GLXvop_GetDrawableAttributesSGIX;
315 }
316
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200317 _XReply(dpy, (xReply *) & reply, 0, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000318
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200319 if (reply.type == X_Error) {
320 UnlockDisplay(dpy);
321 SyncHandle();
322 return 0;
Brian Paul42725d62006-02-07 00:39:56 +0000323 }
324
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000325 length = reply.length;
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200326 if (length) {
327 num_attributes = (use_glx_1_3) ? reply.numAttribs : length / 2;
328 data = (CARD32 *) Xmalloc(length * sizeof(CARD32));
329 if (data == NULL) {
330 /* Throw data on the floor */
331 _XEatData(dpy, length);
332 }
333 else {
334 _XRead(dpy, (char *) data, length * sizeof(CARD32));
Brian Paul42725d62006-02-07 00:39:56 +0000335
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200336 /* Search the set of returned attributes for the attribute requested by
337 * the caller.
338 */
339 for (i = 0; i < num_attributes; i++) {
340 if (data[i * 2] == attribute) {
341 *value = data[(i * 2) + 1];
342 break;
343 }
344 }
Brian Paul42725d62006-02-07 00:39:56 +0000345
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700346#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200347 {
Kristian Høgsbergeeaab202010-07-22 22:36:37 -0400348 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Michel Dänzer236355102008-04-10 15:45:52 -0400349
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200350 if (pdraw != NULL && !pdraw->textureTarget)
351 pdraw->textureTarget =
352 determineTextureTarget((const int *) data, num_attributes);
Eric Anholt66175aa2009-03-18 12:07:09 -0700353 if (pdraw != NULL && !pdraw->textureFormat)
354 pdraw->textureFormat =
355 determineTextureFormat((const int *) data, num_attributes);
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200356 }
Michel Dänzer236355102008-04-10 15:45:52 -0400357#endif
358
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200359 Xfree(data);
360 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000361 }
362
363 UnlockDisplay(dpy);
364 SyncHandle();
365
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000366 return 0;
367}
368
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000369/**
370 * Create a non-pbuffer GLX drawable.
371 *
372 * \todo
373 * This function needs to be modified to work with direct-rendering drivers.
374 */
375static GLXDrawable
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400376CreateDrawable(Display *dpy, struct glx_config *config,
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200377 Drawable drawable, const int *attrib_list, CARD8 glxCode)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000378{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200379 xGLXCreateWindowReq *req;
380 CARD32 *data;
Ian Romanickb47731f2005-03-04 17:53:24 +0000381 unsigned int i;
David Reveman342d1de2006-04-11 12:07:41 +0000382 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000383
Ian Romanickb47731f2005-03-04 17:53:24 +0000384 i = 0;
385 if (attrib_list) {
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200386 while (attrib_list[i * 2] != None)
387 i++;
Ian Romanickb47731f2005-03-04 17:53:24 +0000388 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000389
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000390 opcode = __glXSetupForCommand(dpy);
391 if (!opcode)
392 return None;
David Reveman342d1de2006-04-11 12:07:41 +0000393
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000394 LockDisplay(dpy);
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200395 GetReqExtra(GLXCreateWindow, 8 * i, req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000396 data = (CARD32 *) (req + 1);
397
David Reveman342d1de2006-04-11 12:07:41 +0000398 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000399 req->glxCode = glxCode;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400400 req->screen = config->screen;
401 req->fbconfig = config->fbconfigID;
402 req->window = drawable;
403 req->glxwindow = XAllocID(dpy);
404 req->numAttribs = i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000405
Brian Paul5f40a7a2010-03-02 07:34:29 -0700406 if (attrib_list)
407 memcpy(data, attrib_list, 8 * i);
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200408
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000409 UnlockDisplay(dpy);
410 SyncHandle();
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200411
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400412 CreateDRIDrawable(dpy, config, drawable, req->glxwindow, attrib_list, i);
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400413
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400414 return req->glxwindow;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000415}
416
417
418/**
419 * Destroy a non-pbuffer GLX drawable.
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000420 */
421static void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200422DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000423{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200424 xGLXDestroyPbufferReq *req;
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000425 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000426
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200427 if ((dpy == NULL) || (drawable == 0)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000428 return;
429 }
430
431
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000432 opcode = __glXSetupForCommand(dpy);
433 if (!opcode)
434 return;
435
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000436 LockDisplay(dpy);
437
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200438 GetReqExtra(GLXDestroyPbuffer, 4, req);
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000439 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000440 req->glxCode = glxCode;
441 req->pbuffer = (GLXPbuffer) drawable;
442
443 UnlockDisplay(dpy);
444 SyncHandle();
445
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400446 DestroyDRIDrawable(dpy, drawable, GL_FALSE);
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400447
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000448 return;
449}
450
451
452/**
453 * Create a pbuffer.
454 *
455 * This function is used to implement \c glXCreatePbuffer and
456 * \c glXCreateGLXPbufferSGIX.
457 *
458 * \note
459 * This function dynamically determines whether to use the SGIX_pbuffer
460 * version of the protocol or the GLX 1.3 version of the protocol.
461 *
462 * \todo
463 * This function needs to be modified to work with direct-rendering drivers.
464 */
465static GLXDrawable
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400466CreatePbuffer(Display * dpy, struct glx_config *config,
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200467 unsigned int width, unsigned int height,
468 const int *attrib_list, GLboolean size_in_attribs)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000469{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400470 struct glx_display *priv = __glXInitialize(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000471 GLXDrawable id = 0;
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200472 CARD32 *data;
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000473 CARD8 opcode;
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200474 unsigned int i;
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400475 Pixmap pixmap;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000476
Ian Romanickb47731f2005-03-04 17:53:24 +0000477 i = 0;
478 if (attrib_list) {
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200479 while (attrib_list[i * 2])
480 i++;
Ian Romanickb47731f2005-03-04 17:53:24 +0000481 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000482
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000483 opcode = __glXSetupForCommand(dpy);
484 if (!opcode)
485 return None;
486
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000487 LockDisplay(dpy);
488 id = XAllocID(dpy);
489
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200490 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
491 xGLXCreatePbufferReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000492 unsigned int extra = (size_in_attribs) ? 0 : 2;
493
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200494 GetReqExtra(GLXCreatePbuffer, (8 * (i + extra)), req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000495 data = (CARD32 *) (req + 1);
496
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000497 req->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000498 req->glxCode = X_GLXCreatePbuffer;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400499 req->screen = config->screen;
500 req->fbconfig = config->fbconfigID;
501 req->pbuffer = id;
502 req->numAttribs = i + extra;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000503
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200504 if (!size_in_attribs) {
505 data[(2 * i) + 0] = GLX_PBUFFER_WIDTH;
506 data[(2 * i) + 1] = width;
507 data[(2 * i) + 2] = GLX_PBUFFER_HEIGHT;
508 data[(2 * i) + 3] = height;
509 data += 4;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000510 }
511 }
512 else {
513 xGLXVendorPrivateReq *vpreq;
514
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200515 GetReqExtra(GLXVendorPrivate, 20 + (8 * i), vpreq);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000516 data = (CARD32 *) (vpreq + 1);
517
Kristian Høgsbergc25eb992006-06-13 01:41:18 +0000518 vpreq->reqType = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000519 vpreq->glxCode = X_GLXVendorPrivate;
520 vpreq->vendorCode = X_GLXvop_CreateGLXPbufferSGIX;
521
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400522 data[0] = config->screen;
523 data[1] = config->fbconfigID;
524 data[2] = id;
525 data[3] = width;
526 data[4] = height;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000527 data += 5;
528 }
529
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200530 (void) memcpy(data, attrib_list, sizeof(CARD32) * 2 * i);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000531
532 UnlockDisplay(dpy);
533 SyncHandle();
534
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400535 pixmap = XCreatePixmap(dpy, RootWindow(dpy, config->screen),
536 width, height, config->rgbBits);
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400537
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400538 CreateDRIDrawable(dpy, config, pixmap, id, attrib_list, i);
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400539
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000540 return id;
541}
542
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400543/**
544 * Destroy a pbuffer.
545 *
546 * This function is used to implement \c glXDestroyPbuffer and
547 * \c glXDestroyGLXPbufferSGIX.
548 *
549 * \note
550 * This function dynamically determines whether to use the SGIX_pbuffer
551 * version of the protocol or the GLX 1.3 version of the protocol.
552 */
553static void
554DestroyPbuffer(Display * dpy, GLXDrawable drawable)
555{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400556 struct glx_display *priv = __glXInitialize(dpy);
Kristian Høgsberg5a43dba2010-04-09 17:16:33 -0400557 CARD8 opcode;
558
559 if ((dpy == NULL) || (drawable == 0)) {
560 return;
561 }
562
563 opcode = __glXSetupForCommand(dpy);
564 if (!opcode)
565 return;
566
567 LockDisplay(dpy);
568
569 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
570 xGLXDestroyPbufferReq *req;
571
572 GetReq(GLXDestroyPbuffer, req);
573 req->reqType = opcode;
574 req->glxCode = X_GLXDestroyPbuffer;
575 req->pbuffer = (GLXPbuffer) drawable;
576 }
577 else {
578 xGLXVendorPrivateWithReplyReq *vpreq;
579 CARD32 *data;
580
581 GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq);
582 data = (CARD32 *) (vpreq + 1);
583
584 data[0] = (CARD32) drawable;
585
586 vpreq->reqType = opcode;
587 vpreq->glxCode = X_GLXVendorPrivateWithReply;
588 vpreq->vendorCode = X_GLXvop_DestroyGLXPbufferSGIX;
589 }
590
591 UnlockDisplay(dpy);
592 SyncHandle();
593
594 DestroyDRIDrawable(dpy, drawable, GL_TRUE);
595
596 return;
597}
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000598
599/**
600 * Create a new pbuffer.
601 */
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400602_X_EXPORT GLXPbufferSGIX
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200603glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config,
604 unsigned int width, unsigned int height,
605 int *attrib_list)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000606{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400607 return (GLXPbufferSGIX) CreatePbuffer(dpy, (struct glx_config *) config,
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200608 width, height,
609 attrib_list, GL_FALSE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000610}
611
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700612#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000613
614/**
615 * Create a new pbuffer.
616 */
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400617_X_EXPORT GLXPbuffer
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200618glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000619{
Kristian Høgsberg8b204112007-08-27 14:16:30 -0400620 int i, width, height;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700621#ifdef GLX_USE_APPLEGL
622 GLXPbuffer result;
623 int errorcode;
624#endif
Kristian Høgsberg8b204112007-08-27 14:16:30 -0400625
626 width = 0;
627 height = 0;
628
Tormod Voldene8573032009-09-20 20:20:01 +0200629 WARN_ONCE_GLX_1_3(dpy, __func__);
Ian Romanick1f309c42009-09-15 13:12:22 -0700630
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700631#ifdef GLX_USE_APPLEGL
632 for (i = 0; attrib_list[i]; ++i) {
633 switch (attrib_list[i]) {
634 case GLX_PBUFFER_WIDTH:
635 width = attrib_list[i + 1];
636 ++i;
637 break;
638
639 case GLX_PBUFFER_HEIGHT:
640 height = attrib_list[i + 1];
641 ++i;
642 break;
643
644 case GLX_LARGEST_PBUFFER:
645 /* This is a hint we should probably handle, but how? */
646 ++i;
647 break;
648
649 case GLX_PRESERVED_CONTENTS:
650 /* The contents are always preserved with AppleSGLX with CGL. */
651 ++i;
652 break;
653
654 default:
655 return None;
656 }
657 }
658
659 if (apple_glx_pbuffer_create(dpy, config, width, height, &errorcode,
660 &result)) {
661 /*
662 * apple_glx_pbuffer_create only sets the errorcode to core X11
663 * errors.
664 */
665 __glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true);
666
667 return None;
668 }
669
670 return result;
671#else
Kristian Høgsberg8b204112007-08-27 14:16:30 -0400672 for (i = 0; attrib_list[i * 2]; i++) {
673 switch (attrib_list[i * 2]) {
674 case GLX_PBUFFER_WIDTH:
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200675 width = attrib_list[i * 2 + 1];
676 break;
Kristian Høgsberg8b204112007-08-27 14:16:30 -0400677 case GLX_PBUFFER_HEIGHT:
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200678 height = attrib_list[i * 2 + 1];
679 break;
Kristian Høgsberg8b204112007-08-27 14:16:30 -0400680 }
681 }
682
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400683 return (GLXPbuffer) CreatePbuffer(dpy, (struct glx_config *) config,
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200684 width, height, attrib_list, GL_TRUE);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700685#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000686}
687
688
689/**
690 * Destroy an existing pbuffer.
691 */
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400692_X_EXPORT void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200693glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000694{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700695#ifdef GLX_USE_APPLEGL
696 if (apple_glx_pbuffer_destroy(dpy, pbuf)) {
697 __glXSendError(dpy, GLXBadPbuffer, pbuf, X_GLXDestroyPbuffer, false);
698 }
699#else
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200700 DestroyPbuffer(dpy, pbuf);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700701#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000702}
703
704
705/**
706 * Query an attribute of a drawable.
707 */
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400708_X_EXPORT void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200709glXQueryDrawable(Display * dpy, GLXDrawable drawable,
710 int attribute, unsigned int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000711{
Tormod Voldene8573032009-09-20 20:20:01 +0200712 WARN_ONCE_GLX_1_3(dpy, __func__);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700713#ifdef GLX_USE_APPLEGL
714 Window root;
715 int x, y;
716 unsigned int width, height, bd, depth;
717
718 if (apple_glx_pixmap_query(drawable, attribute, value))
719 return; /*done */
720
721 if (apple_glx_pbuffer_query(drawable, attribute, value))
722 return; /*done */
723
724 /*
725 * The OpenGL spec states that we should report GLXBadDrawable if
726 * the drawable is invalid, however doing so would require that we
727 * use XSetErrorHandler(), which is known to not be thread safe.
728 * If we use a round-trip call to validate the drawable, there could
729 * be a race, so instead we just opt in favor of letting the
730 * XGetGeometry request fail with a GetGeometry request X error
731 * rather than GLXBadDrawable, in what is hoped to be a rare
732 * case of an invalid drawable. In practice most and possibly all
733 * X11 apps using GLX shouldn't notice a difference.
734 */
735 if (XGetGeometry
736 (dpy, drawable, &root, &x, &y, &width, &height, &bd, &depth)) {
737 switch (attribute) {
738 case GLX_WIDTH:
739 *value = width;
740 break;
741
742 case GLX_HEIGHT:
743 *value = height;
744 break;
745 }
746 }
747#else
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200748 GetDrawableAttribute(dpy, drawable, attribute, value);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700749#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000750}
751
752
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700753#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000754/**
755 * Query an attribute of a pbuffer.
756 */
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400757_X_EXPORT int
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200758glXQueryGLXPbufferSGIX(Display * dpy, GLXPbufferSGIX drawable,
759 int attribute, unsigned int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000760{
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200761 return GetDrawableAttribute(dpy, drawable, attribute, value);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000762}
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700763#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000764
765/**
766 * Select the event mask for a drawable.
767 */
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400768_X_EXPORT void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200769glXSelectEvent(Display * dpy, GLXDrawable drawable, unsigned long mask)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000770{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700771#ifdef GLX_USE_APPLEGL
772 XWindowAttributes xwattr;
773
774 if (apple_glx_pbuffer_set_event_mask(drawable, mask))
775 return; /*done */
776
777 /*
778 * The spec allows a window, but currently there are no valid
779 * events for a window, so do nothing.
780 */
781 if (XGetWindowAttributes(dpy, drawable, &xwattr))
782 return; /*done */
783 /* The drawable seems to be invalid. Report an error. */
784
785 __glXSendError(dpy, GLXBadDrawable, drawable,
786 X_GLXChangeDrawableAttributes, false);
787#else
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000788 CARD32 attribs[2];
789
790 attribs[0] = (CARD32) GLX_EVENT_MASK;
791 attribs[1] = (CARD32) mask;
792
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200793 ChangeDrawableAttribute(dpy, drawable, attribs, 1);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700794#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000795}
796
797
798/**
799 * Get the selected event mask for a drawable.
800 */
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400801_X_EXPORT void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200802glXGetSelectedEvent(Display * dpy, GLXDrawable drawable, unsigned long *mask)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000803{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700804#ifdef GLX_USE_APPLEGL
805 XWindowAttributes xwattr;
806
807 if (apple_glx_pbuffer_get_event_mask(drawable, mask))
808 return; /*done */
809
810 /*
811 * The spec allows a window, but currently there are no valid
812 * events for a window, so do nothing, but set the mask to 0.
813 */
814 if (XGetWindowAttributes(dpy, drawable, &xwattr)) {
815 /* The window is valid, so set the mask to 0. */
816 *mask = 0;
817 return; /*done */
818 }
819 /* The drawable seems to be invalid. Report an error. */
820
821 __glXSendError(dpy, GLXBadDrawable, drawable, X_GLXGetDrawableAttributes,
822 true);
823#else
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000824 unsigned int value;
825
826
827 /* The non-sense with value is required because on LP64 platforms
828 * sizeof(unsigned int) != sizeof(unsigned long). On little-endian
829 * we could just type-cast the pointer, but why?
830 */
831
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200832 GetDrawableAttribute(dpy, drawable, GLX_EVENT_MASK_SGIX, &value);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000833 *mask = value;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700834#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000835}
836
837
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400838_X_EXPORT GLXPixmap
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200839glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap,
840 const int *attrib_list)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000841{
Tormod Voldene8573032009-09-20 20:20:01 +0200842 WARN_ONCE_GLX_1_3(dpy, __func__);
Ian Romanick1f309c42009-09-15 13:12:22 -0700843
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700844#ifdef GLX_USE_APPLEGL
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400845 const struct glx_config *modes = (const __GLcontextModes *) config;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700846
847 if (apple_glx_pixmap_create(dpy, modes->screen, pixmap, modes))
848 return None;
849
850 return pixmap;
851#else
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400852 return CreateDrawable(dpy, (struct glx_config *) config,
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200853 (Drawable) pixmap, attrib_list, X_GLXCreatePixmap);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700854#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000855}
856
857
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400858_X_EXPORT GLXWindow
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200859glXCreateWindow(Display * dpy, GLXFBConfig config, Window win,
860 const int *attrib_list)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000861{
Tormod Voldene8573032009-09-20 20:20:01 +0200862 WARN_ONCE_GLX_1_3(dpy, __func__);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700863#ifdef GLX_USE_APPLEGL
864 XWindowAttributes xwattr;
865 XVisualInfo *visinfo;
Ian Romanick1f309c42009-09-15 13:12:22 -0700866
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700867 (void) attrib_list; /*unused according to GLX 1.4 */
868
869 XGetWindowAttributes(dpy, win, &xwattr);
870
871 visinfo = glXGetVisualFromFBConfig(dpy, config);
872
873 if (NULL == visinfo) {
874 __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateWindow, false);
875 return None;
876 }
877
878 if (visinfo->visualid != XVisualIDFromVisual(xwattr.visual)) {
879 __glXSendError(dpy, BadMatch, 0, X_GLXCreateWindow, true);
880 return None;
881 }
882
883 XFree(visinfo);
884
885 return win;
886#else
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400887 return CreateDrawable(dpy, (struct glx_config *) config,
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200888 (Drawable) win, attrib_list, X_GLXCreateWindow);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700889#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000890}
891
892
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400893_X_EXPORT void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200894glXDestroyPixmap(Display * dpy, GLXPixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000895{
Tormod Voldene8573032009-09-20 20:20:01 +0200896 WARN_ONCE_GLX_1_3(dpy, __func__);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700897#ifdef GLX_USE_APPLEGL
898 if (apple_glx_pixmap_destroy(dpy, pixmap))
899 __glXSendError(dpy, GLXBadPixmap, pixmap, X_GLXDestroyPixmap, false);
900#else
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200901 DestroyDrawable(dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700902#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000903}
904
905
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400906_X_EXPORT void
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200907glXDestroyWindow(Display * dpy, GLXWindow win)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000908{
Tormod Voldene8573032009-09-20 20:20:01 +0200909 WARN_ONCE_GLX_1_3(dpy, __func__);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700910#ifndef GLX_USE_APPLEGL
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200911 DestroyDrawable(dpy, (GLXDrawable) win, X_GLXDestroyWindow);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700912#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000913}
914
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700915#ifndef GLX_USE_APPLEGL
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400916_X_EXPORT
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200917GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX,
918 (Display * dpy, GLXPbufferSGIX pbuf),
919 (dpy, pbuf), glXDestroyPbuffer)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000920
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400921_X_EXPORT
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200922GLX_ALIAS_VOID(glXSelectEventSGIX,
923 (Display * dpy, GLXDrawable drawable,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200924 unsigned long mask), (dpy, drawable, mask), glXSelectEvent)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000925
Kristian Høgsberg38c51a72010-07-28 10:20:41 -0400926_X_EXPORT
RALOVICH, Kristóf2d4c26b2008-10-13 14:12:02 +0200927GLX_ALIAS_VOID(glXGetSelectedEventSGIX,
928 (Display * dpy, GLXDrawable drawable,
929 unsigned long *mask), (dpy, drawable, mask),
930 glXGetSelectedEvent)
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700931#endif