1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
3 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
4 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice including the dates of first publication and
14 * either this permission notice or a reference to
15 * http://oss.sgi.com/projects/FreeB/
16 * shall be included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Except as contained in this notice, the name of Silicon Graphics, Inc.
27 * shall not be used in advertising or otherwise to promote the sale, use or
28 * other dealings in this Software without prior written authorization from
29 * Silicon Graphics, Inc.
34 * GLX protocol interface boot-strap code.
36 * Direct rendering support added by Precision Insight, Inc.
38 * \author Kevin E. Martin <kevin@precisioninsight.com>
42 #include "glxclient.h"
43 #include <X11/extensions/Xext.h>
44 #include <X11/extensions/extutil.h>
46 #include "glxextensions.h"
47 #include "glcontextmodes.h"
50 #include <X11/Xlib-xcb.h>
57 void __glXDumpDrawBuffer(__GLXcontext
* ctx
);
61 static void _glx_mesa_init_sparc_glapi_relocs(void);
62 static int _mesa_sparc_needs_init
= 1;
63 #define INIT_MESA_SPARC do { \
64 if (_mesa_sparc_needs_init) { \
65 _glx_mesa_init_sparc_glapi_relocs(); \
66 _mesa_sparc_needs_init = 0; \
70 #define INIT_MESA_SPARC do { } while(0)
74 ** You can set this cell to 1 to force the gl drawing stuff to be
75 ** one command per packet
77 _X_HIDDEN
int __glXDebug
= 0;
79 /* Extension required boiler plate */
81 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
82 XExtensionInfo
*__glXExtensionInfo
= NULL
;
84 static /* const */ char *error_list
[] = {
90 "GLXBadCurrentWindow",
91 "GLXBadRenderRequest",
93 "GLXUnsupportedPrivateRequest",
96 "GLXBadCurrentDrawable",
101 __glXCloseDisplay(Display
* dpy
, XExtCodes
* codes
)
105 gc
= __glXGetCurrentContext();
106 if (dpy
== gc
->currentDpy
) {
107 __glXSetCurrentContextNull();
108 __glXFreeContext(gc
);
111 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
116 XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
117 __GLX_NUMBER_ERRORS
, error_list
)
119 static /* const */ XExtensionHooks __glXExtensionHooks
= {
120 NULL
, /* create_gc */
124 NULL
, /* create_font */
125 NULL
, /* free_font */
126 __glXCloseDisplay
, /* close_display */
127 NULL
, /* wire_to_event */
128 NULL
, /* event_to_wire */
130 __glXErrorString
, /* error_string */
134 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
135 __glXExtensionName
, &__glXExtensionHooks
,
136 __GLX_NUMBER_EVENTS
, NULL
)
138 /************************************************************************/
140 ** Free the per screen configs data as well as the array of
141 ** __glXScreenConfigs.
143 static void 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
)
225 xGLXQueryVersionReq
*req
;
226 xGLXQueryVersionReply reply
;
228 /* Send the glXQueryVersion request */
230 GetReq(GLXQueryVersion
, req
);
231 req
->reqType
= opcode
;
232 req
->glxCode
= X_GLXQueryVersion
;
233 req
->majorVersion
= GLX_MAJOR_VERSION
;
234 req
->minorVersion
= GLX_MINOR_VERSION
;
235 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
239 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
241 ** The server does not support the same major release as this
246 *major
= reply
.majorVersion
;
247 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
253 __glXInitializeVisualConfigFromTags(__GLcontextModes
* config
, int count
,
254 const INT32
* bp
, Bool tagged_only
,
255 Bool fbconfig_style_tags
)
260 /* Copy in the first set of properties */
261 config
->visualID
= *bp
++;
263 config
->visualType
= _gl_convert_from_x_visual_type(*bp
++);
265 config
->rgbMode
= *bp
++;
267 config
->redBits
= *bp
++;
268 config
->greenBits
= *bp
++;
269 config
->blueBits
= *bp
++;
270 config
->alphaBits
= *bp
++;
271 config
->accumRedBits
= *bp
++;
272 config
->accumGreenBits
= *bp
++;
273 config
->accumBlueBits
= *bp
++;
274 config
->accumAlphaBits
= *bp
++;
276 config
->doubleBufferMode
= *bp
++;
277 config
->stereoMode
= *bp
++;
279 config
->rgbBits
= *bp
++;
280 config
->depthBits
= *bp
++;
281 config
->stencilBits
= *bp
++;
282 config
->numAuxBuffers
= *bp
++;
283 config
->level
= *bp
++;
285 count
-= __GLX_MIN_CONFIG_PROPS
;
289 ** Additional properties may be in a list at the end
290 ** of the reply. They are in pairs of property type
291 ** and property value.
294 #define FETCH_OR_SET(tag) \
295 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
297 for (i
= 0; i
< count
; i
+= 2) {
300 FETCH_OR_SET(rgbMode
);
302 case GLX_BUFFER_SIZE
:
303 config
->rgbBits
= *bp
++;
306 config
->level
= *bp
++;
308 case GLX_DOUBLEBUFFER
:
309 FETCH_OR_SET(doubleBufferMode
);
312 FETCH_OR_SET(stereoMode
);
314 case GLX_AUX_BUFFERS
:
315 config
->numAuxBuffers
= *bp
++;
318 config
->redBits
= *bp
++;
321 config
->greenBits
= *bp
++;
324 config
->blueBits
= *bp
++;
327 config
->alphaBits
= *bp
++;
330 config
->depthBits
= *bp
++;
332 case GLX_STENCIL_SIZE
:
333 config
->stencilBits
= *bp
++;
335 case GLX_ACCUM_RED_SIZE
:
336 config
->accumRedBits
= *bp
++;
338 case GLX_ACCUM_GREEN_SIZE
:
339 config
->accumGreenBits
= *bp
++;
341 case GLX_ACCUM_BLUE_SIZE
:
342 config
->accumBlueBits
= *bp
++;
344 case GLX_ACCUM_ALPHA_SIZE
:
345 config
->accumAlphaBits
= *bp
++;
347 case GLX_VISUAL_CAVEAT_EXT
:
348 config
->visualRating
= *bp
++;
350 case GLX_X_VISUAL_TYPE
:
351 config
->visualType
= *bp
++;
353 case GLX_TRANSPARENT_TYPE
:
354 config
->transparentPixel
= *bp
++;
356 case GLX_TRANSPARENT_INDEX_VALUE
:
357 config
->transparentIndex
= *bp
++;
359 case GLX_TRANSPARENT_RED_VALUE
:
360 config
->transparentRed
= *bp
++;
362 case GLX_TRANSPARENT_GREEN_VALUE
:
363 config
->transparentGreen
= *bp
++;
365 case GLX_TRANSPARENT_BLUE_VALUE
:
366 config
->transparentBlue
= *bp
++;
368 case GLX_TRANSPARENT_ALPHA_VALUE
:
369 config
->transparentAlpha
= *bp
++;
372 config
->visualID
= *bp
++;
374 case GLX_DRAWABLE_TYPE
:
375 config
->drawableType
= *bp
++;
377 case GLX_RENDER_TYPE
:
378 config
->renderType
= *bp
++;
380 case GLX_X_RENDERABLE
:
381 config
->xRenderable
= *bp
++;
383 case GLX_FBCONFIG_ID
:
384 config
->fbconfigID
= *bp
++;
386 case GLX_MAX_PBUFFER_WIDTH
:
387 config
->maxPbufferWidth
= *bp
++;
389 case GLX_MAX_PBUFFER_HEIGHT
:
390 config
->maxPbufferHeight
= *bp
++;
392 case GLX_MAX_PBUFFER_PIXELS
:
393 config
->maxPbufferPixels
= *bp
++;
395 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
396 config
->optimalPbufferWidth
= *bp
++;
398 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
399 config
->optimalPbufferHeight
= *bp
++;
401 case GLX_VISUAL_SELECT_GROUP_SGIX
:
402 config
->visualSelectGroup
= *bp
++;
404 case GLX_SWAP_METHOD_OML
:
405 config
->swapMethod
= *bp
++;
407 case GLX_SAMPLE_BUFFERS_SGIS
:
408 config
->sampleBuffers
= *bp
++;
410 case GLX_SAMPLES_SGIS
:
411 config
->samples
= *bp
++;
413 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
414 config
->bindToTextureRgb
= *bp
++;
416 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
417 config
->bindToTextureRgba
= *bp
++;
419 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
420 config
->bindToMipmapTexture
= *bp
++;
422 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
423 config
->bindToTextureTargets
= *bp
++;
425 case GLX_Y_INVERTED_EXT
:
426 config
->yInverted
= *bp
++;
437 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
439 config
->haveAccumBuffer
= ((config
->accumRedBits
+
440 config
->accumGreenBits
+
441 config
->accumBlueBits
+
442 config
->accumAlphaBits
) > 0);
443 config
->haveDepthBuffer
= (config
->depthBits
> 0);
444 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
447 static __GLcontextModes
*
448 createConfigsFromProperties(Display
* dpy
, int nvisuals
, int nprops
,
449 int screen
, GLboolean tagged_only
)
451 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
453 __GLcontextModes
*modes
, *m
;
459 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
461 /* Check number of properties */
462 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
465 /* Allocate memory for our config structure */
466 modes
= _gl_context_modes_create(nvisuals
, sizeof(__GLcontextModes
));
470 prop_size
= nprops
* __GLX_SIZE_INT32
;
471 if (prop_size
<= sizeof(buf
))
474 props
= Xmalloc(prop_size
);
476 /* Read each config structure and convert it into our format */
478 for (i
= 0; i
< nvisuals
; i
++) {
479 _XRead(dpy
, (char *) props
, prop_size
);
480 /* Older X servers don't send this so we default it here. */
481 m
->drawableType
= GLX_WINDOW_BIT
;
482 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
483 tagged_only
, GL_TRUE
);
495 getVisualConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
497 xGLXGetVisualConfigsReq
*req
;
498 __GLXscreenConfigs
*psc
;
499 xGLXGetVisualConfigsReply reply
;
503 psc
= priv
->screenConfigs
+ screen
;
505 GetReq(GLXGetVisualConfigs
, req
);
506 req
->reqType
= priv
->majorOpcode
;
507 req
->glxCode
= X_GLXGetVisualConfigs
;
508 req
->screen
= screen
;
510 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
513 psc
->visuals
= createConfigsFromProperties(dpy
,
520 return psc
->visuals
!= NULL
;
524 getFBConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
526 xGLXGetFBConfigsReq
*fb_req
;
527 xGLXGetFBConfigsSGIXReq
*sgi_req
;
528 xGLXVendorPrivateWithReplyReq
*vpreq
;
529 xGLXGetFBConfigsReply reply
;
530 __GLXscreenConfigs
*psc
;
532 psc
= priv
->screenConfigs
+ screen
;
533 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
534 X_GLXQueryServerString
,
535 screen
, GLX_EXTENSIONS
);
540 if (atof(priv
->serverGLXversion
) >= 1.3) {
541 GetReq(GLXGetFBConfigs
, fb_req
);
542 fb_req
->reqType
= priv
->majorOpcode
;
543 fb_req
->glxCode
= X_GLXGetFBConfigs
;
544 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
;
559 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
562 psc
->configs
= createConfigsFromProperties(dpy
,
564 reply
.numAttribs
* 2,
569 return psc
->configs
!= NULL
;
573 ** Allocate the memory for the per screen configs for each screen.
574 ** If that works then fetch the per screen configs data.
577 AllocAndFetchScreenConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
)
579 __GLXscreenConfigs
*psc
;
583 ** First allocate memory for the array of per screen configs.
585 screens
= ScreenCount(dpy
);
586 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
590 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
591 priv
->screenConfigs
= psc
;
593 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
594 X_GLXQueryServerString
,
596 if (priv
->serverGLXversion
== NULL
) {
597 FreeScreenConfigs(priv
);
601 for (i
= 0; i
< screens
; i
++, psc
++) {
602 getVisualConfigs(dpy
, priv
, i
);
603 getFBConfigs(dpy
, priv
, i
);
605 #ifdef GLX_DIRECT_RENDERING
608 psc
->drawHash
= __glxHashCreate();
609 if (psc
->drawHash
== NULL
)
612 if (priv
->dri2Display
)
613 psc
->driScreen
= (*priv
->dri2Display
->createScreen
) (psc
, i
, priv
);
615 if (psc
->driScreen
== NULL
&& priv
->driDisplay
)
616 psc
->driScreen
= (*priv
->driDisplay
->createScreen
) (psc
, i
, priv
);
618 if (psc
->driScreen
== NULL
&& priv
->driswDisplay
)
619 psc
->driScreen
= (*priv
->driswDisplay
->createScreen
) (psc
, i
, priv
);
621 if (psc
->driScreen
== NULL
) {
622 __glxHashDestroy(psc
->drawHash
);
623 psc
->drawHash
= NULL
;
632 ** Initialize the client side extension code.
634 _X_HIDDEN __GLXdisplayPrivate
*
635 __glXInitialize(Display
* dpy
)
637 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
638 XExtData
**privList
, *private, *found
;
639 __GLXdisplayPrivate
*dpyPriv
;
640 XEDataObject dataObj
;
642 #ifdef GLX_DIRECT_RENDERING
643 Bool glx_direct
, glx_accel
;
646 #if defined(USE_XTHREADS)
648 static int firstCall
= 1;
650 /* initialize the GLX mutexes */
651 xmutex_init(&__glXmutex
);
658 /* The one and only long long lock */
661 if (!XextHasExtension(info
)) {
662 /* No GLX extension supported by this server. Oh well. */
664 XMissingExtension(dpy
, __glXExtensionName
);
668 /* See if a display private already exists. If so, return it */
669 dataObj
.display
= dpy
;
670 privList
= XEHeadOfExtensionList(dataObj
);
671 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
674 return (__GLXdisplayPrivate
*) found
->private_data
;
677 /* See if the versions are compatible */
678 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
679 /* The client and server do not agree on versions. Punt. */
685 ** Allocate memory for all the pieces needed for this buffer.
687 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
692 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
695 Xfree((char *) private);
700 ** Init the display private and then read in the screen config
701 ** structures from the server.
703 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
704 dpyPriv
->majorVersion
= major
;
705 dpyPriv
->minorVersion
= minor
;
708 dpyPriv
->serverGLXvendor
= 0x0;
709 dpyPriv
->serverGLXversion
= 0x0;
711 #ifdef GLX_DIRECT_RENDERING
712 glx_direct
= (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
);
713 glx_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
716 ** Initialize the direct rendering per display data and functions.
717 ** Note: This _must_ be done before calling any other DRI routines
718 ** (e.g., those called in AllocAndFetchScreenConfigs).
720 if (glx_direct
&& glx_accel
) {
721 dpyPriv
->dri2Display
= dri2CreateDisplay(dpy
);
722 dpyPriv
->driDisplay
= driCreateDisplay(dpy
);
725 dpyPriv
->driswDisplay
= driswCreateDisplay(dpy
);
728 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
730 Xfree((char *) dpyPriv
);
731 Xfree((char *) private);
736 ** Fill in the private structure. This is the actual structure that
737 ** hangs off of the Display structure. Our private structure is
738 ** referred to by this structure. Got that?
740 private->number
= info
->codes
->extension
;
742 private->free_private
= __glXFreeDisplayPrivate
;
743 private->private_data
= (char *) dpyPriv
;
744 XAddToExtensionList(privList
, private);
746 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
747 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
755 ** Setup for sending a GLX command on dpy. Make sure the extension is
756 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
759 __glXSetupForCommand(Display
* dpy
)
762 __GLXdisplayPrivate
*priv
;
764 /* If this thread has a current context, flush its rendering commands */
765 gc
= __glXGetCurrentContext();
766 if (gc
->currentDpy
) {
767 /* Flush rendering buffer of the current context, if any */
768 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
770 if (gc
->currentDpy
== dpy
) {
771 /* Use opcode from gc because its right */
773 return gc
->majorOpcode
;
777 ** Have to get info about argument dpy because it might be to
778 ** a different server
783 /* Forced to lookup extension via the slow initialize route */
784 priv
= __glXInitialize(dpy
);
788 return priv
->majorOpcode
;
792 * Flush the drawing command transport buffer.
794 * \param ctx Context whose transport buffer is to be flushed.
795 * \param pc Pointer to first unused buffer location.
798 * Modify this function to use \c ctx->pc instead of the explicit
802 __glXFlushRenderBuffer(__GLXcontext
* ctx
, GLubyte
* pc
)
804 Display
*const dpy
= ctx
->currentDpy
;
806 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
810 const GLint size
= pc
- ctx
->buf
;
812 if ((dpy
!= NULL
) && (size
> 0)) {
814 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
815 (const uint8_t *) ctx
->buf
);
817 /* Send the entire buffer as an X request */
819 GetReq(GLXRender
, req
);
820 req
->reqType
= ctx
->majorOpcode
;
821 req
->glxCode
= X_GLXRender
;
822 req
->contextTag
= ctx
->currentContextTag
;
823 req
->length
+= (size
+ 3) >> 2;
824 _XSend(dpy
, (char *) ctx
->buf
, size
);
830 /* Reset pointer and return it */
837 * Send a portion of a GLXRenderLarge command to the server. The advantage of
838 * this function over \c __glXSendLargeCommand is that callers can use the
839 * data buffer in the GLX context and may be able to avoid allocating an
840 * extra buffer. The disadvantage is the clients will have to do more
841 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
843 * \sa __glXSendLargeCommand
845 * \param gc GLX context
846 * \param requestNumber Which part of the whole command is this? The first
848 * \param totalRequests How many requests will there be?
849 * \param data Command data.
850 * \param dataLen Size, in bytes, of the command data.
853 __glXSendLargeChunk(__GLXcontext
* gc
, GLint requestNumber
,
854 GLint totalRequests
, const GLvoid
* data
, GLint dataLen
)
856 Display
*dpy
= gc
->currentDpy
;
858 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
859 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
,
860 totalRequests
, dataLen
, data
);
862 xGLXRenderLargeReq
*req
;
864 if (requestNumber
== 1) {
868 GetReq(GLXRenderLarge
, req
);
869 req
->reqType
= gc
->majorOpcode
;
870 req
->glxCode
= X_GLXRenderLarge
;
871 req
->contextTag
= gc
->currentContextTag
;
872 req
->length
+= (dataLen
+ 3) >> 2;
873 req
->requestNumber
= requestNumber
;
874 req
->requestTotal
= totalRequests
;
875 req
->dataBytes
= dataLen
;
876 Data(dpy
, data
, dataLen
);
878 if (requestNumber
== totalRequests
) {
887 * Send a command that is too large for the GLXRender protocol request.
889 * Send a large command, one that is too large for some reason to
890 * send using the GLXRender protocol request. One reason to send
891 * a large command is to avoid copying the data.
893 * \param ctx GLX context
894 * \param header Header data.
895 * \param headerLen Size, in bytes, of the header data. It is assumed that
896 * the header data will always be small enough to fit in
897 * a single X protocol packet.
898 * \param data Command data.
899 * \param dataLen Size, in bytes, of the command data.
902 __glXSendLargeCommand(__GLXcontext
* ctx
,
903 const GLvoid
* header
, GLint headerLen
,
904 const GLvoid
* data
, GLint dataLen
)
907 GLint totalRequests
, requestNumber
;
910 ** Calculate the maximum amount of data can be stuffed into a single
911 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
912 ** packet size minus sz_xGLXRenderReq.
914 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
915 totalRequests
= 1 + (dataLen
/ maxSize
);
916 if (dataLen
% maxSize
)
920 ** Send all of the command, except the large array, as one request.
922 assert(headerLen
<= maxSize
);
923 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
926 ** Send enough requests until the whole array is sent.
928 for (requestNumber
= 2; requestNumber
<= (totalRequests
- 1);
930 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
931 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
936 assert(dataLen
<= maxSize
);
937 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
940 /************************************************************************/
944 __glXDumpDrawBuffer(__GLXcontext
* ctx
)
946 GLubyte
*p
= ctx
->buf
;
947 GLubyte
*end
= ctx
->pc
;
948 GLushort opcode
, length
;
952 opcode
= *((GLushort
*) p
);
953 length
= *((GLushort
*) (p
+ 2));
954 printf("%2x: %5d: ", opcode
, length
);
958 printf("%08x ", *((unsigned *) p
));
969 * This is where our dispatch table's bounds are.
970 * And the static mesa_init is taken directly from
971 * Mesa's 'sparc.c' initializer.
973 * We need something like this here, because this version
974 * of openGL/glx never initializes a Mesa context, and so
975 * the address of the dispatch table pointer never gets stuffed
976 * into the dispatch jump table otherwise.
978 * It matters only on SPARC, and only if you are using assembler
979 * code instead of C-code indirect dispatch.
983 extern unsigned int _mesa_sparc_glapi_begin
;
984 extern unsigned int _mesa_sparc_glapi_end
;
985 extern void __glapi_sparc_icache_flush(unsigned int *);
988 _glx_mesa_init_sparc_glapi_relocs(void)
990 unsigned int *insn_ptr
, *end_ptr
;
991 unsigned long disp_addr
;
993 insn_ptr
= &_mesa_sparc_glapi_begin
;
994 end_ptr
= &_mesa_sparc_glapi_end
;
995 disp_addr
= (unsigned long) &_glapi_Dispatch
;
998 * Verbatim from Mesa sparc.c. It's needed because there doesn't
999 * seem to be a better way to do this:
1001 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1003 * This code is patching in the ADDRESS of the pointer to the
1004 * dispatch table. Hence, it must be called exactly once, because
1005 * that address is not going to change.
1007 * What it points to can change, but Mesa (and hence, we) assume
1008 * that there is only one pointer.
1011 while (insn_ptr
< end_ptr
) {
1012 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1014 This code patches for 64-bit addresses. This had better
1015 not happen for Sparc/Linux, no matter what architecture we
1016 are building for. So, don't do this.
1018 The 'defined(__linux_64__)' is used here as a placeholder for
1019 when we do do 64-bit usermode on sparc linux.
1021 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1022 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1023 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1024 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1025 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1026 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1029 insn_ptr
[0] |= (disp_addr
>> 10);
1030 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1031 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1036 #endif /* sparc ASM in use */