2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
33 * GLX protocol interface boot-strap code.
35 * Direct rendering support added by Precision Insight, Inc.
37 * \author Kevin E. Martin <kevin@precisioninsight.com>
41 #include "glxclient.h"
42 #include <X11/extensions/Xext.h>
43 #include <X11/extensions/extutil.h>
44 #ifdef GLX_USE_APPLEGL
45 #include "apple_glx.h"
46 #include "apple_visual.h"
48 #include "glxextensions.h"
51 #include <X11/Xlib-xcb.h>
58 void __glXDumpDrawBuffer(struct glx_context * ctx);
62 ** You can set this cell to 1 to force the gl drawing stuff to be
63 ** one command per packet
65 _X_HIDDEN int __glXDebug = 0;
67 /* Extension required boiler plate */
69 static const char __glXExtensionName[] = GLX_EXTENSION_NAME;
70 static struct glx_display *glx_displays;
72 static /* const */ char *error_list[] = {
78 "GLXBadCurrentWindow",
79 "GLXBadRenderRequest",
81 "GLXUnsupportedPrivateRequest",
84 "GLXBadCurrentDrawable",
88 #ifdef GLX_USE_APPLEGL
89 static char *__glXErrorString(Display *dpy, int code, XExtCodes *codes,
94 XEXT_GENERATE_ERROR_STRING(__glXErrorString, __glXExtensionName,
95 __GLX_NUMBER_ERRORS, error_list)
98 * GLX events are a bit funky. We don't stuff the X event code into
99 * our user exposed (via XNextEvent) structure. Instead we use the GLX
100 * private event code namespace (and hope it doesn't conflict). Clients
101 * have to know that bit 15 in the event type field means they're getting
102 * a GLX event, and then handle the various sub-event types there, rather
103 * than simply checking the event code and handling it directly.
107 __glXWireToEvent(Display *dpy, XEvent *event, xEvent *wire)
109 struct glx_display *glx_dpy = __glXInitialize(dpy);
114 switch ((wire->u.u.type & 0x7f) - glx_dpy->codes->first_event) {
115 case GLX_PbufferClobber:
117 GLXPbufferClobberEvent *aevent = (GLXPbufferClobberEvent *)event;
118 xGLXPbufferClobberEvent *awire = (xGLXPbufferClobberEvent *)wire;
119 aevent->event_type = awire->type;
120 aevent->serial = awire->sequenceNumber;
121 aevent->event_type = awire->event_type;
122 aevent->draw_type = awire->draw_type;
123 aevent->drawable = awire->drawable;
124 aevent->buffer_mask = awire->buffer_mask;
125 aevent->aux_buffer = awire->aux_buffer;
126 aevent->x = awire->x;
127 aevent->y = awire->y;
128 aevent->width = awire->width;
129 aevent->height = awire->height;
130 aevent->count = awire->count;
133 case GLX_BufferSwapComplete:
135 GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event;
136 xGLXBufferSwapComplete *awire = (xGLXBufferSwapComplete *)wire;
137 aevent->event_type = awire->event_type;
138 aevent->drawable = awire->drawable;
139 aevent->ust = ((CARD64)awire->ust_hi << 32) | awire->ust_lo;
140 aevent->msc = ((CARD64)awire->msc_hi << 32) | awire->msc_lo;
141 aevent->sbc = ((CARD64)awire->sbc_hi << 32) | awire->sbc_lo;
145 /* client doesn't support server event */
152 /* We don't actually support this. It doesn't make sense for clients to
153 * send each other GLX events.
156 __glXEventToWire(Display *dpy, XEvent *event, xEvent *wire)
158 struct glx_display *glx_dpy = __glXInitialize(dpy);
163 switch (event->type) {
168 case GLX_EXCHANGE_COMPLETE_INTEL:
170 case GLX_COPY_COMPLETE_INTEL:
172 case GLX_FLIP_COMPLETE_INTEL:
175 /* client doesn't support server event */
182 /************************************************************************/
184 ** Free the per screen configs data as well as the array of
185 ** __glXScreenConfigs.
188 FreeScreenConfigs(struct glx_display * priv)
190 struct glx_screen *psc;
193 /* Free screen configuration information */
194 screens = ScreenCount(priv->dpy);
195 for (i = 0; i < screens; i++) {
196 psc = priv->screens[i];
198 glx_config_destroy_list(psc->configs);
199 if (psc->effectiveGLXexts)
200 Xfree(psc->effectiveGLXexts);
201 psc->configs = NULL; /* NOTE: just for paranoia */
204 glx_config_destroy_list(psc->visuals);
205 psc->visuals = NULL; /* NOTE: just for paranoia */
207 Xfree((char *) psc->serverGLXexts);
209 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
210 if (psc->driScreen) {
211 psc->driScreen->destroyScreen(psc);
219 XFree((char *) priv->screens);
220 priv->screens = NULL;
224 glx_display_free(struct glx_display *priv)
226 struct glx_context *gc;
228 gc = __glXGetCurrentContext();
229 if (priv->dpy == gc->currentDpy) {
230 gc->vtable->destroy(gc);
231 __glXSetCurrentContextNull();
234 FreeScreenConfigs(priv);
235 if (priv->serverGLXvendor)
236 Xfree((char *) priv->serverGLXvendor);
237 if (priv->serverGLXversion)
238 Xfree((char *) priv->serverGLXversion);
240 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
241 __glxHashDestroy(priv->drawHash);
243 /* Free the direct rendering per display data */
244 if (priv->driswDisplay)
245 (*priv->driswDisplay->destroyDisplay) (priv->driswDisplay);
246 priv->driswDisplay = NULL;
248 if (priv->driDisplay)
249 (*priv->driDisplay->destroyDisplay) (priv->driDisplay);
250 priv->driDisplay = NULL;
252 if (priv->dri2Display)
253 (*priv->dri2Display->destroyDisplay) (priv->dri2Display);
254 priv->dri2Display = NULL;
257 Xfree((char *) priv);
261 __glXCloseDisplay(Display * dpy, XExtCodes * codes)
263 struct glx_display *priv, **prev;
265 _XLockMutex(_Xglobal_lock);
266 prev = &glx_displays;
267 for (priv = glx_displays; priv; prev = &priv->next, priv = priv->next) {
268 if (priv->dpy == dpy) {
269 (*prev) = priv->next;
273 _XUnlockMutex(_Xglobal_lock);
275 glx_display_free(priv);
281 ** Query the version of the GLX extension. This procedure works even if
282 ** the client extension is not completely set up.
285 QueryVersion(Display * dpy, int opcode, int *major, int *minor)
288 xcb_connection_t *c = XGetXCBConnection(dpy);
289 xcb_glx_query_version_reply_t *reply = xcb_glx_query_version_reply(c,
290 xcb_glx_query_version
296 if (reply->major_version != GLX_MAJOR_VERSION) {
300 *major = reply->major_version;
301 *minor = min(reply->minor_version, GLX_MINOR_VERSION);
305 xGLXQueryVersionReq *req;
306 xGLXQueryVersionReply reply;
308 /* Send the glXQueryVersion request */
310 GetReq(GLXQueryVersion, req);
311 req->reqType = opcode;
312 req->glxCode = X_GLXQueryVersion;
313 req->majorVersion = GLX_MAJOR_VERSION;
314 req->minorVersion = GLX_MINOR_VERSION;
315 _XReply(dpy, (xReply *) & reply, 0, False);
319 if (reply.majorVersion != GLX_MAJOR_VERSION) {
321 ** The server does not support the same major release as this
326 *major = reply.majorVersion;
327 *minor = min(reply.minorVersion, GLX_MINOR_VERSION);
333 * We don't want to enable this GLX_OML_swap_method in glxext.h,
334 * because we can't support it. The X server writes it out though,
335 * so we should handle it somehow, to avoid false warnings.
338 IGNORE_GLX_SWAP_METHOD_OML = 0x8060
343 convert_from_x_visual_type(int visualType)
345 static const int glx_visual_types[] = {
346 GLX_STATIC_GRAY, GLX_GRAY_SCALE,
347 GLX_STATIC_COLOR, GLX_PSEUDO_COLOR,
348 GLX_TRUE_COLOR, GLX_DIRECT_COLOR
351 if (visualType < ARRAY_SIZE(glx_visual_types))
352 return glx_visual_types[visualType];
358 * getVisualConfigs uses the !tagged_only path.
359 * getFBConfigs uses the tagged_only path.
362 __glXInitializeVisualConfigFromTags(struct glx_config * config, int count,
363 const INT32 * bp, Bool tagged_only,
364 Bool fbconfig_style_tags)
369 /* Copy in the first set of properties */
370 config->visualID = *bp++;
372 config->visualType = convert_from_x_visual_type(*bp++);
374 config->rgbMode = *bp++;
376 config->redBits = *bp++;
377 config->greenBits = *bp++;
378 config->blueBits = *bp++;
379 config->alphaBits = *bp++;
380 config->accumRedBits = *bp++;
381 config->accumGreenBits = *bp++;
382 config->accumBlueBits = *bp++;
383 config->accumAlphaBits = *bp++;
385 config->doubleBufferMode = *bp++;
386 config->stereoMode = *bp++;
388 config->rgbBits = *bp++;
389 config->depthBits = *bp++;
390 config->stencilBits = *bp++;
391 config->numAuxBuffers = *bp++;
392 config->level = *bp++;
394 #ifdef GLX_USE_APPLEGL
395 /* AppleSGLX supports pixmap and pbuffers with all config. */
396 config->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
397 /* Unfortunately this can create an ABI compatibility problem. */
400 count -= __GLX_MIN_CONFIG_PROPS;
405 ** Additional properties may be in a list at the end
406 ** of the reply. They are in pairs of property type
407 ** and property value.
410 #define FETCH_OR_SET(tag) \
411 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
413 for (i = 0; i < count; i += 2) {
414 long int tag = *bp++;
418 FETCH_OR_SET(rgbMode);
420 case GLX_BUFFER_SIZE:
421 config->rgbBits = *bp++;
424 config->level = *bp++;
426 case GLX_DOUBLEBUFFER:
427 FETCH_OR_SET(doubleBufferMode);
430 FETCH_OR_SET(stereoMode);
432 case GLX_AUX_BUFFERS:
433 config->numAuxBuffers = *bp++;
436 config->redBits = *bp++;
439 config->greenBits = *bp++;
442 config->blueBits = *bp++;
445 config->alphaBits = *bp++;
448 config->depthBits = *bp++;
450 case GLX_STENCIL_SIZE:
451 config->stencilBits = *bp++;
453 case GLX_ACCUM_RED_SIZE:
454 config->accumRedBits = *bp++;
456 case GLX_ACCUM_GREEN_SIZE:
457 config->accumGreenBits = *bp++;
459 case GLX_ACCUM_BLUE_SIZE:
460 config->accumBlueBits = *bp++;
462 case GLX_ACCUM_ALPHA_SIZE:
463 config->accumAlphaBits = *bp++;
465 case GLX_VISUAL_CAVEAT_EXT:
466 config->visualRating = *bp++;
468 case GLX_X_VISUAL_TYPE:
469 config->visualType = *bp++;
471 case GLX_TRANSPARENT_TYPE:
472 config->transparentPixel = *bp++;
474 case GLX_TRANSPARENT_INDEX_VALUE:
475 config->transparentIndex = *bp++;
477 case GLX_TRANSPARENT_RED_VALUE:
478 config->transparentRed = *bp++;
480 case GLX_TRANSPARENT_GREEN_VALUE:
481 config->transparentGreen = *bp++;
483 case GLX_TRANSPARENT_BLUE_VALUE:
484 config->transparentBlue = *bp++;
486 case GLX_TRANSPARENT_ALPHA_VALUE:
487 config->transparentAlpha = *bp++;
490 config->visualID = *bp++;
492 case GLX_DRAWABLE_TYPE:
493 config->drawableType = *bp++;
494 #ifdef GLX_USE_APPLEGL
495 /* AppleSGLX supports pixmap and pbuffers with all config. */
496 config->drawableType |= GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
499 case GLX_RENDER_TYPE:
500 config->renderType = *bp++;
502 case GLX_X_RENDERABLE:
503 config->xRenderable = *bp++;
505 case GLX_FBCONFIG_ID:
506 config->fbconfigID = *bp++;
508 case GLX_MAX_PBUFFER_WIDTH:
509 config->maxPbufferWidth = *bp++;
511 case GLX_MAX_PBUFFER_HEIGHT:
512 config->maxPbufferHeight = *bp++;
514 case GLX_MAX_PBUFFER_PIXELS:
515 config->maxPbufferPixels = *bp++;
517 #ifndef GLX_USE_APPLEGL
518 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX:
519 config->optimalPbufferWidth = *bp++;
521 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX:
522 config->optimalPbufferHeight = *bp++;
524 case GLX_VISUAL_SELECT_GROUP_SGIX:
525 config->visualSelectGroup = *bp++;
527 case GLX_SWAP_METHOD_OML:
528 config->swapMethod = *bp++;
531 case GLX_SAMPLE_BUFFERS_SGIS:
532 config->sampleBuffers = *bp++;
534 case GLX_SAMPLES_SGIS:
535 config->samples = *bp++;
537 #ifdef GLX_USE_APPLEGL
538 case IGNORE_GLX_SWAP_METHOD_OML:
539 /* We ignore this tag. See the comment above this function. */
543 case GLX_BIND_TO_TEXTURE_RGB_EXT:
544 config->bindToTextureRgb = *bp++;
546 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
547 config->bindToTextureRgba = *bp++;
549 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
550 config->bindToMipmapTexture = *bp++;
552 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
553 config->bindToTextureTargets = *bp++;
555 case GLX_Y_INVERTED_EXT:
556 config->yInverted = *bp++;
560 if (fbconfig_style_tags)
567 if(getenv("LIBGL_DIAGNOSTIC")) {
568 long int tagvalue = *bp++;
569 fprintf(stderr, "WARNING: unknown GLX tag from server: "
570 "tag 0x%lx value 0x%lx\n", tag, tagvalue);
572 /* Ignore the unrecognized tag's value */
580 (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
583 static struct glx_config *
584 createConfigsFromProperties(Display * dpy, int nvisuals, int nprops,
585 int screen, GLboolean tagged_only)
587 INT32 buf[__GLX_TOTAL_CONFIG], *props;
589 struct glx_config *modes, *m;
595 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
597 /* Check number of properties */
598 if (nprops < __GLX_MIN_CONFIG_PROPS || nprops > __GLX_MAX_CONFIG_PROPS)
601 /* Allocate memory for our config structure */
602 modes = glx_config_create_list(nvisuals);
606 prop_size = nprops * __GLX_SIZE_INT32;
607 if (prop_size <= sizeof(buf))
610 props = Xmalloc(prop_size);
612 /* Read each config structure and convert it into our format */
614 for (i = 0; i < nvisuals; i++) {
615 _XRead(dpy, (char *) props, prop_size);
616 #ifdef GLX_USE_APPLEGL
617 /* Older X servers don't send this so we default it here. */
618 m->drawableType = GLX_WINDOW_BIT;
621 * The XQuartz 2.3.2.1 X server doesn't set this properly, so
622 * set the proper bits here.
623 * AppleSGLX supports windows, pixmaps, and pbuffers with all config.
625 m->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
627 __glXInitializeVisualConfigFromTags(m, nprops, props,
628 tagged_only, GL_TRUE);
640 getVisualConfigs(struct glx_screen *psc,
641 struct glx_display *priv, int screen)
643 xGLXGetVisualConfigsReq *req;
644 xGLXGetVisualConfigsReply reply;
645 Display *dpy = priv->dpy;
650 GetReq(GLXGetVisualConfigs, req);
651 req->reqType = priv->majorOpcode;
652 req->glxCode = X_GLXGetVisualConfigs;
653 req->screen = screen;
655 if (!_XReply(dpy, (xReply *) & reply, 0, False))
658 psc->visuals = createConfigsFromProperties(dpy,
665 return psc->visuals != NULL;
669 getFBConfigs(struct glx_screen *psc, struct glx_display *priv, int screen)
671 xGLXGetFBConfigsReq *fb_req;
672 xGLXGetFBConfigsSGIXReq *sgi_req;
673 xGLXVendorPrivateWithReplyReq *vpreq;
674 xGLXGetFBConfigsReply reply;
675 Display *dpy = priv->dpy;
678 __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS);
683 if (atof(priv->serverGLXversion) >= 1.3) {
684 GetReq(GLXGetFBConfigs, fb_req);
685 fb_req->reqType = priv->majorOpcode;
686 fb_req->glxCode = X_GLXGetFBConfigs;
687 fb_req->screen = screen;
689 else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) {
690 GetReqExtra(GLXVendorPrivateWithReply,
691 sz_xGLXGetFBConfigsSGIXReq +
692 sz_xGLXVendorPrivateWithReplyReq, vpreq);
693 sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq;
694 sgi_req->reqType = priv->majorOpcode;
695 sgi_req->glxCode = X_GLXVendorPrivateWithReply;
696 sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX;
697 sgi_req->screen = screen;
702 if (!_XReply(dpy, (xReply *) & reply, 0, False))
705 psc->configs = createConfigsFromProperties(dpy,
707 reply.numAttribs * 2,
712 return psc->configs != NULL;
716 glx_screen_init(struct glx_screen *psc,
717 int screen, struct glx_display * priv)
719 /* Initialize per screen dynamic client GLX extensions */
720 psc->ext_list_first_time = GL_TRUE;
722 psc->dpy = priv->dpy;
725 getVisualConfigs(psc, priv, screen);
726 getFBConfigs(psc, priv, screen);
732 ** Allocate the memory for the per screen configs for each screen.
733 ** If that works then fetch the per screen configs data.
736 AllocAndFetchScreenConfigs(Display * dpy, struct glx_display * priv)
738 struct glx_screen *psc;
742 ** First allocate memory for the array of per screen configs.
744 screens = ScreenCount(dpy);
745 priv->screens = Xmalloc(screens * sizeof *priv->screens);
749 priv->serverGLXversion =
750 __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION);
751 if (priv->serverGLXversion == NULL) {
752 FreeScreenConfigs(priv);
756 for (i = 0; i < screens; i++, psc++) {
758 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
759 if (priv->dri2Display)
760 psc = (*priv->dri2Display->createScreen) (i, priv);
761 if (psc == NULL && priv->driDisplay)
762 psc = (*priv->driDisplay->createScreen) (i, priv);
763 if (psc == NULL && priv->driswDisplay)
764 psc = (*priv->driswDisplay->createScreen) (i, priv);
766 #if defined(GLX_USE_APPLEGL)
767 if (psc == NULL && priv->appleglDisplay)
768 psc = (*priv->appleglDisplay->createScreen) (i, priv);
771 psc = indirect_create_screen(i, priv);
772 priv->screens[i] = psc;
779 ** Initialize the client side extension code.
781 _X_HIDDEN struct glx_display *
782 __glXInitialize(Display * dpy)
784 struct glx_display *dpyPriv, *d;
785 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
786 Bool glx_direct, glx_accel;
790 _XLockMutex(_Xglobal_lock);
792 for (dpyPriv = glx_displays; dpyPriv; dpyPriv = dpyPriv->next) {
793 if (dpyPriv->dpy == dpy) {
794 _XUnlockMutex(_Xglobal_lock);
799 /* Drop the lock while we create the display private. */
800 _XUnlockMutex(_Xglobal_lock);
802 dpyPriv = Xcalloc(1, sizeof *dpyPriv);
806 dpyPriv->codes = XInitExtension(dpy, __glXExtensionName);
807 if (!dpyPriv->codes) {
809 _XUnlockMutex(_Xglobal_lock);
814 dpyPriv->majorOpcode = dpyPriv->codes->major_opcode;
815 dpyPriv->serverGLXvendor = 0x0;
816 dpyPriv->serverGLXversion = 0x0;
818 /* See if the versions are compatible */
819 if (!QueryVersion(dpy, dpyPriv->majorOpcode,
820 &dpyPriv->majorVersion, &dpyPriv->minorVersion)) {
822 _XUnlockMutex(_Xglobal_lock);
826 for (i = 0; i < __GLX_NUMBER_EVENTS; i++) {
827 XESetWireToEvent(dpy, dpyPriv->codes->first_event + i, __glXWireToEvent);
828 XESetEventToWire(dpy, dpyPriv->codes->first_event + i, __glXEventToWire);
831 XESetCloseDisplay(dpy, dpyPriv->codes->extension, __glXCloseDisplay);
832 XESetErrorString (dpy, dpyPriv->codes->extension,__glXErrorString);
834 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
835 glx_direct = (getenv("LIBGL_ALWAYS_INDIRECT") == NULL);
836 glx_accel = (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL);
838 dpyPriv->drawHash = __glxHashCreate();
841 ** Initialize the direct rendering per display data and functions.
842 ** Note: This _must_ be done before calling any other DRI routines
843 ** (e.g., those called in AllocAndFetchScreenConfigs).
845 if (glx_direct && glx_accel) {
846 dpyPriv->dri2Display = dri2CreateDisplay(dpy);
847 dpyPriv->driDisplay = driCreateDisplay(dpy);
850 dpyPriv->driswDisplay = driswCreateDisplay(dpy);
853 #ifdef GLX_USE_APPLEGL
854 if (!applegl_create_display(dpyPriv)) {
859 if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) {
864 if (dpyPriv->majorVersion == 1 && dpyPriv->minorVersion >= 1)
865 __glXClientInfo(dpy, dpyPriv->majorOpcode);
867 /* Grab the lock again and add the dispay private, unless somebody
868 * beat us to initializing on this display in the meantime. */
869 _XLockMutex(_Xglobal_lock);
871 for (d = glx_displays; d; d = d->next) {
873 _XUnlockMutex(_Xglobal_lock);
874 glx_display_free(dpyPriv);
879 dpyPriv->next = glx_displays;
880 glx_displays = dpyPriv;
882 _XUnlockMutex(_Xglobal_lock);
888 ** Setup for sending a GLX command on dpy. Make sure the extension is
889 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
892 __glXSetupForCommand(Display * dpy)
894 struct glx_context *gc;
895 struct glx_display *priv;
897 /* If this thread has a current context, flush its rendering commands */
898 gc = __glXGetCurrentContext();
899 if (gc->currentDpy) {
900 /* Flush rendering buffer of the current context, if any */
901 (void) __glXFlushRenderBuffer(gc, gc->pc);
903 if (gc->currentDpy == dpy) {
904 /* Use opcode from gc because its right */
905 return gc->majorOpcode;
909 ** Have to get info about argument dpy because it might be to
910 ** a different server
915 /* Forced to lookup extension via the slow initialize route */
916 priv = __glXInitialize(dpy);
920 return priv->majorOpcode;
924 * Flush the drawing command transport buffer.
926 * \param ctx Context whose transport buffer is to be flushed.
927 * \param pc Pointer to first unused buffer location.
930 * Modify this function to use \c ctx->pc instead of the explicit
934 __glXFlushRenderBuffer(struct glx_context * ctx, GLubyte * pc)
936 Display *const dpy = ctx->currentDpy;
938 xcb_connection_t *c = XGetXCBConnection(dpy);
942 const GLint size = pc - ctx->buf;
944 if ((dpy != NULL) && (size > 0)) {
946 xcb_glx_render(c, ctx->currentContextTag, size,
947 (const uint8_t *) ctx->buf);
949 /* Send the entire buffer as an X request */
951 GetReq(GLXRender, req);
952 req->reqType = ctx->majorOpcode;
953 req->glxCode = X_GLXRender;
954 req->contextTag = ctx->currentContextTag;
955 req->length += (size + 3) >> 2;
956 _XSend(dpy, (char *) ctx->buf, size);
962 /* Reset pointer and return it */
969 * Send a portion of a GLXRenderLarge command to the server. The advantage of
970 * this function over \c __glXSendLargeCommand is that callers can use the
971 * data buffer in the GLX context and may be able to avoid allocating an
972 * extra buffer. The disadvantage is the clients will have to do more
973 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
975 * \sa __glXSendLargeCommand
977 * \param gc GLX context
978 * \param requestNumber Which part of the whole command is this? The first
980 * \param totalRequests How many requests will there be?
981 * \param data Command data.
982 * \param dataLen Size, in bytes, of the command data.
985 __glXSendLargeChunk(struct glx_context * gc, GLint requestNumber,
986 GLint totalRequests, const GLvoid * data, GLint dataLen)
988 Display *dpy = gc->currentDpy;
990 xcb_connection_t *c = XGetXCBConnection(dpy);
991 xcb_glx_render_large(c, gc->currentContextTag, requestNumber,
992 totalRequests, dataLen, data);
994 xGLXRenderLargeReq *req;
996 if (requestNumber == 1) {
1000 GetReq(GLXRenderLarge, req);
1001 req->reqType = gc->majorOpcode;
1002 req->glxCode = X_GLXRenderLarge;
1003 req->contextTag = gc->currentContextTag;
1004 req->length += (dataLen + 3) >> 2;
1005 req->requestNumber = requestNumber;
1006 req->requestTotal = totalRequests;
1007 req->dataBytes = dataLen;
1008 Data(dpy, data, dataLen);
1010 if (requestNumber == totalRequests) {
1014 #endif /* USE_XCB */
1019 * Send a command that is too large for the GLXRender protocol request.
1021 * Send a large command, one that is too large for some reason to
1022 * send using the GLXRender protocol request. One reason to send
1023 * a large command is to avoid copying the data.
1025 * \param ctx GLX context
1026 * \param header Header data.
1027 * \param headerLen Size, in bytes, of the header data. It is assumed that
1028 * the header data will always be small enough to fit in
1029 * a single X protocol packet.
1030 * \param data Command data.
1031 * \param dataLen Size, in bytes, of the command data.
1034 __glXSendLargeCommand(struct glx_context * ctx,
1035 const GLvoid * header, GLint headerLen,
1036 const GLvoid * data, GLint dataLen)
1039 GLint totalRequests, requestNumber;
1042 ** Calculate the maximum amount of data can be stuffed into a single
1043 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1044 ** packet size minus sz_xGLXRenderReq.
1046 maxSize = (ctx->bufSize + sz_xGLXRenderReq) - sz_xGLXRenderLargeReq;
1047 totalRequests = 1 + (dataLen / maxSize);
1048 if (dataLen % maxSize)
1052 ** Send all of the command, except the large array, as one request.
1054 assert(headerLen <= maxSize);
1055 __glXSendLargeChunk(ctx, 1, totalRequests, header, headerLen);
1058 ** Send enough requests until the whole array is sent.
1060 for (requestNumber = 2; requestNumber <= (totalRequests - 1);
1062 __glXSendLargeChunk(ctx, requestNumber, totalRequests, data, maxSize);
1063 data = (const GLvoid *) (((const GLubyte *) data) + maxSize);
1065 assert(dataLen > 0);
1068 assert(dataLen <= maxSize);
1069 __glXSendLargeChunk(ctx, requestNumber, totalRequests, data, dataLen);
1072 /************************************************************************/
1076 __glXDumpDrawBuffer(struct glx_context * ctx)
1078 GLubyte *p = ctx->buf;
1079 GLubyte *end = ctx->pc;
1080 GLushort opcode, length;
1084 opcode = *((GLushort *) p);
1085 length = *((GLushort *) (p + 2));
1086 printf("%2x: %5d: ", opcode, length);
1089 while (length > 0) {
1090 printf("%08x ", *((unsigned *) p));