2004-10-25 22:09:16 +01:00
|
|
|
/*
|
|
|
|
* (C) Copyright IBM Corporation 2004
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* on the rights to use, copy, modify, merge, publish, distribute, sub
|
|
|
|
* license, and/or sell copies of the Software, and to permit persons to whom
|
|
|
|
* the Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file glx_pbuffer.c
|
|
|
|
* Implementation of pbuffer related functions.
|
2009-08-12 11:41:22 +01:00
|
|
|
*
|
2004-10-25 22:09:16 +01:00
|
|
|
* \author Ian Romanick <idr@us.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include "glxclient.h"
|
2005-08-11 15:18:53 +01:00
|
|
|
#include <X11/extensions/extutil.h>
|
|
|
|
#include <X11/extensions/Xext.h>
|
2004-10-25 22:09:16 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2020-09-09 19:00:35 +01:00
|
|
|
#include <limits.h>
|
2004-10-25 22:09:16 +01:00
|
|
|
#include "glxextensions.h"
|
|
|
|
|
2021-12-13 14:07:13 +00:00
|
|
|
#include <X11/Xlib-xcb.h>
|
|
|
|
#include <xcb/xproto.h>
|
|
|
|
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifdef GLX_USE_APPLEGL
|
|
|
|
#include <pthread.h>
|
Fix build of appleglx
Define GLX_USE_APPLEGL, as config/darwin used to, to turn on specific code to
use the applegl direct renderer
Convert src/glx/apple/Makefile to automake
Since the applegl libGL is now built by linking libappleglx into libGL, rather
than by linking selected files into a special libGL:
- Remove duplicate code in apple/glxreply.c and apple/apple_glx.c. This makes
apple/glxreply.c empty, so remove it
- Some indirect rendering code is already guarded by !GLX_USE_APPLEGL, but we
need to add those guards to indirect_glx.c, indirect_init.c (via it's
generator), render2.c and vertarr.c so they don't generate anything
Fix and update various includes
glapi_gentable.c (which is only used on darwin), should be included in shared
glapi as well, to provide _glapi_create_table_from_handle()
Note that neither swrast nor indirect is supported in the APPLEGL path at the
moment, which makes things more complex than they need to be. More untangling
is needed to allow that
v2: Correct apple/Makefile.am for srcdir != builddir
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2014-05-12 10:47:07 +01:00
|
|
|
#include "apple/apple_glx_drawable.h"
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
|
|
|
|
2013-08-09 02:17:24 +01:00
|
|
|
#include "glx_error.h"
|
|
|
|
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifndef GLX_USE_APPLEGL
|
2004-10-25 22:09:16 +01:00
|
|
|
/**
|
|
|
|
* Change a drawable's attribute.
|
|
|
|
*
|
|
|
|
* This function is used to implement \c glXSelectEvent and
|
|
|
|
* \c glXSelectEventSGIX.
|
|
|
|
*
|
|
|
|
* \note
|
|
|
|
* This function dynamically determines whether to use the SGIX_pbuffer
|
|
|
|
* version of the protocol or the GLX 1.3 version of the protocol.
|
|
|
|
*/
|
|
|
|
static void
|
2021-05-03 13:38:02 +01:00
|
|
|
ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
|
2008-10-13 13:12:02 +01:00
|
|
|
const CARD32 * attribs, size_t num_attribs)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2021-05-03 13:38:02 +01:00
|
|
|
struct glx_display *priv = __glXInitialize(dpy);
|
2010-08-09 14:47:26 +01:00
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
2010-07-15 08:20:41 +01:00
|
|
|
__GLXDRIdrawable *pdraw;
|
2020-07-16 22:29:26 +01:00
|
|
|
int i;
|
2010-08-09 14:47:26 +01:00
|
|
|
#endif
|
2008-10-13 13:12:02 +01:00
|
|
|
CARD32 *output;
|
2006-06-13 02:41:18 +01:00
|
|
|
CARD8 opcode;
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2014-02-07 12:44:00 +00:00
|
|
|
if ((priv == NULL) || (dpy == NULL) || (drawable == 0)) {
|
2004-10-25 22:09:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-06-13 02:41:18 +01:00
|
|
|
opcode = __glXSetupForCommand(dpy);
|
|
|
|
if (!opcode)
|
|
|
|
return;
|
2004-10-25 22:09:16 +01:00
|
|
|
|
|
|
|
LockDisplay(dpy);
|
|
|
|
|
2021-04-22 18:10:44 +01:00
|
|
|
if (priv->minorVersion >= 3) {
|
2004-10-25 22:09:16 +01:00
|
|
|
xGLXChangeDrawableAttributesReq *req;
|
|
|
|
|
2011-01-23 16:26:35 +00:00
|
|
|
GetReqExtra(GLXChangeDrawableAttributes, 8 * num_attribs, req);
|
2004-10-25 22:09:16 +01:00
|
|
|
output = (CARD32 *) (req + 1);
|
|
|
|
|
2006-06-13 02:41:18 +01:00
|
|
|
req->reqType = opcode;
|
2004-10-25 22:09:16 +01:00
|
|
|
req->glxCode = X_GLXChangeDrawableAttributes;
|
|
|
|
req->drawable = drawable;
|
|
|
|
req->numAttribs = (CARD32) num_attribs;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xGLXVendorPrivateWithReplyReq *vpreq;
|
|
|
|
|
2011-01-26 12:03:16 +00:00
|
|
|
GetReqExtra(GLXVendorPrivateWithReply, 8 + (8 * num_attribs), vpreq);
|
2004-10-25 22:09:16 +01:00
|
|
|
output = (CARD32 *) (vpreq + 1);
|
|
|
|
|
2006-06-13 02:41:18 +01:00
|
|
|
vpreq->reqType = opcode;
|
2004-10-25 22:09:16 +01:00
|
|
|
vpreq->glxCode = X_GLXVendorPrivateWithReply;
|
|
|
|
vpreq->vendorCode = X_GLXvop_ChangeDrawableAttributesSGIX;
|
|
|
|
|
|
|
|
output[0] = (CARD32) drawable;
|
2011-01-26 12:03:16 +00:00
|
|
|
output[1] = num_attribs;
|
|
|
|
output += 2;
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
2008-10-13 13:12:02 +01:00
|
|
|
(void) memcpy(output, attribs, sizeof(CARD32) * 2 * num_attribs);
|
2004-10-25 22:09:16 +01:00
|
|
|
|
|
|
|
UnlockDisplay(dpy);
|
|
|
|
SyncHandle();
|
|
|
|
|
2010-08-09 14:47:26 +01:00
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
2021-05-03 13:38:02 +01:00
|
|
|
pdraw = GetGLXDRIDrawable(dpy, drawable);
|
2010-08-09 14:47:26 +01:00
|
|
|
|
2011-05-03 18:20:14 +01:00
|
|
|
if (!pdraw)
|
|
|
|
return;
|
|
|
|
|
2010-07-14 17:01:49 +01:00
|
|
|
for (i = 0; i < num_attribs; i++) {
|
|
|
|
switch(attribs[i * 2]) {
|
|
|
|
case GLX_EVENT_MASK:
|
|
|
|
/* Keep a local copy for masking out DRI2 proto events as needed */
|
|
|
|
pdraw->eventMask = attribs[i * 2 + 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-08-09 14:47:26 +01:00
|
|
|
#endif
|
2010-07-14 17:01:49 +01:00
|
|
|
|
2004-10-25 22:09:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-10 20:45:52 +01:00
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
|
|
|
static GLenum
|
|
|
|
determineTextureTarget(const int *attribs, int numAttribs)
|
|
|
|
{
|
2008-10-13 13:12:02 +01:00
|
|
|
GLenum target = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numAttribs; i++) {
|
|
|
|
if (attribs[2 * i] == GLX_TEXTURE_TARGET_EXT) {
|
|
|
|
switch (attribs[2 * i + 1]) {
|
|
|
|
case GLX_TEXTURE_2D_EXT:
|
|
|
|
target = GL_TEXTURE_2D;
|
|
|
|
break;
|
|
|
|
case GLX_TEXTURE_RECTANGLE_EXT:
|
|
|
|
target = GL_TEXTURE_RECTANGLE_ARB;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
2008-04-10 20:45:52 +01:00
|
|
|
}
|
2009-03-18 19:07:09 +00:00
|
|
|
|
|
|
|
static GLenum
|
|
|
|
determineTextureFormat(const int *attribs, int numAttribs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numAttribs; i++) {
|
|
|
|
if (attribs[2 * i] == GLX_TEXTURE_FORMAT_EXT)
|
2009-08-12 11:41:22 +01:00
|
|
|
return attribs[2 * i + 1];
|
2009-03-18 19:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-09-16 16:21:10 +01:00
|
|
|
#endif
|
2010-04-09 22:16:33 +01:00
|
|
|
|
2011-03-31 21:43:57 +01:00
|
|
|
static GLboolean
|
2010-07-28 15:07:52 +01:00
|
|
|
CreateDRIDrawable(Display *dpy, struct glx_config *config,
|
2021-11-09 09:19:44 +00:00
|
|
|
XID drawable, XID glxdrawable, int type,
|
2010-04-09 22:16:33 +01:00
|
|
|
const int *attrib_list, size_t num_attribs)
|
|
|
|
{
|
2020-09-16 16:21:10 +01:00
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
2010-07-28 16:16:00 +01:00
|
|
|
struct glx_display *const priv = __glXInitialize(dpy);
|
2010-04-09 22:16:33 +01:00
|
|
|
__GLXDRIdrawable *pdraw;
|
2010-07-28 15:28:43 +01:00
|
|
|
struct glx_screen *psc;
|
2010-04-09 22:16:33 +01:00
|
|
|
|
2014-02-07 12:44:00 +00:00
|
|
|
if (priv == NULL) {
|
|
|
|
fprintf(stderr, "failed to create drawable\n");
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-28 15:28:43 +01:00
|
|
|
psc = priv->screens[config->screen];
|
2010-04-09 22:16:33 +01:00
|
|
|
if (psc->driScreen == NULL)
|
2011-03-31 21:43:57 +01:00
|
|
|
return GL_TRUE;
|
2010-04-09 22:16:33 +01:00
|
|
|
|
2021-11-09 09:19:44 +00:00
|
|
|
pdraw = psc->driScreen->createDrawable(psc, drawable, glxdrawable,
|
|
|
|
type, config);
|
2010-04-09 22:16:33 +01:00
|
|
|
if (pdraw == NULL) {
|
|
|
|
fprintf(stderr, "failed to create drawable\n");
|
2011-03-31 21:43:57 +01:00
|
|
|
return GL_FALSE;
|
2010-04-09 22:16:33 +01:00
|
|
|
}
|
|
|
|
|
2010-07-20 02:15:50 +01:00
|
|
|
if (__glxHashInsert(priv->drawHash, glxdrawable, pdraw)) {
|
2010-04-09 22:16:33 +01:00
|
|
|
(*pdraw->destroyDrawable) (pdraw);
|
2011-03-31 21:43:57 +01:00
|
|
|
return GL_FALSE;
|
2010-04-09 22:16:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pdraw->textureTarget = determineTextureTarget(attrib_list, num_attribs);
|
|
|
|
pdraw->textureFormat = determineTextureFormat(attrib_list, num_attribs);
|
2022-02-09 08:00:30 +00:00
|
|
|
|
|
|
|
pdraw->refcount = 1;
|
2020-09-16 16:21:10 +01:00
|
|
|
#endif
|
2011-03-31 21:43:57 +01:00
|
|
|
|
|
|
|
return GL_TRUE;
|
2010-04-09 22:16:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-11-09 07:41:08 +00:00
|
|
|
DestroyDRIDrawable(Display *dpy, GLXDrawable drawable)
|
2010-04-09 22:16:33 +01:00
|
|
|
{
|
2020-09-16 16:21:10 +01:00
|
|
|
#ifdef GLX_DIRECT_RENDERING
|
2021-05-03 13:38:02 +01:00
|
|
|
struct glx_display *const priv = __glXInitialize(dpy);
|
|
|
|
__GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
|
2010-04-09 22:16:33 +01:00
|
|
|
|
2014-02-07 12:44:00 +00:00
|
|
|
if (priv != NULL && pdraw != NULL) {
|
2010-04-09 22:16:33 +01:00
|
|
|
(*pdraw->destroyDrawable) (pdraw);
|
2010-07-20 02:15:50 +01:00
|
|
|
__glxHashDelete(priv->drawHash, drawable);
|
2010-04-09 22:16:33 +01:00
|
|
|
}
|
2008-04-10 20:45:52 +01:00
|
|
|
#endif
|
2020-09-16 16:21:10 +01:00
|
|
|
}
|
2008-04-10 20:45:52 +01:00
|
|
|
|
2004-10-25 22:09:16 +01:00
|
|
|
/**
|
|
|
|
* Get a drawable's attribute.
|
|
|
|
*
|
|
|
|
* This function is used to implement \c glXGetSelectedEvent and
|
|
|
|
* \c glXGetSelectedEventSGIX.
|
|
|
|
*
|
|
|
|
* \note
|
|
|
|
* This function dynamically determines whether to use the SGIX_pbuffer
|
|
|
|
* version of the protocol or the GLX 1.3 version of the protocol.
|
|
|
|
*
|
|
|
|
* \todo
|
|
|
|
* The number of attributes returned is likely to be small, probably less than
|
|
|
|
* 10. Given that, this routine should try to use an array on the stack to
|
|
|
|
* capture the reply rather than always calling Xmalloc.
|
|
|
|
*/
|
2017-11-14 20:13:05 +00:00
|
|
|
int
|
2021-05-03 13:38:02 +01:00
|
|
|
__glXGetDrawableAttribute(Display * dpy, GLXDrawable drawable,
|
2017-11-14 20:13:05 +00:00
|
|
|
int attribute, unsigned int *value)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2021-05-03 13:38:02 +01:00
|
|
|
struct glx_display *priv;
|
2004-10-25 22:09:16 +01:00
|
|
|
xGLXGetDrawableAttributesReply reply;
|
2008-10-13 13:12:02 +01:00
|
|
|
CARD32 *data;
|
2006-06-13 02:41:18 +01:00
|
|
|
CARD8 opcode;
|
2004-10-25 22:09:16 +01:00
|
|
|
unsigned int length;
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int num_attributes;
|
2021-04-16 18:59:29 +01:00
|
|
|
int found = 0;
|
2006-04-07 01:05:50 +01:00
|
|
|
|
2014-02-24 19:44:42 +00:00
|
|
|
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
|
|
|
|
__GLXDRIdrawable *pdraw;
|
|
|
|
#endif
|
|
|
|
|
2013-08-09 02:17:24 +01:00
|
|
|
if (dpy == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Page 38 (page 52 of the PDF) of glxencode1.3.pdf says:
|
|
|
|
*
|
|
|
|
* "If drawable is not a valid GLX drawable, a GLXBadDrawable error is
|
|
|
|
* generated."
|
|
|
|
*/
|
|
|
|
if (drawable == 0) {
|
|
|
|
__glXSendError(dpy, GLXBadDrawable, 0, X_GLXGetDrawableAttributes, false);
|
2006-04-07 01:05:50 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-03 13:38:02 +01:00
|
|
|
priv = __glXInitialize(dpy);
|
|
|
|
if (priv == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2006-02-07 00:39:56 +00:00
|
|
|
*value = 0;
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2006-06-13 02:41:18 +01:00
|
|
|
opcode = __glXSetupForCommand(dpy);
|
|
|
|
if (!opcode)
|
|
|
|
return 0;
|
|
|
|
|
2014-02-24 19:44:42 +00:00
|
|
|
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
|
2021-05-03 13:38:02 +01:00
|
|
|
pdraw = GetGLXDRIDrawable(dpy, drawable);
|
2014-02-24 19:44:42 +00:00
|
|
|
|
|
|
|
if (attribute == GLX_BACK_BUFFER_AGE_EXT) {
|
|
|
|
struct glx_context *gc = __glXGetCurrentContext();
|
2014-04-25 09:16:50 +01:00
|
|
|
struct glx_screen *psc;
|
2014-02-24 19:44:42 +00:00
|
|
|
|
|
|
|
/* The GLX_EXT_buffer_age spec says:
|
|
|
|
*
|
|
|
|
* "If querying GLX_BACK_BUFFER_AGE_EXT and <draw> is not bound to
|
|
|
|
* the calling thread's current context a GLXBadDrawable error is
|
|
|
|
* generated."
|
|
|
|
*/
|
2016-06-07 11:33:33 +01:00
|
|
|
if (pdraw == NULL || gc == &dummyContext || gc->currentDpy != dpy ||
|
2014-04-25 09:16:50 +01:00
|
|
|
(gc->currentDrawable != drawable &&
|
|
|
|
gc->currentReadable != drawable)) {
|
|
|
|
__glXSendError(dpy, GLXBadDrawable, drawable,
|
|
|
|
X_GLXGetDrawableAttributes, false);
|
2014-02-24 19:44:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-25 09:16:50 +01:00
|
|
|
psc = pdraw->psc;
|
|
|
|
|
2014-02-24 19:44:42 +00:00
|
|
|
if (psc->driScreen->getBufferAge != NULL)
|
|
|
|
*value = psc->driScreen->getBufferAge(pdraw);
|
|
|
|
|
2022-07-06 18:46:24 +01:00
|
|
|
return 1;
|
2014-02-24 19:44:42 +00:00
|
|
|
}
|
2020-09-09 19:00:35 +01:00
|
|
|
|
|
|
|
if (pdraw) {
|
|
|
|
if (attribute == GLX_SWAP_INTERVAL_EXT) {
|
|
|
|
*value = pdraw->psc->driScreen->getSwapInterval(pdraw);
|
2022-07-06 18:46:24 +01:00
|
|
|
return 1;
|
2020-09-09 19:00:35 +01:00
|
|
|
} else if (attribute == GLX_MAX_SWAP_INTERVAL_EXT) {
|
2022-04-28 22:19:13 +01:00
|
|
|
*value = pdraw->psc->driScreen->maxSwapInterval;
|
2022-07-06 18:46:24 +01:00
|
|
|
return 1;
|
2020-09-09 20:14:30 +01:00
|
|
|
} else if (attribute == GLX_LATE_SWAPS_TEAR_EXT) {
|
|
|
|
*value = __glXExtensionBitIsEnabled(pdraw->psc,
|
|
|
|
EXT_swap_control_tear_bit);
|
2022-07-06 18:46:24 +01:00
|
|
|
return 1;
|
2020-09-09 19:00:35 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-24 19:44:42 +00:00
|
|
|
#endif
|
|
|
|
|
2004-10-25 22:09:16 +01:00
|
|
|
LockDisplay(dpy);
|
|
|
|
|
2021-04-22 18:10:44 +01:00
|
|
|
if (priv->minorVersion >= 3) {
|
2004-10-25 22:09:16 +01:00
|
|
|
xGLXGetDrawableAttributesReq *req;
|
|
|
|
|
2011-01-23 16:26:35 +00:00
|
|
|
GetReq(GLXGetDrawableAttributes, req);
|
2006-06-13 02:41:18 +01:00
|
|
|
req->reqType = opcode;
|
2004-10-25 22:09:16 +01:00
|
|
|
req->glxCode = X_GLXGetDrawableAttributes;
|
|
|
|
req->drawable = drawable;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xGLXVendorPrivateWithReplyReq *vpreq;
|
|
|
|
|
2008-10-13 13:12:02 +01:00
|
|
|
GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq);
|
2004-10-25 22:09:16 +01:00
|
|
|
data = (CARD32 *) (vpreq + 1);
|
|
|
|
data[0] = (CARD32) drawable;
|
|
|
|
|
2006-06-13 02:41:18 +01:00
|
|
|
vpreq->reqType = opcode;
|
2004-10-25 22:09:16 +01:00
|
|
|
vpreq->glxCode = X_GLXVendorPrivateWithReply;
|
|
|
|
vpreq->vendorCode = X_GLXvop_GetDrawableAttributesSGIX;
|
|
|
|
}
|
|
|
|
|
2008-10-13 13:12:02 +01:00
|
|
|
_XReply(dpy, (xReply *) & reply, 0, False);
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2008-10-13 13:12:02 +01:00
|
|
|
if (reply.type == X_Error) {
|
|
|
|
UnlockDisplay(dpy);
|
|
|
|
SyncHandle();
|
|
|
|
return 0;
|
2006-02-07 00:39:56 +00:00
|
|
|
}
|
|
|
|
|
2004-10-25 22:09:16 +01:00
|
|
|
length = reply.length;
|
2008-10-13 13:12:02 +01:00
|
|
|
if (length) {
|
2021-04-22 18:10:44 +01:00
|
|
|
num_attributes = (priv->minorVersion > 2) ? reply.numAttribs : length / 2;
|
2012-09-04 03:44:00 +01:00
|
|
|
data = malloc(length * sizeof(CARD32));
|
2008-10-13 13:12:02 +01:00
|
|
|
if (data == NULL) {
|
|
|
|
/* Throw data on the floor */
|
|
|
|
_XEatData(dpy, length);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_XRead(dpy, (char *) data, length * sizeof(CARD32));
|
|
|
|
|
|
|
|
/* Search the set of returned attributes for the attribute requested by
|
|
|
|
* the caller.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < num_attributes; i++) {
|
|
|
|
if (data[i * 2] == attribute) {
|
2021-04-16 18:59:29 +01:00
|
|
|
found = 1;
|
2008-10-13 13:12:02 +01:00
|
|
|
*value = data[(i * 2) + 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-02-07 00:39:56 +00:00
|
|
|
|
2010-04-02 09:35:19 +01:00
|
|
|
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
|
2014-02-24 19:44:41 +00:00
|
|
|
if (pdraw != NULL) {
|
|
|
|
if (!pdraw->textureTarget)
|
2008-10-13 13:12:02 +01:00
|
|
|
pdraw->textureTarget =
|
|
|
|
determineTextureTarget((const int *) data, num_attributes);
|
2014-02-24 19:44:41 +00:00
|
|
|
if (!pdraw->textureFormat)
|
2009-03-18 19:07:09 +00:00
|
|
|
pdraw->textureFormat =
|
|
|
|
determineTextureFormat((const int *) data, num_attributes);
|
2008-10-13 13:12:02 +01:00
|
|
|
}
|
2008-04-10 20:45:52 +01:00
|
|
|
#endif
|
|
|
|
|
2012-09-05 06:52:36 +01:00
|
|
|
free(data);
|
2008-10-13 13:12:02 +01:00
|
|
|
}
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
UnlockDisplay(dpy);
|
|
|
|
SyncHandle();
|
|
|
|
|
2021-12-13 14:07:13 +00:00
|
|
|
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
|
|
|
|
if (pdraw && attribute == GLX_FBCONFIG_ID && !found && priv && priv->screens != NULL) {
|
|
|
|
/* If we failed to lookup the GLX_FBCONFIG_ID, it may be because the drawable is
|
|
|
|
* a bare Window, so try differently by first figure out its visual, then GLX
|
|
|
|
* visual like driInferDrawableConfig does.
|
|
|
|
*/
|
|
|
|
xcb_get_window_attributes_cookie_t cookie = { 0 };
|
|
|
|
xcb_get_window_attributes_reply_t *attr = NULL;
|
|
|
|
|
|
|
|
xcb_connection_t *conn = XGetXCBConnection(dpy);
|
|
|
|
|
|
|
|
if (conn) {
|
|
|
|
cookie = xcb_get_window_attributes(conn, drawable);
|
|
|
|
attr = xcb_get_window_attributes_reply(conn, cookie, NULL);
|
|
|
|
if (attr) {
|
|
|
|
/* Find the Window's GLX Visual */
|
|
|
|
struct glx_config *conf = glx_config_find_visual(pdraw->psc->visuals, attr->visual);
|
|
|
|
free(attr);
|
|
|
|
|
|
|
|
if (conf && conf->screen >= 0 && conf->screen < ScreenCount(dpy)) {
|
|
|
|
/* Then find the GLXFBConfig of the GLX Visual */
|
|
|
|
struct glx_config *c;
|
|
|
|
for (c = priv->screens[conf->screen]->configs; c != NULL;
|
|
|
|
c = c->next) {
|
|
|
|
if (!c->visualID)
|
|
|
|
continue;
|
|
|
|
if (c->visualID == conf->visualID) {
|
|
|
|
*value = c->fbconfigID;
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-04-16 18:59:29 +01:00
|
|
|
return found;
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
2021-10-31 05:02:02 +00:00
|
|
|
static int dummyErrorHandler(Display *display, xError *err, XExtCodes *codes,
|
|
|
|
int *ret_code)
|
|
|
|
{
|
|
|
|
return 1; /* do nothing */
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:43:57 +01:00
|
|
|
static void
|
|
|
|
protocolDestroyDrawable(Display *dpy, GLXDrawable drawable, CARD32 glxCode)
|
|
|
|
{
|
|
|
|
xGLXDestroyPbufferReq *req;
|
|
|
|
CARD8 opcode;
|
|
|
|
|
|
|
|
opcode = __glXSetupForCommand(dpy);
|
|
|
|
if (!opcode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LockDisplay(dpy);
|
|
|
|
|
|
|
|
GetReq(GLXDestroyPbuffer, req);
|
|
|
|
req->reqType = opcode;
|
|
|
|
req->glxCode = glxCode;
|
|
|
|
req->pbuffer = (GLXPbuffer) drawable;
|
|
|
|
|
|
|
|
UnlockDisplay(dpy);
|
|
|
|
SyncHandle();
|
2021-10-31 05:02:02 +00:00
|
|
|
|
|
|
|
/* Viewperf2020/Sw calls XDestroyWindow(win) and then glXDestroyWindow(win),
|
|
|
|
* causing an X error and abort. This is the workaround.
|
|
|
|
*/
|
|
|
|
struct glx_display *priv = __glXInitialize(dpy);
|
|
|
|
|
|
|
|
if (priv->screens[0] &&
|
|
|
|
priv->screens[0]->allow_invalid_glx_destroy_window) {
|
|
|
|
void *old = XESetError(priv->dpy, priv->codes.extension,
|
|
|
|
dummyErrorHandler);
|
|
|
|
XSync(dpy, false);
|
|
|
|
XESetError(priv->dpy, priv->codes.extension, old);
|
|
|
|
}
|
2011-03-31 21:43:57 +01:00
|
|
|
}
|
|
|
|
|
2004-10-25 22:09:16 +01:00
|
|
|
/**
|
|
|
|
* Create a non-pbuffer GLX drawable.
|
|
|
|
*/
|
|
|
|
static GLXDrawable
|
2021-05-03 13:38:02 +01:00
|
|
|
CreateDrawable(Display *dpy, struct glx_config *config,
|
2021-11-09 09:19:44 +00:00
|
|
|
Drawable drawable, int type, const int *attrib_list)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2008-10-13 13:12:02 +01:00
|
|
|
xGLXCreateWindowReq *req;
|
2011-05-06 18:31:24 +01:00
|
|
|
struct glx_drawable *glxDraw;
|
2008-10-13 13:12:02 +01:00
|
|
|
CARD32 *data;
|
2005-03-04 17:53:24 +00:00
|
|
|
unsigned int i;
|
2006-04-11 13:07:41 +01:00
|
|
|
CARD8 opcode;
|
2011-05-25 11:11:20 +01:00
|
|
|
GLXDrawable xid;
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2021-04-12 16:33:17 +01:00
|
|
|
if (!config)
|
|
|
|
return None;
|
|
|
|
|
2005-03-04 17:53:24 +00:00
|
|
|
i = 0;
|
|
|
|
if (attrib_list) {
|
2008-10-13 13:12:02 +01:00
|
|
|
while (attrib_list[i * 2] != None)
|
|
|
|
i++;
|
2005-03-04 17:53:24 +00:00
|
|
|
}
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2006-06-13 02:41:18 +01:00
|
|
|
opcode = __glXSetupForCommand(dpy);
|
|
|
|
if (!opcode)
|
|
|
|
return None;
|
2006-04-11 13:07:41 +01:00
|
|
|
|
2012-09-05 06:52:36 +01:00
|
|
|
glxDraw = malloc(sizeof(*glxDraw));
|
2011-05-06 18:31:24 +01:00
|
|
|
if (!glxDraw)
|
|
|
|
return None;
|
|
|
|
|
2004-10-25 22:09:16 +01:00
|
|
|
LockDisplay(dpy);
|
2008-10-13 13:12:02 +01:00
|
|
|
GetReqExtra(GLXCreateWindow, 8 * i, req);
|
2004-10-25 22:09:16 +01:00
|
|
|
data = (CARD32 *) (req + 1);
|
|
|
|
|
2006-04-11 13:07:41 +01:00
|
|
|
req->reqType = opcode;
|
2010-07-28 15:07:52 +01:00
|
|
|
req->screen = config->screen;
|
|
|
|
req->fbconfig = config->fbconfigID;
|
|
|
|
req->window = drawable;
|
2011-05-25 11:11:20 +01:00
|
|
|
req->glxwindow = xid = XAllocID(dpy);
|
2010-07-28 15:07:52 +01:00
|
|
|
req->numAttribs = i;
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2021-11-09 09:19:44 +00:00
|
|
|
if (type == GLX_WINDOW_BIT)
|
|
|
|
req->glxCode = X_GLXCreateWindow;
|
|
|
|
else
|
|
|
|
req->glxCode = X_GLXCreatePixmap;
|
|
|
|
|
2010-03-02 14:34:29 +00:00
|
|
|
if (attrib_list)
|
|
|
|
memcpy(data, attrib_list, 8 * i);
|
2008-10-13 13:12:02 +01:00
|
|
|
|
2004-10-25 22:09:16 +01:00
|
|
|
UnlockDisplay(dpy);
|
|
|
|
SyncHandle();
|
2008-10-13 13:12:02 +01:00
|
|
|
|
2021-05-03 13:38:02 +01:00
|
|
|
if (InitGLXDrawable(dpy, glxDraw, drawable, xid)) {
|
2011-05-06 18:31:24 +01:00
|
|
|
free(glxDraw);
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2021-11-09 09:19:44 +00:00
|
|
|
if (!CreateDRIDrawable(dpy, config, drawable, xid, type, attrib_list, i)) {
|
|
|
|
CARD8 glxCode;
|
|
|
|
if (type == GLX_PIXMAP_BIT)
|
2011-03-31 21:43:57 +01:00
|
|
|
glxCode = X_GLXDestroyPixmap;
|
|
|
|
else
|
|
|
|
glxCode = X_GLXDestroyWindow;
|
|
|
|
protocolDestroyDrawable(dpy, xid, glxCode);
|
|
|
|
xid = None;
|
|
|
|
}
|
DRI interface changes and DRI2 direct rendering support.
Add DRI2 direct rendering support to libGL and add DRI2 client side
protocol code. Extend the GLX 1.3 create drawable functions in
glx_pbuffer.c to call into the DRI driver when possible.
Introduce __DRIconfig, opaque struct that represents a DRI driver
configuration. Get's rid of the open coded __GLcontextModes in the
DRI driver interface and the context modes create and destroy
functions that the loader was requires to provide. glcore.h is no
longer part of the DRI driver interface. The DRI config is GL binding
agnostic, that is, not specific to GLX, EGL or other bindings.
The core API is now also an extension, and the driver exports a list
of extensions as the symbol __driDriverExtensions, which the loader
must dlsym() for. The list of extension will always include the DRI
core extension, which allows creating and manipulating DRI screens,
drawables and contexts. The DRI legacy extension, when available,
provides alternative entry points for creating the DRI objects that
work with the XF86DRI infrastructure.
Change DRI2 client code to not use drm drawables or contexts. We
never used drm_drawable_t's and the only use for drm_context_t was as
a unique identifier when taking the lock. We now just allocate a
unique lock ID out of the DRILock sarea block. Once we get rid of the
lock entirely, we can drop this hack.
Change the interface between dri_util.c and the drivers, so that the
drivers now export the DriverAPI struct as driDriverAPI instead of the
InitScreen entry point. This lets us avoid dlsym()'ing for the DRI2
init screen function to see if DRI2 is supported by the driver.
2008-03-26 23:26:59 +00:00
|
|
|
|
2011-05-25 11:11:20 +01:00
|
|
|
return xid;
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy a non-pbuffer GLX drawable.
|
|
|
|
*/
|
|
|
|
static void
|
2008-10-13 13:12:02 +01:00
|
|
|
DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2011-03-31 21:43:57 +01:00
|
|
|
protocolDestroyDrawable(dpy, drawable, glxCode);
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2021-05-03 13:38:02 +01:00
|
|
|
DestroyGLXDrawable(dpy, drawable);
|
2021-11-09 07:41:08 +00:00
|
|
|
DestroyDRIDrawable(dpy, drawable);
|
DRI interface changes and DRI2 direct rendering support.
Add DRI2 direct rendering support to libGL and add DRI2 client side
protocol code. Extend the GLX 1.3 create drawable functions in
glx_pbuffer.c to call into the DRI driver when possible.
Introduce __DRIconfig, opaque struct that represents a DRI driver
configuration. Get's rid of the open coded __GLcontextModes in the
DRI driver interface and the context modes create and destroy
functions that the loader was requires to provide. glcore.h is no
longer part of the DRI driver interface. The DRI config is GL binding
agnostic, that is, not specific to GLX, EGL or other bindings.
The core API is now also an extension, and the driver exports a list
of extensions as the symbol __driDriverExtensions, which the loader
must dlsym() for. The list of extension will always include the DRI
core extension, which allows creating and manipulating DRI screens,
drawables and contexts. The DRI legacy extension, when available,
provides alternative entry points for creating the DRI objects that
work with the XF86DRI infrastructure.
Change DRI2 client code to not use drm drawables or contexts. We
never used drm_drawable_t's and the only use for drm_context_t was as
a unique identifier when taking the lock. We now just allocate a
unique lock ID out of the DRILock sarea block. Once we get rid of the
lock entirely, we can drop this hack.
Change the interface between dri_util.c and the drivers, so that the
drivers now export the DriverAPI struct as driDriverAPI instead of the
InitScreen entry point. This lets us avoid dlsym()'ing for the DRI2
init screen function to see if DRI2 is supported by the driver.
2008-03-26 23:26:59 +00:00
|
|
|
|
2004-10-25 22:09:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a pbuffer.
|
|
|
|
*
|
|
|
|
* This function is used to implement \c glXCreatePbuffer and
|
|
|
|
* \c glXCreateGLXPbufferSGIX.
|
|
|
|
*
|
|
|
|
* \note
|
|
|
|
* This function dynamically determines whether to use the SGIX_pbuffer
|
|
|
|
* version of the protocol or the GLX 1.3 version of the protocol.
|
|
|
|
*/
|
|
|
|
static GLXDrawable
|
2010-07-28 15:07:52 +01:00
|
|
|
CreatePbuffer(Display * dpy, struct glx_config *config,
|
2008-10-13 13:12:02 +01:00
|
|
|
unsigned int width, unsigned int height,
|
|
|
|
const int *attrib_list, GLboolean size_in_attribs)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2010-07-28 16:16:00 +01:00
|
|
|
struct glx_display *priv = __glXInitialize(dpy);
|
2004-10-25 22:09:16 +01:00
|
|
|
GLXDrawable id = 0;
|
2008-10-13 13:12:02 +01:00
|
|
|
CARD32 *data;
|
2006-06-13 02:41:18 +01:00
|
|
|
CARD8 opcode;
|
2008-10-13 13:12:02 +01:00
|
|
|
unsigned int i;
|
2011-03-31 21:43:57 +01:00
|
|
|
GLboolean glx_1_3 = GL_FALSE;
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2014-02-07 12:44:00 +00:00
|
|
|
if (priv == NULL)
|
|
|
|
return None;
|
|
|
|
|
2005-03-04 17:53:24 +00:00
|
|
|
i = 0;
|
|
|
|
if (attrib_list) {
|
2008-10-13 13:12:02 +01:00
|
|
|
while (attrib_list[i * 2])
|
|
|
|
i++;
|
2005-03-04 17:53:24 +00:00
|
|
|
}
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2006-06-13 02:41:18 +01:00
|
|
|
opcode = __glXSetupForCommand(dpy);
|
|
|
|
if (!opcode)
|
|
|
|
return None;
|
|
|
|
|
2004-10-25 22:09:16 +01:00
|
|
|
LockDisplay(dpy);
|
|
|
|
id = XAllocID(dpy);
|
|
|
|
|
2021-04-22 18:10:44 +01:00
|
|
|
if (priv->minorVersion >= 3) {
|
2008-10-13 13:12:02 +01:00
|
|
|
xGLXCreatePbufferReq *req;
|
2004-10-25 22:09:16 +01:00
|
|
|
unsigned int extra = (size_in_attribs) ? 0 : 2;
|
|
|
|
|
2011-03-31 21:43:57 +01:00
|
|
|
glx_1_3 = GL_TRUE;
|
|
|
|
|
2008-10-13 13:12:02 +01:00
|
|
|
GetReqExtra(GLXCreatePbuffer, (8 * (i + extra)), req);
|
2004-10-25 22:09:16 +01:00
|
|
|
data = (CARD32 *) (req + 1);
|
|
|
|
|
2006-06-13 02:41:18 +01:00
|
|
|
req->reqType = opcode;
|
2004-10-25 22:09:16 +01:00
|
|
|
req->glxCode = X_GLXCreatePbuffer;
|
2010-07-28 15:07:52 +01:00
|
|
|
req->screen = config->screen;
|
|
|
|
req->fbconfig = config->fbconfigID;
|
|
|
|
req->pbuffer = id;
|
|
|
|
req->numAttribs = i + extra;
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2008-10-13 13:12:02 +01:00
|
|
|
if (!size_in_attribs) {
|
|
|
|
data[(2 * i) + 0] = GLX_PBUFFER_WIDTH;
|
|
|
|
data[(2 * i) + 1] = width;
|
|
|
|
data[(2 * i) + 2] = GLX_PBUFFER_HEIGHT;
|
|
|
|
data[(2 * i) + 3] = height;
|
|
|
|
data += 4;
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xGLXVendorPrivateReq *vpreq;
|
|
|
|
|
2008-10-13 13:12:02 +01:00
|
|
|
GetReqExtra(GLXVendorPrivate, 20 + (8 * i), vpreq);
|
2004-10-25 22:09:16 +01:00
|
|
|
data = (CARD32 *) (vpreq + 1);
|
|
|
|
|
2006-06-13 02:41:18 +01:00
|
|
|
vpreq->reqType = opcode;
|
2004-10-25 22:09:16 +01:00
|
|
|
vpreq->glxCode = X_GLXVendorPrivate;
|
|
|
|
vpreq->vendorCode = X_GLXvop_CreateGLXPbufferSGIX;
|
|
|
|
|
2010-07-28 15:07:52 +01:00
|
|
|
data[0] = config->screen;
|
|
|
|
data[1] = config->fbconfigID;
|
|
|
|
data[2] = id;
|
|
|
|
data[3] = width;
|
|
|
|
data[4] = height;
|
2004-10-25 22:09:16 +01:00
|
|
|
data += 5;
|
|
|
|
}
|
|
|
|
|
2008-10-13 13:12:02 +01:00
|
|
|
(void) memcpy(data, attrib_list, sizeof(CARD32) * 2 * i);
|
2004-10-25 22:09:16 +01:00
|
|
|
|
|
|
|
UnlockDisplay(dpy);
|
|
|
|
SyncHandle();
|
|
|
|
|
2021-11-09 07:41:08 +00:00
|
|
|
/* xserver created a pixmap with the same id as pbuffer */
|
2021-11-09 09:19:44 +00:00
|
|
|
if (!CreateDRIDrawable(dpy, config, id, id, GLX_PBUFFER_BIT, attrib_list, i)) {
|
2011-03-31 21:43:57 +01:00
|
|
|
CARD32 o = glx_1_3 ? X_GLXDestroyPbuffer : X_GLXvop_DestroyGLXPbufferSGIX;
|
|
|
|
protocolDestroyDrawable(dpy, id, o);
|
|
|
|
id = None;
|
|
|
|
}
|
2010-04-09 22:16:33 +01:00
|
|
|
|
2004-10-25 22:09:16 +01:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2010-04-09 22:16:33 +01:00
|
|
|
/**
|
|
|
|
* Destroy a pbuffer.
|
|
|
|
*
|
|
|
|
* This function is used to implement \c glXDestroyPbuffer and
|
|
|
|
* \c glXDestroyGLXPbufferSGIX.
|
|
|
|
*
|
|
|
|
* \note
|
|
|
|
* This function dynamically determines whether to use the SGIX_pbuffer
|
|
|
|
* version of the protocol or the GLX 1.3 version of the protocol.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
DestroyPbuffer(Display * dpy, GLXDrawable drawable)
|
|
|
|
{
|
2010-07-28 16:16:00 +01:00
|
|
|
struct glx_display *priv = __glXInitialize(dpy);
|
2010-04-09 22:16:33 +01:00
|
|
|
CARD8 opcode;
|
|
|
|
|
2014-02-07 12:44:00 +00:00
|
|
|
if ((priv == NULL) || (dpy == NULL) || (drawable == 0)) {
|
2010-04-09 22:16:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
opcode = __glXSetupForCommand(dpy);
|
|
|
|
if (!opcode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LockDisplay(dpy);
|
|
|
|
|
2021-04-22 18:10:44 +01:00
|
|
|
if (priv->minorVersion >= 3) {
|
2010-04-09 22:16:33 +01:00
|
|
|
xGLXDestroyPbufferReq *req;
|
|
|
|
|
|
|
|
GetReq(GLXDestroyPbuffer, req);
|
|
|
|
req->reqType = opcode;
|
|
|
|
req->glxCode = X_GLXDestroyPbuffer;
|
|
|
|
req->pbuffer = (GLXPbuffer) drawable;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xGLXVendorPrivateWithReplyReq *vpreq;
|
|
|
|
CARD32 *data;
|
|
|
|
|
|
|
|
GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq);
|
|
|
|
data = (CARD32 *) (vpreq + 1);
|
|
|
|
|
|
|
|
data[0] = (CARD32) drawable;
|
|
|
|
|
|
|
|
vpreq->reqType = opcode;
|
|
|
|
vpreq->glxCode = X_GLXVendorPrivateWithReply;
|
|
|
|
vpreq->vendorCode = X_GLXvop_DestroyGLXPbufferSGIX;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnlockDisplay(dpy);
|
|
|
|
SyncHandle();
|
|
|
|
|
2021-11-09 07:41:08 +00:00
|
|
|
DestroyDRIDrawable(dpy, drawable);
|
2010-04-09 22:16:33 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2004-10-25 22:09:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new pbuffer.
|
|
|
|
*/
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC GLXPbufferSGIX
|
2008-10-13 13:12:02 +01:00
|
|
|
glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config,
|
|
|
|
unsigned int width, unsigned int height,
|
|
|
|
int *attrib_list)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2010-07-28 15:07:52 +01:00
|
|
|
return (GLXPbufferSGIX) CreatePbuffer(dpy, (struct glx_config *) config,
|
2008-10-13 13:12:02 +01:00
|
|
|
width, height,
|
|
|
|
attrib_list, GL_FALSE);
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif /* GLX_USE_APPLEGL */
|
2004-10-25 22:09:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new pbuffer.
|
|
|
|
*/
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC GLXPbuffer
|
2008-10-13 13:12:02 +01:00
|
|
|
glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2007-08-27 19:16:30 +01:00
|
|
|
int i, width, height;
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifdef GLX_USE_APPLEGL
|
|
|
|
GLXPbuffer result;
|
|
|
|
int errorcode;
|
|
|
|
#endif
|
2007-08-27 19:16:30 +01:00
|
|
|
|
|
|
|
width = 0;
|
|
|
|
height = 0;
|
|
|
|
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifdef GLX_USE_APPLEGL
|
|
|
|
for (i = 0; attrib_list[i]; ++i) {
|
|
|
|
switch (attrib_list[i]) {
|
|
|
|
case GLX_PBUFFER_WIDTH:
|
|
|
|
width = attrib_list[i + 1];
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLX_PBUFFER_HEIGHT:
|
|
|
|
height = attrib_list[i + 1];
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLX_LARGEST_PBUFFER:
|
|
|
|
/* This is a hint we should probably handle, but how? */
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLX_PRESERVED_CONTENTS:
|
|
|
|
/* The contents are always preserved with AppleSGLX with CGL. */
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (apple_glx_pbuffer_create(dpy, config, width, height, &errorcode,
|
|
|
|
&result)) {
|
|
|
|
/*
|
|
|
|
* apple_glx_pbuffer_create only sets the errorcode to core X11
|
|
|
|
* errors.
|
|
|
|
*/
|
|
|
|
__glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true);
|
|
|
|
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
#else
|
2007-08-27 19:16:30 +01:00
|
|
|
for (i = 0; attrib_list[i * 2]; i++) {
|
|
|
|
switch (attrib_list[i * 2]) {
|
|
|
|
case GLX_PBUFFER_WIDTH:
|
2008-10-13 13:12:02 +01:00
|
|
|
width = attrib_list[i * 2 + 1];
|
|
|
|
break;
|
2007-08-27 19:16:30 +01:00
|
|
|
case GLX_PBUFFER_HEIGHT:
|
2008-10-13 13:12:02 +01:00
|
|
|
height = attrib_list[i * 2 + 1];
|
|
|
|
break;
|
2007-08-27 19:16:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-28 15:07:52 +01:00
|
|
|
return (GLXPbuffer) CreatePbuffer(dpy, (struct glx_config *) config,
|
2008-10-13 13:12:02 +01:00
|
|
|
width, height, attrib_list, GL_TRUE);
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy an existing pbuffer.
|
|
|
|
*/
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC void
|
2008-10-13 13:12:02 +01:00
|
|
|
glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifdef GLX_USE_APPLEGL
|
|
|
|
if (apple_glx_pbuffer_destroy(dpy, pbuf)) {
|
|
|
|
__glXSendError(dpy, GLXBadPbuffer, pbuf, X_GLXDestroyPbuffer, false);
|
|
|
|
}
|
|
|
|
#else
|
2008-10-13 13:12:02 +01:00
|
|
|
DestroyPbuffer(dpy, pbuf);
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query an attribute of a drawable.
|
|
|
|
*/
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC void
|
2008-10-13 13:12:02 +01:00
|
|
|
glXQueryDrawable(Display * dpy, GLXDrawable drawable,
|
|
|
|
int attribute, unsigned int *value)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifdef GLX_USE_APPLEGL
|
|
|
|
Window root;
|
|
|
|
int x, y;
|
|
|
|
unsigned int width, height, bd, depth;
|
|
|
|
|
|
|
|
if (apple_glx_pixmap_query(drawable, attribute, value))
|
|
|
|
return; /*done */
|
|
|
|
|
|
|
|
if (apple_glx_pbuffer_query(drawable, attribute, value))
|
|
|
|
return; /*done */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The OpenGL spec states that we should report GLXBadDrawable if
|
|
|
|
* the drawable is invalid, however doing so would require that we
|
|
|
|
* use XSetErrorHandler(), which is known to not be thread safe.
|
|
|
|
* If we use a round-trip call to validate the drawable, there could
|
|
|
|
* be a race, so instead we just opt in favor of letting the
|
|
|
|
* XGetGeometry request fail with a GetGeometry request X error
|
|
|
|
* rather than GLXBadDrawable, in what is hoped to be a rare
|
|
|
|
* case of an invalid drawable. In practice most and possibly all
|
|
|
|
* X11 apps using GLX shouldn't notice a difference.
|
|
|
|
*/
|
|
|
|
if (XGetGeometry
|
|
|
|
(dpy, drawable, &root, &x, &y, &width, &height, &bd, &depth)) {
|
|
|
|
switch (attribute) {
|
|
|
|
case GLX_WIDTH:
|
|
|
|
*value = width;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLX_HEIGHT:
|
|
|
|
*value = height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2021-05-03 13:38:02 +01:00
|
|
|
__glXGetDrawableAttribute(dpy, drawable, attribute, value);
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifndef GLX_USE_APPLEGL
|
2004-10-25 22:09:16 +01:00
|
|
|
/**
|
|
|
|
* Query an attribute of a pbuffer.
|
|
|
|
*/
|
2019-08-20 20:43:06 +01:00
|
|
|
_GLX_PUBLIC void
|
2008-10-13 13:12:02 +01:00
|
|
|
glXQueryGLXPbufferSGIX(Display * dpy, GLXPbufferSGIX drawable,
|
|
|
|
int attribute, unsigned int *value)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2021-05-03 13:38:02 +01:00
|
|
|
__glXGetDrawableAttribute(dpy, drawable, attribute, value);
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
2004-10-25 22:09:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Select the event mask for a drawable.
|
|
|
|
*/
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC void
|
2008-10-13 13:12:02 +01:00
|
|
|
glXSelectEvent(Display * dpy, GLXDrawable drawable, unsigned long mask)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifdef GLX_USE_APPLEGL
|
|
|
|
XWindowAttributes xwattr;
|
|
|
|
|
|
|
|
if (apple_glx_pbuffer_set_event_mask(drawable, mask))
|
|
|
|
return; /*done */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The spec allows a window, but currently there are no valid
|
|
|
|
* events for a window, so do nothing.
|
|
|
|
*/
|
|
|
|
if (XGetWindowAttributes(dpy, drawable, &xwattr))
|
|
|
|
return; /*done */
|
|
|
|
/* The drawable seems to be invalid. Report an error. */
|
|
|
|
|
|
|
|
__glXSendError(dpy, GLXBadDrawable, drawable,
|
|
|
|
X_GLXChangeDrawableAttributes, false);
|
|
|
|
#else
|
2004-10-25 22:09:16 +01:00
|
|
|
CARD32 attribs[2];
|
|
|
|
|
|
|
|
attribs[0] = (CARD32) GLX_EVENT_MASK;
|
|
|
|
attribs[1] = (CARD32) mask;
|
|
|
|
|
2021-05-03 13:38:02 +01:00
|
|
|
ChangeDrawableAttribute(dpy, drawable, attribs, 1);
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the selected event mask for a drawable.
|
|
|
|
*/
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC void
|
2008-10-13 13:12:02 +01:00
|
|
|
glXGetSelectedEvent(Display * dpy, GLXDrawable drawable, unsigned long *mask)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifdef GLX_USE_APPLEGL
|
|
|
|
XWindowAttributes xwattr;
|
|
|
|
|
|
|
|
if (apple_glx_pbuffer_get_event_mask(drawable, mask))
|
|
|
|
return; /*done */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The spec allows a window, but currently there are no valid
|
|
|
|
* events for a window, so do nothing, but set the mask to 0.
|
|
|
|
*/
|
|
|
|
if (XGetWindowAttributes(dpy, drawable, &xwattr)) {
|
|
|
|
/* The window is valid, so set the mask to 0. */
|
|
|
|
*mask = 0;
|
|
|
|
return; /*done */
|
|
|
|
}
|
|
|
|
/* The drawable seems to be invalid. Report an error. */
|
|
|
|
|
|
|
|
__glXSendError(dpy, GLXBadDrawable, drawable, X_GLXGetDrawableAttributes,
|
|
|
|
true);
|
|
|
|
#else
|
2017-04-05 21:07:57 +01:00
|
|
|
unsigned int value = 0;
|
2021-05-03 13:38:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* The non-sense with value is required because on LP64 platforms
|
|
|
|
* sizeof(unsigned int) != sizeof(unsigned long). On little-endian
|
|
|
|
* we could just type-cast the pointer, but why?
|
|
|
|
*/
|
|
|
|
|
|
|
|
__glXGetDrawableAttribute(dpy, drawable, GLX_EVENT_MASK_SGIX, &value);
|
2004-10-25 22:09:16 +01:00
|
|
|
*mask = value;
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC GLXPixmap
|
2008-10-13 13:12:02 +01:00
|
|
|
glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap,
|
|
|
|
const int *attrib_list)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifdef GLX_USE_APPLEGL
|
2011-06-05 22:02:33 +01:00
|
|
|
const struct glx_config *modes = (const struct glx_config *) config;
|
2010-04-01 19:01:31 +01:00
|
|
|
|
|
|
|
if (apple_glx_pixmap_create(dpy, modes->screen, pixmap, modes))
|
|
|
|
return None;
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
#else
|
2021-05-03 13:38:02 +01:00
|
|
|
return CreateDrawable(dpy, (struct glx_config *) config,
|
2021-11-09 09:19:44 +00:00
|
|
|
(Drawable) pixmap, GLX_PIXMAP_BIT, attrib_list);
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC GLXWindow
|
2008-10-13 13:12:02 +01:00
|
|
|
glXCreateWindow(Display * dpy, GLXFBConfig config, Window win,
|
|
|
|
const int *attrib_list)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifdef GLX_USE_APPLEGL
|
|
|
|
XWindowAttributes xwattr;
|
|
|
|
XVisualInfo *visinfo;
|
|
|
|
|
|
|
|
(void) attrib_list; /*unused according to GLX 1.4 */
|
|
|
|
|
|
|
|
XGetWindowAttributes(dpy, win, &xwattr);
|
2009-09-15 21:12:22 +01:00
|
|
|
|
2010-04-01 19:01:31 +01:00
|
|
|
visinfo = glXGetVisualFromFBConfig(dpy, config);
|
|
|
|
|
|
|
|
if (NULL == visinfo) {
|
|
|
|
__glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateWindow, false);
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visinfo->visualid != XVisualIDFromVisual(xwattr.visual)) {
|
|
|
|
__glXSendError(dpy, BadMatch, 0, X_GLXCreateWindow, true);
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2012-09-05 06:52:36 +01:00
|
|
|
free(visinfo);
|
2010-04-01 19:01:31 +01:00
|
|
|
|
|
|
|
return win;
|
|
|
|
#else
|
2021-05-03 13:38:02 +01:00
|
|
|
return CreateDrawable(dpy, (struct glx_config *) config,
|
2021-11-09 09:19:44 +00:00
|
|
|
(Drawable) win, GLX_WINDOW_BIT, attrib_list);
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC void
|
2008-10-13 13:12:02 +01:00
|
|
|
glXDestroyPixmap(Display * dpy, GLXPixmap pixmap)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifdef GLX_USE_APPLEGL
|
|
|
|
if (apple_glx_pixmap_destroy(dpy, pixmap))
|
|
|
|
__glXSendError(dpy, GLXBadPixmap, pixmap, X_GLXDestroyPixmap, false);
|
|
|
|
#else
|
2008-10-13 13:12:02 +01:00
|
|
|
DestroyDrawable(dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap);
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC void
|
2008-10-13 13:12:02 +01:00
|
|
|
glXDestroyWindow(Display * dpy, GLXWindow win)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2010-04-01 19:01:31 +01:00
|
|
|
#ifndef GLX_USE_APPLEGL
|
2008-10-13 13:12:02 +01:00
|
|
|
DestroyDrawable(dpy, (GLXDrawable) win, X_GLXDestroyWindow);
|
2010-04-01 19:01:31 +01:00
|
|
|
#endif
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC
|
2008-10-13 13:12:02 +01:00
|
|
|
GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX,
|
|
|
|
(Display * dpy, GLXPbufferSGIX pbuf),
|
|
|
|
(dpy, pbuf), glXDestroyPbuffer)
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC
|
2008-10-13 13:12:02 +01:00
|
|
|
GLX_ALIAS_VOID(glXSelectEventSGIX,
|
|
|
|
(Display * dpy, GLXDrawable drawable,
|
2009-08-12 11:41:22 +01:00
|
|
|
unsigned long mask), (dpy, drawable, mask), glXSelectEvent)
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2016-05-11 19:01:53 +01:00
|
|
|
_GLX_PUBLIC
|
2008-10-13 13:12:02 +01:00
|
|
|
GLX_ALIAS_VOID(glXGetSelectedEventSGIX,
|
|
|
|
(Display * dpy, GLXDrawable drawable,
|
|
|
|
unsigned long *mask), (dpy, drawable, mask),
|
|
|
|
glXGetSelectedEvent)
|