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 static void _glx_mesa_init_sparc_glapi_relocs(void);
61 static int _mesa_sparc_needs_init
= 1;
62 #define INIT_MESA_SPARC do { \
63 if (_mesa_sparc_needs_init) { \
64 _glx_mesa_init_sparc_glapi_relocs(); \
65 _mesa_sparc_needs_init = 0; \
69 #define INIT_MESA_SPARC do { } while(0)
73 ** You can set this cell to 1 to force the gl drawing stuff to be
74 ** one command per packet
76 _X_HIDDEN
int __glXDebug
= 0;
78 /* Extension required boiler plate */
80 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
81 XExtensionInfo
*__glXExtensionInfo
= NULL
;
83 static /* const */ char *error_list
[] = {
89 "GLXBadCurrentWindow",
90 "GLXBadRenderRequest",
92 "GLXUnsupportedPrivateRequest",
95 "GLXBadCurrentDrawable",
100 __glXCloseDisplay(Display
* dpy
, XExtCodes
* codes
)
104 gc
= __glXGetCurrentContext();
105 if (dpy
== gc
->currentDpy
) {
106 __glXSetCurrentContextNull();
107 __glXFreeContext(gc
);
110 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
115 XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
116 __GLX_NUMBER_ERRORS
, error_list
)
118 static /* const */ XExtensionHooks __glXExtensionHooks
= {
119 NULL
, /* create_gc */
123 NULL
, /* create_font */
124 NULL
, /* free_font */
125 __glXCloseDisplay
, /* close_display */
126 NULL
, /* wire_to_event */
127 NULL
, /* event_to_wire */
129 __glXErrorString
, /* error_string */
133 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
134 __glXExtensionName
, &__glXExtensionHooks
,
135 __GLX_NUMBER_EVENTS
, NULL
)
137 /************************************************************************/
139 ** Free the per screen configs data as well as the array of
140 ** __glXScreenConfigs.
142 static void FreeScreenConfigs(__GLXdisplayPrivate
* priv
)
144 __GLXscreenConfigs
*psc
;
147 /* Free screen configuration information */
148 psc
= priv
->screenConfigs
;
149 screens
= ScreenCount(priv
->dpy
);
150 for (i
= 0; i
< screens
; i
++, psc
++) {
152 _gl_context_modes_destroy(psc
->configs
);
153 if (psc
->effectiveGLXexts
)
154 Xfree(psc
->effectiveGLXexts
);
155 psc
->configs
= NULL
; /* NOTE: just for paranoia */
158 _gl_context_modes_destroy(psc
->visuals
);
159 psc
->visuals
= NULL
; /* NOTE: just for paranoia */
161 Xfree((char *) psc
->serverGLXexts
);
163 #ifdef GLX_DIRECT_RENDERING
164 if (psc
->driScreen
) {
165 psc
->driScreen
->destroyScreen(psc
);
166 __glxHashDestroy(psc
->drawHash
);
167 XFree(psc
->driScreen
);
168 psc
->driScreen
= NULL
;
172 XFree((char *) priv
->screenConfigs
);
173 priv
->screenConfigs
= NULL
;
177 ** Release the private memory referred to in a display private
178 ** structure. The caller will free the extension structure.
181 __glXFreeDisplayPrivate(XExtData
* extension
)
183 __GLXdisplayPrivate
*priv
;
185 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
186 FreeScreenConfigs(priv
);
187 if (priv
->serverGLXvendor
) {
188 Xfree((char *) priv
->serverGLXvendor
);
189 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
191 if (priv
->serverGLXversion
) {
192 Xfree((char *) priv
->serverGLXversion
);
193 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
196 #ifdef GLX_DIRECT_RENDERING
197 /* Free the direct rendering per display data */
198 if (priv
->driswDisplay
)
199 (*priv
->driswDisplay
->destroyDisplay
) (priv
->driswDisplay
);
200 priv
->driswDisplay
= NULL
;
202 if (priv
->driDisplay
)
203 (*priv
->driDisplay
->destroyDisplay
) (priv
->driDisplay
);
204 priv
->driDisplay
= NULL
;
206 if (priv
->dri2Display
)
207 (*priv
->dri2Display
->destroyDisplay
) (priv
->dri2Display
);
208 priv
->dri2Display
= NULL
;
211 Xfree((char *) priv
);
215 /************************************************************************/
218 ** Query the version of the GLX extension. This procedure works even if
219 ** the client extension is not completely set up.
222 QueryVersion(Display
* dpy
, int opcode
, int *major
, int *minor
)
224 xGLXQueryVersionReq
*req
;
225 xGLXQueryVersionReply reply
;
227 /* Send the glXQueryVersion request */
229 GetReq(GLXQueryVersion
, req
);
230 req
->reqType
= opcode
;
231 req
->glxCode
= X_GLXQueryVersion
;
232 req
->majorVersion
= GLX_MAJOR_VERSION
;
233 req
->minorVersion
= GLX_MINOR_VERSION
;
234 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
238 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
240 ** The server does not support the same major release as this
245 *major
= reply
.majorVersion
;
246 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
252 __glXInitializeVisualConfigFromTags(__GLcontextModes
* config
, int count
,
253 const INT32
* bp
, Bool tagged_only
,
254 Bool fbconfig_style_tags
)
259 /* Copy in the first set of properties */
260 config
->visualID
= *bp
++;
262 config
->visualType
= _gl_convert_from_x_visual_type(*bp
++);
264 config
->rgbMode
= *bp
++;
266 config
->redBits
= *bp
++;
267 config
->greenBits
= *bp
++;
268 config
->blueBits
= *bp
++;
269 config
->alphaBits
= *bp
++;
270 config
->accumRedBits
= *bp
++;
271 config
->accumGreenBits
= *bp
++;
272 config
->accumBlueBits
= *bp
++;
273 config
->accumAlphaBits
= *bp
++;
275 config
->doubleBufferMode
= *bp
++;
276 config
->stereoMode
= *bp
++;
278 config
->rgbBits
= *bp
++;
279 config
->depthBits
= *bp
++;
280 config
->stencilBits
= *bp
++;
281 config
->numAuxBuffers
= *bp
++;
282 config
->level
= *bp
++;
284 count
-= __GLX_MIN_CONFIG_PROPS
;
288 ** Additional properties may be in a list at the end
289 ** of the reply. They are in pairs of property type
290 ** and property value.
293 #define FETCH_OR_SET(tag) \
294 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
296 for (i
= 0; i
< count
; i
+= 2) {
299 FETCH_OR_SET(rgbMode
);
301 case GLX_BUFFER_SIZE
:
302 config
->rgbBits
= *bp
++;
305 config
->level
= *bp
++;
307 case GLX_DOUBLEBUFFER
:
308 FETCH_OR_SET(doubleBufferMode
);
311 FETCH_OR_SET(stereoMode
);
313 case GLX_AUX_BUFFERS
:
314 config
->numAuxBuffers
= *bp
++;
317 config
->redBits
= *bp
++;
320 config
->greenBits
= *bp
++;
323 config
->blueBits
= *bp
++;
326 config
->alphaBits
= *bp
++;
329 config
->depthBits
= *bp
++;
331 case GLX_STENCIL_SIZE
:
332 config
->stencilBits
= *bp
++;
334 case GLX_ACCUM_RED_SIZE
:
335 config
->accumRedBits
= *bp
++;
337 case GLX_ACCUM_GREEN_SIZE
:
338 config
->accumGreenBits
= *bp
++;
340 case GLX_ACCUM_BLUE_SIZE
:
341 config
->accumBlueBits
= *bp
++;
343 case GLX_ACCUM_ALPHA_SIZE
:
344 config
->accumAlphaBits
= *bp
++;
346 case GLX_VISUAL_CAVEAT_EXT
:
347 config
->visualRating
= *bp
++;
349 case GLX_X_VISUAL_TYPE
:
350 config
->visualType
= *bp
++;
352 case GLX_TRANSPARENT_TYPE
:
353 config
->transparentPixel
= *bp
++;
355 case GLX_TRANSPARENT_INDEX_VALUE
:
356 config
->transparentIndex
= *bp
++;
358 case GLX_TRANSPARENT_RED_VALUE
:
359 config
->transparentRed
= *bp
++;
361 case GLX_TRANSPARENT_GREEN_VALUE
:
362 config
->transparentGreen
= *bp
++;
364 case GLX_TRANSPARENT_BLUE_VALUE
:
365 config
->transparentBlue
= *bp
++;
367 case GLX_TRANSPARENT_ALPHA_VALUE
:
368 config
->transparentAlpha
= *bp
++;
371 config
->visualID
= *bp
++;
373 case GLX_DRAWABLE_TYPE
:
374 config
->drawableType
= *bp
++;
376 case GLX_RENDER_TYPE
:
377 config
->renderType
= *bp
++;
379 case GLX_X_RENDERABLE
:
380 config
->xRenderable
= *bp
++;
382 case GLX_FBCONFIG_ID
:
383 config
->fbconfigID
= *bp
++;
385 case GLX_MAX_PBUFFER_WIDTH
:
386 config
->maxPbufferWidth
= *bp
++;
388 case GLX_MAX_PBUFFER_HEIGHT
:
389 config
->maxPbufferHeight
= *bp
++;
391 case GLX_MAX_PBUFFER_PIXELS
:
392 config
->maxPbufferPixels
= *bp
++;
394 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
395 config
->optimalPbufferWidth
= *bp
++;
397 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
398 config
->optimalPbufferHeight
= *bp
++;
400 case GLX_VISUAL_SELECT_GROUP_SGIX
:
401 config
->visualSelectGroup
= *bp
++;
403 case GLX_SWAP_METHOD_OML
:
404 config
->swapMethod
= *bp
++;
406 case GLX_SAMPLE_BUFFERS_SGIS
:
407 config
->sampleBuffers
= *bp
++;
409 case GLX_SAMPLES_SGIS
:
410 config
->samples
= *bp
++;
412 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
413 config
->bindToTextureRgb
= *bp
++;
415 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
416 config
->bindToTextureRgba
= *bp
++;
418 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
419 config
->bindToMipmapTexture
= *bp
++;
421 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
422 config
->bindToTextureTargets
= *bp
++;
424 case GLX_Y_INVERTED_EXT
:
425 config
->yInverted
= *bp
++;
436 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
438 config
->haveAccumBuffer
= ((config
->accumRedBits
+
439 config
->accumGreenBits
+
440 config
->accumBlueBits
+
441 config
->accumAlphaBits
) > 0);
442 config
->haveDepthBuffer
= (config
->depthBits
> 0);
443 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
446 static __GLcontextModes
*
447 createConfigsFromProperties(Display
* dpy
, int nvisuals
, int nprops
,
448 int screen
, GLboolean tagged_only
)
450 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
452 __GLcontextModes
*modes
, *m
;
458 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
460 /* Check number of properties */
461 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
464 /* Allocate memory for our config structure */
465 modes
= _gl_context_modes_create(nvisuals
, sizeof(__GLcontextModes
));
469 prop_size
= nprops
* __GLX_SIZE_INT32
;
470 if (prop_size
<= sizeof(buf
))
473 props
= Xmalloc(prop_size
);
475 /* Read each config structure and convert it into our format */
477 for (i
= 0; i
< nvisuals
; i
++) {
478 _XRead(dpy
, (char *) props
, prop_size
);
479 /* Older X servers don't send this so we default it here. */
480 m
->drawableType
= GLX_WINDOW_BIT
;
481 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
482 tagged_only
, GL_TRUE
);
494 getVisualConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
496 xGLXGetVisualConfigsReq
*req
;
497 __GLXscreenConfigs
*psc
;
498 xGLXGetVisualConfigsReply reply
;
502 psc
= priv
->screenConfigs
+ screen
;
504 GetReq(GLXGetVisualConfigs
, req
);
505 req
->reqType
= priv
->majorOpcode
;
506 req
->glxCode
= X_GLXGetVisualConfigs
;
507 req
->screen
= screen
;
509 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
512 psc
->visuals
= createConfigsFromProperties(dpy
,
519 return psc
->visuals
!= NULL
;
523 getFBConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
525 xGLXGetFBConfigsReq
*fb_req
;
526 xGLXGetFBConfigsSGIXReq
*sgi_req
;
527 xGLXVendorPrivateWithReplyReq
*vpreq
;
528 xGLXGetFBConfigsReply reply
;
529 __GLXscreenConfigs
*psc
;
531 psc
= priv
->screenConfigs
+ screen
;
532 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
533 X_GLXQueryServerString
,
534 screen
, GLX_EXTENSIONS
);
539 if (atof(priv
->serverGLXversion
) >= 1.3) {
540 GetReq(GLXGetFBConfigs
, fb_req
);
541 fb_req
->reqType
= priv
->majorOpcode
;
542 fb_req
->glxCode
= X_GLXGetFBConfigs
;
543 fb_req
->screen
= screen
;
545 else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
546 GetReqExtra(GLXVendorPrivateWithReply
,
547 sz_xGLXGetFBConfigsSGIXReq
+
548 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
549 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
550 sgi_req
->reqType
= priv
->majorOpcode
;
551 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
552 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
553 sgi_req
->screen
= screen
;
558 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
561 psc
->configs
= createConfigsFromProperties(dpy
,
563 reply
.numAttribs
* 2,
568 return psc
->configs
!= NULL
;
572 ** Allocate the memory for the per screen configs for each screen.
573 ** If that works then fetch the per screen configs data.
576 AllocAndFetchScreenConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
)
578 __GLXscreenConfigs
*psc
;
582 ** First allocate memory for the array of per screen configs.
584 screens
= ScreenCount(dpy
);
585 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
589 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
590 priv
->screenConfigs
= psc
;
592 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
593 X_GLXQueryServerString
,
595 if (priv
->serverGLXversion
== NULL
) {
596 FreeScreenConfigs(priv
);
600 for (i
= 0; i
< screens
; i
++, psc
++) {
601 getVisualConfigs(dpy
, priv
, i
);
602 getFBConfigs(dpy
, priv
, i
);
604 #ifdef GLX_DIRECT_RENDERING
607 psc
->drawHash
= __glxHashCreate();
608 if (psc
->drawHash
== NULL
)
611 if (priv
->dri2Display
)
612 psc
->driScreen
= (*priv
->dri2Display
->createScreen
) (psc
, i
, priv
);
614 if (psc
->driScreen
== NULL
&& priv
->driDisplay
)
615 psc
->driScreen
= (*priv
->driDisplay
->createScreen
) (psc
, i
, priv
);
617 if (psc
->driScreen
== NULL
&& priv
->driswDisplay
)
618 psc
->driScreen
= (*priv
->driswDisplay
->createScreen
) (psc
, i
, priv
);
620 if (psc
->driScreen
== NULL
) {
621 __glxHashDestroy(psc
->drawHash
);
622 psc
->drawHash
= NULL
;
631 ** Initialize the client side extension code.
633 _X_HIDDEN __GLXdisplayPrivate
*
634 __glXInitialize(Display
* dpy
)
636 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
637 XExtData
**privList
, *private, *found
;
638 __GLXdisplayPrivate
*dpyPriv
;
639 XEDataObject dataObj
;
641 #ifdef GLX_DIRECT_RENDERING
642 Bool glx_direct
, glx_accel
;
645 #if defined(USE_XTHREADS)
647 static int firstCall
= 1;
649 /* initialize the GLX mutexes */
650 xmutex_init(&__glXmutex
);
657 /* The one and only long long lock */
660 if (!XextHasExtension(info
)) {
661 /* No GLX extension supported by this server. Oh well. */
663 XMissingExtension(dpy
, __glXExtensionName
);
667 /* See if a display private already exists. If so, return it */
668 dataObj
.display
= dpy
;
669 privList
= XEHeadOfExtensionList(dataObj
);
670 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
673 return (__GLXdisplayPrivate
*) found
->private_data
;
676 /* See if the versions are compatible */
677 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
678 /* The client and server do not agree on versions. Punt. */
684 ** Allocate memory for all the pieces needed for this buffer.
686 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
691 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
694 Xfree((char *) private);
699 ** Init the display private and then read in the screen config
700 ** structures from the server.
702 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
703 dpyPriv
->majorVersion
= major
;
704 dpyPriv
->minorVersion
= minor
;
707 dpyPriv
->serverGLXvendor
= 0x0;
708 dpyPriv
->serverGLXversion
= 0x0;
710 #ifdef GLX_DIRECT_RENDERING
711 glx_direct
= (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
);
712 glx_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
715 ** Initialize the direct rendering per display data and functions.
716 ** Note: This _must_ be done before calling any other DRI routines
717 ** (e.g., those called in AllocAndFetchScreenConfigs).
719 if (glx_direct
&& glx_accel
) {
720 dpyPriv
->dri2Display
= dri2CreateDisplay(dpy
);
721 dpyPriv
->driDisplay
= driCreateDisplay(dpy
);
724 dpyPriv
->driswDisplay
= driswCreateDisplay(dpy
);
727 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
729 Xfree((char *) dpyPriv
);
730 Xfree((char *) private);
735 ** Fill in the private structure. This is the actual structure that
736 ** hangs off of the Display structure. Our private structure is
737 ** referred to by this structure. Got that?
739 private->number
= info
->codes
->extension
;
741 private->free_private
= __glXFreeDisplayPrivate
;
742 private->private_data
= (char *) dpyPriv
;
743 XAddToExtensionList(privList
, private);
745 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
746 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
754 ** Setup for sending a GLX command on dpy. Make sure the extension is
755 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
758 __glXSetupForCommand(Display
* dpy
)
761 __GLXdisplayPrivate
*priv
;
763 /* If this thread has a current context, flush its rendering commands */
764 gc
= __glXGetCurrentContext();
765 if (gc
->currentDpy
) {
766 /* Flush rendering buffer of the current context, if any */
767 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
769 if (gc
->currentDpy
== dpy
) {
770 /* Use opcode from gc because its right */
772 return gc
->majorOpcode
;
776 ** Have to get info about argument dpy because it might be to
777 ** a different server
782 /* Forced to lookup extension via the slow initialize route */
783 priv
= __glXInitialize(dpy
);
787 return priv
->majorOpcode
;
791 * Flush the drawing command transport buffer.
793 * \param ctx Context whose transport buffer is to be flushed.
794 * \param pc Pointer to first unused buffer location.
797 * Modify this function to use \c ctx->pc instead of the explicit
801 __glXFlushRenderBuffer(__GLXcontext
* ctx
, GLubyte
* pc
)
803 Display
*const dpy
= ctx
->currentDpy
;
805 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
809 const GLint size
= pc
- ctx
->buf
;
811 if ((dpy
!= NULL
) && (size
> 0)) {
813 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
814 (const uint8_t *) ctx
->buf
);
816 /* Send the entire buffer as an X request */
818 GetReq(GLXRender
, req
);
819 req
->reqType
= ctx
->majorOpcode
;
820 req
->glxCode
= X_GLXRender
;
821 req
->contextTag
= ctx
->currentContextTag
;
822 req
->length
+= (size
+ 3) >> 2;
823 _XSend(dpy
, (char *) ctx
->buf
, size
);
829 /* Reset pointer and return it */
836 * Send a portion of a GLXRenderLarge command to the server. The advantage of
837 * this function over \c __glXSendLargeCommand is that callers can use the
838 * data buffer in the GLX context and may be able to avoid allocating an
839 * extra buffer. The disadvantage is the clients will have to do more
840 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
842 * \sa __glXSendLargeCommand
844 * \param gc GLX context
845 * \param requestNumber Which part of the whole command is this? The first
847 * \param totalRequests How many requests will there be?
848 * \param data Command data.
849 * \param dataLen Size, in bytes, of the command data.
852 __glXSendLargeChunk(__GLXcontext
* gc
, GLint requestNumber
,
853 GLint totalRequests
, const GLvoid
* data
, GLint dataLen
)
855 Display
*dpy
= gc
->currentDpy
;
857 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
858 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
,
859 totalRequests
, dataLen
, data
);
861 xGLXRenderLargeReq
*req
;
863 if (requestNumber
== 1) {
867 GetReq(GLXRenderLarge
, req
);
868 req
->reqType
= gc
->majorOpcode
;
869 req
->glxCode
= X_GLXRenderLarge
;
870 req
->contextTag
= gc
->currentContextTag
;
871 req
->length
+= (dataLen
+ 3) >> 2;
872 req
->requestNumber
= requestNumber
;
873 req
->requestTotal
= totalRequests
;
874 req
->dataBytes
= dataLen
;
875 Data(dpy
, data
, dataLen
);
877 if (requestNumber
== totalRequests
) {
886 * Send a command that is too large for the GLXRender protocol request.
888 * Send a large command, one that is too large for some reason to
889 * send using the GLXRender protocol request. One reason to send
890 * a large command is to avoid copying the data.
892 * \param ctx GLX context
893 * \param header Header data.
894 * \param headerLen Size, in bytes, of the header data. It is assumed that
895 * the header data will always be small enough to fit in
896 * a single X protocol packet.
897 * \param data Command data.
898 * \param dataLen Size, in bytes, of the command data.
901 __glXSendLargeCommand(__GLXcontext
* ctx
,
902 const GLvoid
* header
, GLint headerLen
,
903 const GLvoid
* data
, GLint dataLen
)
906 GLint totalRequests
, requestNumber
;
909 ** Calculate the maximum amount of data can be stuffed into a single
910 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
911 ** packet size minus sz_xGLXRenderReq.
913 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
914 totalRequests
= 1 + (dataLen
/ maxSize
);
915 if (dataLen
% maxSize
)
919 ** Send all of the command, except the large array, as one request.
921 assert(headerLen
<= maxSize
);
922 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
925 ** Send enough requests until the whole array is sent.
927 for (requestNumber
= 2; requestNumber
<= (totalRequests
- 1);
929 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
930 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
935 assert(dataLen
<= maxSize
);
936 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
939 /************************************************************************/
943 __glXDumpDrawBuffer(__GLXcontext
* ctx
)
945 GLubyte
*p
= ctx
->buf
;
946 GLubyte
*end
= ctx
->pc
;
947 GLushort opcode
, length
;
951 opcode
= *((GLushort
*) p
);
952 length
= *((GLushort
*) (p
+ 2));
953 printf("%2x: %5d: ", opcode
, length
);
957 printf("%08x ", *((unsigned *) p
));
968 * This is where our dispatch table's bounds are.
969 * And the static mesa_init is taken directly from
970 * Mesa's 'sparc.c' initializer.
972 * We need something like this here, because this version
973 * of openGL/glx never initializes a Mesa context, and so
974 * the address of the dispatch table pointer never gets stuffed
975 * into the dispatch jump table otherwise.
977 * It matters only on SPARC, and only if you are using assembler
978 * code instead of C-code indirect dispatch.
982 extern unsigned int _mesa_sparc_glapi_begin
;
983 extern unsigned int _mesa_sparc_glapi_end
;
984 extern void __glapi_sparc_icache_flush(unsigned int *);
987 _glx_mesa_init_sparc_glapi_relocs(void)
989 unsigned int *insn_ptr
, *end_ptr
;
990 unsigned long disp_addr
;
992 insn_ptr
= &_mesa_sparc_glapi_begin
;
993 end_ptr
= &_mesa_sparc_glapi_end
;
994 disp_addr
= (unsigned long) &_glapi_Dispatch
;
997 * Verbatim from Mesa sparc.c. It's needed because there doesn't
998 * seem to be a better way to do this:
1000 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1002 * This code is patching in the ADDRESS of the pointer to the
1003 * dispatch table. Hence, it must be called exactly once, because
1004 * that address is not going to change.
1006 * What it points to can change, but Mesa (and hence, we) assume
1007 * that there is only one pointer.
1010 while (insn_ptr
< end_ptr
) {
1011 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1013 This code patches for 64-bit addresses. This had better
1014 not happen for Sparc/Linux, no matter what architecture we
1015 are building for. So, don't do this.
1017 The 'defined(__linux_64__)' is used here as a placeholder for
1018 when we do do 64-bit usermode on sparc linux.
1020 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1021 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1022 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1023 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1024 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1025 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1028 insn_ptr
[0] |= (disp_addr
>> 10);
1029 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1030 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1035 #endif /* sparc ASM in use */