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>
45 #include "glxextensions.h"
46 #include "glcontextmodes.h"
49 #include <X11/Xlib-xcb.h>
56 void __glXDumpDrawBuffer(__GLXcontext
* 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 char *__glXExtensionName
= GLX_EXTENSION_NAME
;
68 XExtensionInfo
*__glXExtensionInfo
= NULL
;
70 static /* const */ char *error_list
[] = {
76 "GLXBadCurrentWindow",
77 "GLXBadRenderRequest",
79 "GLXUnsupportedPrivateRequest",
82 "GLXBadCurrentDrawable",
87 __glXCloseDisplay(Display
* dpy
, XExtCodes
* codes
)
91 gc
= __glXGetCurrentContext();
92 if (dpy
== gc
->currentDpy
) {
93 __glXSetCurrentContextNull();
97 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
102 XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
103 __GLX_NUMBER_ERRORS
, error_list
)
105 static /* const */ XExtensionHooks __glXExtensionHooks
= {
106 NULL
, /* create_gc */
110 NULL
, /* create_font */
111 NULL
, /* free_font */
112 __glXCloseDisplay
, /* close_display */
113 NULL
, /* wire_to_event */
114 NULL
, /* event_to_wire */
116 __glXErrorString
, /* error_string */
120 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
121 __glXExtensionName
, &__glXExtensionHooks
,
122 __GLX_NUMBER_EVENTS
, NULL
)
124 /************************************************************************/
126 ** Free the per screen configs data as well as the array of
127 ** __glXScreenConfigs.
130 FreeScreenConfigs(__GLXdisplayPrivate
* priv
)
132 __GLXscreenConfigs
*psc
;
135 /* Free screen configuration information */
136 psc
= priv
->screenConfigs
;
137 screens
= ScreenCount(priv
->dpy
);
138 for (i
= 0; i
< screens
; i
++, psc
++) {
140 _gl_context_modes_destroy(psc
->configs
);
141 if (psc
->effectiveGLXexts
)
142 Xfree(psc
->effectiveGLXexts
);
143 psc
->configs
= NULL
; /* NOTE: just for paranoia */
146 _gl_context_modes_destroy(psc
->visuals
);
147 psc
->visuals
= NULL
; /* NOTE: just for paranoia */
149 Xfree((char *) psc
->serverGLXexts
);
151 #ifdef GLX_DIRECT_RENDERING
152 if (psc
->driScreen
) {
153 psc
->driScreen
->destroyScreen(psc
);
154 __glxHashDestroy(psc
->drawHash
);
155 XFree(psc
->driScreen
);
156 psc
->driScreen
= NULL
;
160 XFree((char *) priv
->screenConfigs
);
161 priv
->screenConfigs
= NULL
;
165 ** Release the private memory referred to in a display private
166 ** structure. The caller will free the extension structure.
169 __glXFreeDisplayPrivate(XExtData
* extension
)
171 __GLXdisplayPrivate
*priv
;
173 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
174 FreeScreenConfigs(priv
);
175 if (priv
->serverGLXvendor
) {
176 Xfree((char *) priv
->serverGLXvendor
);
177 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
179 if (priv
->serverGLXversion
) {
180 Xfree((char *) priv
->serverGLXversion
);
181 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
184 #ifdef GLX_DIRECT_RENDERING
185 /* Free the direct rendering per display data */
186 if (priv
->driswDisplay
)
187 (*priv
->driswDisplay
->destroyDisplay
) (priv
->driswDisplay
);
188 priv
->driswDisplay
= NULL
;
190 if (priv
->driDisplay
)
191 (*priv
->driDisplay
->destroyDisplay
) (priv
->driDisplay
);
192 priv
->driDisplay
= NULL
;
194 if (priv
->dri2Display
)
195 (*priv
->dri2Display
->destroyDisplay
) (priv
->dri2Display
);
196 priv
->dri2Display
= NULL
;
199 Xfree((char *) priv
);
203 /************************************************************************/
206 ** Query the version of the GLX extension. This procedure works even if
207 ** the client extension is not completely set up.
210 QueryVersion(Display
* dpy
, int opcode
, int *major
, int *minor
)
213 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
214 xcb_glx_query_version_reply_t
* reply
=
215 xcb_glx_query_version_reply(c
,
216 xcb_glx_query_version(c
,
221 if(reply
->major_version
!= GLX_MAJOR_VERSION
)
226 *major
= reply
->major_version
;
227 *minor
= min(reply
->minor_version
, GLX_MINOR_VERSION
);
231 xGLXQueryVersionReq
*req
;
232 xGLXQueryVersionReply reply
;
234 /* Send the glXQueryVersion request */
236 GetReq(GLXQueryVersion
, req
);
237 req
->reqType
= opcode
;
238 req
->glxCode
= X_GLXQueryVersion
;
239 req
->majorVersion
= GLX_MAJOR_VERSION
;
240 req
->minorVersion
= GLX_MINOR_VERSION
;
241 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
245 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
247 ** The server does not support the same major release as this
252 *major
= reply
.majorVersion
;
253 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
260 __glXInitializeVisualConfigFromTags(__GLcontextModes
* config
, int count
,
261 const INT32
* bp
, Bool tagged_only
,
262 Bool fbconfig_style_tags
)
267 /* Copy in the first set of properties */
268 config
->visualID
= *bp
++;
270 config
->visualType
= _gl_convert_from_x_visual_type(*bp
++);
272 config
->rgbMode
= *bp
++;
274 config
->redBits
= *bp
++;
275 config
->greenBits
= *bp
++;
276 config
->blueBits
= *bp
++;
277 config
->alphaBits
= *bp
++;
278 config
->accumRedBits
= *bp
++;
279 config
->accumGreenBits
= *bp
++;
280 config
->accumBlueBits
= *bp
++;
281 config
->accumAlphaBits
= *bp
++;
283 config
->doubleBufferMode
= *bp
++;
284 config
->stereoMode
= *bp
++;
286 config
->rgbBits
= *bp
++;
287 config
->depthBits
= *bp
++;
288 config
->stencilBits
= *bp
++;
289 config
->numAuxBuffers
= *bp
++;
290 config
->level
= *bp
++;
292 count
-= __GLX_MIN_CONFIG_PROPS
;
296 ** Additional properties may be in a list at the end
297 ** of the reply. They are in pairs of property type
298 ** and property value.
301 #define FETCH_OR_SET(tag) \
302 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
304 for (i
= 0; i
< count
; i
+= 2) {
307 FETCH_OR_SET(rgbMode
);
309 case GLX_BUFFER_SIZE
:
310 config
->rgbBits
= *bp
++;
313 config
->level
= *bp
++;
315 case GLX_DOUBLEBUFFER
:
316 FETCH_OR_SET(doubleBufferMode
);
319 FETCH_OR_SET(stereoMode
);
321 case GLX_AUX_BUFFERS
:
322 config
->numAuxBuffers
= *bp
++;
325 config
->redBits
= *bp
++;
328 config
->greenBits
= *bp
++;
331 config
->blueBits
= *bp
++;
334 config
->alphaBits
= *bp
++;
337 config
->depthBits
= *bp
++;
339 case GLX_STENCIL_SIZE
:
340 config
->stencilBits
= *bp
++;
342 case GLX_ACCUM_RED_SIZE
:
343 config
->accumRedBits
= *bp
++;
345 case GLX_ACCUM_GREEN_SIZE
:
346 config
->accumGreenBits
= *bp
++;
348 case GLX_ACCUM_BLUE_SIZE
:
349 config
->accumBlueBits
= *bp
++;
351 case GLX_ACCUM_ALPHA_SIZE
:
352 config
->accumAlphaBits
= *bp
++;
354 case GLX_VISUAL_CAVEAT_EXT
:
355 config
->visualRating
= *bp
++;
357 case GLX_X_VISUAL_TYPE
:
358 config
->visualType
= *bp
++;
360 case GLX_TRANSPARENT_TYPE
:
361 config
->transparentPixel
= *bp
++;
363 case GLX_TRANSPARENT_INDEX_VALUE
:
364 config
->transparentIndex
= *bp
++;
366 case GLX_TRANSPARENT_RED_VALUE
:
367 config
->transparentRed
= *bp
++;
369 case GLX_TRANSPARENT_GREEN_VALUE
:
370 config
->transparentGreen
= *bp
++;
372 case GLX_TRANSPARENT_BLUE_VALUE
:
373 config
->transparentBlue
= *bp
++;
375 case GLX_TRANSPARENT_ALPHA_VALUE
:
376 config
->transparentAlpha
= *bp
++;
379 config
->visualID
= *bp
++;
381 case GLX_DRAWABLE_TYPE
:
382 config
->drawableType
= *bp
++;
384 case GLX_RENDER_TYPE
:
385 config
->renderType
= *bp
++;
387 case GLX_X_RENDERABLE
:
388 config
->xRenderable
= *bp
++;
390 case GLX_FBCONFIG_ID
:
391 config
->fbconfigID
= *bp
++;
393 case GLX_MAX_PBUFFER_WIDTH
:
394 config
->maxPbufferWidth
= *bp
++;
396 case GLX_MAX_PBUFFER_HEIGHT
:
397 config
->maxPbufferHeight
= *bp
++;
399 case GLX_MAX_PBUFFER_PIXELS
:
400 config
->maxPbufferPixels
= *bp
++;
402 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
403 config
->optimalPbufferWidth
= *bp
++;
405 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
406 config
->optimalPbufferHeight
= *bp
++;
408 case GLX_VISUAL_SELECT_GROUP_SGIX
:
409 config
->visualSelectGroup
= *bp
++;
411 case GLX_SWAP_METHOD_OML
:
412 config
->swapMethod
= *bp
++;
414 case GLX_SAMPLE_BUFFERS_SGIS
:
415 config
->sampleBuffers
= *bp
++;
417 case GLX_SAMPLES_SGIS
:
418 config
->samples
= *bp
++;
420 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
421 config
->bindToTextureRgb
= *bp
++;
423 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
424 config
->bindToTextureRgba
= *bp
++;
426 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
427 config
->bindToMipmapTexture
= *bp
++;
429 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
430 config
->bindToTextureTargets
= *bp
++;
432 case GLX_Y_INVERTED_EXT
:
433 config
->yInverted
= *bp
++;
444 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
446 config
->haveAccumBuffer
= ((config
->accumRedBits
+
447 config
->accumGreenBits
+
448 config
->accumBlueBits
+
449 config
->accumAlphaBits
) > 0);
450 config
->haveDepthBuffer
= (config
->depthBits
> 0);
451 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
454 static __GLcontextModes
*
455 createConfigsFromProperties(Display
* dpy
, int nvisuals
, int nprops
,
456 int screen
, GLboolean tagged_only
)
458 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
460 __GLcontextModes
*modes
, *m
;
466 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
468 /* Check number of properties */
469 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
472 /* Allocate memory for our config structure */
473 modes
= _gl_context_modes_create(nvisuals
, sizeof(__GLcontextModes
));
477 prop_size
= nprops
* __GLX_SIZE_INT32
;
478 if (prop_size
<= sizeof(buf
))
481 props
= Xmalloc(prop_size
);
483 /* Read each config structure and convert it into our format */
485 for (i
= 0; i
< nvisuals
; i
++) {
486 _XRead(dpy
, (char *) props
, prop_size
);
487 /* Older X servers don't send this so we default it here. */
488 m
->drawableType
= GLX_WINDOW_BIT
;
489 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
490 tagged_only
, GL_TRUE
);
502 getVisualConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
504 xGLXGetVisualConfigsReq
*req
;
505 __GLXscreenConfigs
*psc
;
506 xGLXGetVisualConfigsReply reply
;
510 psc
= priv
->screenConfigs
+ screen
;
512 GetReq(GLXGetVisualConfigs
, req
);
513 req
->reqType
= priv
->majorOpcode
;
514 req
->glxCode
= X_GLXGetVisualConfigs
;
515 req
->screen
= screen
;
517 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
520 psc
->visuals
= createConfigsFromProperties(dpy
,
527 return psc
->visuals
!= NULL
;
531 getFBConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
533 xGLXGetFBConfigsReq
*fb_req
;
534 xGLXGetFBConfigsSGIXReq
*sgi_req
;
535 xGLXVendorPrivateWithReplyReq
*vpreq
;
536 xGLXGetFBConfigsReply reply
;
537 __GLXscreenConfigs
*psc
;
539 psc
= priv
->screenConfigs
+ screen
;
540 psc
->serverGLXexts
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, GLX_EXTENSIONS
);
545 if (atof(priv
->serverGLXversion
) >= 1.3) {
546 GetReq(GLXGetFBConfigs
, fb_req
);
547 fb_req
->reqType
= priv
->majorOpcode
;
548 fb_req
->glxCode
= X_GLXGetFBConfigs
;
549 fb_req
->screen
= screen
;
551 else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
552 GetReqExtra(GLXVendorPrivateWithReply
,
553 sz_xGLXGetFBConfigsSGIXReq
+
554 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
555 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
556 sgi_req
->reqType
= priv
->majorOpcode
;
557 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
558 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
559 sgi_req
->screen
= screen
;
564 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
567 psc
->configs
= createConfigsFromProperties(dpy
,
569 reply
.numAttribs
* 2,
574 return psc
->configs
!= NULL
;
578 ** Allocate the memory for the per screen configs for each screen.
579 ** If that works then fetch the per screen configs data.
582 AllocAndFetchScreenConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
)
584 __GLXscreenConfigs
*psc
;
588 ** First allocate memory for the array of per screen configs.
590 screens
= ScreenCount(dpy
);
591 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
595 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
596 priv
->screenConfigs
= psc
;
598 priv
->serverGLXversion
= __glXQueryServerString(dpy
, priv
->majorOpcode
, 0, GLX_VERSION
);
599 if (priv
->serverGLXversion
== NULL
) {
600 FreeScreenConfigs(priv
);
604 for (i
= 0; i
< screens
; i
++, psc
++) {
605 getVisualConfigs(dpy
, priv
, i
);
606 getFBConfigs(dpy
, priv
, i
);
608 #ifdef GLX_DIRECT_RENDERING
611 psc
->drawHash
= __glxHashCreate();
612 if (psc
->drawHash
== NULL
)
615 if (priv
->dri2Display
)
616 psc
->driScreen
= (*priv
->dri2Display
->createScreen
) (psc
, i
, priv
);
618 if (psc
->driScreen
== NULL
&& priv
->driDisplay
)
619 psc
->driScreen
= (*priv
->driDisplay
->createScreen
) (psc
, i
, priv
);
621 if (psc
->driScreen
== NULL
&& priv
->driswDisplay
)
622 psc
->driScreen
= (*priv
->driswDisplay
->createScreen
) (psc
, i
, priv
);
624 if (psc
->driScreen
== NULL
) {
625 __glxHashDestroy(psc
->drawHash
);
626 psc
->drawHash
= NULL
;
635 ** Initialize the client side extension code.
637 _X_HIDDEN __GLXdisplayPrivate
*
638 __glXInitialize(Display
* dpy
)
640 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
641 XExtData
**privList
, *private, *found
;
642 __GLXdisplayPrivate
*dpyPriv
;
643 XEDataObject dataObj
;
645 #ifdef GLX_DIRECT_RENDERING
646 Bool glx_direct
, glx_accel
;
649 #if defined(USE_XTHREADS)
651 static int firstCall
= 1;
653 /* initialize the GLX mutexes */
654 xmutex_init(&__glXmutex
);
660 /* The one and only long long lock */
663 if (!XextHasExtension(info
)) {
664 /* No GLX extension supported by this server. Oh well. */
666 XMissingExtension(dpy
, __glXExtensionName
);
670 /* See if a display private already exists. If so, return it */
671 dataObj
.display
= dpy
;
672 privList
= XEHeadOfExtensionList(dataObj
);
673 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
676 return (__GLXdisplayPrivate
*) found
->private_data
;
679 /* See if the versions are compatible */
680 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
681 /* The client and server do not agree on versions. Punt. */
687 ** Allocate memory for all the pieces needed for this buffer.
689 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
694 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
697 Xfree((char *) private);
702 ** Init the display private and then read in the screen config
703 ** structures from the server.
705 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
706 dpyPriv
->majorVersion
= major
;
707 dpyPriv
->minorVersion
= minor
;
710 dpyPriv
->serverGLXvendor
= 0x0;
711 dpyPriv
->serverGLXversion
= 0x0;
713 #ifdef GLX_DIRECT_RENDERING
714 glx_direct
= (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
);
715 glx_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
718 ** Initialize the direct rendering per display data and functions.
719 ** Note: This _must_ be done before calling any other DRI routines
720 ** (e.g., those called in AllocAndFetchScreenConfigs).
722 if (glx_direct
&& glx_accel
) {
723 dpyPriv
->dri2Display
= dri2CreateDisplay(dpy
);
724 dpyPriv
->driDisplay
= driCreateDisplay(dpy
);
727 dpyPriv
->driswDisplay
= driswCreateDisplay(dpy
);
730 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
732 Xfree((char *) dpyPriv
);
733 Xfree((char *) private);
738 ** Fill in the private structure. This is the actual structure that
739 ** hangs off of the Display structure. Our private structure is
740 ** referred to by this structure. Got that?
742 private->number
= info
->codes
->extension
;
744 private->free_private
= __glXFreeDisplayPrivate
;
745 private->private_data
= (char *) dpyPriv
;
746 XAddToExtensionList(privList
, private);
748 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
749 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
757 ** Setup for sending a GLX command on dpy. Make sure the extension is
758 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
761 __glXSetupForCommand(Display
* dpy
)
764 __GLXdisplayPrivate
*priv
;
766 /* If this thread has a current context, flush its rendering commands */
767 gc
= __glXGetCurrentContext();
768 if (gc
->currentDpy
) {
769 /* Flush rendering buffer of the current context, if any */
770 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
772 if (gc
->currentDpy
== dpy
) {
773 /* Use opcode from gc because its right */
774 return gc
->majorOpcode
;
778 ** Have to get info about argument dpy because it might be to
779 ** a different server
784 /* Forced to lookup extension via the slow initialize route */
785 priv
= __glXInitialize(dpy
);
789 return priv
->majorOpcode
;
793 * Flush the drawing command transport buffer.
795 * \param ctx Context whose transport buffer is to be flushed.
796 * \param pc Pointer to first unused buffer location.
799 * Modify this function to use \c ctx->pc instead of the explicit
803 __glXFlushRenderBuffer(__GLXcontext
* ctx
, GLubyte
* pc
)
805 Display
*const dpy
= ctx
->currentDpy
;
807 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
811 const GLint size
= pc
- ctx
->buf
;
813 if ((dpy
!= NULL
) && (size
> 0)) {
815 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
816 (const uint8_t *) ctx
->buf
);
818 /* Send the entire buffer as an X request */
820 GetReq(GLXRender
, req
);
821 req
->reqType
= ctx
->majorOpcode
;
822 req
->glxCode
= X_GLXRender
;
823 req
->contextTag
= ctx
->currentContextTag
;
824 req
->length
+= (size
+ 3) >> 2;
825 _XSend(dpy
, (char *) ctx
->buf
, size
);
831 /* Reset pointer and return it */
838 * Send a portion of a GLXRenderLarge command to the server. The advantage of
839 * this function over \c __glXSendLargeCommand is that callers can use the
840 * data buffer in the GLX context and may be able to avoid allocating an
841 * extra buffer. The disadvantage is the clients will have to do more
842 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
844 * \sa __glXSendLargeCommand
846 * \param gc GLX context
847 * \param requestNumber Which part of the whole command is this? The first
849 * \param totalRequests How many requests will there be?
850 * \param data Command data.
851 * \param dataLen Size, in bytes, of the command data.
854 __glXSendLargeChunk(__GLXcontext
* gc
, GLint requestNumber
,
855 GLint totalRequests
, const GLvoid
* data
, GLint dataLen
)
857 Display
*dpy
= gc
->currentDpy
;
859 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
860 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
,
861 totalRequests
, dataLen
, data
);
863 xGLXRenderLargeReq
*req
;
865 if (requestNumber
== 1) {
869 GetReq(GLXRenderLarge
, req
);
870 req
->reqType
= gc
->majorOpcode
;
871 req
->glxCode
= X_GLXRenderLarge
;
872 req
->contextTag
= gc
->currentContextTag
;
873 req
->length
+= (dataLen
+ 3) >> 2;
874 req
->requestNumber
= requestNumber
;
875 req
->requestTotal
= totalRequests
;
876 req
->dataBytes
= dataLen
;
877 Data(dpy
, data
, dataLen
);
879 if (requestNumber
== totalRequests
) {
888 * Send a command that is too large for the GLXRender protocol request.
890 * Send a large command, one that is too large for some reason to
891 * send using the GLXRender protocol request. One reason to send
892 * a large command is to avoid copying the data.
894 * \param ctx GLX context
895 * \param header Header data.
896 * \param headerLen Size, in bytes, of the header data. It is assumed that
897 * the header data will always be small enough to fit in
898 * a single X protocol packet.
899 * \param data Command data.
900 * \param dataLen Size, in bytes, of the command data.
903 __glXSendLargeCommand(__GLXcontext
* ctx
,
904 const GLvoid
* header
, GLint headerLen
,
905 const GLvoid
* data
, GLint dataLen
)
908 GLint totalRequests
, requestNumber
;
911 ** Calculate the maximum amount of data can be stuffed into a single
912 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
913 ** packet size minus sz_xGLXRenderReq.
915 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
916 totalRequests
= 1 + (dataLen
/ maxSize
);
917 if (dataLen
% maxSize
)
921 ** Send all of the command, except the large array, as one request.
923 assert(headerLen
<= maxSize
);
924 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
927 ** Send enough requests until the whole array is sent.
929 for (requestNumber
= 2; requestNumber
<= (totalRequests
- 1);
931 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
932 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
937 assert(dataLen
<= maxSize
);
938 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
941 /************************************************************************/
945 __glXDumpDrawBuffer(__GLXcontext
* ctx
)
947 GLubyte
*p
= ctx
->buf
;
948 GLubyte
*end
= ctx
->pc
;
949 GLushort opcode
, length
;
953 opcode
= *((GLushort
*) p
);
954 length
= *((GLushort
*) (p
+ 2));
955 printf("%2x: %5d: ", opcode
, length
);
959 printf("%08x ", *((unsigned *) p
));