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];
197 glx_screen_cleanup(psc);
199 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
200 if (psc->driScreen) {
201 psc->driScreen->destroyScreen(psc);
209 XFree((char *) priv->screens);
210 priv->screens = NULL;
214 glx_display_free(struct glx_display *priv)
216 struct glx_context *gc;
218 gc = __glXGetCurrentContext();
219 if (priv->dpy == gc->currentDpy) {
220 gc->vtable->destroy(gc);
221 __glXSetCurrentContextNull();
224 FreeScreenConfigs(priv);
225 if (priv->serverGLXvendor)
226 Xfree((char *) priv->serverGLXvendor);
227 if (priv->serverGLXversion)
228 Xfree((char *) priv->serverGLXversion);
230 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
231 __glxHashDestroy(priv->drawHash);
233 /* Free the direct rendering per display data */
234 if (priv->driswDisplay)
235 (*priv->driswDisplay->destroyDisplay) (priv->driswDisplay);
236 priv->driswDisplay = NULL;
238 if (priv->driDisplay)
239 (*priv->driDisplay->destroyDisplay) (priv->driDisplay);
240 priv->driDisplay = NULL;
242 if (priv->dri2Display)
243 (*priv->dri2Display->destroyDisplay) (priv->dri2Display);
244 priv->dri2Display = NULL;
247 Xfree((char *) priv);
251 __glXCloseDisplay(Display * dpy, XExtCodes * codes)
253 struct glx_display *priv, **prev;
255 _XLockMutex(_Xglobal_lock);
256 prev = &glx_displays;
257 for (priv = glx_displays; priv; prev = &priv->next, priv = priv->next) {
258 if (priv->dpy == dpy) {
259 (*prev) = priv->next;
263 _XUnlockMutex(_Xglobal_lock);
265 glx_display_free(priv);
271 ** Query the version of the GLX extension. This procedure works even if
272 ** the client extension is not completely set up.
275 QueryVersion(Display * dpy, int opcode, int *major, int *minor)
278 xcb_connection_t *c = XGetXCBConnection(dpy);
279 xcb_glx_query_version_reply_t *reply = xcb_glx_query_version_reply(c,
280 xcb_glx_query_version
286 if (reply->major_version != GLX_MAJOR_VERSION) {
290 *major = reply->major_version;
291 *minor = min(reply->minor_version, GLX_MINOR_VERSION);
295 xGLXQueryVersionReq *req;
296 xGLXQueryVersionReply reply;
298 /* Send the glXQueryVersion request */
300 GetReq(GLXQueryVersion, req);
301 req->reqType = opcode;
302 req->glxCode = X_GLXQueryVersion;
303 req->majorVersion = GLX_MAJOR_VERSION;
304 req->minorVersion = GLX_MINOR_VERSION;
305 _XReply(dpy, (xReply *) & reply, 0, False);
309 if (reply.majorVersion != GLX_MAJOR_VERSION) {
311 ** The server does not support the same major release as this
316 *major = reply.majorVersion;
317 *minor = min(reply.minorVersion, GLX_MINOR_VERSION);
323 * We don't want to enable this GLX_OML_swap_method in glxext.h,
324 * because we can't support it. The X server writes it out though,
325 * so we should handle it somehow, to avoid false warnings.
328 IGNORE_GLX_SWAP_METHOD_OML = 0x8060
333 convert_from_x_visual_type(int visualType)
335 static const int glx_visual_types[] = {
336 GLX_STATIC_GRAY, GLX_GRAY_SCALE,
337 GLX_STATIC_COLOR, GLX_PSEUDO_COLOR,
338 GLX_TRUE_COLOR, GLX_DIRECT_COLOR
341 if (visualType < ARRAY_SIZE(glx_visual_types))
342 return glx_visual_types[visualType];
348 * getVisualConfigs uses the !tagged_only path.
349 * getFBConfigs uses the tagged_only path.
352 __glXInitializeVisualConfigFromTags(struct glx_config * config, int count,
353 const INT32 * bp, Bool tagged_only,
354 Bool fbconfig_style_tags)
359 /* Copy in the first set of properties */
360 config->visualID = *bp++;
362 config->visualType = convert_from_x_visual_type(*bp++);
364 config->rgbMode = *bp++;
366 config->redBits = *bp++;
367 config->greenBits = *bp++;
368 config->blueBits = *bp++;
369 config->alphaBits = *bp++;
370 config->accumRedBits = *bp++;
371 config->accumGreenBits = *bp++;
372 config->accumBlueBits = *bp++;
373 config->accumAlphaBits = *bp++;
375 config->doubleBufferMode = *bp++;
376 config->stereoMode = *bp++;
378 config->rgbBits = *bp++;
379 config->depthBits = *bp++;
380 config->stencilBits = *bp++;
381 config->numAuxBuffers = *bp++;
382 config->level = *bp++;
384 #ifdef GLX_USE_APPLEGL
385 /* AppleSGLX supports pixmap and pbuffers with all config. */
386 config->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
387 /* Unfortunately this can create an ABI compatibility problem. */
390 count -= __GLX_MIN_CONFIG_PROPS;
395 ** Additional properties may be in a list at the end
396 ** of the reply. They are in pairs of property type
397 ** and property value.
400 #define FETCH_OR_SET(tag) \
401 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
403 for (i = 0; i < count; i += 2) {
404 long int tag = *bp++;
408 FETCH_OR_SET(rgbMode);
410 case GLX_BUFFER_SIZE:
411 config->rgbBits = *bp++;
414 config->level = *bp++;
416 case GLX_DOUBLEBUFFER:
417 FETCH_OR_SET(doubleBufferMode);
420 FETCH_OR_SET(stereoMode);
422 case GLX_AUX_BUFFERS:
423 config->numAuxBuffers = *bp++;
426 config->redBits = *bp++;
429 config->greenBits = *bp++;
432 config->blueBits = *bp++;
435 config->alphaBits = *bp++;
438 config->depthBits = *bp++;
440 case GLX_STENCIL_SIZE:
441 config->stencilBits = *bp++;
443 case GLX_ACCUM_RED_SIZE:
444 config->accumRedBits = *bp++;
446 case GLX_ACCUM_GREEN_SIZE:
447 config->accumGreenBits = *bp++;
449 case GLX_ACCUM_BLUE_SIZE:
450 config->accumBlueBits = *bp++;
452 case GLX_ACCUM_ALPHA_SIZE:
453 config->accumAlphaBits = *bp++;
455 case GLX_VISUAL_CAVEAT_EXT:
456 config->visualRating = *bp++;
458 case GLX_X_VISUAL_TYPE:
459 config->visualType = *bp++;
461 case GLX_TRANSPARENT_TYPE:
462 config->transparentPixel = *bp++;
464 case GLX_TRANSPARENT_INDEX_VALUE:
465 config->transparentIndex = *bp++;
467 case GLX_TRANSPARENT_RED_VALUE:
468 config->transparentRed = *bp++;
470 case GLX_TRANSPARENT_GREEN_VALUE:
471 config->transparentGreen = *bp++;
473 case GLX_TRANSPARENT_BLUE_VALUE:
474 config->transparentBlue = *bp++;
476 case GLX_TRANSPARENT_ALPHA_VALUE:
477 config->transparentAlpha = *bp++;
480 config->visualID = *bp++;
482 case GLX_DRAWABLE_TYPE:
483 config->drawableType = *bp++;
484 #ifdef GLX_USE_APPLEGL
485 /* AppleSGLX supports pixmap and pbuffers with all config. */
486 config->drawableType |= GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
489 case GLX_RENDER_TYPE:
490 config->renderType = *bp++;
492 case GLX_X_RENDERABLE:
493 config->xRenderable = *bp++;
495 case GLX_FBCONFIG_ID:
496 config->fbconfigID = *bp++;
498 case GLX_MAX_PBUFFER_WIDTH:
499 config->maxPbufferWidth = *bp++;
501 case GLX_MAX_PBUFFER_HEIGHT:
502 config->maxPbufferHeight = *bp++;
504 case GLX_MAX_PBUFFER_PIXELS:
505 config->maxPbufferPixels = *bp++;
507 #ifndef GLX_USE_APPLEGL
508 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX:
509 config->optimalPbufferWidth = *bp++;
511 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX:
512 config->optimalPbufferHeight = *bp++;
514 case GLX_VISUAL_SELECT_GROUP_SGIX:
515 config->visualSelectGroup = *bp++;
517 case GLX_SWAP_METHOD_OML:
518 config->swapMethod = *bp++;
521 case GLX_SAMPLE_BUFFERS_SGIS:
522 config->sampleBuffers = *bp++;
524 case GLX_SAMPLES_SGIS:
525 config->samples = *bp++;
527 #ifdef GLX_USE_APPLEGL
528 case IGNORE_GLX_SWAP_METHOD_OML:
529 /* We ignore this tag. See the comment above this function. */
533 case GLX_BIND_TO_TEXTURE_RGB_EXT:
534 config->bindToTextureRgb = *bp++;
536 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
537 config->bindToTextureRgba = *bp++;
539 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
540 config->bindToMipmapTexture = *bp++;
542 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
543 config->bindToTextureTargets = *bp++;
545 case GLX_Y_INVERTED_EXT:
546 config->yInverted = *bp++;
550 if (fbconfig_style_tags)
557 if(getenv("LIBGL_DIAGNOSTIC")) {
558 long int tagvalue = *bp++;
559 fprintf(stderr, "WARNING: unknown GLX tag from server: "
560 "tag 0x%lx value 0x%lx\n", tag, tagvalue);
562 /* Ignore the unrecognized tag's value */
570 (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
573 static struct glx_config *
574 createConfigsFromProperties(Display * dpy, int nvisuals, int nprops,
575 int screen, GLboolean tagged_only)
577 INT32 buf[__GLX_TOTAL_CONFIG], *props;
579 struct glx_config *modes, *m;
585 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
587 /* Check number of properties */
588 if (nprops < __GLX_MIN_CONFIG_PROPS || nprops > __GLX_MAX_CONFIG_PROPS)
591 /* Allocate memory for our config structure */
592 modes = glx_config_create_list(nvisuals);
596 prop_size = nprops * __GLX_SIZE_INT32;
597 if (prop_size <= sizeof(buf))
600 props = Xmalloc(prop_size);
602 /* Read each config structure and convert it into our format */
604 for (i = 0; i < nvisuals; i++) {
605 _XRead(dpy, (char *) props, prop_size);
606 #ifdef GLX_USE_APPLEGL
607 /* Older X servers don't send this so we default it here. */
608 m->drawableType = GLX_WINDOW_BIT;
611 * The XQuartz 2.3.2.1 X server doesn't set this properly, so
612 * set the proper bits here.
613 * AppleSGLX supports windows, pixmaps, and pbuffers with all config.
615 m->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
617 __glXInitializeVisualConfigFromTags(m, nprops, props,
618 tagged_only, GL_TRUE);
630 getVisualConfigs(struct glx_screen *psc,
631 struct glx_display *priv, int screen)
633 xGLXGetVisualConfigsReq *req;
634 xGLXGetVisualConfigsReply reply;
635 Display *dpy = priv->dpy;
640 GetReq(GLXGetVisualConfigs, req);
641 req->reqType = priv->majorOpcode;
642 req->glxCode = X_GLXGetVisualConfigs;
643 req->screen = screen;
645 if (!_XReply(dpy, (xReply *) & reply, 0, False))
648 psc->visuals = createConfigsFromProperties(dpy,
655 return psc->visuals != NULL;
659 getFBConfigs(struct glx_screen *psc, struct glx_display *priv, int screen)
661 xGLXGetFBConfigsReq *fb_req;
662 xGLXGetFBConfigsSGIXReq *sgi_req;
663 xGLXVendorPrivateWithReplyReq *vpreq;
664 xGLXGetFBConfigsReply reply;
665 Display *dpy = priv->dpy;
668 __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS);
673 if (atof(priv->serverGLXversion) >= 1.3) {
674 GetReq(GLXGetFBConfigs, fb_req);
675 fb_req->reqType = priv->majorOpcode;
676 fb_req->glxCode = X_GLXGetFBConfigs;
677 fb_req->screen = screen;
679 else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) {
680 GetReqExtra(GLXVendorPrivateWithReply,
681 sz_xGLXGetFBConfigsSGIXReq -
682 sz_xGLXVendorPrivateWithReplyReq, vpreq);
683 sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq;
684 sgi_req->reqType = priv->majorOpcode;
685 sgi_req->glxCode = X_GLXVendorPrivateWithReply;
686 sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX;
687 sgi_req->screen = screen;
692 if (!_XReply(dpy, (xReply *) & reply, 0, False))
695 psc->configs = createConfigsFromProperties(dpy,
697 reply.numAttribs * 2,
702 return psc->configs != NULL;
706 glx_screen_init(struct glx_screen *psc,
707 int screen, struct glx_display * priv)
709 /* Initialize per screen dynamic client GLX extensions */
710 psc->ext_list_first_time = GL_TRUE;
712 psc->dpy = priv->dpy;
715 getVisualConfigs(psc, priv, screen);
716 getFBConfigs(psc, priv, screen);
722 glx_screen_cleanup(struct glx_screen *psc)
725 glx_config_destroy_list(psc->configs);
726 if (psc->effectiveGLXexts)
727 Xfree(psc->effectiveGLXexts);
728 psc->configs = NULL; /* NOTE: just for paranoia */
731 glx_config_destroy_list(psc->visuals);
732 psc->visuals = NULL; /* NOTE: just for paranoia */
734 Xfree((char *) psc->serverGLXexts);
738 ** Allocate the memory for the per screen configs for each screen.
739 ** If that works then fetch the per screen configs data.
742 AllocAndFetchScreenConfigs(Display * dpy, struct glx_display * priv)
744 struct glx_screen *psc;
748 ** First allocate memory for the array of per screen configs.
750 screens = ScreenCount(dpy);
751 priv->screens = Xmalloc(screens * sizeof *priv->screens);
755 priv->serverGLXversion =
756 __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION);
757 if (priv->serverGLXversion == NULL) {
758 FreeScreenConfigs(priv);
762 for (i = 0; i < screens; i++, psc++) {
764 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
765 if (priv->dri2Display)
766 psc = (*priv->dri2Display->createScreen) (i, priv);
767 if (psc == NULL && priv->driDisplay)
768 psc = (*priv->driDisplay->createScreen) (i, priv);
769 if (psc == NULL && priv->driswDisplay)
770 psc = (*priv->driswDisplay->createScreen) (i, priv);
772 #if defined(GLX_USE_APPLEGL)
773 if (psc == NULL && priv->appleglDisplay)
774 psc = (*priv->appleglDisplay->createScreen) (i, priv);
777 psc = indirect_create_screen(i, priv);
778 priv->screens[i] = psc;
785 ** Initialize the client side extension code.
787 _X_HIDDEN struct glx_display *
788 __glXInitialize(Display * dpy)
790 struct glx_display *dpyPriv, *d;
791 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
792 Bool glx_direct, glx_accel;
796 _XLockMutex(_Xglobal_lock);
798 for (dpyPriv = glx_displays; dpyPriv; dpyPriv = dpyPriv->next) {
799 if (dpyPriv->dpy == dpy) {
800 _XUnlockMutex(_Xglobal_lock);
805 /* Drop the lock while we create the display private. */
806 _XUnlockMutex(_Xglobal_lock);
808 dpyPriv = Xcalloc(1, sizeof *dpyPriv);
812 dpyPriv->codes = XInitExtension(dpy, __glXExtensionName);
813 if (!dpyPriv->codes) {
815 _XUnlockMutex(_Xglobal_lock);
820 dpyPriv->majorOpcode = dpyPriv->codes->major_opcode;
821 dpyPriv->serverGLXvendor = 0x0;
822 dpyPriv->serverGLXversion = 0x0;
824 /* See if the versions are compatible */
825 if (!QueryVersion(dpy, dpyPriv->majorOpcode,
826 &dpyPriv->majorVersion, &dpyPriv->minorVersion)) {
828 _XUnlockMutex(_Xglobal_lock);
832 for (i = 0; i < __GLX_NUMBER_EVENTS; i++) {
833 XESetWireToEvent(dpy, dpyPriv->codes->first_event + i, __glXWireToEvent);
834 XESetEventToWire(dpy, dpyPriv->codes->first_event + i, __glXEventToWire);
837 XESetCloseDisplay(dpy, dpyPriv->codes->extension, __glXCloseDisplay);
838 XESetErrorString (dpy, dpyPriv->codes->extension,__glXErrorString);
840 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
841 glx_direct = (getenv("LIBGL_ALWAYS_INDIRECT") == NULL);
842 glx_accel = (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL);
844 dpyPriv->drawHash = __glxHashCreate();
847 ** Initialize the direct rendering per display data and functions.
848 ** Note: This _must_ be done before calling any other DRI routines
849 ** (e.g., those called in AllocAndFetchScreenConfigs).
851 if (glx_direct && glx_accel) {
852 dpyPriv->dri2Display = dri2CreateDisplay(dpy);
853 dpyPriv->driDisplay = driCreateDisplay(dpy);
856 dpyPriv->driswDisplay = driswCreateDisplay(dpy);
859 #ifdef GLX_USE_APPLEGL
860 if (!applegl_create_display(dpyPriv)) {
865 if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) {
870 if (dpyPriv->majorVersion == 1 && dpyPriv->minorVersion >= 1)
871 __glXClientInfo(dpy, dpyPriv->majorOpcode);
873 /* Grab the lock again and add the dispay private, unless somebody
874 * beat us to initializing on this display in the meantime. */
875 _XLockMutex(_Xglobal_lock);
877 for (d = glx_displays; d; d = d->next) {
879 _XUnlockMutex(_Xglobal_lock);
880 glx_display_free(dpyPriv);
885 dpyPriv->next = glx_displays;
886 glx_displays = dpyPriv;
888 _XUnlockMutex(_Xglobal_lock);
894 ** Setup for sending a GLX command on dpy. Make sure the extension is
895 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
898 __glXSetupForCommand(Display * dpy)
900 struct glx_context *gc;
901 struct glx_display *priv;
903 /* If this thread has a current context, flush its rendering commands */
904 gc = __glXGetCurrentContext();
905 if (gc->currentDpy) {
906 /* Flush rendering buffer of the current context, if any */
907 (void) __glXFlushRenderBuffer(gc, gc->pc);
909 if (gc->currentDpy == dpy) {
910 /* Use opcode from gc because its right */
911 return gc->majorOpcode;
915 ** Have to get info about argument dpy because it might be to
916 ** a different server
921 /* Forced to lookup extension via the slow initialize route */
922 priv = __glXInitialize(dpy);
926 return priv->majorOpcode;
930 * Flush the drawing command transport buffer.
932 * \param ctx Context whose transport buffer is to be flushed.
933 * \param pc Pointer to first unused buffer location.
936 * Modify this function to use \c ctx->pc instead of the explicit
940 __glXFlushRenderBuffer(struct glx_context * ctx, GLubyte * pc)
942 Display *const dpy = ctx->currentDpy;
944 xcb_connection_t *c = XGetXCBConnection(dpy);
948 const GLint size = pc - ctx->buf;
950 if ((dpy != NULL) && (size > 0)) {
952 xcb_glx_render(c, ctx->currentContextTag, size,
953 (const uint8_t *) ctx->buf);
955 /* Send the entire buffer as an X request */
957 GetReq(GLXRender, req);
958 req->reqType = ctx->majorOpcode;
959 req->glxCode = X_GLXRender;
960 req->contextTag = ctx->currentContextTag;
961 req->length += (size + 3) >> 2;
962 _XSend(dpy, (char *) ctx->buf, size);
968 /* Reset pointer and return it */
975 * Send a portion of a GLXRenderLarge command to the server. The advantage of
976 * this function over \c __glXSendLargeCommand is that callers can use the
977 * data buffer in the GLX context and may be able to avoid allocating an
978 * extra buffer. The disadvantage is the clients will have to do more
979 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
981 * \sa __glXSendLargeCommand
983 * \param gc GLX context
984 * \param requestNumber Which part of the whole command is this? The first
986 * \param totalRequests How many requests will there be?
987 * \param data Command data.
988 * \param dataLen Size, in bytes, of the command data.
991 __glXSendLargeChunk(struct glx_context * gc, GLint requestNumber,
992 GLint totalRequests, const GLvoid * data, GLint dataLen)
994 Display *dpy = gc->currentDpy;
996 xcb_connection_t *c = XGetXCBConnection(dpy);
997 xcb_glx_render_large(c, gc->currentContextTag, requestNumber,
998 totalRequests, dataLen, data);
1000 xGLXRenderLargeReq *req;
1002 if (requestNumber == 1) {
1006 GetReq(GLXRenderLarge, req);
1007 req->reqType = gc->majorOpcode;
1008 req->glxCode = X_GLXRenderLarge;
1009 req->contextTag = gc->currentContextTag;
1010 req->length += (dataLen + 3) >> 2;
1011 req->requestNumber = requestNumber;
1012 req->requestTotal = totalRequests;
1013 req->dataBytes = dataLen;
1014 Data(dpy, data, dataLen);
1016 if (requestNumber == totalRequests) {
1020 #endif /* USE_XCB */
1025 * Send a command that is too large for the GLXRender protocol request.
1027 * Send a large command, one that is too large for some reason to
1028 * send using the GLXRender protocol request. One reason to send
1029 * a large command is to avoid copying the data.
1031 * \param ctx GLX context
1032 * \param header Header data.
1033 * \param headerLen Size, in bytes, of the header data. It is assumed that
1034 * the header data will always be small enough to fit in
1035 * a single X protocol packet.
1036 * \param data Command data.
1037 * \param dataLen Size, in bytes, of the command data.
1040 __glXSendLargeCommand(struct glx_context * ctx,
1041 const GLvoid * header, GLint headerLen,
1042 const GLvoid * data, GLint dataLen)
1045 GLint totalRequests, requestNumber;
1048 ** Calculate the maximum amount of data can be stuffed into a single
1049 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1050 ** packet size minus sz_xGLXRenderReq.
1052 maxSize = (ctx->bufSize + sz_xGLXRenderReq) - sz_xGLXRenderLargeReq;
1053 totalRequests = 1 + (dataLen / maxSize);
1054 if (dataLen % maxSize)
1058 ** Send all of the command, except the large array, as one request.
1060 assert(headerLen <= maxSize);
1061 __glXSendLargeChunk(ctx, 1, totalRequests, header, headerLen);
1064 ** Send enough requests until the whole array is sent.
1066 for (requestNumber = 2; requestNumber <= (totalRequests - 1);
1068 __glXSendLargeChunk(ctx, requestNumber, totalRequests, data, maxSize);
1069 data = (const GLvoid *) (((const GLubyte *) data) + maxSize);
1071 assert(dataLen > 0);
1074 assert(dataLen <= maxSize);
1075 __glXSendLargeChunk(ctx, requestNumber, totalRequests, data, dataLen);
1078 /************************************************************************/
1082 __glXDumpDrawBuffer(struct glx_context * ctx)
1084 GLubyte *p = ctx->buf;
1085 GLubyte *end = ctx->pc;
1086 GLushort opcode, length;
1090 opcode = *((GLushort *) p);
1091 length = *((GLushort *) (p + 2));
1092 printf("%2x: %5d: ", opcode, length);
1095 while (length > 0) {
1096 printf("%08x ", *((unsigned *) p));