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"
50 #include <X11/Xlib-xcb.h>
56 void __glXDumpDrawBuffer(struct glx_context
* ctx
);
60 ** You can set this cell to 1 to force the gl drawing stuff to be
61 ** one command per packet
63 _X_HIDDEN
int __glXDebug
= 0;
65 /* Extension required boiler plate */
67 static const char __glXExtensionName
[] = GLX_EXTENSION_NAME
;
68 static struct glx_display
*glx_displays
;
70 static /* const */ char *error_list
[] = {
76 "GLXBadCurrentWindow",
77 "GLXBadRenderRequest",
79 "GLXUnsupportedPrivateRequest",
82 "GLXBadCurrentDrawable",
87 #ifdef GLX_USE_APPLEGL
88 static char *__glXErrorString(Display
*dpy
, int code
, XExtCodes
*codes
,
93 XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
94 __GLX_NUMBER_ERRORS
, error_list
)
97 * GLX events are a bit funky. We don't stuff the X event code into
98 * our user exposed (via XNextEvent) structure. Instead we use the GLX
99 * private event code namespace (and hope it doesn't conflict). Clients
100 * have to know that bit 15 in the event type field means they're getting
101 * a GLX event, and then handle the various sub-event types there, rather
102 * than simply checking the event code and handling it directly.
106 __glXWireToEvent(Display
*dpy
, XEvent
*event
, xEvent
*wire
)
108 struct glx_display
*glx_dpy
= __glXInitialize(dpy
);
113 switch ((wire
->u
.u
.type
& 0x7f) - glx_dpy
->codes
->first_event
) {
114 case GLX_PbufferClobber
:
116 GLXPbufferClobberEvent
*aevent
= (GLXPbufferClobberEvent
*)event
;
117 xGLXPbufferClobberEvent
*awire
= (xGLXPbufferClobberEvent
*)wire
;
118 aevent
->event_type
= awire
->type
;
119 aevent
->serial
= awire
->sequenceNumber
;
120 aevent
->event_type
= awire
->event_type
;
121 aevent
->draw_type
= awire
->draw_type
;
122 aevent
->drawable
= awire
->drawable
;
123 aevent
->buffer_mask
= awire
->buffer_mask
;
124 aevent
->aux_buffer
= awire
->aux_buffer
;
125 aevent
->x
= awire
->x
;
126 aevent
->y
= awire
->y
;
127 aevent
->width
= awire
->width
;
128 aevent
->height
= awire
->height
;
129 aevent
->count
= awire
->count
;
132 case GLX_BufferSwapComplete
:
134 GLXBufferSwapComplete
*aevent
= (GLXBufferSwapComplete
*)event
;
135 xGLXBufferSwapComplete2
*awire
= (xGLXBufferSwapComplete2
*)wire
;
136 struct glx_drawable
*glxDraw
= GetGLXDrawable(dpy
, awire
->drawable
);
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
;
145 if (awire
->sbc
< glxDraw
->lastEventSbc
)
146 glxDraw
->eventSbcWrap
+= 0x100000000;
147 glxDraw
->lastEventSbc
= awire
->sbc
;
148 aevent
->sbc
= awire
->sbc
+ glxDraw
->eventSbcWrap
;
152 /* client doesn't support server event */
159 /* We don't actually support this. It doesn't make sense for clients to
160 * send each other GLX events.
163 __glXEventToWire(Display
*dpy
, XEvent
*event
, xEvent
*wire
)
165 struct glx_display
*glx_dpy
= __glXInitialize(dpy
);
170 switch (event
->type
) {
175 case GLX_EXCHANGE_COMPLETE_INTEL
:
177 case GLX_COPY_COMPLETE_INTEL
:
179 case GLX_FLIP_COMPLETE_INTEL
:
182 /* client doesn't support server event */
189 /************************************************************************/
191 ** Free the per screen configs data as well as the array of
192 ** __glXScreenConfigs.
195 FreeScreenConfigs(struct glx_display
* priv
)
197 struct glx_screen
*psc
;
200 /* Free screen configuration information */
201 screens
= ScreenCount(priv
->dpy
);
202 for (i
= 0; i
< screens
; i
++) {
203 psc
= priv
->screens
[i
];
204 glx_screen_cleanup(psc
);
206 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
207 if (psc
->driScreen
) {
208 psc
->driScreen
->destroyScreen(psc
);
216 free((char *) priv
->screens
);
217 priv
->screens
= NULL
;
221 glx_display_free(struct glx_display
*priv
)
223 struct glx_context
*gc
;
225 gc
= __glXGetCurrentContext();
226 if (priv
->dpy
== gc
->currentDpy
) {
227 gc
->vtable
->destroy(gc
);
228 __glXSetCurrentContextNull();
231 FreeScreenConfigs(priv
);
232 free((char *) priv
->serverGLXvendor
);
233 free((char *) priv
->serverGLXversion
);
235 __glxHashDestroy(priv
->glXDrawHash
);
237 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
238 __glxHashDestroy(priv
->drawHash
);
240 /* Free the direct rendering per display data */
241 if (priv
->driswDisplay
)
242 (*priv
->driswDisplay
->destroyDisplay
) (priv
->driswDisplay
);
243 priv
->driswDisplay
= NULL
;
245 if (priv
->driDisplay
)
246 (*priv
->driDisplay
->destroyDisplay
) (priv
->driDisplay
);
247 priv
->driDisplay
= NULL
;
249 if (priv
->dri2Display
)
250 (*priv
->dri2Display
->destroyDisplay
) (priv
->dri2Display
);
251 priv
->dri2Display
= NULL
;
258 __glXCloseDisplay(Display
* dpy
, XExtCodes
* codes
)
260 struct glx_display
*priv
, **prev
;
262 _XLockMutex(_Xglobal_lock
);
263 prev
= &glx_displays
;
264 for (priv
= glx_displays
; priv
; prev
= &priv
->next
, priv
= priv
->next
) {
265 if (priv
->dpy
== dpy
) {
270 _XUnlockMutex(_Xglobal_lock
);
272 glx_display_free(priv
);
278 ** Query the version of the GLX extension. This procedure works even if
279 ** the client extension is not completely set up.
282 QueryVersion(Display
* dpy
, int opcode
, int *major
, int *minor
)
284 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
285 xcb_glx_query_version_reply_t
*reply
= xcb_glx_query_version_reply(c
,
286 xcb_glx_query_version
295 if (reply
->major_version
!= GLX_MAJOR_VERSION
) {
299 *major
= reply
->major_version
;
300 *minor
= min(reply
->minor_version
, GLX_MINOR_VERSION
);
306 * We don't want to enable this GLX_OML_swap_method in glxext.h,
307 * because we can't support it. The X server writes it out though,
308 * so we should handle it somehow, to avoid false warnings.
311 IGNORE_GLX_SWAP_METHOD_OML
= 0x8060
316 convert_from_x_visual_type(int visualType
)
318 static const int glx_visual_types
[] = {
319 GLX_STATIC_GRAY
, GLX_GRAY_SCALE
,
320 GLX_STATIC_COLOR
, GLX_PSEUDO_COLOR
,
321 GLX_TRUE_COLOR
, GLX_DIRECT_COLOR
324 if (visualType
< ARRAY_SIZE(glx_visual_types
))
325 return glx_visual_types
[visualType
];
331 * getVisualConfigs uses the !tagged_only path.
332 * getFBConfigs uses the tagged_only path.
335 __glXInitializeVisualConfigFromTags(struct glx_config
* config
, int count
,
336 const INT32
* bp
, Bool tagged_only
,
337 Bool fbconfig_style_tags
)
342 /* Copy in the first set of properties */
343 config
->visualID
= *bp
++;
345 config
->visualType
= convert_from_x_visual_type(*bp
++);
347 config
->rgbMode
= *bp
++;
349 config
->redBits
= *bp
++;
350 config
->greenBits
= *bp
++;
351 config
->blueBits
= *bp
++;
352 config
->alphaBits
= *bp
++;
353 config
->accumRedBits
= *bp
++;
354 config
->accumGreenBits
= *bp
++;
355 config
->accumBlueBits
= *bp
++;
356 config
->accumAlphaBits
= *bp
++;
358 config
->doubleBufferMode
= *bp
++;
359 config
->stereoMode
= *bp
++;
361 config
->rgbBits
= *bp
++;
362 config
->depthBits
= *bp
++;
363 config
->stencilBits
= *bp
++;
364 config
->numAuxBuffers
= *bp
++;
365 config
->level
= *bp
++;
367 #ifdef GLX_USE_APPLEGL
368 /* AppleSGLX supports pixmap and pbuffers with all config. */
369 config
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
370 /* Unfortunately this can create an ABI compatibility problem. */
373 count
-= __GLX_MIN_CONFIG_PROPS
;
377 config
->sRGBCapable
= GL_FALSE
;
380 ** Additional properties may be in a list at the end
381 ** of the reply. They are in pairs of property type
382 ** and property value.
385 #define FETCH_OR_SET(tag) \
386 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
388 for (i
= 0; i
< count
; i
+= 2) {
389 long int tag
= *bp
++;
393 FETCH_OR_SET(rgbMode
);
395 case GLX_BUFFER_SIZE
:
396 config
->rgbBits
= *bp
++;
399 config
->level
= *bp
++;
401 case GLX_DOUBLEBUFFER
:
402 FETCH_OR_SET(doubleBufferMode
);
405 FETCH_OR_SET(stereoMode
);
407 case GLX_AUX_BUFFERS
:
408 config
->numAuxBuffers
= *bp
++;
411 config
->redBits
= *bp
++;
414 config
->greenBits
= *bp
++;
417 config
->blueBits
= *bp
++;
420 config
->alphaBits
= *bp
++;
423 config
->depthBits
= *bp
++;
425 case GLX_STENCIL_SIZE
:
426 config
->stencilBits
= *bp
++;
428 case GLX_ACCUM_RED_SIZE
:
429 config
->accumRedBits
= *bp
++;
431 case GLX_ACCUM_GREEN_SIZE
:
432 config
->accumGreenBits
= *bp
++;
434 case GLX_ACCUM_BLUE_SIZE
:
435 config
->accumBlueBits
= *bp
++;
437 case GLX_ACCUM_ALPHA_SIZE
:
438 config
->accumAlphaBits
= *bp
++;
440 case GLX_VISUAL_CAVEAT_EXT
:
441 config
->visualRating
= *bp
++;
443 case GLX_X_VISUAL_TYPE
:
444 config
->visualType
= *bp
++;
446 case GLX_TRANSPARENT_TYPE
:
447 config
->transparentPixel
= *bp
++;
449 case GLX_TRANSPARENT_INDEX_VALUE
:
450 config
->transparentIndex
= *bp
++;
452 case GLX_TRANSPARENT_RED_VALUE
:
453 config
->transparentRed
= *bp
++;
455 case GLX_TRANSPARENT_GREEN_VALUE
:
456 config
->transparentGreen
= *bp
++;
458 case GLX_TRANSPARENT_BLUE_VALUE
:
459 config
->transparentBlue
= *bp
++;
461 case GLX_TRANSPARENT_ALPHA_VALUE
:
462 config
->transparentAlpha
= *bp
++;
465 config
->visualID
= *bp
++;
467 case GLX_DRAWABLE_TYPE
:
468 config
->drawableType
= *bp
++;
469 #ifdef GLX_USE_APPLEGL
470 /* AppleSGLX supports pixmap and pbuffers with all config. */
471 config
->drawableType
|= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
474 case GLX_RENDER_TYPE
:
475 config
->renderType
= *bp
++;
477 case GLX_X_RENDERABLE
:
478 config
->xRenderable
= *bp
++;
480 case GLX_FBCONFIG_ID
:
481 config
->fbconfigID
= *bp
++;
483 case GLX_MAX_PBUFFER_WIDTH
:
484 config
->maxPbufferWidth
= *bp
++;
486 case GLX_MAX_PBUFFER_HEIGHT
:
487 config
->maxPbufferHeight
= *bp
++;
489 case GLX_MAX_PBUFFER_PIXELS
:
490 config
->maxPbufferPixels
= *bp
++;
492 #ifndef GLX_USE_APPLEGL
493 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
494 config
->optimalPbufferWidth
= *bp
++;
496 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
497 config
->optimalPbufferHeight
= *bp
++;
499 case GLX_VISUAL_SELECT_GROUP_SGIX
:
500 config
->visualSelectGroup
= *bp
++;
502 case GLX_SWAP_METHOD_OML
:
503 config
->swapMethod
= *bp
++;
506 case GLX_SAMPLE_BUFFERS_SGIS
:
507 config
->sampleBuffers
= *bp
++;
509 case GLX_SAMPLES_SGIS
:
510 config
->samples
= *bp
++;
512 #ifdef GLX_USE_APPLEGL
513 case IGNORE_GLX_SWAP_METHOD_OML
:
514 /* We ignore this tag. See the comment above this function. */
518 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
519 config
->bindToTextureRgb
= *bp
++;
521 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
522 config
->bindToTextureRgba
= *bp
++;
524 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
525 config
->bindToMipmapTexture
= *bp
++;
527 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
528 config
->bindToTextureTargets
= *bp
++;
530 case GLX_Y_INVERTED_EXT
:
531 config
->yInverted
= *bp
++;
534 case GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
535 config
->sRGBCapable
= *bp
++;
539 if (fbconfig_style_tags
)
546 if(getenv("LIBGL_DIAGNOSTIC")) {
547 long int tagvalue
= *bp
++;
548 fprintf(stderr
, "WARNING: unknown GLX tag from server: "
549 "tag 0x%lx value 0x%lx\n", tag
, tagvalue
);
551 /* Ignore the unrecognized tag's value */
559 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
562 static struct glx_config
*
563 createConfigsFromProperties(Display
* dpy
, int nvisuals
, int nprops
,
564 int screen
, GLboolean tagged_only
)
566 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
568 struct glx_config
*modes
, *m
;
574 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
576 /* Check number of properties */
577 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
580 /* Allocate memory for our config structure */
581 modes
= glx_config_create_list(nvisuals
);
585 prop_size
= nprops
* __GLX_SIZE_INT32
;
586 if (prop_size
<= sizeof(buf
))
589 props
= malloc(prop_size
);
591 /* Read each config structure and convert it into our format */
593 for (i
= 0; i
< nvisuals
; i
++) {
594 _XRead(dpy
, (char *) props
, prop_size
);
595 #ifdef GLX_USE_APPLEGL
596 /* Older X servers don't send this so we default it here. */
597 m
->drawableType
= GLX_WINDOW_BIT
;
600 * The XQuartz 2.3.2.1 X server doesn't set this properly, so
601 * set the proper bits here.
602 * AppleSGLX supports windows, pixmaps, and pbuffers with all config.
604 m
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
606 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
607 tagged_only
, GL_TRUE
);
619 getVisualConfigs(struct glx_screen
*psc
,
620 struct glx_display
*priv
, int screen
)
622 xGLXGetVisualConfigsReq
*req
;
623 xGLXGetVisualConfigsReply reply
;
624 Display
*dpy
= priv
->dpy
;
629 GetReq(GLXGetVisualConfigs
, req
);
630 req
->reqType
= priv
->majorOpcode
;
631 req
->glxCode
= X_GLXGetVisualConfigs
;
632 req
->screen
= screen
;
634 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
637 psc
->visuals
= createConfigsFromProperties(dpy
,
644 return psc
->visuals
!= NULL
;
648 getFBConfigs(struct glx_screen
*psc
, struct glx_display
*priv
, int screen
)
650 xGLXGetFBConfigsReq
*fb_req
;
651 xGLXGetFBConfigsSGIXReq
*sgi_req
;
652 xGLXVendorPrivateWithReplyReq
*vpreq
;
653 xGLXGetFBConfigsReply reply
;
654 Display
*dpy
= priv
->dpy
;
657 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, GLX_EXTENSIONS
);
662 if (atof(priv
->serverGLXversion
) >= 1.3) {
663 GetReq(GLXGetFBConfigs
, fb_req
);
664 fb_req
->reqType
= priv
->majorOpcode
;
665 fb_req
->glxCode
= X_GLXGetFBConfigs
;
666 fb_req
->screen
= screen
;
668 else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
669 GetReqExtra(GLXVendorPrivateWithReply
,
670 sz_xGLXGetFBConfigsSGIXReq
-
671 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
672 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
673 sgi_req
->reqType
= priv
->majorOpcode
;
674 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
675 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
676 sgi_req
->screen
= screen
;
681 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
684 psc
->configs
= createConfigsFromProperties(dpy
,
686 reply
.numAttribs
* 2,
691 return psc
->configs
!= NULL
;
695 glx_screen_init(struct glx_screen
*psc
,
696 int screen
, struct glx_display
* priv
)
698 /* Initialize per screen dynamic client GLX extensions */
699 psc
->ext_list_first_time
= GL_TRUE
;
701 psc
->dpy
= priv
->dpy
;
704 getVisualConfigs(psc
, priv
, screen
);
705 getFBConfigs(psc
, priv
, screen
);
711 glx_screen_cleanup(struct glx_screen
*psc
)
714 glx_config_destroy_list(psc
->configs
);
715 free(psc
->effectiveGLXexts
);
716 psc
->configs
= NULL
; /* NOTE: just for paranoia */
719 glx_config_destroy_list(psc
->visuals
);
720 psc
->visuals
= NULL
; /* NOTE: just for paranoia */
722 free((char *) psc
->serverGLXexts
);
726 ** Allocate the memory for the per screen configs for each screen.
727 ** If that works then fetch the per screen configs data.
730 AllocAndFetchScreenConfigs(Display
* dpy
, struct glx_display
* priv
)
732 struct glx_screen
*psc
;
736 ** First allocate memory for the array of per screen configs.
738 screens
= ScreenCount(dpy
);
739 priv
->screens
= malloc(screens
* sizeof *priv
->screens
);
743 priv
->serverGLXversion
=
744 __glXQueryServerString(dpy
, priv
->majorOpcode
, 0, GLX_VERSION
);
745 if (priv
->serverGLXversion
== NULL
) {
746 FreeScreenConfigs(priv
);
750 for (i
= 0; i
< screens
; i
++, psc
++) {
752 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
753 if (priv
->dri2Display
)
754 psc
= (*priv
->dri2Display
->createScreen
) (i
, priv
);
755 if (psc
== NULL
&& priv
->driDisplay
)
756 psc
= (*priv
->driDisplay
->createScreen
) (i
, priv
);
757 if (psc
== NULL
&& priv
->driswDisplay
)
758 psc
= (*priv
->driswDisplay
->createScreen
) (i
, priv
);
760 #if defined(GLX_USE_APPLEGL)
762 psc
= applegl_create_screen(i
, priv
);
765 psc
= indirect_create_screen(i
, priv
);
767 priv
->screens
[i
] = psc
;
774 ** Initialize the client side extension code.
776 _X_HIDDEN
struct glx_display
*
777 __glXInitialize(Display
* dpy
)
779 struct glx_display
*dpyPriv
, *d
;
780 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
781 Bool glx_direct
, glx_accel
;
785 _XLockMutex(_Xglobal_lock
);
787 for (dpyPriv
= glx_displays
; dpyPriv
; dpyPriv
= dpyPriv
->next
) {
788 if (dpyPriv
->dpy
== dpy
) {
789 _XUnlockMutex(_Xglobal_lock
);
794 /* Drop the lock while we create the display private. */
795 _XUnlockMutex(_Xglobal_lock
);
797 dpyPriv
= calloc(1, sizeof *dpyPriv
);
801 dpyPriv
->codes
= XInitExtension(dpy
, __glXExtensionName
);
802 if (!dpyPriv
->codes
) {
804 _XUnlockMutex(_Xglobal_lock
);
809 dpyPriv
->majorOpcode
= dpyPriv
->codes
->major_opcode
;
810 dpyPriv
->serverGLXvendor
= 0x0;
811 dpyPriv
->serverGLXversion
= 0x0;
813 /* See if the versions are compatible. This GLX implementation does not
814 * work with servers that only support GLX 1.0.
816 if (!QueryVersion(dpy
, dpyPriv
->majorOpcode
,
817 &dpyPriv
->majorVersion
, &dpyPriv
->minorVersion
)
818 || (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
< 1)) {
820 _XUnlockMutex(_Xglobal_lock
);
824 for (i
= 0; i
< __GLX_NUMBER_EVENTS
; i
++) {
825 XESetWireToEvent(dpy
, dpyPriv
->codes
->first_event
+ i
, __glXWireToEvent
);
826 XESetEventToWire(dpy
, dpyPriv
->codes
->first_event
+ i
, __glXEventToWire
);
829 XESetCloseDisplay(dpy
, dpyPriv
->codes
->extension
, __glXCloseDisplay
);
830 XESetErrorString (dpy
, dpyPriv
->codes
->extension
,__glXErrorString
);
832 dpyPriv
->glXDrawHash
= __glxHashCreate();
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 __glX_send_client_info(dpyPriv
);
866 /* Grab the lock again and add the dispay private, unless somebody
867 * beat us to initializing on this display in the meantime. */
868 _XLockMutex(_Xglobal_lock
);
870 for (d
= glx_displays
; d
; d
= d
->next
) {
872 _XUnlockMutex(_Xglobal_lock
);
873 glx_display_free(dpyPriv
);
878 dpyPriv
->next
= glx_displays
;
879 glx_displays
= dpyPriv
;
881 _XUnlockMutex(_Xglobal_lock
);
887 ** Setup for sending a GLX command on dpy. Make sure the extension is
888 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
891 __glXSetupForCommand(Display
* dpy
)
893 struct glx_context
*gc
;
894 struct glx_display
*priv
;
896 /* If this thread has a current context, flush its rendering commands */
897 gc
= __glXGetCurrentContext();
898 if (gc
->currentDpy
) {
899 /* Flush rendering buffer of the current context, if any */
900 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
902 if (gc
->currentDpy
== dpy
) {
903 /* Use opcode from gc because its right */
904 return gc
->majorOpcode
;
908 ** Have to get info about argument dpy because it might be to
909 ** a different server
914 /* Forced to lookup extension via the slow initialize route */
915 priv
= __glXInitialize(dpy
);
919 return priv
->majorOpcode
;
923 * Flush the drawing command transport buffer.
925 * \param ctx Context whose transport buffer is to be flushed.
926 * \param pc Pointer to first unused buffer location.
929 * Modify this function to use \c ctx->pc instead of the explicit
933 __glXFlushRenderBuffer(struct glx_context
* ctx
, GLubyte
* pc
)
935 Display
*const dpy
= ctx
->currentDpy
;
936 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
937 const GLint size
= pc
- ctx
->buf
;
939 if ((dpy
!= NULL
) && (size
> 0)) {
940 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
941 (const uint8_t *) ctx
->buf
);
944 /* Reset pointer and return it */
951 * Send a portion of a GLXRenderLarge command to the server. The advantage of
952 * this function over \c __glXSendLargeCommand is that callers can use the
953 * data buffer in the GLX context and may be able to avoid allocating an
954 * extra buffer. The disadvantage is the clients will have to do more
955 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
957 * \sa __glXSendLargeCommand
959 * \param gc GLX context
960 * \param requestNumber Which part of the whole command is this? The first
962 * \param totalRequests How many requests will there be?
963 * \param data Command data.
964 * \param dataLen Size, in bytes, of the command data.
967 __glXSendLargeChunk(struct glx_context
* gc
, GLint requestNumber
,
968 GLint totalRequests
, const GLvoid
* data
, GLint dataLen
)
970 Display
*dpy
= gc
->currentDpy
;
971 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
972 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
,
973 totalRequests
, dataLen
, data
);
978 * Send a command that is too large for the GLXRender protocol request.
980 * Send a large command, one that is too large for some reason to
981 * send using the GLXRender protocol request. One reason to send
982 * a large command is to avoid copying the data.
984 * \param ctx GLX context
985 * \param header Header data.
986 * \param headerLen Size, in bytes, of the header data. It is assumed that
987 * the header data will always be small enough to fit in
988 * a single X protocol packet.
989 * \param data Command data.
990 * \param dataLen Size, in bytes, of the command data.
993 __glXSendLargeCommand(struct glx_context
* ctx
,
994 const GLvoid
* header
, GLint headerLen
,
995 const GLvoid
* data
, GLint dataLen
)
998 GLint totalRequests
, requestNumber
;
1001 ** Calculate the maximum amount of data can be stuffed into a single
1002 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1003 ** packet size minus sz_xGLXRenderReq.
1005 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1006 totalRequests
= 1 + (dataLen
/ maxSize
);
1007 if (dataLen
% maxSize
)
1011 ** Send all of the command, except the large array, as one request.
1013 assert(headerLen
<= maxSize
);
1014 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1017 ** Send enough requests until the whole array is sent.
1019 for (requestNumber
= 2; requestNumber
<= (totalRequests
- 1);
1021 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1022 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1024 assert(dataLen
> 0);
1027 assert(dataLen
<= maxSize
);
1028 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1031 /************************************************************************/
1035 __glXDumpDrawBuffer(struct glx_context
* ctx
)
1037 GLubyte
*p
= ctx
->buf
;
1038 GLubyte
*end
= ctx
->pc
;
1039 GLushort opcode
, length
;
1043 opcode
= *((GLushort
*) p
);
1044 length
= *((GLushort
*) (p
+ 2));
1045 printf("%2x: %5d: ", opcode
, length
);
1048 while (length
> 0) {
1049 printf("%08x ", *((unsigned *) p
));