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.
143 FreeScreenConfigs(__GLXdisplayPrivate
* priv
)
145 __GLXscreenConfigs
*psc
;
148 /* Free screen configuration information */
149 psc
= priv
->screenConfigs
;
150 screens
= ScreenCount(priv
->dpy
);
151 for (i
= 0; i
< screens
; i
++, psc
++) {
153 _gl_context_modes_destroy(psc
->configs
);
154 if (psc
->effectiveGLXexts
)
155 Xfree(psc
->effectiveGLXexts
);
156 psc
->configs
= NULL
; /* NOTE: just for paranoia */
159 _gl_context_modes_destroy(psc
->visuals
);
160 psc
->visuals
= NULL
; /* NOTE: just for paranoia */
162 Xfree((char *) psc
->serverGLXexts
);
164 #ifdef GLX_DIRECT_RENDERING
165 if (psc
->driScreen
) {
166 psc
->driScreen
->destroyScreen(psc
);
167 __glxHashDestroy(psc
->drawHash
);
168 XFree(psc
->driScreen
);
169 psc
->driScreen
= NULL
;
173 XFree((char *) priv
->screenConfigs
);
174 priv
->screenConfigs
= NULL
;
178 ** Release the private memory referred to in a display private
179 ** structure. The caller will free the extension structure.
182 __glXFreeDisplayPrivate(XExtData
* extension
)
184 __GLXdisplayPrivate
*priv
;
186 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
187 FreeScreenConfigs(priv
);
188 if (priv
->serverGLXvendor
) {
189 Xfree((char *) priv
->serverGLXvendor
);
190 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
192 if (priv
->serverGLXversion
) {
193 Xfree((char *) priv
->serverGLXversion
);
194 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
197 #ifdef GLX_DIRECT_RENDERING
198 /* Free the direct rendering per display data */
199 if (priv
->driswDisplay
)
200 (*priv
->driswDisplay
->destroyDisplay
) (priv
->driswDisplay
);
201 priv
->driswDisplay
= NULL
;
203 if (priv
->driDisplay
)
204 (*priv
->driDisplay
->destroyDisplay
) (priv
->driDisplay
);
205 priv
->driDisplay
= NULL
;
207 if (priv
->dri2Display
)
208 (*priv
->dri2Display
->destroyDisplay
) (priv
->dri2Display
);
209 priv
->dri2Display
= NULL
;
212 Xfree((char *) priv
);
216 /************************************************************************/
219 ** Query the version of the GLX extension. This procedure works even if
220 ** the client extension is not completely set up.
223 QueryVersion(Display
* dpy
, int opcode
, int *major
, int *minor
)
226 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
227 xcb_glx_query_version_reply_t
* reply
=
228 xcb_glx_query_version_reply(c
,
229 xcb_glx_query_version(c
,
234 if(reply
->major_version
!= GLX_MAJOR_VERSION
)
239 *major
= reply
->major_version
;
240 *minor
= min(reply
->minor_version
, GLX_MINOR_VERSION
);
244 xGLXQueryVersionReq
*req
;
245 xGLXQueryVersionReply reply
;
247 /* Send the glXQueryVersion request */
249 GetReq(GLXQueryVersion
, req
);
250 req
->reqType
= opcode
;
251 req
->glxCode
= X_GLXQueryVersion
;
252 req
->majorVersion
= GLX_MAJOR_VERSION
;
253 req
->minorVersion
= GLX_MINOR_VERSION
;
254 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
258 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
260 ** The server does not support the same major release as this
265 *major
= reply
.majorVersion
;
266 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
273 __glXInitializeVisualConfigFromTags(__GLcontextModes
* config
, int count
,
274 const INT32
* bp
, Bool tagged_only
,
275 Bool fbconfig_style_tags
)
280 /* Copy in the first set of properties */
281 config
->visualID
= *bp
++;
283 config
->visualType
= _gl_convert_from_x_visual_type(*bp
++);
285 config
->rgbMode
= *bp
++;
287 config
->redBits
= *bp
++;
288 config
->greenBits
= *bp
++;
289 config
->blueBits
= *bp
++;
290 config
->alphaBits
= *bp
++;
291 config
->accumRedBits
= *bp
++;
292 config
->accumGreenBits
= *bp
++;
293 config
->accumBlueBits
= *bp
++;
294 config
->accumAlphaBits
= *bp
++;
296 config
->doubleBufferMode
= *bp
++;
297 config
->stereoMode
= *bp
++;
299 config
->rgbBits
= *bp
++;
300 config
->depthBits
= *bp
++;
301 config
->stencilBits
= *bp
++;
302 config
->numAuxBuffers
= *bp
++;
303 config
->level
= *bp
++;
305 count
-= __GLX_MIN_CONFIG_PROPS
;
309 ** Additional properties may be in a list at the end
310 ** of the reply. They are in pairs of property type
311 ** and property value.
314 #define FETCH_OR_SET(tag) \
315 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
317 for (i
= 0; i
< count
; i
+= 2) {
320 FETCH_OR_SET(rgbMode
);
322 case GLX_BUFFER_SIZE
:
323 config
->rgbBits
= *bp
++;
326 config
->level
= *bp
++;
328 case GLX_DOUBLEBUFFER
:
329 FETCH_OR_SET(doubleBufferMode
);
332 FETCH_OR_SET(stereoMode
);
334 case GLX_AUX_BUFFERS
:
335 config
->numAuxBuffers
= *bp
++;
338 config
->redBits
= *bp
++;
341 config
->greenBits
= *bp
++;
344 config
->blueBits
= *bp
++;
347 config
->alphaBits
= *bp
++;
350 config
->depthBits
= *bp
++;
352 case GLX_STENCIL_SIZE
:
353 config
->stencilBits
= *bp
++;
355 case GLX_ACCUM_RED_SIZE
:
356 config
->accumRedBits
= *bp
++;
358 case GLX_ACCUM_GREEN_SIZE
:
359 config
->accumGreenBits
= *bp
++;
361 case GLX_ACCUM_BLUE_SIZE
:
362 config
->accumBlueBits
= *bp
++;
364 case GLX_ACCUM_ALPHA_SIZE
:
365 config
->accumAlphaBits
= *bp
++;
367 case GLX_VISUAL_CAVEAT_EXT
:
368 config
->visualRating
= *bp
++;
370 case GLX_X_VISUAL_TYPE
:
371 config
->visualType
= *bp
++;
373 case GLX_TRANSPARENT_TYPE
:
374 config
->transparentPixel
= *bp
++;
376 case GLX_TRANSPARENT_INDEX_VALUE
:
377 config
->transparentIndex
= *bp
++;
379 case GLX_TRANSPARENT_RED_VALUE
:
380 config
->transparentRed
= *bp
++;
382 case GLX_TRANSPARENT_GREEN_VALUE
:
383 config
->transparentGreen
= *bp
++;
385 case GLX_TRANSPARENT_BLUE_VALUE
:
386 config
->transparentBlue
= *bp
++;
388 case GLX_TRANSPARENT_ALPHA_VALUE
:
389 config
->transparentAlpha
= *bp
++;
392 config
->visualID
= *bp
++;
394 case GLX_DRAWABLE_TYPE
:
395 config
->drawableType
= *bp
++;
397 case GLX_RENDER_TYPE
:
398 config
->renderType
= *bp
++;
400 case GLX_X_RENDERABLE
:
401 config
->xRenderable
= *bp
++;
403 case GLX_FBCONFIG_ID
:
404 config
->fbconfigID
= *bp
++;
406 case GLX_MAX_PBUFFER_WIDTH
:
407 config
->maxPbufferWidth
= *bp
++;
409 case GLX_MAX_PBUFFER_HEIGHT
:
410 config
->maxPbufferHeight
= *bp
++;
412 case GLX_MAX_PBUFFER_PIXELS
:
413 config
->maxPbufferPixels
= *bp
++;
415 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
416 config
->optimalPbufferWidth
= *bp
++;
418 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
419 config
->optimalPbufferHeight
= *bp
++;
421 case GLX_VISUAL_SELECT_GROUP_SGIX
:
422 config
->visualSelectGroup
= *bp
++;
424 case GLX_SWAP_METHOD_OML
:
425 config
->swapMethod
= *bp
++;
427 case GLX_SAMPLE_BUFFERS_SGIS
:
428 config
->sampleBuffers
= *bp
++;
430 case GLX_SAMPLES_SGIS
:
431 config
->samples
= *bp
++;
433 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
434 config
->bindToTextureRgb
= *bp
++;
436 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
437 config
->bindToTextureRgba
= *bp
++;
439 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
440 config
->bindToMipmapTexture
= *bp
++;
442 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
443 config
->bindToTextureTargets
= *bp
++;
445 case GLX_Y_INVERTED_EXT
:
446 config
->yInverted
= *bp
++;
457 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
459 config
->haveAccumBuffer
= ((config
->accumRedBits
+
460 config
->accumGreenBits
+
461 config
->accumBlueBits
+
462 config
->accumAlphaBits
) > 0);
463 config
->haveDepthBuffer
= (config
->depthBits
> 0);
464 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
467 static __GLcontextModes
*
468 createConfigsFromProperties(Display
* dpy
, int nvisuals
, int nprops
,
469 int screen
, GLboolean tagged_only
)
471 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
473 __GLcontextModes
*modes
, *m
;
479 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
481 /* Check number of properties */
482 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
485 /* Allocate memory for our config structure */
486 modes
= _gl_context_modes_create(nvisuals
, sizeof(__GLcontextModes
));
490 prop_size
= nprops
* __GLX_SIZE_INT32
;
491 if (prop_size
<= sizeof(buf
))
494 props
= Xmalloc(prop_size
);
496 /* Read each config structure and convert it into our format */
498 for (i
= 0; i
< nvisuals
; i
++) {
499 _XRead(dpy
, (char *) props
, prop_size
);
500 /* Older X servers don't send this so we default it here. */
501 m
->drawableType
= GLX_WINDOW_BIT
;
502 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
503 tagged_only
, GL_TRUE
);
515 getVisualConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
517 xGLXGetVisualConfigsReq
*req
;
518 __GLXscreenConfigs
*psc
;
519 xGLXGetVisualConfigsReply reply
;
523 psc
= priv
->screenConfigs
+ screen
;
525 GetReq(GLXGetVisualConfigs
, req
);
526 req
->reqType
= priv
->majorOpcode
;
527 req
->glxCode
= X_GLXGetVisualConfigs
;
528 req
->screen
= screen
;
530 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
533 psc
->visuals
= createConfigsFromProperties(dpy
,
540 return psc
->visuals
!= NULL
;
544 getFBConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
546 xGLXGetFBConfigsReq
*fb_req
;
547 xGLXGetFBConfigsSGIXReq
*sgi_req
;
548 xGLXVendorPrivateWithReplyReq
*vpreq
;
549 xGLXGetFBConfigsReply reply
;
550 __GLXscreenConfigs
*psc
;
552 psc
= priv
->screenConfigs
+ screen
;
553 psc
->serverGLXexts
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, GLX_EXTENSIONS
);
558 if (atof(priv
->serverGLXversion
) >= 1.3) {
559 GetReq(GLXGetFBConfigs
, fb_req
);
560 fb_req
->reqType
= priv
->majorOpcode
;
561 fb_req
->glxCode
= X_GLXGetFBConfigs
;
562 fb_req
->screen
= screen
;
564 else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
565 GetReqExtra(GLXVendorPrivateWithReply
,
566 sz_xGLXGetFBConfigsSGIXReq
+
567 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
568 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
569 sgi_req
->reqType
= priv
->majorOpcode
;
570 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
571 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
572 sgi_req
->screen
= screen
;
577 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
580 psc
->configs
= createConfigsFromProperties(dpy
,
582 reply
.numAttribs
* 2,
587 return psc
->configs
!= NULL
;
591 ** Allocate the memory for the per screen configs for each screen.
592 ** If that works then fetch the per screen configs data.
595 AllocAndFetchScreenConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
)
597 __GLXscreenConfigs
*psc
;
601 ** First allocate memory for the array of per screen configs.
603 screens
= ScreenCount(dpy
);
604 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
608 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
609 priv
->screenConfigs
= psc
;
611 priv
->serverGLXversion
= __glXQueryServerString(dpy
, priv
->majorOpcode
, 0, GLX_VERSION
);
612 if (priv
->serverGLXversion
== NULL
) {
613 FreeScreenConfigs(priv
);
617 for (i
= 0; i
< screens
; i
++, psc
++) {
618 getVisualConfigs(dpy
, priv
, i
);
619 getFBConfigs(dpy
, priv
, i
);
621 #ifdef GLX_DIRECT_RENDERING
624 psc
->drawHash
= __glxHashCreate();
625 if (psc
->drawHash
== NULL
)
628 if (priv
->dri2Display
)
629 psc
->driScreen
= (*priv
->dri2Display
->createScreen
) (psc
, i
, priv
);
631 if (psc
->driScreen
== NULL
&& priv
->driDisplay
)
632 psc
->driScreen
= (*priv
->driDisplay
->createScreen
) (psc
, i
, priv
);
634 if (psc
->driScreen
== NULL
&& priv
->driswDisplay
)
635 psc
->driScreen
= (*priv
->driswDisplay
->createScreen
) (psc
, i
, priv
);
637 if (psc
->driScreen
== NULL
) {
638 __glxHashDestroy(psc
->drawHash
);
639 psc
->drawHash
= NULL
;
648 ** Initialize the client side extension code.
650 _X_HIDDEN __GLXdisplayPrivate
*
651 __glXInitialize(Display
* dpy
)
653 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
654 XExtData
**privList
, *private, *found
;
655 __GLXdisplayPrivate
*dpyPriv
;
656 XEDataObject dataObj
;
658 #ifdef GLX_DIRECT_RENDERING
659 Bool glx_direct
, glx_accel
;
662 #if defined(USE_XTHREADS)
664 static int firstCall
= 1;
666 /* initialize the GLX mutexes */
667 xmutex_init(&__glXmutex
);
674 /* The one and only long long lock */
677 if (!XextHasExtension(info
)) {
678 /* No GLX extension supported by this server. Oh well. */
680 XMissingExtension(dpy
, __glXExtensionName
);
684 /* See if a display private already exists. If so, return it */
685 dataObj
.display
= dpy
;
686 privList
= XEHeadOfExtensionList(dataObj
);
687 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
690 return (__GLXdisplayPrivate
*) found
->private_data
;
693 /* See if the versions are compatible */
694 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
695 /* The client and server do not agree on versions. Punt. */
701 ** Allocate memory for all the pieces needed for this buffer.
703 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
708 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
711 Xfree((char *) private);
716 ** Init the display private and then read in the screen config
717 ** structures from the server.
719 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
720 dpyPriv
->majorVersion
= major
;
721 dpyPriv
->minorVersion
= minor
;
724 dpyPriv
->serverGLXvendor
= 0x0;
725 dpyPriv
->serverGLXversion
= 0x0;
727 #ifdef GLX_DIRECT_RENDERING
728 glx_direct
= (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
);
729 glx_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
732 ** Initialize the direct rendering per display data and functions.
733 ** Note: This _must_ be done before calling any other DRI routines
734 ** (e.g., those called in AllocAndFetchScreenConfigs).
736 if (glx_direct
&& glx_accel
) {
737 dpyPriv
->dri2Display
= dri2CreateDisplay(dpy
);
738 dpyPriv
->driDisplay
= driCreateDisplay(dpy
);
741 dpyPriv
->driswDisplay
= driswCreateDisplay(dpy
);
744 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
746 Xfree((char *) dpyPriv
);
747 Xfree((char *) private);
752 ** Fill in the private structure. This is the actual structure that
753 ** hangs off of the Display structure. Our private structure is
754 ** referred to by this structure. Got that?
756 private->number
= info
->codes
->extension
;
758 private->free_private
= __glXFreeDisplayPrivate
;
759 private->private_data
= (char *) dpyPriv
;
760 XAddToExtensionList(privList
, private);
762 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
763 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
771 ** Setup for sending a GLX command on dpy. Make sure the extension is
772 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
775 __glXSetupForCommand(Display
* dpy
)
778 __GLXdisplayPrivate
*priv
;
780 /* If this thread has a current context, flush its rendering commands */
781 gc
= __glXGetCurrentContext();
782 if (gc
->currentDpy
) {
783 /* Flush rendering buffer of the current context, if any */
784 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
786 if (gc
->currentDpy
== dpy
) {
787 /* Use opcode from gc because its right */
789 return gc
->majorOpcode
;
793 ** Have to get info about argument dpy because it might be to
794 ** a different server
799 /* Forced to lookup extension via the slow initialize route */
800 priv
= __glXInitialize(dpy
);
804 return priv
->majorOpcode
;
808 * Flush the drawing command transport buffer.
810 * \param ctx Context whose transport buffer is to be flushed.
811 * \param pc Pointer to first unused buffer location.
814 * Modify this function to use \c ctx->pc instead of the explicit
818 __glXFlushRenderBuffer(__GLXcontext
* ctx
, GLubyte
* pc
)
820 Display
*const dpy
= ctx
->currentDpy
;
822 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
826 const GLint size
= pc
- ctx
->buf
;
828 if ((dpy
!= NULL
) && (size
> 0)) {
830 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
831 (const uint8_t *) ctx
->buf
);
833 /* Send the entire buffer as an X request */
835 GetReq(GLXRender
, req
);
836 req
->reqType
= ctx
->majorOpcode
;
837 req
->glxCode
= X_GLXRender
;
838 req
->contextTag
= ctx
->currentContextTag
;
839 req
->length
+= (size
+ 3) >> 2;
840 _XSend(dpy
, (char *) ctx
->buf
, size
);
846 /* Reset pointer and return it */
853 * Send a portion of a GLXRenderLarge command to the server. The advantage of
854 * this function over \c __glXSendLargeCommand is that callers can use the
855 * data buffer in the GLX context and may be able to avoid allocating an
856 * extra buffer. The disadvantage is the clients will have to do more
857 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
859 * \sa __glXSendLargeCommand
861 * \param gc GLX context
862 * \param requestNumber Which part of the whole command is this? The first
864 * \param totalRequests How many requests will there be?
865 * \param data Command data.
866 * \param dataLen Size, in bytes, of the command data.
869 __glXSendLargeChunk(__GLXcontext
* gc
, GLint requestNumber
,
870 GLint totalRequests
, const GLvoid
* data
, GLint dataLen
)
872 Display
*dpy
= gc
->currentDpy
;
874 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
875 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
,
876 totalRequests
, dataLen
, data
);
878 xGLXRenderLargeReq
*req
;
880 if (requestNumber
== 1) {
884 GetReq(GLXRenderLarge
, req
);
885 req
->reqType
= gc
->majorOpcode
;
886 req
->glxCode
= X_GLXRenderLarge
;
887 req
->contextTag
= gc
->currentContextTag
;
888 req
->length
+= (dataLen
+ 3) >> 2;
889 req
->requestNumber
= requestNumber
;
890 req
->requestTotal
= totalRequests
;
891 req
->dataBytes
= dataLen
;
892 Data(dpy
, data
, dataLen
);
894 if (requestNumber
== totalRequests
) {
903 * Send a command that is too large for the GLXRender protocol request.
905 * Send a large command, one that is too large for some reason to
906 * send using the GLXRender protocol request. One reason to send
907 * a large command is to avoid copying the data.
909 * \param ctx GLX context
910 * \param header Header data.
911 * \param headerLen Size, in bytes, of the header data. It is assumed that
912 * the header data will always be small enough to fit in
913 * a single X protocol packet.
914 * \param data Command data.
915 * \param dataLen Size, in bytes, of the command data.
918 __glXSendLargeCommand(__GLXcontext
* ctx
,
919 const GLvoid
* header
, GLint headerLen
,
920 const GLvoid
* data
, GLint dataLen
)
923 GLint totalRequests
, requestNumber
;
926 ** Calculate the maximum amount of data can be stuffed into a single
927 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
928 ** packet size minus sz_xGLXRenderReq.
930 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
931 totalRequests
= 1 + (dataLen
/ maxSize
);
932 if (dataLen
% maxSize
)
936 ** Send all of the command, except the large array, as one request.
938 assert(headerLen
<= maxSize
);
939 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
942 ** Send enough requests until the whole array is sent.
944 for (requestNumber
= 2; requestNumber
<= (totalRequests
- 1);
946 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
947 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
952 assert(dataLen
<= maxSize
);
953 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
956 /************************************************************************/
960 __glXDumpDrawBuffer(__GLXcontext
* ctx
)
962 GLubyte
*p
= ctx
->buf
;
963 GLubyte
*end
= ctx
->pc
;
964 GLushort opcode
, length
;
968 opcode
= *((GLushort
*) p
);
969 length
= *((GLushort
*) (p
+ 2));
970 printf("%2x: %5d: ", opcode
, length
);
974 printf("%08x ", *((unsigned *) p
));
985 * This is where our dispatch table's bounds are.
986 * And the static mesa_init is taken directly from
987 * Mesa's 'sparc.c' initializer.
989 * We need something like this here, because this version
990 * of openGL/glx never initializes a Mesa context, and so
991 * the address of the dispatch table pointer never gets stuffed
992 * into the dispatch jump table otherwise.
994 * It matters only on SPARC, and only if you are using assembler
995 * code instead of C-code indirect dispatch.
999 extern unsigned int _mesa_sparc_glapi_begin
;
1000 extern unsigned int _mesa_sparc_glapi_end
;
1001 extern void __glapi_sparc_icache_flush(unsigned int *);
1004 _glx_mesa_init_sparc_glapi_relocs(void)
1006 unsigned int *insn_ptr
, *end_ptr
;
1007 unsigned long disp_addr
;
1009 insn_ptr
= &_mesa_sparc_glapi_begin
;
1010 end_ptr
= &_mesa_sparc_glapi_end
;
1011 disp_addr
= (unsigned long) &_glapi_Dispatch
;
1014 * Verbatim from Mesa sparc.c. It's needed because there doesn't
1015 * seem to be a better way to do this:
1017 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1019 * This code is patching in the ADDRESS of the pointer to the
1020 * dispatch table. Hence, it must be called exactly once, because
1021 * that address is not going to change.
1023 * What it points to can change, but Mesa (and hence, we) assume
1024 * that there is only one pointer.
1027 while (insn_ptr
< end_ptr
) {
1028 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1030 This code patches for 64-bit addresses. This had better
1031 not happen for Sparc/Linux, no matter what architecture we
1032 are building for. So, don't do this.
1034 The 'defined(__linux_64__)' is used here as a placeholder for
1035 when we do do 64-bit usermode on sparc linux.
1037 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1038 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1039 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1040 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1041 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1042 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1045 insn_ptr
[0] |= (disp_addr
>> 10);
1046 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1047 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1052 #endif /* sparc ASM in use */