diff options
Diffstat (limited to 'src/glx')
-rw-r--r-- | src/glx/x11/dri2.c | 550 | ||||
-rw-r--r-- | src/glx/x11/dri2.h | 58 | ||||
-rw-r--r-- | src/glx/x11/dri2_glx.c | 718 | ||||
-rw-r--r-- | src/glx/x11/dri_common.c | 443 | ||||
-rw-r--r-- | src/glx/x11/dri_glx.c | 1069 | ||||
-rw-r--r-- | src/glx/x11/glx_pbuffer.c | 9 | ||||
-rw-r--r-- | src/glx/x11/glx_query.c | 46 | ||||
-rw-r--r-- | src/glx/x11/glxclient.h | 428 | ||||
-rw-r--r-- | src/glx/x11/glxcmds.c | 3689 | ||||
-rw-r--r-- | src/glx/x11/glxcurrent.c | 69 | ||||
-rw-r--r-- | src/glx/x11/glxext.c | 72 | ||||
-rw-r--r-- | src/glx/x11/glxextensions.c | 24 | ||||
-rw-r--r-- | src/glx/x11/indirect.c | 103 | ||||
-rw-r--r-- | src/glx/x11/indirect_size.c | 4 | ||||
-rw-r--r-- | src/glx/x11/indirect_vertex_array.c | 78 | ||||
-rw-r--r-- | src/glx/x11/single2.c | 156 |
16 files changed, 3794 insertions, 3722 deletions
diff --git a/src/glx/x11/dri2.c b/src/glx/x11/dri2.c index ebb2985924..e144ed3e1f 100644 --- a/src/glx/x11/dri2.c +++ b/src/glx/x11/dri2.c @@ -52,320 +52,328 @@ static char dri2ExtensionName[] = DRI2_NAME; static XExtensionInfo *dri2Info; static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay, dri2Info) + static /* const */ XExtensionHooks dri2ExtensionHooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - DRI2CloseDisplay, /* close_display */ - NULL, /* wire_to_event */ - NULL, /* event_to_wire */ - NULL, /* error */ - NULL, /* error_string */ + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + DRI2CloseDisplay, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ }; -static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay, dri2Info, - dri2ExtensionName, - &dri2ExtensionHooks, - 0, NULL) +static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay, + dri2Info, + dri2ExtensionName, + &dri2ExtensionHooks, + 0, NULL) -Bool DRI2QueryExtension(Display *dpy, int *eventBase, int *errorBase) +Bool +DRI2QueryExtension(Display * dpy, int *eventBase, int *errorBase) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); + XExtDisplayInfo *info = DRI2FindDisplay(dpy); - if (XextHasExtension(info)) { - *eventBase = info->codes->first_event; - *errorBase = info->codes->first_error; - return True; - } + if (XextHasExtension(info)) { + *eventBase = info->codes->first_event; + *errorBase = info->codes->first_error; + return True; + } - return False; + return False; } -Bool DRI2QueryVersion(Display *dpy, int *major, int *minor) +Bool +DRI2QueryVersion(Display * dpy, int *major, int *minor) { - XExtDisplayInfo *info = DRI2FindDisplay (dpy); - xDRI2QueryVersionReply rep; - xDRI2QueryVersionReq *req; - - XextCheckExtension (dpy, info, dri2ExtensionName, False); - - LockDisplay(dpy); - GetReq(DRI2QueryVersion, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2QueryVersion; - req->majorVersion = DRI2_MAJOR; - req->minorVersion = DRI2_MINOR; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - *major = rep.majorVersion; - *minor = rep.minorVersion; - UnlockDisplay(dpy); - SyncHandle(); - - return True; + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2QueryVersionReply rep; + xDRI2QueryVersionReq *req; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2QueryVersion, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2QueryVersion; + req->majorVersion = DRI2_MAJOR; + req->minorVersion = DRI2_MINOR; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + *major = rep.majorVersion; + *minor = rep.minorVersion; + UnlockDisplay(dpy); + SyncHandle(); + + return True; } -Bool DRI2Connect(Display *dpy, XID window, - char **driverName, char **deviceName) +Bool +DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2ConnectReply rep; - xDRI2ConnectReq *req; - - XextCheckExtension (dpy, info, dri2ExtensionName, False); - - LockDisplay(dpy); - GetReq(DRI2Connect, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2Connect; - req->window = window; - req->driverType = DRI2DriverDRI; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - - if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) { - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - - *driverName = Xmalloc(rep.driverNameLength + 1); - if (*driverName == NULL) { - _XEatData(dpy, - ((rep.driverNameLength + 3) & ~3) + - ((rep.deviceNameLength + 3) & ~3)); - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - _XReadPad(dpy, *driverName, rep.driverNameLength); - (*driverName)[rep.driverNameLength] = '\0'; - - *deviceName = Xmalloc(rep.deviceNameLength + 1); - if (*deviceName == NULL) { - Xfree(*driverName); - _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3)); - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - _XReadPad(dpy, *deviceName, rep.deviceNameLength); - (*deviceName)[rep.deviceNameLength] = '\0'; - - UnlockDisplay(dpy); - SyncHandle(); - - return True; + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2ConnectReply rep; + xDRI2ConnectReq *req; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2Connect, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2Connect; + req->window = window; + req->driverType = DRI2DriverDRI; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + *driverName = Xmalloc(rep.driverNameLength + 1); + if (*driverName == NULL) { + _XEatData(dpy, + ((rep.driverNameLength + 3) & ~3) + + ((rep.deviceNameLength + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + _XReadPad(dpy, *driverName, rep.driverNameLength); + (*driverName)[rep.driverNameLength] = '\0'; + + *deviceName = Xmalloc(rep.deviceNameLength + 1); + if (*deviceName == NULL) { + Xfree(*driverName); + _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + _XReadPad(dpy, *deviceName, rep.deviceNameLength); + (*deviceName)[rep.deviceNameLength] = '\0'; + + UnlockDisplay(dpy); + SyncHandle(); + + return True; } -Bool DRI2Authenticate(Display *dpy, XID window, drm_magic_t magic) +Bool +DRI2Authenticate(Display * dpy, XID window, drm_magic_t magic) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2AuthenticateReq *req; - xDRI2AuthenticateReply rep; + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2AuthenticateReq *req; + xDRI2AuthenticateReply rep; - XextCheckExtension (dpy, info, dri2ExtensionName, False); + XextCheckExtension(dpy, info, dri2ExtensionName, False); - LockDisplay(dpy); - GetReq(DRI2Authenticate, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2Authenticate; - req->window = window; - req->magic = magic; + LockDisplay(dpy); + GetReq(DRI2Authenticate, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2Authenticate; + req->window = window; + req->magic = magic; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; - } + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay(dpy); + SyncHandle(); - return rep.authenticated; + return rep.authenticated; } -void DRI2CreateDrawable(Display *dpy, XID drawable) +void +DRI2CreateDrawable(Display * dpy, XID drawable) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2CreateDrawableReq *req; - - XextSimpleCheckExtension (dpy, info, dri2ExtensionName); - - LockDisplay(dpy); - GetReq(DRI2CreateDrawable, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2CreateDrawable; - req->drawable = drawable; - UnlockDisplay(dpy); - SyncHandle(); + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2CreateDrawableReq *req; + + XextSimpleCheckExtension(dpy, info, dri2ExtensionName); + + LockDisplay(dpy); + GetReq(DRI2CreateDrawable, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2CreateDrawable; + req->drawable = drawable; + UnlockDisplay(dpy); + SyncHandle(); } -void DRI2DestroyDrawable(Display *dpy, XID drawable) +void +DRI2DestroyDrawable(Display * dpy, XID drawable) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2DestroyDrawableReq *req; + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2DestroyDrawableReq *req; - XextSimpleCheckExtension (dpy, info, dri2ExtensionName); + XextSimpleCheckExtension(dpy, info, dri2ExtensionName); - XSync(dpy, False); + XSync(dpy, False); - LockDisplay(dpy); - GetReq(DRI2DestroyDrawable, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2DestroyDrawable; - req->drawable = drawable; - UnlockDisplay(dpy); - SyncHandle(); + LockDisplay(dpy); + GetReq(DRI2DestroyDrawable, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2DestroyDrawable; + req->drawable = drawable; + UnlockDisplay(dpy); + SyncHandle(); } -DRI2Buffer *DRI2GetBuffers(Display *dpy, XID drawable, - int *width, int *height, - unsigned int *attachments, int count, - int *outCount) +DRI2Buffer * +DRI2GetBuffers(Display * dpy, XID drawable, + int *width, int *height, + unsigned int *attachments, int count, int *outCount) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2GetBuffersReply rep; - xDRI2GetBuffersReq *req; - DRI2Buffer *buffers; - xDRI2Buffer repBuffer; - CARD32 *p; - int i; - - XextCheckExtension (dpy, info, dri2ExtensionName, False); - - LockDisplay(dpy); - GetReqExtra(DRI2GetBuffers, count * 4, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2GetBuffers; - req->drawable = drawable; - req->count = count; - p = (CARD32 *) &req[1]; - for (i = 0; i < count; i++) - p[i] = attachments[i]; - - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return NULL; - } - - *width = rep.width; - *height = rep.height; - *outCount = rep.count; - - buffers = Xmalloc(rep.count * sizeof buffers[0]); - if (buffers == NULL) { - _XEatData(dpy, rep.count * sizeof repBuffer); - UnlockDisplay(dpy); - SyncHandle(); - return NULL; - } - - for (i = 0; i < rep.count; i++) { - _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer); - buffers[i].attachment = repBuffer.attachment; - buffers[i].name = repBuffer.name; - buffers[i].pitch = repBuffer.pitch; - buffers[i].cpp = repBuffer.cpp; - buffers[i].flags = repBuffer.flags; - } - - UnlockDisplay(dpy); - SyncHandle(); - - return buffers; + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2GetBuffersReply rep; + xDRI2GetBuffersReq *req; + DRI2Buffer *buffers; + xDRI2Buffer repBuffer; + CARD32 *p; + int i; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReqExtra(DRI2GetBuffers, count * 4, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2GetBuffers; + req->drawable = drawable; + req->count = count; + p = (CARD32 *) & req[1]; + for (i = 0; i < count; i++) + p[i] = attachments[i]; + + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + *width = rep.width; + *height = rep.height; + *outCount = rep.count; + + buffers = Xmalloc(rep.count * sizeof buffers[0]); + if (buffers == NULL) { + _XEatData(dpy, rep.count * sizeof repBuffer); + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + for (i = 0; i < rep.count; i++) { + _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer); + buffers[i].attachment = repBuffer.attachment; + buffers[i].name = repBuffer.name; + buffers[i].pitch = repBuffer.pitch; + buffers[i].cpp = repBuffer.cpp; + buffers[i].flags = repBuffer.flags; + } + + UnlockDisplay(dpy); + SyncHandle(); + + return buffers; } -DRI2Buffer *DRI2GetBuffersWithFormat(Display *dpy, XID drawable, - int *width, int *height, - unsigned int *attachments, int count, - int *outCount) +DRI2Buffer * +DRI2GetBuffersWithFormat(Display * dpy, XID drawable, + int *width, int *height, + unsigned int *attachments, int count, int *outCount) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2GetBuffersReply rep; - xDRI2GetBuffersReq *req; - DRI2Buffer *buffers; - xDRI2Buffer repBuffer; - CARD32 *p; - int i; - - XextCheckExtension (dpy, info, dri2ExtensionName, False); - - LockDisplay(dpy); - GetReqExtra(DRI2GetBuffers, count * (4 * 2), req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2GetBuffersWithFormat; - req->drawable = drawable; - req->count = count; - p = (CARD32 *) &req[1]; - for (i = 0; i < (count * 2); i++) - p[i] = attachments[i]; - - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return NULL; - } - - *width = rep.width; - *height = rep.height; - *outCount = rep.count; - - buffers = Xmalloc(rep.count * sizeof buffers[0]); - if (buffers == NULL) { - _XEatData(dpy, rep.count * sizeof repBuffer); - UnlockDisplay(dpy); - SyncHandle(); - return NULL; - } - - for (i = 0; i < rep.count; i++) { - _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer); - buffers[i].attachment = repBuffer.attachment; - buffers[i].name = repBuffer.name; - buffers[i].pitch = repBuffer.pitch; - buffers[i].cpp = repBuffer.cpp; - buffers[i].flags = repBuffer.flags; - } - - UnlockDisplay(dpy); - SyncHandle(); - - return buffers; + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2GetBuffersReply rep; + xDRI2GetBuffersReq *req; + DRI2Buffer *buffers; + xDRI2Buffer repBuffer; + CARD32 *p; + int i; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReqExtra(DRI2GetBuffers, count * (4 * 2), req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2GetBuffersWithFormat; + req->drawable = drawable; + req->count = count; + p = (CARD32 *) & req[1]; + for (i = 0; i < (count * 2); i++) + p[i] = attachments[i]; + + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + *width = rep.width; + *height = rep.height; + *outCount = rep.count; + + buffers = Xmalloc(rep.count * sizeof buffers[0]); + if (buffers == NULL) { + _XEatData(dpy, rep.count * sizeof repBuffer); + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + for (i = 0; i < rep.count; i++) { + _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer); + buffers[i].attachment = repBuffer.attachment; + buffers[i].name = repBuffer.name; + buffers[i].pitch = repBuffer.pitch; + buffers[i].cpp = repBuffer.cpp; + buffers[i].flags = repBuffer.flags; + } + + UnlockDisplay(dpy); + SyncHandle(); + + return buffers; } -void DRI2CopyRegion(Display *dpy, XID drawable, XserverRegion region, - CARD32 dest, CARD32 src) +void +DRI2CopyRegion(Display * dpy, XID drawable, XserverRegion region, + CARD32 dest, CARD32 src) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2CopyRegionReq *req; - xDRI2CopyRegionReply rep; + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2CopyRegionReq *req; + xDRI2CopyRegionReply rep; - XextSimpleCheckExtension (dpy, info, dri2ExtensionName); + XextSimpleCheckExtension(dpy, info, dri2ExtensionName); - LockDisplay(dpy); - GetReq(DRI2CopyRegion, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2CopyRegion; - req->drawable = drawable; - req->region = region; - req->dest = dest; - req->src = src; + LockDisplay(dpy); + GetReq(DRI2CopyRegion, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2CopyRegion; + req->drawable = drawable; + req->region = region; + req->dest = dest; + req->src = src; - _XReply(dpy, (xReply *)&rep, 0, xFalse); + _XReply(dpy, (xReply *) & rep, 0, xFalse); - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay(dpy); + SyncHandle(); } diff --git a/src/glx/x11/dri2.h b/src/glx/x11/dri2.h index b0e61f80d7..a6fe66e136 100644 --- a/src/glx/x11/dri2.h +++ b/src/glx/x11/dri2.h @@ -36,45 +36,53 @@ #include <X11/extensions/Xfixes.h> #include <X11/extensions/dri2tokens.h> -typedef struct { - unsigned int attachment; - unsigned int name; - unsigned int pitch; - unsigned int cpp; - unsigned int flags; +typedef struct +{ + unsigned int attachment; + unsigned int name; + unsigned int pitch; + unsigned int cpp; + unsigned int flags; } DRI2Buffer; extern Bool -DRI2QueryExtension(Display *display, int *eventBase, int *errorBase); +DRI2QueryExtension(Display * display, int *eventBase, int *errorBase); + extern Bool -DRI2QueryVersion(Display *display, int *major, int *minor); +DRI2QueryVersion(Display * display, int *major, int *minor); + extern Bool -DRI2Connect(Display *display, XID window, - char **driverName, char **deviceName); +DRI2Connect(Display * display, XID window, + char **driverName, char **deviceName); + extern Bool -DRI2Authenticate(Display *display, XID window, drm_magic_t magic); +DRI2Authenticate(Display * display, XID window, drm_magic_t magic); + extern void -DRI2CreateDrawable(Display *display, XID drawable); +DRI2CreateDrawable(Display * display, XID drawable); + extern void -DRI2DestroyDrawable(Display *display, XID handle); -extern DRI2Buffer * -DRI2GetBuffers(Display *dpy, XID drawable, - int *width, int *height, - unsigned int *attachments, int count, - int *outCount); +DRI2DestroyDrawable(Display * display, XID handle); + +extern DRI2Buffer* +DRI2GetBuffers(Display * dpy, XID drawable, + int *width, int *height, + unsigned int *attachments, int count, + int *outCount); /** * \note * This function is only supported with DRI2 version 1.1 or later. */ -extern DRI2Buffer * -DRI2GetBuffersWithFormat(Display *dpy, XID drawable, - int *width, int *height, - unsigned int *attachments, int count, - int *outCount); +extern DRI2Buffer* +DRI2GetBuffersWithFormat(Display * dpy, XID drawable, + int *width, int *height, + unsigned int *attachments, + int count, int *outCount); extern void -DRI2CopyRegion(Display *dpy, XID drawable, XserverRegion region, - CARD32 dest, CARD32 src); +DRI2CopyRegion(Display * dpy, XID drawable, + XserverRegion region, + CARD32 dest, CARD32 src); #endif diff --git a/src/glx/x11/dri2_glx.c b/src/glx/x11/dri2_glx.c index c5635a94ab..89efe3ab29 100644 --- a/src/glx/x11/dri2_glx.c +++ b/src/glx/x11/dri2_glx.c @@ -54,242 +54,260 @@ typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate; typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate; typedef struct __GLXDRIdrawablePrivateRec __GLXDRIdrawablePrivate; -struct __GLXDRIdisplayPrivateRec { - __GLXDRIdisplay base; +struct __GLXDRIdisplayPrivateRec +{ + __GLXDRIdisplay base; - /* + /* ** XFree86-DRI version information */ - int driMajor; - int driMinor; - int driPatch; + int driMajor; + int driMinor; + int driPatch; }; -struct __GLXDRIcontextPrivateRec { - __GLXDRIcontext base; - __DRIcontext *driContext; - __GLXscreenConfigs *psc; +struct __GLXDRIcontextPrivateRec +{ + __GLXDRIcontext base; + __DRIcontext *driContext; + __GLXscreenConfigs *psc; }; -struct __GLXDRIdrawablePrivateRec { - __GLXDRIdrawable base; - __DRIbuffer buffers[5]; - int bufferCount; - int width, height; - int have_back; - int have_fake_front; +struct __GLXDRIdrawablePrivateRec +{ + __GLXDRIdrawable base; + __DRIbuffer buffers[5]; + int bufferCount; + int width, height; + int have_back; + int have_fake_front; }; -static void dri2DestroyContext(__GLXDRIcontext *context, - __GLXscreenConfigs *psc, Display *dpy) +static void dri2WaitX(__GLXDRIdrawable * pdraw); + +static void +dri2DestroyContext(__GLXDRIcontext * context, + __GLXscreenConfigs * psc, Display * dpy) { - __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; - const __DRIcoreExtension *core = pcp->psc->core; + __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + const __DRIcoreExtension *core = pcp->psc->core; - (*core->destroyContext)(pcp->driContext); + (*core->destroyContext) (pcp->driContext); - Xfree(pcp); + Xfree(pcp); } -static Bool dri2BindContext(__GLXDRIcontext *context, - __GLXDRIdrawable *draw, __GLXDRIdrawable *read) +static Bool +dri2BindContext(__GLXDRIcontext * context, + __GLXDRIdrawable * draw, __GLXDRIdrawable * read) { - __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; - const __DRIcoreExtension *core = pcp->psc->core; + __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + const __DRIcoreExtension *core = pcp->psc->core; - return (*core->bindContext)(pcp->driContext, - draw->driDrawable, - read->driDrawable); + return (*core->bindContext) (pcp->driContext, + draw->driDrawable, read->driDrawable); } -static void dri2UnbindContext(__GLXDRIcontext *context) +static void +dri2UnbindContext(__GLXDRIcontext * context) { - __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; - const __DRIcoreExtension *core = pcp->psc->core; + __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + const __DRIcoreExtension *core = pcp->psc->core; - (*core->unbindContext)(pcp->driContext); + (*core->unbindContext) (pcp->driContext); } -static __GLXDRIcontext *dri2CreateContext(__GLXscreenConfigs *psc, - const __GLcontextModes *mode, - GLXContext gc, - GLXContext shareList, int renderType) +static __GLXDRIcontext * +dri2CreateContext(__GLXscreenConfigs * psc, + const __GLcontextModes * mode, + GLXContext gc, GLXContext shareList, int renderType) { - __GLXDRIcontextPrivate *pcp, *pcp_shared; - __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; - __DRIcontext *shared = NULL; - - if (shareList) { - pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext; - shared = pcp_shared->driContext; - } - - pcp = Xmalloc(sizeof *pcp); - if (pcp == NULL) - return NULL; - - pcp->psc = psc; - pcp->driContext = - (*psc->dri2->createNewContext)(psc->__driScreen, - config->driConfig, shared, pcp); - gc->__driContext = pcp->driContext; - - if (pcp->driContext == NULL) { - Xfree(pcp); - return NULL; - } - - pcp->base.destroyContext = dri2DestroyContext; - pcp->base.bindContext = dri2BindContext; - pcp->base.unbindContext = dri2UnbindContext; - - return &pcp->base; + __GLXDRIcontextPrivate *pcp, *pcp_shared; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; + __DRIcontext *shared = NULL; + + if (shareList) { + pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext; + shared = pcp_shared->driContext; + } + + pcp = Xmalloc(sizeof *pcp); + if (pcp == NULL) + return NULL; + + pcp->psc = psc; + pcp->driContext = + (*psc->dri2->createNewContext) (psc->__driScreen, + config->driConfig, shared, pcp); + gc->__driContext = pcp->driContext; + + if (pcp->driContext == NULL) { + Xfree(pcp); + return NULL; + } + + pcp->base.destroyContext = dri2DestroyContext; + pcp->base.bindContext = dri2BindContext; + pcp->base.unbindContext = dri2UnbindContext; + + return &pcp->base; } -static void dri2DestroyDrawable(__GLXDRIdrawable *pdraw) +static void +dri2DestroyDrawable(__GLXDRIdrawable * pdraw) { - const __DRIcoreExtension *core = pdraw->psc->core; + const __DRIcoreExtension *core = pdraw->psc->core; - (*core->destroyDrawable)(pdraw->driDrawable); - DRI2DestroyDrawable(pdraw->psc->dpy, pdraw->drawable); - Xfree(pdraw); + (*core->destroyDrawable) (pdraw->driDrawable); + DRI2DestroyDrawable(pdraw->psc->dpy, pdraw->xDrawable); + Xfree(pdraw); } -static __GLXDRIdrawable *dri2CreateDrawable(__GLXscreenConfigs *psc, - XID xDrawable, - GLXDrawable drawable, - const __GLcontextModes *modes) +static __GLXDRIdrawable * +dri2CreateDrawable(__GLXscreenConfigs * psc, + XID xDrawable, + GLXDrawable drawable, const __GLcontextModes * modes) { - __GLXDRIdrawablePrivate *pdraw; - __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; + __GLXDRIdrawablePrivate *pdraw; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; - pdraw = Xmalloc(sizeof(*pdraw)); - if (!pdraw) - return NULL; + pdraw = Xmalloc(sizeof(*pdraw)); + if (!pdraw) + return NULL; - pdraw->base.destroyDrawable = dri2DestroyDrawable; - pdraw->base.xDrawable = xDrawable; - pdraw->base.drawable = drawable; - pdraw->base.psc = psc; - pdraw->bufferCount = 0; + pdraw->base.destroyDrawable = dri2DestroyDrawable; + pdraw->base.xDrawable = xDrawable; + pdraw->base.drawable = drawable; + pdraw->base.psc = psc; + pdraw->bufferCount = 0; - DRI2CreateDrawable(psc->dpy, xDrawable); + DRI2CreateDrawable(psc->dpy, xDrawable); - /* Create a new drawable */ - pdraw->base.driDrawable = - (*psc->dri2->createNewDrawable)(psc->__driScreen, - config->driConfig, pdraw); + /* Create a new drawable */ + pdraw->base.driDrawable = + (*psc->dri2->createNewDrawable) (psc->__driScreen, + config->driConfig, pdraw); - if (!pdraw->base.driDrawable) { - DRI2DestroyDrawable(psc->dpy, drawable); - Xfree(pdraw); - return NULL; - } + if (!pdraw->base.driDrawable) { + DRI2DestroyDrawable(psc->dpy, xDrawable); + Xfree(pdraw); + return NULL; + } - return &pdraw->base; + return &pdraw->base; } -static void dri2CopySubBuffer(__GLXDRIdrawable *pdraw, - int x, int y, int width, int height) +static void +dri2CopySubBuffer(__GLXDRIdrawable * pdraw, + int x, int y, int width, int height) { - __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw; - XRectangle xrect; - XserverRegion region; + __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw; + XRectangle xrect; + XserverRegion region; - /* Check we have the right attachments */ - if (!priv->have_back) - return; + /* Check we have the right attachments */ + if (!priv->have_back) + return; - xrect.x = x; - xrect.y = priv->height - y - height; - xrect.width = width; - xrect.height = height; + xrect.x = x; + xrect.y = priv->height - y - height; + xrect.width = width; + xrect.height = height; #ifdef __DRI2_FLUSH - if (pdraw->psc->f) - (*pdraw->psc->f->flush)(pdraw->driDrawable); + if (pdraw->psc->f) + (*pdraw->psc->f->flush) (pdraw->driDrawable); #endif - region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1); - /* should get a fence ID back from here at some point */ - DRI2CopyRegion(pdraw->psc->dpy, pdraw->drawable, region, - DRI2BufferFrontLeft, DRI2BufferBackLeft); - XFixesDestroyRegion(pdraw->psc->dpy, region); + region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1); + /* should get a fence ID back from here at some point */ + DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region, + DRI2BufferFrontLeft, DRI2BufferBackLeft); + XFixesDestroyRegion(pdraw->psc->dpy, region); + + /* Refresh the fake front (if present) after we just damaged the real + * front. + */ + dri2WaitX(pdraw); } -static void dri2SwapBuffers(__GLXDRIdrawable *pdraw) +static void +dri2SwapBuffers(__GLXDRIdrawable * pdraw) { - __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw; + __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw; - dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height); + dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height); } -static void dri2WaitX(__GLXDRIdrawable *pdraw) +static void +dri2WaitX(__GLXDRIdrawable * pdraw) { - __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw; - XRectangle xrect; - XserverRegion region; + __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw; + XRectangle xrect; + XserverRegion region; - /* Check we have the right attachments */ - if (!priv->have_fake_front) - return; + /* Check we have the right attachments */ + if (!priv->have_fake_front) + return; - xrect.x = 0; - xrect.y = 0; - xrect.width = priv->width; - xrect.height = priv->height; + xrect.x = 0; + xrect.y = 0; + xrect.width = priv->width; + xrect.height = priv->height; #ifdef __DRI2_FLUSH - if (pdraw->psc->f) - (*pdraw->psc->f->flush)(pdraw->driDrawable); + if (pdraw->psc->f) + (*pdraw->psc->f->flush) (pdraw->driDrawable); #endif - region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1); - DRI2CopyRegion(pdraw->psc->dpy, pdraw->drawable, region, - DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft); - XFixesDestroyRegion(pdraw->psc->dpy, region); + region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1); + DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region, + DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft); + XFixesDestroyRegion(pdraw->psc->dpy, region); } -static void dri2WaitGL(__GLXDRIdrawable *pdraw) +static void +dri2WaitGL(__GLXDRIdrawable * pdraw) { - __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw; - XRectangle xrect; - XserverRegion region; + __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw; + XRectangle xrect; + XserverRegion region; - if (!priv->have_fake_front) - return; + if (!priv->have_fake_front) + return; - xrect.x = 0; - xrect.y = 0; - xrect.width = priv->width; - xrect.height = priv->height; + xrect.x = 0; + xrect.y = 0; + xrect.width = priv->width; + xrect.height = priv->height; #ifdef __DRI2_FLUSH - if (pdraw->psc->f) - (*pdraw->psc->f->flush)(pdraw->driDrawable); + if (pdraw->psc->f) + (*pdraw->psc->f->flush) (pdraw->driDrawable); #endif - region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1); - DRI2CopyRegion(pdraw->psc->dpy, pdraw->drawable, region, - DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft); - XFixesDestroyRegion(pdraw->psc->dpy, region); + region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1); + DRI2CopyRegion(pdraw->psc->dpy, pdraw->xDrawable, region, + DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft); + XFixesDestroyRegion(pdraw->psc->dpy, region); } -static void dri2FlushFrontBuffer(__DRIdrawable *driDrawable, - void *loaderPrivate) +static void +dri2FlushFrontBuffer(__DRIdrawable * driDrawable, void *loaderPrivate) { - (void) driDrawable; - dri2WaitGL((__GLXDRIdrawable *) loaderPrivate); + (void) driDrawable; + dri2WaitGL((__GLXDRIdrawable *) loaderPrivate); } -static void dri2DestroyScreen(__GLXscreenConfigs *psc) +static void +dri2DestroyScreen(__GLXscreenConfigs * psc) { - /* Free the direct rendering per screen data */ - (*psc->core->destroyScreen)(psc->__driScreen); - close(psc->fd); - psc->__driScreen = NULL; + /* Free the direct rendering per screen data */ + (*psc->core->destroyScreen) (psc->__driScreen); + close(psc->fd); + psc->__driScreen = NULL; } /** @@ -299,221 +317,222 @@ static void dri2DestroyScreen(__GLXscreenConfigs *psc) * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat. */ static void -process_buffers(__GLXDRIdrawablePrivate *pdraw, DRI2Buffer *buffers, - unsigned count) +process_buffers(__GLXDRIdrawablePrivate * pdraw, DRI2Buffer * buffers, + unsigned count) { - int i; - - pdraw->bufferCount = count; - pdraw->have_fake_front = 0; - pdraw->have_back = 0; - - /* This assumes the DRI2 buffer attachment tokens matches the - * __DRIbuffer tokens. */ - for (i = 0; i < count; i++) { - pdraw->buffers[i].attachment = buffers[i].attachment; - pdraw->buffers[i].name = buffers[i].name; - pdraw->buffers[i].pitch = buffers[i].pitch; - pdraw->buffers[i].cpp = buffers[i].cpp; - pdraw->buffers[i].flags = buffers[i].flags; - if (pdraw->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT) - pdraw->have_fake_front = 1; - if (pdraw->buffers[i].attachment == __DRI_BUFFER_BACK_LEFT) - pdraw->have_back = 1; - } + int i; + + pdraw->bufferCount = count; + pdraw->have_fake_front = 0; + pdraw->have_back = 0; + + /* This assumes the DRI2 buffer attachment tokens matches the + * __DRIbuffer tokens. */ + for (i = 0; i < count; i++) { + pdraw->buffers[i].attachment = buffers[i].attachment; + pdraw->buffers[i].name = buffers[i].name; + pdraw->buffers[i].pitch = buffers[i].pitch; + pdraw->buffers[i].cpp = buffers[i].cpp; + pdraw->buffers[i].flags = buffers[i].flags; + if (pdraw->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT) + pdraw->have_fake_front = 1; + if (pdraw->buffers[i].attachment == __DRI_BUFFER_BACK_LEFT) + pdraw->have_back = 1; + } } static __DRIbuffer * -dri2GetBuffers(__DRIdrawable *driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *loaderPrivate) +dri2GetBuffers(__DRIdrawable * driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate) { - __GLXDRIdrawablePrivate *pdraw = loaderPrivate; - DRI2Buffer *buffers; + __GLXDRIdrawablePrivate *pdraw = loaderPrivate; + DRI2Buffer *buffers; - buffers = DRI2GetBuffers(pdraw->base.psc->dpy, pdraw->base.xDrawable, - width, height, attachments, count, out_count); - if (buffers == NULL) - return NULL; + buffers = DRI2GetBuffers(pdraw->base.psc->dpy, pdraw->base.xDrawable, + width, height, attachments, count, out_count); + if (buffers == NULL) + return NULL; - pdraw->width = *width; - pdraw->height = *height; - process_buffers(pdraw, buffers, *out_count); + pdraw->width = *width; + pdraw->height = *height; + process_buffers(pdraw, buffers, *out_count); - Xfree(buffers); + Xfree(buffers); - return pdraw->buffers; + return pdraw->buffers; } static __DRIbuffer * -dri2GetBuffersWithFormat(__DRIdrawable *driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *loaderPrivate) +dri2GetBuffersWithFormat(__DRIdrawable * driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate) { - __GLXDRIdrawablePrivate *pdraw = loaderPrivate; - DRI2Buffer *buffers; + __GLXDRIdrawablePrivate *pdraw = loaderPrivate; + DRI2Buffer *buffers; - buffers = DRI2GetBuffersWithFormat(pdraw->base.psc->dpy, - pdraw->base.xDrawable, - width, height, attachments, - count, out_count); - if (buffers == NULL) - return NULL; + buffers = DRI2GetBuffersWithFormat(pdraw->base.psc->dpy, + pdraw->base.xDrawable, + width, height, attachments, + count, out_count); + if (buffers == NULL) + return NULL; - pdraw->width = *width; - pdraw->height = *height; - process_buffers(pdraw, buffers, *out_count); + pdraw->width = *width; + pdraw->height = *height; + process_buffers(pdraw, buffers, *out_count); - Xfree(buffers); + Xfree(buffers); - return pdraw->buffers; + return pdraw->buffers; } static const __DRIdri2LoaderExtension dri2LoaderExtension = { - { __DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION }, - dri2GetBuffers, - dri2FlushFrontBuffer, - dri2GetBuffersWithFormat, + {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION}, + dri2GetBuffers, + dri2FlushFrontBuffer, + dri2GetBuffersWithFormat, }; static const __DRIdri2LoaderExtension dri2LoaderExtension_old = { - { __DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION }, - dri2GetBuffers, - dri2FlushFrontBuffer, - NULL, + {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION}, + dri2GetBuffers, + dri2FlushFrontBuffer, + NULL, }; static const __DRIextension *loader_extensions[] = { - &dri2LoaderExtension.base, - &systemTimeExtension.base, - NULL + &dri2LoaderExtension.base, + &systemTimeExtension.base, + NULL }; static const __DRIextension *loader_extensions_old[] = { - &dri2LoaderExtension_old.base, - &systemTimeExtension.base, - NULL + &dri2LoaderExtension_old.base, + &systemTimeExtension.base, + NULL }; -static __GLXDRIscreen *dri2CreateScreen(__GLXscreenConfigs *psc, int screen, - __GLXdisplayPrivate *priv) +static __GLXDRIscreen * +dri2CreateScreen(__GLXscreenConfigs * psc, int screen, + __GLXdisplayPrivate * priv) { - const __DRIconfig **driver_configs; - const __DRIextension **extensions; - const __GLXDRIdisplayPrivate *const pdp = (__GLXDRIdisplayPrivate *) + const __DRIconfig **driver_configs; + const __DRIextension **extensions; + const __GLXDRIdisplayPrivate *const pdp = (__GLXDRIdisplayPrivate *) priv->dri2Display; - __GLXDRIscreen *psp; - char *driverName, *deviceName; - drm_magic_t magic; - int i; - - psp = Xmalloc(sizeof *psp); - if (psp == NULL) - return NULL; - - /* Initialize per screen dynamic client GLX extensions */ - psc->ext_list_first_time = GL_TRUE; - - if (!DRI2Connect(psc->dpy, RootWindow(psc->dpy, screen), - &driverName, &deviceName)) - return NULL; - - psc->driver = driOpenDriver(driverName); - if (psc->driver == NULL) { - ErrorMessageF("driver pointer missing\n"); - goto handle_error; - } - - extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); - if (extensions == NULL) { - ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); - goto handle_error; - } - - for (i = 0; extensions[i]; i++) { - if (strcmp(extensions[i]->name, __DRI_CORE) == 0) - psc->core = (__DRIcoreExtension *) extensions[i]; - if (strcmp(extensions[i]->name, __DRI_DRI2) == 0) - psc->dri2 = (__DRIdri2Extension *) extensions[i]; - } - - if (psc->core == NULL || psc->dri2 == NULL) { - ErrorMessageF("core dri or dri2 extension not found\n"); - goto handle_error; - } - - psc->fd = open(deviceName, O_RDWR); - if (psc->fd < 0) { - ErrorMessageF("failed to open drm device: %s\n", strerror(errno)); - return NULL; - } - - if (drmGetMagic(psc->fd, &magic)) { - ErrorMessageF("failed to get magic\n"); - return NULL; - } - - if (!DRI2Authenticate(psc->dpy, RootWindow(psc->dpy, screen), magic)) { - ErrorMessageF("failed to authenticate magic %d\n", magic); - return NULL; - } - - /* If the server does not support the protocol for - * DRI2GetBuffersWithFormat, don't supply that interface to the driver. - */ - psc->__driScreen = - psc->dri2->createNewScreen(screen, psc->fd, - ((pdp->driMinor < 1) - ? loader_extensions_old - : loader_extensions), - &driver_configs, psc); - - if (psc->__driScreen == NULL) { - ErrorMessageF("failed to create dri screen\n"); - return NULL; - } - - driBindExtensions(psc, 1); - - psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs); - psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs); - - psc->driver_configs = driver_configs; - - psp->destroyScreen = dri2DestroyScreen; - psp->createContext = dri2CreateContext; - psp->createDrawable = dri2CreateDrawable; - psp->swapBuffers = dri2SwapBuffers; - psp->waitGL = dri2WaitGL; - psp->waitX = dri2WaitX; - - /* DRI2 suports SubBuffer through DRI2CopyRegion, so it's always - * available.*/ - psp->copySubBuffer = dri2CopySubBuffer; - __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer"); - - Xfree(driverName); - Xfree(deviceName); - - return psp; + __GLXDRIscreen *psp; + char *driverName, *deviceName; + drm_magic_t magic; + int i; + + psp = Xmalloc(sizeof *psp); + if (psp == NULL) + return NULL; + + /* Initialize per screen dynamic client GLX extensions */ + psc->ext_list_first_time = GL_TRUE; + + if (!DRI2Connect(psc->dpy, RootWindow(psc->dpy, screen), + &driverName, &deviceName)) + return NULL; + + psc->driver = driOpenDriver(driverName); + if (psc->driver == NULL) { + ErrorMessageF("driver pointer missing\n"); + goto handle_error; + } + + extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); + if (extensions == NULL) { + ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); + goto handle_error; + } + + for (i = 0; extensions[i]; i++) { + if (strcmp(extensions[i]->name, __DRI_CORE) == 0) + psc->core = (__DRIcoreExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_DRI2) == 0) + psc->dri2 = (__DRIdri2Extension *) extensions[i]; + } + + if (psc->core == NULL || psc->dri2 == NULL) { + ErrorMessageF("core dri or dri2 extension not found\n"); + goto handle_error; + } + + psc->fd = open(deviceName, O_RDWR); + if (psc->fd < 0) { + ErrorMessageF("failed to open drm device: %s\n", strerror(errno)); + return NULL; + } + + if (drmGetMagic(psc->fd, &magic)) { + ErrorMessageF("failed to get magic\n"); + return NULL; + } + + if (!DRI2Authenticate(psc->dpy, RootWindow(psc->dpy, screen), magic)) { + ErrorMessageF("failed to authenticate magic %d\n", magic); + return NULL; + } + + /* If the server does not support the protocol for + * DRI2GetBuffersWithFormat, don't supply that interface to the driver. + */ + psc->__driScreen = + psc->dri2->createNewScreen(screen, psc->fd, ((pdp->driMinor < 1) + ? loader_extensions_old + : loader_extensions), + &driver_configs, psc); + + if (psc->__driScreen == NULL) { + ErrorMessageF("failed to create dri screen\n"); + return NULL; + } + + driBindExtensions(psc, 1); + + psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs); + psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs); + + psc->driver_configs = driver_configs; + + psp->destroyScreen = dri2DestroyScreen; + psp->createContext = dri2CreateContext; + psp->createDrawable = dri2CreateDrawable; + psp->swapBuffers = dri2SwapBuffers; + psp->waitGL = dri2WaitGL; + psp->waitX = dri2WaitX; + + /* DRI2 suports SubBuffer through DRI2CopyRegion, so it's always + * available.*/ + psp->copySubBuffer = dri2CopySubBuffer; + __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer"); + + Xfree(driverName); + Xfree(deviceName); + + return psp; handle_error: - Xfree(driverName); - Xfree(deviceName); + Xfree(driverName); + Xfree(deviceName); - /* FIXME: clean up here */ + /* FIXME: clean up here */ - return NULL; + return NULL; } /* Called from __glXFreeDisplayPrivate. */ -static void dri2DestroyDisplay(__GLXDRIdisplay *dpy) +static void +dri2DestroyDisplay(__GLXDRIdisplay * dpy) { - Xfree(dpy); + Xfree(dpy); } /* @@ -521,29 +540,30 @@ static void dri2DestroyDisplay(__GLXDRIdisplay *dpy) * This is called from __glXInitialize() when we are given a new * display pointer. */ -_X_HIDDEN __GLXDRIdisplay *dri2CreateDisplay(Display *dpy) +_X_HIDDEN __GLXDRIdisplay * +dri2CreateDisplay(Display * dpy) { - __GLXDRIdisplayPrivate *pdp; - int eventBase, errorBase; + __GLXDRIdisplayPrivate *pdp; + int eventBase, errorBase; - if (!DRI2QueryExtension(dpy, &eventBase, &errorBase)) - return NULL; + if (!DRI2QueryExtension(dpy, &eventBase, &errorBase)) + return NULL; - pdp = Xmalloc(sizeof *pdp); - if (pdp == NULL) - return NULL; + pdp = Xmalloc(sizeof *pdp); + if (pdp == NULL) + return NULL; - if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) { - Xfree(pdp); - return NULL; - } + if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) { + Xfree(pdp); + return NULL; + } - pdp->driPatch = 0; + pdp->driPatch = 0; - pdp->base.destroyDisplay = dri2DestroyDisplay; - pdp->base.createScreen = dri2CreateScreen; + pdp->base.destroyDisplay = dri2DestroyDisplay; + pdp->base.createScreen = dri2CreateScreen; - return &pdp->base; + return &pdp->base; } #endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/x11/dri_common.c b/src/glx/x11/dri_common.c index 6de4111113..9c825ad74a 100644 --- a/src/glx/x11/dri_common.c +++ b/src/glx/x11/dri_common.c @@ -49,33 +49,35 @@ #define RTLD_GLOBAL 0 #endif -_X_HIDDEN void InfoMessageF(const char *f, ...) +_X_HIDDEN void +InfoMessageF(const char *f, ...) { - va_list args; - const char *env; - - if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) { - fprintf(stderr, "libGL: "); - va_start(args, f); - vfprintf(stderr, f, args); - va_end(args); - } + va_list args; + const char *env; + + if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) { + fprintf(stderr, "libGL: "); + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + } } /** * Print error to stderr, unless LIBGL_DEBUG=="quiet". */ -_X_HIDDEN void ErrorMessageF(const char *f, ...) +_X_HIDDEN void +ErrorMessageF(const char *f, ...) { - va_list args; - const char *env; - - if ((env = getenv("LIBGL_DEBUG")) && !strstr(env, "quiet")) { - fprintf(stderr, "libGL error: "); - va_start(args, f); - vfprintf(stderr, f, args); - va_end(args); - } + va_list args; + const char *env; + + if ((env = getenv("LIBGL_DEBUG")) && !strstr(env, "quiet")) { + fprintf(stderr, "libGL error: "); + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + } } #ifndef DEFAULT_DRIVER_DIR @@ -95,7 +97,8 @@ _X_HIDDEN void ErrorMessageF(const char *f, ...) * \returns * A handle from \c dlopen, or \c NULL if driver file not found. */ -_X_HIDDEN void *driOpenDriver(const char *driverName) +_X_HIDDEN void * +driOpenDriver(const char *driverName) { void *glhandle, *handle; const char *libPaths, *p, *next; @@ -110,40 +113,41 @@ _X_HIDDEN void *driOpenDriver(const char *driverName) /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ libPaths = getenv("LIBGL_DRIVERS_PATH"); if (!libPaths) - libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */ + libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */ } if (libPaths == NULL) - libPaths = DEFAULT_DRIVER_DIR; + libPaths = DEFAULT_DRIVER_DIR; handle = NULL; for (p = libPaths; *p; p = next) { - next = strchr(p, ':'); - if (next == NULL) { - len = strlen(p); - next = p + len; - } else { - len = next - p; - next++; - } + next = strchr(p, ':'); + if (next == NULL) { + len = strlen(p); + next = p + len; + } + else { + len = next - p; + next++; + } #ifdef GLX_USE_TLS snprintf(realDriverName, sizeof realDriverName, - "%.*s/tls/%s_dri.so", len, p, driverName); + "%.*s/tls/%s_dri.so", len, p, driverName); InfoMessageF("OpenDriver: trying %s\n", realDriverName); handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL); #endif - if ( handle == NULL ) { - snprintf(realDriverName, sizeof realDriverName, - "%.*s/%s_dri.so", len, p, driverName); - InfoMessageF("OpenDriver: trying %s\n", realDriverName); - handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL); + if (handle == NULL) { + snprintf(realDriverName, sizeof realDriverName, + "%.*s/%s_dri.so", len, p, driverName); + InfoMessageF("OpenDriver: trying %s\n", realDriverName); + handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL); } - if ( handle != NULL ) - break; + if (handle != NULL) + break; else - ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror()); + ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror()); } if (!handle) @@ -156,253 +160,258 @@ _X_HIDDEN void *driOpenDriver(const char *driverName) } _X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension = { - { __DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION }, - __glXGetUST, - __driGetMscRateOML + {__DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION}, + __glXGetUST, + __driGetMscRateOML }; #define __ATTRIB(attrib, field) \ { attrib, offsetof(__GLcontextModes, field) } -static const struct { unsigned int attrib, offset; } attribMap[] = { - __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits), - __ATTRIB(__DRI_ATTRIB_LEVEL, level), - __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits), - __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits), - __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits), - __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits), - __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits), - __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits), - __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits), - __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits), - __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits), - __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits), - __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers), - __ATTRIB(__DRI_ATTRIB_SAMPLES, samples), - __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode), - __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode), - __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers), +static const struct +{ + unsigned int attrib, offset; +} attribMap[] = { + __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits), + __ATTRIB(__DRI_ATTRIB_LEVEL, level), + __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits), + __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits), + __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits), + __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits), + __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits), + __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits), + __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers), + __ATTRIB(__DRI_ATTRIB_SAMPLES, samples), + __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode), + __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode), + __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers), #if 0 - __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel), - __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentIndex), - __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed), - __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen), - __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue), - __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha), - __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask), - __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask), - __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask), - __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentIndex), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha), + __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask), + __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask), + __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask), + __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask), #endif - __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth), - __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight), - __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels), - __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth), - __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels), + __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth), + __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight), #if 0 - __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod), + __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod), #endif - __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb), - __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba), - __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture), - __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted), -}; +__ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba), + __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, + bindToMipmapTexture), + __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),}; #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) static int -scalarEqual(__GLcontextModes *mode, unsigned int attrib, unsigned int value) +scalarEqual(__GLcontextModes * mode, unsigned int attrib, unsigned int value) { - unsigned int glxValue; - int i; + unsigned int glxValue; + int i; - for (i = 0; i < ARRAY_SIZE(attribMap); i++) - if (attribMap[i].attrib == attrib) { - glxValue = *(unsigned int *) ((char *) mode + attribMap[i].offset); - return glxValue == GLX_DONT_CARE || glxValue == value; - } + for (i = 0; i < ARRAY_SIZE(attribMap); i++) + if (attribMap[i].attrib == attrib) { + glxValue = *(unsigned int *) ((char *) mode + attribMap[i].offset); + return glxValue == GLX_DONT_CARE || glxValue == value; + } - return GL_TRUE; /* Is a non-existing attribute equal to value? */ + return GL_TRUE; /* Is a non-existing attribute equal to value? */ } static int -driConfigEqual(const __DRIcoreExtension *core, - __GLcontextModes *modes, const __DRIconfig *driConfig) +driConfigEqual(const __DRIcoreExtension * core, + __GLcontextModes * modes, const __DRIconfig * driConfig) { - unsigned int attrib, value, glxValue; - int i; - - i = 0; - while (core->indexConfigAttrib(driConfig, i++, &attrib, &value)) { - switch (attrib) { - case __DRI_ATTRIB_RENDER_TYPE: - glxValue = 0; - if (value & __DRI_ATTRIB_RGBA_BIT) { - glxValue |= GLX_RGBA_BIT; - } else if (value & __DRI_ATTRIB_COLOR_INDEX_BIT) { - glxValue |= GLX_COLOR_INDEX_BIT; - } - if (glxValue != modes->renderType) - return GL_FALSE; - break; - - case __DRI_ATTRIB_CONFIG_CAVEAT: - if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) - glxValue = GLX_NON_CONFORMANT_CONFIG; - else if (value & __DRI_ATTRIB_SLOW_BIT) - glxValue = GLX_SLOW_CONFIG; - else - glxValue = GLX_NONE; - if (glxValue != modes->visualRating) - return GL_FALSE; - break; - - case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS: - glxValue = 0; - if (value & __DRI_ATTRIB_TEXTURE_1D_BIT) - glxValue |= GLX_TEXTURE_1D_BIT_EXT; - if (value & __DRI_ATTRIB_TEXTURE_2D_BIT) - glxValue |= GLX_TEXTURE_2D_BIT_EXT; - if (value & __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT) - glxValue |= GLX_TEXTURE_RECTANGLE_BIT_EXT; - if (modes->bindToTextureTargets != GLX_DONT_CARE && - glxValue != modes->bindToTextureTargets) - return GL_FALSE; - break; - - default: - if (!scalarEqual(modes, attrib, value)) - return GL_FALSE; - } - } - - return GL_TRUE; + unsigned int attrib, value, glxValue; + int i; + + i = 0; + while (core->indexConfigAttrib(driConfig, i++, &attrib, &value)) { + switch (attrib) { + case __DRI_ATTRIB_RENDER_TYPE: + glxValue = 0; + if (value & __DRI_ATTRIB_RGBA_BIT) { + glxValue |= GLX_RGBA_BIT; + } + else if (value & __DRI_ATTRIB_COLOR_INDEX_BIT) { + glxValue |= GLX_COLOR_INDEX_BIT; + } + if (glxValue != modes->renderType) + return GL_FALSE; + break; + + case __DRI_ATTRIB_CONFIG_CAVEAT: + if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) + glxValue = GLX_NON_CONFORMANT_CONFIG; + else if (value & __DRI_ATTRIB_SLOW_BIT) + glxValue = GLX_SLOW_CONFIG; + else + glxValue = GLX_NONE; + if (glxValue != modes->visualRating) + return GL_FALSE; + break; + + case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS: + glxValue = 0; + if (value & __DRI_ATTRIB_TEXTURE_1D_BIT) + glxValue |= GLX_TEXTURE_1D_BIT_EXT; + if (value & __DRI_ATTRIB_TEXTURE_2D_BIT) + glxValue |= GLX_TEXTURE_2D_BIT_EXT; + if (value & __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT) + glxValue |= GLX_TEXTURE_RECTANGLE_BIT_EXT; + if (modes->bindToTextureTargets != GLX_DONT_CARE && + glxValue != modes->bindToTextureTargets) + return GL_FALSE; + break; + + default: + if (!scalarEqual(modes, attrib, value)) + return GL_FALSE; + } + } + + return GL_TRUE; } static __GLcontextModes * -createDriMode(const __DRIcoreExtension *core, - __GLcontextModes *modes, const __DRIconfig **driConfigs) +createDriMode(const __DRIcoreExtension * core, + __GLcontextModes * modes, const __DRIconfig ** driConfigs) { - __GLXDRIconfigPrivate *config; - int i; + __GLXDRIconfigPrivate *config; + int i; - for (i = 0; driConfigs[i]; i++) { - if (driConfigEqual(core, modes, driConfigs[i])) - break; - } + for (i = 0; driConfigs[i]; i++) { + if (driConfigEqual(core, modes, driConfigs[i])) + break; + } - if (driConfigs[i] == NULL) - return NULL; + if (driConfigs[i] == NULL) + return NULL; - config = Xmalloc(sizeof *config); - if (config == NULL) - return NULL; + config = Xmalloc(sizeof *config); + if (config == NULL) + return NULL; - config->modes = *modes; - config->driConfig = driConfigs[i]; + config->modes = *modes; + config->driConfig = driConfigs[i]; - return &config->modes; + return &config->modes; } _X_HIDDEN __GLcontextModes * -driConvertConfigs(const __DRIcoreExtension *core, - __GLcontextModes *modes, const __DRIconfig **configs) +driConvertConfigs(const __DRIcoreExtension * core, + __GLcontextModes * modes, const __DRIconfig ** configs) { - __GLcontextModes head, *tail, *m; - - tail = &head; - head.next = NULL; - for (m = modes; m; m = m->next) { - tail->next = createDriMode(core, m, configs); - if (tail->next == NULL) { - /* no matching dri config for m */ - continue; - } + __GLcontextModes head, *tail, *m; + + tail = &head; + head.next = NULL; + for (m = modes; m; m = m->next) { + tail->next = createDriMode(core, m, configs); + if (tail->next == NULL) { + /* no matching dri config for m */ + continue; + } - tail = tail->next; - } + tail = tail->next; + } - _gl_context_modes_destroy(modes); + _gl_context_modes_destroy(modes); - return head.next; + return head.next; } _X_HIDDEN void -driBindExtensions(__GLXscreenConfigs *psc, int dri2) +driBindExtensions(__GLXscreenConfigs * psc, int dri2) { - const __DRIextension **extensions; - int i; + const __DRIextension **extensions; + int i; - extensions = psc->core->getExtensions(psc->__driScreen); + extensions = psc->core->getExtensions(psc->__driScreen); - for (i = 0; extensions[i]; i++) { + for (i = 0; extensions[i]; i++) { #ifdef __DRI_COPY_SUB_BUFFER - if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) { - psc->driCopySubBuffer = (__DRIcopySubBufferExtension *) extensions[i]; - __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer"); - } + if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) { + psc->driCopySubBuffer = + (__DRIcopySubBufferExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer"); + } #endif #ifdef __DRI_SWAP_CONTROL - /* No DRI2 support for swap_control at the moment, since SwapBuffers - * is done by the X server */ - if (strcmp(extensions[i]->name, __DRI_SWAP_CONTROL) == 0 && !dri2) { - psc->swapControl = (__DRIswapControlExtension *) extensions[i]; - __glXEnableDirectExtension(psc, "GLX_SGI_swap_control"); - __glXEnableDirectExtension(psc, "GLX_MESA_swap_control"); - } + /* No DRI2 support for swap_control at the moment, since SwapBuffers + * is done by the X server */ + if (strcmp(extensions[i]->name, __DRI_SWAP_CONTROL) == 0 && !dri2) { + psc->swapControl = (__DRIswapControlExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_SGI_swap_control"); + __glXEnableDirectExtension(psc, "GLX_MESA_swap_control"); + } #endif #ifdef __DRI_ALLOCATE - if (strcmp(extensions[i]->name, __DRI_ALLOCATE) == 0) { - psc->allocate = (__DRIallocateExtension *) extensions[i]; - __glXEnableDirectExtension(psc, "GLX_MESA_allocate_memory"); - } + if (strcmp(extensions[i]->name, __DRI_ALLOCATE) == 0) { + psc->allocate = (__DRIallocateExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_MESA_allocate_memory"); + } #endif #ifdef __DRI_FRAME_TRACKING - if (strcmp(extensions[i]->name, __DRI_FRAME_TRACKING) == 0) { - psc->frameTracking = (__DRIframeTrackingExtension *) extensions[i]; - __glXEnableDirectExtension(psc, "GLX_MESA_swap_frame_usage"); - } + if (strcmp(extensions[i]->name, __DRI_FRAME_TRACKING) == 0) { + psc->frameTracking = (__DRIframeTrackingExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_MESA_swap_frame_usage"); + } #endif #ifdef __DRI_MEDIA_STREAM_COUNTER - if (strcmp(extensions[i]->name, __DRI_MEDIA_STREAM_COUNTER) == 0) { - psc->msc = (__DRImediaStreamCounterExtension *) extensions[i]; - __glXEnableDirectExtension(psc, "GLX_SGI_video_sync"); - } + if (strcmp(extensions[i]->name, __DRI_MEDIA_STREAM_COUNTER) == 0) { + psc->msc = (__DRImediaStreamCounterExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_SGI_video_sync"); + } #endif #ifdef __DRI_SWAP_BUFFER_COUNTER - /* No driver supports this at this time and the extension is - * not defined in dri_interface.h. Will enable - * GLX_OML_sync_control if implemented. */ + /* No driver supports this at this time and the extension is + * not defined in dri_interface.h. Will enable + * GLX_OML_sync_control if implemented. */ #endif #ifdef __DRI_READ_DRAWABLE - if (strcmp(extensions[i]->name, __DRI_READ_DRAWABLE) == 0) { - __glXEnableDirectExtension(psc, "GLX_SGI_make_current_read"); - } + if (strcmp(extensions[i]->name, __DRI_READ_DRAWABLE) == 0) { + __glXEnableDirectExtension(psc, "GLX_SGI_make_current_read"); + } #endif #ifdef __DRI_TEX_BUFFER - if ((strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) && dri2) { - psc->texBuffer = (__DRItexBufferExtension *) extensions[i]; - __glXEnableDirectExtension(psc, "GLX_EXT_texture_from_pixmap"); - } + if ((strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) && dri2) { + psc->texBuffer = (__DRItexBufferExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_EXT_texture_from_pixmap"); + } #endif #ifdef __DRI2_FLUSH - if ((strcmp(extensions[i]->name, __DRI2_FLUSH) == 0) && dri2) { - psc->f = (__DRI2flushExtension *) extensions[i]; - /* internal driver extension, no GL extension exposed */ - } + if ((strcmp(extensions[i]->name, __DRI2_FLUSH) == 0) && dri2) { + psc->f = (__DRI2flushExtension *) extensions[i]; + /* internal driver extension, no GL extension exposed */ + } #endif - /* Ignore unknown extensions */ - } + /* Ignore unknown extensions */ + } } #endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/x11/dri_glx.c b/src/glx/x11/dri_glx.c index d24471c436..ab24bd8ffe 100644 --- a/src/glx/x11/dri_glx.c +++ b/src/glx/x11/dri_glx.c @@ -51,22 +51,24 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate; typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate; -struct __GLXDRIdisplayPrivateRec { - __GLXDRIdisplay base; +struct __GLXDRIdisplayPrivateRec +{ + __GLXDRIdisplay base; - /* + /* ** XFree86-DRI version information */ - int driMajor; - int driMinor; - int driPatch; + int driMajor; + int driMinor; + int driPatch; }; -struct __GLXDRIcontextPrivateRec { - __GLXDRIcontext base; - __DRIcontext *driContext; - XID hwContextID; - __GLXscreenConfigs *psc; +struct __GLXDRIcontextPrivateRec +{ + __GLXDRIcontext base; + __DRIcontext *driContext; + XID hwContextID; + __GLXscreenConfigs *psc; }; /* @@ -74,47 +76,51 @@ struct __GLXDRIcontextPrivateRec { * the DRI driver for the screen. (I.e. "r128", "tdfx", etc). * Return True for success, False for failure. */ -static Bool driGetDriverName(Display *dpy, int scrNum, char **driverName) +static Bool +driGetDriverName(Display * dpy, int scrNum, char **driverName) { - int directCapable; - Bool b; - int event, error; - int driverMajor, driverMinor, driverPatch; - - *driverName = NULL; - - if (XF86DRIQueryExtension(dpy, &event, &error)) { /* DRI1 */ - if (!XF86DRIQueryDirectRenderingCapable(dpy, scrNum, &directCapable)) { - ErrorMessageF("XF86DRIQueryDirectRenderingCapable failed\n"); - return False; - } - if (!directCapable) { - ErrorMessageF("XF86DRIQueryDirectRenderingCapable returned false\n"); - return False; - } - - b = XF86DRIGetClientDriverName(dpy, scrNum, &driverMajor, &driverMinor, - &driverPatch, driverName); - if (!b) { - ErrorMessageF("Cannot determine driver name for screen %d\n", scrNum); - return False; - } - - InfoMessageF("XF86DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n", - driverMajor, driverMinor, driverPatch, *driverName, scrNum); - - return True; - } else if (DRI2QueryExtension(dpy, &event, &error)) { /* DRI2 */ - char *dev; - Bool ret = DRI2Connect(dpy, RootWindow(dpy, scrNum), driverName, &dev); - - if (ret) - Xfree(dev); - - return ret; - } - - return False; + int directCapable; + Bool b; + int event, error; + int driverMajor, driverMinor, driverPatch; + + *driverName = NULL; + + if (XF86DRIQueryExtension(dpy, &event, &error)) { /* DRI1 */ + if (!XF86DRIQueryDirectRenderingCapable(dpy, scrNum, &directCapable)) { + ErrorMessageF("XF86DRIQueryDirectRenderingCapable failed\n"); + return False; + } + if (!directCapable) { + ErrorMessageF("XF86DRIQueryDirectRenderingCapable returned false\n"); + return False; + } + + b = XF86DRIGetClientDriverName(dpy, scrNum, &driverMajor, &driverMinor, + &driverPatch, driverName); + if (!b) { + ErrorMessageF("Cannot determine driver name for screen %d\n", + scrNum); + return False; + } + + InfoMessageF("XF86DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n", + driverMajor, driverMinor, driverPatch, *driverName, + scrNum); + + return True; + } + else if (DRI2QueryExtension(dpy, &event, &error)) { /* DRI2 */ + char *dev; + Bool ret = DRI2Connect(dpy, RootWindow(dpy, scrNum), driverName, &dev); + + if (ret) + Xfree(dev); + + return ret; + } + + return False; } /* @@ -123,17 +129,19 @@ static Bool driGetDriverName(Display *dpy, int scrNum, char **driverName) * The returned char pointer points to a static array that will be * overwritten by subsequent calls. */ -PUBLIC const char *glXGetScreenDriver (Display *dpy, int scrNum) { +PUBLIC const char * +glXGetScreenDriver(Display * dpy, int scrNum) +{ static char ret[32]; char *driverName; if (driGetDriverName(dpy, scrNum, &driverName)) { int len; if (!driverName) - return NULL; - len = strlen (driverName); + return NULL; + len = strlen(driverName); if (len >= 31) - return NULL; - memcpy (ret, driverName, len+1); + return NULL; + memcpy(ret, driverName, len + 1); Xfree(driverName); return ret; } @@ -151,121 +159,125 @@ PUBLIC const char *glXGetScreenDriver (Display *dpy, int scrNum) { * * Note: The driver remains opened after this function returns. */ -PUBLIC const char *glXGetDriverConfig (const char *driverName) +PUBLIC const char * +glXGetDriverConfig(const char *driverName) { - void *handle = driOpenDriver (driverName); + void *handle = driOpenDriver(driverName); if (handle) - return dlsym (handle, "__driConfigOptions"); + return dlsym(handle, "__driConfigOptions"); else return NULL; } #ifdef XDAMAGE_1_1_INTERFACE -static GLboolean has_damage_post(Display *dpy) +static GLboolean +has_damage_post(Display * dpy) { - static GLboolean inited = GL_FALSE; - static GLboolean has_damage; - - if (!inited) { - int major, minor; - - if (XDamageQueryVersion(dpy, &major, &minor) && - major == 1 && minor >= 1) - { - has_damage = GL_TRUE; - } else { - has_damage = GL_FALSE; - } - inited = GL_TRUE; - } - - return has_damage; + static GLboolean inited = GL_FALSE; + static GLboolean has_damage; + + if (!inited) { + int major, minor; + + if (XDamageQueryVersion(dpy, &major, &minor) && + major == 1 && minor >= 1) { + has_damage = GL_TRUE; + } + else { + has_damage = GL_FALSE; + } + inited = GL_TRUE; + } + + return has_damage; } -static void __glXReportDamage(__DRIdrawable *driDraw, - int x, int y, - drm_clip_rect_t *rects, int num_rects, - GLboolean front_buffer, - void *loaderPrivate) +static void +__glXReportDamage(__DRIdrawable * driDraw, + int x, int y, + drm_clip_rect_t * rects, int num_rects, + GLboolean front_buffer, void *loaderPrivate) { - XRectangle *xrects; - XserverRegion region; - int i; - int x_off, y_off; - __GLXDRIdrawable *glxDraw = loaderPrivate; - __GLXscreenConfigs *psc = glxDraw->psc; - Display *dpy = psc->dpy; - Drawable drawable; - - if (!has_damage_post(dpy)) - return; - - if (front_buffer) { - x_off = x; - y_off = y; - drawable = RootWindow(dpy, psc->scr); - } else{ - x_off = 0; - y_off = 0; - drawable = glxDraw->xDrawable; - } - - xrects = malloc(sizeof(XRectangle) * num_rects); - if (xrects == NULL) - return; - - for (i = 0; i < num_rects; i++) { - xrects[i].x = rects[i].x1 + x_off; - xrects[i].y = rects[i].y1 + y_off; - xrects[i].width = rects[i].x2 - rects[i].x1; - xrects[i].height = rects[i].y2 - rects[i].y1; - } - region = XFixesCreateRegion(dpy, xrects, num_rects); - free(xrects); - XDamageAdd(dpy, drawable, region); - XFixesDestroyRegion(dpy, region); + XRectangle *xrects; + XserverRegion region; + int i; + int x_off, y_off; + __GLXDRIdrawable *glxDraw = loaderPrivate; + __GLXscreenConfigs *psc = glxDraw->psc; + Display *dpy = psc->dpy; + Drawable drawable; + + if (!has_damage_post(dpy)) + return; + + if (front_buffer) { + x_off = x; + y_off = y; + drawable = RootWindow(dpy, psc->scr); + } + else { + x_off = 0; + y_off = 0; + drawable = glxDraw->xDrawable; + } + + xrects = malloc(sizeof(XRectangle) * num_rects); + if (xrects == NULL) + return; + + for (i = 0; i < num_rects; i++) { + xrects[i].x = rects[i].x1 + x_off; + xrects[i].y = rects[i].y1 + y_off; + xrects[i].width = rects[i].x2 - rects[i].x1; + xrects[i].height = rects[i].y2 - rects[i].y1; + } + region = XFixesCreateRegion(dpy, xrects, num_rects); + free(xrects); + XDamageAdd(dpy, drawable, region); + XFixesDestroyRegion(dpy, region); } static const __DRIdamageExtension damageExtension = { - { __DRI_DAMAGE, __DRI_DAMAGE_VERSION }, - __glXReportDamage, + {__DRI_DAMAGE, __DRI_DAMAGE_VERSION}, + __glXReportDamage, }; #endif static GLboolean -__glXDRIGetDrawableInfo(__DRIdrawable *drawable, - unsigned int *index, unsigned int *stamp, - int *X, int *Y, int *W, int *H, - int *numClipRects, drm_clip_rect_t ** pClipRects, - int *backX, int *backY, - int *numBackClipRects, drm_clip_rect_t **pBackClipRects, - void *loaderPrivate) +__glXDRIGetDrawableInfo(__DRIdrawable * drawable, + unsigned int *index, unsigned int *stamp, + int *X, int *Y, int *W, int *H, + int *numClipRects, drm_clip_rect_t ** pClipRects, + int *backX, int *backY, + int *numBackClipRects, + drm_clip_rect_t ** pBackClipRects, + void *loaderPrivate) { - __GLXDRIdrawable *glxDraw = loaderPrivate; - __GLXscreenConfigs *psc = glxDraw->psc; - Display *dpy = psc->dpy; - - return XF86DRIGetDrawableInfo(dpy, psc->scr, glxDraw->drawable, - index, stamp, X, Y, W, H, - numClipRects, pClipRects, - backX, backY, - numBackClipRects, pBackClipRects); + __GLXDRIdrawable *glxDraw = loaderPrivate; + __GLXscreenConfigs *psc = glxDraw->psc; + Display *dpy = psc->dpy; + + return XF86DRIGetDrawableInfo(dpy, psc->scr, glxDraw->drawable, + index, stamp, X, Y, W, H, + numClipRects, pClipRects, + backX, backY, + numBackClipRects, pBackClipRects); } static const __DRIgetDrawableInfoExtension getDrawableInfoExtension = { - { __DRI_GET_DRAWABLE_INFO, __DRI_GET_DRAWABLE_INFO_VERSION }, - __glXDRIGetDrawableInfo + {__DRI_GET_DRAWABLE_INFO, __DRI_GET_DRAWABLE_INFO_VERSION}, + __glXDRIGetDrawableInfo }; static const __DRIextension *loader_extensions[] = { - &systemTimeExtension.base, - &getDrawableInfoExtension.base, + &systemTimeExtension.base, + &getDrawableInfoExtension.base, #ifdef XDAMAGE_1_1_INTERFACE - &damageExtension.base, + &damageExtension.base, #endif - NULL + NULL }; #ifndef GLX_USE_APPLEGL @@ -284,427 +296,429 @@ static const __DRIextension *loader_extensions[] = { * the client-side driver on success, or \c NULL on failure. */ static void * -CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc, - __GLXDRIdisplayPrivate * driDpy) +CallCreateNewScreen(Display * dpy, int scrn, __GLXscreenConfigs * psc, + __GLXDRIdisplayPrivate * driDpy) { - void *psp = NULL; - drm_handle_t hSAREA; - drmAddress pSAREA = MAP_FAILED; - char *BusID; - __DRIversion ddx_version; - __DRIversion dri_version; - __DRIversion drm_version; - __DRIframebuffer framebuffer; - int fd = -1; - int status; - - drm_magic_t magic; - drmVersionPtr version; - int newlyopened; - char *driverName; - drm_handle_t hFB; - int junk; - const __DRIconfig **driver_configs; - __GLcontextModes *visual; - - /* DRI protocol version. */ - dri_version.major = driDpy->driMajor; - dri_version.minor = driDpy->driMinor; - dri_version.patch = driDpy->driPatch; - - framebuffer.base = MAP_FAILED; - framebuffer.dev_priv = NULL; - - if (!XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) { - ErrorMessageF("XF86DRIOpenConnection failed\n"); - goto handle_error; - } - - fd = drmOpenOnce(NULL, BusID, &newlyopened); - - Xfree(BusID); /* No longer needed */ - - if (fd < 0) { - ErrorMessageF("drmOpenOnce failed (%s)\n", strerror(-fd)); - goto handle_error; - } - - if (drmGetMagic(fd, &magic)) { - ErrorMessageF("drmGetMagic failed\n"); - goto handle_error; - } - - version = drmGetVersion(fd); - if (version) { - drm_version.major = version->version_major; - drm_version.minor = version->version_minor; - drm_version.patch = version->version_patchlevel; - drmFreeVersion(version); - } - else { - drm_version.major = -1; - drm_version.minor = -1; - drm_version.patch = -1; - } - - if (newlyopened && !XF86DRIAuthConnection(dpy, scrn, magic)) { - ErrorMessageF("XF86DRIAuthConnection failed\n"); - goto handle_error; - } - - /* Get device name (like "tdfx") and the ddx version numbers. - * We'll check the version in each DRI driver's "createNewScreen" - * function. */ - if (!XF86DRIGetClientDriverName(dpy, scrn, - &ddx_version.major, - &ddx_version.minor, - &ddx_version.patch, - &driverName)) { - ErrorMessageF("XF86DRIGetClientDriverName failed\n"); - goto handle_error; - } - - Xfree(driverName); /* No longer needed. */ - - /* - * Get device-specific info. pDevPriv will point to a struct - * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h) that - * has information about the screen size, depth, pitch, ancilliary - * buffers, DRM mmap handles, etc. - */ - if (!XF86DRIGetDeviceInfo(dpy, scrn, &hFB, &junk, - &framebuffer.size, &framebuffer.stride, - &framebuffer.dev_priv_size, &framebuffer.dev_priv)) { - ErrorMessageF("XF86DRIGetDeviceInfo failed"); - goto handle_error; - } - - framebuffer.width = DisplayWidth(dpy, scrn); - framebuffer.height = DisplayHeight(dpy, scrn); - - /* Map the framebuffer region. */ - status = drmMap(fd, hFB, framebuffer.size, - (drmAddressPtr)&framebuffer.base); - if (status != 0) { - ErrorMessageF("drmMap of framebuffer failed (%s)", strerror(-status)); - goto handle_error; - } - - /* Map the SAREA region. Further mmap regions may be setup in - * each DRI driver's "createNewScreen" function. - */ - status = drmMap(fd, hSAREA, SAREA_MAX, &pSAREA); - if (status != 0) { - ErrorMessageF("drmMap of SAREA failed (%s)", strerror(-status)); - goto handle_error; - } - - psp = (*psc->legacy->createNewScreen)(scrn, - &ddx_version, - &dri_version, - &drm_version, - &framebuffer, - pSAREA, - fd, - loader_extensions, - &driver_configs, - psc); - - if (psp == NULL) { - ErrorMessageF("Calling driver entry point failed"); - goto handle_error; - } - - psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs); - psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs); - - psc->driver_configs = driver_configs; - - /* Visuals with depth != screen depth are subject to automatic compositing - * in the X server, so DRI1 can't render to them properly. Mark them as - * non-conformant to prevent apps from picking them up accidentally. - */ - for (visual = psc->visuals; visual; visual = visual->next) { - XVisualInfo template; - XVisualInfo *visuals; - int num_visuals; - long mask; - - template.visualid = visual->visualID; - mask = VisualIDMask; - visuals = XGetVisualInfo(dpy, mask, &template, &num_visuals); - - if (visuals) { - if (num_visuals > 0 && visuals->depth != DefaultDepth(dpy, scrn)) - visual->visualRating = GLX_NON_CONFORMANT_CONFIG; - - XFree(visuals); - } - } - - return psp; + void *psp = NULL; + drm_handle_t hSAREA; + drmAddress pSAREA = MAP_FAILED; + char *BusID; + __DRIversion ddx_version; + __DRIversion dri_version; + __DRIversion drm_version; + __DRIframebuffer framebuffer; + int fd = -1; + int status; + + drm_magic_t magic; + drmVersionPtr version; + int newlyopened; + char *driverName; + drm_handle_t hFB; + int junk; + const __DRIconfig **driver_configs; + __GLcontextModes *visual; + + /* DRI protocol version. */ + dri_version.major = driDpy->driMajor; + dri_version.minor = driDpy->driMinor; + dri_version.patch = driDpy->driPatch; + + framebuffer.base = MAP_FAILED; + framebuffer.dev_priv = NULL; + + if (!XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) { + ErrorMessageF("XF86DRIOpenConnection failed\n"); + goto handle_error; + } + + fd = drmOpenOnce(NULL, BusID, &newlyopened); + + Xfree(BusID); /* No longer needed */ + + if (fd < 0) { + ErrorMessageF("drmOpenOnce failed (%s)\n", strerror(-fd)); + goto handle_error; + } + + if (drmGetMagic(fd, &magic)) { + ErrorMessageF("drmGetMagic failed\n"); + goto handle_error; + } + + version = drmGetVersion(fd); + if (version) { + drm_version.major = version->version_major; + drm_version.minor = version->version_minor; + drm_version.patch = version->version_patchlevel; + drmFreeVersion(version); + } + else { + drm_version.major = -1; + drm_version.minor = -1; + drm_version.patch = -1; + } + + if (newlyopened && !XF86DRIAuthConnection(dpy, scrn, magic)) { + ErrorMessageF("XF86DRIAuthConnection failed\n"); + goto handle_error; + } + + /* Get device name (like "tdfx") and the ddx version numbers. + * We'll check the version in each DRI driver's "createNewScreen" + * function. */ + if (!XF86DRIGetClientDriverName(dpy, scrn, + &ddx_version.major, + &ddx_version.minor, + &ddx_version.patch, &driverName)) { + ErrorMessageF("XF86DRIGetClientDriverName failed\n"); + goto handle_error; + } + + Xfree(driverName); /* No longer needed. */ + + /* + * Get device-specific info. pDevPriv will point to a struct + * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h) that + * has information about the screen size, depth, pitch, ancilliary + * buffers, DRM mmap handles, etc. + */ + if (!XF86DRIGetDeviceInfo(dpy, scrn, &hFB, &junk, + &framebuffer.size, &framebuffer.stride, + &framebuffer.dev_priv_size, + &framebuffer.dev_priv)) { + ErrorMessageF("XF86DRIGetDeviceInfo failed"); + goto handle_error; + } + + framebuffer.width = DisplayWidth(dpy, scrn); + framebuffer.height = DisplayHeight(dpy, scrn); + + /* Map the framebuffer region. */ + status = drmMap(fd, hFB, framebuffer.size, + (drmAddressPtr) & framebuffer.base); + if (status != 0) { + ErrorMessageF("drmMap of framebuffer failed (%s)", strerror(-status)); + goto handle_error; + } + + /* Map the SAREA region. Further mmap regions may be setup in + * each DRI driver's "createNewScreen" function. + */ + status = drmMap(fd, hSAREA, SAREA_MAX, &pSAREA); + if (status != 0) { + ErrorMessageF("drmMap of SAREA failed (%s)", strerror(-status)); + goto handle_error; + } + + psp = (*psc->legacy->createNewScreen) (scrn, + &ddx_version, + &dri_version, + &drm_version, + &framebuffer, + pSAREA, + fd, + loader_extensions, + &driver_configs, psc); + + if (psp == NULL) { + ErrorMessageF("Calling driver entry point failed"); + goto handle_error; + } + + psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs); + psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs); + + psc->driver_configs = driver_configs; + + /* Visuals with depth != screen depth are subject to automatic compositing + * in the X server, so DRI1 can't render to them properly. Mark them as + * non-conformant to prevent apps from picking them up accidentally. + */ + for (visual = psc->visuals; visual; visual = visual->next) { + XVisualInfo template; + XVisualInfo *visuals; + int num_visuals; + long mask; + + template.visualid = visual->visualID; + mask = VisualIDMask; + visuals = XGetVisualInfo(dpy, mask, &template, &num_visuals); + + if (visuals) { + if (num_visuals > 0 && visuals->depth != DefaultDepth(dpy, scrn)) + visual->visualRating = GLX_NON_CONFORMANT_CONFIG; + + XFree(visuals); + } + } + + return psp; handle_error: - if (pSAREA != MAP_FAILED) - drmUnmap(pSAREA, SAREA_MAX); + if (pSAREA != MAP_FAILED) + drmUnmap(pSAREA, SAREA_MAX); - if (framebuffer.base != MAP_FAILED) - drmUnmap((drmAddress)framebuffer.base, framebuffer.size); + if (framebuffer.base != MAP_FAILED) + drmUnmap((drmAddress) framebuffer.base, framebuffer.size); - if (framebuffer.dev_priv != NULL) - Xfree(framebuffer.dev_priv); + if (framebuffer.dev_priv != NULL) + Xfree(framebuffer.dev_priv); - if (fd >= 0) - drmCloseOnce(fd); + if (fd >= 0) + drmCloseOnce(fd); - XF86DRICloseConnection(dpy, scrn); + XF86DRICloseConnection(dpy, scrn); - ErrorMessageF("reverting to software direct rendering\n"); + ErrorMessageF("reverting to software direct rendering\n"); - return NULL; + return NULL; } #else /* !GLX_USE_APPLEGL */ static void * -CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc, - __GLXDRIdisplayPrivate * driDpy) +CallCreateNewScreen(Display * dpy, int scrn, __GLXscreenConfigs * psc, + __GLXDRIdisplayPrivate * driDpy) { - return NULL; + return NULL; } #endif /* !GLX_USE_APPLEGL */ -static void driDestroyContext(__GLXDRIcontext *context, - __GLXscreenConfigs *psc, Display *dpy) +static void +driDestroyContext(__GLXDRIcontext * context, + __GLXscreenConfigs * psc, Display * dpy) { - __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; - - (*psc->core->destroyContext)(pcp->driContext); + __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; - XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID); - Xfree(pcp); + (*psc->core->destroyContext) (pcp->driContext); + + XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID); + Xfree(pcp); } -static Bool driBindContext(__GLXDRIcontext *context, - __GLXDRIdrawable *draw, __GLXDRIdrawable *read) +static Bool +driBindContext(__GLXDRIcontext * context, + __GLXDRIdrawable * draw, __GLXDRIdrawable * read) { - __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; - const __DRIcoreExtension *core = pcp->psc->core; + __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + const __DRIcoreExtension *core = pcp->psc->core; - return (*core->bindContext)(pcp->driContext, - draw->driDrawable, - read->driDrawable); + return (*core->bindContext) (pcp->driContext, + draw->driDrawable, read->driDrawable); } -static void driUnbindContext(__GLXDRIcontext *context) +static void +driUnbindContext(__GLXDRIcontext * context) { - __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; - const __DRIcoreExtension *core = pcp->psc->core; + __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + const __DRIcoreExtension *core = pcp->psc->core; - (*core->unbindContext)(pcp->driContext); + (*core->unbindContext) (pcp->driContext); } -static __GLXDRIcontext *driCreateContext(__GLXscreenConfigs *psc, - const __GLcontextModes *mode, - GLXContext gc, - GLXContext shareList, int renderType) +static __GLXDRIcontext * +driCreateContext(__GLXscreenConfigs * psc, + const __GLcontextModes * mode, + GLXContext gc, GLXContext shareList, int renderType) { - __GLXDRIcontextPrivate *pcp, *pcp_shared; - drm_context_t hwContext; - __DRIcontext *shared = NULL; - __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; - - if (!psc || !psc->driScreen) - return NULL; - - if (shareList) { - pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext; - shared = pcp_shared->driContext; - } - - pcp = Xmalloc(sizeof *pcp); - if (pcp == NULL) - return NULL; - - pcp->psc = psc; - if (!XF86DRICreateContextWithConfig(psc->dpy, psc->scr, - mode->visualID, - &pcp->hwContextID, &hwContext)) { - Xfree(pcp); - return NULL; - } - - pcp->driContext = - (*psc->legacy->createNewContext)(psc->__driScreen, - config->driConfig, - renderType, - shared, - hwContext, - pcp); - if (pcp->driContext == NULL) { - XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID); - Xfree(pcp); - return NULL; - } - - pcp->base.destroyContext = driDestroyContext; - pcp->base.bindContext = driBindContext; - pcp->base.unbindContext = driUnbindContext; - - return &pcp->base; + __GLXDRIcontextPrivate *pcp, *pcp_shared; + drm_context_t hwContext; + __DRIcontext *shared = NULL; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; + + if (!psc || !psc->driScreen) + return NULL; + + if (shareList) { + pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext; + shared = pcp_shared->driContext; + } + + pcp = Xmalloc(sizeof *pcp); + if (pcp == NULL) + return NULL; + + pcp->psc = psc; + if (!XF86DRICreateContextWithConfig(psc->dpy, psc->scr, + mode->visualID, + &pcp->hwContextID, &hwContext)) { + Xfree(pcp); + return NULL; + } + + pcp->driContext = + (*psc->legacy->createNewContext) (psc->__driScreen, + config->driConfig, + renderType, shared, hwContext, pcp); + if (pcp->driContext == NULL) { + XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID); + Xfree(pcp); + return NULL; + } + + pcp->base.destroyContext = driDestroyContext; + pcp->base.bindContext = driBindContext; + pcp->base.unbindContext = driUnbindContext; + + return &pcp->base; } -static void driDestroyDrawable(__GLXDRIdrawable *pdraw) +static void +driDestroyDrawable(__GLXDRIdrawable * pdraw) { - __GLXscreenConfigs *psc = pdraw->psc; + __GLXscreenConfigs *psc = pdraw->psc; - (*psc->core->destroyDrawable)(pdraw->driDrawable); - XF86DRIDestroyDrawable(psc->dpy, psc->scr, pdraw->drawable); - Xfree(pdraw); + (*psc->core->destroyDrawable) (pdraw->driDrawable); + XF86DRIDestroyDrawable(psc->dpy, psc->scr, pdraw->drawable); + Xfree(pdraw); } -static __GLXDRIdrawable *driCreateDrawable(__GLXscreenConfigs *psc, - XID xDrawable, - GLXDrawable drawable, - const __GLcontextModes *modes) +static __GLXDRIdrawable * +driCreateDrawable(__GLXscreenConfigs * psc, + XID xDrawable, + GLXDrawable drawable, const __GLcontextModes * modes) { - __GLXDRIdrawable *pdraw; - drm_drawable_t hwDrawable; - void *empty_attribute_list = NULL; - __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; - - /* Old dri can't handle GLX 1.3+ drawable constructors. */ - if (xDrawable != drawable) - return NULL; - - pdraw = Xmalloc(sizeof(*pdraw)); - if (!pdraw) - return NULL; - - pdraw->drawable = drawable; - pdraw->psc = psc; - - if (!XF86DRICreateDrawable(psc->dpy, psc->scr, drawable, &hwDrawable)) - return NULL; - - /* Create a new drawable */ - pdraw->driDrawable = - (*psc->legacy->createNewDrawable)(psc->__driScreen, - config->driConfig, - hwDrawable, - GLX_WINDOW_BIT, - empty_attribute_list, - pdraw); - - if (!pdraw->driDrawable) { - XF86DRIDestroyDrawable(psc->dpy, psc->scr, drawable); - Xfree(pdraw); - return NULL; - } - - pdraw->destroyDrawable = driDestroyDrawable; - - return pdraw; + __GLXDRIdrawable *pdraw; + drm_drawable_t hwDrawable; + void *empty_attribute_list = NULL; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; + + /* Old dri can't handle GLX 1.3+ drawable constructors. */ + if (xDrawable != drawable) + return NULL; + + pdraw = Xmalloc(sizeof(*pdraw)); + if (!pdraw) + return NULL; + + pdraw->drawable = drawable; + pdraw->psc = psc; + + if (!XF86DRICreateDrawable(psc->dpy, psc->scr, drawable, &hwDrawable)) + return NULL; + + /* Create a new drawable */ + pdraw->driDrawable = + (*psc->legacy->createNewDrawable) (psc->__driScreen, + config->driConfig, + hwDrawable, + GLX_WINDOW_BIT, + empty_attribute_list, pdraw); + + if (!pdraw->driDrawable) { + XF86DRIDestroyDrawable(psc->dpy, psc->scr, drawable); + Xfree(pdraw); + return NULL; + } + + pdraw->destroyDrawable = driDestroyDrawable; + + return pdraw; } -static void driSwapBuffers(__GLXDRIdrawable *pdraw) +static void +driSwapBuffers(__GLXDRIdrawable * pdraw) { - (*pdraw->psc->core->swapBuffers)(pdraw->driDrawable); + (*pdraw->psc->core->swapBuffers) (pdraw->driDrawable); } -static void driCopySubBuffer(__GLXDRIdrawable *pdraw, - int x, int y, int width, int height) +static void +driCopySubBuffer(__GLXDRIdrawable * pdraw, + int x, int y, int width, int height) { - (*pdraw->psc->driCopySubBuffer->copySubBuffer)(pdraw->driDrawable, - x, y, width, height); + (*pdraw->psc->driCopySubBuffer->copySubBuffer) (pdraw->driDrawable, + x, y, width, height); } -static void driDestroyScreen(__GLXscreenConfigs *psc) +static void +driDestroyScreen(__GLXscreenConfigs * psc) { - /* Free the direct rendering per screen data */ - if (psc->__driScreen) - (*psc->core->destroyScreen)(psc->__driScreen); - psc->__driScreen = NULL; - if (psc->driver) - dlclose(psc->driver); + /* Free the direct rendering per screen data */ + if (psc->__driScreen) + (*psc->core->destroyScreen) (psc->__driScreen); + psc->__driScreen = NULL; + if (psc->driver) + dlclose(psc->driver); } -static __GLXDRIscreen *driCreateScreen(__GLXscreenConfigs *psc, int screen, - __GLXdisplayPrivate *priv) +static __GLXDRIscreen * +driCreateScreen(__GLXscreenConfigs * psc, int screen, + __GLXdisplayPrivate * priv) { - __GLXDRIdisplayPrivate *pdp; - __GLXDRIscreen *psp; - const __DRIextension **extensions; - char *driverName; - int i; - - psp = Xcalloc(1, sizeof *psp); - if (psp == NULL) - return NULL; - - /* Initialize per screen dynamic client GLX extensions */ - psc->ext_list_first_time = GL_TRUE; - - if (!driGetDriverName(priv->dpy, screen, &driverName)) { - Xfree(psp); - return NULL; - } - - psc->driver = driOpenDriver(driverName); - Xfree(driverName); - if (psc->driver == NULL) { - Xfree(psp); - return NULL; - } - - extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); - if (extensions == NULL) { - ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); - Xfree(psp); - return NULL; - } - - for (i = 0; extensions[i]; i++) { - if (strcmp(extensions[i]->name, __DRI_CORE) == 0) - psc->core = (__DRIcoreExtension *) extensions[i]; - if (strcmp(extensions[i]->name, __DRI_LEGACY) == 0) - psc->legacy = (__DRIlegacyExtension *) extensions[i]; - } - - if (psc->core == NULL || psc->legacy == NULL) { - Xfree(psp); - return NULL; - } - - pdp = (__GLXDRIdisplayPrivate *) priv->driDisplay; - psc->__driScreen = - CallCreateNewScreen(psc->dpy, screen, psc, pdp); - if (psc->__driScreen == NULL) { - dlclose(psc->driver); - Xfree(psp); - return NULL; - } - - driBindExtensions(psc, 0); - if (psc->driCopySubBuffer) - psp->copySubBuffer = driCopySubBuffer; - - psp->destroyScreen = driDestroyScreen; - psp->createContext = driCreateContext; - psp->createDrawable = driCreateDrawable; - psp->swapBuffers = driSwapBuffers; - psp->waitX = NULL; - psp->waitGL = NULL; - - return psp; + __GLXDRIdisplayPrivate *pdp; + __GLXDRIscreen *psp; + const __DRIextension **extensions; + char *driverName; + int i; + + psp = Xcalloc(1, sizeof *psp); + if (psp == NULL) + return NULL; + + /* Initialize per screen dynamic client GLX extensions */ + psc->ext_list_first_time = GL_TRUE; + + if (!driGetDriverName(priv->dpy, screen, &driverName)) { + Xfree(psp); + return NULL; + } + + psc->driver = driOpenDriver(driverName); + Xfree(driverName); + if (psc->driver == NULL) { + Xfree(psp); + return NULL; + } + + extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); + if (extensions == NULL) { + ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); + Xfree(psp); + return NULL; + } + + for (i = 0; extensions[i]; i++) { + if (strcmp(extensions[i]->name, __DRI_CORE) == 0) + psc->core = (__DRIcoreExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_LEGACY) == 0) + psc->legacy = (__DRIlegacyExtension *) extensions[i]; + } + + if (psc->core == NULL || psc->legacy == NULL) { + Xfree(psp); + return NULL; + } + + pdp = (__GLXDRIdisplayPrivate *) priv->driDisplay; + psc->__driScreen = CallCreateNewScreen(psc->dpy, screen, psc, pdp); + if (psc->__driScreen == NULL) { + dlclose(psc->driver); + Xfree(psp); + return NULL; + } + + driBindExtensions(psc, 0); + if (psc->driCopySubBuffer) + psp->copySubBuffer = driCopySubBuffer; + + psp->destroyScreen = driDestroyScreen; + psp->createContext = driCreateContext; + psp->createDrawable = driCreateDrawable; + psp->swapBuffers = driSwapBuffers; + psp->waitX = NULL; + psp->waitGL = NULL; + + return psp; } /* Called from __glXFreeDisplayPrivate. */ -static void driDestroyDisplay(__GLXDRIdisplay *dpy) +static void +driDestroyDisplay(__GLXDRIdisplay * dpy) { - Xfree(dpy); + Xfree(dpy); } /* @@ -712,33 +726,34 @@ static void driDestroyDisplay(__GLXDRIdisplay *dpy) * This is called from __glXInitialize() when we are given a new * display pointer. */ -_X_HIDDEN __GLXDRIdisplay *driCreateDisplay(Display *dpy) +_X_HIDDEN __GLXDRIdisplay * +driCreateDisplay(Display * dpy) { - __GLXDRIdisplayPrivate *pdpyp; - int eventBase, errorBase; - int major, minor, patch; + __GLXDRIdisplayPrivate *pdpyp; + int eventBase, errorBase; + int major, minor, patch; - if (!XF86DRIQueryExtension(dpy, &eventBase, &errorBase)) { - return NULL; - } + if (!XF86DRIQueryExtension(dpy, &eventBase, &errorBase)) { + return NULL; + } - if (!XF86DRIQueryVersion(dpy, &major, &minor, &patch)) { - return NULL; - } + if (!XF86DRIQueryVersion(dpy, &major, &minor, &patch)) { + return NULL; + } - pdpyp = Xmalloc(sizeof *pdpyp); - if (!pdpyp) { - return NULL; - } + pdpyp = Xmalloc(sizeof *pdpyp); + if (!pdpyp) { + return NULL; + } - pdpyp->driMajor = major; - pdpyp->driMinor = minor; - pdpyp->driPatch = patch; + pdpyp->driMajor = major; + pdpyp->driMinor = minor; + pdpyp->driPatch = patch; - pdpyp->base.destroyDisplay = driDestroyDisplay; - pdpyp->base.createScreen = driCreateScreen; + pdpyp->base.destroyDisplay = driDestroyDisplay; + pdpyp->base.createScreen = driCreateScreen; - return &pdpyp->base; + return &pdpyp->base; } #endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/x11/glx_pbuffer.c b/src/glx/x11/glx_pbuffer.c index 0ff25bff9e..501500afc3 100644 --- a/src/glx/x11/glx_pbuffer.c +++ b/src/glx/x11/glx_pbuffer.c @@ -25,7 +25,7 @@ /** * \file glx_pbuffer.c * Implementation of pbuffer related functions. - * + * * \author Ian Romanick <idr@us.ibm.com> */ @@ -138,7 +138,7 @@ ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable, * \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 * This function needs to be modified to work with direct-rendering drivers. */ @@ -222,7 +222,7 @@ determineTextureFormat(const int *attribs, int numAttribs) for (i = 0; i < numAttribs; i++) { if (attribs[2 * i] == GLX_TEXTURE_FORMAT_EXT) - return attribs[2 * i + 1]; + return attribs[2 * i + 1]; } return 0; @@ -716,8 +716,7 @@ GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX, PUBLIC GLX_ALIAS_VOID(glXSelectEventSGIX, (Display * dpy, GLXDrawable drawable, - unsigned long mask), (dpy, drawable, mask), - glXSelectEvent) + unsigned long mask), (dpy, drawable, mask), glXSelectEvent) PUBLIC GLX_ALIAS_VOID(glXGetSelectedEventSGIX, diff --git a/src/glx/x11/glx_query.c b/src/glx/x11/glx_query.c index 2789b841b1..efad13d376 100644 --- a/src/glx/x11/glx_query.c +++ b/src/glx/x11/glx_query.c @@ -25,7 +25,7 @@ /** * \file glx_query.c * Generic utility functions to query internal data from the server. - * + * * \author Ian Romanick <idr@us.ibm.com> */ @@ -43,13 +43,10 @@ * Exchange a protocol request for glXQueryServerString. */ char * -__glXQueryServerString(Display* dpy, - int opcode, - CARD32 screen, - CARD32 name) +__glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name) { xcb_connection_t *c = XGetXCBConnection(dpy); - xcb_glx_query_server_string_reply_t* reply = + xcb_glx_query_server_string_reply_t *reply = xcb_glx_query_server_string_reply(c, xcb_glx_query_server_string(c, screen, @@ -59,7 +56,7 @@ __glXQueryServerString(Display* dpy, /* The spec doesn't mention this, but the Xorg server replies with * a string already terminated with '\0'. */ uint32_t len = xcb_glx_query_server_string_string_length(reply); - char* buf = Xmalloc(len); + char *buf = Xmalloc(len); memcpy(buf, xcb_glx_query_server_string_string(reply), len); free(reply); @@ -70,23 +67,20 @@ __glXQueryServerString(Display* dpy, * Exchange a protocol request for glGetString. */ char * -__glXGetString(Display* dpy, - int opcode, - CARD32 contextTag, - CARD32 name) +__glXGetString(Display * dpy, int opcode, CARD32 contextTag, CARD32 name) { xcb_connection_t *c = XGetXCBConnection(dpy); - xcb_glx_get_string_reply_t* reply = - xcb_glx_get_string_reply(c, - xcb_glx_get_string(c, - contextTag, - name), - NULL); + xcb_glx_get_string_reply_t *reply = xcb_glx_get_string_reply(c, + xcb_glx_get_string + (c, + contextTag, + name), + NULL); /* The spec doesn't mention this, but the Xorg server replies with * a string already terminated with '\0'. */ uint32_t len = xcb_glx_get_string_string_length(reply); - char* buf = Xmalloc(len); + char *buf = Xmalloc(len); memcpy(buf, xcb_glx_get_string_string(reply), len); free(reply); @@ -97,7 +91,7 @@ __glXGetString(Display* dpy, /** * GLX protocol structure for the ficticious "GXLGenericGetString" request. - * + * * This is a non-existant protocol packet. It just so happens that all of * the real protocol packets used to request a string from the server have * an identical binary layout. The only difference between them is the @@ -167,25 +161,17 @@ __glXGetStringFromServer(Display * dpy, int opcode, CARD32 glxCode, } char * -__glXQueryServerString(Display* dpy, - int opcode, - CARD32 screen, - CARD32 name) +__glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name) { return __glXGetStringFromServer(dpy, opcode, - X_GLXQueryServerString, - screen, name); + X_GLXQueryServerString, screen, name); } char * -__glXGetString(Display* dpy, - int opcode, - CARD32 contextTag, - CARD32 name) +__glXGetString(Display * dpy, int opcode, CARD32 contextTag, CARD32 name) { return __glXGetStringFromServer(dpy, opcode, X_GLsop_GetString, contextTag, name); } #endif /* USE_XCB */ - diff --git a/src/glx/x11/glxclient.h b/src/glx/x11/glxclient.h index 2778ad878e..00ee14fb05 100644 --- a/src/glx/x11/glxclient.h +++ b/src/glx/x11/glxclient.h @@ -55,9 +55,7 @@ #include "GL/internal/glcore.h" #include "glapi/glapitable.h" #include "glxhash.h" -#if defined( USE_XTHREADS ) -# include <X11/Xthreads.h> -#elif defined( PTHREADS ) +#if defined( PTHREADS ) # include <pthread.h> #endif @@ -67,7 +65,7 @@ /* If we build the library with gcc's -fvisibility=hidden flag, we'll * use the PUBLIC macro to mark functions that are to be exported. * - * We also need to define a USED attribute, so the optimizer doesn't + * We also need to define a USED attribute, so the optimizer doesn't * inline a static function that we later use in an alias. - ajax */ #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303 @@ -80,8 +78,8 @@ -#define GLX_MAJOR_VERSION 1 /* current version numbers */ -#define GLX_MINOR_VERSION 4 +#define GLX_MAJOR_VERSION 1 /* current version numbers */ +#define GLX_MINOR_VERSION 4 #define __GLX_MAX_TEXTURE_UNITS 32 @@ -95,7 +93,7 @@ typedef struct _glapi_table __GLapi; #ifdef GLX_DIRECT_RENDERING -#define containerOf(ptr, type, member) \ +#define containerOf(ptr, type, member) \ (type *)( (char *)ptr - offsetof(type,member) ) #include <GL/internal/dri_interface.h> @@ -112,75 +110,78 @@ typedef struct __GLXDRIcontextRec __GLXDRIcontext; #include "glxextensions.h" -struct __GLXDRIdisplayRec { +struct __GLXDRIdisplayRec +{ /** * Method to destroy the private DRI display data. */ - void (*destroyDisplay)(__GLXDRIdisplay *display); + void (*destroyDisplay) (__GLXDRIdisplay * display); - __GLXDRIscreen *(*createScreen)(__GLXscreenConfigs *psc, int screen, - __GLXdisplayPrivate *priv); + __GLXDRIscreen *(*createScreen) (__GLXscreenConfigs * psc, int screen, + __GLXdisplayPrivate * priv); }; -struct __GLXDRIscreenRec { - - void (*destroyScreen)(__GLXscreenConfigs *psc); - - __GLXDRIcontext *(*createContext)(__GLXscreenConfigs *psc, - const __GLcontextModes *mode, - GLXContext gc, - GLXContext shareList, int renderType); - - __GLXDRIdrawable *(*createDrawable)(__GLXscreenConfigs *psc, - XID drawable, - GLXDrawable glxDrawable, - const __GLcontextModes *modes); - - void (*swapBuffers)(__GLXDRIdrawable *pdraw); - void (*copySubBuffer)(__GLXDRIdrawable *pdraw, - int x, int y, int width, int height); - void (*waitX)(__GLXDRIdrawable *pdraw); - void (*waitGL)(__GLXDRIdrawable *pdraw); +struct __GLXDRIscreenRec +{ + + void (*destroyScreen) (__GLXscreenConfigs * psc); + + __GLXDRIcontext *(*createContext) (__GLXscreenConfigs * psc, + const __GLcontextModes * mode, + GLXContext gc, + GLXContext shareList, int renderType); + + __GLXDRIdrawable *(*createDrawable) (__GLXscreenConfigs * psc, + XID drawable, + GLXDrawable glxDrawable, + const __GLcontextModes * modes); + + void (*swapBuffers) (__GLXDRIdrawable * pdraw); + void (*copySubBuffer) (__GLXDRIdrawable * pdraw, + int x, int y, int width, int height); + void (*waitX) (__GLXDRIdrawable * pdraw); + void (*waitGL) (__GLXDRIdrawable * pdraw); }; -struct __GLXDRIcontextRec { - void (*destroyContext)(__GLXDRIcontext *context, __GLXscreenConfigs *psc, - Display *dpy); - Bool (*bindContext)(__GLXDRIcontext *context, - __GLXDRIdrawable *pdraw, - __GLXDRIdrawable *pread); - - void (*unbindContext)(__GLXDRIcontext *context); +struct __GLXDRIcontextRec +{ + void (*destroyContext) (__GLXDRIcontext * context, + __GLXscreenConfigs * psc, Display * dpy); + Bool(*bindContext) (__GLXDRIcontext * context, __GLXDRIdrawable * pdraw, + __GLXDRIdrawable * pread); + + void (*unbindContext) (__GLXDRIcontext * context); }; -struct __GLXDRIdrawableRec { - void (*destroyDrawable)(__GLXDRIdrawable *drawable); +struct __GLXDRIdrawableRec +{ + void (*destroyDrawable) (__GLXDRIdrawable * drawable); - XID xDrawable; - XID drawable; - __GLXscreenConfigs *psc; - GLenum textureTarget; - __DRIdrawable *driDrawable; - GLenum textureFormat; /* EXT_texture_from_pixmap support */ + XID xDrawable; + XID drawable; + __GLXscreenConfigs *psc; + GLenum textureTarget; + __DRIdrawable *driDrawable; + GLenum textureFormat; /* EXT_texture_from_pixmap support */ }; /* ** Function to create and DRI display data and initialize the display ** dependent methods. */ -extern __GLXDRIdisplay *driswCreateDisplay(Display *dpy); -extern __GLXDRIdisplay *driCreateDisplay(Display *dpy); -extern __GLXDRIdisplay *dri2CreateDisplay(Display *dpy); +extern __GLXDRIdisplay *driswCreateDisplay(Display * dpy); +extern __GLXDRIdisplay *driCreateDisplay(Display * dpy); +extern __GLXDRIdisplay *dri2CreateDisplay(Display * dpy); -extern void DRI_glXUseXFont( Font font, int first, int count, int listbase ); +extern void DRI_glXUseXFont(Font font, int first, int count, int listbase); /* ** Functions to obtain driver configuration information from a direct ** rendering client application */ -extern const char *glXGetScreenDriver (Display *dpy, int scrNum); +extern const char *glXGetScreenDriver(Display * dpy, int scrNum); -extern const char *glXGetDriverConfig (const char *driverName); +extern const char *glXGetDriverConfig(const char *driverName); #endif @@ -188,53 +189,57 @@ extern const char *glXGetDriverConfig (const char *driverName); #define __GL_CLIENT_ATTRIB_STACK_DEPTH 16 -typedef struct __GLXpixelStoreModeRec { - GLboolean swapEndian; - GLboolean lsbFirst; - GLuint rowLength; - GLuint imageHeight; - GLuint imageDepth; - GLuint skipRows; - GLuint skipPixels; - GLuint skipImages; - GLuint alignment; +typedef struct __GLXpixelStoreModeRec +{ + GLboolean swapEndian; + GLboolean lsbFirst; + GLuint rowLength; + GLuint imageHeight; + GLuint imageDepth; + GLuint skipRows; + GLuint skipPixels; + GLuint skipImages; + GLuint alignment; } __GLXpixelStoreMode; -typedef struct __GLXattributeRec { - GLuint mask; +typedef struct __GLXattributeRec +{ + GLuint mask; /** * Pixel storage state. Most of the pixel store mode state is kept * here and used by the client code to manage the packing and * unpacking of data sent to/received from the server. */ - __GLXpixelStoreMode storePack, storeUnpack; + __GLXpixelStoreMode storePack, storeUnpack; /** * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically * disabled? */ - GLboolean NoDrawArraysProtocol; - + GLboolean NoDrawArraysProtocol; + /** * Vertex Array storage state. The vertex array component * state is stored here and is used to manage the packing of * DrawArrays data sent to the server. */ - struct array_state_vector * array_state; + struct array_state_vector *array_state; } __GLXattribute; -typedef struct __GLXattributeMachineRec { - __GLXattribute *stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; - __GLXattribute **stackPointer; +typedef struct __GLXattributeMachineRec +{ + __GLXattribute *stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; + __GLXattribute **stackPointer; } __GLXattributeMachine; /** * GLX state that needs to be kept on the client. One of these records * exist for each context that has been made current by this client. */ -struct __GLXcontextRec { +struct __GLXcontextRec +{ /** * \name Drawing command buffer. * @@ -251,13 +256,13 @@ struct __GLXcontextRec { * These must be the first 6 fields since they are static initialized * in the dummy context in glxext.c */ - /*@{*/ - GLubyte *buf; - GLubyte *pc; - GLubyte *limit; - GLubyte *bufEnd; - GLint bufSize; - /*@}*/ + /*@{ */ + GLubyte *buf; + GLubyte *pc; + GLubyte *limit; + GLubyte *bufEnd; + GLint bufSize; + /*@} */ /** * The XID of this rendering context. When the context is created a @@ -265,24 +270,24 @@ struct __GLXcontextRec { * destroyed but is still current to some thread. In this case the * context will be freed on next MakeCurrent. */ - XID xid; + XID xid; /** * The XID of the \c shareList context. */ - XID share_xid; + XID share_xid; /** * Screen number. */ - GLint screen; - __GLXscreenConfigs *psc; + GLint screen; + __GLXscreenConfigs *psc; /** * \c GL_TRUE if the context was created with ImportContext, which * means the server-side context was created by another X client. */ - GLboolean imported; + GLboolean imported; /** * The context tag returned by MakeCurrent when this context is made @@ -292,7 +297,7 @@ struct __GLXcontextRec { * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old * context)). */ - GLXContextTag currentContextTag; + GLXContextTag currentContextTag; /** * \name Rendering mode @@ -301,11 +306,11 @@ struct __GLXcontextRec { * When \c glRenderMode is called, the buffer associated with the * previous rendering mode (feedback or select) is filled. */ - /*@{*/ - GLenum renderMode; - GLfloat *feedbackBuf; - GLuint *selectBuf; - /*@}*/ + /*@{ */ + GLenum renderMode; + GLfloat *feedbackBuf; + GLuint *selectBuf; + /*@} */ /** * This is \c GL_TRUE if the pixel unpack modes are such that an image @@ -313,43 +318,43 @@ struct __GLXcontextRec { * still be true that the server will have to do some work. This * just promises that a straight copy will fetch the correct bytes. */ - GLboolean fastImageUnpack; + GLboolean fastImageUnpack; /** * Fill newImage with the unpacked form of \c oldImage getting it * ready for transport to the server. */ - void (*fillImage)(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum, - GLenum, const GLvoid*, GLubyte*, GLubyte*); + void (*fillImage) (__GLXcontext *, GLint, GLint, GLint, GLint, GLenum, + GLenum, const GLvoid *, GLubyte *, GLubyte *); /** * Client side attribs. */ - __GLXattributeMachine attributes; + __GLXattributeMachine attributes; /** * Client side error code. This is set when client side gl API * routines need to set an error because of a bad enumerant or * running out of memory, etc. */ - GLenum error; + GLenum error; /** * Whether this context does direct rendering. */ - Bool isDirect; + Bool isDirect; /** * \c dpy of current display for this context. Will be \c NULL if not * current to any display, or if this is the "dummy context". */ - Display *currentDpy; + Display *currentDpy; /** * The current drawable for this context. Will be None if this * context is not current to any drawable. currentReadable is below. */ - GLXDrawable currentDrawable; + GLXDrawable currentDrawable; /** * \name GL Constant Strings @@ -358,38 +363,38 @@ struct __GLXcontextRec { * These pertain to GL attributes, not to be confused with * GLX versioning attributes. */ - /*@{*/ - GLubyte *vendor; - GLubyte *renderer; - GLubyte *version; - GLubyte *extensions; - /*@}*/ + /*@{ */ + GLubyte *vendor; + GLubyte *renderer; + GLubyte *version; + GLubyte *extensions; + /*@} */ /** * Record the dpy this context was created on for later freeing */ - Display *createDpy; + Display *createDpy; /** * Maximum small render command size. This is the smaller of 64k and * the size of the above buffer. */ - GLint maxSmallRenderCommandSize; + GLint maxSmallRenderCommandSize; /** * Major opcode for the extension. Copied here so a lookup isn't * needed. */ - GLint majorOpcode; + GLint majorOpcode; /** * Pointer to the mode used to create this context. */ - const __GLcontextModes * mode; + const __GLcontextModes *mode; #ifdef GLX_DIRECT_RENDERING - __GLXDRIcontext *driContext; - __DRIcontext *__driContext; + __GLXDRIcontext *driContext; + __DRIcontext *__driContext; #endif /** @@ -398,22 +403,22 @@ struct __GLXcontextRec { * * \since Internal API version 20030606. */ - GLXDrawable currentReadable; + GLXDrawable currentReadable; - /** + /** * Pointer to client-state data that is private to libGL. This is only * used for indirect rendering contexts. * * No internal API version change was made for this change. Client-side * drivers should NEVER use this data or even care that it exists. */ - void * client_state_private; + void *client_state_private; /** * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE. */ int renderType; - + /** * \name Raw server GL version * @@ -421,23 +426,23 @@ struct __GLXcontextRec { * returned by the server, and it may not reflect what is actually * supported (or reported) by the client-side library. */ - /*@{*/ + /*@{ */ int server_major; /**< Major version number. */ int server_minor; /**< Minor version number. */ - /*@}*/ + /*@} */ /** * Thread ID we're currently current in. Zero if none. */ unsigned long thread_id; - char gl_extension_bits[ __GL_EXT_BYTES ]; + char gl_extension_bits[__GL_EXT_BYTES]; }; -#define __glXSetError(gc,code) \ - if (!(gc)->error) { \ - (gc)->error = code; \ - } +#define __glXSetError(gc,code) \ + if (!(gc)->error) { \ + (gc)->error = code; \ + } extern void __glFreeAttributeState(__GLXcontext *); @@ -448,7 +453,7 @@ extern void __glFreeAttributeState(__GLXcontext *); * that will use the GLXRender GLX command. In this case it is * \c glPolygonStipple. */ -#define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156 +#define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156 /** * To keep the implementation fast, the code uses a "limit" pointer @@ -460,75 +465,76 @@ extern void __glFreeAttributeState(__GLXcontext *); * efficacy of the buffer. The "+32" is just to keep the code working * in case somebody counts wrong. */ -#define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32) +#define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32) /** * This implementation uses a smaller threshold for switching * to the RenderLarge protocol than the protcol requires so that * large copies don't occur. */ -#define __GLX_RENDER_CMD_SIZE_LIMIT 4096 +#define __GLX_RENDER_CMD_SIZE_LIMIT 4096 /** * One of these records exists per screen of the display. It contains * a pointer to the config data for that screen (if the screen supports GL). */ -struct __GLXscreenConfigsRec { +struct __GLXscreenConfigsRec +{ /** * GLX extension string reported by the X-server. */ - const char *serverGLXexts; + const char *serverGLXexts; /** * GLX extension string to be reported to applications. This is the * set of extensions that the application can actually use. */ - char *effectiveGLXexts; + char *effectiveGLXexts; #ifdef GLX_DIRECT_RENDERING /** * Per screen direct rendering interface functions and data. */ - __DRIscreen *__driScreen; - const __DRIcoreExtension *core; - const __DRIlegacyExtension *legacy; - const __DRIswrastExtension *swrast; - const __DRIdri2Extension *dri2; - __glxHashTable *drawHash; - Display *dpy; - int scr, fd; - void *driver; + __DRIscreen *__driScreen; + const __DRIcoreExtension *core; + const __DRIlegacyExtension *legacy; + const __DRIswrastExtension *swrast; + const __DRIdri2Extension *dri2; + __glxHashTable *drawHash; + Display *dpy; + int scr, fd; + void *driver; - __GLXDRIscreen *driScreen; + __GLXDRIscreen *driScreen; - const __DRIconfig** driver_configs; + const __DRIconfig **driver_configs; #ifdef __DRI_COPY_SUB_BUFFER - const __DRIcopySubBufferExtension *driCopySubBuffer; + const __DRIcopySubBufferExtension *driCopySubBuffer; #endif #ifdef __DRI_SWAP_CONTROL - const __DRIswapControlExtension *swapControl; + const __DRIswapControlExtension *swapControl; #endif #ifdef __DRI_ALLOCATE - const __DRIallocateExtension *allocate; + const __DRIallocateExtension *allocate; #endif #ifdef __DRI_FRAME_TRACKING - const __DRIframeTrackingExtension *frameTracking; + const __DRIframeTrackingExtension *frameTracking; #endif #ifdef __DRI_MEDIA_STREAM_COUNTER - const __DRImediaStreamCounterExtension *msc; + const __DRImediaStreamCounterExtension *msc; #endif #ifdef __DRI_TEX_BUFFER - const __DRItexBufferExtension *texBuffer; + const __DRItexBufferExtension *texBuffer; #endif #ifdef __DRI2_FLUSH - const __DRI2flushExtension *f; + const __DRI2flushExtension *f; #endif #endif @@ -536,7 +542,7 @@ struct __GLXscreenConfigsRec { /** * Linked list of glx visuals and fbconfigs for this screen. */ - __GLcontextModes *visuals, *configs; + __GLcontextModes *visuals, *configs; /** * Per-screen dynamic GLX extension tracking. The \c direct_support @@ -545,10 +551,10 @@ struct __GLXscreenConfigsRec { * this field. The \c __GLXscreenConfigs structure is not used outside * libGL. */ - /*@{*/ - unsigned char direct_support[8]; - GLboolean ext_list_first_time; - /*@}*/ + /*@{ */ + unsigned char direct_support[8]; + GLboolean ext_list_first_time; + /*@} */ }; @@ -556,67 +562,68 @@ struct __GLXscreenConfigsRec { * Per display private data. One of these records exists for each display * that is using the OpenGL (GLX) extension. */ -struct __GLXdisplayPrivateRec { +struct __GLXdisplayPrivateRec +{ /** * Back pointer to the display */ - Display *dpy; + Display *dpy; /** * The \c majorOpcode is common to all connections to the same server. * It is also copied into the context structure. */ - int majorOpcode; + int majorOpcode; /** * \name Server Version * * Major and minor version returned by the server during initialization. */ - /*@{*/ - int majorVersion, minorVersion; - /*@}*/ + /*@{ */ + int majorVersion, minorVersion; + /*@} */ /** * \name Storage for the servers GLX vendor and versions strings. - * + * * These are the same for all screens on this display. These fields will * be filled in on demand. */ - /*@{*/ - const char *serverGLXvendor; - const char *serverGLXversion; - /*@}*/ + /*@{ */ + const char *serverGLXvendor; + const char *serverGLXversion; + /*@} */ /** * Configurations of visuals for all screens on this display. * Also, per screen data which now includes the server \c GLX_EXTENSION * string. */ - __GLXscreenConfigs *screenConfigs; + __GLXscreenConfigs *screenConfigs; #ifdef GLX_DIRECT_RENDERING /** * Per display direct rendering interface functions and data. */ - __GLXDRIdisplay *driswDisplay; - __GLXDRIdisplay *driDisplay; - __GLXDRIdisplay *dri2Display; + __GLXDRIdisplay *driswDisplay; + __GLXDRIdisplay *driDisplay; + __GLXDRIdisplay *dri2Display; #endif }; -extern GLubyte *__glXFlushRenderBuffer(__GLXcontext*, GLubyte*); +extern GLubyte *__glXFlushRenderBuffer(__GLXcontext *, GLubyte *); -extern void __glXSendLargeChunk(__GLXcontext *gc, GLint requestNumber, - GLint totalRequests, - const GLvoid * data, GLint dataLen); +extern void __glXSendLargeChunk(__GLXcontext * gc, GLint requestNumber, + GLint totalRequests, + const GLvoid * data, GLint dataLen); extern void __glXSendLargeCommand(__GLXcontext *, const GLvoid *, GLint, - const GLvoid *, GLint); + const GLvoid *, GLint); /* Initialize the GLX extension for dpy */ -extern __GLXdisplayPrivate *__glXInitialize(Display*); +extern __GLXdisplayPrivate *__glXInitialize(Display *); extern void __glXPreferEGL(int state); @@ -625,16 +632,16 @@ extern void __glXPreferEGL(int state); extern int __glXDebug; /* This is per-thread storage in an MT environment */ -#if defined( USE_XTHREADS ) || defined( PTHREADS ) +#if defined( PTHREADS ) -extern void __glXSetCurrentContext(__GLXcontext *c); +extern void __glXSetCurrentContext(__GLXcontext * c); # if defined( GLX_USE_TLS ) -extern __thread void * __glX_tls_Context - __attribute__((tls_model("initial-exec"))); +extern __thread void *__glX_tls_Context + __attribute__ ((tls_model("initial-exec"))); -# define __glXGetCurrentContext() __glX_tls_Context +# define __glXGetCurrentContext() __glX_tls_Context # else @@ -645,25 +652,21 @@ extern __GLXcontext *__glXGetCurrentContext(void); #else extern __GLXcontext *__glXcurrentContext; -#define __glXGetCurrentContext() __glXcurrentContext -#define __glXSetCurrentContext(gc) __glXcurrentContext = gc +#define __glXGetCurrentContext() __glXcurrentContext +#define __glXSetCurrentContext(gc) __glXcurrentContext = gc -#endif /* defined( USE_XTHREADS ) || defined( PTHREADS ) */ +#endif /* defined( PTHREADS ) */ extern void __glXSetCurrentContextNull(void); -extern void __glXFreeContext(__GLXcontext*); +extern void __glXFreeContext(__GLXcontext *); /* ** Global lock for all threads in this address space using the GLX ** extension */ -#if defined( USE_XTHREADS ) -extern xmutex_rec __glXmutex; -#define __glXLock() xmutex_lock(&__glXmutex) -#define __glXUnlock() xmutex_unlock(&__glXmutex) -#elif defined( PTHREADS ) +#if defined( PTHREADS ) extern pthread_mutex_t __glXmutex; #define __glXLock() pthread_mutex_lock(&__glXmutex) #define __glXUnlock() pthread_mutex_unlock(&__glXmutex) @@ -675,7 +678,7 @@ extern pthread_mutex_t __glXmutex; /* ** Setup for a command. Initialize the extension for dpy if necessary. */ -extern CARD8 __glXSetupForCommand(Display *dpy); +extern CARD8 __glXSetupForCommand(Display * dpy); /************************************************************************/ @@ -686,9 +689,11 @@ extern CARD8 __glXSetupForCommand(Display *dpy); extern const GLuint __glXDefaultPixelStore[9]; /* Send an image to the server using RenderLarge. */ -extern void __glXSendLargeImage(__GLXcontext *gc, GLint compsize, GLint dim, - GLint width, GLint height, GLint depth, GLenum format, GLenum type, - const GLvoid *src, GLubyte *pc, GLubyte *modes); +extern void __glXSendLargeImage(__GLXcontext * gc, GLint compsize, GLint dim, + GLint width, GLint height, GLint depth, + GLenum format, GLenum type, + const GLvoid * src, GLubyte * pc, + GLubyte * modes); /* Return the size, in bytes, of some pixel data */ extern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum, GLenum); @@ -708,23 +713,23 @@ extern GLint __glBytesPerElement(GLenum type); ** updated to contain the modes needed by the server to decode the ** sent data. */ -extern void __glFillImage(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum, - GLenum, const GLvoid*, GLubyte*, GLubyte*); +extern void __glFillImage(__GLXcontext *, GLint, GLint, GLint, GLint, GLenum, + GLenum, const GLvoid *, GLubyte *, GLubyte *); /* Copy map data with a stride into a packed buffer */ extern void __glFillMap1f(GLint, GLint, GLint, const GLfloat *, GLubyte *); extern void __glFillMap1d(GLint, GLint, GLint, const GLdouble *, GLubyte *); extern void __glFillMap2f(GLint, GLint, GLint, GLint, GLint, - const GLfloat *, GLfloat *); + const GLfloat *, GLfloat *); extern void __glFillMap2d(GLint, GLint, GLint, GLint, GLint, - const GLdouble *, GLdouble *); + const GLdouble *, GLdouble *); /* ** Empty an image out of the reply buffer into the clients memory applying ** the pack modes to pack back into the clients requested format. */ -extern void __glEmptyImage(__GLXcontext*, GLint, GLint, GLint, GLint, GLenum, - GLenum, const GLubyte *, GLvoid *); +extern void __glEmptyImage(__GLXcontext *, GLint, GLint, GLint, GLint, GLenum, + GLenum, const GLubyte *, GLvoid *); /* @@ -737,7 +742,7 @@ extern void __glXFreeVertexArrayState(__GLXcontext *); ** Inform the Server of the major and minor numbers and of the client ** libraries extension string. */ -extern void __glXClientInfo ( Display *dpy, int opcode ); +extern void __glXClientInfo(Display * dpy, int opcode); /************************************************************************/ @@ -745,20 +750,22 @@ extern void __glXClientInfo ( Display *dpy, int opcode ); ** Declarations that should be in Xlib */ #ifdef __GL_USE_OUR_PROTOTYPES -extern void _XFlush(Display*); -extern Status _XReply(Display*, xReply*, int, Bool); -extern void _XRead(Display*, void*, long); -extern void _XSend(Display*, const void*, long); +extern void _XFlush(Display *); +extern Status _XReply(Display *, xReply *, int, Bool); +extern void _XRead(Display *, void *, long); +extern void _XSend(Display *, const void *, long); #endif -extern void __glXInitializeVisualConfigFromTags( __GLcontextModes *config, - int count, const INT32 *bp, Bool tagged_only, Bool fbconfig_style_tags ); +extern void __glXInitializeVisualConfigFromTags(__GLcontextModes * config, + int count, const INT32 * bp, + Bool tagged_only, + Bool fbconfig_style_tags); -extern char * __glXQueryServerString(Display* dpy, int opcode, - CARD32 screen, CARD32 name); -extern char * __glXGetString(Display* dpy, int opcode, - CARD32 screen, CARD32 name); +extern char *__glXQueryServerString(Display * dpy, int opcode, + CARD32 screen, CARD32 name); +extern char *__glXGetString(Display * dpy, int opcode, + CARD32 screen, CARD32 name); extern char *__glXstrdup(const char *str); @@ -767,15 +774,16 @@ extern const char __glXGLClientVersion[]; extern const char __glXGLClientExtensions[]; /* Get the unadjusted system time */ -extern int __glXGetUST( int64_t * ust ); +extern int __glXGetUST(int64_t * ust); extern GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, - int32_t * numerator, int32_t * denominator); + int32_t * numerator, + int32_t * denominator); #ifdef GLX_DIRECT_RENDERING GLboolean -__driGetMscRateOML(__DRIdrawable *draw, - int32_t *numerator, int32_t *denominator, void *private); +__driGetMscRateOML(__DRIdrawable * draw, + int32_t * numerator, int32_t * denominator, void *private); #endif #endif /* !__GLX_client_h__ */ diff --git a/src/glx/x11/glxcmds.c b/src/glx/x11/glxcmds.c index 3242ac7712..ea55cc49ef 100644 --- a/src/glx/x11/glxcmds.c +++ b/src/glx/x11/glxcmds.c @@ -59,56 +59,59 @@ static const char __glXGLXClientVersion[] = "1.4"; #ifdef GLX_DIRECT_RENDERING static Bool windowExistsFlag; -static int windowExistsErrorHandler(Display *dpy, XErrorEvent *xerr) +static int +windowExistsErrorHandler(Display * dpy, XErrorEvent * xerr) { - if (xerr->error_code == BadWindow) { - windowExistsFlag = GL_FALSE; - } - return 0; + if (xerr->error_code == BadWindow) { + windowExistsFlag = GL_FALSE; + } + return 0; } /** * Find drawables in the local hash that have been destroyed on the * server. - * + * * \param dpy Display to destroy drawables for * \param screen Screen number to destroy drawables for */ -static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc) -{ - XID draw; - __GLXDRIdrawable *pdraw; - XWindowAttributes xwa; - int (*oldXErrorHandler)(Display *, XErrorEvent *); - - /* Set no-op error handler so Xlib doesn't bail out if the windows - * has alreay been destroyed on the server. */ - XSync(dpy, GL_FALSE); - oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler); - - if (__glxHashFirst(sc->drawHash, &draw, (void *)&pdraw) == 1) { - do { - windowExistsFlag = GL_TRUE; - XGetWindowAttributes(dpy, draw, &xwa); /* dummy request */ - if (!windowExistsFlag) { - /* Destroy the local drawable data, if the drawable no - longer exists in the Xserver */ - (*pdraw->destroyDrawable)(pdraw); - __glxHashDelete(sc->drawHash, draw); - } - } while (__glxHashNext(sc->drawHash, &draw, (void *)&pdraw) == 1); - } - - XSync(dpy, GL_FALSE); - XSetErrorHandler(oldXErrorHandler); -} - -extern __GLXDRIdrawable * -GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num); +static void +GarbageCollectDRIDrawables(Display * dpy, __GLXscreenConfigs * sc) +{ + XID draw; + __GLXDRIdrawable *pdraw; + XWindowAttributes xwa; + int (*oldXErrorHandler) (Display *, XErrorEvent *); + + /* Set no-op error handler so Xlib doesn't bail out if the windows + * has alreay been destroyed on the server. */ + XSync(dpy, GL_FALSE); + oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler); + + if (__glxHashFirst(sc->drawHash, &draw, (void *) &pdraw) == 1) { + do { + windowExistsFlag = GL_TRUE; + XGetWindowAttributes(dpy, draw, &xwa); /* dummy request */ + if (!windowExistsFlag) { + /* Destroy the local drawable data, if the drawable no + longer exists in the Xserver */ + (*pdraw->destroyDrawable) (pdraw); + __glxHashDelete(sc->drawHash, draw); + } + } while (__glxHashNext(sc->drawHash, &draw, (void *) &pdraw) == 1); + } + + XSync(dpy, GL_FALSE); + XSetErrorHandler(oldXErrorHandler); +} + +extern __GLXDRIdrawable *GetGLXDRIDrawable(Display * dpy, + GLXDrawable drawable, + int *const scrn_num); /** * Get the __DRIdrawable for the drawable associated with a GLXContext - * + * * \param dpy The display associated with \c drawable. * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved. * \param scrn_num If non-NULL, the drawables screen is stored there @@ -116,30 +119,30 @@ GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num); * the drawable is not associated with a direct-rendering context. */ _X_HIDDEN __GLXDRIdrawable * -GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num) +GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable, int *const scrn_num) { - __GLXdisplayPrivate *priv = __glXInitialize(dpy); - __GLXDRIdrawable *pdraw; - const unsigned screen_count = ScreenCount(dpy); - unsigned i; - __GLXscreenConfigs *psc; + __GLXdisplayPrivate *priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw; + const unsigned screen_count = ScreenCount(dpy); + unsigned i; + __GLXscreenConfigs *psc; - if (priv == NULL) - return NULL; - - for (i = 0; i < screen_count; i++) { - psc = &priv->screenConfigs[i]; - if (psc->drawHash == NULL) - continue; + if (priv == NULL) + return NULL; - if (__glxHashLookup(psc->drawHash, drawable, (void *) &pdraw) == 0) { - if (scrn_num != NULL) - *scrn_num = i; - return pdraw; - } - } + for (i = 0; i < screen_count; i++) { + psc = &priv->screenConfigs[i]; + if (psc->drawHash == NULL) + continue; + + if (__glxHashLookup(psc->drawHash, drawable, (void *) &pdraw) == 0) { + if (scrn_num != NULL) + *scrn_num = i; + return pdraw; + } + } - return NULL; + return NULL; } #endif @@ -147,57 +150,59 @@ GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num) /** * Get the GLX per-screen data structure associated with a GLX context. - * + * * \param dpy Display for which the GLX per-screen information is to be * retrieved. * \param scrn Screen on \c dpy for which the GLX per-screen information is * to be retrieved. * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn * specify a valid GLX screen, or NULL otherwise. - * + * * \todo Should this function validate that \c scrn is within the screen * number range for \c dpy? */ static __GLXscreenConfigs * -GetGLXScreenConfigs(Display *dpy, int scrn) +GetGLXScreenConfigs(Display * dpy, int scrn) { - __GLXdisplayPrivate * const priv = __glXInitialize(dpy); + __GLXdisplayPrivate *const priv = __glXInitialize(dpy); - return (priv && priv->screenConfigs != NULL) ? &priv->screenConfigs[scrn] : NULL; + return (priv + && priv->screenConfigs != + NULL) ? &priv->screenConfigs[scrn] : NULL; } static int -GetGLXPrivScreenConfig( Display *dpy, int scrn, __GLXdisplayPrivate ** ppriv, - __GLXscreenConfigs ** ppsc ) +GetGLXPrivScreenConfig(Display * dpy, int scrn, __GLXdisplayPrivate ** ppriv, + __GLXscreenConfigs ** ppsc) { - /* Initialize the extension, if needed . This has the added value - * of initializing/allocating the display private - */ - - if ( dpy == NULL ) { - return GLX_NO_EXTENSION; - } + /* Initialize the extension, if needed . This has the added value + * of initializing/allocating the display private + */ - *ppriv = __glXInitialize(dpy); - if ( *ppriv == NULL ) { - return GLX_NO_EXTENSION; - } + if (dpy == NULL) { + return GLX_NO_EXTENSION; + } - /* Check screen number to see if its valid */ - if ((scrn < 0) || (scrn >= ScreenCount(dpy))) { - return GLX_BAD_SCREEN; - } + *ppriv = __glXInitialize(dpy); + if (*ppriv == NULL) { + return GLX_NO_EXTENSION; + } - /* Check to see if the GL is supported on this screen */ - *ppsc = &((*ppriv)->screenConfigs[scrn]); - if ( (*ppsc)->configs == NULL ) { - /* No support for GL on this screen regardless of visual */ - return GLX_BAD_VISUAL; - } + /* Check screen number to see if its valid */ + if ((scrn < 0) || (scrn >= ScreenCount(dpy))) { + return GLX_BAD_SCREEN; + } - return Success; + /* Check to see if the GL is supported on this screen */ + *ppsc = &((*ppriv)->screenConfigs[scrn]); + if ((*ppsc)->configs == NULL) { + /* No support for GL on this screen regardless of visual */ + return GLX_BAD_VISUAL; + } + + return Success; } @@ -212,27 +217,26 @@ GetGLXPrivScreenConfig( Display *dpy, int scrn, __GLXdisplayPrivate ** ppriv, * is returned. */ static __GLcontextModes * -ValidateGLXFBConfig( Display * dpy, GLXFBConfig config ) -{ - __GLXdisplayPrivate * const priv = __glXInitialize(dpy); - const unsigned num_screens = ScreenCount(dpy); - unsigned i; - const __GLcontextModes * modes; - - - if ( priv != NULL ) { - for ( i = 0 ; i < num_screens ; i++ ) { - for ( modes = priv->screenConfigs[i].configs - ; modes != NULL - ; modes = modes->next ) { - if ( modes == (__GLcontextModes *) config ) { - return (__GLcontextModes *) config; - } - } - } - } +ValidateGLXFBConfig(Display * dpy, GLXFBConfig config) +{ + __GLXdisplayPrivate *const priv = __glXInitialize(dpy); + const unsigned num_screens = ScreenCount(dpy); + unsigned i; + const __GLcontextModes *modes; + + + if (priv != NULL) { + for (i = 0; i < num_screens; i++) { + for (modes = priv->screenConfigs[i].configs; modes != NULL; + modes = modes->next) { + if (modes == (__GLcontextModes *) config) { + return (__GLcontextModes *) config; + } + } + } + } - return NULL; + return NULL; } @@ -241,471 +245,497 @@ ValidateGLXFBConfig( Display * dpy, GLXFBConfig config ) * later in the function for direct-rendering contexts. Direct-rendering * contexts don't need to track client state, so they don't need that memory * at all. - * + * * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new * function called \c __glXAllocateClientState that allocates the memory and * does all the initialization (including the pixel pack / unpack). */ -static -GLXContext AllocateGLXContext( Display *dpy ) -{ - GLXContext gc; - int bufSize; - CARD8 opcode; - __GLXattribute *state; - - if (!dpy) - return NULL; - - opcode = __glXSetupForCommand(dpy); - if (!opcode) { - return NULL; - } - - /* Allocate our context record */ - gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec)); - if (!gc) { - /* Out of memory */ - return NULL; - } - memset(gc, 0, sizeof(struct __GLXcontextRec)); - - state = Xmalloc(sizeof(struct __GLXattributeRec)); - if (state == NULL) { - /* Out of memory */ - Xfree(gc); - return NULL; - } - gc->client_state_private = state; - memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec)); - state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL); - - /* +static GLXContext +AllocateGLXContext(Display * dpy) +{ + GLXContext gc; + int bufSize; + CARD8 opcode; + __GLXattribute *state; + + if (!dpy) + return NULL; + + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return NULL; + } + + /* Allocate our context record */ + gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec)); + if (!gc) { + /* Out of memory */ + return NULL; + } + memset(gc, 0, sizeof(struct __GLXcontextRec)); + + state = Xmalloc(sizeof(struct __GLXattributeRec)); + if (state == NULL) { + /* Out of memory */ + Xfree(gc); + return NULL; + } + gc->client_state_private = state; + memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec)); + state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL); + + /* ** Create a temporary buffer to hold GLX rendering commands. The size ** of the buffer is selected so that the maximum number of GLX rendering ** commands can fit in a single X packet and still have room in the X ** packet for the GLXRenderReq header. */ - bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq; - gc->buf = (GLubyte *) Xmalloc(bufSize); - if (!gc->buf) { - Xfree(gc->client_state_private); - Xfree(gc); - return NULL; - } - gc->bufSize = bufSize; + bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq; + gc->buf = (GLubyte *) Xmalloc(bufSize); + if (!gc->buf) { + Xfree(gc->client_state_private); + Xfree(gc); + return NULL; + } + gc->bufSize = bufSize; - /* Fill in the new context */ - gc->renderMode = GL_RENDER; + /* Fill in the new context */ + gc->renderMode = GL_RENDER; - state->storePack.alignment = 4; - state->storeUnpack.alignment = 4; + state->storePack.alignment = 4; + state->storeUnpack.alignment = 4; - gc->attributes.stackPointer = &gc->attributes.stack[0]; + gc->attributes.stackPointer = &gc->attributes.stack[0]; - /* + /* ** PERFORMANCE NOTE: A mode dependent fill image can speed things up. ** Other code uses the fastImageUnpack bit, but it is never set ** to GL_TRUE. */ - gc->fastImageUnpack = GL_FALSE; - gc->fillImage = __glFillImage; - gc->pc = gc->buf; - gc->bufEnd = gc->buf + bufSize; - gc->isDirect = GL_FALSE; - if (__glXDebug) { - /* - ** Set limit register so that there will be one command per packet - */ - gc->limit = gc->buf; - } else { - gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE; - } - gc->createDpy = dpy; - gc->majorOpcode = opcode; - - /* + gc->fastImageUnpack = GL_FALSE; + gc->fillImage = __glFillImage; + gc->pc = gc->buf; + gc->bufEnd = gc->buf + bufSize; + gc->isDirect = GL_FALSE; + if (__glXDebug) { + /* + ** Set limit register so that there will be one command per packet + */ + gc->limit = gc->buf; + } + else { + gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE; + } + gc->createDpy = dpy; + gc->majorOpcode = opcode; + + /* ** Constrain the maximum drawing command size allowed to be ** transfered using the X_GLXRender protocol request. First ** constrain by a software limit, then constrain by the protocl ** limit. */ - if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) { - bufSize = __GLX_RENDER_CMD_SIZE_LIMIT; - } - if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) { - bufSize = __GLX_MAX_RENDER_CMD_SIZE; - } - gc->maxSmallRenderCommandSize = bufSize; - return gc; + if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) { + bufSize = __GLX_RENDER_CMD_SIZE_LIMIT; + } + if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) { + bufSize = __GLX_MAX_RENDER_CMD_SIZE; + } + gc->maxSmallRenderCommandSize = bufSize; + return gc; } /** * Create a new context. Exactly one of \c vis and \c fbconfig should be * non-NULL. - * + * * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or * SGIX_fbconfig protocol be used? * \param renderType For FBConfigs, what is the rendering type? */ static GLXContext -CreateContext(Display *dpy, XVisualInfo *vis, - const __GLcontextModes * const fbconfig, - GLXContext shareList, - Bool allowDirect, GLXContextID contextID, - Bool use_glx_1_3, int renderType) +CreateContext(Display * dpy, XVisualInfo * vis, + const __GLcontextModes * const fbconfig, + GLXContext shareList, + Bool allowDirect, GLXContextID contextID, + Bool use_glx_1_3, int renderType) { - GLXContext gc; + GLXContext gc; #ifdef GLX_DIRECT_RENDERING - int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen; - __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); + int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen; + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); #endif - if ( dpy == NULL ) - return NULL; + if (dpy == NULL) + return NULL; - gc = AllocateGLXContext(dpy); - if (!gc) - return NULL; + gc = AllocateGLXContext(dpy); + if (!gc) + return NULL; - if (None == contextID) { - if ( (vis == NULL) && (fbconfig == NULL) ) - return NULL; + if (None == contextID) { + if ((vis == NULL) && (fbconfig == NULL)) + return NULL; #ifdef GLX_DIRECT_RENDERING - if (allowDirect && psc->driScreen) { - const __GLcontextModes * mode; - - if (fbconfig == NULL) { - mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid); - if (mode == NULL) { - xError error; - - error.errorCode = BadValue; - error.resourceID = vis->visualid; - error.sequenceNumber = dpy->request; - error.type = X_Error; - error.majorCode = gc->majorOpcode; - error.minorCode = X_GLXCreateContext; - _XError(dpy, &error); - return None; - } - } - else { - mode = fbconfig; - } - - gc->driContext = psc->driScreen->createContext(psc, mode, gc, - shareList, - renderType); - if (gc->driContext != NULL) { - gc->screen = mode->screen; - gc->psc = psc; - gc->mode = mode; - gc->isDirect = GL_TRUE; - } - } + if (allowDirect && psc->driScreen) { + const __GLcontextModes *mode; + + if (fbconfig == NULL) { + mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid); + if (mode == NULL) { + xError error; + + error.errorCode = BadValue; + error.resourceID = vis->visualid; + error.sequenceNumber = dpy->request; + error.type = X_Error; + error.majorCode = gc->majorOpcode; + error.minorCode = X_GLXCreateContext; + _XError(dpy, &error); + return None; + } + } + else { + mode = fbconfig; + } + + gc->driContext = psc->driScreen->createContext(psc, mode, gc, + shareList, + renderType); + if (gc->driContext != NULL) { + gc->screen = mode->screen; + gc->psc = psc; + gc->mode = mode; + gc->isDirect = GL_TRUE; + } + } #endif - LockDisplay(dpy); - if ( fbconfig == NULL ) { - xGLXCreateContextReq *req; - - /* Send the glXCreateContext request */ - GetReq(GLXCreateContext,req); - req->reqType = gc->majorOpcode; - req->glxCode = X_GLXCreateContext; - req->context = gc->xid = XAllocID(dpy); - req->visual = vis->visualid; - req->screen = vis->screen; - req->shareList = shareList ? shareList->xid : None; + LockDisplay(dpy); + if (fbconfig == NULL) { + xGLXCreateContextReq *req; + + /* Send the glXCreateContext request */ + GetReq(GLXCreateContext, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXCreateContext; + req->context = gc->xid = XAllocID(dpy); + req->visual = vis->visualid; + req->screen = vis->screen; + req->shareList = shareList ? shareList->xid : None; #ifdef GLX_DIRECT_RENDERING - req->isDirect = gc->driContext != NULL; + req->isDirect = gc->driContext != NULL; #else - req->isDirect = 0; + req->isDirect = 0; #endif - } - else if ( use_glx_1_3 ) { - xGLXCreateNewContextReq *req; - - /* Send the glXCreateNewContext request */ - GetReq(GLXCreateNewContext,req); - req->reqType = gc->majorOpcode; - req->glxCode = X_GLXCreateNewContext; - req->context = gc->xid = XAllocID(dpy); - req->fbconfig = fbconfig->fbconfigID; - req->screen = fbconfig->screen; - req->renderType = renderType; - req->shareList = shareList ? shareList->xid : None; + } + else if (use_glx_1_3) { + xGLXCreateNewContextReq *req; + + /* Send the glXCreateNewContext request */ + GetReq(GLXCreateNewContext, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXCreateNewContext; + req->context = gc->xid = XAllocID(dpy); + req->fbconfig = fbconfig->fbconfigID; + req->screen = fbconfig->screen; + req->renderType = renderType; + req->shareList = shareList ? shareList->xid : None; #ifdef GLX_DIRECT_RENDERING - req->isDirect = gc->driContext != NULL; + req->isDirect = gc->driContext != NULL; #else - req->isDirect = 0; + req->isDirect = 0; #endif - } - else { - xGLXVendorPrivateWithReplyReq *vpreq; - xGLXCreateContextWithConfigSGIXReq *req; - - /* Send the glXCreateNewContext request */ - GetReqExtra(GLXVendorPrivateWithReply, - sz_xGLXCreateContextWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq); - req = (xGLXCreateContextWithConfigSGIXReq *)vpreq; - req->reqType = gc->majorOpcode; - req->glxCode = X_GLXVendorPrivateWithReply; - req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX; - req->context = gc->xid = XAllocID(dpy); - req->fbconfig = fbconfig->fbconfigID; - req->screen = fbconfig->screen; - req->renderType = renderType; - req->shareList = shareList ? shareList->xid : None; + } + else { + xGLXVendorPrivateWithReplyReq *vpreq; + xGLXCreateContextWithConfigSGIXReq *req; + + /* Send the glXCreateNewContext request */ + GetReqExtra(GLXVendorPrivateWithReply, + sz_xGLXCreateContextWithConfigSGIXReq - + sz_xGLXVendorPrivateWithReplyReq, vpreq); + req = (xGLXCreateContextWithConfigSGIXReq *) vpreq; + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXVendorPrivateWithReply; + req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX; + req->context = gc->xid = XAllocID(dpy); + req->fbconfig = fbconfig->fbconfigID; + req->screen = fbconfig->screen; + req->renderType = renderType; + req->shareList = shareList ? shareList->xid : None; #ifdef GLX_DIRECT_RENDERING - req->isDirect = gc->driContext != NULL; + req->isDirect = gc->driContext != NULL; #else - req->isDirect = 0; + req->isDirect = 0; #endif - } + } - UnlockDisplay(dpy); - SyncHandle(); - gc->imported = GL_FALSE; - } - else { - gc->xid = contextID; - gc->imported = GL_TRUE; - } + UnlockDisplay(dpy); + SyncHandle(); + gc->imported = GL_FALSE; + } + else { + gc->xid = contextID; + gc->imported = GL_TRUE; + } - return gc; + return gc; } -PUBLIC GLXContext glXCreateContext(Display *dpy, XVisualInfo *vis, - GLXContext shareList, Bool allowDirect) +PUBLIC GLXContext +glXCreateContext(Display * dpy, XVisualInfo * vis, + GLXContext shareList, Bool allowDirect) { return CreateContext(dpy, vis, NULL, shareList, allowDirect, None, - False, 0); + False, 0); } -_X_HIDDEN void __glXFreeContext(__GLXcontext *gc) +_X_HIDDEN void +__glXFreeContext(__GLXcontext * gc) { - if (gc->vendor) XFree((char *) gc->vendor); - if (gc->renderer) XFree((char *) gc->renderer); - if (gc->version) XFree((char *) gc->version); - if (gc->extensions) XFree((char *) gc->extensions); - __glFreeAttributeState(gc); - XFree((char *) gc->buf); - Xfree((char *) gc->client_state_private); - XFree((char *) gc); - + if (gc->vendor) + XFree((char *) gc->vendor); + if (gc->renderer) + XFree((char *) gc->renderer); + if (gc->version) + XFree((char *) gc->version); + if (gc->extensions) + XFree((char *) gc->extensions); + __glFreeAttributeState(gc); + XFree((char *) gc->buf); + Xfree((char *) gc->client_state_private); + XFree((char *) gc); + } /* ** Destroy the named context */ -static void -DestroyContext(Display *dpy, GLXContext gc) +static void +DestroyContext(Display * dpy, GLXContext gc) { - xGLXDestroyContextReq *req; - GLXContextID xid; - CARD8 opcode; - GLboolean imported; + xGLXDestroyContextReq *req; + GLXContextID xid; + CARD8 opcode; + GLboolean imported; - opcode = __glXSetupForCommand(dpy); - if (!opcode || !gc) { - return; - } + opcode = __glXSetupForCommand(dpy); + if (!opcode || !gc) { + return; + } - __glXLock(); - xid = gc->xid; - imported = gc->imported; - gc->xid = None; + __glXLock(); + xid = gc->xid; + imported = gc->imported; + gc->xid = None; #ifdef GLX_DIRECT_RENDERING - /* Destroy the direct rendering context */ - if (gc->driContext) { - (*gc->driContext->destroyContext)(gc->driContext, gc->psc, dpy); - gc->driContext = NULL; - GarbageCollectDRIDrawables(dpy, gc->psc); - } + /* Destroy the direct rendering context */ + if (gc->driContext) { + (*gc->driContext->destroyContext) (gc->driContext, gc->psc, dpy); + gc->driContext = NULL; + GarbageCollectDRIDrawables(dpy, gc->psc); + } #endif - __glXFreeVertexArrayState(gc); + __glXFreeVertexArrayState(gc); - if (gc->currentDpy) { - /* Have to free later cuz it's in use now */ - __glXUnlock(); - } else { - /* Destroy the handle if not current to anybody */ - __glXUnlock(); - __glXFreeContext(gc); - } + if (gc->currentDpy) { + /* Have to free later cuz it's in use now */ + __glXUnlock(); + } + else { + /* Destroy the handle if not current to anybody */ + __glXUnlock(); + __glXFreeContext(gc); + } - if (!imported) { - /* - ** This dpy also created the server side part of the context. - ** Send the glXDestroyContext request. - */ - LockDisplay(dpy); - GetReq(GLXDestroyContext,req); - req->reqType = opcode; - req->glxCode = X_GLXDestroyContext; - req->context = xid; - UnlockDisplay(dpy); - SyncHandle(); - } + if (!imported) { + /* + ** This dpy also created the server side part of the context. + ** Send the glXDestroyContext request. + */ + LockDisplay(dpy); + GetReq(GLXDestroyContext, req); + req->reqType = opcode; + req->glxCode = X_GLXDestroyContext; + req->context = xid; + UnlockDisplay(dpy); + SyncHandle(); + } } -PUBLIC void glXDestroyContext(Display *dpy, GLXContext gc) +PUBLIC void +glXDestroyContext(Display * dpy, GLXContext gc) { - DestroyContext(dpy, gc); + DestroyContext(dpy, gc); } /* ** Return the major and minor version #s for the GLX extension */ -PUBLIC Bool glXQueryVersion(Display *dpy, int *major, int *minor) +PUBLIC Bool +glXQueryVersion(Display * dpy, int *major, int *minor) { - __GLXdisplayPrivate *priv; + __GLXdisplayPrivate *priv; - /* Init the extension. This fetches the major and minor version. */ - priv = __glXInitialize(dpy); - if (!priv) return GL_FALSE; + /* Init the extension. This fetches the major and minor version. */ + priv = __glXInitialize(dpy); + if (!priv) + return GL_FALSE; - if (major) *major = priv->majorVersion; - if (minor) *minor = priv->minorVersion; - return GL_TRUE; + if (major) + *major = priv->majorVersion; + if (minor) + *minor = priv->minorVersion; + return GL_TRUE; } /* ** Query the existance of the GLX extension */ -PUBLIC Bool glXQueryExtension(Display *dpy, int *errorBase, int *eventBase) -{ - int major_op, erb, evb; - Bool rv; - - rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb); - if (rv) { - if (errorBase) *errorBase = erb; - if (eventBase) *eventBase = evb; - } - return rv; +PUBLIC Bool +glXQueryExtension(Display * dpy, int *errorBase, int *eventBase) +{ + int major_op, erb, evb; + Bool rv; + + rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb); + if (rv) { + if (errorBase) + *errorBase = erb; + if (eventBase) + *eventBase = evb; + } + return rv; } /* ** Put a barrier in the token stream that forces the GL to finish its ** work before X can proceed. */ -PUBLIC void glXWaitGL(void) +PUBLIC void +glXWaitGL(void) { - xGLXWaitGLReq *req; - GLXContext gc = __glXGetCurrentContext(); - Display *dpy = gc->currentDpy; + xGLXWaitGLReq *req; + GLXContext gc = __glXGetCurrentContext(); + Display *dpy = gc->currentDpy; - if (!dpy) return; + if (!dpy) + return; - /* Flush any pending commands out */ - __glXFlushRenderBuffer(gc, gc->pc); + /* Flush any pending commands out */ + __glXFlushRenderBuffer(gc, gc->pc); #ifdef GLX_DIRECT_RENDERING - if (gc->driContext) { - int screen; - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, gc->currentDrawable, &screen); - - if ( pdraw != NULL ) { - __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); - glFlush(); - if (psc->driScreen->waitGL != NULL) - (*psc->driScreen->waitGL)(pdraw); - } - return; - } + if (gc->driContext) { + int screen; + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(dpy, gc->currentDrawable, &screen); + + if (pdraw != NULL) { + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); + glFlush(); + if (psc->driScreen->waitGL != NULL) + (*psc->driScreen->waitGL) (pdraw); + } + return; + } #endif - /* Send the glXWaitGL request */ - LockDisplay(dpy); - GetReq(GLXWaitGL,req); - req->reqType = gc->majorOpcode; - req->glxCode = X_GLXWaitGL; - req->contextTag = gc->currentContextTag; - UnlockDisplay(dpy); - SyncHandle(); + /* Send the glXWaitGL request */ + LockDisplay(dpy); + GetReq(GLXWaitGL, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXWaitGL; + req->contextTag = gc->currentContextTag; + UnlockDisplay(dpy); + SyncHandle(); } /* ** Put a barrier in the token stream that forces X to finish its ** work before GL can proceed. */ -PUBLIC void glXWaitX(void) +PUBLIC void +glXWaitX(void) { - xGLXWaitXReq *req; - GLXContext gc = __glXGetCurrentContext(); - Display *dpy = gc->currentDpy; + xGLXWaitXReq *req; + GLXContext gc = __glXGetCurrentContext(); + Display *dpy = gc->currentDpy; - if (!dpy) return; + if (!dpy) + return; - /* Flush any pending commands out */ - __glXFlushRenderBuffer(gc, gc->pc); + /* Flush any pending commands out */ + __glXFlushRenderBuffer(gc, gc->pc); #ifdef GLX_DIRECT_RENDERING - if (gc->driContext) { - int screen; - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, gc->currentDrawable, &screen); - - if ( pdraw != NULL ) { - __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); - if (psc->driScreen->waitX != NULL) - (*psc->driScreen->waitX)(pdraw); - } else - XSync(dpy, False); - return; - } + if (gc->driContext) { + int screen; + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(dpy, gc->currentDrawable, &screen); + + if (pdraw != NULL) { + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); + if (psc->driScreen->waitX != NULL) + (*psc->driScreen->waitX) (pdraw); + } + else + XSync(dpy, False); + return; + } #endif - /* + /* ** Send the glXWaitX request. */ - LockDisplay(dpy); - GetReq(GLXWaitX,req); - req->reqType = gc->majorOpcode; - req->glxCode = X_GLXWaitX; - req->contextTag = gc->currentContextTag; - UnlockDisplay(dpy); - SyncHandle(); + LockDisplay(dpy); + GetReq(GLXWaitX, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXWaitX; + req->contextTag = gc->currentContextTag; + UnlockDisplay(dpy); + SyncHandle(); } -PUBLIC void glXUseXFont(Font font, int first, int count, int listBase) +PUBLIC void +glXUseXFont(Font font, int first, int count, int listBase) { - xGLXUseXFontReq *req; - GLXContext gc = __glXGetCurrentContext(); - Display *dpy = gc->currentDpy; + xGLXUseXFontReq *req; + GLXContext gc = __glXGetCurrentContext(); + Display *dpy = gc->currentDpy; - if (!dpy) return; + if (!dpy) + return; - /* Flush any pending commands out */ - (void) __glXFlushRenderBuffer(gc, gc->pc); + /* Flush any pending commands out */ + (void) __glXFlushRenderBuffer(gc, gc->pc); #ifdef GLX_DIRECT_RENDERING - if (gc->driContext) { + if (gc->driContext) { DRI_glXUseXFont(font, first, count, listBase); return; - } + } #endif - /* Send the glXUseFont request */ - LockDisplay(dpy); - GetReq(GLXUseXFont,req); - req->reqType = gc->majorOpcode; - req->glxCode = X_GLXUseXFont; - req->contextTag = gc->currentContextTag; - req->font = font; - req->first = first; - req->count = count; - req->listBase = listBase; - UnlockDisplay(dpy); - SyncHandle(); + /* Send the glXUseFont request */ + LockDisplay(dpy); + GetReq(GLXUseXFont, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXUseXFont; + req->contextTag = gc->currentContextTag; + req->font = font; + req->first = first; + req->count = count; + req->listBase = listBase; + UnlockDisplay(dpy); + SyncHandle(); } /************************************************************************/ @@ -714,46 +744,48 @@ PUBLIC void glXUseXFont(Font font, int first, int count, int listBase) ** Copy the source context to the destination context using the ** attribute "mask". */ -PUBLIC void glXCopyContext(Display *dpy, GLXContext source, - GLXContext dest, unsigned long mask) +PUBLIC void +glXCopyContext(Display * dpy, GLXContext source, + GLXContext dest, unsigned long mask) { - xGLXCopyContextReq *req; - GLXContext gc = __glXGetCurrentContext(); - GLXContextTag tag; - CARD8 opcode; + xGLXCopyContextReq *req; + GLXContext gc = __glXGetCurrentContext(); + GLXContextTag tag; + CARD8 opcode; - opcode = __glXSetupForCommand(dpy); - if (!opcode) { - return; - } + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return; + } #ifdef GLX_DIRECT_RENDERING - if (gc->driContext) { - /* NOT_DONE: This does not work yet */ - } + if (gc->driContext) { + /* NOT_DONE: This does not work yet */ + } #endif - /* + /* ** If the source is the current context, send its tag so that the context ** can be flushed before the copy. */ - if (source == gc && dpy == gc->currentDpy) { - tag = gc->currentContextTag; - } else { - tag = 0; - } - - /* Send the glXCopyContext request */ - LockDisplay(dpy); - GetReq(GLXCopyContext,req); - req->reqType = opcode; - req->glxCode = X_GLXCopyContext; - req->source = source ? source->xid : None; - req->dest = dest ? dest->xid : None; - req->mask = mask; - req->contextTag = tag; - UnlockDisplay(dpy); - SyncHandle(); + if (source == gc && dpy == gc->currentDpy) { + tag = gc->currentContextTag; + } + else { + tag = 0; + } + + /* Send the glXCopyContext request */ + LockDisplay(dpy); + GetReq(GLXCopyContext, req); + req->reqType = opcode; + req->glxCode = X_GLXCopyContext; + req->source = source ? source->xid : None; + req->dest = dest ? dest->xid : None; + req->mask = mask; + req->contextTag = tag; + UnlockDisplay(dpy); + SyncHandle(); } @@ -765,42 +797,43 @@ PUBLIC void glXCopyContext(Display *dpy, GLXContext source, * * \returns \c GL_TRUE if the context is direct rendering or not. */ -static Bool __glXIsDirect(Display *dpy, GLXContextID contextID) +static Bool +__glXIsDirect(Display * dpy, GLXContextID contextID) { #if !defined(USE_XCB) - xGLXIsDirectReq *req; - xGLXIsDirectReply reply; + xGLXIsDirectReq *req; + xGLXIsDirectReply reply; #endif - CARD8 opcode; + CARD8 opcode; - opcode = __glXSetupForCommand(dpy); - if (!opcode) { - return GL_FALSE; - } + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return GL_FALSE; + } #ifdef USE_XCB - xcb_connection_t* c = XGetXCBConnection(dpy); - xcb_glx_is_direct_reply_t* reply = - xcb_glx_is_direct_reply(c, - xcb_glx_is_direct(c, contextID), - NULL); + xcb_connection_t *c = XGetXCBConnection(dpy); + xcb_glx_is_direct_reply_t *reply = xcb_glx_is_direct_reply(c, + xcb_glx_is_direct + (c, contextID), + NULL); const Bool is_direct = reply->is_direct ? True : False; free(reply); return is_direct; #else - /* Send the glXIsDirect request */ - LockDisplay(dpy); - GetReq(GLXIsDirect,req); - req->reqType = opcode; - req->glxCode = X_GLXIsDirect; - req->context = contextID; - _XReply(dpy, (xReply*) &reply, 0, False); - UnlockDisplay(dpy); - SyncHandle(); - - return reply.isDirect; + /* Send the glXIsDirect request */ + LockDisplay(dpy); + GetReq(GLXIsDirect, req); + req->reqType = opcode; + req->glxCode = X_GLXIsDirect; + req->context = contextID; + _XReply(dpy, (xReply *) & reply, 0, False); + UnlockDisplay(dpy); + SyncHandle(); + + return reply.isDirect; #endif /* USE_XCB */ } @@ -810,162 +843,168 @@ static Bool __glXIsDirect(Display *dpy, GLXContextID contextID) * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with * the GLX protocol here at all? */ -PUBLIC Bool glXIsDirect(Display *dpy, GLXContext gc) +PUBLIC Bool +glXIsDirect(Display * dpy, GLXContext gc) { - if (!gc) { - return GL_FALSE; + if (!gc) { + return GL_FALSE; #ifdef GLX_DIRECT_RENDERING - } else if (gc->driContext) { - return GL_TRUE; + } + else if (gc->driContext) { + return GL_TRUE; #endif - } - return __glXIsDirect(dpy, gc->xid); -} - -PUBLIC GLXPixmap glXCreateGLXPixmap(Display *dpy, XVisualInfo *vis, - Pixmap pixmap) -{ - xGLXCreateGLXPixmapReq *req; - GLXPixmap xid; - CARD8 opcode; - - opcode = __glXSetupForCommand(dpy); - if (!opcode) { - return None; - } - - /* Send the glXCreateGLXPixmap request */ - LockDisplay(dpy); - GetReq(GLXCreateGLXPixmap,req); - req->reqType = opcode; - req->glxCode = X_GLXCreateGLXPixmap; - req->screen = vis->screen; - req->visual = vis->visualid; - req->pixmap = pixmap; - req->glxpixmap = xid = XAllocID(dpy); - UnlockDisplay(dpy); - SyncHandle(); + } + return __glXIsDirect(dpy, gc->xid); +} + +PUBLIC GLXPixmap +glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap) +{ + xGLXCreateGLXPixmapReq *req; + GLXPixmap xid; + CARD8 opcode; + + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return None; + } + + /* Send the glXCreateGLXPixmap request */ + LockDisplay(dpy); + GetReq(GLXCreateGLXPixmap, req); + req->reqType = opcode; + req->glxCode = X_GLXCreateGLXPixmap; + req->screen = vis->screen; + req->visual = vis->visualid; + req->pixmap = pixmap; + req->glxpixmap = xid = XAllocID(dpy); + UnlockDisplay(dpy); + SyncHandle(); #ifdef GLX_DIRECT_RENDERING - do { - /* FIXME: Maybe delay __DRIdrawable creation until the drawable - * is actually bound to a context... */ - - __GLXdisplayPrivate *const priv = __glXInitialize(dpy); - __GLXDRIdrawable *pdraw; - __GLXscreenConfigs *psc; - __GLcontextModes *modes; - - psc = &priv->screenConfigs[vis->screen]; - if (psc->driScreen == NULL) - break; - modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid); - pdraw = psc->driScreen->createDrawable(psc, pixmap, req->glxpixmap, modes); - if (pdraw == NULL) { - fprintf(stderr, "failed to create pixmap\n"); - break; - } - - if (__glxHashInsert(psc->drawHash, req->glxpixmap, pdraw)) { - (*pdraw->destroyDrawable) (pdraw); - return None; /* FIXME: Check what we're supposed to do here... */ - } - } while (0); + do { + /* FIXME: Maybe delay __DRIdrawable creation until the drawable + * is actually bound to a context... */ + + __GLXdisplayPrivate *const priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw; + __GLXscreenConfigs *psc; + __GLcontextModes *modes; + + psc = &priv->screenConfigs[vis->screen]; + if (psc->driScreen == NULL) + break; + modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid); + pdraw = psc->driScreen->createDrawable(psc, pixmap, req->glxpixmap, modes); + if (pdraw == NULL) { + fprintf(stderr, "failed to create pixmap\n"); + break; + } + + if (__glxHashInsert(psc->drawHash, req->glxpixmap, pdraw)) { + (*pdraw->destroyDrawable) (pdraw); + return None; /* FIXME: Check what we're supposed to do here... */ + } + } while (0); #endif - return xid; + return xid; } /* ** Destroy the named pixmap */ -PUBLIC void glXDestroyGLXPixmap(Display *dpy, GLXPixmap glxpixmap) -{ - xGLXDestroyGLXPixmapReq *req; - CARD8 opcode; - - opcode = __glXSetupForCommand(dpy); - if (!opcode) { - return; - } - - /* Send the glXDestroyGLXPixmap request */ - LockDisplay(dpy); - GetReq(GLXDestroyGLXPixmap,req); - req->reqType = opcode; - req->glxCode = X_GLXDestroyGLXPixmap; - req->glxpixmap = glxpixmap; - UnlockDisplay(dpy); - SyncHandle(); +PUBLIC void +glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap) +{ + xGLXDestroyGLXPixmapReq *req; + CARD8 opcode; + + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return; + } + + /* Send the glXDestroyGLXPixmap request */ + LockDisplay(dpy); + GetReq(GLXDestroyGLXPixmap, req); + req->reqType = opcode; + req->glxCode = X_GLXDestroyGLXPixmap; + req->glxpixmap = glxpixmap; + UnlockDisplay(dpy); + SyncHandle(); #ifdef GLX_DIRECT_RENDERING - { - int screen; - __GLXdisplayPrivate *const priv = __glXInitialize(dpy); - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap, &screen); - __GLXscreenConfigs *psc = &priv->screenConfigs[screen]; - - if (pdraw != NULL) { - (*pdraw->destroyDrawable) (pdraw); - __glxHashDelete(psc->drawHash, glxpixmap); - } - } + { + int screen; + __GLXdisplayPrivate *const priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap, &screen); + __GLXscreenConfigs *psc = &priv->screenConfigs[screen]; + + if (pdraw != NULL) { + (*pdraw->destroyDrawable) (pdraw); + __glxHashDelete(psc->drawHash, glxpixmap); + } + } #endif } -PUBLIC void glXSwapBuffers(Display *dpy, GLXDrawable drawable) +PUBLIC void +glXSwapBuffers(Display * dpy, GLXDrawable drawable) { - GLXContext gc; - GLXContextTag tag; - CARD8 opcode; + GLXContext gc; + GLXContextTag tag; + CARD8 opcode; #ifdef USE_XCB - xcb_connection_t *c; + xcb_connection_t *c; #else - xGLXSwapBuffersReq *req; + xGLXSwapBuffersReq *req; #endif #ifdef GLX_DIRECT_RENDERING - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); - if (pdraw != NULL) { - glFlush(); - (*pdraw->psc->driScreen->swapBuffers)(pdraw); - return; - } + if (pdraw != NULL) { + glFlush(); + (*pdraw->psc->driScreen->swapBuffers) (pdraw); + return; + } #endif - opcode = __glXSetupForCommand(dpy); - if (!opcode) { - return; - } + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return; + } - /* + /* ** The calling thread may or may not have a current context. If it ** does, send the context tag so the server can do a flush. */ - gc = __glXGetCurrentContext(); - if ((gc != NULL) && (dpy == gc->currentDpy) && - ((drawable == gc->currentDrawable) || (drawable == gc->currentReadable)) ) { - tag = gc->currentContextTag; - } else { - tag = 0; - } + gc = __glXGetCurrentContext(); + if ((gc != NULL) && (dpy == gc->currentDpy) && + ((drawable == gc->currentDrawable) + || (drawable == gc->currentReadable))) { + tag = gc->currentContextTag; + } + else { + tag = 0; + } #ifdef USE_XCB - c = XGetXCBConnection(dpy); - xcb_glx_swap_buffers(c, tag, drawable); - xcb_flush(c); + c = XGetXCBConnection(dpy); + xcb_glx_swap_buffers(c, tag, drawable); + xcb_flush(c); #else - /* Send the glXSwapBuffers request */ - LockDisplay(dpy); - GetReq(GLXSwapBuffers,req); - req->reqType = opcode; - req->glxCode = X_GLXSwapBuffers; - req->drawable = drawable; - req->contextTag = tag; - UnlockDisplay(dpy); - SyncHandle(); - XFlush(dpy); + /* Send the glXSwapBuffers request */ + LockDisplay(dpy); + GetReq(GLXSwapBuffers, req); + req->reqType = opcode; + req->glxCode = X_GLXSwapBuffers; + req->drawable = drawable; + req->contextTag = tag; + UnlockDisplay(dpy); + SyncHandle(); + XFlush(dpy); #endif /* USE_XCB */ } @@ -974,94 +1013,96 @@ PUBLIC void glXSwapBuffers(Display *dpy, GLXDrawable drawable) ** Return configuration information for the given display, screen and ** visual combination. */ -PUBLIC int glXGetConfig(Display *dpy, XVisualInfo *vis, int attribute, - int *value_return) -{ - __GLXdisplayPrivate *priv; - __GLXscreenConfigs *psc; - __GLcontextModes *modes; - int status; - - status = GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ); - if ( status == Success ) { - modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid); - - /* Lookup attribute after first finding a match on the visual */ - if ( modes != NULL ) { - return _gl_get_context_mode_data( modes, attribute, value_return ); - } - - status = GLX_BAD_VISUAL; - } - - /* +PUBLIC int +glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute, + int *value_return) +{ + __GLXdisplayPrivate *priv; + __GLXscreenConfigs *psc; + __GLcontextModes *modes; + int status; + + status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc); + if (status == Success) { + modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid); + + /* Lookup attribute after first finding a match on the visual */ + if (modes != NULL) { + return _gl_get_context_mode_data(modes, attribute, value_return); + } + + status = GLX_BAD_VISUAL; + } + + /* ** If we can't find the config for this visual, this visual is not ** supported by the OpenGL implementation on the server. */ - if ( (status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL) ) { - *value_return = GL_FALSE; - status = Success; - } + if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) { + *value_return = GL_FALSE; + status = Success; + } - return status; + return status; } /************************************************************************/ static void -init_fbconfig_for_chooser( __GLcontextModes * config, - GLboolean fbconfig_style_tags ) -{ - memset( config, 0, sizeof( __GLcontextModes ) ); - config->visualID = (XID) GLX_DONT_CARE; - config->visualType = GLX_DONT_CARE; - - /* glXChooseFBConfig specifies different defaults for these two than - * glXChooseVisual. - */ - if ( fbconfig_style_tags ) { - config->rgbMode = GL_TRUE; - config->doubleBufferMode = GLX_DONT_CARE; - } - - config->visualRating = GLX_DONT_CARE; - config->transparentPixel = GLX_NONE; - config->transparentRed = GLX_DONT_CARE; - config->transparentGreen = GLX_DONT_CARE; - config->transparentBlue = GLX_DONT_CARE; - config->transparentAlpha = GLX_DONT_CARE; - config->transparentIndex = GLX_DONT_CARE; - - config->drawableType = GLX_WINDOW_BIT; - config->renderType = (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT; - config->xRenderable = GLX_DONT_CARE; - config->fbconfigID = (GLXFBConfigID)(GLX_DONT_CARE); - - config->swapMethod = GLX_DONT_CARE; -} - -#define MATCH_DONT_CARE( param ) \ - do { \ - if ( (a-> param != GLX_DONT_CARE) \ - && (a-> param != b-> param) ) { \ - return False; \ - } \ - } while ( 0 ) - -#define MATCH_MINIMUM( param ) \ - do { \ - if ( (a-> param != GLX_DONT_CARE) \ - && (a-> param > b-> param) ) { \ - return False; \ - } \ - } while ( 0 ) - -#define MATCH_EXACT( param ) \ - do { \ - if ( a-> param != b-> param) { \ - return False; \ - } \ - } while ( 0 ) +init_fbconfig_for_chooser(__GLcontextModes * config, + GLboolean fbconfig_style_tags) +{ + memset(config, 0, sizeof(__GLcontextModes)); + config->visualID = (XID) GLX_DONT_CARE; + config->visualType = GLX_DONT_CARE; + + /* glXChooseFBConfig specifies different defaults for these two than + * glXChooseVisual. + */ + if (fbconfig_style_tags) { + config->rgbMode = GL_TRUE; + config->doubleBufferMode = GLX_DONT_CARE; + } + + config->visualRating = GLX_DONT_CARE; + config->transparentPixel = GLX_NONE; + config->transparentRed = GLX_DONT_CARE; + config->transparentGreen = GLX_DONT_CARE; + config->transparentBlue = GLX_DONT_CARE; + config->transparentAlpha = GLX_DONT_CARE; + config->transparentIndex = GLX_DONT_CARE; + + config->drawableType = GLX_WINDOW_BIT; + config->renderType = + (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT; + config->xRenderable = GLX_DONT_CARE; + config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE); + + config->swapMethod = GLX_DONT_CARE; +} + +#define MATCH_DONT_CARE( param ) \ + do { \ + if ( (a-> param != GLX_DONT_CARE) \ + && (a-> param != b-> param) ) { \ + return False; \ + } \ + } while ( 0 ) + +#define MATCH_MINIMUM( param ) \ + do { \ + if ( (a-> param != GLX_DONT_CARE) \ + && (a-> param > b-> param) ) { \ + return False; \ + } \ + } while ( 0 ) + +#define MATCH_EXACT( param ) \ + do { \ + if ( a-> param != b-> param) { \ + return False; \ + } \ + } while ( 0 ) /** * Determine if two GLXFBConfigs are compatible. @@ -1070,80 +1111,80 @@ init_fbconfig_for_chooser( __GLcontextModes * config, * \param b Server specified config to test against \c a. */ static Bool -fbconfigs_compatible( const __GLcontextModes * const a, - const __GLcontextModes * const b ) -{ - MATCH_DONT_CARE( doubleBufferMode ); - MATCH_DONT_CARE( visualType ); - MATCH_DONT_CARE( visualRating ); - MATCH_DONT_CARE( xRenderable ); - MATCH_DONT_CARE( fbconfigID ); - MATCH_DONT_CARE( swapMethod ); - - MATCH_MINIMUM( rgbBits ); - MATCH_MINIMUM( numAuxBuffers ); - MATCH_MINIMUM( redBits ); - MATCH_MINIMUM( greenBits ); - MATCH_MINIMUM( blueBits ); - MATCH_MINIMUM( alphaBits ); - MATCH_MINIMUM( depthBits ); - MATCH_MINIMUM( stencilBits ); - MATCH_MINIMUM( accumRedBits ); - MATCH_MINIMUM( accumGreenBits ); - MATCH_MINIMUM( accumBlueBits ); - MATCH_MINIMUM( accumAlphaBits ); - MATCH_MINIMUM( sampleBuffers ); - MATCH_MINIMUM( maxPbufferWidth ); - MATCH_MINIMUM( maxPbufferHeight ); - MATCH_MINIMUM( maxPbufferPixels ); - MATCH_MINIMUM( samples ); - - MATCH_DONT_CARE( stereoMode ); - MATCH_EXACT( level ); - - if ( ((a->drawableType & b->drawableType) == 0) - || ((a->renderType & b->renderType) == 0) ) { - return False; - } - - - /* There is a bug in a few of the XFree86 DDX drivers. They contain - * visuals with a "transparent type" of 0 when they really mean GLX_NONE. - * Technically speaking, it is a bug in the DDX driver, but there is - * enough of an installed base to work around the problem here. In any - * case, 0 is not a valid value of the transparent type, so we'll treat 0 - * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and - * 0 from the server to be a match to maintain backward compatibility with - * the (broken) drivers. - */ - - if ( a->transparentPixel != GLX_DONT_CARE - && a->transparentPixel != 0 ) { - if ( a->transparentPixel == GLX_NONE ) { - if ( b->transparentPixel != GLX_NONE && b->transparentPixel != 0 ) - return False; - } else { - MATCH_EXACT( transparentPixel ); - } - - switch ( a->transparentPixel ) { - case GLX_TRANSPARENT_RGB: - MATCH_DONT_CARE( transparentRed ); - MATCH_DONT_CARE( transparentGreen ); - MATCH_DONT_CARE( transparentBlue ); - MATCH_DONT_CARE( transparentAlpha ); - break; - - case GLX_TRANSPARENT_INDEX: - MATCH_DONT_CARE( transparentIndex ); - break; - - default: - break; - } - } - - return True; +fbconfigs_compatible(const __GLcontextModes * const a, + const __GLcontextModes * const b) +{ + MATCH_DONT_CARE(doubleBufferMode); + MATCH_DONT_CARE(visualType); + MATCH_DONT_CARE(visualRating); + MATCH_DONT_CARE(xRenderable); + MATCH_DONT_CARE(fbconfigID); + MATCH_DONT_CARE(swapMethod); + + MATCH_MINIMUM(rgbBits); + MATCH_MINIMUM(numAuxBuffers); + MATCH_MINIMUM(redBits); + MATCH_MINIMUM(greenBits); + MATCH_MINIMUM(blueBits); + MATCH_MINIMUM(alphaBits); + MATCH_MINIMUM(depthBits); + MATCH_MINIMUM(stencilBits); + MATCH_MINIMUM(accumRedBits); + MATCH_MINIMUM(accumGreenBits); + MATCH_MINIMUM(accumBlueBits); + MATCH_MINIMUM(accumAlphaBits); + MATCH_MINIMUM(sampleBuffers); + MATCH_MINIMUM(maxPbufferWidth); + MATCH_MINIMUM(maxPbufferHeight); + MATCH_MINIMUM(maxPbufferPixels); + MATCH_MINIMUM(samples); + + MATCH_DONT_CARE(stereoMode); + MATCH_EXACT(level); + + if (((a->drawableType & b->drawableType) == 0) + || ((a->renderType & b->renderType) == 0)) { + return False; + } + + + /* There is a bug in a few of the XFree86 DDX drivers. They contain + * visuals with a "transparent type" of 0 when they really mean GLX_NONE. + * Technically speaking, it is a bug in the DDX driver, but there is + * enough of an installed base to work around the problem here. In any + * case, 0 is not a valid value of the transparent type, so we'll treat 0 + * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and + * 0 from the server to be a match to maintain backward compatibility with + * the (broken) drivers. + */ + + if (a->transparentPixel != GLX_DONT_CARE && a->transparentPixel != 0) { + if (a->transparentPixel == GLX_NONE) { + if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0) + return False; + } + else { + MATCH_EXACT(transparentPixel); + } + + switch (a->transparentPixel) { + case GLX_TRANSPARENT_RGB: + MATCH_DONT_CARE(transparentRed); + MATCH_DONT_CARE(transparentGreen); + MATCH_DONT_CARE(transparentBlue); + MATCH_DONT_CARE(transparentAlpha); + break; + + case GLX_TRANSPARENT_INDEX: + MATCH_DONT_CARE(transparentIndex); + break; + + default: + break; + } + } + + return True; } @@ -1153,39 +1194,39 @@ fbconfigs_compatible( const __GLcontextModes * const a, * Well, that's really hard to do with the code as-is. This behavior is * closer to correct, but still not technically right. */ -#define PREFER_LARGER_OR_ZERO(comp) \ - do { \ - if ( ((*a)-> comp) != ((*b)-> comp) ) { \ - if ( ((*a)-> comp) == 0 ) { \ - return -1; \ - } \ - else if ( ((*b)-> comp) == 0 ) { \ - return 1; \ - } \ - else { \ - return ((*b)-> comp) - ((*a)-> comp) ; \ - } \ - } \ - } while( 0 ) - -#define PREFER_LARGER(comp) \ - do { \ - if ( ((*a)-> comp) != ((*b)-> comp) ) { \ - return ((*b)-> comp) - ((*a)-> comp) ; \ - } \ - } while( 0 ) - -#define PREFER_SMALLER(comp) \ - do { \ - if ( ((*a)-> comp) != ((*b)-> comp) ) { \ - return ((*a)-> comp) - ((*b)-> comp) ; \ - } \ - } while( 0 ) +#define PREFER_LARGER_OR_ZERO(comp) \ + do { \ + if ( ((*a)-> comp) != ((*b)-> comp) ) { \ + if ( ((*a)-> comp) == 0 ) { \ + return -1; \ + } \ + else if ( ((*b)-> comp) == 0 ) { \ + return 1; \ + } \ + else { \ + return ((*b)-> comp) - ((*a)-> comp) ; \ + } \ + } \ + } while( 0 ) + +#define PREFER_LARGER(comp) \ + do { \ + if ( ((*a)-> comp) != ((*b)-> comp) ) { \ + return ((*b)-> comp) - ((*a)-> comp) ; \ + } \ + } while( 0 ) + +#define PREFER_SMALLER(comp) \ + do { \ + if ( ((*a)-> comp) != ((*b)-> comp) ) { \ + return ((*a)-> comp) - ((*b)-> comp) ; \ + } \ + } while( 0 ) /** * Compare two GLXFBConfigs. This function is intended to be used as the * compare function passed in to qsort. - * + * * \returns If \c a is a "better" config, according to the specification of * SGIX_fbconfig, a number less than zero is returned. If \c b is * better, then a number greater than zero is return. If both are @@ -1193,66 +1234,66 @@ fbconfigs_compatible( const __GLcontextModes * const a, * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX */ static int -fbconfig_compare( const __GLcontextModes * const * const a, - const __GLcontextModes * const * const b ) +fbconfig_compare(const __GLcontextModes * const *const a, + const __GLcontextModes * const *const b) { - /* The order of these comparisons must NOT change. It is defined by - * the GLX 1.3 spec and ARB_multisample. - */ + /* The order of these comparisons must NOT change. It is defined by + * the GLX 1.3 spec and ARB_multisample. + */ - PREFER_SMALLER( visualSelectGroup ); + PREFER_SMALLER(visualSelectGroup); - /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and - * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the - * numerical sort order of the enums (0x8000, 0x8001, and 0x800D). - */ - PREFER_SMALLER( visualRating ); + /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and + * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the + * numerical sort order of the enums (0x8000, 0x8001, and 0x800D). + */ + PREFER_SMALLER(visualRating); - /* This isn't quite right. It is supposed to compare the sum of the - * components the user specifically set minimums for. - */ - PREFER_LARGER_OR_ZERO( redBits ); - PREFER_LARGER_OR_ZERO( greenBits ); - PREFER_LARGER_OR_ZERO( blueBits ); - PREFER_LARGER_OR_ZERO( alphaBits ); + /* This isn't quite right. It is supposed to compare the sum of the + * components the user specifically set minimums for. + */ + PREFER_LARGER_OR_ZERO(redBits); + PREFER_LARGER_OR_ZERO(greenBits); + PREFER_LARGER_OR_ZERO(blueBits); + PREFER_LARGER_OR_ZERO(alphaBits); - PREFER_SMALLER( rgbBits ); + PREFER_SMALLER(rgbBits); - if ( ((*a)->doubleBufferMode != (*b)->doubleBufferMode) ) { - /* Prefer single-buffer. - */ - return ( !(*a)->doubleBufferMode ) ? -1 : 1; - } + if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) { + /* Prefer single-buffer. + */ + return (!(*a)->doubleBufferMode) ? -1 : 1; + } - PREFER_SMALLER( numAuxBuffers ); + PREFER_SMALLER(numAuxBuffers); - PREFER_LARGER_OR_ZERO( depthBits ); - PREFER_SMALLER( stencilBits ); + PREFER_LARGER_OR_ZERO(depthBits); + PREFER_SMALLER(stencilBits); - /* This isn't quite right. It is supposed to compare the sum of the - * components the user specifically set minimums for. - */ - PREFER_LARGER_OR_ZERO( accumRedBits ); - PREFER_LARGER_OR_ZERO( accumGreenBits ); - PREFER_LARGER_OR_ZERO( accumBlueBits ); - PREFER_LARGER_OR_ZERO( accumAlphaBits ); + /* This isn't quite right. It is supposed to compare the sum of the + * components the user specifically set minimums for. + */ + PREFER_LARGER_OR_ZERO(accumRedBits); + PREFER_LARGER_OR_ZERO(accumGreenBits); + PREFER_LARGER_OR_ZERO(accumBlueBits); + PREFER_LARGER_OR_ZERO(accumAlphaBits); - PREFER_SMALLER( visualType ); + PREFER_SMALLER(visualType); - /* None of the multisample specs say where this comparison should happen, - * so I put it near the end. - */ - PREFER_SMALLER( sampleBuffers ); - PREFER_SMALLER( samples ); + /* None of the multisample specs say where this comparison should happen, + * so I put it near the end. + */ + PREFER_SMALLER(sampleBuffers); + PREFER_SMALLER(samples); - /* None of the pbuffer or fbconfig specs say that this comparison needs - * to happen at all, but it seems like it should. - */ - PREFER_LARGER( maxPbufferWidth ); - PREFER_LARGER( maxPbufferHeight ); - PREFER_LARGER( maxPbufferPixels ); + /* None of the pbuffer or fbconfig specs say that this comparison needs + * to happen at all, but it seems like it should. + */ + PREFER_LARGER(maxPbufferWidth); + PREFER_LARGER(maxPbufferHeight); + PREFER_LARGER(maxPbufferPixels); - return 0; + return 0; } @@ -1260,7 +1301,7 @@ fbconfig_compare( const __GLcontextModes * const * const a, * Selects and sorts a subset of the supplied configs based on the attributes. * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig, * and \c glXChooseFBConfigSGIX. - * + * * \param configs Array of pointers to possible configs. The elements of * this array that do not meet the criteria will be set to * NULL. The remaining elements will be sorted according to @@ -1275,53 +1316,52 @@ fbconfig_compare( const __GLcontextModes * const * const a, * \c glXChooseVisual style or * \c glXChooseFBConfig style. * \returns The number of valid elements left in \c configs. - * + * * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX */ static int -choose_visual( __GLcontextModes ** configs, int num_configs, - const int *attribList, GLboolean fbconfig_style_tags ) -{ - __GLcontextModes test_config; - int base; - int i; - - /* This is a fairly direct implementation of the selection method - * described by GLX_SGIX_fbconfig. Start by culling out all the - * configs that are not compatible with the selected parameter - * list. - */ - - init_fbconfig_for_chooser( & test_config, fbconfig_style_tags ); - __glXInitializeVisualConfigFromTags( & test_config, 512, - (const INT32 *) attribList, - GL_TRUE, fbconfig_style_tags ); - - base = 0; - for ( i = 0 ; i < num_configs ; i++ ) { - if ( fbconfigs_compatible( & test_config, configs[i] ) ) { - configs[ base ] = configs[ i ]; - base++; - } - } - - if ( base == 0 ) { - return 0; - } - - if ( base < num_configs ) { - (void) memset( & configs[ base ], 0, - sizeof( void * ) * (num_configs - base) ); - } - - /* After the incompatible configs are removed, the resulting - * list is sorted according to the rules set out in the various - * specifications. - */ - - qsort( configs, base, sizeof( __GLcontextModes * ), - (int (*)(const void*, const void*)) fbconfig_compare ); - return base; +choose_visual(__GLcontextModes ** configs, int num_configs, + const int *attribList, GLboolean fbconfig_style_tags) +{ + __GLcontextModes test_config; + int base; + int i; + + /* This is a fairly direct implementation of the selection method + * described by GLX_SGIX_fbconfig. Start by culling out all the + * configs that are not compatible with the selected parameter + * list. + */ + + init_fbconfig_for_chooser(&test_config, fbconfig_style_tags); + __glXInitializeVisualConfigFromTags(&test_config, 512, + (const INT32 *) attribList, + GL_TRUE, fbconfig_style_tags); + + base = 0; + for (i = 0; i < num_configs; i++) { + if (fbconfigs_compatible(&test_config, configs[i])) { + configs[base] = configs[i]; + base++; + } + } + + if (base == 0) { + return 0; + } + + if (base < num_configs) { + (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base)); + } + + /* After the incompatible configs are removed, the resulting + * list is sorted according to the rules set out in the various + * specifications. + */ + + qsort(configs, base, sizeof(__GLcontextModes *), + (int (*)(const void *, const void *)) fbconfig_compare); + return base; } @@ -1331,33 +1371,34 @@ choose_visual( __GLcontextModes ** configs, int num_configs, ** Return the visual that best matches the template. Return None if no ** visual matches the template. */ -PUBLIC XVisualInfo *glXChooseVisual(Display *dpy, int screen, int *attribList) +PUBLIC XVisualInfo * +glXChooseVisual(Display * dpy, int screen, int *attribList) { - XVisualInfo *visualList = NULL; - __GLXdisplayPrivate *priv; - __GLXscreenConfigs *psc; - __GLcontextModes test_config; - __GLcontextModes *modes; - const __GLcontextModes *best_config = NULL; + XVisualInfo *visualList = NULL; + __GLXdisplayPrivate *priv; + __GLXscreenConfigs *psc; + __GLcontextModes test_config; + __GLcontextModes *modes; + const __GLcontextModes *best_config = NULL; - /* + /* ** Get a list of all visuals, return if list is empty */ - if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) { - return None; - } - + if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) { + return None; + } + - /* + /* ** Build a template from the defaults and the attribute list ** Free visual list and return if an unexpected token is encountered */ - init_fbconfig_for_chooser( & test_config, GL_FALSE ); - __glXInitializeVisualConfigFromTags( & test_config, 512, - (const INT32 *) attribList, - GL_TRUE, GL_FALSE ); + init_fbconfig_for_chooser(&test_config, GL_FALSE); + __glXInitializeVisualConfigFromTags(&test_config, 512, + (const INT32 *) attribList, + GL_TRUE, GL_FALSE); - /* + /* ** Eliminate visuals that don't meet minimum requirements ** Compute a score for those that do ** Remember which visual, if any, got the highest score @@ -1365,136 +1406,141 @@ PUBLIC XVisualInfo *glXChooseVisual(Display *dpy, int screen, int *attribList) ** Otherwise, create an XVisualInfo list with just the selected X visual ** and return this. */ - for ( modes = psc->visuals ; modes != NULL ; modes = modes->next ) { - if ( fbconfigs_compatible( & test_config, modes ) - && ((best_config == NULL) - || (fbconfig_compare( (const __GLcontextModes * const * const)&modes, &best_config ) < 0)) ) { - XVisualInfo visualTemplate; - XVisualInfo *newList; - int i; - - visualTemplate.screen = screen; - visualTemplate.visualid = modes->visualID; - newList = XGetVisualInfo( dpy, VisualScreenMask|VisualIDMask, - &visualTemplate, &i ); - - if (newList) { - Xfree(visualList); - visualList = newList; - best_config = modes; - } - } - } + for (modes = psc->visuals; modes != NULL; modes = modes->next) { + if (fbconfigs_compatible(&test_config, modes) + && ((best_config == NULL) + || + (fbconfig_compare + ((const __GLcontextModes * const *const) &modes, + &best_config) < 0))) { + XVisualInfo visualTemplate; + XVisualInfo *newList; + int i; + + visualTemplate.screen = screen; + visualTemplate.visualid = modes->visualID; + newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask, + &visualTemplate, &i); + + if (newList) { + Xfree(visualList); + visualList = newList; + best_config = modes; + } + } + } - return visualList; + return visualList; } -PUBLIC const char *glXQueryExtensionsString( Display *dpy, int screen ) +PUBLIC const char * +glXQueryExtensionsString(Display * dpy, int screen) { - __GLXscreenConfigs *psc; - __GLXdisplayPrivate *priv; + __GLXscreenConfigs *psc; + __GLXdisplayPrivate *priv; - if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) { - return NULL; - } + if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) { + return NULL; + } - if (!psc->effectiveGLXexts) { - if (!psc->serverGLXexts) { - psc->serverGLXexts = - __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS); - } + if (!psc->effectiveGLXexts) { + if (!psc->serverGLXexts) { + psc->serverGLXexts = + __glXQueryServerString(dpy, priv->majorOpcode, screen, + GLX_EXTENSIONS); + } - __glXCalculateUsableExtensions(psc, + __glXCalculateUsableExtensions(psc, #ifdef GLX_DIRECT_RENDERING - (psc->driScreen != NULL), + (psc->driScreen != NULL), #else - GL_FALSE, + GL_FALSE, #endif - priv->minorVersion); - } + priv->minorVersion); + } - return psc->effectiveGLXexts; + return psc->effectiveGLXexts; } -PUBLIC const char *glXGetClientString( Display *dpy, int name ) +PUBLIC const char * +glXGetClientString(Display * dpy, int name) { - switch(name) { - case GLX_VENDOR: - return (__glXGLXClientVendorName); - case GLX_VERSION: - return (__glXGLXClientVersion); - case GLX_EXTENSIONS: - return (__glXGetClientExtensions()); - default: - return NULL; - } + switch (name) { + case GLX_VENDOR: + return (__glXGLXClientVendorName); + case GLX_VERSION: + return (__glXGLXClientVersion); + case GLX_EXTENSIONS: + return (__glXGetClientExtensions()); + default: + return NULL; + } } -PUBLIC const char *glXQueryServerString( Display *dpy, int screen, int name ) +PUBLIC const char * +glXQueryServerString(Display * dpy, int screen, int name) { - __GLXscreenConfigs *psc; - __GLXdisplayPrivate *priv; - const char ** str; + __GLXscreenConfigs *psc; + __GLXdisplayPrivate *priv; + const char **str; - if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) { - return NULL; - } + if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) { + return NULL; + } + + switch (name) { + case GLX_VENDOR: + str = &priv->serverGLXvendor; + break; + case GLX_VERSION: + str = &priv->serverGLXversion; + break; + case GLX_EXTENSIONS: + str = &psc->serverGLXexts; + break; + default: + return NULL; + } - switch(name) { - case GLX_VENDOR: - str = & priv->serverGLXvendor; - break; - case GLX_VERSION: - str = & priv->serverGLXversion; - break; - case GLX_EXTENSIONS: - str = & psc->serverGLXexts; - break; - default: - return NULL; - } + if (*str == NULL) { + *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name); + } - if ( *str == NULL ) { - *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name); - } - - return *str; + return *str; } -void __glXClientInfo ( Display *dpy, int opcode ) +void +__glXClientInfo(Display * dpy, int opcode) { - char * ext_str = __glXGetClientGLExtensionString(); - int size = strlen( ext_str ) + 1; + char *ext_str = __glXGetClientGLExtensionString(); + int size = strlen(ext_str) + 1; #ifdef USE_XCB xcb_connection_t *c = XGetXCBConnection(dpy); xcb_glx_client_info(c, - GLX_MAJOR_VERSION, - GLX_MINOR_VERSION, - size, - (const uint8_t *)ext_str); + GLX_MAJOR_VERSION, GLX_MINOR_VERSION, size, ext_str); #else - xGLXClientInfoReq *req; - - /* Send the glXClientInfo request */ - LockDisplay(dpy); - GetReq(GLXClientInfo,req); - req->reqType = opcode; - req->glxCode = X_GLXClientInfo; - req->major = GLX_MAJOR_VERSION; - req->minor = GLX_MINOR_VERSION; - - req->length += (size + 3) >> 2; - req->numbytes = size; - Data(dpy, ext_str, size); - - UnlockDisplay(dpy); - SyncHandle(); + xGLXClientInfoReq *req; + + /* Send the glXClientInfo request */ + LockDisplay(dpy); + GetReq(GLXClientInfo, req); + req->reqType = opcode; + req->glxCode = X_GLXClientInfo; + req->major = GLX_MAJOR_VERSION; + req->minor = GLX_MINOR_VERSION; + + req->length += (size + 3) >> 2; + req->numbytes = size; + Data(dpy, ext_str, size); + + UnlockDisplay(dpy); + SyncHandle(); #endif /* USE_XCB */ - Xfree( ext_str ); + Xfree(ext_str); } @@ -1502,194 +1548,201 @@ void __glXClientInfo ( Display *dpy, int opcode ) ** EXT_import_context */ -PUBLIC Display *glXGetCurrentDisplay(void) +PUBLIC Display * +glXGetCurrentDisplay(void) { - GLXContext gc = __glXGetCurrentContext(); - if (NULL == gc) return NULL; - return gc->currentDpy; + GLXContext gc = __glXGetCurrentContext(); + if (NULL == gc) + return NULL; + return gc->currentDpy; } -PUBLIC GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (), - glXGetCurrentDisplay) +PUBLIC +GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (), + glXGetCurrentDisplay) /** * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests * to the X-server. - * + * * \param dpy Display where \c ctx was created. * \param ctx Context to query. * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid, * or zero if the request failed due to internal problems (i.e., * unable to allocate temporary memory, etc.) - * + * * \note * This function dynamically determines whether to use the EXT_import_context * version of the protocol or the GLX 1.3 version of the protocol. */ -static int __glXQueryContextInfo(Display *dpy, GLXContext ctx) -{ - __GLXdisplayPrivate *priv = __glXInitialize(dpy); - xGLXQueryContextReply reply; - CARD8 opcode; - GLuint numValues; - int retval; - - if (ctx == NULL) { - return GLX_BAD_CONTEXT; - } - opcode = __glXSetupForCommand(dpy); - if (!opcode) { - return 0; - } - - /* Send the glXQueryContextInfoEXT request */ - LockDisplay(dpy); - - if ( (priv->majorVersion > 1) || (priv->minorVersion >= 3) ) { - xGLXQueryContextReq *req; - - GetReq(GLXQueryContext, req); - - req->reqType = opcode; - req->glxCode = X_GLXQueryContext; - req->context = (unsigned int)(ctx->xid); - } - else { - xGLXVendorPrivateReq *vpreq; - xGLXQueryContextInfoEXTReq *req; - - GetReqExtra( GLXVendorPrivate, - sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq, - vpreq ); - req = (xGLXQueryContextInfoEXTReq *)vpreq; - req->reqType = opcode; - req->glxCode = X_GLXVendorPrivateWithReply; - req->vendorCode = X_GLXvop_QueryContextInfoEXT; - req->context = (unsigned int)(ctx->xid); - } - - _XReply(dpy, (xReply*) &reply, 0, False); - - numValues = reply.n; - if (numValues == 0) - retval = Success; - else if (numValues > __GLX_MAX_CONTEXT_PROPS) - retval = 0; - else - { - int *propList, *pProp; - int nPropListBytes; - int i; - - nPropListBytes = numValues << 3; - propList = (int *) Xmalloc(nPropListBytes); - if (NULL == propList) { - retval = 0; - } else { - _XRead(dpy, (char *)propList, nPropListBytes); - pProp = propList; - for (i=0; i < numValues; i++) { - switch (*pProp++) { - case GLX_SHARE_CONTEXT_EXT: - ctx->share_xid = *pProp++; - break; - case GLX_VISUAL_ID_EXT: - ctx->mode = - _gl_context_modes_find_visual(ctx->psc->visuals, *pProp++); - break; - case GLX_SCREEN: - ctx->screen = *pProp++; - break; - case GLX_FBCONFIG_ID: - ctx->mode = - _gl_context_modes_find_fbconfig(ctx->psc->configs, *pProp++); - break; - case GLX_RENDER_TYPE: - ctx->renderType = *pProp++; - break; - default: - pProp++; - continue; - } - } - Xfree((char *)propList); - retval = Success; - } - } - UnlockDisplay(dpy); - SyncHandle(); - return retval; + static int __glXQueryContextInfo(Display * dpy, GLXContext ctx) +{ + __GLXdisplayPrivate *priv = __glXInitialize(dpy); + xGLXQueryContextReply reply; + CARD8 opcode; + GLuint numValues; + int retval; + + if (ctx == NULL) { + return GLX_BAD_CONTEXT; + } + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return 0; + } + + /* Send the glXQueryContextInfoEXT request */ + LockDisplay(dpy); + + if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { + xGLXQueryContextReq *req; + + GetReq(GLXQueryContext, req); + + req->reqType = opcode; + req->glxCode = X_GLXQueryContext; + req->context = (unsigned int) (ctx->xid); + } + else { + xGLXVendorPrivateReq *vpreq; + xGLXQueryContextInfoEXTReq *req; + + GetReqExtra(GLXVendorPrivate, + sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq, + vpreq); + req = (xGLXQueryContextInfoEXTReq *) vpreq; + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivateWithReply; + req->vendorCode = X_GLXvop_QueryContextInfoEXT; + req->context = (unsigned int) (ctx->xid); + } + + _XReply(dpy, (xReply *) & reply, 0, False); + + numValues = reply.n; + if (numValues == 0) + retval = Success; + else if (numValues > __GLX_MAX_CONTEXT_PROPS) + retval = 0; + else { + int *propList, *pProp; + int nPropListBytes; + int i; + + nPropListBytes = numValues << 3; + propList = (int *) Xmalloc(nPropListBytes); + if (NULL == propList) { + retval = 0; + } + else { + _XRead(dpy, (char *) propList, nPropListBytes); + pProp = propList; + for (i = 0; i < numValues; i++) { + switch (*pProp++) { + case GLX_SHARE_CONTEXT_EXT: + ctx->share_xid = *pProp++; + break; + case GLX_VISUAL_ID_EXT: + ctx->mode = + _gl_context_modes_find_visual(ctx->psc->visuals, *pProp++); + break; + case GLX_SCREEN: + ctx->screen = *pProp++; + break; + case GLX_FBCONFIG_ID: + ctx->mode = + _gl_context_modes_find_fbconfig(ctx->psc->configs, + *pProp++); + break; + case GLX_RENDER_TYPE: + ctx->renderType = *pProp++; + break; + default: + pProp++; + continue; + } + } + Xfree((char *) propList); + retval = Success; + } + } + UnlockDisplay(dpy); + SyncHandle(); + return retval; } PUBLIC int -glXQueryContext(Display *dpy, GLXContext ctx, int attribute, int *value) +glXQueryContext(Display * dpy, GLXContext ctx, int attribute, int *value) { - int retVal; + int retVal; - /* get the information from the server if we don't have it already */ + /* get the information from the server if we don't have it already */ #ifdef GLX_DIRECT_RENDERING - if (!ctx->driContext && (ctx->mode == NULL)) { + if (!ctx->driContext && (ctx->mode == NULL)) { #else - if (ctx->mode == NULL) { + if (ctx->mode == NULL) { #endif - retVal = __glXQueryContextInfo(dpy, ctx); - if (Success != retVal) return retVal; - } - switch (attribute) { - case GLX_SHARE_CONTEXT_EXT: - *value = (int)(ctx->share_xid); - break; - case GLX_VISUAL_ID_EXT: - *value = ctx->mode ? ctx->mode->visualID : None; - break; - case GLX_SCREEN: - *value = (int)(ctx->screen); - break; - case GLX_FBCONFIG_ID: - *value = ctx->mode ? ctx->mode->fbconfigID : None; - break; - case GLX_RENDER_TYPE: - *value = (int)(ctx->renderType); - break; - default: - return GLX_BAD_ATTRIBUTE; - } - return Success; + retVal = __glXQueryContextInfo(dpy, ctx); + if (Success != retVal) + return retVal; + } + switch (attribute) { + case GLX_SHARE_CONTEXT_EXT: + *value = (int) (ctx->share_xid); + break; + case GLX_VISUAL_ID_EXT: + *value = ctx->mode ? ctx->mode->visualID : None; + break; + case GLX_SCREEN: + *value = (int) (ctx->screen); + break; + case GLX_FBCONFIG_ID: + *value = ctx->mode ? ctx->mode->fbconfigID : None; + break; + case GLX_RENDER_TYPE: + *value = (int) (ctx->renderType); + break; + default: + return GLX_BAD_ATTRIBUTE; + } + return Success; } -PUBLIC GLX_ALIAS( int, glXQueryContextInfoEXT, - (Display *dpy, GLXContext ctx, int attribute, int *value), - (dpy, ctx, attribute, value), - glXQueryContext ) +PUBLIC +GLX_ALIAS(int, glXQueryContextInfoEXT, + (Display * dpy, GLXContext ctx, int attribute, int *value), + (dpy, ctx, attribute, value), glXQueryContext) -PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx) + PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx) { - return ctx->xid; + return ctx->xid; } -PUBLIC GLXContext glXImportContextEXT(Display *dpy, GLXContextID contextID) +PUBLIC GLXContext +glXImportContextEXT(Display * dpy, GLXContextID contextID) { - GLXContext ctx; + GLXContext ctx; - if (contextID == None) { - return NULL; - } - if (__glXIsDirect(dpy, contextID)) { - return NULL; - } + if (contextID == None) { + return NULL; + } + if (__glXIsDirect(dpy, contextID)) { + return NULL; + } - ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0); - if (NULL != ctx) { - if (Success != __glXQueryContextInfo(dpy, ctx)) { - return NULL; - } - } - return ctx; + ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0); + if (NULL != ctx) { + if (Success != __glXQueryContextInfo(dpy, ctx)) { + return NULL; + } + } + return ctx; } -PUBLIC void glXFreeContextEXT(Display *dpy, GLXContext ctx) +PUBLIC void +glXFreeContextEXT(Display * dpy, GLXContext ctx) { - DestroyContext(dpy, ctx); + DestroyContext(dpy, ctx); } @@ -1698,147 +1751,149 @@ PUBLIC void glXFreeContextEXT(Display *dpy, GLXContext ctx) * GLX 1.3 functions - these are just stubs for now! */ -PUBLIC GLXFBConfig *glXChooseFBConfig(Display *dpy, int screen, - const int *attribList, int *nitems) +PUBLIC GLXFBConfig * +glXChooseFBConfig(Display * dpy, int screen, + const int *attribList, int *nitems) { - __GLcontextModes ** config_list; - int list_size; + __GLcontextModes **config_list; + int list_size; - config_list = (__GLcontextModes **) - glXGetFBConfigs( dpy, screen, & list_size ); + config_list = (__GLcontextModes **) + glXGetFBConfigs(dpy, screen, &list_size); - if ( (config_list != NULL) && (list_size > 0) && (attribList != NULL) ) { - list_size = choose_visual( config_list, list_size, attribList, - GL_TRUE ); - if ( list_size == 0 ) { - XFree( config_list ); - config_list = NULL; - } - } + if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) { + list_size = choose_visual(config_list, list_size, attribList, GL_TRUE); + if (list_size == 0) { + XFree(config_list); + config_list = NULL; + } + } - *nitems = list_size; - return (GLXFBConfig *) config_list; + *nitems = list_size; + return (GLXFBConfig *) config_list; } -PUBLIC GLXContext glXCreateNewContext(Display *dpy, GLXFBConfig config, - int renderType, GLXContext shareList, - Bool allowDirect) +PUBLIC GLXContext +glXCreateNewContext(Display * dpy, GLXFBConfig config, + int renderType, GLXContext shareList, Bool allowDirect) { - return CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList, - allowDirect, None, True, renderType ); + return CreateContext(dpy, NULL, (__GLcontextModes *) config, shareList, + allowDirect, None, True, renderType); } -PUBLIC GLXDrawable glXGetCurrentReadDrawable(void) +PUBLIC GLXDrawable +glXGetCurrentReadDrawable(void) { - GLXContext gc = __glXGetCurrentContext(); - return gc->currentReadable; + GLXContext gc = __glXGetCurrentContext(); + return gc->currentReadable; } -PUBLIC GLXFBConfig *glXGetFBConfigs(Display *dpy, int screen, int *nelements) +PUBLIC GLXFBConfig * +glXGetFBConfigs(Display * dpy, int screen, int *nelements) { - __GLXdisplayPrivate *priv = __glXInitialize(dpy); - __GLcontextModes ** config = NULL; - int i; + __GLXdisplayPrivate *priv = __glXInitialize(dpy); + __GLcontextModes **config = NULL; + int i; - *nelements = 0; - if ( priv - && (priv->screenConfigs != NULL) - && (screen >= 0) && (screen <= ScreenCount(dpy)) - && (priv->screenConfigs[screen].configs != NULL) - && (priv->screenConfigs[screen].configs->fbconfigID != GLX_DONT_CARE) ) { - unsigned num_configs = 0; - __GLcontextModes * modes; + *nelements = 0; + if (priv && (priv->screenConfigs != NULL) + && (screen >= 0) && (screen <= ScreenCount(dpy)) + && (priv->screenConfigs[screen].configs != NULL) + && (priv->screenConfigs[screen].configs->fbconfigID != GLX_DONT_CARE)) { + unsigned num_configs = 0; + __GLcontextModes *modes; - for ( modes = priv->screenConfigs[screen].configs - ; modes != NULL - ; modes = modes->next ) { - if ( modes->fbconfigID != GLX_DONT_CARE ) { - num_configs++; - } - } + for (modes = priv->screenConfigs[screen].configs; modes != NULL; + modes = modes->next) { + if (modes->fbconfigID != GLX_DONT_CARE) { + num_configs++; + } + } - config = (__GLcontextModes **) Xmalloc( sizeof(__GLcontextModes *) - * num_configs ); - if ( config != NULL ) { - *nelements = num_configs; - i = 0; - for ( modes = priv->screenConfigs[screen].configs - ; modes != NULL - ; modes = modes->next ) { - if ( modes->fbconfigID != GLX_DONT_CARE ) { - config[i] = modes; - i++; - } - } - } - } - return (GLXFBConfig *) config; + config = (__GLcontextModes **) Xmalloc(sizeof(__GLcontextModes *) + * num_configs); + if (config != NULL) { + *nelements = num_configs; + i = 0; + for (modes = priv->screenConfigs[screen].configs; modes != NULL; + modes = modes->next) { + if (modes->fbconfigID != GLX_DONT_CARE) { + config[i] = modes; + i++; + } + } + } + } + return (GLXFBConfig *) config; } -PUBLIC int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, - int attribute, int *value) +PUBLIC int +glXGetFBConfigAttrib(Display * dpy, GLXFBConfig config, + int attribute, int *value) { - __GLcontextModes * const modes = ValidateGLXFBConfig( dpy, config ); + __GLcontextModes *const modes = ValidateGLXFBConfig(dpy, config); - return (modes != NULL) - ? _gl_get_context_mode_data( modes, attribute, value ) - : GLXBadFBConfig; + return (modes != NULL) + ? _gl_get_context_mode_data(modes, attribute, value) + : GLXBadFBConfig; } -PUBLIC XVisualInfo *glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config) +PUBLIC XVisualInfo * +glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig config) { - XVisualInfo visualTemplate; - __GLcontextModes * fbconfig = (__GLcontextModes *) config; - int count; + XVisualInfo visualTemplate; + __GLcontextModes *fbconfig = (__GLcontextModes *) config; + int count; - /* + /* ** Get a list of all visuals, return if list is empty */ - visualTemplate.visualid = fbconfig->visualID; - return XGetVisualInfo(dpy,VisualIDMask,&visualTemplate,&count); + visualTemplate.visualid = fbconfig->visualID; + return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count); } /* ** GLX_SGI_swap_control */ -static int __glXSwapIntervalSGI(int interval) +static int +__glXSwapIntervalSGI(int interval) { xGLXVendorPrivateReq *req; GLXContext gc = __glXGetCurrentContext(); - Display * dpy; - CARD32 * interval_ptr; + Display *dpy; + CARD32 *interval_ptr; CARD8 opcode; - if ( gc == NULL ) { + if (gc == NULL) { return GLX_BAD_CONTEXT; } - - if ( interval <= 0 ) { + + if (interval <= 0) { return GLX_BAD_VALUE; } #ifdef __DRI_SWAP_CONTROL if (gc->driContext) { - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, - gc->screen ); - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(gc->currentDpy, - gc->currentDrawable, - NULL); - if (psc->swapControl != NULL && pdraw != NULL) { - psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); - return 0; - } - else { - return GLX_BAD_CONTEXT; - } + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(gc->currentDpy, + gc->screen); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(gc->currentDpy, + gc->currentDrawable, + NULL); + if (psc->swapControl != NULL && pdraw != NULL) { + psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); + return 0; + } + else { + return GLX_BAD_CONTEXT; + } } #endif dpy = gc->currentDpy; @@ -1849,7 +1904,7 @@ static int __glXSwapIntervalSGI(int interval) /* Send the glXSwapIntervalSGI request */ LockDisplay(dpy); - GetReqExtra(GLXVendorPrivate,sizeof(CARD32),req); + GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req); req->reqType = opcode; req->glxCode = X_GLXVendorPrivate; req->vendorCode = X_GLXvop_SwapIntervalSGI; @@ -1869,26 +1924,27 @@ static int __glXSwapIntervalSGI(int interval) /* ** GLX_MESA_swap_control */ -static int __glXSwapIntervalMESA(unsigned int interval) +static int +__glXSwapIntervalMESA(unsigned int interval) { #ifdef __DRI_SWAP_CONTROL GLXContext gc = __glXGetCurrentContext(); - if ( interval < 0 ) { + if (interval < 0) { return GLX_BAD_VALUE; } if (gc != NULL && gc->driContext) { - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, - gc->screen ); - - if ( (psc != NULL) && (psc->driScreen != NULL) ) { - __GLXDRIdrawable *pdraw = - GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); - if (psc->swapControl != NULL && pdraw != NULL) { - psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); - return 0; - } + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(gc->currentDpy, + gc->screen); + + if ((psc != NULL) && (psc->driScreen != NULL)) { + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); + if (psc->swapControl != NULL && pdraw != NULL) { + psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); + return 0; + } } } #else @@ -1897,23 +1953,24 @@ static int __glXSwapIntervalMESA(unsigned int interval) return GLX_BAD_CONTEXT; } - -static int __glXGetSwapIntervalMESA(void) + +static int +__glXGetSwapIntervalMESA(void) { #ifdef __DRI_SWAP_CONTROL GLXContext gc = __glXGetCurrentContext(); if (gc != NULL && gc->driContext) { - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, - gc->screen ); - - if ( (psc != NULL) && (psc->driScreen != NULL) ) { - __GLXDRIdrawable *pdraw = - GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); - if (psc->swapControl != NULL && pdraw != NULL) { - return psc->swapControl->getSwapInterval(pdraw->driDrawable); - } + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(gc->currentDpy, + gc->screen); + + if ((psc != NULL) && (psc->driScreen != NULL)) { + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); + if (psc->swapControl != NULL && pdraw != NULL) { + return psc->swapControl->getSwapInterval(pdraw->driDrawable); + } } } #endif @@ -1926,16 +1983,17 @@ static int __glXGetSwapIntervalMESA(void) ** GLX_MESA_swap_frame_usage */ -static GLint __glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable) +static GLint +__glXBeginFrameTrackingMESA(Display * dpy, GLXDrawable drawable) { - int status = GLX_BAD_CONTEXT; + int status = GLX_BAD_CONTEXT; #ifdef __DRI_FRAME_TRACKING - int screen; + int screen = 0; __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); - __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); if (pdraw != NULL && psc->frameTracking != NULL) - status = psc->frameTracking->frameTracking(pdraw->driDrawable, GL_TRUE); + status = psc->frameTracking->frameTracking(pdraw->driDrawable, GL_TRUE); #else (void) dpy; (void) drawable; @@ -1943,18 +2001,19 @@ static GLint __glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable) return status; } - -static GLint __glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable) + +static GLint +__glXEndFrameTrackingMESA(Display * dpy, GLXDrawable drawable) { - int status = GLX_BAD_CONTEXT; + int status = GLX_BAD_CONTEXT; #ifdef __DRI_FRAME_TRACKING - int screen; - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen); + int screen = 0; + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); __GLXscreenConfigs *psc = GetGLXScreenConfigs(dpy, screen); if (pdraw != NULL && psc->frameTracking != NULL) - status = psc->frameTracking->frameTracking(pdraw->driDrawable, - GL_FALSE); + status = psc->frameTracking->frameTracking(pdraw->driDrawable, + GL_FALSE); #else (void) dpy; (void) drawable; @@ -1963,24 +2022,24 @@ static GLint __glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable) } -static GLint __glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable, - GLfloat *usage) +static GLint +__glXGetFrameUsageMESA(Display * dpy, GLXDrawable drawable, GLfloat * usage) { - int status = GLX_BAD_CONTEXT; + int status = GLX_BAD_CONTEXT; #ifdef __DRI_FRAME_TRACKING - int screen; - __GLXDRIdrawable * const pdraw = GetGLXDRIDrawable(dpy, drawable, & screen); - __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); + int screen = 0; + __GLXDRIdrawable *const pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); if (pdraw != NULL && psc->frameTracking != NULL) { - int64_t sbc, missedFrames; - float lastMissedUsage; + int64_t sbc, missedFrames; + float lastMissedUsage; - status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable, - &sbc, - &missedFrames, - &lastMissedUsage, - usage); + status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable, + &sbc, + &missedFrames, + &lastMissedUsage, + usage); } #else (void) dpy; @@ -1991,22 +2050,24 @@ static GLint __glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable, } -static GLint __glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable, - int64_t *sbc, int64_t *missedFrames, - GLfloat *lastMissedUsage) +static GLint +__glXQueryFrameTrackingMESA(Display * dpy, GLXDrawable drawable, + int64_t * sbc, int64_t * missedFrames, + GLfloat * lastMissedUsage) { - int status = GLX_BAD_CONTEXT; + int status = GLX_BAD_CONTEXT; #ifdef __DRI_FRAME_TRACKING - int screen; - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen); - __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); + int screen = 0; + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); if (pdraw != NULL && psc->frameTracking != NULL) { - float usage; + float usage; status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable, - sbc, missedFrames, - lastMissedUsage, &usage); + sbc, missedFrames, + lastMissedUsage, + &usage); } #else (void) dpy; @@ -2022,7 +2083,8 @@ static GLint __glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable, /* ** GLX_SGI_video_sync */ -static int __glXGetVideoSyncSGI(unsigned int *count) +static int +__glXGetVideoSyncSGI(unsigned int *count) { /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry, * FIXME: there should be a GLX encoding for this call. I can find no @@ -2033,49 +2095,50 @@ static int __glXGetVideoSyncSGI(unsigned int *count) if (gc != NULL && gc->driContext) { - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, - gc->screen ); - if ( psc->msc && psc->driScreen ) { - __GLXDRIdrawable *pdraw = - GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); - int64_t temp; - int ret; - - ret = (*psc->msc->getDrawableMSC)(psc->__driScreen, - pdraw->driDrawable, &temp); - *count = (unsigned) temp; - - return (ret == 0) ? 0 : GLX_BAD_CONTEXT; + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(gc->currentDpy, + gc->screen); + if (psc->msc && psc->driScreen) { + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); + int64_t temp; + int ret; + + ret = (*psc->msc->getDrawableMSC) (psc->__driScreen, + pdraw->driDrawable, &temp); + *count = (unsigned) temp; + + return (ret == 0) ? 0 : GLX_BAD_CONTEXT; } } #else - (void) count; + (void) count; #endif return GLX_BAD_CONTEXT; } -static int __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) +static int +__glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) { #ifdef __DRI_MEDIA_STREAM_COUNTER GLXContext gc = __glXGetCurrentContext(); - if ( divisor <= 0 || remainder < 0 ) - return GLX_BAD_VALUE; + if (divisor <= 0 || remainder < 0) + return GLX_BAD_VALUE; if (gc != NULL && gc->driContext) { - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, - gc->screen ); - if (psc->msc != NULL && psc->driScreen ) { - __GLXDRIdrawable *pdraw = - GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); - int ret; - int64_t msc; - int64_t sbc; - - ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, 0, - divisor, remainder, &msc, &sbc); - *count = (unsigned) msc; - return (ret == 0) ? 0 : GLX_BAD_CONTEXT; + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(gc->currentDpy, + gc->screen); + if (psc->msc != NULL && psc->driScreen) { + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); + int ret; + int64_t msc; + int64_t sbc; + + ret = (*psc->msc->waitForMSC) (pdraw->driDrawable, 0, + divisor, remainder, &msc, &sbc); + *count = (unsigned) msc; + return (ret == 0) ? 0 : GLX_BAD_CONTEXT; } } #else @@ -2091,109 +2154,112 @@ static int __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count ** GLX_functions table. */ -PUBLIC GLX_ALIAS(int, glXGetFBConfigAttribSGIX, - (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value), - (dpy, config, attribute, value), - glXGetFBConfigAttrib) +PUBLIC +GLX_ALIAS(int, glXGetFBConfigAttribSGIX, + (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value), + (dpy, config, attribute, value), glXGetFBConfigAttrib) -PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX, - (Display *dpy, int screen, int *attrib_list, int *nelements), - (dpy, screen, attrib_list, nelements), - glXChooseFBConfig) + PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX, + (Display * dpy, int screen, int *attrib_list, + int *nelements), (dpy, screen, attrib_list, nelements), + glXChooseFBConfig) -PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX, - (Display * dpy, GLXFBConfigSGIX config), - (dpy, config), - glXGetVisualFromFBConfig) + PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX, + (Display * dpy, GLXFBConfigSGIX config), + (dpy, config), glXGetVisualFromFBConfig) -PUBLIC GLXPixmap glXCreateGLXPixmapWithConfigSGIX(Display *dpy, - GLXFBConfigSGIX config, Pixmap pixmap) + PUBLIC GLXPixmap glXCreateGLXPixmapWithConfigSGIX(Display * dpy, + GLXFBConfigSGIX config, + Pixmap pixmap) { - xGLXVendorPrivateWithReplyReq *vpreq; - xGLXCreateGLXPixmapWithConfigSGIXReq *req; - GLXPixmap xid = None; - CARD8 opcode; - const __GLcontextModes * const fbconfig = (__GLcontextModes *) config; - __GLXscreenConfigs * psc; + xGLXVendorPrivateWithReplyReq *vpreq; + xGLXCreateGLXPixmapWithConfigSGIXReq *req; + GLXPixmap xid = None; + CARD8 opcode; + const __GLcontextModes *const fbconfig = (__GLcontextModes *) config; + __GLXscreenConfigs *psc; - if ( (dpy == NULL) || (config == NULL) ) { - return None; - } + if ((dpy == NULL) || (config == NULL)) { + return None; + } - psc = GetGLXScreenConfigs( dpy, fbconfig->screen ); - if ( (psc != NULL) - && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) { - opcode = __glXSetupForCommand(dpy); - if (!opcode) { - return None; - } + psc = GetGLXScreenConfigs(dpy, fbconfig->screen); + if ((psc != NULL) + && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) { + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return None; + } - /* Send the glXCreateGLXPixmapWithConfigSGIX request */ - LockDisplay(dpy); - GetReqExtra(GLXVendorPrivateWithReply, - sz_xGLXCreateGLXPixmapWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq); - req = (xGLXCreateGLXPixmapWithConfigSGIXReq *)vpreq; - req->reqType = opcode; - req->glxCode = X_GLXVendorPrivateWithReply; - req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX; - req->screen = fbconfig->screen; - req->fbconfig = fbconfig->fbconfigID; - req->pixmap = pixmap; - req->glxpixmap = xid = XAllocID(dpy); - UnlockDisplay(dpy); - SyncHandle(); - } + /* Send the glXCreateGLXPixmapWithConfigSGIX request */ + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivateWithReply, + sz_xGLXCreateGLXPixmapWithConfigSGIXReq - + sz_xGLXVendorPrivateWithReplyReq, vpreq); + req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq; + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivateWithReply; + req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX; + req->screen = fbconfig->screen; + req->fbconfig = fbconfig->fbconfigID; + req->pixmap = pixmap; + req->glxpixmap = xid = XAllocID(dpy); + UnlockDisplay(dpy); + SyncHandle(); + } - return xid; + return xid; } -PUBLIC GLXContext glXCreateContextWithConfigSGIX(Display *dpy, - GLXFBConfigSGIX config, int renderType, - GLXContext shareList, Bool allowDirect) +PUBLIC GLXContext +glXCreateContextWithConfigSGIX(Display * dpy, + GLXFBConfigSGIX config, int renderType, + GLXContext shareList, Bool allowDirect) { - GLXContext gc = NULL; - const __GLcontextModes * const fbconfig = (__GLcontextModes *) config; - __GLXscreenConfigs * psc; + GLXContext gc = NULL; + const __GLcontextModes *const fbconfig = (__GLcontextModes *) config; + __GLXscreenConfigs *psc; - if ( (dpy == NULL) || (config == NULL) ) { - return None; - } + if ((dpy == NULL) || (config == NULL)) { + return None; + } - psc = GetGLXScreenConfigs( dpy, fbconfig->screen ); - if ( (psc != NULL) - && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) { - gc = CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList, - allowDirect, None, False, renderType ); - } + psc = GetGLXScreenConfigs(dpy, fbconfig->screen); + if ((psc != NULL) + && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) { + gc = CreateContext(dpy, NULL, (__GLcontextModes *) config, shareList, + allowDirect, None, False, renderType); + } - return gc; + return gc; } -PUBLIC GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX(Display *dpy, - XVisualInfo *vis) +PUBLIC GLXFBConfigSGIX +glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis) { - __GLXdisplayPrivate *priv; - __GLXscreenConfigs *psc; + __GLXdisplayPrivate *priv; + __GLXscreenConfigs *psc = NULL; - if ( (GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ) != Success) - && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) - && (psc->configs->fbconfigID != GLX_DONT_CARE) ) { - return (GLXFBConfigSGIX) _gl_context_modes_find_visual( psc->configs, - vis->visualid ); - } + if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) != Success) + && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit) + && (psc->configs->fbconfigID != GLX_DONT_CARE)) { + return (GLXFBConfigSGIX) _gl_context_modes_find_visual(psc->configs, + vis->visualid); + } - return NULL; + return NULL; } /* ** GLX_SGIX_swap_group */ -static void __glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, - GLXDrawable member) +static void +__glXJoinSwapGroupSGIX(Display * dpy, GLXDrawable drawable, + GLXDrawable member) { (void) dpy; (void) drawable; @@ -2204,15 +2270,16 @@ static void __glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, /* ** GLX_SGIX_swap_barrier */ -static void __glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, - int barrier) +static void +__glXBindSwapBarrierSGIX(Display * dpy, GLXDrawable drawable, int barrier) { (void) dpy; (void) drawable; (void) barrier; } -static Bool __glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max) +static Bool +__glXQueryMaxSwapBarriersSGIX(Display * dpy, int screen, int *max) { (void) dpy; (void) screen; @@ -2224,23 +2291,24 @@ static Bool __glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max) /* ** GLX_OML_sync_control */ -static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable, - int64_t *ust, int64_t *msc, int64_t *sbc) +static Bool +__glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable, + int64_t * ust, int64_t * msc, int64_t * sbc) { #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER) - __GLXdisplayPrivate * const priv = __glXInitialize(dpy); - - if ( priv != NULL ) { - int i; - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &i); - __GLXscreenConfigs * const psc = &priv->screenConfigs[i]; - - assert( (pdraw == NULL) || (i != -1) ); - return ( (pdraw && psc->sbc && psc->msc) - && ((*psc->msc->getMSC)(psc->driScreen, msc) == 0) - && ((*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0) - && (__glXGetUST(ust) == 0) ); - } + __GLXdisplayPrivate *const priv = __glXInitialize(dpy); + + if (priv != NULL) { + int i; + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &i); + __GLXscreenConfigs *const psc = &priv->screenConfigs[i]; + + assert((pdraw == NULL) || (i != -1)); + return ((pdraw && psc->sbc && psc->msc) + && ((*psc->msc->getMSC) (psc->driScreen, msc) == 0) + && ((*psc->sbc->getSBC) (pdraw->driDrawable, sbc) == 0) + && (__glXGetUST(ust) == 0)); + } #else (void) dpy; (void) drawable; @@ -2253,94 +2321,94 @@ static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable, #ifdef GLX_DIRECT_RENDERING _X_HIDDEN GLboolean -__driGetMscRateOML(__DRIdrawable *draw, - int32_t *numerator, int32_t *denominator, void *private) +__driGetMscRateOML(__DRIdrawable * draw, + int32_t * numerator, int32_t * denominator, void *private) { #ifdef XF86VIDMODE - __GLXscreenConfigs *psc; - XF86VidModeModeLine mode_line; - int dot_clock; - int i; - __GLXDRIdrawable *glxDraw = private; - - psc = glxDraw->psc; - if (XF86VidModeQueryVersion(psc->dpy, &i, &i) && - XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line) ) { - unsigned n = dot_clock * 1000; - unsigned d = mode_line.vtotal * mode_line.htotal; - + __GLXscreenConfigs *psc; + XF86VidModeModeLine mode_line; + int dot_clock; + int i; + __GLXDRIdrawable *glxDraw = private; + + psc = glxDraw->psc; + if (XF86VidModeQueryVersion(psc->dpy, &i, &i) && + XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) { + unsigned n = dot_clock * 1000; + unsigned d = mode_line.vtotal * mode_line.htotal; + # define V_INTERLACE 0x010 # define V_DBLSCAN 0x020 - if (mode_line.flags & V_INTERLACE) - n *= 2; - else if (mode_line.flags & V_DBLSCAN) - d *= 2; - - /* The OML_sync_control spec requires that if the refresh rate is a - * whole number, that the returned numerator be equal to the refresh - * rate and the denominator be 1. - */ - - if (n % d == 0) { - n /= d; - d = 1; - } - else { - static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 }; - - /* This is a poor man's way to reduce a fraction. It's far from - * perfect, but it will work well enough for this situation. - */ - - for (i = 0; f[i] != 0; i++) { - while (n % f[i] == 0 && d % f[i] == 0) { - d /= f[i]; - n /= f[i]; - } - } - } - - *numerator = n; - *denominator = d; - - return True; - } - else - return False; + if (mode_line.flags & V_INTERLACE) + n *= 2; + else if (mode_line.flags & V_DBLSCAN) + d *= 2; + + /* The OML_sync_control spec requires that if the refresh rate is a + * whole number, that the returned numerator be equal to the refresh + * rate and the denominator be 1. + */ + + if (n % d == 0) { + n /= d; + d = 1; + } + else { + static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 }; + + /* This is a poor man's way to reduce a fraction. It's far from + * perfect, but it will work well enough for this situation. + */ + + for (i = 0; f[i] != 0; i++) { + while (n % f[i] == 0 && d % f[i] == 0) { + d /= f[i]; + n /= f[i]; + } + } + } + + *numerator = n; + *denominator = d; + + return True; + } + else + return False; #else - return False; + return False; #endif } #endif /** * Determine the refresh rate of the specified drawable and display. - * + * * \param dpy Display whose refresh rate is to be determined. * \param drawable Drawable whose refresh rate is to be determined. * \param numerator Numerator of the refresh rate. * \param demoninator Denominator of the refresh rate. * \return If the refresh rate for the specified display and drawable could * be calculated, True is returned. Otherwise False is returned. - * + * * \note This function is implemented entirely client-side. A lot of other * functionality is required to export GLX_OML_sync_control, so on * XFree86 this function can be called for direct-rendering contexts * when GLX_OML_sync_control appears in the client extension string. */ -_X_HIDDEN GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, - int32_t * numerator, - int32_t * denominator) +_X_HIDDEN GLboolean +__glXGetMscRateOML(Display * dpy, GLXDrawable drawable, + int32_t * numerator, int32_t * denominator) { #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE ) - __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable, NULL); + __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable, NULL); - if (draw == NULL) - return False; + if (draw == NULL) + return False; - return __driGetMscRateOML(draw->driDrawable, numerator, denominator, draw); + return __driGetMscRateOML(draw->driDrawable, numerator, denominator, draw); #else (void) dpy; (void) drawable; @@ -2351,28 +2419,28 @@ _X_HIDDEN GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, } -static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable, - int64_t target_msc, int64_t divisor, - int64_t remainder) +static int64_t +__glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable, + int64_t target_msc, int64_t divisor, int64_t remainder) { #ifdef __DRI_SWAP_BUFFER_COUNTER int screen; __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE * error", but it also says "It [glXSwapBuffersMscOML] will return a value * of -1 if the function failed because of errors detected in the input * parameters" */ - if ( divisor < 0 || remainder < 0 || target_msc < 0 ) + if (divisor < 0 || remainder < 0 || target_msc < 0) return -1; - if ( divisor > 0 && remainder >= divisor ) + if (divisor > 0 && remainder >= divisor) return -1; if (pdraw != NULL && psc->counters != NULL) - return (*psc->sbc->swapBuffersMSC)(pdraw->driDrawable, target_msc, - divisor, remainder); + return (*psc->sbc->swapBuffersMSC) (pdraw->driDrawable, target_msc, + divisor, remainder); #else (void) dpy; @@ -2385,33 +2453,34 @@ static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable, } -static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable, - int64_t target_msc, int64_t divisor, - int64_t remainder, int64_t *ust, - int64_t *msc, int64_t *sbc) +static Bool +__glXWaitForMscOML(Display * dpy, GLXDrawable drawable, + int64_t target_msc, int64_t divisor, + int64_t remainder, int64_t * ust, + int64_t * msc, int64_t * sbc) { #ifdef __DRI_MEDIA_STREAM_COUNTER - int screen; + int screen = 0; __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); - int ret; + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); + int ret; /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE * error", but the return type in the spec is Bool. */ - if ( divisor < 0 || remainder < 0 || target_msc < 0 ) + if (divisor < 0 || remainder < 0 || target_msc < 0) return False; - if ( divisor > 0 && remainder >= divisor ) + if (divisor > 0 && remainder >= divisor) return False; if (pdraw != NULL && psc->msc != NULL) { - ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, target_msc, - divisor, remainder, msc, sbc); + ret = (*psc->msc->waitForMSC) (pdraw->driDrawable, target_msc, + divisor, remainder, msc, sbc); /* __glXGetUST returns zero on success and non-zero on failure. * This function returns True on success and False on failure. */ - return ( (ret == 0) && (__glXGetUST( ust ) == 0) ); + return ((ret == 0) && (__glXGetUST(ust) == 0)); } #else (void) dpy; @@ -2427,29 +2496,31 @@ static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable, } -static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable, - int64_t target_sbc, int64_t *ust, - int64_t *msc, int64_t *sbc ) +static Bool +__glXWaitForSbcOML(Display * dpy, GLXDrawable drawable, + int64_t target_sbc, int64_t * ust, + int64_t * msc, int64_t * sbc) { #ifdef __DRI_SWAP_BUFFER_COUNTER int screen; __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); - int ret; + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); + int ret; /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE * error", but the return type in the spec is Bool. */ - if ( target_sbc < 0 ) + if (target_sbc < 0) return False; if (pdraw != NULL && psc->sbc != NULL) { - ret = (*psc->sbc->waitForSBC)(pdraw->driDrawable, target_sbc, msc, sbc); + ret = + (*psc->sbc->waitForSBC) (pdraw->driDrawable, target_sbc, msc, sbc); /* __glXGetUST returns zero on success and non-zero on failure. * This function returns True on success and False on failure. */ - return( (ret == 0) && (__glXGetUST( ust ) == 0) ); + return ((ret == 0) && (__glXGetUST(ust) == 0)); } #else (void) dpy; @@ -2468,16 +2539,17 @@ static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable, */ /*@{*/ -PUBLIC void *glXAllocateMemoryMESA(Display *dpy, int scrn, - size_t size, float readFreq, - float writeFreq, float priority) +PUBLIC void * +glXAllocateMemoryMESA(Display * dpy, int scrn, + size_t size, float readFreq, + float writeFreq, float priority) { #ifdef __DRI_ALLOCATE - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, scrn); if (psc && psc->allocate) - return (*psc->allocate->allocateMemory)(psc->__driScreen, size, - readFreq, writeFreq, priority); + return (*psc->allocate->allocateMemory) (psc->__driScreen, size, + readFreq, writeFreq, priority); #else (void) dpy; @@ -2492,13 +2564,14 @@ PUBLIC void *glXAllocateMemoryMESA(Display *dpy, int scrn, } -PUBLIC void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer) +PUBLIC void +glXFreeMemoryMESA(Display * dpy, int scrn, void *pointer) { #ifdef __DRI_ALLOCATE - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, scrn); if (psc && psc->allocate) - (*psc->allocate->freeMemory)(psc->__driScreen, pointer); + (*psc->allocate->freeMemory) (psc->__driScreen, pointer); #else (void) dpy; @@ -2508,14 +2581,14 @@ PUBLIC void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer) } -PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn, - const void *pointer ) +PUBLIC GLuint +glXGetMemoryOffsetMESA(Display * dpy, int scrn, const void *pointer) { #ifdef __DRI_ALLOCATE - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, scrn); if (psc && psc->allocate) - return (*psc->allocate->memoryOffset)(psc->__driScreen, pointer); + return (*psc->allocate->memoryOffset) (psc->__driScreen, pointer); #else (void) dpy; @@ -2525,6 +2598,7 @@ PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn, return ~0L; } + /*@}*/ @@ -2555,7 +2629,8 @@ PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn, * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX */ -static Bool __glXReleaseBuffersMESA( Display *dpy, GLXDrawable d ) +static Bool +__glXReleaseBuffersMESA(Display * dpy, GLXDrawable d) { (void) dpy; (void) d; @@ -2563,8 +2638,9 @@ static Bool __glXReleaseBuffersMESA( Display *dpy, GLXDrawable d ) } -PUBLIC GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual, - Pixmap pixmap, Colormap cmap ) +PUBLIC GLXPixmap +glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual, + Pixmap pixmap, Colormap cmap) { (void) dpy; (void) visual; @@ -2572,6 +2648,7 @@ PUBLIC GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual, (void) cmap; return 0; } + /*@}*/ @@ -2579,68 +2656,70 @@ PUBLIC GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual, * GLX_MESA_copy_sub_buffer */ #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */ -static void __glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable, - int x, int y, int width, int height) +static void +__glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable, + int x, int y, int width, int height) { - xGLXVendorPrivateReq *req; - GLXContext gc; - GLXContextTag tag; - CARD32 *drawable_ptr; - INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr; - CARD8 opcode; + xGLXVendorPrivateReq *req; + GLXContext gc; + GLXContextTag tag; + CARD32 *drawable_ptr; + INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr; + CARD8 opcode; #ifdef __DRI_COPY_SUB_BUFFER - int screen; - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); - if ( pdraw != NULL ) { - __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); - if (psc->driScreen->copySubBuffer != NULL) { - glFlush(); - (*psc->driScreen->copySubBuffer)(pdraw, x, y, width, height); - } - - return; - } + int screen; + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); + if (pdraw != NULL) { + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); + if (psc->driScreen->copySubBuffer != NULL) { + glFlush(); + (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height); + } + + return; + } #endif - opcode = __glXSetupForCommand(dpy); - if (!opcode) - return; + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return; - /* + /* ** The calling thread may or may not have a current context. If it ** does, send the context tag so the server can do a flush. */ - gc = __glXGetCurrentContext(); - if ((gc != NULL) && (dpy == gc->currentDpy) && - ((drawable == gc->currentDrawable) || - (drawable == gc->currentReadable)) ) { - tag = gc->currentContextTag; - } else { - tag = 0; - } - - LockDisplay(dpy); - GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4,req); - req->reqType = opcode; - req->glxCode = X_GLXVendorPrivate; - req->vendorCode = X_GLXvop_CopySubBufferMESA; - req->contextTag = tag; - - drawable_ptr = (CARD32 *) (req + 1); - x_ptr = (INT32 *) (drawable_ptr + 1); - y_ptr = (INT32 *) (drawable_ptr + 2); - w_ptr = (INT32 *) (drawable_ptr + 3); - h_ptr = (INT32 *) (drawable_ptr + 4); - - *drawable_ptr = drawable; - *x_ptr = x; - *y_ptr = y; - *w_ptr = width; - *h_ptr = height; - - UnlockDisplay(dpy); - SyncHandle(); + gc = __glXGetCurrentContext(); + if ((gc != NULL) && (dpy == gc->currentDpy) && + ((drawable == gc->currentDrawable) || + (drawable == gc->currentReadable))) { + tag = gc->currentContextTag; + } + else { + tag = 0; + } + + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req); + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivate; + req->vendorCode = X_GLXvop_CopySubBufferMESA; + req->contextTag = tag; + + drawable_ptr = (CARD32 *) (req + 1); + x_ptr = (INT32 *) (drawable_ptr + 1); + y_ptr = (INT32 *) (drawable_ptr + 2); + w_ptr = (INT32 *) (drawable_ptr + 3); + h_ptr = (INT32 *) (drawable_ptr + 4); + + *drawable_ptr = drawable; + *x_ptr = x; + *y_ptr = y; + *w_ptr = width; + *h_ptr = height; + + UnlockDisplay(dpy); + SyncHandle(); } @@ -2648,128 +2727,127 @@ static void __glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable, * GLX_EXT_texture_from_pixmap */ /*@{*/ -static void __glXBindTexImageEXT(Display *dpy, - GLXDrawable drawable, - int buffer, - const int *attrib_list) -{ - xGLXVendorPrivateReq *req; - GLXContext gc = __glXGetCurrentContext(); - CARD32 *drawable_ptr; - INT32 *buffer_ptr; - CARD32 *num_attrib_ptr; - CARD32 *attrib_ptr; - CARD8 opcode; - unsigned int i; - - if (gc == NULL) - return; - - i = 0; - if (attrib_list) { - while (attrib_list[i * 2] != None) - i++; - } - +static void +__glXBindTexImageEXT(Display * dpy, + GLXDrawable drawable, int buffer, const int *attrib_list) +{ + xGLXVendorPrivateReq *req; + GLXContext gc = __glXGetCurrentContext(); + CARD32 *drawable_ptr; + INT32 *buffer_ptr; + CARD32 *num_attrib_ptr; + CARD32 *attrib_ptr; + CARD8 opcode; + unsigned int i; + + if (gc == NULL) + return; + + i = 0; + if (attrib_list) { + while (attrib_list[i * 2] != None) + i++; + } + #ifdef GLX_DIRECT_RENDERING - if (gc->driContext) { - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); - - if (pdraw != NULL) { - if (pdraw->psc->texBuffer->base.version >= 2 && - pdraw->psc->texBuffer->setTexBuffer2 != NULL) { - (*pdraw->psc->texBuffer->setTexBuffer2)(gc->__driContext, - pdraw->textureTarget, - pdraw->textureFormat, - pdraw->driDrawable); - } else { - (*pdraw->psc->texBuffer->setTexBuffer)(gc->__driContext, - pdraw->textureTarget, - pdraw->driDrawable); - } - } - return; - } + if (gc->driContext) { + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); + + if (pdraw != NULL) { + if (pdraw->psc->texBuffer->base.version >= 2 && + pdraw->psc->texBuffer->setTexBuffer2 != NULL) { + (*pdraw->psc->texBuffer->setTexBuffer2) (gc->__driContext, + pdraw->textureTarget, + pdraw->textureFormat, + pdraw->driDrawable); + } + else { + (*pdraw->psc->texBuffer->setTexBuffer) (gc->__driContext, + pdraw->textureTarget, + pdraw->driDrawable); + } + } + return; + } #endif - opcode = __glXSetupForCommand(dpy); - if (!opcode) - return; - - LockDisplay(dpy); - GetReqExtra(GLXVendorPrivate, 12 + 8 * i,req); - req->reqType = opcode; - req->glxCode = X_GLXVendorPrivate; - req->vendorCode = X_GLXvop_BindTexImageEXT; - req->contextTag = gc->currentContextTag; - - drawable_ptr = (CARD32 *) (req + 1); - buffer_ptr = (INT32 *) (drawable_ptr + 1); - num_attrib_ptr = (CARD32 *) (buffer_ptr + 1); - attrib_ptr = (CARD32 *) (num_attrib_ptr + 1); - - *drawable_ptr = drawable; - *buffer_ptr = buffer; - *num_attrib_ptr = (CARD32) i; - - i = 0; - if (attrib_list) { - while (attrib_list[i * 2] != None) - { - *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0]; - *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1]; - i++; - } - } - - UnlockDisplay(dpy); - SyncHandle(); -} - -static void __glXReleaseTexImageEXT(Display *dpy, - GLXDrawable drawable, - int buffer) -{ - xGLXVendorPrivateReq *req; - GLXContext gc = __glXGetCurrentContext(); - CARD32 *drawable_ptr; - INT32 *buffer_ptr; - CARD8 opcode; - - if (gc == NULL) - return; + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return; + + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivate, 12 + 8 * i, req); + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivate; + req->vendorCode = X_GLXvop_BindTexImageEXT; + req->contextTag = gc->currentContextTag; + + drawable_ptr = (CARD32 *) (req + 1); + buffer_ptr = (INT32 *) (drawable_ptr + 1); + num_attrib_ptr = (CARD32 *) (buffer_ptr + 1); + attrib_ptr = (CARD32 *) (num_attrib_ptr + 1); + + *drawable_ptr = drawable; + *buffer_ptr = buffer; + *num_attrib_ptr = (CARD32) i; + + i = 0; + if (attrib_list) { + while (attrib_list[i * 2] != None) { + *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0]; + *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1]; + i++; + } + } + + UnlockDisplay(dpy); + SyncHandle(); +} + +static void +__glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer) +{ + xGLXVendorPrivateReq *req; + GLXContext gc = __glXGetCurrentContext(); + CARD32 *drawable_ptr; + INT32 *buffer_ptr; + CARD8 opcode; + + if (gc == NULL) + return; #ifdef GLX_DIRECT_RENDERING - if (gc->driContext) - return; + if (gc->driContext) + return; #endif - opcode = __glXSetupForCommand(dpy); - if (!opcode) - return; + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return; - LockDisplay(dpy); - GetReqExtra(GLXVendorPrivate, sizeof(CARD32)+sizeof(INT32),req); - req->reqType = opcode; - req->glxCode = X_GLXVendorPrivate; - req->vendorCode = X_GLXvop_ReleaseTexImageEXT; - req->contextTag = gc->currentContextTag; + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32), req); + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivate; + req->vendorCode = X_GLXvop_ReleaseTexImageEXT; + req->contextTag = gc->currentContextTag; - drawable_ptr = (CARD32 *) (req + 1); - buffer_ptr = (INT32 *) (drawable_ptr + 1); + drawable_ptr = (CARD32 *) (req + 1); + buffer_ptr = (INT32 *) (drawable_ptr + 1); - *drawable_ptr = drawable; - *buffer_ptr = buffer; + *drawable_ptr = drawable; + *buffer_ptr = buffer; - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay(dpy); + SyncHandle(); } + /*@}*/ /** * \c strdup is actually not a standard ANSI C or POSIX routine. * Irix will not define it if ANSI mode is in effect. - * + * * \sa strdup */ _X_HIDDEN char * @@ -2787,7 +2865,8 @@ __glXstrdup(const char *str) ** glXGetProcAddress support */ -struct name_address_pair { +struct name_address_pair +{ const char *Name; GLvoid *Address; }; @@ -2797,139 +2876,139 @@ struct name_address_pair { static const struct name_address_pair GLX_functions[] = { /*** GLX_VERSION_1_0 ***/ - GLX_FUNCTION( glXChooseVisual ), - GLX_FUNCTION( glXCopyContext ), - GLX_FUNCTION( glXCreateContext ), - GLX_FUNCTION( glXCreateGLXPixmap ), - GLX_FUNCTION( glXDestroyContext ), - GLX_FUNCTION( glXDestroyGLXPixmap ), - GLX_FUNCTION( glXGetConfig ), - GLX_FUNCTION( glXGetCurrentContext ), - GLX_FUNCTION( glXGetCurrentDrawable ), - GLX_FUNCTION( glXIsDirect ), - GLX_FUNCTION( glXMakeCurrent ), - GLX_FUNCTION( glXQueryExtension ), - GLX_FUNCTION( glXQueryVersion ), - GLX_FUNCTION( glXSwapBuffers ), - GLX_FUNCTION( glXUseXFont ), - GLX_FUNCTION( glXWaitGL ), - GLX_FUNCTION( glXWaitX ), + GLX_FUNCTION(glXChooseVisual), + GLX_FUNCTION(glXCopyContext), + GLX_FUNCTION(glXCreateContext), + GLX_FUNCTION(glXCreateGLXPixmap), + GLX_FUNCTION(glXDestroyContext), + GLX_FUNCTION(glXDestroyGLXPixmap), + GLX_FUNCTION(glXGetConfig), + GLX_FUNCTION(glXGetCurrentContext), + GLX_FUNCTION(glXGetCurrentDrawable), + GLX_FUNCTION(glXIsDirect), + GLX_FUNCTION(glXMakeCurrent), + GLX_FUNCTION(glXQueryExtension), + GLX_FUNCTION(glXQueryVersion), + GLX_FUNCTION(glXSwapBuffers), + GLX_FUNCTION(glXUseXFont), + GLX_FUNCTION(glXWaitGL), + GLX_FUNCTION(glXWaitX), /*** GLX_VERSION_1_1 ***/ - GLX_FUNCTION( glXGetClientString ), - GLX_FUNCTION( glXQueryExtensionsString ), - GLX_FUNCTION( glXQueryServerString ), + GLX_FUNCTION(glXGetClientString), + GLX_FUNCTION(glXQueryExtensionsString), + GLX_FUNCTION(glXQueryServerString), /*** GLX_VERSION_1_2 ***/ - GLX_FUNCTION( glXGetCurrentDisplay ), + GLX_FUNCTION(glXGetCurrentDisplay), /*** GLX_VERSION_1_3 ***/ - GLX_FUNCTION( glXChooseFBConfig ), - GLX_FUNCTION( glXCreateNewContext ), - GLX_FUNCTION( glXCreatePbuffer ), - GLX_FUNCTION( glXCreatePixmap ), - GLX_FUNCTION( glXCreateWindow ), - GLX_FUNCTION( glXDestroyPbuffer ), - GLX_FUNCTION( glXDestroyPixmap ), - GLX_FUNCTION( glXDestroyWindow ), - GLX_FUNCTION( glXGetCurrentReadDrawable ), - GLX_FUNCTION( glXGetFBConfigAttrib ), - GLX_FUNCTION( glXGetFBConfigs ), - GLX_FUNCTION( glXGetSelectedEvent ), - GLX_FUNCTION( glXGetVisualFromFBConfig ), - GLX_FUNCTION( glXMakeContextCurrent ), - GLX_FUNCTION( glXQueryContext ), - GLX_FUNCTION( glXQueryDrawable ), - GLX_FUNCTION( glXSelectEvent ), + GLX_FUNCTION(glXChooseFBConfig), + GLX_FUNCTION(glXCreateNewContext), + GLX_FUNCTION(glXCreatePbuffer), + GLX_FUNCTION(glXCreatePixmap), + GLX_FUNCTION(glXCreateWindow), + GLX_FUNCTION(glXDestroyPbuffer), + GLX_FUNCTION(glXDestroyPixmap), + GLX_FUNCTION(glXDestroyWindow), + GLX_FUNCTION(glXGetCurrentReadDrawable), + GLX_FUNCTION(glXGetFBConfigAttrib), + GLX_FUNCTION(glXGetFBConfigs), + GLX_FUNCTION(glXGetSelectedEvent), + GLX_FUNCTION(glXGetVisualFromFBConfig), + GLX_FUNCTION(glXMakeContextCurrent), + GLX_FUNCTION(glXQueryContext), + GLX_FUNCTION(glXQueryDrawable), + GLX_FUNCTION(glXSelectEvent), /*** GLX_SGI_swap_control ***/ - GLX_FUNCTION2( glXSwapIntervalSGI, __glXSwapIntervalSGI ), + GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI), /*** GLX_SGI_video_sync ***/ - GLX_FUNCTION2( glXGetVideoSyncSGI, __glXGetVideoSyncSGI ), - GLX_FUNCTION2( glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI ), + GLX_FUNCTION2(glXGetVideoSyncSGI, __glXGetVideoSyncSGI), + GLX_FUNCTION2(glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI), /*** GLX_SGI_make_current_read ***/ - GLX_FUNCTION2( glXMakeCurrentReadSGI, glXMakeContextCurrent ), - GLX_FUNCTION2( glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable ), + GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent), + GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable), /*** GLX_EXT_import_context ***/ - GLX_FUNCTION( glXFreeContextEXT ), - GLX_FUNCTION( glXGetContextIDEXT ), - GLX_FUNCTION2( glXGetCurrentDisplayEXT, glXGetCurrentDisplay ), - GLX_FUNCTION( glXImportContextEXT ), - GLX_FUNCTION2( glXQueryContextInfoEXT, glXQueryContext ), + GLX_FUNCTION(glXFreeContextEXT), + GLX_FUNCTION(glXGetContextIDEXT), + GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay), + GLX_FUNCTION(glXImportContextEXT), + GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext), /*** GLX_SGIX_fbconfig ***/ - GLX_FUNCTION2( glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib ), - GLX_FUNCTION2( glXChooseFBConfigSGIX, glXChooseFBConfig ), - GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX ), - GLX_FUNCTION( glXCreateContextWithConfigSGIX ), - GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig ), - GLX_FUNCTION( glXGetFBConfigFromVisualSGIX ), + GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib), + GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig), + GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX), + GLX_FUNCTION(glXCreateContextWithConfigSGIX), + GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig), + GLX_FUNCTION(glXGetFBConfigFromVisualSGIX), /*** GLX_SGIX_pbuffer ***/ - GLX_FUNCTION( glXCreateGLXPbufferSGIX ), - GLX_FUNCTION( glXDestroyGLXPbufferSGIX ), - GLX_FUNCTION( glXQueryGLXPbufferSGIX ), - GLX_FUNCTION( glXSelectEventSGIX ), - GLX_FUNCTION( glXGetSelectedEventSGIX ), + GLX_FUNCTION(glXCreateGLXPbufferSGIX), + GLX_FUNCTION(glXDestroyGLXPbufferSGIX), + GLX_FUNCTION(glXQueryGLXPbufferSGIX), + GLX_FUNCTION(glXSelectEventSGIX), + GLX_FUNCTION(glXGetSelectedEventSGIX), /*** GLX_SGIX_swap_group ***/ - GLX_FUNCTION2( glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX ), + GLX_FUNCTION2(glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX), /*** GLX_SGIX_swap_barrier ***/ - GLX_FUNCTION2( glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX ), - GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX ), + GLX_FUNCTION2(glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX), + GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX), /*** GLX_MESA_allocate_memory ***/ - GLX_FUNCTION( glXAllocateMemoryMESA ), - GLX_FUNCTION( glXFreeMemoryMESA ), - GLX_FUNCTION( glXGetMemoryOffsetMESA ), + GLX_FUNCTION(glXAllocateMemoryMESA), + GLX_FUNCTION(glXFreeMemoryMESA), + GLX_FUNCTION(glXGetMemoryOffsetMESA), /*** GLX_MESA_copy_sub_buffer ***/ - GLX_FUNCTION2( glXCopySubBufferMESA, __glXCopySubBufferMESA ), + GLX_FUNCTION2(glXCopySubBufferMESA, __glXCopySubBufferMESA), /*** GLX_MESA_pixmap_colormap ***/ - GLX_FUNCTION( glXCreateGLXPixmapMESA ), + GLX_FUNCTION(glXCreateGLXPixmapMESA), /*** GLX_MESA_release_buffers ***/ - GLX_FUNCTION2( glXReleaseBuffersMESA, __glXReleaseBuffersMESA ), + GLX_FUNCTION2(glXReleaseBuffersMESA, __glXReleaseBuffersMESA), /*** GLX_MESA_swap_control ***/ - GLX_FUNCTION2( glXSwapIntervalMESA, __glXSwapIntervalMESA ), - GLX_FUNCTION2( glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA ), + GLX_FUNCTION2(glXSwapIntervalMESA, __glXSwapIntervalMESA), + GLX_FUNCTION2(glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA), /*** GLX_MESA_swap_frame_usage ***/ - GLX_FUNCTION2( glXBeginFrameTrackingMESA, __glXBeginFrameTrackingMESA ), - GLX_FUNCTION2( glXEndFrameTrackingMESA, __glXEndFrameTrackingMESA ), - GLX_FUNCTION2( glXGetFrameUsageMESA, __glXGetFrameUsageMESA ), - GLX_FUNCTION2( glXQueryFrameTrackingMESA, __glXQueryFrameTrackingMESA ), + GLX_FUNCTION2(glXBeginFrameTrackingMESA, __glXBeginFrameTrackingMESA), + GLX_FUNCTION2(glXEndFrameTrackingMESA, __glXEndFrameTrackingMESA), + GLX_FUNCTION2(glXGetFrameUsageMESA, __glXGetFrameUsageMESA), + GLX_FUNCTION2(glXQueryFrameTrackingMESA, __glXQueryFrameTrackingMESA), /*** GLX_ARB_get_proc_address ***/ - GLX_FUNCTION( glXGetProcAddressARB ), + GLX_FUNCTION(glXGetProcAddressARB), /*** GLX 1.4 ***/ - GLX_FUNCTION2( glXGetProcAddress, glXGetProcAddressARB ), + GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB), /*** GLX_OML_sync_control ***/ - GLX_FUNCTION2( glXWaitForSbcOML, __glXWaitForSbcOML ), - GLX_FUNCTION2( glXWaitForMscOML, __glXWaitForMscOML ), - GLX_FUNCTION2( glXSwapBuffersMscOML, __glXSwapBuffersMscOML ), - GLX_FUNCTION2( glXGetMscRateOML, __glXGetMscRateOML ), - GLX_FUNCTION2( glXGetSyncValuesOML, __glXGetSyncValuesOML ), + GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML), + GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML), + GLX_FUNCTION2(glXSwapBuffersMscOML, __glXSwapBuffersMscOML), + GLX_FUNCTION2(glXGetMscRateOML, __glXGetMscRateOML), + GLX_FUNCTION2(glXGetSyncValuesOML, __glXGetSyncValuesOML), /*** GLX_EXT_texture_from_pixmap ***/ - GLX_FUNCTION2( glXBindTexImageEXT, __glXBindTexImageEXT ), - GLX_FUNCTION2( glXReleaseTexImageEXT, __glXReleaseTexImageEXT ), + GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT), + GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT), #ifdef GLX_DIRECT_RENDERING /*** DRI configuration ***/ - GLX_FUNCTION( glXGetScreenDriver ), - GLX_FUNCTION( glXGetDriverConfig ), + GLX_FUNCTION(glXGetScreenDriver), + GLX_FUNCTION(glXGetDriverConfig), #endif - { NULL, NULL } /* end of list */ + {NULL, NULL} /* end of list */ }; @@ -2941,7 +3020,7 @@ get_glx_proc_address(const char *funcName) /* try static functions */ for (i = 0; GLX_functions[i].Name; i++) { if (strcmp(GLX_functions[i].Name, funcName) == 0) - return GLX_functions[i].Address; + return GLX_functions[i].Address; } return NULL; @@ -2957,9 +3036,9 @@ get_glx_proc_address(const char *funcName) * * \sa glXGetProcAddress */ -PUBLIC void (*glXGetProcAddressARB(const GLubyte *procName))( void ) +PUBLIC void (*glXGetProcAddressARB(const GLubyte * procName)) (void) { - typedef void (*gl_function)( void ); + typedef void (*gl_function) (void); gl_function f; @@ -2971,8 +3050,8 @@ PUBLIC void (*glXGetProcAddressARB(const GLubyte *procName))( void ) */ f = (gl_function) get_glx_proc_address((const char *) procName); - if ( (f == NULL) && (procName[0] == 'g') && (procName[1] == 'l') - && (procName[2] != 'X') ) { + if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l') + && (procName[2] != 'X')) { f = (gl_function) _glapi_get_proc_address((const char *) procName); } @@ -2988,9 +3067,9 @@ PUBLIC void (*glXGetProcAddressARB(const GLubyte *procName))( void ) * * \sa glXGetProcAddressARB */ -PUBLIC void (*glXGetProcAddress(const GLubyte *procName))( void ) +PUBLIC void (*glXGetProcAddress(const GLubyte * procName)) (void) #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED) - __attribute__ ((alias ("glXGetProcAddressARB"))); + __attribute__ ((alias("glXGetProcAddressARB"))); #else { return glXGetProcAddressARB(procName); @@ -3008,24 +3087,26 @@ PUBLIC void (*glXGetProcAddress(const GLubyte *procName))( void ) * * \param ust Location to store the 64-bit UST * \returns Zero on success or a negative errno value on failure. - * + * * \sa glXGetProcAddress, PFNGLXGETUSTPROC * * \since Internal API version 20030317. */ -_X_HIDDEN int __glXGetUST( int64_t * ust ) -{ - struct timeval tv; - - if ( ust == NULL ) { - return -EFAULT; - } - - if ( gettimeofday( & tv, NULL ) == 0 ) { - ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec; - return 0; - } else { - return -errno; - } +_X_HIDDEN int +__glXGetUST(int64_t * ust) +{ + struct timeval tv; + + if (ust == NULL) { + return -EFAULT; + } + + if (gettimeofday(&tv, NULL) == 0) { + ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec; + return 0; + } + else { + return -errno; + } } #endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/x11/glxcurrent.c b/src/glx/x11/glxcurrent.c index d44e0dd1fc..f1e3e161be 100644 --- a/src/glx/x11/glxcurrent.c +++ b/src/glx/x11/glxcurrent.c @@ -73,45 +73,7 @@ static __GLapi *IndirectAPI = NULL; * Current context management and locking */ -#if defined( USE_XTHREADS ) - -/* thread safe */ -static GLboolean TSDinitialized = GL_FALSE; -static xthread_key_t ContextTSD; - -_X_HIDDEN __GLXcontext * -__glXGetCurrentContext(void) -{ - if (!TSDinitialized) { - xthread_key_create(&ContextTSD, NULL); - TSDinitialized = GL_TRUE; - return &dummyContext; - } - else { - void *p; - xthread_get_specific(ContextTSD, &p); - if (!p) - return &dummyContext; - else - return (__GLXcontext *) p; - } -} - -_X_HIDDEN void -__glXSetCurrentContext(__GLXcontext * c) -{ - if (!TSDinitialized) { - xthread_key_create(&ContextTSD, NULL); - TSDinitialized = GL_TRUE; - } - xthread_set_specific(ContextTSD, c); -} - - -/* Used by the __glXLock() and __glXUnlock() macros */ -_X_HIDDEN xmutex_rec __glXmutex; - -#elif defined( PTHREADS ) +#if defined( PTHREADS ) _X_HIDDEN pthread_mutex_t __glXmutex = PTHREAD_MUTEX_INITIALIZER; @@ -119,7 +81,7 @@ _X_HIDDEN pthread_mutex_t __glXmutex = PTHREAD_MUTEX_INITIALIZER; /** * Per-thread GLX context pointer. - * + * * \c __glXSetCurrentContext is written is such a way that this pointer can * \b never be \c NULL. This is important! Because of this * \c __glXGetCurrentContext can be implemented as trivial macro. @@ -139,7 +101,7 @@ static pthread_once_t once_control = PTHREAD_ONCE_INIT; /** * Per-thread data key. - * + * * Once \c init_thread_data has been called, the per-thread data key will * take a value of \c NULL. As each new thread is created the default * value, in that thread, will be \c NULL. @@ -148,7 +110,7 @@ static pthread_key_t ContextTSD; /** * Initialize the per-thread data key. - * + * * This function is called \b exactly once per-process (not per-thread!) to * initialize the per-thread data key. This is ideally done using the * \c pthread_once mechanism. @@ -340,8 +302,8 @@ FetchDRIDrawable(Display * dpy, GLXDrawable glxDrawable, GLXContext gc) #endif /* GLX_DIRECT_RENDERING */ static void -__glXGenerateError(Display *dpy, GLXContext gc, XID resource, - BYTE errorCode, CARD16 minorCode) +__glXGenerateError(Display * dpy, GLXContext gc, XID resource, + BYTE errorCode, CARD16 minorCode) { xError error; @@ -356,7 +318,7 @@ __glXGenerateError(Display *dpy, GLXContext gc, XID resource, /** * Make a particular context current. - * + * * \note This is in this file so that it can access dummyContext. */ static Bool @@ -385,21 +347,19 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, if (gc == NULL && (draw != None || read != None)) { __glXGenerateError(dpy, gc, (draw != None) ? draw : read, - BadMatch, X_GLXMakeContextCurrent); + BadMatch, X_GLXMakeContextCurrent); return False; } if (gc != NULL && (draw == None || read == None)) { - __glXGenerateError(dpy, gc, None, - BadMatch, X_GLXMakeContextCurrent); + __glXGenerateError(dpy, gc, None, BadMatch, X_GLXMakeContextCurrent); return False; } _glapi_check_multithread(); - if (gc != NULL && gc->thread_id != 0 && - gc->thread_id != _glthread_GetID()) { + if (gc != NULL && gc->thread_id != 0 && gc->thread_id != _glthread_GetID()) { __glXGenerateError(dpy, gc, gc->xid, - BadAccess, X_GLXMakeContextCurrent); + BadAccess, X_GLXMakeContextCurrent); return False; } @@ -411,7 +371,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, if ((pdraw == NULL) || (pread == NULL)) { __glXGenerateError(dpy, gc, (pdraw == NULL) ? draw : read, - GLXBadDrawable, X_GLXMakeContextCurrent); + GLXBadDrawable, X_GLXMakeContextCurrent); return False; } @@ -559,6 +519,5 @@ GLX_ALIAS(Bool, glXMakeCurrentReadSGI, PUBLIC GLX_ALIAS(Bool, glXMakeContextCurrent, - (Display * dpy, GLXDrawable d, GLXDrawable r, - GLXContext ctx), (dpy, d, r, ctx), - MakeContextCurrent) + (Display * dpy, GLXDrawable d, GLXDrawable r, + GLXContext ctx), (dpy, d, r, ctx), MakeContextCurrent) diff --git a/src/glx/x11/glxext.c b/src/glx/x11/glxext.c index 3078662c9d..e5553cbf76 100644 --- a/src/glx/x11/glxext.c +++ b/src/glx/x11/glxext.c @@ -102,19 +102,19 @@ static XEXT_GENERATE_ERROR_STRING(__glXErrorString, __glXExtensionName, __GLX_NUMBER_ERRORS, error_list) - static /* const */ XExtensionHooks __glXExtensionHooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - __glXCloseDisplay, /* close_display */ - NULL, /* wire_to_event */ - NULL, /* event_to_wire */ - NULL, /* error */ - __glXErrorString, /* error_string */ - }; +static /* const */ XExtensionHooks __glXExtensionHooks = { + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + __glXCloseDisplay, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + __glXErrorString, /* error_string */ +}; static XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay, __glXExtensionInfo, @@ -150,8 +150,8 @@ FreeScreenConfigs(__GLXdisplayPrivate * priv) #ifdef GLX_DIRECT_RENDERING if (psc->driver_configs) { - for(unsigned int i = 0; psc->driver_configs[i]; i++) - free((__DRIconfig*)psc->driver_configs[i]); + for (unsigned int i = 0; psc->driver_configs[i]; i++) + free((__DRIconfig *) psc->driver_configs[i]); free(psc->driver_configs); psc->driver_configs = NULL; } @@ -217,15 +217,14 @@ 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) - { + 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; } @@ -543,7 +542,8 @@ getFBConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen) __GLXscreenConfigs *psc; psc = priv->screenConfigs + screen; - psc->serverGLXexts = __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS); + psc->serverGLXexts = + __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS); LockDisplay(dpy); @@ -601,7 +601,8 @@ AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv) memset(psc, 0, screens * sizeof(__GLXscreenConfigs)); priv->screenConfigs = psc; - priv->serverGLXversion = __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION); + priv->serverGLXversion = + __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION); if (priv->serverGLXversion == NULL) { FreeScreenConfigs(priv); return GL_FALSE; @@ -652,17 +653,6 @@ __glXInitialize(Display * dpy) Bool glx_direct, glx_accel; #endif -#if defined(USE_XTHREADS) - { - static int firstCall = 1; - if (firstCall) { - /* initialize the GLX mutexes */ - xmutex_init(&__glXmutex); - firstCall = 0; - } - } -#endif - /* The one and only long long lock */ __glXLock(); @@ -797,10 +787,10 @@ __glXSetupForCommand(Display * dpy) /** * Flush the drawing command transport buffer. - * + * * \param ctx Context whose transport buffer is to be flushed. * \param pc Pointer to first unused buffer location. - * + * * \todo * Modify this function to use \c ctx->pc instead of the explicit * \c pc parameter. @@ -892,11 +882,11 @@ __glXSendLargeChunk(__GLXcontext * gc, GLint requestNumber, /** * Send a command that is too large for the GLXRender protocol request. - * + * * Send a large command, one that is too large for some reason to * send using the GLXRender protocol request. One reason to send * a large command is to avoid copying the data. - * + * * \param ctx GLX context * \param header Header data. * \param headerLen Size, in bytes, of the header data. It is assumed that diff --git a/src/glx/x11/glxextensions.c b/src/glx/x11/glxextensions.c index 051433a006..473f46d1e5 100644 --- a/src/glx/x11/glxextensions.c +++ b/src/glx/x11/glxextensions.c @@ -315,10 +315,10 @@ set_glx_extension(const struct extension_info *ext, /** * Convert the server's extension string to a bit-field. - * + * * \param server_string GLX extension string from the server. * \param server_support Bit-field of supported extensions. - * + * * \note * This function is used to process both GLX and GL extension strings. The * bit-fields used to track each of these have different sizes. Therefore, @@ -336,8 +336,7 @@ __glXProcessServerString(const struct extension_info *ext, /* Determine the length of the next extension name. */ for (len = 0; (server_string[base + len] != SEPARATOR) - && (server_string[base + len] != NUL); - len++) { + && (server_string[base + len] != NUL); len++) { /* empty */ } @@ -351,8 +350,7 @@ __glXProcessServerString(const struct extension_info *ext, * over the previous string and any trialing white-space. */ for (base += len; (server_string[base] == SEPARATOR) - && (server_string[base] != NUL); - base++) { + && (server_string[base] != NUL); base++) { /* empty */ } } @@ -549,7 +547,7 @@ __glXGetClientExtensions(void) /** * Calculate the list of application usable extensions. The resulting * string is stored in \c psc->effectiveGLXexts. - * + * * \param psc Pointer to GLX per-screen record. * \param display_is_direct_capable True if the display is capable of * direct rendering. @@ -600,7 +598,7 @@ __glXCalculateUsableExtensions(__GLXscreenConfigs * psc, * it and the "server" supports it. In this case that means that either * the true server supports it or it is only for direct-rendering and * the direct rendering driver supports it. - * + * * If the display is not capable of direct rendering, then the extension * is enabled if and only if the client-side library and the server * support it. @@ -609,10 +607,10 @@ __glXCalculateUsableExtensions(__GLXscreenConfigs * psc, if (display_is_direct_capable) { for (i = 0; i < 8; i++) { usable[i] = (client_glx_support[i] & client_glx_only[i]) - | (client_glx_support[i] & psc-> - direct_support[i] & server_support[i]) - | (client_glx_support[i] & psc-> - direct_support[i] & direct_glx_only[i]); + | (client_glx_support[i] & psc->direct_support[i] & + server_support[i]) + | (client_glx_support[i] & psc->direct_support[i] & + direct_glx_only[i]); } } else { @@ -630,7 +628,7 @@ __glXCalculateUsableExtensions(__GLXscreenConfigs * psc, /** * Calculate the list of application usable extensions. The resulting * string is stored in \c gc->extensions. - * + * * \param gc Pointer to GLX context. * \param server_string Extension string from the server. * \param major_version GL major version from the server. diff --git a/src/glx/x11/indirect.c b/src/glx/x11/indirect.c index aea117ec32..e0cafd43bc 100644 --- a/src/glx/x11/indirect.c +++ b/src/glx/x11/indirect.c @@ -5201,10 +5201,9 @@ glDeleteTexturesEXT(GLsizei n, const GLuint * textures) #ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_DeleteTextures(GET_DISPATCH(), (n, textures)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); @@ -5270,13 +5269,12 @@ glGenTexturesEXT(GLsizei n, GLuint * textures) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GenTextures(GET_DISPATCH(), (n, textures)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; const GLuint cmdlen = 4; @@ -5336,13 +5334,12 @@ glIsTextureEXT(GLuint texture) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { return CALL_IsTexture(GET_DISPATCH(), (texture)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; GLboolean retval = (GLboolean) 0; @@ -5653,13 +5650,12 @@ glGetColorTableEXT(GLenum target, GLenum format, GLenum type, GLvoid * table) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetColorTable(GET_DISPATCH(), (target, format, type, table)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); const __GLXattribute *const state = gc->client_state_private; Display *const dpy = gc->currentDpy; @@ -5730,14 +5726,13 @@ glGetColorTableParameterfvEXT(GLenum target, GLenum pname, GLfloat * params) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetColorTableParameterfv(GET_DISPATCH(), (target, pname, params)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; const GLuint cmdlen = 8; @@ -5804,14 +5799,13 @@ glGetColorTableParameterivEXT(GLenum target, GLenum pname, GLint * params) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetColorTableParameteriv(GET_DISPATCH(), (target, pname, params)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; const GLuint cmdlen = 8; @@ -6131,14 +6125,13 @@ gl_dispatch_stub_356(GLenum target, GLenum format, GLenum type, { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetConvolutionFilter(GET_DISPATCH(), (target, format, type, image)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); const __GLXattribute *const state = gc->client_state_private; Display *const dpy = gc->currentDpy; @@ -6210,14 +6203,13 @@ gl_dispatch_stub_357(GLenum target, GLenum pname, GLfloat * params) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetConvolutionParameterfv(GET_DISPATCH(), (target, pname, params)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; const GLuint cmdlen = 8; @@ -6284,14 +6276,13 @@ gl_dispatch_stub_358(GLenum target, GLenum pname, GLint * params) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetConvolutionParameteriv(GET_DISPATCH(), (target, pname, params)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; const GLuint cmdlen = 8; @@ -6365,14 +6356,13 @@ gl_dispatch_stub_361(GLenum target, GLboolean reset, GLenum format, { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetHistogram(GET_DISPATCH(), (target, reset, format, type, values)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); const __GLXattribute *const state = gc->client_state_private; Display *const dpy = gc->currentDpy; @@ -6443,13 +6433,12 @@ gl_dispatch_stub_362(GLenum target, GLenum pname, GLfloat * params) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetHistogramParameterfv(GET_DISPATCH(), (target, pname, params)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; const GLuint cmdlen = 8; @@ -6515,13 +6504,12 @@ gl_dispatch_stub_363(GLenum target, GLenum pname, GLint * params) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetHistogramParameteriv(GET_DISPATCH(), (target, pname, params)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; const GLuint cmdlen = 8; @@ -6591,13 +6579,12 @@ gl_dispatch_stub_364(GLenum target, GLboolean reset, GLenum format, { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetMinmax(GET_DISPATCH(), (target, reset, format, type, values)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); const __GLXattribute *const state = gc->client_state_private; Display *const dpy = gc->currentDpy; @@ -6666,13 +6653,12 @@ gl_dispatch_stub_365(GLenum target, GLenum pname, GLfloat * params) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetMinmaxParameterfv(GET_DISPATCH(), (target, pname, params)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; const GLuint cmdlen = 8; @@ -6735,13 +6721,12 @@ gl_dispatch_stub_366(GLenum target, GLenum pname, GLint * params) { __GLXcontext *const gc = __glXGetCurrentContext(); -#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_DIRECT_RENDERING if (gc->driContext) { CALL_GetMinmaxParameteriv(GET_DISPATCH(), (target, pname, params)); - } else { -#else - { + } else #endif + { __GLXcontext *const gc = __glXGetCurrentContext(); Display *const dpy = gc->currentDpy; const GLuint cmdlen = 8; diff --git a/src/glx/x11/indirect_size.c b/src/glx/x11/indirect_size.c index 54c039dd6c..cdaf02ffe6 100644 --- a/src/glx/x11/indirect_size.c +++ b/src/glx/x11/indirect_size.c @@ -192,6 +192,10 @@ __glTexParameterfv_size(GLenum e) case GL_TEXTURE_MAX_ANISOTROPY_EXT: case GL_TEXTURE_LOD_BIAS: /* case GL_TEXTURE_LOD_BIAS_EXT:*/ + case GL_TEXTURE_STORAGE_HINT_APPLE: + case GL_STORAGE_PRIVATE_APPLE: + case GL_STORAGE_CACHED_APPLE: + case GL_STORAGE_SHARED_APPLE: case GL_DEPTH_TEXTURE_MODE: /* case GL_DEPTH_TEXTURE_MODE_ARB:*/ case GL_TEXTURE_COMPARE_MODE: diff --git a/src/glx/x11/indirect_vertex_array.c b/src/glx/x11/indirect_vertex_array.c index bb5232f618..ad9882528f 100644 --- a/src/glx/x11/indirect_vertex_array.c +++ b/src/glx/x11/indirect_vertex_array.c @@ -1,18 +1,18 @@ /* * (C) Copyright IBM Corporation 2004, 2005 * 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 * 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 @@ -39,7 +39,7 @@ /** * \file indirect_vertex_array.c * Implement GLX protocol for vertex arrays and vertex buffer objects. - * + * * The most important function in this fill is \c fill_array_info_cache. * The \c array_state_vector contains a cache of the ARRAY_INFO data sent * in the DrawArrays protocol. Certain operations, such as enabling or @@ -47,7 +47,7 @@ * fills-in this data. Additionally, it examines the enabled state and * other factors to determine what "version" of DrawArrays protocoal can be * used. - * + * * Current, only two versions of DrawArrays protocol are implemented. The * first version is the "none" protocol. This is the fallback when the * server does not support GL 1.1 / EXT_vertex_arrays. It is implemented @@ -90,11 +90,11 @@ static GLboolean validate_type(__GLXcontext * gc, GLenum type); /** - * Table of sizes, in bytes, of a GL types. All of the type enums are be in + * Table of sizes, in bytes, of a GL types. All of the type enums are be in * the range 0x1400 - 0x140F. That includes types added by extensions (i.e., * \c GL_HALF_FLOAT_NV). This elements of this table correspond to the * type enums masked with 0x0f. - * + * * \notes * \c GL_HALF_FLOAT_NV is not included. Neither are \c GL_2_BYTES, * \c GL_3_BYTES, or \c GL_4_BYTES. @@ -131,15 +131,15 @@ __glXFreeVertexArrayState(__GLXcontext * gc) /** * Initialize vertex array state of a GLX context. - * + * * \param gc GLX context whose vertex array state is to be initialized. - * + * * \warning * This function may only be called after __GLXcontext::gl_extension_bits, * __GLXcontext::server_minor, and __GLXcontext::server_major have been * initialized. These values are used to determine what vertex arrays are * supported. - * + * * \bug * Return values from malloc are not properly tested. */ @@ -171,7 +171,7 @@ __glXInitVertexArrayState(__GLXcontext * gc) * are supported by the server are create. For example, if the server * supports only 2 texture units, then only 2 texture coordinate arrays * are created. - * + * * At the very least, GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, * GL_COLOR_ARRAY, GL_INDEX_ARRAY, GL_TEXTURE_COORD_ARRAY, and * GL_EDGE_FLAG_ARRAY are supported. @@ -532,7 +532,7 @@ emit_DrawArrays_none(GLenum mode, GLint first, GLsizei count) /** * Emit the header data for the GL 1.1 / EXT_vertex_arrays DrawArrays * protocol. - * + * * \param gc GLX context. * \param arrays Array state. * \param elements_per_request Location to store the number of elements that @@ -543,7 +543,7 @@ emit_DrawArrays_none(GLenum mode, GLint first, GLsizei count) * will be zero. * \param mode Drawing mode. * \param count Number of vertices. - * + * * \returns * A pointer to the buffer for array data. */ @@ -594,7 +594,7 @@ emit_DrawArrays_header_old(__GLXcontext * gc, /* Calculate the number of data packets that will be required to send * the whole command. To do this, the number of verticies that * will fit in a single buffer must be calculated. - * + * * The important value here is elements_per_request. This is the * number of complete array elements that will fit in a single * buffer. There may be some wasted space at the end of the buffer, @@ -869,7 +869,7 @@ emit_DrawElements_old(GLenum mode, GLsizei count, GLenum type, /** * Validate that the \c mode parameter to \c glDrawArrays, et. al. is valid. * If it is not valid, then an error code is set in the GLX context. - * + * * \returns * \c GL_TRUE if the argument is valid, \c GL_FALSE if is not. */ @@ -902,7 +902,7 @@ validate_mode(__GLXcontext * gc, GLenum mode) * A value less than zero is invalid and will result in \c GL_INVALID_VALUE * being set. A value of zero will not result in an error being set, but * will result in \c GL_FALSE being returned. - * + * * \returns * \c GL_TRUE if the argument is valid, \c GL_FALSE if it is not. */ @@ -1084,21 +1084,21 @@ __indirect_glMultiDrawElementsEXT(GLenum mode, const GLsizei * count, #define COMMON_ARRAY_DATA_INIT(a, PTR, TYPE, STRIDE, COUNT, NORMALIZED, HDR_SIZE, OPCODE) \ - do { \ - (a)->data = PTR; \ - (a)->data_type = TYPE; \ - (a)->user_stride = STRIDE; \ - (a)->count = COUNT; \ - (a)->normalized = NORMALIZED; \ - \ - (a)->element_size = __glXTypeSize( TYPE ) * COUNT; \ - (a)->true_stride = (STRIDE == 0) \ - ? (a)->element_size : STRIDE; \ - \ - (a)->header_size = HDR_SIZE; \ - ((uint16_t *) (a)->header)[0] = __GLX_PAD((a)->header_size + (a)->element_size); \ - ((uint16_t *) (a)->header)[1] = OPCODE; \ - } while(0) + do { \ + (a)->data = PTR; \ + (a)->data_type = TYPE; \ + (a)->user_stride = STRIDE; \ + (a)->count = COUNT; \ + (a)->normalized = NORMALIZED; \ + \ + (a)->element_size = __glXTypeSize( TYPE ) * COUNT; \ + (a)->true_stride = (STRIDE == 0) \ + ? (a)->element_size : STRIDE; \ + \ + (a)->header_size = HDR_SIZE; \ + ((uint16_t *) (a)->header)[0] = __GLX_PAD((a)->header_size + (a)->element_size); \ + ((uint16_t *) (a)->header)[1] = OPCODE; \ + } while(0) void @@ -1363,36 +1363,36 @@ __indirect_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, { static const uint16_t short_ops[5] = { 0, X_GLrop_TexCoord1sv, X_GLrop_TexCoord2sv, X_GLrop_TexCoord3sv, - X_GLrop_TexCoord4sv + X_GLrop_TexCoord4sv }; static const uint16_t int_ops[5] = { 0, X_GLrop_TexCoord1iv, X_GLrop_TexCoord2iv, X_GLrop_TexCoord3iv, - X_GLrop_TexCoord4iv + X_GLrop_TexCoord4iv }; static const uint16_t float_ops[5] = { 0, X_GLrop_TexCoord1dv, X_GLrop_TexCoord2fv, X_GLrop_TexCoord3fv, - X_GLrop_TexCoord4fv + X_GLrop_TexCoord4fv }; static const uint16_t double_ops[5] = { 0, X_GLrop_TexCoord1dv, X_GLrop_TexCoord2dv, X_GLrop_TexCoord3dv, - X_GLrop_TexCoord4dv + X_GLrop_TexCoord4dv }; static const uint16_t mshort_ops[5] = { 0, X_GLrop_MultiTexCoord1svARB, X_GLrop_MultiTexCoord2svARB, - X_GLrop_MultiTexCoord3svARB, X_GLrop_MultiTexCoord4svARB + X_GLrop_MultiTexCoord3svARB, X_GLrop_MultiTexCoord4svARB }; static const uint16_t mint_ops[5] = { 0, X_GLrop_MultiTexCoord1ivARB, X_GLrop_MultiTexCoord2ivARB, - X_GLrop_MultiTexCoord3ivARB, X_GLrop_MultiTexCoord4ivARB + X_GLrop_MultiTexCoord3ivARB, X_GLrop_MultiTexCoord4ivARB }; static const uint16_t mfloat_ops[5] = { 0, X_GLrop_MultiTexCoord1dvARB, X_GLrop_MultiTexCoord2fvARB, - X_GLrop_MultiTexCoord3fvARB, X_GLrop_MultiTexCoord4fvARB + X_GLrop_MultiTexCoord3fvARB, X_GLrop_MultiTexCoord4fvARB }; static const uint16_t mdouble_ops[5] = { 0, X_GLrop_MultiTexCoord1dvARB, X_GLrop_MultiTexCoord2dvARB, - X_GLrop_MultiTexCoord3dvARB, X_GLrop_MultiTexCoord4dvARB + X_GLrop_MultiTexCoord3dvARB, X_GLrop_MultiTexCoord4dvARB }; uint16_t opcode; diff --git a/src/glx/x11/single2.c b/src/glx/x11/single2.c index 0b2d5113cc..d128ba2053 100644 --- a/src/glx/x11/single2.c +++ b/src/glx/x11/single2.c @@ -147,7 +147,7 @@ __indirect_glGetError(void) /** * Get the selected attribute from the client state. - * + * * \returns * On success \c GL_TRUE is returned. Otherwise, \c GL_FALSE is returned. */ @@ -679,7 +679,8 @@ __indirect_glGetString(GLenum name) */ (void) __glXFlushRenderBuffer(gc, gc->pc); - s = (GLubyte *) __glXGetString(dpy, gc->majorOpcode, gc->currentContextTag, name); + s = (GLubyte *) __glXGetString(dpy, gc->majorOpcode, gc->currentContextTag, + name); if (!s) { /* Throw data on the floor */ __glXSetError(gc, GL_OUT_OF_MEMORY); @@ -753,7 +754,7 @@ __indirect_glGetString(GLenum name) * hardware accelerated. For example, a TNT will show core * version 1.5, but most of the post-1.2 functionality is a * software fallback. - * + * * I don't want to break applications that rely on this odd * behavior. At the same time, the code is written and tested, * so I didn't want to throw it away. Therefore, the code is here @@ -766,7 +767,7 @@ __indirect_glGetString(GLenum name) * gc->server_minor are set. This version may be higher than we * can completely support, but it may imply support for some * extensions that we can support. - * + * * For example, at the time of this writing, the client-side * library only supports upto core GL version 1.2. However, cubic * textures, multitexture, multisampling, and some other 1.3 @@ -880,50 +881,50 @@ GLboolean __indirect_glAreTexturesResident(GLsizei n, const GLuint * textures, GLboolean * residences) { - __GLXcontext *const gc = __glXGetCurrentContext(); - Display *const dpy = gc->currentDpy; - GLboolean retval = (GLboolean) 0; - const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); - if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { + __GLXcontext *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; + const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { #ifdef USE_XCB - xcb_connection_t *c = XGetXCBConnection(dpy); - (void) __glXFlushRenderBuffer(gc, gc->pc); - xcb_glx_are_textures_resident_reply_t *reply = - xcb_glx_are_textures_resident_reply(c, - xcb_glx_are_textures_resident - (c, gc->currentContextTag, n, - textures), NULL); - (void) memcpy(residences, xcb_glx_are_textures_resident_data(reply), - xcb_glx_are_textures_resident_data_length(reply) * - sizeof(GLboolean)); - retval = reply->ret_val; - free(reply); + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_are_textures_resident_reply_t *reply = + xcb_glx_are_textures_resident_reply(c, + xcb_glx_are_textures_resident + (c, gc->currentContextTag, n, + textures), NULL); + (void) memcpy(residences, xcb_glx_are_textures_resident_data(reply), + xcb_glx_are_textures_resident_data_length(reply) * + sizeof(GLboolean)); + retval = reply->ret_val; + free(reply); #else - GLubyte const *pc = - __glXSetupSingleRequest(gc, X_GLsop_AreTexturesResident, cmdlen); - (void) memcpy((void *) (pc + 0), (void *) (&n), 4); - (void) memcpy((void *) (pc + 4), (void *) (textures), (n * 4)); - if (n & 3) { - /* n is not a multiple of four. - * When reply_is_always_array is TRUE, __glXReadReply() will - * put a multiple of four bytes into the dest buffer. If the - * caller's buffer is not a multiple of four in size, we'll write - * out of bounds. So use a temporary buffer that's a few bytes - * larger. - */ - GLboolean *res4 = malloc((n + 3) & ~3); - retval = (GLboolean) __glXReadReply(dpy, 1, res4, GL_TRUE); - memcpy(residences, res4, n); - free(res4); - } - else { - retval = (GLboolean) __glXReadReply(dpy, 1, residences, GL_TRUE); - } - UnlockDisplay(dpy); - SyncHandle(); + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_AreTexturesResident, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) memcpy((void *) (pc + 4), (void *) (textures), (n * 4)); + if (n & 3) { + /* n is not a multiple of four. + * When reply_is_always_array is TRUE, __glXReadReply() will + * put a multiple of four bytes into the dest buffer. If the + * caller's buffer is not a multiple of four in size, we'll write + * out of bounds. So use a temporary buffer that's a few bytes + * larger. + */ + GLboolean *res4 = malloc((n + 3) & ~3); + retval = (GLboolean) __glXReadReply(dpy, 1, res4, GL_TRUE); + memcpy(residences, res4, n); + free(res4); + } + else { + retval = (GLboolean) __glXReadReply(dpy, 1, residences, GL_TRUE); + } + UnlockDisplay(dpy); + SyncHandle(); #endif /* USE_XCB */ - } - return retval; + } + return retval; } @@ -936,36 +937,37 @@ GLboolean glAreTexturesResidentEXT(GLsizei n, const GLuint * textures, GLboolean * residences) { - __GLXcontext *const gc = __glXGetCurrentContext(); - - if (gc->isDirect) { - return CALL_AreTexturesResident(GET_DISPATCH(), - (n, textures, residences)); - } else { - __GLXcontext *const gc = __glXGetCurrentContext(); - Display *const dpy = gc->currentDpy; - GLboolean retval = (GLboolean) 0; - const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); - if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { - GLubyte const *pc = - __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, - X_GLvop_AreTexturesResidentEXT, - cmdlen); - (void) memcpy((void *) (pc + 0), (void *) (&n), 4); - (void) memcpy((void *) (pc + 4), (void *) (textures), (n * 4)); - if (n & 3) { - /* see comments in __indirect_glAreTexturesResident() */ - GLboolean *res4 = malloc((n + 3) & ~3); - retval = (GLboolean) __glXReadReply(dpy, 1, res4, GL_TRUE); - memcpy(residences, res4, n); - free(res4); - } - else { - retval = (GLboolean) __glXReadReply(dpy, 1, residences, GL_TRUE); - } - UnlockDisplay(dpy); - SyncHandle(); - } - return retval; - } + __GLXcontext *const gc = __glXGetCurrentContext(); + + if (gc->isDirect) { + return CALL_AreTexturesResident(GET_DISPATCH(), + (n, textures, residences)); + } + else { + __GLXcontext *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; + const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_AreTexturesResidentEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) memcpy((void *) (pc + 4), (void *) (textures), (n * 4)); + if (n & 3) { + /* see comments in __indirect_glAreTexturesResident() */ + GLboolean *res4 = malloc((n + 3) & ~3); + retval = (GLboolean) __glXReadReply(dpy, 1, res4, GL_TRUE); + memcpy(residences, res4, n); + free(res4); + } + else { + retval = (GLboolean) __glXReadReply(dpy, 1, residences, GL_TRUE); + } + UnlockDisplay(dpy); + SyncHandle(); + } + return retval; + } } |