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 "glxextensions.h"
45 #include "glcontextmodes.h"
48 #include <X11/Xlib-xcb.h>
55 void __glXDumpDrawBuffer(__GLXcontext
* ctx
);
59 ** You can set this cell to 1 to force the gl drawing stuff to be
60 ** one command per packet
62 _X_HIDDEN
int __glXDebug
= 0;
64 /* Extension required boiler plate */
66 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
67 XExtensionInfo
*__glXExtensionInfo
= NULL
;
69 static /* const */ char *error_list
[] = {
75 "GLXBadCurrentWindow",
76 "GLXBadRenderRequest",
78 "GLXUnsupportedPrivateRequest",
81 "GLXBadCurrentDrawable",
86 __glXCloseDisplay(Display
* dpy
, XExtCodes
* codes
)
90 gc
= __glXGetCurrentContext();
91 if (dpy
== gc
->currentDpy
) {
92 __glXSetCurrentContextNull();
96 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
101 XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
102 __GLX_NUMBER_ERRORS
, error_list
)
104 __glXWireToEvent(Display
*dpy
, XEvent
*event
, xEvent
*wire
);
106 __glXEventToWire(Display
*dpy
, XEvent
*event
, xEvent
*wire
);
108 static /* const */ XExtensionHooks __glXExtensionHooks
= {
109 NULL
, /* create_gc */
113 NULL
, /* create_font */
114 NULL
, /* free_font */
115 __glXCloseDisplay
, /* close_display */
116 __glXWireToEvent
, /* wire_to_event */
117 __glXEventToWire
, /* event_to_wire */
119 __glXErrorString
, /* error_string */
122 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
123 __glXExtensionName
, &__glXExtensionHooks
,
124 __GLX_NUMBER_EVENTS
, NULL
)
127 * GLX events are a bit funky. We don't stuff the X event code into
128 * our user exposed (via XNextEvent) structure. Instead we use the GLX
129 * private event code namespace (and hope it doesn't conflict). Clients
130 * have to know that bit 15 in the event type field means they're getting
131 * a GLX event, and then handle the various sub-event types there, rather
132 * than simply checking the event code and handling it directly.
136 __glXWireToEvent(Display
*dpy
, XEvent
*event
, xEvent
*wire
)
138 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
140 XextCheckExtension(dpy
, info
, __glXExtensionName
, False
);
142 switch ((wire
->u
.u
.type
& 0x7f) - info
->codes
->first_event
) {
143 case GLX_PbufferClobber
:
145 GLXPbufferClobberEvent
*aevent
= (GLXPbufferClobberEvent
*)event
;
146 xGLXPbufferClobberEvent
*awire
= (xGLXPbufferClobberEvent
*)wire
;
147 aevent
->event_type
= awire
->type
;
148 aevent
->serial
= awire
->sequenceNumber
;
149 aevent
->event_type
= awire
->event_type
;
150 aevent
->draw_type
= awire
->draw_type
;
151 aevent
->drawable
= awire
->drawable
;
152 aevent
->buffer_mask
= awire
->buffer_mask
;
153 aevent
->aux_buffer
= awire
->aux_buffer
;
154 aevent
->x
= awire
->x
;
155 aevent
->y
= awire
->y
;
156 aevent
->width
= awire
->width
;
157 aevent
->height
= awire
->height
;
158 aevent
->count
= awire
->count
;
161 /* No easy symbol to test for this, as GLX_BufferSwapComplete is
162 * defined in the local glx.h header, but the
163 * xGLXBufferSwapComplete typedef is only available in new versions
164 * of the external glxproto.h header, which doesn't have any
165 * testable versioning define.
167 * I'll use the related DRI2 define, in the hope that we won't
168 * receive these events unless we know how to ask for them:
170 #ifdef X_DRI2SwapBuffers
171 case GLX_BufferSwapComplete
:
173 GLXBufferSwapComplete
*aevent
= (GLXBufferSwapComplete
*)event
;
174 xGLXBufferSwapComplete
*awire
= (xGLXBufferSwapComplete
*)wire
;
175 aevent
->event_type
= awire
->event_type
;
176 aevent
->drawable
= awire
->drawable
;
177 aevent
->ust
= ((CARD64
)awire
->ust_hi
<< 32) | awire
->ust_lo
;
178 aevent
->msc
= ((CARD64
)awire
->msc_hi
<< 32) | awire
->msc_lo
;
179 aevent
->sbc
= ((CARD64
)awire
->sbc_hi
<< 32) | awire
->sbc_lo
;
184 /* client doesn't support server event */
191 /* We don't actually support this. It doesn't make sense for clients to
192 * send each other GLX events.
195 __glXEventToWire(Display
*dpy
, XEvent
*event
, xEvent
*wire
)
197 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
199 XextCheckExtension(dpy
, info
, __glXExtensionName
, False
);
201 switch (event
->type
) {
206 case GLX_EXCHANGE_COMPLETE_INTEL
:
208 case GLX_BLIT_COMPLETE_INTEL
:
210 case GLX_FLIP_COMPLETE_INTEL
:
213 /* client doesn't support server event */
220 /************************************************************************/
222 ** Free the per screen configs data as well as the array of
223 ** __glXScreenConfigs.
226 FreeScreenConfigs(__GLXdisplayPrivate
* priv
)
228 __GLXscreenConfigs
*psc
;
231 /* Free screen configuration information */
232 psc
= priv
->screenConfigs
;
233 screens
= ScreenCount(priv
->dpy
);
234 for (i
= 0; i
< screens
; i
++, psc
++) {
236 _gl_context_modes_destroy(psc
->configs
);
237 if (psc
->effectiveGLXexts
)
238 Xfree(psc
->effectiveGLXexts
);
239 psc
->configs
= NULL
; /* NOTE: just for paranoia */
242 _gl_context_modes_destroy(psc
->visuals
);
243 psc
->visuals
= NULL
; /* NOTE: just for paranoia */
245 Xfree((char *) psc
->serverGLXexts
);
247 #ifdef GLX_DIRECT_RENDERING
248 if (psc
->driver_configs
) {
250 for (j
= 0; psc
->driver_configs
[j
]; j
++)
251 free((__DRIconfig
*) psc
->driver_configs
[j
]);
252 free(psc
->driver_configs
);
253 psc
->driver_configs
= NULL
;
255 if (psc
->driScreen
) {
256 psc
->driScreen
->destroyScreen(psc
);
257 __glxHashDestroy(psc
->drawHash
);
258 XFree(psc
->driScreen
);
259 psc
->driScreen
= NULL
;
263 XFree((char *) priv
->screenConfigs
);
264 priv
->screenConfigs
= NULL
;
268 ** Release the private memory referred to in a display private
269 ** structure. The caller will free the extension structure.
272 __glXFreeDisplayPrivate(XExtData
* extension
)
274 __GLXdisplayPrivate
*priv
;
276 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
277 FreeScreenConfigs(priv
);
278 if (priv
->serverGLXvendor
) {
279 Xfree((char *) priv
->serverGLXvendor
);
280 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
282 if (priv
->serverGLXversion
) {
283 Xfree((char *) priv
->serverGLXversion
);
284 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
287 #ifdef GLX_DIRECT_RENDERING
288 /* Free the direct rendering per display data */
289 if (priv
->driswDisplay
)
290 (*priv
->driswDisplay
->destroyDisplay
) (priv
->driswDisplay
);
291 priv
->driswDisplay
= NULL
;
293 if (priv
->driDisplay
)
294 (*priv
->driDisplay
->destroyDisplay
) (priv
->driDisplay
);
295 priv
->driDisplay
= NULL
;
297 if (priv
->dri2Display
)
298 (*priv
->dri2Display
->destroyDisplay
) (priv
->dri2Display
);
299 priv
->dri2Display
= NULL
;
302 Xfree((char *) priv
);
306 /************************************************************************/
309 ** Query the version of the GLX extension. This procedure works even if
310 ** the client extension is not completely set up.
313 QueryVersion(Display
* dpy
, int opcode
, int *major
, int *minor
)
316 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
317 xcb_glx_query_version_reply_t
*reply
= xcb_glx_query_version_reply(c
,
318 xcb_glx_query_version
324 if (reply
->major_version
!= GLX_MAJOR_VERSION
) {
328 *major
= reply
->major_version
;
329 *minor
= min(reply
->minor_version
, GLX_MINOR_VERSION
);
333 xGLXQueryVersionReq
*req
;
334 xGLXQueryVersionReply reply
;
336 /* Send the glXQueryVersion request */
338 GetReq(GLXQueryVersion
, req
);
339 req
->reqType
= opcode
;
340 req
->glxCode
= X_GLXQueryVersion
;
341 req
->majorVersion
= GLX_MAJOR_VERSION
;
342 req
->minorVersion
= GLX_MINOR_VERSION
;
343 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
347 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
349 ** The server does not support the same major release as this
354 *major
= reply
.majorVersion
;
355 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
362 __glXInitializeVisualConfigFromTags(__GLcontextModes
* config
, int count
,
363 const INT32
* bp
, Bool tagged_only
,
364 Bool fbconfig_style_tags
)
369 /* Copy in the first set of properties */
370 config
->visualID
= *bp
++;
372 config
->visualType
= _gl_convert_from_x_visual_type(*bp
++);
374 config
->rgbMode
= *bp
++;
376 config
->redBits
= *bp
++;
377 config
->greenBits
= *bp
++;
378 config
->blueBits
= *bp
++;
379 config
->alphaBits
= *bp
++;
380 config
->accumRedBits
= *bp
++;
381 config
->accumGreenBits
= *bp
++;
382 config
->accumBlueBits
= *bp
++;
383 config
->accumAlphaBits
= *bp
++;
385 config
->doubleBufferMode
= *bp
++;
386 config
->stereoMode
= *bp
++;
388 config
->rgbBits
= *bp
++;
389 config
->depthBits
= *bp
++;
390 config
->stencilBits
= *bp
++;
391 config
->numAuxBuffers
= *bp
++;
392 config
->level
= *bp
++;
394 count
-= __GLX_MIN_CONFIG_PROPS
;
398 ** Additional properties may be in a list at the end
399 ** of the reply. They are in pairs of property type
400 ** and property value.
403 #define FETCH_OR_SET(tag) \
404 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
406 for (i
= 0; i
< count
; i
+= 2) {
409 FETCH_OR_SET(rgbMode
);
411 case GLX_BUFFER_SIZE
:
412 config
->rgbBits
= *bp
++;
415 config
->level
= *bp
++;
417 case GLX_DOUBLEBUFFER
:
418 FETCH_OR_SET(doubleBufferMode
);
421 FETCH_OR_SET(stereoMode
);
423 case GLX_AUX_BUFFERS
:
424 config
->numAuxBuffers
= *bp
++;
427 config
->redBits
= *bp
++;
430 config
->greenBits
= *bp
++;
433 config
->blueBits
= *bp
++;
436 config
->alphaBits
= *bp
++;
439 config
->depthBits
= *bp
++;
441 case GLX_STENCIL_SIZE
:
442 config
->stencilBits
= *bp
++;
444 case GLX_ACCUM_RED_SIZE
:
445 config
->accumRedBits
= *bp
++;
447 case GLX_ACCUM_GREEN_SIZE
:
448 config
->accumGreenBits
= *bp
++;
450 case GLX_ACCUM_BLUE_SIZE
:
451 config
->accumBlueBits
= *bp
++;
453 case GLX_ACCUM_ALPHA_SIZE
:
454 config
->accumAlphaBits
= *bp
++;
456 case GLX_VISUAL_CAVEAT_EXT
:
457 config
->visualRating
= *bp
++;
459 case GLX_X_VISUAL_TYPE
:
460 config
->visualType
= *bp
++;
462 case GLX_TRANSPARENT_TYPE
:
463 config
->transparentPixel
= *bp
++;
465 case GLX_TRANSPARENT_INDEX_VALUE
:
466 config
->transparentIndex
= *bp
++;
468 case GLX_TRANSPARENT_RED_VALUE
:
469 config
->transparentRed
= *bp
++;
471 case GLX_TRANSPARENT_GREEN_VALUE
:
472 config
->transparentGreen
= *bp
++;
474 case GLX_TRANSPARENT_BLUE_VALUE
:
475 config
->transparentBlue
= *bp
++;
477 case GLX_TRANSPARENT_ALPHA_VALUE
:
478 config
->transparentAlpha
= *bp
++;
481 config
->visualID
= *bp
++;
483 case GLX_DRAWABLE_TYPE
:
484 config
->drawableType
= *bp
++;
486 case GLX_RENDER_TYPE
:
487 config
->renderType
= *bp
++;
489 case GLX_X_RENDERABLE
:
490 config
->xRenderable
= *bp
++;
492 case GLX_FBCONFIG_ID
:
493 config
->fbconfigID
= *bp
++;
495 case GLX_MAX_PBUFFER_WIDTH
:
496 config
->maxPbufferWidth
= *bp
++;
498 case GLX_MAX_PBUFFER_HEIGHT
:
499 config
->maxPbufferHeight
= *bp
++;
501 case GLX_MAX_PBUFFER_PIXELS
:
502 config
->maxPbufferPixels
= *bp
++;
504 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
505 config
->optimalPbufferWidth
= *bp
++;
507 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
508 config
->optimalPbufferHeight
= *bp
++;
510 case GLX_VISUAL_SELECT_GROUP_SGIX
:
511 config
->visualSelectGroup
= *bp
++;
513 case GLX_SWAP_METHOD_OML
:
514 config
->swapMethod
= *bp
++;
516 case GLX_SAMPLE_BUFFERS_SGIS
:
517 config
->sampleBuffers
= *bp
++;
519 case GLX_SAMPLES_SGIS
:
520 config
->samples
= *bp
++;
522 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
523 config
->bindToTextureRgb
= *bp
++;
525 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
526 config
->bindToTextureRgba
= *bp
++;
528 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
529 config
->bindToMipmapTexture
= *bp
++;
531 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
532 config
->bindToTextureTargets
= *bp
++;
534 case GLX_Y_INVERTED_EXT
:
535 config
->yInverted
= *bp
++;
546 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
548 config
->haveAccumBuffer
= ((config
->accumRedBits
+
549 config
->accumGreenBits
+
550 config
->accumBlueBits
+
551 config
->accumAlphaBits
) > 0);
552 config
->haveDepthBuffer
= (config
->depthBits
> 0);
553 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
556 static __GLcontextModes
*
557 createConfigsFromProperties(Display
* dpy
, int nvisuals
, int nprops
,
558 int screen
, GLboolean tagged_only
)
560 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
562 __GLcontextModes
*modes
, *m
;
568 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
570 /* Check number of properties */
571 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
574 /* Allocate memory for our config structure */
575 modes
= _gl_context_modes_create(nvisuals
, sizeof(__GLcontextModes
));
579 prop_size
= nprops
* __GLX_SIZE_INT32
;
580 if (prop_size
<= sizeof(buf
))
583 props
= Xmalloc(prop_size
);
585 /* Read each config structure and convert it into our format */
587 for (i
= 0; i
< nvisuals
; i
++) {
588 _XRead(dpy
, (char *) props
, prop_size
);
589 /* Older X servers don't send this so we default it here. */
590 m
->drawableType
= GLX_WINDOW_BIT
;
591 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
592 tagged_only
, GL_TRUE
);
604 getVisualConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
606 xGLXGetVisualConfigsReq
*req
;
607 __GLXscreenConfigs
*psc
;
608 xGLXGetVisualConfigsReply reply
;
612 psc
= priv
->screenConfigs
+ screen
;
614 GetReq(GLXGetVisualConfigs
, req
);
615 req
->reqType
= priv
->majorOpcode
;
616 req
->glxCode
= X_GLXGetVisualConfigs
;
617 req
->screen
= screen
;
619 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
622 psc
->visuals
= createConfigsFromProperties(dpy
,
629 return psc
->visuals
!= NULL
;
633 getFBConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
635 xGLXGetFBConfigsReq
*fb_req
;
636 xGLXGetFBConfigsSGIXReq
*sgi_req
;
637 xGLXVendorPrivateWithReplyReq
*vpreq
;
638 xGLXGetFBConfigsReply reply
;
639 __GLXscreenConfigs
*psc
;
641 psc
= priv
->screenConfigs
+ screen
;
643 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, GLX_EXTENSIONS
);
648 if (atof(priv
->serverGLXversion
) >= 1.3) {
649 GetReq(GLXGetFBConfigs
, fb_req
);
650 fb_req
->reqType
= priv
->majorOpcode
;
651 fb_req
->glxCode
= X_GLXGetFBConfigs
;
652 fb_req
->screen
= screen
;
654 else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
655 GetReqExtra(GLXVendorPrivateWithReply
,
656 sz_xGLXGetFBConfigsSGIXReq
+
657 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
658 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
659 sgi_req
->reqType
= priv
->majorOpcode
;
660 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
661 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
662 sgi_req
->screen
= screen
;
667 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
670 psc
->configs
= createConfigsFromProperties(dpy
,
672 reply
.numAttribs
* 2,
677 return psc
->configs
!= NULL
;
681 ** Allocate the memory for the per screen configs for each screen.
682 ** If that works then fetch the per screen configs data.
685 AllocAndFetchScreenConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
)
687 __GLXscreenConfigs
*psc
;
691 ** First allocate memory for the array of per screen configs.
693 screens
= ScreenCount(dpy
);
694 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
698 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
699 priv
->screenConfigs
= psc
;
701 priv
->serverGLXversion
=
702 __glXQueryServerString(dpy
, priv
->majorOpcode
, 0, GLX_VERSION
);
703 if (priv
->serverGLXversion
== NULL
) {
704 FreeScreenConfigs(priv
);
708 for (i
= 0; i
< screens
; i
++, psc
++) {
709 getVisualConfigs(dpy
, priv
, i
);
710 getFBConfigs(dpy
, priv
, i
);
712 #ifdef GLX_DIRECT_RENDERING
715 psc
->drawHash
= __glxHashCreate();
716 if (psc
->drawHash
== NULL
)
719 if (priv
->dri2Display
)
720 psc
->driScreen
= (*priv
->dri2Display
->createScreen
) (psc
, i
, priv
);
722 if (psc
->driScreen
== NULL
&& priv
->driDisplay
)
723 psc
->driScreen
= (*priv
->driDisplay
->createScreen
) (psc
, i
, priv
);
725 if (psc
->driScreen
== NULL
&& priv
->driswDisplay
)
726 psc
->driScreen
= (*priv
->driswDisplay
->createScreen
) (psc
, i
, priv
);
728 if (psc
->driScreen
== NULL
) {
729 __glxHashDestroy(psc
->drawHash
);
730 psc
->drawHash
= NULL
;
739 ** Initialize the client side extension code.
741 _X_HIDDEN __GLXdisplayPrivate
*
742 __glXInitialize(Display
* dpy
)
744 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
745 XExtData
**privList
, *private, *found
;
746 __GLXdisplayPrivate
*dpyPriv
;
747 XEDataObject dataObj
;
749 #ifdef GLX_DIRECT_RENDERING
750 Bool glx_direct
, glx_accel
;
753 /* The one and only long long lock */
756 if (!XextHasExtension(info
)) {
757 /* No GLX extension supported by this server. Oh well. */
759 XMissingExtension(dpy
, __glXExtensionName
);
763 /* See if a display private already exists. If so, return it */
764 dataObj
.display
= dpy
;
765 privList
= XEHeadOfExtensionList(dataObj
);
766 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
769 return (__GLXdisplayPrivate
*) found
->private_data
;
772 /* See if the versions are compatible */
773 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
774 /* The client and server do not agree on versions. Punt. */
780 ** Allocate memory for all the pieces needed for this buffer.
782 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
787 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
790 Xfree((char *) private);
795 ** Init the display private and then read in the screen config
796 ** structures from the server.
798 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
799 dpyPriv
->majorVersion
= major
;
800 dpyPriv
->minorVersion
= minor
;
803 dpyPriv
->serverGLXvendor
= 0x0;
804 dpyPriv
->serverGLXversion
= 0x0;
806 #ifdef GLX_DIRECT_RENDERING
807 glx_direct
= (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
);
808 glx_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
811 ** Initialize the direct rendering per display data and functions.
812 ** Note: This _must_ be done before calling any other DRI routines
813 ** (e.g., those called in AllocAndFetchScreenConfigs).
815 if (glx_direct
&& glx_accel
) {
816 dpyPriv
->dri2Display
= dri2CreateDisplay(dpy
);
817 dpyPriv
->driDisplay
= driCreateDisplay(dpy
);
820 dpyPriv
->driswDisplay
= driswCreateDisplay(dpy
);
823 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
825 Xfree((char *) dpyPriv
);
826 Xfree((char *) private);
831 ** Fill in the private structure. This is the actual structure that
832 ** hangs off of the Display structure. Our private structure is
833 ** referred to by this structure. Got that?
835 private->number
= info
->codes
->extension
;
837 private->free_private
= __glXFreeDisplayPrivate
;
838 private->private_data
= (char *) dpyPriv
;
839 XAddToExtensionList(privList
, private);
841 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
842 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
850 ** Setup for sending a GLX command on dpy. Make sure the extension is
851 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
854 __glXSetupForCommand(Display
* dpy
)
857 __GLXdisplayPrivate
*priv
;
859 /* If this thread has a current context, flush its rendering commands */
860 gc
= __glXGetCurrentContext();
861 if (gc
->currentDpy
) {
862 /* Flush rendering buffer of the current context, if any */
863 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
865 if (gc
->currentDpy
== dpy
) {
866 /* Use opcode from gc because its right */
867 return gc
->majorOpcode
;
871 ** Have to get info about argument dpy because it might be to
872 ** a different server
877 /* Forced to lookup extension via the slow initialize route */
878 priv
= __glXInitialize(dpy
);
882 return priv
->majorOpcode
;
886 * Flush the drawing command transport buffer.
888 * \param ctx Context whose transport buffer is to be flushed.
889 * \param pc Pointer to first unused buffer location.
892 * Modify this function to use \c ctx->pc instead of the explicit
896 __glXFlushRenderBuffer(__GLXcontext
* ctx
, GLubyte
* pc
)
898 Display
*const dpy
= ctx
->currentDpy
;
900 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
904 const GLint size
= pc
- ctx
->buf
;
906 if ((dpy
!= NULL
) && (size
> 0)) {
908 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
909 (const uint8_t *) ctx
->buf
);
911 /* Send the entire buffer as an X request */
913 GetReq(GLXRender
, req
);
914 req
->reqType
= ctx
->majorOpcode
;
915 req
->glxCode
= X_GLXRender
;
916 req
->contextTag
= ctx
->currentContextTag
;
917 req
->length
+= (size
+ 3) >> 2;
918 _XSend(dpy
, (char *) ctx
->buf
, size
);
924 /* Reset pointer and return it */
931 * Send a portion of a GLXRenderLarge command to the server. The advantage of
932 * this function over \c __glXSendLargeCommand is that callers can use the
933 * data buffer in the GLX context and may be able to avoid allocating an
934 * extra buffer. The disadvantage is the clients will have to do more
935 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
937 * \sa __glXSendLargeCommand
939 * \param gc GLX context
940 * \param requestNumber Which part of the whole command is this? The first
942 * \param totalRequests How many requests will there be?
943 * \param data Command data.
944 * \param dataLen Size, in bytes, of the command data.
947 __glXSendLargeChunk(__GLXcontext
* gc
, GLint requestNumber
,
948 GLint totalRequests
, const GLvoid
* data
, GLint dataLen
)
950 Display
*dpy
= gc
->currentDpy
;
952 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
953 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
,
954 totalRequests
, dataLen
, data
);
956 xGLXRenderLargeReq
*req
;
958 if (requestNumber
== 1) {
962 GetReq(GLXRenderLarge
, req
);
963 req
->reqType
= gc
->majorOpcode
;
964 req
->glxCode
= X_GLXRenderLarge
;
965 req
->contextTag
= gc
->currentContextTag
;
966 req
->length
+= (dataLen
+ 3) >> 2;
967 req
->requestNumber
= requestNumber
;
968 req
->requestTotal
= totalRequests
;
969 req
->dataBytes
= dataLen
;
970 Data(dpy
, data
, dataLen
);
972 if (requestNumber
== totalRequests
) {
981 * Send a command that is too large for the GLXRender protocol request.
983 * Send a large command, one that is too large for some reason to
984 * send using the GLXRender protocol request. One reason to send
985 * a large command is to avoid copying the data.
987 * \param ctx GLX context
988 * \param header Header data.
989 * \param headerLen Size, in bytes, of the header data. It is assumed that
990 * the header data will always be small enough to fit in
991 * a single X protocol packet.
992 * \param data Command data.
993 * \param dataLen Size, in bytes, of the command data.
996 __glXSendLargeCommand(__GLXcontext
* ctx
,
997 const GLvoid
* header
, GLint headerLen
,
998 const GLvoid
* data
, GLint dataLen
)
1001 GLint totalRequests
, requestNumber
;
1004 ** Calculate the maximum amount of data can be stuffed into a single
1005 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1006 ** packet size minus sz_xGLXRenderReq.
1008 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1009 totalRequests
= 1 + (dataLen
/ maxSize
);
1010 if (dataLen
% maxSize
)
1014 ** Send all of the command, except the large array, as one request.
1016 assert(headerLen
<= maxSize
);
1017 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1020 ** Send enough requests until the whole array is sent.
1022 for (requestNumber
= 2; requestNumber
<= (totalRequests
- 1);
1024 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1025 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1027 assert(dataLen
> 0);
1030 assert(dataLen
<= maxSize
);
1031 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1034 /************************************************************************/
1038 __glXDumpDrawBuffer(__GLXcontext
* ctx
)
1040 GLubyte
*p
= ctx
->buf
;
1041 GLubyte
*end
= ctx
->pc
;
1042 GLushort opcode
, length
;
1046 opcode
= *((GLushort
*) p
);
1047 length
= *((GLushort
*) (p
+ 2));
1048 printf("%2x: %5d: ", opcode
, length
);
1051 while (length
> 0) {
1052 printf("%08x ", *((unsigned *) p
));