#include <assert.h>
#include "glxclient.h"
#include <X11/extensions/Xext.h>
#include <X11/extensions/extutil.h>
#include <X11/extensions/dri2proto.h>
#ifdef GLX_USE_APPLEGL
#include "apple_glx.h"
#include "apple_visual.h"
#endif
#include "glxextensions.h"
#include "glcontextmodes.h"
#ifdef USE_XCB
#include <X11/Xlib-xcb.h>
#include <xcb/xcb.h>
#include <xcb/glx.h>
#endif
#ifdef DEBUG
void __glXDumpDrawBuffer(__GLXcontext * ctx);
#endif
_X_HIDDEN int __glXDebug = 0;
static char *__glXExtensionName = GLX_EXTENSION_NAME;
#ifdef GLX_USE_APPLEGL
static XExtensionInfo __glXExtensionInfo_data;
XExtensionInfo *__glXExtensionInfo = &__glXExtensionInfo_data;
#else
XExtensionInfo *__glXExtensionInfo = NULL;
#endif
static char *error_list[] = {
"GLXBadContext",
"GLXBadContextState",
"GLXBadDrawable",
"GLXBadPixmap",
"GLXBadContextTag",
"GLXBadCurrentWindow",
"GLXBadRenderRequest",
"GLXBadLargeRequest",
"GLXUnsupportedPrivateRequest",
"GLXBadFBConfig",
"GLXBadPbuffer",
"GLXBadCurrentDrawable",
"GLXBadWindow",
};
static int
__glXCloseDisplay(Display * dpy, XExtCodes * codes)
{
GLXContext gc;
gc = __glXGetCurrentContext();
if (dpy == gc->currentDpy) {
__glXSetCurrentContextNull();
__glXFreeContext(gc);
}
return XextRemoveDisplay(__glXExtensionInfo, dpy);
}
#ifdef GLX_USE_APPLEGL
static char *__glXErrorString(Display *dpy, int code, XExtCodes *codes,
char *buf, int n);
#endif
static
XEXT_GENERATE_ERROR_STRING(__glXErrorString, __glXExtensionName,
__GLX_NUMBER_ERRORS, error_list)
static Bool
__glXWireToEvent(Display *dpy, XEvent *event, xEvent *wire);
static Status
__glXEventToWire(Display *dpy, XEvent *event, xEvent *wire);
static XExtensionHooks __glXExtensionHooks = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
__glXCloseDisplay,
__glXWireToEvent,
__glXEventToWire,
NULL,
__glXErrorString,
};
XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay, __glXExtensionInfo,
__glXExtensionName, &__glXExtensionHooks,
__GLX_NUMBER_EVENTS, NULL)
static Bool
__glXWireToEvent(Display *dpy, XEvent *event, xEvent *wire)
{
XExtDisplayInfo *info = __glXFindDisplay(dpy);
XextCheckExtension(dpy, info, __glXExtensionName, False);
switch ((wire->u.u.type & 0x7f) - info->codes->first_event) {
case GLX_PbufferClobber:
{
GLXPbufferClobberEvent *aevent = (GLXPbufferClobberEvent *)event;
xGLXPbufferClobberEvent *awire = (xGLXPbufferClobberEvent *)wire;
aevent->event_type = awire->type;
aevent->serial = awire->sequenceNumber;
aevent->event_type = awire->event_type;
aevent->draw_type = awire->draw_type;
aevent->drawable = awire->drawable;
aevent->buffer_mask = awire->buffer_mask;
aevent->aux_buffer = awire->aux_buffer;
aevent->x = awire->x;
aevent->y = awire->y;
aevent->width = awire->width;
aevent->height = awire->height;
aevent->count = awire->count;
return True;
}
#ifdef X_DRI2SwapBuffers
case GLX_BufferSwapComplete:
{
GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event;
xGLXBufferSwapComplete *awire = (xGLXBufferSwapComplete *)wire;
aevent->event_type = awire->event_type;
aevent->drawable = awire->drawable;
aevent->ust = ((CARD64)awire->ust_hi << 32) | awire->ust_lo;
aevent->msc = ((CARD64)awire->msc_hi << 32) | awire->msc_lo;
aevent->sbc = ((CARD64)awire->sbc_hi << 32) | awire->sbc_lo;
return True;
}
#endif
default:
break;
}
return False;
}
static Status
__glXEventToWire(Display *dpy, XEvent *event, xEvent *wire)
{
XExtDisplayInfo *info = __glXFindDisplay(dpy);
XextCheckExtension(dpy, info, __glXExtensionName, False);
switch (event->type) {
case GLX_DAMAGED:
break;
case GLX_SAVED:
break;
case GLX_EXCHANGE_COMPLETE_INTEL:
break;
case GLX_COPY_COMPLETE_INTEL:
break;
case GLX_FLIP_COMPLETE_INTEL:
break;
default:
break;
}
return Success;
}
static void
FreeScreenConfigs(__GLXdisplayPrivate * priv)
{
__GLXscreenConfigs *psc;
GLint i, screens;
psc = priv->screenConfigs;
screens = ScreenCount(priv->dpy);
for (i = 0; i < screens; i++, psc++) {
if (psc->configs) {
_gl_context_modes_destroy(psc->configs);
if (psc->effectiveGLXexts)
Xfree(psc->effectiveGLXexts);
psc->configs = NULL;
}
if (psc->visuals) {
_gl_context_modes_destroy(psc->visuals);
psc->visuals = NULL;
}
Xfree((char *) psc->serverGLXexts);
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (psc->driver_configs) {
unsigned int j;
for (j = 0; psc->driver_configs[j]; j++)
free((__DRIconfig *) psc->driver_configs[j]);
free(psc->driver_configs);
psc->driver_configs = NULL;
}
if (psc->driScreen) {
psc->driScreen->destroyScreen(psc);
__glxHashDestroy(psc->drawHash);
XFree(psc->driScreen);
psc->driScreen = NULL;
}
#endif
}
XFree((char *) priv->screenConfigs);
priv->screenConfigs = NULL;
}
static int
__glXFreeDisplayPrivate(XExtData * extension)
{
__GLXdisplayPrivate *priv;
priv = (__GLXdisplayPrivate *) extension->private_data;
FreeScreenConfigs(priv);
if (priv->serverGLXvendor) {
Xfree((char *) priv->serverGLXvendor);
priv->serverGLXvendor = 0x0;
}
if (priv->serverGLXversion) {
Xfree((char *) priv->serverGLXversion);
priv->serverGLXversion = 0x0;
}
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (priv->driswDisplay)
(*priv->driswDisplay->destroyDisplay) (priv->driswDisplay);
priv->driswDisplay = NULL;
if (priv->driDisplay)
(*priv->driDisplay->destroyDisplay) (priv->driDisplay);
priv->driDisplay = NULL;
if (priv->dri2Display)
(*priv->dri2Display->destroyDisplay) (priv->dri2Display);
priv->dri2Display = NULL;
#endif
Xfree((char *) priv);
return 0;
}
static Bool
QueryVersion(Display * dpy, int opcode, int *major, int *minor)
{
#ifdef USE_XCB
xcb_connection_t *c = XGetXCBConnection(dpy);
xcb_glx_query_version_reply_t *reply = xcb_glx_query_version_reply(c,
xcb_glx_query_version
(c,
GLX_MAJOR_VERSION,
GLX_MINOR_VERSION),
NULL);
if (reply->major_version != GLX_MAJOR_VERSION) {
free(reply);
return GL_FALSE;
}
*major = reply->major_version;
*minor = min(reply->minor_version, GLX_MINOR_VERSION);
free(reply);
return GL_TRUE;
#else
xGLXQueryVersionReq *req;
xGLXQueryVersionReply reply;
LockDisplay(dpy);
GetReq(GLXQueryVersion, req);
req->reqType = opcode;
req->glxCode = X_GLXQueryVersion;
req->majorVersion = GLX_MAJOR_VERSION;
req->minorVersion = GLX_MINOR_VERSION;
_XReply(dpy, (xReply *) & reply, 0, False);
UnlockDisplay(dpy);
SyncHandle();
if (reply.majorVersion != GLX_MAJOR_VERSION) {
return GL_FALSE;
}
*major = reply.majorVersion;
*minor = min(reply.minorVersion, GLX_MINOR_VERSION);
return GL_TRUE;
#endif
}
enum {
IGNORE_GLX_SWAP_METHOD_OML = 0x8060
};
_X_HIDDEN void
__glXInitializeVisualConfigFromTags(__GLcontextModes * config, int count,
const INT32 * bp, Bool tagged_only,
Bool fbconfig_style_tags)
{
int i;
if (!tagged_only) {
config->visualID = *bp++;
config->visualType = _gl_convert_from_x_visual_type(*bp++);
config->rgbMode = *bp++;
config->redBits = *bp++;
config->greenBits = *bp++;
config->blueBits = *bp++;
config->alphaBits = *bp++;
config->accumRedBits = *bp++;
config->accumGreenBits = *bp++;
config->accumBlueBits = *bp++;
config->accumAlphaBits = *bp++;
config->doubleBufferMode = *bp++;
config->stereoMode = *bp++;
config->rgbBits = *bp++;
config->depthBits = *bp++;
config->stencilBits = *bp++;
config->numAuxBuffers = *bp++;
config->level = *bp++;
#ifdef GLX_USE_APPLEGL
config->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
count -= 18;
#else
count -= __GLX_MIN_CONFIG_PROPS;
#endif
}
#define FETCH_OR_SET(tag) \
config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
for (i = 0; i < count; i += 2) {
long int tag = *bp++;
switch (tag) {
case GLX_RGBA:
FETCH_OR_SET(rgbMode);
break;
case GLX_BUFFER_SIZE:
config->rgbBits = *bp++;
break;
case GLX_LEVEL:
config->level = *bp++;
break;
case GLX_DOUBLEBUFFER:
FETCH_OR_SET(doubleBufferMode);
break;
case GLX_STEREO:
FETCH_OR_SET(stereoMode);
break;
case GLX_AUX_BUFFERS:
config->numAuxBuffers = *bp++;
break;
case GLX_RED_SIZE:
config->redBits = *bp++;
break;
case GLX_GREEN_SIZE:
config->greenBits = *bp++;
break;
case GLX_BLUE_SIZE:
config->blueBits = *bp++;
break;
case GLX_ALPHA_SIZE:
config->alphaBits = *bp++;
break;
case GLX_DEPTH_SIZE:
config->depthBits = *bp++;
break;
case GLX_STENCIL_SIZE:
config->stencilBits = *bp++;
break;
case GLX_ACCUM_RED_SIZE:
config->accumRedBits = *bp++;
break;
case GLX_ACCUM_GREEN_SIZE:
config->accumGreenBits = *bp++;
break;
case GLX_ACCUM_BLUE_SIZE:
config->accumBlueBits = *bp++;
break;
case GLX_ACCUM_ALPHA_SIZE:
config->accumAlphaBits = *bp++;
break;
case GLX_VISUAL_CAVEAT_EXT:
config->visualRating = *bp++;
break;
case GLX_X_VISUAL_TYPE:
config->visualType = *bp++;
break;
case GLX_TRANSPARENT_TYPE:
config->transparentPixel = *bp++;
break;
case GLX_TRANSPARENT_INDEX_VALUE:
config->transparentIndex = *bp++;
break;
case GLX_TRANSPARENT_RED_VALUE:
config->transparentRed = *bp++;
break;
case GLX_TRANSPARENT_GREEN_VALUE:
config->transparentGreen = *bp++;
break;
case GLX_TRANSPARENT_BLUE_VALUE:
config->transparentBlue = *bp++;
break;
case GLX_TRANSPARENT_ALPHA_VALUE:
config->transparentAlpha = *bp++;
break;
case GLX_VISUAL_ID:
config->visualID = *bp++;
break;
case GLX_DRAWABLE_TYPE:
config->drawableType = *bp++;
#ifdef GLX_USE_APPLEGL
config->drawableType |= GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
#endif
break;
case GLX_RENDER_TYPE:
config->renderType = *bp++;
break;
case GLX_X_RENDERABLE:
config->xRenderable = *bp++;
break;
case GLX_FBCONFIG_ID:
config->fbconfigID = *bp++;
break;
case GLX_MAX_PBUFFER_WIDTH:
config->maxPbufferWidth = *bp++;
break;
case GLX_MAX_PBUFFER_HEIGHT:
config->maxPbufferHeight = *bp++;
break;
case GLX_MAX_PBUFFER_PIXELS:
config->maxPbufferPixels = *bp++;
break;
#ifndef GLX_USE_APPLEGL
case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX:
config->optimalPbufferWidth = *bp++;
break;
case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX:
config->optimalPbufferHeight = *bp++;
break;
case GLX_VISUAL_SELECT_GROUP_SGIX:
config->visualSelectGroup = *bp++;
break;
case GLX_SWAP_METHOD_OML:
config->swapMethod = *bp++;
break;
#endif
case GLX_SAMPLE_BUFFERS_SGIS:
config->sampleBuffers = *bp++;
break;
case GLX_SAMPLES_SGIS:
config->samples = *bp++;
break;
#ifdef GLX_USE_APPLEGL
case IGNORE_GLX_SWAP_METHOD_OML:
++bp;
break;
#else
case GLX_BIND_TO_TEXTURE_RGB_EXT:
config->bindToTextureRgb = *bp++;
break;
case GLX_BIND_TO_TEXTURE_RGBA_EXT:
config->bindToTextureRgba = *bp++;
break;
case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
config->bindToMipmapTexture = *bp++;
break;
case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
config->bindToTextureTargets = *bp++;
break;
case GLX_Y_INVERTED_EXT:
config->yInverted = *bp++;
break;
#endif
case GLX_USE_GL:
if (fbconfig_style_tags)
bp++;
break;
case None:
i = count;
break;
default:
if(getenv("LIBGL_DIAGNOSTIC")) {
long int tagvalue = *bp++;
fprintf(stderr, "WARNING: unknown GLX tag from server: "
"tag 0x%lx value 0x%lx\n", tag, tagvalue);
} else {
bp++;
break;
}
break;
}
}
config->renderType =
(config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
config->haveAccumBuffer = ((config->accumRedBits +
config->accumGreenBits +
config->accumBlueBits +
config->accumAlphaBits) > 0);
config->haveDepthBuffer = (config->depthBits > 0);
config->haveStencilBuffer = (config->stencilBits > 0);
}
static __GLcontextModes *
createConfigsFromProperties(Display * dpy, int nvisuals, int nprops,
int screen, GLboolean tagged_only)
{
INT32 buf[__GLX_TOTAL_CONFIG], *props;
unsigned prop_size;
__GLcontextModes *modes, *m;
int i;
if (nprops == 0)
return NULL;
if (nprops < __GLX_MIN_CONFIG_PROPS || nprops > __GLX_MAX_CONFIG_PROPS)
return NULL;
modes = _gl_context_modes_create(nvisuals, sizeof(__GLcontextModes));
if (!modes)
return NULL;
prop_size = nprops * __GLX_SIZE_INT32;
if (prop_size <= sizeof(buf))
props = buf;
else
props = Xmalloc(prop_size);
m = modes;
for (i = 0; i < nvisuals; i++) {
_XRead(dpy, (char *) props, prop_size);
#ifdef GLX_USE_APPLEGL
m->drawableType = GLX_WINDOW_BIT;
#else
m->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
#endif
__glXInitializeVisualConfigFromTags(m, nprops, props,
tagged_only, GL_TRUE);
m->screen = screen;
m = m->next;
}
if (props != buf)
Xfree(props);
return modes;
}
static GLboolean
getVisualConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen)
{
xGLXGetVisualConfigsReq *req;
__GLXscreenConfigs *psc;
xGLXGetVisualConfigsReply reply;
LockDisplay(dpy);
psc = priv->screenConfigs + screen;
psc->visuals = NULL;
GetReq(GLXGetVisualConfigs, req);
req->reqType = priv->majorOpcode;
req->glxCode = X_GLXGetVisualConfigs;
req->screen = screen;
if (!_XReply(dpy, (xReply *) & reply, 0, False))
goto out;
psc->visuals = createConfigsFromProperties(dpy,
reply.numVisuals,
reply.numProps,
screen, GL_FALSE);
out:
UnlockDisplay(dpy);
return psc->visuals != NULL;
}
static GLboolean
getFBConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen)
{
xGLXGetFBConfigsReq *fb_req;
xGLXGetFBConfigsSGIXReq *sgi_req;
xGLXVendorPrivateWithReplyReq *vpreq;
xGLXGetFBConfigsReply reply;
__GLXscreenConfigs *psc;
psc = priv->screenConfigs + screen;
psc->serverGLXexts =
__glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS);
LockDisplay(dpy);
psc->configs = NULL;
if (atof(priv->serverGLXversion) >= 1.3) {
GetReq(GLXGetFBConfigs, fb_req);
fb_req->reqType = priv->majorOpcode;
fb_req->glxCode = X_GLXGetFBConfigs;
fb_req->screen = screen;
}
else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) {
GetReqExtra(GLXVendorPrivateWithReply,
sz_xGLXGetFBConfigsSGIXReq +
sz_xGLXVendorPrivateWithReplyReq, vpreq);
sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq;
sgi_req->reqType = priv->majorOpcode;
sgi_req->glxCode = X_GLXVendorPrivateWithReply;
sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX;
sgi_req->screen = screen;
}
else
goto out;
if (!_XReply(dpy, (xReply *) & reply, 0, False))
goto out;
psc->configs = createConfigsFromProperties(dpy,
reply.numFBConfigs,
reply.numAttribs * 2,
screen, GL_TRUE);
out:
UnlockDisplay(dpy);
return psc->configs != NULL;
}
static Bool
AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv)
{
__GLXscreenConfigs *psc;
GLint i, screens;
screens = ScreenCount(dpy);
psc = (__GLXscreenConfigs *) Xmalloc(screens * sizeof(__GLXscreenConfigs));
if (!psc) {
return GL_FALSE;
}
memset(psc, 0, screens * sizeof(__GLXscreenConfigs));
priv->screenConfigs = psc;
priv->serverGLXversion =
__glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION);
if (priv->serverGLXversion == NULL) {
FreeScreenConfigs(priv);
return GL_FALSE;
}
for (i = 0; i < screens; i++, psc++) {
getVisualConfigs(dpy, priv, i);
getFBConfigs(dpy, priv, i);
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
psc->scr = i;
psc->dpy = dpy;
psc->drawHash = __glxHashCreate();
if (psc->drawHash == NULL)
continue;
psc->ext_list_first_time = GL_TRUE;
if (priv->dri2Display)
psc->driScreen = (*priv->dri2Display->createScreen) (psc, i, priv);
if (psc->driScreen == NULL && priv->driDisplay)
psc->driScreen = (*priv->driDisplay->createScreen) (psc, i, priv);
if (psc->driScreen == NULL && priv->driswDisplay)
psc->driScreen = (*priv->driswDisplay->createScreen) (psc, i, priv);
if (psc->driScreen == NULL) {
__glxHashDestroy(psc->drawHash);
psc->drawHash = NULL;
}
#endif
}
SyncHandle();
return GL_TRUE;
}
_X_HIDDEN __GLXdisplayPrivate *
__glXInitialize(Display * dpy)
{
XExtDisplayInfo *info = __glXFindDisplay(dpy);
XExtData **privList, *private, *found;
__GLXdisplayPrivate *dpyPriv;
XEDataObject dataObj;
int major, minor;
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Bool glx_direct, glx_accel;
#endif
__glXLock();
if (!XextHasExtension(info)) {
__glXUnlock();
XMissingExtension(dpy, __glXExtensionName);
return 0;
}
dataObj.display = dpy;
privList = XEHeadOfExtensionList(dataObj);
found = XFindOnExtensionList(privList, info->codes->extension);
if (found) {
__glXUnlock();
return (__GLXdisplayPrivate *) found->private_data;
}
if (!QueryVersion(dpy, info->codes->major_opcode, &major, &minor)) {
__glXUnlock();
return 0;
}
private = (XExtData *) Xmalloc(sizeof(XExtData));
if (!private) {
__glXUnlock();
return 0;
}
dpyPriv = (__GLXdisplayPrivate *) Xcalloc(1, sizeof(__GLXdisplayPrivate));
if (!dpyPriv) {
__glXUnlock();
Xfree((char *) private);
return 0;
}
dpyPriv->majorOpcode = info->codes->major_opcode;
dpyPriv->majorVersion = major;
dpyPriv->minorVersion = minor;
dpyPriv->dpy = dpy;
dpyPriv->serverGLXvendor = 0x0;
dpyPriv->serverGLXversion = 0x0;
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
glx_direct = (getenv("LIBGL_ALWAYS_INDIRECT") == NULL);
glx_accel = (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL);
if (glx_direct && glx_accel) {
dpyPriv->dri2Display = dri2CreateDisplay(dpy);
dpyPriv->driDisplay = driCreateDisplay(dpy);
}
if (glx_direct)
dpyPriv->driswDisplay = driswCreateDisplay(dpy);
#endif
#ifdef GLX_USE_APPLEGL
if (apple_init_glx(dpy) || !AllocAndFetchScreenConfigs(dpy, dpyPriv)) {
#else
if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) {
#endif
__glXUnlock();
Xfree((char *) dpyPriv);
Xfree((char *) private);
return 0;
}
private->number = info->codes->extension;
private->next = 0;
private->free_private = __glXFreeDisplayPrivate;
private->private_data = (char *) dpyPriv;
XAddToExtensionList(privList, private);
if (dpyPriv->majorVersion == 1 && dpyPriv->minorVersion >= 1) {
__glXClientInfo(dpy, dpyPriv->majorOpcode);
}
__glXUnlock();
return dpyPriv;
}
_X_HIDDEN CARD8
__glXSetupForCommand(Display * dpy)
{
GLXContext gc;
__GLXdisplayPrivate *priv;
gc = __glXGetCurrentContext();
if (gc->currentDpy) {
(void) __glXFlushRenderBuffer(gc, gc->pc);
if (gc->currentDpy == dpy) {
return gc->majorOpcode;
}
else {
}
}
priv = __glXInitialize(dpy);
if (!priv) {
return 0;
}
return priv->majorOpcode;
}
_X_HIDDEN GLubyte *
__glXFlushRenderBuffer(__GLXcontext * ctx, GLubyte * pc)
{
Display *const dpy = ctx->currentDpy;
#ifdef USE_XCB
xcb_connection_t *c = XGetXCBConnection(dpy);
#else
xGLXRenderReq *req;
#endif
const GLint size = pc - ctx->buf;
if ((dpy != NULL) && (size > 0)) {
#ifdef USE_XCB
xcb_glx_render(c, ctx->currentContextTag, size,
(const uint8_t *) ctx->buf);
#else
LockDisplay(dpy);
GetReq(GLXRender, req);
req->reqType = ctx->majorOpcode;
req->glxCode = X_GLXRender;
req->contextTag = ctx->currentContextTag;
req->length += (size + 3) >> 2;
_XSend(dpy, (char *) ctx->buf, size);
UnlockDisplay(dpy);
SyncHandle();
#endif
}
ctx->pc = ctx->buf;
return ctx->pc;
}
_X_HIDDEN void
__glXSendLargeChunk(__GLXcontext * gc, GLint requestNumber,
GLint totalRequests, const GLvoid * data, GLint dataLen)
{
Display *dpy = gc->currentDpy;
#ifdef USE_XCB
xcb_connection_t *c = XGetXCBConnection(dpy);
xcb_glx_render_large(c, gc->currentContextTag, requestNumber,
totalRequests, dataLen, data);
#else
xGLXRenderLargeReq *req;
if (requestNumber == 1) {
LockDisplay(dpy);
}
GetReq(GLXRenderLarge, req);
req->reqType = gc->majorOpcode;
req->glxCode = X_GLXRenderLarge;
req->contextTag = gc->currentContextTag;
req->length += (dataLen + 3) >> 2;
req->requestNumber = requestNumber;
req->requestTotal = totalRequests;
req->dataBytes = dataLen;
Data(dpy, data, dataLen);
if (requestNumber == totalRequests) {
UnlockDisplay(dpy);
SyncHandle();
}
#endif
}
_X_HIDDEN void
__glXSendLargeCommand(__GLXcontext * ctx,
const GLvoid * header, GLint headerLen,
const GLvoid * data, GLint dataLen)
{
GLint maxSize;
GLint totalRequests, requestNumber;
maxSize = (ctx->bufSize + sz_xGLXRenderReq) - sz_xGLXRenderLargeReq;
totalRequests = 1 + (dataLen / maxSize);
if (dataLen % maxSize)
totalRequests++;
assert(headerLen <= maxSize);
__glXSendLargeChunk(ctx, 1, totalRequests, header, headerLen);
for (requestNumber = 2; requestNumber <= (totalRequests - 1);
requestNumber++) {
__glXSendLargeChunk(ctx, requestNumber, totalRequests, data, maxSize);
data = (const GLvoid *) (((const GLubyte *) data) + maxSize);
dataLen -= maxSize;
assert(dataLen > 0);
}
assert(dataLen <= maxSize);
__glXSendLargeChunk(ctx, requestNumber, totalRequests, data, dataLen);
}
#ifdef DEBUG
_X_HIDDEN void
__glXDumpDrawBuffer(__GLXcontext * ctx)
{
GLubyte *p = ctx->buf;
GLubyte *end = ctx->pc;
GLushort opcode, length;
while (p < end) {
opcode = *((GLushort *) p);
length = *((GLushort *) (p + 2));
printf("%2x: %5d: ", opcode, length);
length -= 4;
p += 4;
while (length > 0) {
printf("%08x ", *((unsigned *) p));
p += 4;
length -= 4;
}
printf("\n");
}
}
#endif