1 /* $XFree86: xc/lib/GL/glx/glxext.c,v 1.22 2003/12/08 17:35:28 dawes Exp $ */
4 ** License Applicability. Except to the extent portions of this file are
5 ** made subject to an alternative license as permitted in the SGI Free
6 ** Software License B, Version 1.1 (the "License"), the contents of this
7 ** file are subject only to the provisions of the License. You may not use
8 ** this file except in compliance with the License. You may obtain a copy
9 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
10 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
12 ** http://oss.sgi.com/projects/FreeB
14 ** Note that, as provided in the License, the Software is distributed on an
15 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
16 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
17 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
18 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
20 ** Original Code. The Original Code is: OpenGL Sample Implementation,
21 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
22 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
23 ** Copyright in any portions created by third parties is as indicated
24 ** elsewhere herein. All Rights Reserved.
26 ** Additional Notice Provisions: The application programming interfaces
27 ** established by SGI in conjunction with the Original Code are The
28 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
29 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
30 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
31 ** Window System(R) (Version 1.3), released October 19, 1998. This software
32 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
33 ** published by SGI, but has not been independently verified as being
34 ** compliant with the OpenGL(R) version 1.2.1 Specification.
40 * GLX protocol interface boot-strap code.
42 * Direct rendering support added by Precision Insight, Inc.
44 * \author Kevin E. Martin <kevin@precisioninsight.com>
47 #include "glxclient.h"
48 #include <X11/extensions/Xext.h>
49 #include <X11/extensions/extutil.h>
51 #include "glxextensions.h"
52 #include "glcontextmodes.h"
56 #include <X11/Xlib-xcb.h>
63 void __glXDumpDrawBuffer(__GLXcontext
*ctx
);
67 static void _glx_mesa_init_sparc_glapi_relocs(void);
68 static int _mesa_sparc_needs_init
= 1;
69 #define INIT_MESA_SPARC { \
70 if(_mesa_sparc_needs_init) { \
71 _glx_mesa_init_sparc_glapi_relocs(); \
72 _mesa_sparc_needs_init = 0; \
76 #define INIT_MESA_SPARC
80 ** You can set this cell to 1 to force the gl drawing stuff to be
81 ** one command per packet
83 _X_HIDDEN
int __glXDebug
= 0;
85 /* Extension required boiler plate */
87 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
88 XExtensionInfo
*__glXExtensionInfo
= NULL
;
90 static /* const */ char *error_list
[] = {
96 "GLXBadCurrentWindow",
97 "GLXBadRenderRequest",
99 "GLXUnsupportedPrivateRequest",
102 "GLXBadCurrentDrawable",
106 static int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
)
110 gc
= __glXGetCurrentContext();
111 if (dpy
== gc
->currentDpy
) {
112 __glXSetCurrentContextNull();
113 __glXFreeContext(gc
);
116 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
120 static XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
121 __GLX_NUMBER_ERRORS
, error_list
)
123 static /* const */ XExtensionHooks __glXExtensionHooks
= {
124 NULL
, /* create_gc */
128 NULL
, /* create_font */
129 NULL
, /* free_font */
130 __glXCloseDisplay
, /* close_display */
131 NULL
, /* wire_to_event */
132 NULL
, /* event_to_wire */
134 __glXErrorString
, /* error_string */
138 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
139 __glXExtensionName
, &__glXExtensionHooks
,
140 __GLX_NUMBER_EVENTS
, NULL
)
142 /************************************************************************/
145 ** Free the per screen configs data as well as the array of
146 ** __glXScreenConfigs.
148 static void FreeScreenConfigs(__GLXdisplayPrivate
*priv
)
150 __GLXscreenConfigs
*psc
;
153 /* Free screen configuration information */
154 psc
= priv
->screenConfigs
;
155 screens
= ScreenCount(priv
->dpy
);
156 for (i
= 0; i
< screens
; i
++, psc
++) {
158 _gl_context_modes_destroy( psc
->configs
);
159 if(psc
->effectiveGLXexts
)
160 Xfree(psc
->effectiveGLXexts
);
162 psc
->configs
= NULL
; /* NOTE: just for paranoia */
164 Xfree((char*) psc
->serverGLXexts
);
166 #ifdef GLX_DIRECT_RENDERING
167 if (psc
->driScreen
) {
168 psc
->driScreen
->destroyScreen(psc
);
169 __glxHashDestroy(psc
->drawHash
);
173 XFree((char*) priv
->screenConfigs
);
177 ** Release the private memory referred to in a display private
178 ** structure. The caller will free the extension structure.
180 static int __glXFreeDisplayPrivate(XExtData
*extension
)
182 __GLXdisplayPrivate
*priv
;
184 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
185 FreeScreenConfigs(priv
);
186 if(priv
->serverGLXvendor
) {
187 Xfree((char*)priv
->serverGLXvendor
);
188 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
190 if(priv
->serverGLXversion
) {
191 Xfree((char*)priv
->serverGLXversion
);
192 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
195 #ifdef GLX_DIRECT_RENDERING
196 /* Free the direct rendering per display data */
197 if (priv
->driDisplay
)
198 (*priv
->driDisplay
->destroyDisplay
)(priv
->driDisplay
);
199 priv
->driDisplay
= NULL
;
200 if (priv
->dri2Display
)
201 (*priv
->dri2Display
->destroyDisplay
)(priv
->dri2Display
);
202 priv
->dri2Display
= NULL
;
209 /************************************************************************/
212 ** Query the version of the GLX extension. This procedure works even if
213 ** the client extension is not completely set up.
215 static Bool
QueryVersion(Display
*dpy
, int opcode
, int *major
, int *minor
)
217 xGLXQueryVersionReq
*req
;
218 xGLXQueryVersionReply reply
;
220 /* Send the glXQueryVersion request */
222 GetReq(GLXQueryVersion
,req
);
223 req
->reqType
= opcode
;
224 req
->glxCode
= X_GLXQueryVersion
;
225 req
->majorVersion
= GLX_MAJOR_VERSION
;
226 req
->minorVersion
= GLX_MINOR_VERSION
;
227 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
231 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
233 ** The server does not support the same major release as this
238 *major
= reply
.majorVersion
;
239 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
245 __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
, int count
,
246 const INT32
*bp
, Bool tagged_only
,
247 Bool fbconfig_style_tags
)
252 /* Copy in the first set of properties */
253 config
->visualID
= *bp
++;
255 config
->visualType
= _gl_convert_from_x_visual_type( *bp
++ );
257 config
->rgbMode
= *bp
++;
259 config
->redBits
= *bp
++;
260 config
->greenBits
= *bp
++;
261 config
->blueBits
= *bp
++;
262 config
->alphaBits
= *bp
++;
263 config
->accumRedBits
= *bp
++;
264 config
->accumGreenBits
= *bp
++;
265 config
->accumBlueBits
= *bp
++;
266 config
->accumAlphaBits
= *bp
++;
268 config
->doubleBufferMode
= *bp
++;
269 config
->stereoMode
= *bp
++;
271 config
->rgbBits
= *bp
++;
272 config
->depthBits
= *bp
++;
273 config
->stencilBits
= *bp
++;
274 config
->numAuxBuffers
= *bp
++;
275 config
->level
= *bp
++;
277 count
-= __GLX_MIN_CONFIG_PROPS
;
281 ** Additional properties may be in a list at the end
282 ** of the reply. They are in pairs of property type
283 ** and property value.
286 #define FETCH_OR_SET(tag) \
287 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
289 for (i
= 0; i
< count
; i
+= 2 ) {
292 FETCH_OR_SET( rgbMode
);
294 case GLX_BUFFER_SIZE
:
295 config
->rgbBits
= *bp
++;
298 config
->level
= *bp
++;
300 case GLX_DOUBLEBUFFER
:
301 FETCH_OR_SET( doubleBufferMode
);
304 FETCH_OR_SET( stereoMode
);
306 case GLX_AUX_BUFFERS
:
307 config
->numAuxBuffers
= *bp
++;
310 config
->redBits
= *bp
++;
313 config
->greenBits
= *bp
++;
316 config
->blueBits
= *bp
++;
319 config
->alphaBits
= *bp
++;
322 config
->depthBits
= *bp
++;
324 case GLX_STENCIL_SIZE
:
325 config
->stencilBits
= *bp
++;
327 case GLX_ACCUM_RED_SIZE
:
328 config
->accumRedBits
= *bp
++;
330 case GLX_ACCUM_GREEN_SIZE
:
331 config
->accumGreenBits
= *bp
++;
333 case GLX_ACCUM_BLUE_SIZE
:
334 config
->accumBlueBits
= *bp
++;
336 case GLX_ACCUM_ALPHA_SIZE
:
337 config
->accumAlphaBits
= *bp
++;
339 case GLX_VISUAL_CAVEAT_EXT
:
340 config
->visualRating
= *bp
++;
342 case GLX_X_VISUAL_TYPE
:
343 config
->visualType
= *bp
++;
345 case GLX_TRANSPARENT_TYPE
:
346 config
->transparentPixel
= *bp
++;
348 case GLX_TRANSPARENT_INDEX_VALUE
:
349 config
->transparentIndex
= *bp
++;
351 case GLX_TRANSPARENT_RED_VALUE
:
352 config
->transparentRed
= *bp
++;
354 case GLX_TRANSPARENT_GREEN_VALUE
:
355 config
->transparentGreen
= *bp
++;
357 case GLX_TRANSPARENT_BLUE_VALUE
:
358 config
->transparentBlue
= *bp
++;
360 case GLX_TRANSPARENT_ALPHA_VALUE
:
361 config
->transparentAlpha
= *bp
++;
364 config
->visualID
= *bp
++;
366 case GLX_DRAWABLE_TYPE
:
367 config
->drawableType
= *bp
++;
369 case GLX_RENDER_TYPE
:
370 config
->renderType
= *bp
++;
372 case GLX_X_RENDERABLE
:
373 config
->xRenderable
= *bp
++;
375 case GLX_FBCONFIG_ID
:
376 config
->fbconfigID
= *bp
++;
378 case GLX_MAX_PBUFFER_WIDTH
:
379 config
->maxPbufferWidth
= *bp
++;
381 case GLX_MAX_PBUFFER_HEIGHT
:
382 config
->maxPbufferHeight
= *bp
++;
384 case GLX_MAX_PBUFFER_PIXELS
:
385 config
->maxPbufferPixels
= *bp
++;
387 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
388 config
->optimalPbufferWidth
= *bp
++;
390 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
391 config
->optimalPbufferHeight
= *bp
++;
393 case GLX_VISUAL_SELECT_GROUP_SGIX
:
394 config
->visualSelectGroup
= *bp
++;
396 case GLX_SWAP_METHOD_OML
:
397 config
->swapMethod
= *bp
++;
399 case GLX_SAMPLE_BUFFERS_SGIS
:
400 config
->sampleBuffers
= *bp
++;
402 case GLX_SAMPLES_SGIS
:
403 config
->samples
= *bp
++;
405 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
406 config
->bindToTextureRgb
= *bp
++;
408 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
409 config
->bindToTextureRgba
= *bp
++;
411 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
412 config
->bindToMipmapTexture
= *bp
++;
414 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
415 config
->bindToTextureTargets
= *bp
++;
417 case GLX_Y_INVERTED_EXT
:
418 config
->yInverted
= *bp
++;
428 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
430 config
->haveAccumBuffer
= ((config
->accumRedBits
+
431 config
->accumGreenBits
+
432 config
->accumBlueBits
+
433 config
->accumAlphaBits
) > 0);
434 config
->haveDepthBuffer
= (config
->depthBits
> 0);
435 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
438 static __GLcontextModes
*
439 createConfigsFromProperties(Display
*dpy
, int nvisuals
, int nprops
,
440 int screen
, GLboolean tagged_only
)
442 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
444 __GLcontextModes
*modes
, *m
;
450 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
452 /* Check number of properties */
453 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
456 /* Allocate memory for our config structure */
457 modes
= _gl_context_modes_create(nvisuals
, sizeof(__GLcontextModes
));
461 prop_size
= nprops
* __GLX_SIZE_INT32
;
462 if (prop_size
<= sizeof(buf
))
465 props
= Xmalloc(prop_size
);
467 /* Read each config structure and convert it into our format */
469 for (i
= 0; i
< nvisuals
; i
++) {
470 _XRead(dpy
, (char *)props
, prop_size
);
471 /* Older X servers don't send this so we default it here. */
472 m
->drawableType
= GLX_WINDOW_BIT
;
473 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
474 tagged_only
, GL_TRUE
);
486 getVisualConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
, int screen
)
488 xGLXGetVisualConfigsReq
*req
;
489 __GLXscreenConfigs
*psc
;
490 xGLXGetVisualConfigsReply reply
;
494 psc
= priv
->screenConfigs
+ screen
;
496 GetReq(GLXGetVisualConfigs
, req
);
497 req
->reqType
= priv
->majorOpcode
;
498 req
->glxCode
= X_GLXGetVisualConfigs
;
499 req
->screen
= screen
;
501 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
))
504 psc
->visuals
= createConfigsFromProperties(dpy
,
511 return psc
->visuals
!= NULL
;
515 getFBConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
, int screen
)
517 xGLXGetFBConfigsReq
*fb_req
;
518 xGLXGetFBConfigsSGIXReq
*sgi_req
;
519 xGLXVendorPrivateWithReplyReq
*vpreq
;
520 xGLXGetFBConfigsReply reply
;
521 __GLXscreenConfigs
*psc
;
523 psc
= priv
->screenConfigs
+ screen
;
524 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
525 X_GLXQueryServerString
,
526 screen
, GLX_EXTENSIONS
);
531 if (atof(priv
->serverGLXversion
) >= 1.3) {
532 GetReq(GLXGetFBConfigs
, fb_req
);
533 fb_req
->reqType
= priv
->majorOpcode
;
534 fb_req
->glxCode
= X_GLXGetFBConfigs
;
535 fb_req
->screen
= screen
;
536 } else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
537 GetReqExtra(GLXVendorPrivateWithReply
,
538 sz_xGLXGetFBConfigsSGIXReq
+
539 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
540 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
541 sgi_req
->reqType
= priv
->majorOpcode
;
542 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
543 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
544 sgi_req
->screen
= screen
;
548 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
))
551 psc
->configs
= createConfigsFromProperties(dpy
,
553 reply
.numAttribs
* 2,
558 return psc
->configs
!= NULL
;
562 ** Allocate the memory for the per screen configs for each screen.
563 ** If that works then fetch the per screen configs data.
565 static Bool
AllocAndFetchScreenConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
)
567 __GLXscreenConfigs
*psc
;
571 ** First allocate memory for the array of per screen configs.
573 screens
= ScreenCount(dpy
);
574 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
578 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
579 priv
->screenConfigs
= psc
;
581 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
582 X_GLXQueryServerString
,
584 if ( priv
->serverGLXversion
== NULL
) {
585 FreeScreenConfigs(priv
);
589 for (i
= 0; i
< screens
; i
++, psc
++) {
590 getVisualConfigs(dpy
, priv
, i
);
591 getFBConfigs(dpy
, priv
, i
);
595 #ifdef GLX_DIRECT_RENDERING
596 psc
->drawHash
= __glxHashCreate();
597 if (psc
->drawHash
== NULL
)
599 if (priv
->dri2Display
)
600 psc
->driScreen
= (*priv
->dri2Display
->createScreen
)(psc
, i
, priv
);
601 if (psc
->driScreen
== NULL
&& priv
->driDisplay
)
602 psc
->driScreen
= (*priv
->driDisplay
->createScreen
)(psc
, i
, priv
);
603 if (psc
->driScreen
== NULL
) {
604 __glxHashDestroy(psc
->drawHash
);
605 psc
->drawHash
= NULL
;
614 ** Initialize the client side extension code.
616 _X_HIDDEN __GLXdisplayPrivate
*__glXInitialize(Display
* dpy
)
618 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
619 XExtData
**privList
, *private, *found
;
620 __GLXdisplayPrivate
*dpyPriv
;
621 XEDataObject dataObj
;
624 #if defined(USE_XTHREADS)
626 static int firstCall
= 1;
628 /* initialize the GLX mutexes */
629 xmutex_init(&__glXmutex
);
636 /* The one and only long long lock */
639 if (!XextHasExtension(info
)) {
640 /* No GLX extension supported by this server. Oh well. */
642 XMissingExtension(dpy
, __glXExtensionName
);
646 /* See if a display private already exists. If so, return it */
647 dataObj
.display
= dpy
;
648 privList
= XEHeadOfExtensionList(dataObj
);
649 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
652 return (__GLXdisplayPrivate
*) found
->private_data
;
655 /* See if the versions are compatible */
656 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
657 /* The client and server do not agree on versions. Punt. */
663 ** Allocate memory for all the pieces needed for this buffer.
665 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
670 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
673 Xfree((char*) private);
678 ** Init the display private and then read in the screen config
679 ** structures from the server.
681 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
682 dpyPriv
->majorVersion
= major
;
683 dpyPriv
->minorVersion
= minor
;
686 dpyPriv
->serverGLXvendor
= 0x0;
687 dpyPriv
->serverGLXversion
= 0x0;
689 #ifdef GLX_DIRECT_RENDERING
691 ** Initialize the direct rendering per display data and functions.
692 ** Note: This _must_ be done before calling any other DRI routines
693 ** (e.g., those called in AllocAndFetchScreenConfigs).
695 if (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
) {
696 dpyPriv
->dri2Display
= dri2CreateDisplay(dpy
);
697 dpyPriv
->driDisplay
= driCreateDisplay(dpy
);
701 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
703 Xfree((char*) dpyPriv
);
704 Xfree((char*) private);
709 ** Fill in the private structure. This is the actual structure that
710 ** hangs off of the Display structure. Our private structure is
711 ** referred to by this structure. Got that?
713 private->number
= info
->codes
->extension
;
715 private->free_private
= __glXFreeDisplayPrivate
;
716 private->private_data
= (char *) dpyPriv
;
717 XAddToExtensionList(privList
, private);
719 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
720 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
728 ** Setup for sending a GLX command on dpy. Make sure the extension is
729 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
731 _X_HIDDEN CARD8
__glXSetupForCommand(Display
*dpy
)
734 __GLXdisplayPrivate
*priv
;
736 /* If this thread has a current context, flush its rendering commands */
737 gc
= __glXGetCurrentContext();
738 if (gc
->currentDpy
) {
739 /* Flush rendering buffer of the current context, if any */
740 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
742 if (gc
->currentDpy
== dpy
) {
743 /* Use opcode from gc because its right */
745 return gc
->majorOpcode
;
748 ** Have to get info about argument dpy because it might be to
749 ** a different server
754 /* Forced to lookup extension via the slow initialize route */
755 priv
= __glXInitialize(dpy
);
759 return priv
->majorOpcode
;
763 * Flush the drawing command transport buffer.
765 * \param ctx Context whose transport buffer is to be flushed.
766 * \param pc Pointer to first unused buffer location.
769 * Modify this function to use \c ctx->pc instead of the explicit
772 _X_HIDDEN GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*ctx
, GLubyte
*pc
)
774 Display
* const dpy
= ctx
->currentDpy
;
776 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
780 const GLint size
= pc
- ctx
->buf
;
782 if ( (dpy
!= NULL
) && (size
> 0) ) {
784 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
785 (const uint8_t *)ctx
->buf
);
787 /* Send the entire buffer as an X request */
789 GetReq(GLXRender
,req
);
790 req
->reqType
= ctx
->majorOpcode
;
791 req
->glxCode
= X_GLXRender
;
792 req
->contextTag
= ctx
->currentContextTag
;
793 req
->length
+= (size
+ 3) >> 2;
794 _XSend(dpy
, (char *)ctx
->buf
, size
);
800 /* Reset pointer and return it */
807 * Send a portion of a GLXRenderLarge command to the server. The advantage of
808 * this function over \c __glXSendLargeCommand is that callers can use the
809 * data buffer in the GLX context and may be able to avoid allocating an
810 * extra buffer. The disadvantage is the clients will have to do more
811 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
813 * \sa __glXSendLargeCommand
815 * \param gc GLX context
816 * \param requestNumber Which part of the whole command is this? The first
818 * \param totalRequests How many requests will there be?
819 * \param data Command data.
820 * \param dataLen Size, in bytes, of the command data.
822 _X_HIDDEN
void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
824 const GLvoid
* data
, GLint dataLen
)
826 Display
*dpy
= gc
->currentDpy
;
828 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
829 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
, totalRequests
, dataLen
, data
);
831 xGLXRenderLargeReq
*req
;
833 if ( requestNumber
== 1 ) {
837 GetReq(GLXRenderLarge
,req
);
838 req
->reqType
= gc
->majorOpcode
;
839 req
->glxCode
= X_GLXRenderLarge
;
840 req
->contextTag
= gc
->currentContextTag
;
841 req
->length
+= (dataLen
+ 3) >> 2;
842 req
->requestNumber
= requestNumber
;
843 req
->requestTotal
= totalRequests
;
844 req
->dataBytes
= dataLen
;
845 Data(dpy
, data
, dataLen
);
847 if ( requestNumber
== totalRequests
) {
856 * Send a command that is too large for the GLXRender protocol request.
858 * Send a large command, one that is too large for some reason to
859 * send using the GLXRender protocol request. One reason to send
860 * a large command is to avoid copying the data.
862 * \param ctx GLX context
863 * \param header Header data.
864 * \param headerLen Size, in bytes, of the header data. It is assumed that
865 * the header data will always be small enough to fit in
866 * a single X protocol packet.
867 * \param data Command data.
868 * \param dataLen Size, in bytes, of the command data.
870 _X_HIDDEN
void __glXSendLargeCommand(__GLXcontext
*ctx
,
871 const GLvoid
*header
, GLint headerLen
,
872 const GLvoid
*data
, GLint dataLen
)
875 GLint totalRequests
, requestNumber
;
878 ** Calculate the maximum amount of data can be stuffed into a single
879 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
880 ** packet size minus sz_xGLXRenderReq.
882 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
883 totalRequests
= 1 + (dataLen
/ maxSize
);
884 if (dataLen
% maxSize
) totalRequests
++;
887 ** Send all of the command, except the large array, as one request.
889 assert( headerLen
<= maxSize
);
890 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
893 ** Send enough requests until the whole array is sent.
895 for ( requestNumber
= 2 ; requestNumber
<= (totalRequests
- 1) ; requestNumber
++ ) {
896 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
897 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
899 assert( dataLen
> 0 );
902 assert( dataLen
<= maxSize
);
903 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
906 /************************************************************************/
909 _X_HIDDEN
void __glXDumpDrawBuffer(__GLXcontext
*ctx
)
911 GLubyte
*p
= ctx
->buf
;
912 GLubyte
*end
= ctx
->pc
;
913 GLushort opcode
, length
;
917 opcode
= *((GLushort
*) p
);
918 length
= *((GLushort
*) (p
+ 2));
919 printf("%2x: %5d: ", opcode
, length
);
923 printf("%08x ", *((unsigned *) p
));
934 * This is where our dispatch table's bounds are.
935 * And the static mesa_init is taken directly from
936 * Mesa's 'sparc.c' initializer.
938 * We need something like this here, because this version
939 * of openGL/glx never initializes a Mesa context, and so
940 * the address of the dispatch table pointer never gets stuffed
941 * into the dispatch jump table otherwise.
943 * It matters only on SPARC, and only if you are using assembler
944 * code instead of C-code indirect dispatch.
948 extern unsigned int _mesa_sparc_glapi_begin
;
949 extern unsigned int _mesa_sparc_glapi_end
;
950 extern void __glapi_sparc_icache_flush(unsigned int *);
953 _glx_mesa_init_sparc_glapi_relocs(void)
955 unsigned int *insn_ptr
, *end_ptr
;
956 unsigned long disp_addr
;
958 insn_ptr
= &_mesa_sparc_glapi_begin
;
959 end_ptr
= &_mesa_sparc_glapi_end
;
960 disp_addr
= (unsigned long) &_glapi_Dispatch
;
963 * Verbatim from Mesa sparc.c. It's needed because there doesn't
964 * seem to be a better way to do this:
966 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
968 * This code is patching in the ADDRESS of the pointer to the
969 * dispatch table. Hence, it must be called exactly once, because
970 * that address is not going to change.
972 * What it points to can change, but Mesa (and hence, we) assume
973 * that there is only one pointer.
976 while (insn_ptr
< end_ptr
) {
977 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
979 This code patches for 64-bit addresses. This had better
980 not happen for Sparc/Linux, no matter what architecture we
981 are building for. So, don't do this.
983 The 'defined(__linux_64__)' is used here as a placeholder for
984 when we do do 64-bit usermode on sparc linux.
986 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
987 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
988 __glapi_sparc_icache_flush(&insn_ptr
[0]);
989 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
990 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
991 __glapi_sparc_icache_flush(&insn_ptr
[2]);
994 insn_ptr
[0] |= (disp_addr
>> 10);
995 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
996 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1001 #endif /* sparc ASM in use */