3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
11 ** http://oss.sgi.com/projects/FreeB
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
39 * GLX protocol interface boot-strap code.
41 * Direct rendering support added by Precision Insight, Inc.
43 * \author Kevin E. Martin <kevin@precisioninsight.com>
46 #include "glxclient.h"
47 #include <X11/extensions/Xext.h>
48 #include <X11/extensions/extutil.h>
50 #include "glxextensions.h"
51 #include "glcontextmodes.h"
55 #include <X11/Xlib-xcb.h>
62 void __glXDumpDrawBuffer(__GLXcontext
*ctx
);
66 static void _glx_mesa_init_sparc_glapi_relocs(void);
67 static int _mesa_sparc_needs_init
= 1;
68 #define INIT_MESA_SPARC { \
69 if(_mesa_sparc_needs_init) { \
70 _glx_mesa_init_sparc_glapi_relocs(); \
71 _mesa_sparc_needs_init = 0; \
75 #define INIT_MESA_SPARC
79 ** You can set this cell to 1 to force the gl drawing stuff to be
80 ** one command per packet
82 _X_HIDDEN
int __glXDebug
= 0;
84 /* Extension required boiler plate */
86 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
87 XExtensionInfo
*__glXExtensionInfo
= NULL
;
89 static /* const */ char *error_list
[] = {
95 "GLXBadCurrentWindow",
96 "GLXBadRenderRequest",
98 "GLXUnsupportedPrivateRequest",
101 "GLXBadCurrentDrawable",
105 static int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
)
109 gc
= __glXGetCurrentContext();
110 if (dpy
== gc
->currentDpy
) {
111 __glXSetCurrentContextNull();
112 __glXFreeContext(gc
);
115 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
119 static XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
120 __GLX_NUMBER_ERRORS
, error_list
)
122 static /* const */ XExtensionHooks __glXExtensionHooks
= {
123 NULL
, /* create_gc */
127 NULL
, /* create_font */
128 NULL
, /* free_font */
129 __glXCloseDisplay
, /* close_display */
130 NULL
, /* wire_to_event */
131 NULL
, /* event_to_wire */
133 __glXErrorString
, /* error_string */
137 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
138 __glXExtensionName
, &__glXExtensionHooks
,
139 __GLX_NUMBER_EVENTS
, NULL
)
141 /************************************************************************/
144 ** Free the per screen configs data as well as the array of
145 ** __glXScreenConfigs.
147 static void FreeScreenConfigs(__GLXdisplayPrivate
*priv
)
149 __GLXscreenConfigs
*psc
;
152 /* Free screen configuration information */
153 psc
= priv
->screenConfigs
;
154 screens
= ScreenCount(priv
->dpy
);
155 for (i
= 0; i
< screens
; i
++, psc
++) {
157 _gl_context_modes_destroy( psc
->configs
);
158 if (psc
->effectiveGLXexts
)
159 Xfree(psc
->effectiveGLXexts
);
160 psc
->configs
= NULL
; /* NOTE: just for paranoia */
163 _gl_context_modes_destroy( psc
->visuals
);
164 psc
->visuals
= NULL
; /* NOTE: just for paranoia */
166 Xfree((char*) psc
->serverGLXexts
);
168 #ifdef GLX_DIRECT_RENDERING
169 if (psc
->driScreen
) {
170 psc
->driScreen
->destroyScreen(psc
);
171 __glxHashDestroy(psc
->drawHash
);
172 XFree(psc
->driScreen
);
173 psc
->driScreen
= NULL
;
177 XFree((char*) priv
->screenConfigs
);
178 priv
->screenConfigs
= NULL
;
182 ** Release the private memory referred to in a display private
183 ** structure. The caller will free the extension structure.
185 static int __glXFreeDisplayPrivate(XExtData
*extension
)
187 __GLXdisplayPrivate
*priv
;
189 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
190 FreeScreenConfigs(priv
);
191 if(priv
->serverGLXvendor
) {
192 Xfree((char*)priv
->serverGLXvendor
);
193 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
195 if(priv
->serverGLXversion
) {
196 Xfree((char*)priv
->serverGLXversion
);
197 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
200 #ifdef GLX_DIRECT_RENDERING
201 /* Free the direct rendering per display data */
202 if (priv
->driswDisplay
)
203 (*priv
->driswDisplay
->destroyDisplay
)(priv
->driswDisplay
);
204 priv
->driswDisplay
= NULL
;
206 if (priv
->driDisplay
)
207 (*priv
->driDisplay
->destroyDisplay
)(priv
->driDisplay
);
208 priv
->driDisplay
= NULL
;
210 if (priv
->dri2Display
)
211 (*priv
->dri2Display
->destroyDisplay
)(priv
->dri2Display
);
212 priv
->dri2Display
= NULL
;
219 /************************************************************************/
222 ** Query the version of the GLX extension. This procedure works even if
223 ** the client extension is not completely set up.
225 static Bool
QueryVersion(Display
*dpy
, int opcode
, int *major
, int *minor
)
227 xGLXQueryVersionReq
*req
;
228 xGLXQueryVersionReply reply
;
230 /* Send the glXQueryVersion request */
232 GetReq(GLXQueryVersion
,req
);
233 req
->reqType
= opcode
;
234 req
->glxCode
= X_GLXQueryVersion
;
235 req
->majorVersion
= GLX_MAJOR_VERSION
;
236 req
->minorVersion
= GLX_MINOR_VERSION
;
237 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
241 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
243 ** The server does not support the same major release as this
248 *major
= reply
.majorVersion
;
249 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
255 __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
, int count
,
256 const INT32
*bp
, Bool tagged_only
,
257 Bool fbconfig_style_tags
)
262 /* Copy in the first set of properties */
263 config
->visualID
= *bp
++;
265 config
->visualType
= _gl_convert_from_x_visual_type( *bp
++ );
267 config
->rgbMode
= *bp
++;
269 config
->redBits
= *bp
++;
270 config
->greenBits
= *bp
++;
271 config
->blueBits
= *bp
++;
272 config
->alphaBits
= *bp
++;
273 config
->accumRedBits
= *bp
++;
274 config
->accumGreenBits
= *bp
++;
275 config
->accumBlueBits
= *bp
++;
276 config
->accumAlphaBits
= *bp
++;
278 config
->doubleBufferMode
= *bp
++;
279 config
->stereoMode
= *bp
++;
281 config
->rgbBits
= *bp
++;
282 config
->depthBits
= *bp
++;
283 config
->stencilBits
= *bp
++;
284 config
->numAuxBuffers
= *bp
++;
285 config
->level
= *bp
++;
287 count
-= __GLX_MIN_CONFIG_PROPS
;
291 ** Additional properties may be in a list at the end
292 ** of the reply. They are in pairs of property type
293 ** and property value.
296 #define FETCH_OR_SET(tag) \
297 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
299 for (i
= 0; i
< count
; i
+= 2 ) {
302 FETCH_OR_SET( rgbMode
);
304 case GLX_BUFFER_SIZE
:
305 config
->rgbBits
= *bp
++;
308 config
->level
= *bp
++;
310 case GLX_DOUBLEBUFFER
:
311 FETCH_OR_SET( doubleBufferMode
);
314 FETCH_OR_SET( stereoMode
);
316 case GLX_AUX_BUFFERS
:
317 config
->numAuxBuffers
= *bp
++;
320 config
->redBits
= *bp
++;
323 config
->greenBits
= *bp
++;
326 config
->blueBits
= *bp
++;
329 config
->alphaBits
= *bp
++;
332 config
->depthBits
= *bp
++;
334 case GLX_STENCIL_SIZE
:
335 config
->stencilBits
= *bp
++;
337 case GLX_ACCUM_RED_SIZE
:
338 config
->accumRedBits
= *bp
++;
340 case GLX_ACCUM_GREEN_SIZE
:
341 config
->accumGreenBits
= *bp
++;
343 case GLX_ACCUM_BLUE_SIZE
:
344 config
->accumBlueBits
= *bp
++;
346 case GLX_ACCUM_ALPHA_SIZE
:
347 config
->accumAlphaBits
= *bp
++;
349 case GLX_VISUAL_CAVEAT_EXT
:
350 config
->visualRating
= *bp
++;
352 case GLX_X_VISUAL_TYPE
:
353 config
->visualType
= *bp
++;
355 case GLX_TRANSPARENT_TYPE
:
356 config
->transparentPixel
= *bp
++;
358 case GLX_TRANSPARENT_INDEX_VALUE
:
359 config
->transparentIndex
= *bp
++;
361 case GLX_TRANSPARENT_RED_VALUE
:
362 config
->transparentRed
= *bp
++;
364 case GLX_TRANSPARENT_GREEN_VALUE
:
365 config
->transparentGreen
= *bp
++;
367 case GLX_TRANSPARENT_BLUE_VALUE
:
368 config
->transparentBlue
= *bp
++;
370 case GLX_TRANSPARENT_ALPHA_VALUE
:
371 config
->transparentAlpha
= *bp
++;
374 config
->visualID
= *bp
++;
376 case GLX_DRAWABLE_TYPE
:
377 config
->drawableType
= *bp
++;
379 case GLX_RENDER_TYPE
:
380 config
->renderType
= *bp
++;
382 case GLX_X_RENDERABLE
:
383 config
->xRenderable
= *bp
++;
385 case GLX_FBCONFIG_ID
:
386 config
->fbconfigID
= *bp
++;
388 case GLX_MAX_PBUFFER_WIDTH
:
389 config
->maxPbufferWidth
= *bp
++;
391 case GLX_MAX_PBUFFER_HEIGHT
:
392 config
->maxPbufferHeight
= *bp
++;
394 case GLX_MAX_PBUFFER_PIXELS
:
395 config
->maxPbufferPixels
= *bp
++;
397 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
398 config
->optimalPbufferWidth
= *bp
++;
400 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
401 config
->optimalPbufferHeight
= *bp
++;
403 case GLX_VISUAL_SELECT_GROUP_SGIX
:
404 config
->visualSelectGroup
= *bp
++;
406 case GLX_SWAP_METHOD_OML
:
407 config
->swapMethod
= *bp
++;
409 case GLX_SAMPLE_BUFFERS_SGIS
:
410 config
->sampleBuffers
= *bp
++;
412 case GLX_SAMPLES_SGIS
:
413 config
->samples
= *bp
++;
415 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
416 config
->bindToTextureRgb
= *bp
++;
418 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
419 config
->bindToTextureRgba
= *bp
++;
421 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
422 config
->bindToMipmapTexture
= *bp
++;
424 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
425 config
->bindToTextureTargets
= *bp
++;
427 case GLX_Y_INVERTED_EXT
:
428 config
->yInverted
= *bp
++;
438 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
440 config
->haveAccumBuffer
= ((config
->accumRedBits
+
441 config
->accumGreenBits
+
442 config
->accumBlueBits
+
443 config
->accumAlphaBits
) > 0);
444 config
->haveDepthBuffer
= (config
->depthBits
> 0);
445 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
448 static __GLcontextModes
*
449 createConfigsFromProperties(Display
*dpy
, int nvisuals
, int nprops
,
450 int screen
, GLboolean tagged_only
)
452 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
454 __GLcontextModes
*modes
, *m
;
460 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
462 /* Check number of properties */
463 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
466 /* Allocate memory for our config structure */
467 modes
= _gl_context_modes_create(nvisuals
, sizeof(__GLcontextModes
));
471 prop_size
= nprops
* __GLX_SIZE_INT32
;
472 if (prop_size
<= sizeof(buf
))
475 props
= Xmalloc(prop_size
);
477 /* Read each config structure and convert it into our format */
479 for (i
= 0; i
< nvisuals
; i
++) {
480 _XRead(dpy
, (char *)props
, prop_size
);
481 /* Older X servers don't send this so we default it here. */
482 m
->drawableType
= GLX_WINDOW_BIT
;
483 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
484 tagged_only
, GL_TRUE
);
496 getVisualConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
, int screen
)
498 xGLXGetVisualConfigsReq
*req
;
499 __GLXscreenConfigs
*psc
;
500 xGLXGetVisualConfigsReply reply
;
504 psc
= priv
->screenConfigs
+ screen
;
506 GetReq(GLXGetVisualConfigs
, req
);
507 req
->reqType
= priv
->majorOpcode
;
508 req
->glxCode
= X_GLXGetVisualConfigs
;
509 req
->screen
= screen
;
511 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
))
514 psc
->visuals
= createConfigsFromProperties(dpy
,
521 return psc
->visuals
!= NULL
;
525 getFBConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
, int screen
)
527 xGLXGetFBConfigsReq
*fb_req
;
528 xGLXGetFBConfigsSGIXReq
*sgi_req
;
529 xGLXVendorPrivateWithReplyReq
*vpreq
;
530 xGLXGetFBConfigsReply reply
;
531 __GLXscreenConfigs
*psc
;
533 psc
= priv
->screenConfigs
+ screen
;
534 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
535 X_GLXQueryServerString
,
536 screen
, GLX_EXTENSIONS
);
541 if (atof(priv
->serverGLXversion
) >= 1.3) {
542 GetReq(GLXGetFBConfigs
, fb_req
);
543 fb_req
->reqType
= priv
->majorOpcode
;
544 fb_req
->glxCode
= X_GLXGetFBConfigs
;
545 fb_req
->screen
= screen
;
546 } else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
547 GetReqExtra(GLXVendorPrivateWithReply
,
548 sz_xGLXGetFBConfigsSGIXReq
+
549 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
550 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
551 sgi_req
->reqType
= priv
->majorOpcode
;
552 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
553 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
554 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.
575 static Bool
AllocAndFetchScreenConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
)
577 __GLXscreenConfigs
*psc
;
581 ** First allocate memory for the array of per screen configs.
583 screens
= ScreenCount(dpy
);
584 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
588 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
589 priv
->screenConfigs
= psc
;
591 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
592 X_GLXQueryServerString
,
594 if ( priv
->serverGLXversion
== NULL
) {
595 FreeScreenConfigs(priv
);
599 for (i
= 0; i
< screens
; i
++, psc
++) {
600 getVisualConfigs(dpy
, priv
, i
);
601 getFBConfigs(dpy
, priv
, i
);
603 #ifdef GLX_DIRECT_RENDERING
606 psc
->drawHash
= __glxHashCreate();
607 if (psc
->drawHash
== NULL
)
610 if (priv
->dri2Display
)
611 psc
->driScreen
= (*priv
->dri2Display
->createScreen
)(psc
, i
, priv
);
613 if (psc
->driScreen
== NULL
&& priv
->driDisplay
)
614 psc
->driScreen
= (*priv
->driDisplay
->createScreen
)(psc
, i
, priv
);
616 if (psc
->driScreen
== NULL
&& priv
->driswDisplay
)
617 psc
->driScreen
= (*priv
->driswDisplay
->createScreen
)(psc
, i
, priv
);
619 if (psc
->driScreen
== NULL
) {
620 __glxHashDestroy(psc
->drawHash
);
621 psc
->drawHash
= NULL
;
630 ** Initialize the client side extension code.
632 _X_HIDDEN __GLXdisplayPrivate
*__glXInitialize(Display
* dpy
)
634 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
635 XExtData
**privList
, *private, *found
;
636 __GLXdisplayPrivate
*dpyPriv
;
637 XEDataObject dataObj
;
639 #ifdef GLX_DIRECT_RENDERING
640 Bool glx_direct
, glx_accel
;
643 #if defined(USE_XTHREADS)
645 static int firstCall
= 1;
647 /* initialize the GLX mutexes */
648 xmutex_init(&__glXmutex
);
655 /* The one and only long long lock */
658 if (!XextHasExtension(info
)) {
659 /* No GLX extension supported by this server. Oh well. */
661 XMissingExtension(dpy
, __glXExtensionName
);
665 /* See if a display private already exists. If so, return it */
666 dataObj
.display
= dpy
;
667 privList
= XEHeadOfExtensionList(dataObj
);
668 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
671 return (__GLXdisplayPrivate
*) found
->private_data
;
674 /* See if the versions are compatible */
675 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
676 /* The client and server do not agree on versions. Punt. */
682 ** Allocate memory for all the pieces needed for this buffer.
684 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
689 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
692 Xfree((char*) private);
697 ** Init the display private and then read in the screen config
698 ** structures from the server.
700 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
701 dpyPriv
->majorVersion
= major
;
702 dpyPriv
->minorVersion
= minor
;
705 dpyPriv
->serverGLXvendor
= 0x0;
706 dpyPriv
->serverGLXversion
= 0x0;
708 #ifdef GLX_DIRECT_RENDERING
709 glx_direct
= (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
);
710 glx_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
713 ** Initialize the direct rendering per display data and functions.
714 ** Note: This _must_ be done before calling any other DRI routines
715 ** (e.g., those called in AllocAndFetchScreenConfigs).
717 if (glx_direct
&& glx_accel
) {
718 dpyPriv
->dri2Display
= dri2CreateDisplay(dpy
);
719 dpyPriv
->driDisplay
= driCreateDisplay(dpy
);
722 dpyPriv
->driswDisplay
= driswCreateDisplay(dpy
);
725 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
727 Xfree((char*) dpyPriv
);
728 Xfree((char*) private);
733 ** Fill in the private structure. This is the actual structure that
734 ** hangs off of the Display structure. Our private structure is
735 ** referred to by this structure. Got that?
737 private->number
= info
->codes
->extension
;
739 private->free_private
= __glXFreeDisplayPrivate
;
740 private->private_data
= (char *) dpyPriv
;
741 XAddToExtensionList(privList
, private);
743 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
744 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
752 ** Setup for sending a GLX command on dpy. Make sure the extension is
753 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
755 _X_HIDDEN CARD8
__glXSetupForCommand(Display
*dpy
)
758 __GLXdisplayPrivate
*priv
;
760 /* If this thread has a current context, flush its rendering commands */
761 gc
= __glXGetCurrentContext();
762 if (gc
->currentDpy
) {
763 /* Flush rendering buffer of the current context, if any */
764 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
766 if (gc
->currentDpy
== dpy
) {
767 /* Use opcode from gc because its right */
769 return gc
->majorOpcode
;
772 ** Have to get info about argument dpy because it might be to
773 ** a different server
778 /* Forced to lookup extension via the slow initialize route */
779 priv
= __glXInitialize(dpy
);
783 return priv
->majorOpcode
;
787 * Flush the drawing command transport buffer.
789 * \param ctx Context whose transport buffer is to be flushed.
790 * \param pc Pointer to first unused buffer location.
793 * Modify this function to use \c ctx->pc instead of the explicit
796 _X_HIDDEN GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*ctx
, GLubyte
*pc
)
798 Display
* const dpy
= ctx
->currentDpy
;
800 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
804 const GLint size
= pc
- ctx
->buf
;
806 if ( (dpy
!= NULL
) && (size
> 0) ) {
808 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
809 (const uint8_t *)ctx
->buf
);
811 /* Send the entire buffer as an X request */
813 GetReq(GLXRender
,req
);
814 req
->reqType
= ctx
->majorOpcode
;
815 req
->glxCode
= X_GLXRender
;
816 req
->contextTag
= ctx
->currentContextTag
;
817 req
->length
+= (size
+ 3) >> 2;
818 _XSend(dpy
, (char *)ctx
->buf
, size
);
824 /* Reset pointer and return it */
831 * Send a portion of a GLXRenderLarge command to the server. The advantage of
832 * this function over \c __glXSendLargeCommand is that callers can use the
833 * data buffer in the GLX context and may be able to avoid allocating an
834 * extra buffer. The disadvantage is the clients will have to do more
835 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
837 * \sa __glXSendLargeCommand
839 * \param gc GLX context
840 * \param requestNumber Which part of the whole command is this? The first
842 * \param totalRequests How many requests will there be?
843 * \param data Command data.
844 * \param dataLen Size, in bytes, of the command data.
846 _X_HIDDEN
void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
848 const GLvoid
* data
, GLint dataLen
)
850 Display
*dpy
= gc
->currentDpy
;
852 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
853 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
, totalRequests
, dataLen
, data
);
855 xGLXRenderLargeReq
*req
;
857 if ( requestNumber
== 1 ) {
861 GetReq(GLXRenderLarge
,req
);
862 req
->reqType
= gc
->majorOpcode
;
863 req
->glxCode
= X_GLXRenderLarge
;
864 req
->contextTag
= gc
->currentContextTag
;
865 req
->length
+= (dataLen
+ 3) >> 2;
866 req
->requestNumber
= requestNumber
;
867 req
->requestTotal
= totalRequests
;
868 req
->dataBytes
= dataLen
;
869 Data(dpy
, data
, dataLen
);
871 if ( requestNumber
== totalRequests
) {
880 * Send a command that is too large for the GLXRender protocol request.
882 * Send a large command, one that is too large for some reason to
883 * send using the GLXRender protocol request. One reason to send
884 * a large command is to avoid copying the data.
886 * \param ctx GLX context
887 * \param header Header data.
888 * \param headerLen Size, in bytes, of the header data. It is assumed that
889 * the header data will always be small enough to fit in
890 * a single X protocol packet.
891 * \param data Command data.
892 * \param dataLen Size, in bytes, of the command data.
894 _X_HIDDEN
void __glXSendLargeCommand(__GLXcontext
*ctx
,
895 const GLvoid
*header
, GLint headerLen
,
896 const GLvoid
*data
, GLint dataLen
)
899 GLint totalRequests
, requestNumber
;
902 ** Calculate the maximum amount of data can be stuffed into a single
903 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
904 ** packet size minus sz_xGLXRenderReq.
906 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
907 totalRequests
= 1 + (dataLen
/ maxSize
);
908 if (dataLen
% maxSize
) totalRequests
++;
911 ** Send all of the command, except the large array, as one request.
913 assert( headerLen
<= maxSize
);
914 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
917 ** Send enough requests until the whole array is sent.
919 for ( requestNumber
= 2 ; requestNumber
<= (totalRequests
- 1) ; requestNumber
++ ) {
920 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
921 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
923 assert( dataLen
> 0 );
926 assert( dataLen
<= maxSize
);
927 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
930 /************************************************************************/
933 _X_HIDDEN
void __glXDumpDrawBuffer(__GLXcontext
*ctx
)
935 GLubyte
*p
= ctx
->buf
;
936 GLubyte
*end
= ctx
->pc
;
937 GLushort opcode
, length
;
941 opcode
= *((GLushort
*) p
);
942 length
= *((GLushort
*) (p
+ 2));
943 printf("%2x: %5d: ", opcode
, length
);
947 printf("%08x ", *((unsigned *) p
));
958 * This is where our dispatch table's bounds are.
959 * And the static mesa_init is taken directly from
960 * Mesa's 'sparc.c' initializer.
962 * We need something like this here, because this version
963 * of openGL/glx never initializes a Mesa context, and so
964 * the address of the dispatch table pointer never gets stuffed
965 * into the dispatch jump table otherwise.
967 * It matters only on SPARC, and only if you are using assembler
968 * code instead of C-code indirect dispatch.
972 extern unsigned int _mesa_sparc_glapi_begin
;
973 extern unsigned int _mesa_sparc_glapi_end
;
974 extern void __glapi_sparc_icache_flush(unsigned int *);
977 _glx_mesa_init_sparc_glapi_relocs(void)
979 unsigned int *insn_ptr
, *end_ptr
;
980 unsigned long disp_addr
;
982 insn_ptr
= &_mesa_sparc_glapi_begin
;
983 end_ptr
= &_mesa_sparc_glapi_end
;
984 disp_addr
= (unsigned long) &_glapi_Dispatch
;
987 * Verbatim from Mesa sparc.c. It's needed because there doesn't
988 * seem to be a better way to do this:
990 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
992 * This code is patching in the ADDRESS of the pointer to the
993 * dispatch table. Hence, it must be called exactly once, because
994 * that address is not going to change.
996 * What it points to can change, but Mesa (and hence, we) assume
997 * that there is only one pointer.
1000 while (insn_ptr
< end_ptr
) {
1001 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1003 This code patches for 64-bit addresses. This had better
1004 not happen for Sparc/Linux, no matter what architecture we
1005 are building for. So, don't do this.
1007 The 'defined(__linux_64__)' is used here as a placeholder for
1008 when we do do 64-bit usermode on sparc linux.
1010 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1011 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1012 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1013 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1014 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1015 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1018 insn_ptr
[0] |= (disp_addr
>> 10);
1019 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1020 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1025 #endif /* sparc ASM in use */