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 char *__glXExtensionName
= GLX_EXTENSION_NAME
;
72 #ifdef GLX_USE_APPLEGL
73 static XExtensionInfo __glXExtensionInfo_data
;
74 XExtensionInfo
*__glXExtensionInfo
= &__glXExtensionInfo_data
;
76 XExtensionInfo
*__glXExtensionInfo
= NULL
;
79 static /* const */ char *error_list
[] = {
85 "GLXBadCurrentWindow",
86 "GLXBadRenderRequest",
88 "GLXUnsupportedPrivateRequest",
91 "GLXBadCurrentDrawable",
96 __glXCloseDisplay(Display
* dpy
, XExtCodes
* codes
)
100 gc
= __glXGetCurrentContext();
101 if (dpy
== gc
->currentDpy
) {
102 __glXSetCurrentContextNull();
103 __glXFreeContext(gc
);
106 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
110 #ifdef GLX_USE_APPLEGL
111 static char *__glXErrorString(Display
*dpy
, int code
, XExtCodes
*codes
,
116 XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
117 __GLX_NUMBER_ERRORS
, error_list
)
119 __glXWireToEvent(Display
*dpy
, XEvent
*event
, xEvent
*wire
);
121 __glXEventToWire(Display
*dpy
, XEvent
*event
, xEvent
*wire
);
123 static /* const */ XExtensionHooks __glXExtensionHooks
= {
124 NULL
, /* create_gc */
128 NULL
, /* create_font */
129 NULL
, /* free_font */
130 __glXCloseDisplay
, /* close_display */
131 __glXWireToEvent
, /* wire_to_event */
132 __glXEventToWire
, /* event_to_wire */
134 __glXErrorString
, /* error_string */
137 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
138 __glXExtensionName
, &__glXExtensionHooks
,
139 __GLX_NUMBER_EVENTS
, NULL
)
142 * GLX events are a bit funky. We don't stuff the X event code into
143 * our user exposed (via XNextEvent) structure. Instead we use the GLX
144 * private event code namespace (and hope it doesn't conflict). Clients
145 * have to know that bit 15 in the event type field means they're getting
146 * a GLX event, and then handle the various sub-event types there, rather
147 * than simply checking the event code and handling it directly.
151 __glXWireToEvent(Display
*dpy
, XEvent
*event
, xEvent
*wire
)
153 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
155 XextCheckExtension(dpy
, info
, __glXExtensionName
, False
);
157 switch ((wire
->u
.u
.type
& 0x7f) - info
->codes
->first_event
) {
158 case GLX_PbufferClobber
:
160 GLXPbufferClobberEvent
*aevent
= (GLXPbufferClobberEvent
*)event
;
161 xGLXPbufferClobberEvent
*awire
= (xGLXPbufferClobberEvent
*)wire
;
162 aevent
->event_type
= awire
->type
;
163 aevent
->serial
= awire
->sequenceNumber
;
164 aevent
->event_type
= awire
->event_type
;
165 aevent
->draw_type
= awire
->draw_type
;
166 aevent
->drawable
= awire
->drawable
;
167 aevent
->buffer_mask
= awire
->buffer_mask
;
168 aevent
->aux_buffer
= awire
->aux_buffer
;
169 aevent
->x
= awire
->x
;
170 aevent
->y
= awire
->y
;
171 aevent
->width
= awire
->width
;
172 aevent
->height
= awire
->height
;
173 aevent
->count
= awire
->count
;
176 /* No easy symbol to test for this, as GLX_BufferSwapComplete is
177 * defined in the local glx.h header, but the
178 * xGLXBufferSwapComplete typedef is only available in new versions
179 * of the external glxproto.h header, which doesn't have any
180 * testable versioning define.
182 * I'll use the related DRI2 define, in the hope that we won't
183 * receive these events unless we know how to ask for them:
185 #ifdef X_DRI2SwapBuffers
186 case GLX_BufferSwapComplete
:
188 GLXBufferSwapComplete
*aevent
= (GLXBufferSwapComplete
*)event
;
189 xGLXBufferSwapComplete
*awire
= (xGLXBufferSwapComplete
*)wire
;
190 aevent
->event_type
= awire
->event_type
;
191 aevent
->drawable
= awire
->drawable
;
192 aevent
->ust
= ((CARD64
)awire
->ust_hi
<< 32) | awire
->ust_lo
;
193 aevent
->msc
= ((CARD64
)awire
->msc_hi
<< 32) | awire
->msc_lo
;
194 aevent
->sbc
= ((CARD64
)awire
->sbc_hi
<< 32) | awire
->sbc_lo
;
199 /* client doesn't support server event */
206 /* We don't actually support this. It doesn't make sense for clients to
207 * send each other GLX events.
210 __glXEventToWire(Display
*dpy
, XEvent
*event
, xEvent
*wire
)
212 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
214 XextCheckExtension(dpy
, info
, __glXExtensionName
, False
);
216 switch (event
->type
) {
221 case GLX_EXCHANGE_COMPLETE_INTEL
:
223 case GLX_BLIT_COMPLETE_INTEL
:
225 case GLX_FLIP_COMPLETE_INTEL
:
228 /* client doesn't support server event */
235 /************************************************************************/
237 ** Free the per screen configs data as well as the array of
238 ** __glXScreenConfigs.
241 FreeScreenConfigs(__GLXdisplayPrivate
* priv
)
243 __GLXscreenConfigs
*psc
;
246 /* Free screen configuration information */
247 psc
= priv
->screenConfigs
;
248 screens
= ScreenCount(priv
->dpy
);
249 for (i
= 0; i
< screens
; i
++, psc
++) {
251 _gl_context_modes_destroy(psc
->configs
);
252 if (psc
->effectiveGLXexts
)
253 Xfree(psc
->effectiveGLXexts
);
254 psc
->configs
= NULL
; /* NOTE: just for paranoia */
257 _gl_context_modes_destroy(psc
->visuals
);
258 psc
->visuals
= NULL
; /* NOTE: just for paranoia */
260 Xfree((char *) psc
->serverGLXexts
);
262 #ifdef GLX_DIRECT_RENDERING
263 if (psc
->driver_configs
) {
265 for (j
= 0; psc
->driver_configs
[j
]; j
++)
266 free((__DRIconfig
*) psc
->driver_configs
[j
]);
267 free(psc
->driver_configs
);
268 psc
->driver_configs
= NULL
;
270 if (psc
->driScreen
) {
271 psc
->driScreen
->destroyScreen(psc
);
272 __glxHashDestroy(psc
->drawHash
);
273 XFree(psc
->driScreen
);
274 psc
->driScreen
= NULL
;
278 XFree((char *) priv
->screenConfigs
);
279 priv
->screenConfigs
= NULL
;
283 ** Release the private memory referred to in a display private
284 ** structure. The caller will free the extension structure.
287 __glXFreeDisplayPrivate(XExtData
* extension
)
289 __GLXdisplayPrivate
*priv
;
291 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
292 FreeScreenConfigs(priv
);
293 if (priv
->serverGLXvendor
) {
294 Xfree((char *) priv
->serverGLXvendor
);
295 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
297 if (priv
->serverGLXversion
) {
298 Xfree((char *) priv
->serverGLXversion
);
299 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
302 #ifdef GLX_DIRECT_RENDERING
303 /* Free the direct rendering per display data */
304 if (priv
->driswDisplay
)
305 (*priv
->driswDisplay
->destroyDisplay
) (priv
->driswDisplay
);
306 priv
->driswDisplay
= NULL
;
308 if (priv
->driDisplay
)
309 (*priv
->driDisplay
->destroyDisplay
) (priv
->driDisplay
);
310 priv
->driDisplay
= NULL
;
312 if (priv
->dri2Display
)
313 (*priv
->dri2Display
->destroyDisplay
) (priv
->dri2Display
);
314 priv
->dri2Display
= NULL
;
317 Xfree((char *) priv
);
321 /************************************************************************/
324 ** Query the version of the GLX extension. This procedure works even if
325 ** the client extension is not completely set up.
328 QueryVersion(Display
* dpy
, int opcode
, int *major
, int *minor
)
331 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
332 xcb_glx_query_version_reply_t
*reply
= xcb_glx_query_version_reply(c
,
333 xcb_glx_query_version
339 if (reply
->major_version
!= GLX_MAJOR_VERSION
) {
343 *major
= reply
->major_version
;
344 *minor
= min(reply
->minor_version
, GLX_MINOR_VERSION
);
348 xGLXQueryVersionReq
*req
;
349 xGLXQueryVersionReply reply
;
351 /* Send the glXQueryVersion request */
353 GetReq(GLXQueryVersion
, req
);
354 req
->reqType
= opcode
;
355 req
->glxCode
= X_GLXQueryVersion
;
356 req
->majorVersion
= GLX_MAJOR_VERSION
;
357 req
->minorVersion
= GLX_MINOR_VERSION
;
358 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
362 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
364 ** The server does not support the same major release as this
369 *major
= reply
.majorVersion
;
370 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
376 * We don't want to enable this GLX_OML_swap_method in glxext.h,
377 * because we can't support it. The X server writes it out though,
378 * so we should handle it somehow, to avoid false warnings.
381 IGNORE_GLX_SWAP_METHOD_OML
= 0x8060
386 * getVisualConfigs uses the !tagged_only path.
387 * getFBConfigs uses the tagged_only path.
390 __glXInitializeVisualConfigFromTags(__GLcontextModes
* config
, int count
,
391 const INT32
* bp
, Bool tagged_only
,
392 Bool fbconfig_style_tags
)
397 /* Copy in the first set of properties */
398 config
->visualID
= *bp
++;
400 config
->visualType
= _gl_convert_from_x_visual_type(*bp
++);
402 config
->rgbMode
= *bp
++;
404 config
->redBits
= *bp
++;
405 config
->greenBits
= *bp
++;
406 config
->blueBits
= *bp
++;
407 config
->alphaBits
= *bp
++;
408 config
->accumRedBits
= *bp
++;
409 config
->accumGreenBits
= *bp
++;
410 config
->accumBlueBits
= *bp
++;
411 config
->accumAlphaBits
= *bp
++;
413 config
->doubleBufferMode
= *bp
++;
414 config
->stereoMode
= *bp
++;
416 config
->rgbBits
= *bp
++;
417 config
->depthBits
= *bp
++;
418 config
->stencilBits
= *bp
++;
419 config
->numAuxBuffers
= *bp
++;
420 config
->level
= *bp
++;
422 #ifdef GLX_USE_APPLEGL
423 /* AppleSGLX supports pixmap and pbuffers with all config. */
424 config
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
425 /* Unfortunately this can create an ABI compatibility problem. */
428 count
-= __GLX_MIN_CONFIG_PROPS
;
433 ** Additional properties may be in a list at the end
434 ** of the reply. They are in pairs of property type
435 ** and property value.
438 #define FETCH_OR_SET(tag) \
439 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
441 for (i
= 0; i
< count
; i
+= 2) {
442 long int tag
= *bp
++;
446 FETCH_OR_SET(rgbMode
);
448 case GLX_BUFFER_SIZE
:
449 config
->rgbBits
= *bp
++;
452 config
->level
= *bp
++;
454 case GLX_DOUBLEBUFFER
:
455 FETCH_OR_SET(doubleBufferMode
);
458 FETCH_OR_SET(stereoMode
);
460 case GLX_AUX_BUFFERS
:
461 config
->numAuxBuffers
= *bp
++;
464 config
->redBits
= *bp
++;
467 config
->greenBits
= *bp
++;
470 config
->blueBits
= *bp
++;
473 config
->alphaBits
= *bp
++;
476 config
->depthBits
= *bp
++;
478 case GLX_STENCIL_SIZE
:
479 config
->stencilBits
= *bp
++;
481 case GLX_ACCUM_RED_SIZE
:
482 config
->accumRedBits
= *bp
++;
484 case GLX_ACCUM_GREEN_SIZE
:
485 config
->accumGreenBits
= *bp
++;
487 case GLX_ACCUM_BLUE_SIZE
:
488 config
->accumBlueBits
= *bp
++;
490 case GLX_ACCUM_ALPHA_SIZE
:
491 config
->accumAlphaBits
= *bp
++;
493 case GLX_VISUAL_CAVEAT_EXT
:
494 config
->visualRating
= *bp
++;
496 case GLX_X_VISUAL_TYPE
:
497 config
->visualType
= *bp
++;
499 case GLX_TRANSPARENT_TYPE
:
500 config
->transparentPixel
= *bp
++;
502 case GLX_TRANSPARENT_INDEX_VALUE
:
503 config
->transparentIndex
= *bp
++;
505 case GLX_TRANSPARENT_RED_VALUE
:
506 config
->transparentRed
= *bp
++;
508 case GLX_TRANSPARENT_GREEN_VALUE
:
509 config
->transparentGreen
= *bp
++;
511 case GLX_TRANSPARENT_BLUE_VALUE
:
512 config
->transparentBlue
= *bp
++;
514 case GLX_TRANSPARENT_ALPHA_VALUE
:
515 config
->transparentAlpha
= *bp
++;
518 config
->visualID
= *bp
++;
520 case GLX_DRAWABLE_TYPE
:
521 config
->drawableType
= *bp
++;
522 #ifdef GLX_USE_APPLEGL
523 /* AppleSGLX supports pixmap and pbuffers with all config. */
524 config
->drawableType
|= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
527 case GLX_RENDER_TYPE
:
528 config
->renderType
= *bp
++;
530 case GLX_X_RENDERABLE
:
531 config
->xRenderable
= *bp
++;
533 case GLX_FBCONFIG_ID
:
534 config
->fbconfigID
= *bp
++;
536 case GLX_MAX_PBUFFER_WIDTH
:
537 config
->maxPbufferWidth
= *bp
++;
539 case GLX_MAX_PBUFFER_HEIGHT
:
540 config
->maxPbufferHeight
= *bp
++;
542 case GLX_MAX_PBUFFER_PIXELS
:
543 config
->maxPbufferPixels
= *bp
++;
545 #ifndef GLX_USE_APPLEGL
546 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
547 config
->optimalPbufferWidth
= *bp
++;
549 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
550 config
->optimalPbufferHeight
= *bp
++;
552 case GLX_VISUAL_SELECT_GROUP_SGIX
:
553 config
->visualSelectGroup
= *bp
++;
555 case GLX_SWAP_METHOD_OML
:
556 config
->swapMethod
= *bp
++;
559 case GLX_SAMPLE_BUFFERS_SGIS
:
560 config
->sampleBuffers
= *bp
++;
562 case GLX_SAMPLES_SGIS
:
563 config
->samples
= *bp
++;
565 #ifdef GLX_USE_APPLEGL
566 case IGNORE_GLX_SWAP_METHOD_OML
:
567 /* We ignore this tag. See the comment above this function. */
571 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
572 config
->bindToTextureRgb
= *bp
++;
574 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
575 config
->bindToTextureRgba
= *bp
++;
577 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
578 config
->bindToMipmapTexture
= *bp
++;
580 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
581 config
->bindToTextureTargets
= *bp
++;
583 case GLX_Y_INVERTED_EXT
:
584 config
->yInverted
= *bp
++;
591 if(getenv("LIBGL_DIAGNOSTIC")) {
592 long int tagvalue
= *bp
++;
593 fprintf(stderr
, "WARNING: unknown GLX tag from server: "
594 "tag 0x%lx value 0x%lx\n", tag
, tagvalue
);
601 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
603 config
->haveAccumBuffer
= ((config
->accumRedBits
+
604 config
->accumGreenBits
+
605 config
->accumBlueBits
+
606 config
->accumAlphaBits
) > 0);
607 config
->haveDepthBuffer
= (config
->depthBits
> 0);
608 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
611 static __GLcontextModes
*
612 createConfigsFromProperties(Display
* dpy
, int nvisuals
, int nprops
,
613 int screen
, GLboolean tagged_only
)
615 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
617 __GLcontextModes
*modes
, *m
;
623 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
625 /* Check number of properties */
626 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
629 /* Allocate memory for our config structure */
630 modes
= _gl_context_modes_create(nvisuals
, sizeof(__GLcontextModes
));
634 prop_size
= nprops
* __GLX_SIZE_INT32
;
635 if (prop_size
<= sizeof(buf
))
638 props
= Xmalloc(prop_size
);
640 /* Read each config structure and convert it into our format */
642 for (i
= 0; i
< nvisuals
; i
++) {
643 _XRead(dpy
, (char *) props
, prop_size
);
644 #ifdef GLX_USE_APPLEGL
645 /* Older X servers don't send this so we default it here. */
646 m
->drawableType
= GLX_WINDOW_BIT
;
649 * The XQuartz 2.3.2.1 X server doesn't set this properly, so
650 * set the proper bits here.
651 * AppleSGLX supports windows, pixmaps, and pbuffers with all config.
653 m
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
655 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
656 tagged_only
, GL_TRUE
);
668 getVisualConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
670 xGLXGetVisualConfigsReq
*req
;
671 __GLXscreenConfigs
*psc
;
672 xGLXGetVisualConfigsReply reply
;
676 psc
= priv
->screenConfigs
+ screen
;
678 GetReq(GLXGetVisualConfigs
, req
);
679 req
->reqType
= priv
->majorOpcode
;
680 req
->glxCode
= X_GLXGetVisualConfigs
;
681 req
->screen
= screen
;
683 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
686 psc
->visuals
= createConfigsFromProperties(dpy
,
693 return psc
->visuals
!= NULL
;
697 getFBConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
699 xGLXGetFBConfigsReq
*fb_req
;
700 xGLXGetFBConfigsSGIXReq
*sgi_req
;
701 xGLXVendorPrivateWithReplyReq
*vpreq
;
702 xGLXGetFBConfigsReply reply
;
703 __GLXscreenConfigs
*psc
;
705 psc
= priv
->screenConfigs
+ screen
;
707 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, GLX_EXTENSIONS
);
712 if (atof(priv
->serverGLXversion
) >= 1.3) {
713 GetReq(GLXGetFBConfigs
, fb_req
);
714 fb_req
->reqType
= priv
->majorOpcode
;
715 fb_req
->glxCode
= X_GLXGetFBConfigs
;
716 fb_req
->screen
= screen
;
718 else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
719 GetReqExtra(GLXVendorPrivateWithReply
,
720 sz_xGLXGetFBConfigsSGIXReq
+
721 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
722 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
723 sgi_req
->reqType
= priv
->majorOpcode
;
724 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
725 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
726 sgi_req
->screen
= screen
;
731 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
734 psc
->configs
= createConfigsFromProperties(dpy
,
736 reply
.numAttribs
* 2,
741 return psc
->configs
!= NULL
;
745 ** Allocate the memory for the per screen configs for each screen.
746 ** If that works then fetch the per screen configs data.
749 AllocAndFetchScreenConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
)
751 __GLXscreenConfigs
*psc
;
755 ** First allocate memory for the array of per screen configs.
757 screens
= ScreenCount(dpy
);
758 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
762 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
763 priv
->screenConfigs
= psc
;
765 priv
->serverGLXversion
=
766 __glXQueryServerString(dpy
, priv
->majorOpcode
, 0, GLX_VERSION
);
767 if (priv
->serverGLXversion
== NULL
) {
768 FreeScreenConfigs(priv
);
772 for (i
= 0; i
< screens
; i
++, psc
++) {
773 getVisualConfigs(dpy
, priv
, i
);
774 getFBConfigs(dpy
, priv
, i
);
776 #ifdef GLX_DIRECT_RENDERING
779 psc
->drawHash
= __glxHashCreate();
780 if (psc
->drawHash
== NULL
)
783 /* Initialize per screen dynamic client GLX extensions */
784 psc
->ext_list_first_time
= GL_TRUE
;
786 if (priv
->dri2Display
)
787 psc
->driScreen
= (*priv
->dri2Display
->createScreen
) (psc
, i
, priv
);
789 if (psc
->driScreen
== NULL
&& priv
->driDisplay
)
790 psc
->driScreen
= (*priv
->driDisplay
->createScreen
) (psc
, i
, priv
);
792 if (psc
->driScreen
== NULL
&& priv
->driswDisplay
)
793 psc
->driScreen
= (*priv
->driswDisplay
->createScreen
) (psc
, i
, priv
);
795 if (psc
->driScreen
== NULL
) {
796 __glxHashDestroy(psc
->drawHash
);
797 psc
->drawHash
= NULL
;
806 ** Initialize the client side extension code.
808 _X_HIDDEN __GLXdisplayPrivate
*
809 __glXInitialize(Display
* dpy
)
811 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
812 XExtData
**privList
, *private, *found
;
813 __GLXdisplayPrivate
*dpyPriv
;
814 XEDataObject dataObj
;
816 #ifdef GLX_DIRECT_RENDERING
817 Bool glx_direct
, glx_accel
;
820 /* The one and only long long lock */
823 if (!XextHasExtension(info
)) {
824 /* No GLX extension supported by this server. Oh well. */
826 XMissingExtension(dpy
, __glXExtensionName
);
830 /* See if a display private already exists. If so, return it */
831 dataObj
.display
= dpy
;
832 privList
= XEHeadOfExtensionList(dataObj
);
833 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
836 return (__GLXdisplayPrivate
*) found
->private_data
;
839 /* See if the versions are compatible */
840 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
841 /* The client and server do not agree on versions. Punt. */
847 ** Allocate memory for all the pieces needed for this buffer.
849 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
854 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
857 Xfree((char *) private);
862 ** Init the display private and then read in the screen config
863 ** structures from the server.
865 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
866 dpyPriv
->majorVersion
= major
;
867 dpyPriv
->minorVersion
= minor
;
870 dpyPriv
->serverGLXvendor
= 0x0;
871 dpyPriv
->serverGLXversion
= 0x0;
873 #ifdef GLX_DIRECT_RENDERING
874 glx_direct
= (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
);
875 glx_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
878 ** Initialize the direct rendering per display data and functions.
879 ** Note: This _must_ be done before calling any other DRI routines
880 ** (e.g., those called in AllocAndFetchScreenConfigs).
882 if (glx_direct
&& glx_accel
) {
883 dpyPriv
->dri2Display
= dri2CreateDisplay(dpy
);
884 dpyPriv
->driDisplay
= driCreateDisplay(dpy
);
887 dpyPriv
->driswDisplay
= driswCreateDisplay(dpy
);
889 #ifdef GLX_USE_APPLEGL
890 if (apple_init_glx(dpy
) || !AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
892 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
895 Xfree((char *) dpyPriv
);
896 Xfree((char *) private);
901 ** Fill in the private structure. This is the actual structure that
902 ** hangs off of the Display structure. Our private structure is
903 ** referred to by this structure. Got that?
905 private->number
= info
->codes
->extension
;
907 private->free_private
= __glXFreeDisplayPrivate
;
908 private->private_data
= (char *) dpyPriv
;
909 XAddToExtensionList(privList
, private);
911 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
912 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
920 ** Setup for sending a GLX command on dpy. Make sure the extension is
921 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
924 __glXSetupForCommand(Display
* dpy
)
927 __GLXdisplayPrivate
*priv
;
929 /* If this thread has a current context, flush its rendering commands */
930 gc
= __glXGetCurrentContext();
931 if (gc
->currentDpy
) {
932 /* Flush rendering buffer of the current context, if any */
933 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
935 if (gc
->currentDpy
== dpy
) {
936 /* Use opcode from gc because its right */
937 return gc
->majorOpcode
;
941 ** Have to get info about argument dpy because it might be to
942 ** a different server
947 /* Forced to lookup extension via the slow initialize route */
948 priv
= __glXInitialize(dpy
);
952 return priv
->majorOpcode
;
956 * Flush the drawing command transport buffer.
958 * \param ctx Context whose transport buffer is to be flushed.
959 * \param pc Pointer to first unused buffer location.
962 * Modify this function to use \c ctx->pc instead of the explicit
966 __glXFlushRenderBuffer(__GLXcontext
* ctx
, GLubyte
* pc
)
968 Display
*const dpy
= ctx
->currentDpy
;
970 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
974 const GLint size
= pc
- ctx
->buf
;
976 if ((dpy
!= NULL
) && (size
> 0)) {
978 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
979 (const uint8_t *) ctx
->buf
);
981 /* Send the entire buffer as an X request */
983 GetReq(GLXRender
, req
);
984 req
->reqType
= ctx
->majorOpcode
;
985 req
->glxCode
= X_GLXRender
;
986 req
->contextTag
= ctx
->currentContextTag
;
987 req
->length
+= (size
+ 3) >> 2;
988 _XSend(dpy
, (char *) ctx
->buf
, size
);
994 /* Reset pointer and return it */
1001 * Send a portion of a GLXRenderLarge command to the server. The advantage of
1002 * this function over \c __glXSendLargeCommand is that callers can use the
1003 * data buffer in the GLX context and may be able to avoid allocating an
1004 * extra buffer. The disadvantage is the clients will have to do more
1005 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
1007 * \sa __glXSendLargeCommand
1009 * \param gc GLX context
1010 * \param requestNumber Which part of the whole command is this? The first
1012 * \param totalRequests How many requests will there be?
1013 * \param data Command data.
1014 * \param dataLen Size, in bytes, of the command data.
1017 __glXSendLargeChunk(__GLXcontext
* gc
, GLint requestNumber
,
1018 GLint totalRequests
, const GLvoid
* data
, GLint dataLen
)
1020 Display
*dpy
= gc
->currentDpy
;
1022 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1023 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
,
1024 totalRequests
, dataLen
, data
);
1026 xGLXRenderLargeReq
*req
;
1028 if (requestNumber
== 1) {
1032 GetReq(GLXRenderLarge
, req
);
1033 req
->reqType
= gc
->majorOpcode
;
1034 req
->glxCode
= X_GLXRenderLarge
;
1035 req
->contextTag
= gc
->currentContextTag
;
1036 req
->length
+= (dataLen
+ 3) >> 2;
1037 req
->requestNumber
= requestNumber
;
1038 req
->requestTotal
= totalRequests
;
1039 req
->dataBytes
= dataLen
;
1040 Data(dpy
, data
, dataLen
);
1042 if (requestNumber
== totalRequests
) {
1046 #endif /* USE_XCB */
1051 * Send a command that is too large for the GLXRender protocol request.
1053 * Send a large command, one that is too large for some reason to
1054 * send using the GLXRender protocol request. One reason to send
1055 * a large command is to avoid copying the data.
1057 * \param ctx GLX context
1058 * \param header Header data.
1059 * \param headerLen Size, in bytes, of the header data. It is assumed that
1060 * the header data will always be small enough to fit in
1061 * a single X protocol packet.
1062 * \param data Command data.
1063 * \param dataLen Size, in bytes, of the command data.
1066 __glXSendLargeCommand(__GLXcontext
* ctx
,
1067 const GLvoid
* header
, GLint headerLen
,
1068 const GLvoid
* data
, GLint dataLen
)
1071 GLint totalRequests
, requestNumber
;
1074 ** Calculate the maximum amount of data can be stuffed into a single
1075 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1076 ** packet size minus sz_xGLXRenderReq.
1078 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1079 totalRequests
= 1 + (dataLen
/ maxSize
);
1080 if (dataLen
% maxSize
)
1084 ** Send all of the command, except the large array, as one request.
1086 assert(headerLen
<= maxSize
);
1087 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1090 ** Send enough requests until the whole array is sent.
1092 for (requestNumber
= 2; requestNumber
<= (totalRequests
- 1);
1094 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1095 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1097 assert(dataLen
> 0);
1100 assert(dataLen
<= maxSize
);
1101 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1104 /************************************************************************/
1108 __glXDumpDrawBuffer(__GLXcontext
* ctx
)
1110 GLubyte
*p
= ctx
->buf
;
1111 GLubyte
*end
= ctx
->pc
;
1112 GLushort opcode
, length
;
1116 opcode
= *((GLushort
*) p
);
1117 length
= *((GLushort
*) (p
+ 2));
1118 printf("%2x: %5d: ", opcode
, length
);
1121 while (length
> 0) {
1122 printf("%08x ", *((unsigned *) p
));