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 #include <X11/extensions/dri2proto.h>
45 #ifdef GLX_USE_APPLEGL
46 #include "apple_glx.h"
47 #include "apple_visual.h"
49 #include "glxextensions.h"
50 #include "glcontextmodes.h"
53 #include <X11/Xlib-xcb.h>
60 void __glXDumpDrawBuffer(__GLXcontext * ctx);
64 ** You can set this cell to 1 to force the gl drawing stuff to be
65 ** one command per packet
67 _X_HIDDEN int __glXDebug = 0;
69 /* Extension required boiler plate */
71 static const char __glXExtensionName[] = GLX_EXTENSION_NAME;
72 static __GLXdisplayPrivate *glx_displays;
74 static /* const */ char *error_list[] = {
80 "GLXBadCurrentWindow",
81 "GLXBadRenderRequest",
83 "GLXUnsupportedPrivateRequest",
86 "GLXBadCurrentDrawable",
90 #ifdef GLX_USE_APPLEGL
91 static char *__glXErrorString(Display *dpy, int code, XExtCodes *codes,
96 XEXT_GENERATE_ERROR_STRING(__glXErrorString, __glXExtensionName,
97 __GLX_NUMBER_ERRORS, error_list)
100 __glXCloseDisplay(Display * dpy, XExtCodes * codes);
102 __glXWireToEvent(Display *dpy, XEvent *event, xEvent *wire);
104 __glXEventToWire(Display *dpy, XEvent *event, xEvent *wire);
107 * GLX events are a bit funky. We don't stuff the X event code into
108 * our user exposed (via XNextEvent) structure. Instead we use the GLX
109 * private event code namespace (and hope it doesn't conflict). Clients
110 * have to know that bit 15 in the event type field means they're getting
111 * a GLX event, and then handle the various sub-event types there, rather
112 * than simply checking the event code and handling it directly.
116 __glXWireToEvent(Display *dpy, XEvent *event, xEvent *wire)
118 __GLXdisplayPrivate *glx_dpy = __glXInitialize(dpy);
123 switch ((wire->u.u.type & 0x7f) - glx_dpy->codes->first_event) {
124 case GLX_PbufferClobber:
126 GLXPbufferClobberEvent *aevent = (GLXPbufferClobberEvent *)event;
127 xGLXPbufferClobberEvent *awire = (xGLXPbufferClobberEvent *)wire;
128 aevent->event_type = awire->type;
129 aevent->serial = awire->sequenceNumber;
130 aevent->event_type = awire->event_type;
131 aevent->draw_type = awire->draw_type;
132 aevent->drawable = awire->drawable;
133 aevent->buffer_mask = awire->buffer_mask;
134 aevent->aux_buffer = awire->aux_buffer;
135 aevent->x = awire->x;
136 aevent->y = awire->y;
137 aevent->width = awire->width;
138 aevent->height = awire->height;
139 aevent->count = awire->count;
142 /* No easy symbol to test for this, as GLX_BufferSwapComplete is
143 * defined in the local glx.h header, but the
144 * xGLXBufferSwapComplete typedef is only available in new versions
145 * of the external glxproto.h header, which doesn't have any
146 * testable versioning define.
148 * I'll use the related DRI2 define, in the hope that we won't
149 * receive these events unless we know how to ask for them:
151 #ifdef X_DRI2SwapBuffers
152 case GLX_BufferSwapComplete:
154 GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event;
155 xGLXBufferSwapComplete *awire = (xGLXBufferSwapComplete *)wire;
156 aevent->event_type = awire->event_type;
157 aevent->drawable = awire->drawable;
158 aevent->ust = ((CARD64)awire->ust_hi << 32) | awire->ust_lo;
159 aevent->msc = ((CARD64)awire->msc_hi << 32) | awire->msc_lo;
160 aevent->sbc = ((CARD64)awire->sbc_hi << 32) | awire->sbc_lo;
165 /* client doesn't support server event */
172 /* We don't actually support this. It doesn't make sense for clients to
173 * send each other GLX events.
176 __glXEventToWire(Display *dpy, XEvent *event, xEvent *wire)
178 __GLXdisplayPrivate *glx_dpy = __glXInitialize(dpy);
183 switch (event->type) {
188 case GLX_EXCHANGE_COMPLETE_INTEL:
190 case GLX_COPY_COMPLETE_INTEL:
192 case GLX_FLIP_COMPLETE_INTEL:
195 /* client doesn't support server event */
202 /************************************************************************/
204 ** Free the per screen configs data as well as the array of
205 ** __glXScreenConfigs.
208 FreeScreenConfigs(__GLXdisplayPrivate * priv)
210 __GLXscreenConfigs *psc;
213 /* Free screen configuration information */
214 screens = ScreenCount(priv->dpy);
215 for (i = 0; i < screens; i++) {
216 psc = priv->screenConfigs[i];
218 _gl_context_modes_destroy(psc->configs);
219 if (psc->effectiveGLXexts)
220 Xfree(psc->effectiveGLXexts);
221 psc->configs = NULL; /* NOTE: just for paranoia */
224 _gl_context_modes_destroy(psc->visuals);
225 psc->visuals = NULL; /* NOTE: just for paranoia */
227 Xfree((char *) psc->serverGLXexts);
229 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
230 if (psc->driScreen) {
231 psc->driScreen->destroyScreen(psc);
232 psc->driScreen = NULL;
240 XFree((char *) priv->screenConfigs);
241 priv->screenConfigs = NULL;
245 ** Release the private memory referred to in a display private
246 ** structure. The caller will free the extension structure.
249 __glXCloseDisplay(Display * dpy, XExtCodes * codes)
251 __GLXdisplayPrivate *priv, **prev;
254 _XLockMutex(_Xglobal_lock);
255 prev = &glx_displays;
256 for (priv = glx_displays; priv; prev = &priv->next, priv = priv->next) {
257 if (priv->dpy == dpy) {
258 (*prev)->next = priv->next;
262 _XUnlockMutex(_Xglobal_lock);
264 gc = __glXGetCurrentContext();
265 if (dpy == gc->currentDpy) {
266 gc->vtable->destroy(gc);
267 __glXSetCurrentContextNull();
270 FreeScreenConfigs(priv);
271 if (priv->serverGLXvendor)
272 Xfree((char *) priv->serverGLXvendor);
273 if (priv->serverGLXversion)
274 Xfree((char *) priv->serverGLXversion);
276 __glxHashDestroy(priv->drawHash);
278 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
279 /* Free the direct rendering per display data */
280 if (priv->driswDisplay)
281 (*priv->driswDisplay->destroyDisplay) (priv->driswDisplay);
282 priv->driswDisplay = NULL;
284 if (priv->driDisplay)
285 (*priv->driDisplay->destroyDisplay) (priv->driDisplay);
286 priv->driDisplay = NULL;
288 if (priv->dri2Display)
289 (*priv->dri2Display->destroyDisplay) (priv->dri2Display);
290 priv->dri2Display = NULL;
293 Xfree((char *) priv);
299 ** Query the version of the GLX extension. This procedure works even if
300 ** the client extension is not completely set up.
303 QueryVersion(Display * dpy, int opcode, int *major, int *minor)
306 xcb_connection_t *c = XGetXCBConnection(dpy);
307 xcb_glx_query_version_reply_t *reply = xcb_glx_query_version_reply(c,
308 xcb_glx_query_version
314 if (reply->major_version != GLX_MAJOR_VERSION) {
318 *major = reply->major_version;
319 *minor = min(reply->minor_version, GLX_MINOR_VERSION);
323 xGLXQueryVersionReq *req;
324 xGLXQueryVersionReply reply;
326 /* Send the glXQueryVersion request */
328 GetReq(GLXQueryVersion, req);
329 req->reqType = opcode;
330 req->glxCode = X_GLXQueryVersion;
331 req->majorVersion = GLX_MAJOR_VERSION;
332 req->minorVersion = GLX_MINOR_VERSION;
333 _XReply(dpy, (xReply *) & reply, 0, False);
337 if (reply.majorVersion != GLX_MAJOR_VERSION) {
339 ** The server does not support the same major release as this
344 *major = reply.majorVersion;
345 *minor = min(reply.minorVersion, GLX_MINOR_VERSION);
351 * We don't want to enable this GLX_OML_swap_method in glxext.h,
352 * because we can't support it. The X server writes it out though,
353 * so we should handle it somehow, to avoid false warnings.
356 IGNORE_GLX_SWAP_METHOD_OML = 0x8060
361 * getVisualConfigs uses the !tagged_only path.
362 * getFBConfigs uses the tagged_only path.
365 __glXInitializeVisualConfigFromTags(__GLcontextModes * config, int count,
366 const INT32 * bp, Bool tagged_only,
367 Bool fbconfig_style_tags)
372 /* Copy in the first set of properties */
373 config->visualID = *bp++;
375 config->visualType = _gl_convert_from_x_visual_type(*bp++);
377 config->rgbMode = *bp++;
379 config->redBits = *bp++;
380 config->greenBits = *bp++;
381 config->blueBits = *bp++;
382 config->alphaBits = *bp++;
383 config->accumRedBits = *bp++;
384 config->accumGreenBits = *bp++;
385 config->accumBlueBits = *bp++;
386 config->accumAlphaBits = *bp++;
388 config->doubleBufferMode = *bp++;
389 config->stereoMode = *bp++;
391 config->rgbBits = *bp++;
392 config->depthBits = *bp++;
393 config->stencilBits = *bp++;
394 config->numAuxBuffers = *bp++;
395 config->level = *bp++;
397 #ifdef GLX_USE_APPLEGL
398 /* AppleSGLX supports pixmap and pbuffers with all config. */
399 config->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
400 /* Unfortunately this can create an ABI compatibility problem. */
403 count -= __GLX_MIN_CONFIG_PROPS;
408 ** Additional properties may be in a list at the end
409 ** of the reply. They are in pairs of property type
410 ** and property value.
413 #define FETCH_OR_SET(tag) \
414 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
416 for (i = 0; i < count; i += 2) {
417 long int tag = *bp++;
421 FETCH_OR_SET(rgbMode);
423 case GLX_BUFFER_SIZE:
424 config->rgbBits = *bp++;
427 config->level = *bp++;
429 case GLX_DOUBLEBUFFER:
430 FETCH_OR_SET(doubleBufferMode);
433 FETCH_OR_SET(stereoMode);
435 case GLX_AUX_BUFFERS:
436 config->numAuxBuffers = *bp++;
439 config->redBits = *bp++;
442 config->greenBits = *bp++;
445 config->blueBits = *bp++;
448 config->alphaBits = *bp++;
451 config->depthBits = *bp++;
453 case GLX_STENCIL_SIZE:
454 config->stencilBits = *bp++;
456 case GLX_ACCUM_RED_SIZE:
457 config->accumRedBits = *bp++;
459 case GLX_ACCUM_GREEN_SIZE:
460 config->accumGreenBits = *bp++;
462 case GLX_ACCUM_BLUE_SIZE:
463 config->accumBlueBits = *bp++;
465 case GLX_ACCUM_ALPHA_SIZE:
466 config->accumAlphaBits = *bp++;
468 case GLX_VISUAL_CAVEAT_EXT:
469 config->visualRating = *bp++;
471 case GLX_X_VISUAL_TYPE:
472 config->visualType = *bp++;
474 case GLX_TRANSPARENT_TYPE:
475 config->transparentPixel = *bp++;
477 case GLX_TRANSPARENT_INDEX_VALUE:
478 config->transparentIndex = *bp++;
480 case GLX_TRANSPARENT_RED_VALUE:
481 config->transparentRed = *bp++;
483 case GLX_TRANSPARENT_GREEN_VALUE:
484 config->transparentGreen = *bp++;
486 case GLX_TRANSPARENT_BLUE_VALUE:
487 config->transparentBlue = *bp++;
489 case GLX_TRANSPARENT_ALPHA_VALUE:
490 config->transparentAlpha = *bp++;
493 config->visualID = *bp++;
495 case GLX_DRAWABLE_TYPE:
496 config->drawableType = *bp++;
497 #ifdef GLX_USE_APPLEGL
498 /* AppleSGLX supports pixmap and pbuffers with all config. */
499 config->drawableType |= GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
502 case GLX_RENDER_TYPE:
503 config->renderType = *bp++;
505 case GLX_X_RENDERABLE:
506 config->xRenderable = *bp++;
508 case GLX_FBCONFIG_ID:
509 config->fbconfigID = *bp++;
511 case GLX_MAX_PBUFFER_WIDTH:
512 config->maxPbufferWidth = *bp++;
514 case GLX_MAX_PBUFFER_HEIGHT:
515 config->maxPbufferHeight = *bp++;
517 case GLX_MAX_PBUFFER_PIXELS:
518 config->maxPbufferPixels = *bp++;
520 #ifndef GLX_USE_APPLEGL
521 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX:
522 config->optimalPbufferWidth = *bp++;
524 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX:
525 config->optimalPbufferHeight = *bp++;
527 case GLX_VISUAL_SELECT_GROUP_SGIX:
528 config->visualSelectGroup = *bp++;
530 case GLX_SWAP_METHOD_OML:
531 config->swapMethod = *bp++;
534 case GLX_SAMPLE_BUFFERS_SGIS:
535 config->sampleBuffers = *bp++;
537 case GLX_SAMPLES_SGIS:
538 config->samples = *bp++;
540 #ifdef GLX_USE_APPLEGL
541 case IGNORE_GLX_SWAP_METHOD_OML:
542 /* We ignore this tag. See the comment above this function. */
546 case GLX_BIND_TO_TEXTURE_RGB_EXT:
547 config->bindToTextureRgb = *bp++;
549 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
550 config->bindToTextureRgba = *bp++;
552 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
553 config->bindToMipmapTexture = *bp++;
555 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
556 config->bindToTextureTargets = *bp++;
558 case GLX_Y_INVERTED_EXT:
559 config->yInverted = *bp++;
563 if (fbconfig_style_tags)
570 if(getenv("LIBGL_DIAGNOSTIC")) {
571 long int tagvalue = *bp++;
572 fprintf(stderr, "WARNING: unknown GLX tag from server: "
573 "tag 0x%lx value 0x%lx\n", tag, tagvalue);
575 /* Ignore the unrecognized tag's value */
583 (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
585 config->haveAccumBuffer = ((config->accumRedBits +
586 config->accumGreenBits +
587 config->accumBlueBits +
588 config->accumAlphaBits) > 0);
589 config->haveDepthBuffer = (config->depthBits > 0);
590 config->haveStencilBuffer = (config->stencilBits > 0);
593 static __GLcontextModes *
594 createConfigsFromProperties(Display * dpy, int nvisuals, int nprops,
595 int screen, GLboolean tagged_only)
597 INT32 buf[__GLX_TOTAL_CONFIG], *props;
599 __GLcontextModes *modes, *m;
605 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
607 /* Check number of properties */
608 if (nprops < __GLX_MIN_CONFIG_PROPS || nprops > __GLX_MAX_CONFIG_PROPS)
611 /* Allocate memory for our config structure */
612 modes = _gl_context_modes_create(nvisuals, sizeof(__GLcontextModes));
616 prop_size = nprops * __GLX_SIZE_INT32;
617 if (prop_size <= sizeof(buf))
620 props = Xmalloc(prop_size);
622 /* Read each config structure and convert it into our format */
624 for (i = 0; i < nvisuals; i++) {
625 _XRead(dpy, (char *) props, prop_size);
626 #ifdef GLX_USE_APPLEGL
627 /* Older X servers don't send this so we default it here. */
628 m->drawableType = GLX_WINDOW_BIT;
631 * The XQuartz 2.3.2.1 X server doesn't set this properly, so
632 * set the proper bits here.
633 * AppleSGLX supports windows, pixmaps, and pbuffers with all config.
635 m->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
637 __glXInitializeVisualConfigFromTags(m, nprops, props,
638 tagged_only, GL_TRUE);
650 getVisualConfigs(__GLXscreenConfigs *psc,
651 __GLXdisplayPrivate *priv, int screen)
653 xGLXGetVisualConfigsReq *req;
654 xGLXGetVisualConfigsReply reply;
655 Display *dpy = priv->dpy;
660 GetReq(GLXGetVisualConfigs, req);
661 req->reqType = priv->majorOpcode;
662 req->glxCode = X_GLXGetVisualConfigs;
663 req->screen = screen;
665 if (!_XReply(dpy, (xReply *) & reply, 0, False))
668 psc->visuals = createConfigsFromProperties(dpy,
675 return psc->visuals != NULL;
679 getFBConfigs(__GLXscreenConfigs *psc, __GLXdisplayPrivate *priv, int screen)
681 xGLXGetFBConfigsReq *fb_req;
682 xGLXGetFBConfigsSGIXReq *sgi_req;
683 xGLXVendorPrivateWithReplyReq *vpreq;
684 xGLXGetFBConfigsReply reply;
685 Display *dpy = priv->dpy;
688 __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS);
693 if (atof(priv->serverGLXversion) >= 1.3) {
694 GetReq(GLXGetFBConfigs, fb_req);
695 fb_req->reqType = priv->majorOpcode;
696 fb_req->glxCode = X_GLXGetFBConfigs;
697 fb_req->screen = screen;
699 else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) {
700 GetReqExtra(GLXVendorPrivateWithReply,
701 sz_xGLXGetFBConfigsSGIXReq +
702 sz_xGLXVendorPrivateWithReplyReq, vpreq);
703 sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq;
704 sgi_req->reqType = priv->majorOpcode;
705 sgi_req->glxCode = X_GLXVendorPrivateWithReply;
706 sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX;
707 sgi_req->screen = screen;
712 if (!_XReply(dpy, (xReply *) & reply, 0, False))
715 psc->configs = createConfigsFromProperties(dpy,
717 reply.numAttribs * 2,
722 return psc->configs != NULL;
726 glx_screen_init(__GLXscreenConfigs *psc,
727 int screen, __GLXdisplayPrivate * priv)
729 /* Initialize per screen dynamic client GLX extensions */
730 psc->ext_list_first_time = GL_TRUE;
732 psc->dpy = priv->dpy;
735 getVisualConfigs(psc, priv, screen);
736 getFBConfigs(psc, priv, screen);
742 ** Allocate the memory for the per screen configs for each screen.
743 ** If that works then fetch the per screen configs data.
746 AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv)
748 __GLXscreenConfigs *psc;
752 ** First allocate memory for the array of per screen configs.
754 screens = ScreenCount(dpy);
755 priv->screenConfigs = Xmalloc(screens * sizeof *priv->screenConfigs);
756 if (!priv->screenConfigs)
759 priv->serverGLXversion =
760 __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION);
761 if (priv->serverGLXversion == NULL) {
762 FreeScreenConfigs(priv);
766 for (i = 0; i < screens; i++, psc++) {
768 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
769 if (priv->dri2Display)
770 psc = (*priv->dri2Display->createScreen) (i, priv);
771 if (psc == NULL && priv->driDisplay)
772 psc = (*priv->driDisplay->createScreen) (i, priv);
773 if (psc == NULL && priv->driswDisplay)
774 psc = (*priv->driswDisplay->createScreen) (i, priv);
777 psc = indirect_create_screen(i, priv);
778 priv->screenConfigs[i] = psc;
785 ** Initialize the client side extension code.
787 _X_HIDDEN __GLXdisplayPrivate *
788 __glXInitialize(Display * dpy)
790 __GLXdisplayPrivate *dpyPriv;
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 dpyPriv = Xcalloc(1, sizeof *dpyPriv);
809 dpyPriv->codes = XInitExtension(dpy, __glXExtensionName);
810 if (!dpyPriv->codes) {
812 _XUnlockMutex(_Xglobal_lock);
817 dpyPriv->majorOpcode = dpyPriv->codes->major_opcode;
818 dpyPriv->serverGLXvendor = 0x0;
819 dpyPriv->serverGLXversion = 0x0;
821 /* See if the versions are compatible */
822 if (!QueryVersion(dpy, dpyPriv->majorOpcode,
823 &dpyPriv->majorVersion, &dpyPriv->minorVersion)) {
825 _XUnlockMutex(_Xglobal_lock);
829 for (i = 0; i < __GLX_NUMBER_EVENTS; i++) {
830 XESetWireToEvent(dpy, dpyPriv->codes->first_event + i, __glXWireToEvent);
831 XESetEventToWire(dpy, dpyPriv->codes->first_event + i, __glXEventToWire);
834 XESetCloseDisplay(dpy, dpyPriv->codes->extension, __glXCloseDisplay);
835 XESetErrorString (dpy, dpyPriv->codes->extension,__glXErrorString);
837 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
838 glx_direct = (getenv("LIBGL_ALWAYS_INDIRECT") == NULL);
839 glx_accel = (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL);
841 dpyPriv->drawHash = __glxHashCreate();
844 ** Initialize the direct rendering per display data and functions.
845 ** Note: This _must_ be done before calling any other DRI routines
846 ** (e.g., those called in AllocAndFetchScreenConfigs).
848 if (glx_direct && glx_accel) {
849 dpyPriv->dri2Display = dri2CreateDisplay(dpy);
850 dpyPriv->driDisplay = driCreateDisplay(dpy);
853 dpyPriv->driswDisplay = driswCreateDisplay(dpy);
856 #ifdef GLX_USE_APPLEGL
857 if (apple_init_glx(dpy)) {
862 if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) {
867 if (dpyPriv->majorVersion == 1 && dpyPriv->minorVersion >= 1)
868 __glXClientInfo(dpy, dpyPriv->majorOpcode);
870 dpyPriv->next = glx_displays;
871 glx_displays = dpyPriv;
873 _XUnlockMutex(_Xglobal_lock);
879 ** Setup for sending a GLX command on dpy. Make sure the extension is
880 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
883 __glXSetupForCommand(Display * dpy)
886 __GLXdisplayPrivate *priv;
888 /* If this thread has a current context, flush its rendering commands */
889 gc = __glXGetCurrentContext();
890 if (gc->currentDpy) {
891 /* Flush rendering buffer of the current context, if any */
892 (void) __glXFlushRenderBuffer(gc, gc->pc);
894 if (gc->currentDpy == dpy) {
895 /* Use opcode from gc because its right */
896 return gc->majorOpcode;
900 ** Have to get info about argument dpy because it might be to
901 ** a different server
906 /* Forced to lookup extension via the slow initialize route */
907 priv = __glXInitialize(dpy);
911 return priv->majorOpcode;
915 * Flush the drawing command transport buffer.
917 * \param ctx Context whose transport buffer is to be flushed.
918 * \param pc Pointer to first unused buffer location.
921 * Modify this function to use \c ctx->pc instead of the explicit
925 __glXFlushRenderBuffer(__GLXcontext * ctx, GLubyte * pc)
927 Display *const dpy = ctx->currentDpy;
929 xcb_connection_t *c = XGetXCBConnection(dpy);
933 const GLint size = pc - ctx->buf;
935 if ((dpy != NULL) && (size > 0)) {
937 xcb_glx_render(c, ctx->currentContextTag, size,
938 (const uint8_t *) ctx->buf);
940 /* Send the entire buffer as an X request */
942 GetReq(GLXRender, req);
943 req->reqType = ctx->majorOpcode;
944 req->glxCode = X_GLXRender;
945 req->contextTag = ctx->currentContextTag;
946 req->length += (size + 3) >> 2;
947 _XSend(dpy, (char *) ctx->buf, size);
953 /* Reset pointer and return it */
960 * Send a portion of a GLXRenderLarge command to the server. The advantage of
961 * this function over \c __glXSendLargeCommand is that callers can use the
962 * data buffer in the GLX context and may be able to avoid allocating an
963 * extra buffer. The disadvantage is the clients will have to do more
964 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
966 * \sa __glXSendLargeCommand
968 * \param gc GLX context
969 * \param requestNumber Which part of the whole command is this? The first
971 * \param totalRequests How many requests will there be?
972 * \param data Command data.
973 * \param dataLen Size, in bytes, of the command data.
976 __glXSendLargeChunk(__GLXcontext * gc, GLint requestNumber,
977 GLint totalRequests, const GLvoid * data, GLint dataLen)
979 Display *dpy = gc->currentDpy;
981 xcb_connection_t *c = XGetXCBConnection(dpy);
982 xcb_glx_render_large(c, gc->currentContextTag, requestNumber,
983 totalRequests, dataLen, data);
985 xGLXRenderLargeReq *req;
987 if (requestNumber == 1) {
991 GetReq(GLXRenderLarge, req);
992 req->reqType = gc->majorOpcode;
993 req->glxCode = X_GLXRenderLarge;
994 req->contextTag = gc->currentContextTag;
995 req->length += (dataLen + 3) >> 2;
996 req->requestNumber = requestNumber;
997 req->requestTotal = totalRequests;
998 req->dataBytes = dataLen;
999 Data(dpy, data, dataLen);
1001 if (requestNumber == totalRequests) {
1005 #endif /* USE_XCB */
1010 * Send a command that is too large for the GLXRender protocol request.
1012 * Send a large command, one that is too large for some reason to
1013 * send using the GLXRender protocol request. One reason to send
1014 * a large command is to avoid copying the data.
1016 * \param ctx GLX context
1017 * \param header Header data.
1018 * \param headerLen Size, in bytes, of the header data. It is assumed that
1019 * the header data will always be small enough to fit in
1020 * a single X protocol packet.
1021 * \param data Command data.
1022 * \param dataLen Size, in bytes, of the command data.
1025 __glXSendLargeCommand(__GLXcontext * ctx,
1026 const GLvoid * header, GLint headerLen,
1027 const GLvoid * data, GLint dataLen)
1030 GLint totalRequests, requestNumber;
1033 ** Calculate the maximum amount of data can be stuffed into a single
1034 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1035 ** packet size minus sz_xGLXRenderReq.
1037 maxSize = (ctx->bufSize + sz_xGLXRenderReq) - sz_xGLXRenderLargeReq;
1038 totalRequests = 1 + (dataLen / maxSize);
1039 if (dataLen % maxSize)
1043 ** Send all of the command, except the large array, as one request.
1045 assert(headerLen <= maxSize);
1046 __glXSendLargeChunk(ctx, 1, totalRequests, header, headerLen);
1049 ** Send enough requests until the whole array is sent.
1051 for (requestNumber = 2; requestNumber <= (totalRequests - 1);
1053 __glXSendLargeChunk(ctx, requestNumber, totalRequests, data, maxSize);
1054 data = (const GLvoid *) (((const GLubyte *) data) + maxSize);
1056 assert(dataLen > 0);
1059 assert(dataLen <= maxSize);
1060 __glXSendLargeChunk(ctx, requestNumber, totalRequests, data, dataLen);
1063 /************************************************************************/
1067 __glXDumpDrawBuffer(__GLXcontext * ctx)
1069 GLubyte *p = ctx->buf;
1070 GLubyte *end = ctx->pc;
1071 GLushort opcode, length;
1075 opcode = *((GLushort *) p);
1076 length = *((GLushort *) (p + 2));
1077 printf("%2x: %5d: ", opcode, length);
1080 while (length > 0) {
1081 printf("%08x ", *((unsigned *) p));