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(
470 uint32_t* properties
,
474 int nvisuals
, int nprops
,
475 int screen
, GLboolean tagged_only
)
477 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
479 __GLcontextModes
*modes
, *m
;
485 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
487 /* Check number of properties */
488 if (nprops
< __GLX_MIN_CONFIG_PROPS
|| nprops
> __GLX_MAX_CONFIG_PROPS
)
491 /* Allocate memory for our config structure */
492 modes
= _gl_context_modes_create(nvisuals
, sizeof(__GLcontextModes
));
496 prop_size
= nprops
* __GLX_SIZE_INT32
;
497 if (prop_size
<= sizeof(buf
))
500 props
= Xmalloc(prop_size
);
502 /* Read each config structure and convert it into our format */
504 for (i
= 0; i
< nvisuals
; i
++) {
506 memcpy(props
, &properties
[i
*nprops
], prop_size
);
508 _XRead(dpy
, (char *) props
, prop_size
);
510 /* Older X servers don't send this so we default it here. */
511 m
->drawableType
= GLX_WINDOW_BIT
;
512 __glXInitializeVisualConfigFromTags(m
, nprops
, props
,
513 tagged_only
, GL_TRUE
);
525 getVisualConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
527 __GLXscreenConfigs
*psc
;
529 xcb_connection_t
* c
= XGetXCBConnection(dpy
);
530 xcb_glx_get_visual_configs_reply_t
* reply
= NULL
;
533 psc
= priv
->screenConfigs
+ screen
;
536 reply
= xcb_glx_get_visual_configs_reply(c
,
537 xcb_glx_get_visual_configs(c
,
543 props
= xcb_glx_get_visual_configs_property_list(reply
);
544 psc
->visuals
= createConfigsFromProperties(props
,
546 reply
->num_properties
,
552 return psc
->visuals
!= NULL
;
554 xGLXGetVisualConfigsReq
*req
;
555 xGLXGetVisualConfigsReply reply
;
559 psc
= priv
->screenConfigs
+ screen
;
561 GetReq(GLXGetVisualConfigs
, req
);
562 req
->reqType
= priv
->majorOpcode
;
563 req
->glxCode
= X_GLXGetVisualConfigs
;
564 req
->screen
= screen
;
566 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
569 psc
->visuals
= createConfigsFromProperties(dpy
,
576 return psc
->visuals
!= NULL
;
581 getFBConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
, int screen
)
583 __GLXscreenConfigs
*psc
;
585 xcb_connection_t
* c
= XGetXCBConnection(dpy
);
586 xcb_glx_get_fb_configs_reply_t
* reply_fb
= NULL
;
587 xcb_glx_get_fb_configs_sgix_reply_t
* reply_sgix
= NULL
;
588 uint32_t num_fb_configs
;
589 uint32_t num_properties
;
592 psc
= priv
->screenConfigs
+ screen
;
593 psc
->serverGLXexts
= __glXQueryServerString(dpy
, priv
->majorOpcode
,
594 screen
, GLX_EXTENSIONS
);
597 if (atof(priv
->serverGLXversion
) >= 1.3) {
598 reply_fb
= xcb_glx_get_fb_configs_reply(c
,
599 xcb_glx_get_fb_configs(c
,
605 num_fb_configs
= reply_fb
->num_fb_configs
;
606 num_properties
= reply_fb
->num_properties
* 2;
607 props
= xcb_glx_get_fb_configs_property_list(reply_fb
);
608 } else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
609 reply_sgix
= xcb_glx_get_fb_configs_sgix_reply(
611 xcb_glx_get_fb_configs_sgix(c
,
612 65540, /* X_GLXvop_GetFBConfigsSGIX */
620 num_fb_configs
= reply_sgix
->num_fb_configs
;
621 num_properties
= reply_sgix
->num_properties
* 2;
622 props
= xcb_glx_get_fb_configs_sgix_property_list(reply_sgix
);
626 psc
->configs
= createConfigsFromProperties(props
,
639 return psc
->configs
!= NULL
;
641 xGLXGetFBConfigsReq
*fb_req
;
642 xGLXGetFBConfigsSGIXReq
*sgi_req
;
643 xGLXVendorPrivateWithReplyReq
*vpreq
;
644 xGLXGetFBConfigsReply reply
;
646 psc
= priv
->screenConfigs
+ screen
;
647 psc
->serverGLXexts
= __glXQueryServerString(dpy
, priv
->majorOpcode
,
648 screen
, GLX_EXTENSIONS
);
653 if (atof(priv
->serverGLXversion
) >= 1.3) {
654 GetReq(GLXGetFBConfigs
, fb_req
);
655 fb_req
->reqType
= priv
->majorOpcode
;
656 fb_req
->glxCode
= X_GLXGetFBConfigs
;
657 fb_req
->screen
= screen
;
659 else if (strstr(psc
->serverGLXexts
, "GLX_SGIX_fbconfig") != NULL
) {
660 GetReqExtra(GLXVendorPrivateWithReply
,
661 sz_xGLXGetFBConfigsSGIXReq
+
662 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
663 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
664 sgi_req
->reqType
= priv
->majorOpcode
;
665 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
666 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
667 sgi_req
->screen
= screen
;
672 if (!_XReply(dpy
, (xReply
*) & reply
, 0, False
))
675 psc
->configs
= createConfigsFromProperties(dpy
,
677 reply
.numAttribs
* 2,
682 return psc
->configs
!= NULL
;
687 ** Allocate the memory for the per screen configs for each screen.
688 ** If that works then fetch the per screen configs data.
691 AllocAndFetchScreenConfigs(Display
* dpy
, __GLXdisplayPrivate
* priv
)
693 __GLXscreenConfigs
*psc
;
697 ** First allocate memory for the array of per screen configs.
699 screens
= ScreenCount(dpy
);
700 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
704 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
705 priv
->screenConfigs
= psc
;
707 priv
->serverGLXversion
= __glXQueryServerString(dpy
, priv
->majorOpcode
,
709 if (priv
->serverGLXversion
== NULL
) {
710 FreeScreenConfigs(priv
);
714 for (i
= 0; i
< screens
; i
++, psc
++) {
715 getVisualConfigs(dpy
, priv
, i
);
716 getFBConfigs(dpy
, priv
, i
);
718 #ifdef GLX_DIRECT_RENDERING
721 psc
->drawHash
= __glxHashCreate();
722 if (psc
->drawHash
== NULL
)
725 if (priv
->dri2Display
)
726 psc
->driScreen
= (*priv
->dri2Display
->createScreen
) (psc
, i
, priv
);
728 if (psc
->driScreen
== NULL
&& priv
->driDisplay
)
729 psc
->driScreen
= (*priv
->driDisplay
->createScreen
) (psc
, i
, priv
);
731 if (psc
->driScreen
== NULL
&& priv
->driswDisplay
)
732 psc
->driScreen
= (*priv
->driswDisplay
->createScreen
) (psc
, i
, priv
);
734 if (psc
->driScreen
== NULL
) {
735 __glxHashDestroy(psc
->drawHash
);
736 psc
->drawHash
= NULL
;
745 ** Initialize the client side extension code.
747 _X_HIDDEN __GLXdisplayPrivate
*
748 __glXInitialize(Display
* dpy
)
750 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
751 XExtData
**privList
, *private, *found
;
752 __GLXdisplayPrivate
*dpyPriv
;
753 XEDataObject dataObj
;
755 #ifdef GLX_DIRECT_RENDERING
756 Bool glx_direct
, glx_accel
;
759 #if defined(USE_XTHREADS)
761 static int firstCall
= 1;
763 /* initialize the GLX mutexes */
764 xmutex_init(&__glXmutex
);
771 /* The one and only long long lock */
774 if (!XextHasExtension(info
)) {
775 /* No GLX extension supported by this server. Oh well. */
777 XMissingExtension(dpy
, __glXExtensionName
);
781 /* See if a display private already exists. If so, return it */
782 dataObj
.display
= dpy
;
783 privList
= XEHeadOfExtensionList(dataObj
);
784 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
787 return (__GLXdisplayPrivate
*) found
->private_data
;
790 /* See if the versions are compatible */
791 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
792 /* The client and server do not agree on versions. Punt. */
798 ** Allocate memory for all the pieces needed for this buffer.
800 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
805 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
808 Xfree((char *) private);
813 ** Init the display private and then read in the screen config
814 ** structures from the server.
816 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
817 dpyPriv
->majorVersion
= major
;
818 dpyPriv
->minorVersion
= minor
;
821 dpyPriv
->serverGLXvendor
= 0x0;
822 dpyPriv
->serverGLXversion
= 0x0;
824 #ifdef GLX_DIRECT_RENDERING
825 glx_direct
= (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
);
826 glx_accel
= (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL
);
829 ** Initialize the direct rendering per display data and functions.
830 ** Note: This _must_ be done before calling any other DRI routines
831 ** (e.g., those called in AllocAndFetchScreenConfigs).
833 if (glx_direct
&& glx_accel
) {
834 dpyPriv
->dri2Display
= dri2CreateDisplay(dpy
);
835 dpyPriv
->driDisplay
= driCreateDisplay(dpy
);
838 dpyPriv
->driswDisplay
= driswCreateDisplay(dpy
);
841 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
843 Xfree((char *) dpyPriv
);
844 Xfree((char *) private);
849 ** Fill in the private structure. This is the actual structure that
850 ** hangs off of the Display structure. Our private structure is
851 ** referred to by this structure. Got that?
853 private->number
= info
->codes
->extension
;
855 private->free_private
= __glXFreeDisplayPrivate
;
856 private->private_data
= (char *) dpyPriv
;
857 XAddToExtensionList(privList
, private);
859 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
860 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
868 ** Setup for sending a GLX command on dpy. Make sure the extension is
869 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
872 __glXSetupForCommand(Display
* dpy
)
875 __GLXdisplayPrivate
*priv
;
877 /* If this thread has a current context, flush its rendering commands */
878 gc
= __glXGetCurrentContext();
879 if (gc
->currentDpy
) {
880 /* Flush rendering buffer of the current context, if any */
881 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
883 if (gc
->currentDpy
== dpy
) {
884 /* Use opcode from gc because its right */
886 return gc
->majorOpcode
;
890 ** Have to get info about argument dpy because it might be to
891 ** a different server
896 /* Forced to lookup extension via the slow initialize route */
897 priv
= __glXInitialize(dpy
);
901 return priv
->majorOpcode
;
905 * Flush the drawing command transport buffer.
907 * \param ctx Context whose transport buffer is to be flushed.
908 * \param pc Pointer to first unused buffer location.
911 * Modify this function to use \c ctx->pc instead of the explicit
915 __glXFlushRenderBuffer(__GLXcontext
* ctx
, GLubyte
* pc
)
917 Display
*const dpy
= ctx
->currentDpy
;
919 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
923 const GLint size
= pc
- ctx
->buf
;
925 if ((dpy
!= NULL
) && (size
> 0)) {
927 xcb_glx_render(c
, ctx
->currentContextTag
, size
,
928 (const uint8_t *) ctx
->buf
);
930 /* Send the entire buffer as an X request */
932 GetReq(GLXRender
, req
);
933 req
->reqType
= ctx
->majorOpcode
;
934 req
->glxCode
= X_GLXRender
;
935 req
->contextTag
= ctx
->currentContextTag
;
936 req
->length
+= (size
+ 3) >> 2;
937 _XSend(dpy
, (char *) ctx
->buf
, size
);
943 /* Reset pointer and return it */
950 * Send a portion of a GLXRenderLarge command to the server. The advantage of
951 * this function over \c __glXSendLargeCommand is that callers can use the
952 * data buffer in the GLX context and may be able to avoid allocating an
953 * extra buffer. The disadvantage is the clients will have to do more
954 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
956 * \sa __glXSendLargeCommand
958 * \param gc GLX context
959 * \param requestNumber Which part of the whole command is this? The first
961 * \param totalRequests How many requests will there be?
962 * \param data Command data.
963 * \param dataLen Size, in bytes, of the command data.
966 __glXSendLargeChunk(__GLXcontext
* gc
, GLint requestNumber
,
967 GLint totalRequests
, const GLvoid
* data
, GLint dataLen
)
969 Display
*dpy
= gc
->currentDpy
;
971 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
972 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
,
973 totalRequests
, dataLen
, data
);
975 xGLXRenderLargeReq
*req
;
977 if (requestNumber
== 1) {
981 GetReq(GLXRenderLarge
, req
);
982 req
->reqType
= gc
->majorOpcode
;
983 req
->glxCode
= X_GLXRenderLarge
;
984 req
->contextTag
= gc
->currentContextTag
;
985 req
->length
+= (dataLen
+ 3) >> 2;
986 req
->requestNumber
= requestNumber
;
987 req
->requestTotal
= totalRequests
;
988 req
->dataBytes
= dataLen
;
989 Data(dpy
, data
, dataLen
);
991 if (requestNumber
== totalRequests
) {
1000 * Send a command that is too large for the GLXRender protocol request.
1002 * Send a large command, one that is too large for some reason to
1003 * send using the GLXRender protocol request. One reason to send
1004 * a large command is to avoid copying the data.
1006 * \param ctx GLX context
1007 * \param header Header data.
1008 * \param headerLen Size, in bytes, of the header data. It is assumed that
1009 * the header data will always be small enough to fit in
1010 * a single X protocol packet.
1011 * \param data Command data.
1012 * \param dataLen Size, in bytes, of the command data.
1015 __glXSendLargeCommand(__GLXcontext
* ctx
,
1016 const GLvoid
* header
, GLint headerLen
,
1017 const GLvoid
* data
, GLint dataLen
)
1020 GLint totalRequests
, requestNumber
;
1023 ** Calculate the maximum amount of data can be stuffed into a single
1024 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1025 ** packet size minus sz_xGLXRenderReq.
1027 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1028 totalRequests
= 1 + (dataLen
/ maxSize
);
1029 if (dataLen
% maxSize
)
1033 ** Send all of the command, except the large array, as one request.
1035 assert(headerLen
<= maxSize
);
1036 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1039 ** Send enough requests until the whole array is sent.
1041 for (requestNumber
= 2; requestNumber
<= (totalRequests
- 1);
1043 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1044 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1046 assert(dataLen
> 0);
1049 assert(dataLen
<= maxSize
);
1050 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1053 /************************************************************************/
1057 __glXDumpDrawBuffer(__GLXcontext
* ctx
)
1059 GLubyte
*p
= ctx
->buf
;
1060 GLubyte
*end
= ctx
->pc
;
1061 GLushort opcode
, length
;
1065 opcode
= *((GLushort
*) p
);
1066 length
= *((GLushort
*) (p
+ 2));
1067 printf("%2x: %5d: ", opcode
, length
);
1070 while (length
> 0) {
1071 printf("%08x ", *((unsigned *) p
));
1080 #ifdef USE_SPARC_ASM
1082 * This is where our dispatch table's bounds are.
1083 * And the static mesa_init is taken directly from
1084 * Mesa's 'sparc.c' initializer.
1086 * We need something like this here, because this version
1087 * of openGL/glx never initializes a Mesa context, and so
1088 * the address of the dispatch table pointer never gets stuffed
1089 * into the dispatch jump table otherwise.
1091 * It matters only on SPARC, and only if you are using assembler
1092 * code instead of C-code indirect dispatch.
1096 extern unsigned int _mesa_sparc_glapi_begin
;
1097 extern unsigned int _mesa_sparc_glapi_end
;
1098 extern void __glapi_sparc_icache_flush(unsigned int *);
1101 _glx_mesa_init_sparc_glapi_relocs(void)
1103 unsigned int *insn_ptr
, *end_ptr
;
1104 unsigned long disp_addr
;
1106 insn_ptr
= &_mesa_sparc_glapi_begin
;
1107 end_ptr
= &_mesa_sparc_glapi_end
;
1108 disp_addr
= (unsigned long) &_glapi_Dispatch
;
1111 * Verbatim from Mesa sparc.c. It's needed because there doesn't
1112 * seem to be a better way to do this:
1114 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1116 * This code is patching in the ADDRESS of the pointer to the
1117 * dispatch table. Hence, it must be called exactly once, because
1118 * that address is not going to change.
1120 * What it points to can change, but Mesa (and hence, we) assume
1121 * that there is only one pointer.
1124 while (insn_ptr
< end_ptr
) {
1125 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1127 This code patches for 64-bit addresses. This had better
1128 not happen for Sparc/Linux, no matter what architecture we
1129 are building for. So, don't do this.
1131 The 'defined(__linux_64__)' is used here as a placeholder for
1132 when we do do 64-bit usermode on sparc linux.
1134 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1135 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1136 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1137 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1138 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1139 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1142 insn_ptr
[0] |= (disp_addr
>> 10);
1143 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1144 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1149 #endif /* sparc ASM in use */