1 /* $XFree86: xc/lib/GL/glx/glxext.c,v 1.22 2003/12/08 17:35:28 dawes Exp $ */
4 ** License Applicability. Except to the extent portions of this file are
5 ** made subject to an alternative license as permitted in the SGI Free
6 ** Software License B, Version 1.1 (the "License"), the contents of this
7 ** file are subject only to the provisions of the License. You may not use
8 ** this file except in compliance with the License. You may obtain a copy
9 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
10 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
12 ** http://oss.sgi.com/projects/FreeB
14 ** Note that, as provided in the License, the Software is distributed on an
15 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
16 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
17 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
18 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
20 ** Original Code. The Original Code is: OpenGL Sample Implementation,
21 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
22 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
23 ** Copyright in any portions created by third parties is as indicated
24 ** elsewhere herein. All Rights Reserved.
26 ** Additional Notice Provisions: The application programming interfaces
27 ** established by SGI in conjunction with the Original Code are The
28 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
29 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
30 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
31 ** Window System(R) (Version 1.3), released October 19, 1998. This software
32 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
33 ** published by SGI, but has not been independently verified as being
34 ** compliant with the OpenGL(R) version 1.2.1 Specification.
40 * GLX protocol interface boot-strap code.
42 * Direct rendering support added by Precision Insight, Inc.
44 * \author Kevin E. Martin <kevin@precisioninsight.com>
47 #include "glxclient.h"
49 #include <X11/extensions/Xext.h>
50 #include <X11/extensions/extutil.h>
52 #include "indirect_init.h"
54 #include "glxextensions.h"
55 #include "glcontextmodes.h"
58 #ifdef GLX_DIRECT_RENDERING
68 #include <X11/XCB/xcb.h>
69 #include <X11/XCB/glx.h>
75 void __glXDumpDrawBuffer(__GLXcontext
*ctx
);
80 * This is where our dispatch table's bounds are.
81 * And the static mesa_init is taken directly from
82 * Mesa's 'sparc.c' initializer.
84 * We need something like this here, because this version
85 * of openGL/glx never initializes a Mesa context, and so
86 * the address of the dispatch table pointer never gets stuffed
87 * into the dispatch jump table otherwise.
89 * It matters only on SPARC, and only if you are using assembler
90 * code instead of C-code indirect dispatch.
94 extern unsigned int _mesa_sparc_glapi_begin
;
95 extern unsigned int _mesa_sparc_glapi_end
;
96 extern void __glapi_sparc_icache_flush(unsigned int *);
97 static void _glx_mesa_init_sparc_glapi_relocs(void);
98 static int _mesa_sparc_needs_init
= 1;
99 #define INIT_MESA_SPARC { \
100 if(_mesa_sparc_needs_init) { \
101 _glx_mesa_init_sparc_glapi_relocs(); \
102 _mesa_sparc_needs_init = 0; \
106 #define INIT_MESA_SPARC
109 #ifdef GLX_DIRECT_RENDERING
110 static __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
);
111 #endif /* GLX_DIRECT_RENDERING */
113 static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
114 GLXDrawable read
, GLXContext gc
);
117 ** We setup some dummy structures here so that the API can be used
118 ** even if no context is current.
121 static GLubyte dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
];
124 ** Dummy context used by small commands when there is no current context.
126 ** gl and glx entry points are designed to operate as nop's when using
127 ** the dummy context structure.
129 static __GLXcontext dummyContext
= {
133 &dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
],
139 ** All indirect rendering contexts will share the same indirect dispatch table.
141 static __GLapi
*IndirectAPI
= NULL
;
145 * Current context management and locking
148 #if defined( USE_XTHREADS )
151 static GLboolean TSDinitialized
= GL_FALSE
;
152 static xthread_key_t ContextTSD
;
154 __GLXcontext
*__glXGetCurrentContext(void)
156 if (!TSDinitialized
) {
157 xthread_key_create(&ContextTSD
, NULL
);
158 TSDinitialized
= GL_TRUE
;
159 return &dummyContext
;
163 xthread_get_specific(ContextTSD
, &p
);
165 return &dummyContext
;
167 return (__GLXcontext
*) p
;
171 void __glXSetCurrentContext(__GLXcontext
*c
)
173 if (!TSDinitialized
) {
174 xthread_key_create(&ContextTSD
, NULL
);
175 TSDinitialized
= GL_TRUE
;
177 xthread_set_specific(ContextTSD
, c
);
181 /* Used by the __glXLock() and __glXUnlock() macros */
182 xmutex_rec __glXmutex
;
184 #elif defined( PTHREADS )
186 pthread_mutex_t __glXmutex
= PTHREAD_MUTEX_INITIALIZER
;
188 # if defined( GLX_USE_TLS )
191 * Per-thread GLX context pointer.
193 * \c __glXSetCurrentContext is written is such a way that this pointer can
194 * \b never be \c NULL. This is important! Because of this
195 * \c __glXGetCurrentContext can be implemented as trivial macro.
197 __thread
void * __glX_tls_Context
__attribute__((tls_model("initial-exec")))
200 void __glXSetCurrentContext( __GLXcontext
* c
)
202 __glX_tls_Context
= (c
!= NULL
) ? c
: &dummyContext
;
207 static pthread_once_t once_control
= PTHREAD_ONCE_INIT
;
210 * Per-thread data key.
212 * Once \c init_thread_data has been called, the per-thread data key will
213 * take a value of \c NULL. As each new thread is created the default
214 * value, in that thread, will be \c NULL.
216 static pthread_key_t ContextTSD
;
219 * Initialize the per-thread data key.
221 * This function is called \b exactly once per-process (not per-thread!) to
222 * initialize the per-thread data key. This is ideally done using the
223 * \c pthread_once mechanism.
225 static void init_thread_data( void )
227 if ( pthread_key_create( & ContextTSD
, NULL
) != 0 ) {
228 perror( "pthread_key_create" );
233 void __glXSetCurrentContext( __GLXcontext
* c
)
235 pthread_once( & once_control
, init_thread_data
);
236 pthread_setspecific( ContextTSD
, c
);
239 __GLXcontext
* __glXGetCurrentContext( void )
243 pthread_once( & once_control
, init_thread_data
);
245 v
= pthread_getspecific( ContextTSD
);
246 return (v
== NULL
) ? & dummyContext
: (__GLXcontext
*) v
;
249 # endif /* defined( GLX_USE_TLS ) */
251 #elif defined( THREADS )
253 #error Unknown threading method specified.
257 /* not thread safe */
258 __GLXcontext
*__glXcurrentContext
= &dummyContext
;
264 ** You can set this cell to 1 to force the gl drawing stuff to be
265 ** one command per packet
270 ** forward prototype declarations
272 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
);
275 /************************************************************************/
277 /* Extension required boiler plate */
279 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
280 XExtensionInfo
*__glXExtensionInfo
= NULL
;
282 static /* const */ char *error_list
[] = {
284 "GLXBadContextState",
288 "GLXBadCurrentWindow",
289 "GLXBadRenderRequest",
290 "GLXBadLargeRequest",
291 "GLXUnsupportedPrivateRequest",
294 "GLXBadCurrentDrawable",
298 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
)
302 gc
= __glXGetCurrentContext();
303 if (dpy
== gc
->currentDpy
) {
304 __glXSetCurrentContext(&dummyContext
);
305 #ifdef GLX_DIRECT_RENDERING
306 _glapi_set_dispatch(NULL
); /* no-op functions */
308 __glXFreeContext(gc
);
311 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
315 static XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
316 __GLX_NUMBER_ERRORS
, error_list
)
318 static /* const */ XExtensionHooks __glXExtensionHooks
= {
319 NULL
, /* create_gc */
323 NULL
, /* create_font */
324 NULL
, /* free_font */
325 __glXCloseDisplay
, /* close_display */
326 NULL
, /* wire_to_event */
327 NULL
, /* event_to_wire */
329 __glXErrorString
, /* error_string */
333 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
334 __glXExtensionName
, &__glXExtensionHooks
,
335 __GLX_NUMBER_EVENTS
, NULL
)
337 /************************************************************************/
340 ** Free the per screen configs data as well as the array of
341 ** __glXScreenConfigs.
343 static void FreeScreenConfigs(__GLXdisplayPrivate
*priv
)
345 __GLXscreenConfigs
*psc
;
348 /* Free screen configuration information */
349 psc
= priv
->screenConfigs
;
350 screens
= ScreenCount(priv
->dpy
);
351 for (i
= 0; i
< screens
; i
++, psc
++) {
353 _gl_context_modes_destroy( psc
->configs
);
354 if(psc
->effectiveGLXexts
)
355 Xfree(psc
->effectiveGLXexts
);
357 psc
->configs
= NULL
; /* NOTE: just for paranoia */
360 #ifdef GLX_DIRECT_RENDERING
361 /* Free the direct rendering per screen data */
362 if (psc
->driScreen
.private)
363 (*psc
->driScreen
.destroyScreen
)(priv
->dpy
, i
,
364 psc
->driScreen
.private);
365 psc
->driScreen
.private = NULL
;
368 XFree((char*) priv
->screenConfigs
);
372 ** Release the private memory referred to in a display private
373 ** structure. The caller will free the extension structure.
375 static int __glXFreeDisplayPrivate(XExtData
*extension
)
377 __GLXdisplayPrivate
*priv
;
379 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
380 FreeScreenConfigs(priv
);
381 if(priv
->serverGLXvendor
) {
382 Xfree((char*)priv
->serverGLXvendor
);
383 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
385 if(priv
->serverGLXversion
) {
386 Xfree((char*)priv
->serverGLXversion
);
387 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
390 #if 0 /* GLX_DIRECT_RENDERING */
391 /* Free the direct rendering per display data */
392 if (priv
->driDisplay
.private)
393 (*priv
->driDisplay
.destroyDisplay
)(priv
->dpy
,
394 priv
->driDisplay
.private);
395 priv
->driDisplay
.private = NULL
;
402 /************************************************************************/
405 ** Query the version of the GLX extension. This procedure works even if
406 ** the client extension is not completely set up.
408 static Bool
QueryVersion(Display
*dpy
, int opcode
, int *major
, int *minor
)
410 xGLXQueryVersionReq
*req
;
411 xGLXQueryVersionReply reply
;
413 /* Send the glXQueryVersion request */
415 GetReq(GLXQueryVersion
,req
);
416 req
->reqType
= opcode
;
417 req
->glxCode
= X_GLXQueryVersion
;
418 req
->majorVersion
= GLX_MAJOR_VERSION
;
419 req
->minorVersion
= GLX_MINOR_VERSION
;
420 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
424 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
426 ** The server does not support the same major release as this
431 *major
= reply
.majorVersion
;
432 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
438 __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
, int count
,
439 const INT32
*bp
, Bool tagged_only
,
440 Bool fbconfig_style_tags
)
445 /* Copy in the first set of properties */
446 config
->visualID
= *bp
++;
448 config
->visualType
= _gl_convert_from_x_visual_type( *bp
++ );
450 config
->rgbMode
= *bp
++;
452 config
->redBits
= *bp
++;
453 config
->greenBits
= *bp
++;
454 config
->blueBits
= *bp
++;
455 config
->alphaBits
= *bp
++;
456 config
->accumRedBits
= *bp
++;
457 config
->accumGreenBits
= *bp
++;
458 config
->accumBlueBits
= *bp
++;
459 config
->accumAlphaBits
= *bp
++;
461 config
->doubleBufferMode
= *bp
++;
462 config
->stereoMode
= *bp
++;
464 config
->rgbBits
= *bp
++;
465 config
->depthBits
= *bp
++;
466 config
->stencilBits
= *bp
++;
467 config
->numAuxBuffers
= *bp
++;
468 config
->level
= *bp
++;
470 count
-= __GLX_MIN_CONFIG_PROPS
;
474 ** Additional properties may be in a list at the end
475 ** of the reply. They are in pairs of property type
476 ** and property value.
479 #define FETCH_OR_SET(tag) \
480 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
482 for (i
= 0; i
< count
; i
+= 2 ) {
485 FETCH_OR_SET( rgbMode
);
487 case GLX_BUFFER_SIZE
:
488 config
->rgbBits
= *bp
++;
491 config
->level
= *bp
++;
493 case GLX_DOUBLEBUFFER
:
494 FETCH_OR_SET( doubleBufferMode
);
497 FETCH_OR_SET( stereoMode
);
499 case GLX_AUX_BUFFERS
:
500 config
->numAuxBuffers
= *bp
++;
503 config
->redBits
= *bp
++;
506 config
->greenBits
= *bp
++;
509 config
->blueBits
= *bp
++;
512 config
->alphaBits
= *bp
++;
515 config
->depthBits
= *bp
++;
517 case GLX_STENCIL_SIZE
:
518 config
->stencilBits
= *bp
++;
520 case GLX_ACCUM_RED_SIZE
:
521 config
->accumRedBits
= *bp
++;
523 case GLX_ACCUM_GREEN_SIZE
:
524 config
->accumGreenBits
= *bp
++;
526 case GLX_ACCUM_BLUE_SIZE
:
527 config
->accumBlueBits
= *bp
++;
529 case GLX_ACCUM_ALPHA_SIZE
:
530 config
->accumAlphaBits
= *bp
++;
532 case GLX_VISUAL_CAVEAT_EXT
:
533 config
->visualRating
= *bp
++;
535 case GLX_X_VISUAL_TYPE
:
536 config
->visualType
= *bp
++;
538 case GLX_TRANSPARENT_TYPE
:
539 config
->transparentPixel
= *bp
++;
541 case GLX_TRANSPARENT_INDEX_VALUE
:
542 config
->transparentIndex
= *bp
++;
544 case GLX_TRANSPARENT_RED_VALUE
:
545 config
->transparentRed
= *bp
++;
547 case GLX_TRANSPARENT_GREEN_VALUE
:
548 config
->transparentGreen
= *bp
++;
550 case GLX_TRANSPARENT_BLUE_VALUE
:
551 config
->transparentBlue
= *bp
++;
553 case GLX_TRANSPARENT_ALPHA_VALUE
:
554 config
->transparentAlpha
= *bp
++;
557 config
->visualID
= *bp
++;
559 case GLX_DRAWABLE_TYPE
:
560 config
->drawableType
= *bp
++;
562 case GLX_RENDER_TYPE
:
563 config
->renderType
= *bp
++;
565 case GLX_X_RENDERABLE
:
566 config
->xRenderable
= *bp
++;
568 case GLX_FBCONFIG_ID
:
569 config
->fbconfigID
= *bp
++;
571 case GLX_MAX_PBUFFER_WIDTH
:
572 config
->maxPbufferWidth
= *bp
++;
574 case GLX_MAX_PBUFFER_HEIGHT
:
575 config
->maxPbufferHeight
= *bp
++;
577 case GLX_MAX_PBUFFER_PIXELS
:
578 config
->maxPbufferPixels
= *bp
++;
580 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
581 config
->optimalPbufferWidth
= *bp
++;
583 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
584 config
->optimalPbufferHeight
= *bp
++;
586 case GLX_VISUAL_SELECT_GROUP_SGIX
:
587 config
->visualSelectGroup
= *bp
++;
589 case GLX_SWAP_METHOD_OML
:
590 config
->swapMethod
= *bp
++;
592 case GLX_SAMPLE_BUFFERS_SGIS
:
593 config
->sampleBuffers
= *bp
++;
595 case GLX_SAMPLES_SGIS
:
596 config
->samples
= *bp
++;
598 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
599 config
->bindToTextureRgb
= *bp
++;
601 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
602 config
->bindToTextureRgba
= *bp
++;
604 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
605 config
->bindToMipmapTexture
= *bp
++;
607 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
608 config
->bindToTextureTargets
= *bp
++;
610 case GLX_Y_INVERTED_EXT
:
611 config
->yInverted
= *bp
++;
621 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
623 config
->haveAccumBuffer
= ((config
->accumRedBits
+
624 config
->accumGreenBits
+
625 config
->accumBlueBits
+
626 config
->accumAlphaBits
) > 0);
627 config
->haveDepthBuffer
= (config
->depthBits
> 0);
628 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
632 #ifdef GLX_DIRECT_RENDERING
634 filter_modes( __GLcontextModes
** server_modes
,
635 const __GLcontextModes
* driver_modes
)
637 __GLcontextModes
* m
;
638 __GLcontextModes
** prev_next
;
639 const __GLcontextModes
* check
;
640 unsigned modes_count
= 0;
642 if ( driver_modes
== NULL
) {
643 fprintf(stderr
, "libGL warning: 3D driver returned no fbconfigs.\n");
647 /* For each mode in server_modes, check to see if a matching mode exists
648 * in driver_modes. If not, then the mode is not available.
651 prev_next
= server_modes
;
652 for ( m
= *prev_next
; m
!= NULL
; m
= *prev_next
) {
653 GLboolean do_delete
= GL_TRUE
;
655 for ( check
= driver_modes
; check
!= NULL
; check
= check
->next
) {
656 if ( _gl_context_modes_are_same( m
, check
) ) {
657 do_delete
= GL_FALSE
;
662 /* The 3D has to support all the modes that match the GLX visuals
663 * sent from the X server.
665 if ( do_delete
&& (m
->visualID
!= 0) ) {
666 do_delete
= GL_FALSE
;
668 fprintf(stderr
, "libGL warning: 3D driver claims to not support "
669 "visual 0x%02x\n", m
->visualID
);
673 *prev_next
= m
->next
;
676 _gl_context_modes_destroy( m
);
680 prev_next
= & m
->next
;
689 * Implement \c __DRIinterfaceMethods::getProcAddress.
691 static __DRIfuncPtr
get_proc_address( const char * proc_name
)
693 if (strcmp( proc_name
, "glxEnableExtension" ) == 0) {
694 return (__DRIfuncPtr
) __glXScrEnableExtension
;
702 * Table of functions exported by the loader to the driver.
704 static const __DRIinterfaceMethods interface_methods
= {
707 _gl_context_modes_create
,
708 _gl_context_modes_destroy
,
713 XF86DRICreateContextWithConfig
,
714 XF86DRIDestroyContext
,
716 XF86DRICreateDrawable
,
717 XF86DRIDestroyDrawable
,
718 XF86DRIGetDrawableInfo
,
726 * Perform the required libGL-side initialization and call the client-side
727 * driver's \c __driCreateNewScreen function.
729 * \param dpy Display pointer.
730 * \param scrn Screen number on the display.
731 * \param psc DRI screen information.
732 * \param driDpy DRI display information.
733 * \param createNewScreen Pointer to the client-side driver's
734 * \c __driCreateNewScreen function.
735 * \returns A pointer to the \c __DRIscreenPrivate structure returned by
736 * the client-side driver on success, or \c NULL on failure.
738 * \todo This function needs to be modified to remove context-modes from the
739 * list stored in the \c __GLXscreenConfigsRec to match the list
740 * returned by the client-side driver.
743 CallCreateNewScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
744 __DRIdisplay
* driDpy
,
745 PFNCREATENEWSCREENFUNC createNewScreen
)
747 __DRIscreenPrivate
*psp
= NULL
;
748 #ifndef GLX_USE_APPLEGL
750 drmAddress pSAREA
= MAP_FAILED
;
752 __DRIversion ddx_version
;
753 __DRIversion dri_version
;
754 __DRIversion drm_version
;
755 __DRIframebuffer framebuffer
;
758 const char * err_msg
;
759 const char * err_extra
;
760 int api_ver
= __glXGetInternalVersion();
763 dri_version
.major
= driDpy
->private->driMajor
;
764 dri_version
.minor
= driDpy
->private->driMinor
;
765 dri_version
.patch
= driDpy
->private->driPatch
;
768 err_msg
= "XF86DRIOpenConnection";
771 framebuffer
.base
= MAP_FAILED
;
772 framebuffer
.dev_priv
= NULL
;
774 if (XF86DRIOpenConnection(dpy
, scrn
, &hSAREA
, &BusID
)) {
775 fd
= drmOpen(NULL
,BusID
);
776 Xfree(BusID
); /* No longer needed */
778 err_msg
= "open DRM";
779 err_extra
= strerror( -fd
);
784 err_msg
= "drmGetMagic";
787 if (!drmGetMagic(fd
, &magic
)) {
788 drmVersionPtr version
= drmGetVersion(fd
);
790 drm_version
.major
= version
->version_major
;
791 drm_version
.minor
= version
->version_minor
;
792 drm_version
.patch
= version
->version_patchlevel
;
793 drmFreeVersion(version
);
796 drm_version
.major
= -1;
797 drm_version
.minor
= -1;
798 drm_version
.patch
= -1;
801 err_msg
= "XF86DRIAuthConnection";
802 if (XF86DRIAuthConnection(dpy
, scrn
, magic
)) {
806 * Get device name (like "tdfx") and the ddx version
807 * numbers. We'll check the version in each DRI driver's
808 * "createNewScreen" function.
810 err_msg
= "XF86DRIGetClientDriverName";
811 if (XF86DRIGetClientDriverName(dpy
, scrn
,
819 /* No longer needed. */
824 * Get device-specific info. pDevPriv will point to a struct
825 * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h)
826 * that has information about the screen size, depth, pitch,
827 * ancilliary buffers, DRM mmap handles, etc.
829 err_msg
= "XF86DRIGetDeviceInfo";
830 if (XF86DRIGetDeviceInfo(dpy
, scrn
,
835 &framebuffer
.dev_priv_size
,
836 &framebuffer
.dev_priv
)) {
837 framebuffer
.width
= DisplayWidth(dpy
, scrn
);
838 framebuffer
.height
= DisplayHeight(dpy
, scrn
);
841 * Map the framebuffer region.
843 status
= drmMap(fd
, hFB
, framebuffer
.size
,
844 (drmAddressPtr
)&framebuffer
.base
);
846 err_msg
= "drmMap of framebuffer";
847 err_extra
= strerror( -status
);
851 * Map the SAREA region. Further mmap regions
852 * may be setup in each DRI driver's
853 * "createNewScreen" function.
855 status
= drmMap(fd
, hSAREA
, SAREA_MAX
,
858 err_msg
= "drmMap of sarea";
859 err_extra
= strerror( -status
);
862 __GLcontextModes
* driver_modes
= NULL
;
863 __GLXscreenConfigs
*configs
= psc
->screenConfigs
;
865 err_msg
= "InitDriver";
867 psp
= (*createNewScreen
)(dpy
, scrn
,
880 filter_modes( & configs
->configs
,
882 _gl_context_modes_destroy( driver_modes
);
893 if ( pSAREA
!= MAP_FAILED
) {
894 (void)drmUnmap(pSAREA
, SAREA_MAX
);
897 if ( framebuffer
.base
!= MAP_FAILED
) {
898 (void)drmUnmap((drmAddress
)framebuffer
.base
, framebuffer
.size
);
901 if ( framebuffer
.dev_priv
!= NULL
) {
902 Xfree(framebuffer
.dev_priv
);
909 (void)XF86DRICloseConnection(dpy
, scrn
);
911 if ( err_extra
!= NULL
) {
912 fprintf(stderr
, "libGL error: %s failed (%s)\n", err_msg
,
916 fprintf(stderr
, "libGL error: %s failed\n", err_msg
);
919 fprintf(stderr
, "libGL error: reverting to (slow) indirect rendering\n");
921 #endif /* !GLX_USE_APPLEGL */
925 #endif /* GLX_DIRECT_RENDERING */
929 ** Allocate the memory for the per screen configs for each screen.
930 ** If that works then fetch the per screen configs data.
932 static Bool
AllocAndFetchScreenConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
)
934 xGLXGetVisualConfigsReq
*req
;
935 xGLXGetFBConfigsReq
*fb_req
;
936 xGLXVendorPrivateWithReplyReq
*vpreq
;
937 xGLXGetFBConfigsSGIXReq
*sgi_req
;
938 xGLXGetVisualConfigsReply reply
;
939 __GLXscreenConfigs
*psc
;
940 __GLcontextModes
*config
;
941 GLint i
, j
, nprops
, screens
;
942 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
943 unsigned supported_request
= 0;
947 ** First allocate memory for the array of per screen configs.
949 screens
= ScreenCount(dpy
);
950 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
954 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
955 priv
->screenConfigs
= psc
;
957 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
958 X_GLXQueryServerString
,
960 if ( priv
->serverGLXversion
== NULL
) {
961 FreeScreenConfigs(priv
);
965 if ( atof( priv
->serverGLXversion
) >= 1.3 ) {
966 supported_request
= 1;
970 ** Now fetch each screens configs structures. If a screen supports
971 ** GL (by returning a numVisuals > 0) then allocate memory for our
972 ** config structure and then fill it in.
974 for (i
= 0; i
< screens
; i
++, psc
++) {
975 if ( supported_request
!= 1 ) {
976 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
977 X_GLXQueryServerString
,
979 if ( strstr( psc
->serverGLXexts
, "GLX_SGIX_fbconfig" ) != NULL
) {
980 supported_request
= 2;
983 supported_request
= 3;
989 switch( supported_request
) {
991 GetReq(GLXGetFBConfigs
,fb_req
);
992 fb_req
->reqType
= priv
->majorOpcode
;
993 fb_req
->glxCode
= X_GLXGetFBConfigs
;
998 GetReqExtra(GLXVendorPrivateWithReply
,
999 sz_xGLXGetFBConfigsSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1000 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
1001 sgi_req
->reqType
= priv
->majorOpcode
;
1002 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
1003 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
1004 sgi_req
->screen
= i
;
1008 GetReq(GLXGetVisualConfigs
,req
);
1009 req
->reqType
= priv
->majorOpcode
;
1010 req
->glxCode
= X_GLXGetVisualConfigs
;
1015 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
)) {
1016 /* Something is busted. Punt. */
1018 FreeScreenConfigs(priv
);
1023 if (!reply
.numVisuals
) {
1024 /* This screen does not support GL rendering */
1029 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for
1032 /* Check number of properties */
1033 nprops
= reply
.numProps
;
1034 if ((nprops
< __GLX_MIN_CONFIG_PROPS
) ||
1035 (nprops
> __GLX_MAX_CONFIG_PROPS
)) {
1036 /* Huh? Not in protocol defined limits. Punt */
1039 FreeScreenConfigs(priv
);
1043 /* Allocate memory for our config structure */
1044 psc
->configs
= _gl_context_modes_create(reply
.numVisuals
,
1045 sizeof(__GLcontextModes
));
1046 if (!psc
->configs
) {
1049 FreeScreenConfigs(priv
);
1053 /* Allocate memory for the properties, if needed */
1054 if ( supported_request
!= 3 ) {
1058 prop_size
= nprops
* __GLX_SIZE_INT32
;
1060 if (prop_size
<= sizeof(buf
)) {
1063 props
= (INT32
*) Xmalloc(prop_size
);
1066 /* Read each config structure and convert it into our format */
1067 config
= psc
->configs
;
1068 for (j
= 0; j
< reply
.numVisuals
; j
++) {
1069 assert( config
!= NULL
);
1070 _XRead(dpy
, (char *)props
, prop_size
);
1072 if ( supported_request
!= 3 ) {
1073 config
->rgbMode
= GL_TRUE
;
1074 config
->drawableType
= GLX_WINDOW_BIT
;
1077 config
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
1080 __glXInitializeVisualConfigFromTags( config
, nprops
, props
,
1081 (supported_request
!= 3),
1083 if ( config
->fbconfigID
== GLX_DONT_CARE
) {
1084 config
->fbconfigID
= config
->visualID
;
1087 config
= config
->next
;
1090 Xfree((char *)props
);
1094 #ifdef GLX_DIRECT_RENDERING
1095 /* Initialize per screen dynamic client GLX extensions */
1096 psc
->ext_list_first_time
= GL_TRUE
;
1097 /* Initialize the direct rendering per screen data and functions */
1098 if (priv
->driDisplay
.private != NULL
) {
1099 /* FIXME: Should it be some sort of an error if createNewScreen[i]
1102 if (priv
->driDisplay
.createNewScreen
&&
1103 priv
->driDisplay
.createNewScreen
[i
]) {
1105 psc
->driScreen
.screenConfigs
= (void *)psc
;
1106 psc
->driScreen
.private =
1107 CallCreateNewScreen(dpy
, i
, & psc
->driScreen
,
1109 priv
->driDisplay
.createNewScreen
[i
] );
1119 ** Initialize the client side extension code.
1121 __GLXdisplayPrivate
*__glXInitialize(Display
* dpy
)
1123 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1124 XExtData
**privList
, *private, *found
;
1125 __GLXdisplayPrivate
*dpyPriv
;
1126 XEDataObject dataObj
;
1129 #if defined(USE_XTHREADS)
1131 static int firstCall
= 1;
1133 /* initialize the GLX mutexes */
1134 xmutex_init(&__glXmutex
);
1141 /* The one and only long long lock */
1144 if (!XextHasExtension(info
)) {
1145 /* No GLX extension supported by this server. Oh well. */
1147 XMissingExtension(dpy
, __glXExtensionName
);
1151 /* See if a display private already exists. If so, return it */
1152 dataObj
.display
= dpy
;
1153 privList
= XEHeadOfExtensionList(dataObj
);
1154 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1157 return (__GLXdisplayPrivate
*) found
->private_data
;
1160 /* See if the versions are compatible */
1161 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
1162 /* The client and server do not agree on versions. Punt. */
1168 ** Allocate memory for all the pieces needed for this buffer.
1170 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
1175 dpyPriv
= (__GLXdisplayPrivate
*) Xmalloc(sizeof(__GLXdisplayPrivate
));
1178 Xfree((char*) private);
1183 ** Init the display private and then read in the screen config
1184 ** structures from the server.
1186 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
1187 dpyPriv
->majorVersion
= major
;
1188 dpyPriv
->minorVersion
= minor
;
1191 dpyPriv
->serverGLXvendor
= 0x0;
1192 dpyPriv
->serverGLXversion
= 0x0;
1194 #ifdef GLX_DIRECT_RENDERING
1196 ** Initialize the direct rendering per display data and functions.
1197 ** Note: This _must_ be done before calling any other DRI routines
1198 ** (e.g., those called in AllocAndFetchScreenConfigs).
1200 if (getenv("LIBGL_ALWAYS_INDIRECT")) {
1201 /* Assinging zero here assures we'll never go direct */
1202 dpyPriv
->driDisplay
.private = 0;
1203 dpyPriv
->driDisplay
.destroyDisplay
= 0;
1206 dpyPriv
->driDisplay
.private =
1207 driCreateDisplay(dpy
, &dpyPriv
->driDisplay
);
1211 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
1213 Xfree((char*) dpyPriv
);
1214 Xfree((char*) private);
1219 ** Fill in the private structure. This is the actual structure that
1220 ** hangs off of the Display structure. Our private structure is
1221 ** referred to by this structure. Got that?
1223 private->number
= info
->codes
->extension
;
1225 private->free_private
= __glXFreeDisplayPrivate
;
1226 private->private_data
= (char *) dpyPriv
;
1227 XAddToExtensionList(privList
, private);
1229 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
1230 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
1238 ** Setup for sending a GLX command on dpy. Make sure the extension is
1239 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
1241 CARD8
__glXSetupForCommand(Display
*dpy
)
1244 __GLXdisplayPrivate
*priv
;
1246 /* If this thread has a current context, flush its rendering commands */
1247 gc
= __glXGetCurrentContext();
1248 if (gc
->currentDpy
) {
1249 /* Flush rendering buffer of the current context, if any */
1250 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
1252 if (gc
->currentDpy
== dpy
) {
1253 /* Use opcode from gc because its right */
1255 return gc
->majorOpcode
;
1258 ** Have to get info about argument dpy because it might be to
1259 ** a different server
1264 /* Forced to lookup extension via the slow initialize route */
1265 priv
= __glXInitialize(dpy
);
1269 return priv
->majorOpcode
;
1273 * Flush the drawing command transport buffer.
1275 * \param ctx Context whose transport buffer is to be flushed.
1276 * \param pc Pointer to first unused buffer location.
1279 * Modify this function to use \c ctx->pc instead of the explicit
1282 GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*ctx
, GLubyte
*pc
)
1284 Display
* const dpy
= ctx
->currentDpy
;
1286 XCBConnection
*c
= XCBConnectionOfDisplay(dpy
);
1289 #endif /* USE_XCB */
1290 const GLint size
= pc
- ctx
->buf
;
1292 if ( (dpy
!= NULL
) && (size
> 0) ) {
1294 XCBGlxRender(c
, ctx
->currentContextTag
, size
, (char *)ctx
->buf
);
1296 /* Send the entire buffer as an X request */
1298 GetReq(GLXRender
,req
);
1299 req
->reqType
= ctx
->majorOpcode
;
1300 req
->glxCode
= X_GLXRender
;
1301 req
->contextTag
= ctx
->currentContextTag
;
1302 req
->length
+= (size
+ 3) >> 2;
1303 _XSend(dpy
, (char *)ctx
->buf
, size
);
1309 /* Reset pointer and return it */
1316 * Send a portion of a GLXRenderLarge command to the server. The advantage of
1317 * this function over \c __glXSendLargeCommand is that callers can use the
1318 * data buffer in the GLX context and may be able to avoid allocating an
1319 * extra buffer. The disadvantage is the clients will have to do more
1320 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
1322 * \sa __glXSendLargeCommand
1324 * \param gc GLX context
1325 * \param requestNumber Which part of the whole command is this? The first
1327 * \param totalRequests How many requests will there be?
1328 * \param data Command data.
1329 * \param dataLen Size, in bytes, of the command data.
1331 void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
1332 GLint totalRequests
,
1333 const GLvoid
* data
, GLint dataLen
)
1335 Display
*dpy
= gc
->currentDpy
;
1337 XCBConnection
*c
= XCBConnectionOfDisplay(dpy
);
1338 XCBGlxRenderLarge(c
, gc
->currentContextTag
, requestNumber
, totalRequests
, dataLen
, data
);
1340 xGLXRenderLargeReq
*req
;
1342 if ( requestNumber
== 1 ) {
1346 GetReq(GLXRenderLarge
,req
);
1347 req
->reqType
= gc
->majorOpcode
;
1348 req
->glxCode
= X_GLXRenderLarge
;
1349 req
->contextTag
= gc
->currentContextTag
;
1350 req
->length
+= (dataLen
+ 3) >> 2;
1351 req
->requestNumber
= requestNumber
;
1352 req
->requestTotal
= totalRequests
;
1353 req
->dataBytes
= dataLen
;
1354 Data(dpy
, data
, dataLen
);
1356 if ( requestNumber
== totalRequests
) {
1360 #endif /* USE_XCB */
1365 * Send a command that is too large for the GLXRender protocol request.
1367 * Send a large command, one that is too large for some reason to
1368 * send using the GLXRender protocol request. One reason to send
1369 * a large command is to avoid copying the data.
1371 * \param ctx GLX context
1372 * \param header Header data.
1373 * \param headerLen Size, in bytes, of the header data. It is assumed that
1374 * the header data will always be small enough to fit in
1375 * a single X protocol packet.
1376 * \param data Command data.
1377 * \param dataLen Size, in bytes, of the command data.
1379 void __glXSendLargeCommand(__GLXcontext
*ctx
,
1380 const GLvoid
*header
, GLint headerLen
,
1381 const GLvoid
*data
, GLint dataLen
)
1384 GLint totalRequests
, requestNumber
;
1387 ** Calculate the maximum amount of data can be stuffed into a single
1388 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1389 ** packet size minus sz_xGLXRenderReq.
1391 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1392 totalRequests
= 1 + (dataLen
/ maxSize
);
1393 if (dataLen
% maxSize
) totalRequests
++;
1396 ** Send all of the command, except the large array, as one request.
1398 assert( headerLen
<= maxSize
);
1399 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1402 ** Send enough requests until the whole array is sent.
1404 for ( requestNumber
= 2 ; requestNumber
<= (totalRequests
- 1) ; requestNumber
++ ) {
1405 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1406 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1408 assert( dataLen
> 0 );
1411 assert( dataLen
<= maxSize
);
1412 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1415 /************************************************************************/
1417 GLXContext
glXGetCurrentContext(void)
1419 GLXContext cx
= __glXGetCurrentContext();
1421 if (cx
== &dummyContext
) {
1428 GLXDrawable
glXGetCurrentDrawable(void)
1430 GLXContext gc
= __glXGetCurrentContext();
1431 return gc
->currentDrawable
;
1435 /************************************************************************/
1437 #ifdef GLX_DIRECT_RENDERING
1438 /* Return the DRI per screen structure */
1439 __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
)
1441 __DRIscreen
*pDRIScreen
= NULL
;
1442 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1443 XExtData
**privList
, *found
;
1444 __GLXdisplayPrivate
*dpyPriv
;
1445 XEDataObject dataObj
;
1448 dataObj
.display
= dpy
;
1449 privList
= XEHeadOfExtensionList(dataObj
);
1450 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1454 dpyPriv
= (__GLXdisplayPrivate
*)found
->private_data
;
1455 pDRIScreen
= &dpyPriv
->screenConfigs
[scrn
].driScreen
;
1462 /************************************************************************/
1464 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1465 GLXContextID gc
, GLXContextTag old_gc
, GLXDrawable draw
, GLXDrawable read
,
1466 xGLXMakeCurrentReply
* reply
);
1469 * Sends a GLX protocol message to the specified display to make the context
1470 * and the drawables current.
1472 * \param dpy Display to send the message to.
1473 * \param opcode Major opcode value for the display.
1474 * \param gc_id Context tag for the context to be made current.
1475 * \param draw Drawable ID for the "draw" drawable.
1476 * \param read Drawable ID for the "read" drawable.
1477 * \param reply Space to store the X-server's reply.
1480 * This function assumes that \c dpy is locked with \c LockDisplay on entry.
1482 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1483 GLXContextID gc_id
, GLXContextTag gc_tag
,
1484 GLXDrawable draw
, GLXDrawable read
,
1485 xGLXMakeCurrentReply
* reply
)
1487 if ( draw
== read
) {
1488 xGLXMakeCurrentReq
*req
;
1490 GetReq(GLXMakeCurrent
,req
);
1491 req
->reqType
= opcode
;
1492 req
->glxCode
= X_GLXMakeCurrent
;
1493 req
->drawable
= draw
;
1494 req
->context
= gc_id
;
1495 req
->oldContextTag
= gc_tag
;
1498 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1500 /* If the server can support the GLX 1.3 version, we should
1501 * perfer that. Not only that, some servers support GLX 1.3 but
1502 * not the SGI extension.
1505 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1506 xGLXMakeContextCurrentReq
*req
;
1508 GetReq(GLXMakeContextCurrent
,req
);
1509 req
->reqType
= opcode
;
1510 req
->glxCode
= X_GLXMakeContextCurrent
;
1511 req
->drawable
= draw
;
1512 req
->readdrawable
= read
;
1513 req
->context
= gc_id
;
1514 req
->oldContextTag
= gc_tag
;
1517 xGLXVendorPrivateWithReplyReq
*vpreq
;
1518 xGLXMakeCurrentReadSGIReq
*req
;
1520 GetReqExtra(GLXVendorPrivateWithReply
,
1521 sz_xGLXMakeCurrentReadSGIReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1522 req
= (xGLXMakeCurrentReadSGIReq
*)vpreq
;
1523 req
->reqType
= opcode
;
1524 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1525 req
->vendorCode
= X_GLXvop_MakeCurrentReadSGI
;
1526 req
->drawable
= draw
;
1527 req
->readable
= read
;
1528 req
->context
= gc_id
;
1529 req
->oldContextTag
= gc_tag
;
1533 return _XReply(dpy
, (xReply
*) reply
, 0, False
);
1537 #ifdef GLX_DIRECT_RENDERING
1538 static Bool
BindContextWrapper( Display
*dpy
, GLXContext gc
,
1539 GLXDrawable draw
, GLXDrawable read
)
1541 return (*gc
->driContext
.bindContext
)(dpy
, gc
->screen
, draw
, read
,
1546 static Bool
UnbindContextWrapper( GLXContext gc
)
1548 return (*gc
->driContext
.unbindContext
)(gc
->currentDpy
, gc
->screen
,
1549 gc
->currentDrawable
,
1550 gc
->currentReadable
,
1553 #endif /* GLX_DIRECT_RENDERING */
1557 ** Make a particular context current.
1558 ** NOTE: this is in this file so that it can access dummyContext.
1560 USED
static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
1561 GLXDrawable read
, GLXContext gc
)
1563 xGLXMakeCurrentReply reply
;
1565 CARD8 opcode
, oldOpcode
;
1566 Bool sentRequestToOldDpy
= False
;
1567 Bool bindReturnValue
= True
;
1569 opcode
= __glXSetupForCommand(dpy
);
1575 ** Make sure that the new context has a nonzero ID. In the request,
1576 ** a zero context ID is used only to mean that we bind to no current
1579 if ((gc
!= NULL
) && (gc
->xid
== None
)) {
1583 oldGC
= __glXGetCurrentContext();
1584 oldOpcode
= (gc
== oldGC
) ? opcode
: __glXSetupForCommand(dpy
);
1589 if ((dpy
!= oldGC
->currentDpy
|| (gc
&& gc
->isDirect
)) &&
1590 !oldGC
->isDirect
&& oldGC
!= &dummyContext
) {
1592 ** We are either switching from one dpy to another and have to
1593 ** send a request to the previous dpy to unbind the previous
1594 ** context, or we are switching away from a indirect context to
1595 ** a direct context and have to send a request to the dpy to
1596 ** unbind the previous context.
1598 sentRequestToOldDpy
= True
;
1599 LockDisplay(oldGC
->currentDpy
);
1600 if ( ! SendMakeCurrentRequest( oldGC
->currentDpy
, oldOpcode
, None
,
1601 oldGC
->currentContextTag
, None
, None
,
1603 /* The make current failed. Just return GL_FALSE. */
1604 UnlockDisplay(oldGC
->currentDpy
);
1609 oldGC
->currentContextTag
= 0;
1612 _glapi_check_multithread();
1614 #ifdef GLX_DIRECT_RENDERING
1615 /* Unbind the old direct rendering context */
1616 if (oldGC
->isDirect
) {
1617 if (oldGC
->driContext
.private) {
1618 if (! UnbindContextWrapper( oldGC
)) {
1619 /* The make current failed. Just return GL_FALSE. */
1623 oldGC
->currentContextTag
= 0;
1626 /* Bind the direct rendering context to the drawable */
1627 if (gc
&& gc
->isDirect
) {
1628 if (gc
->driContext
.private) {
1629 bindReturnValue
= BindContextWrapper( dpy
, gc
, draw
, read
);
1633 /* Send a glXMakeCurrent request to bind the new context. */
1636 bindReturnValue
= SendMakeCurrentRequest( dpy
, opcode
,
1637 gc
? gc
->xid
: None
,
1638 oldGC
->currentContextTag
,
1639 draw
, read
, &reply
);
1641 #ifdef GLX_DIRECT_RENDERING
1646 if (!bindReturnValue
) {
1647 /* The make current failed. */
1648 if (gc
&& !gc
->isDirect
) {
1652 #ifdef GLX_DIRECT_RENDERING
1653 /* If the old context was direct rendering, then re-bind to it. */
1654 if (oldGC
->isDirect
) {
1655 if (oldGC
->driContext
.private) {
1656 if (! BindContextWrapper( oldGC
->currentDpy
, oldGC
,
1657 oldGC
->currentDrawable
,
1658 oldGC
->currentReadable
)) {
1660 ** The request failed; this cannot happen with the
1661 ** current API. If in the future the API is
1662 ** extended to allow context sharing between
1663 ** clients, then this may fail (because another
1664 ** client may have grabbed the context); in that
1665 ** case, we cannot undo the previous request, and
1666 ** cannot adhere to the "no-op" behavior.
1673 ** If we had just sent a request to a previous dpy, we have to
1674 ** undo that request (because if a command fails, it should act
1675 ** like a no-op) by making current to the previous context and
1678 if (sentRequestToOldDpy
) {
1679 if ( !SendMakeCurrentRequest( oldGC
->currentDpy
, oldOpcode
,
1681 oldGC
->currentDrawable
,
1682 oldGC
->currentReadable
, &reply
) ) {
1683 UnlockDisplay(oldGC
->currentDpy
);
1686 ** The request failed; this cannot happen with the
1687 ** current API. If in the future the API is extended to
1688 ** allow context sharing between clients, then this may
1689 ** fail (because another client may have grabbed the
1690 ** context); in that case, we cannot undo the previous
1691 ** request, and cannot adhere to the "no-op" behavior.
1695 UnlockDisplay(oldGC
->currentDpy
);
1697 oldGC
->currentContextTag
= reply
.contextTag
;
1702 /* Update our notion of what is current */
1706 ** Even though the contexts are the same the drawable might have
1707 ** changed. Note that gc cannot be the dummy, and that oldGC
1708 ** cannot be NULL, therefore if they are the same, gc is not
1709 ** NULL and not the dummy.
1711 gc
->currentDrawable
= draw
;
1712 gc
->currentReadable
= read
;
1714 if (oldGC
!= &dummyContext
) {
1715 /* Old current context is no longer current to anybody */
1716 oldGC
->currentDpy
= 0;
1717 oldGC
->currentDrawable
= None
;
1718 oldGC
->currentReadable
= None
;
1719 oldGC
->currentContextTag
= 0;
1721 if (oldGC
->xid
== None
) {
1723 ** We are switching away from a context that was
1724 ** previously destroyed, so we need to free the memory
1725 ** for the old handle.
1727 #ifdef GLX_DIRECT_RENDERING
1728 /* Destroy the old direct rendering context */
1729 if (oldGC
->isDirect
) {
1730 if (oldGC
->driContext
.private) {
1731 (*oldGC
->driContext
.destroyContext
)
1732 (dpy
, oldGC
->screen
, oldGC
->driContext
.private);
1733 oldGC
->driContext
.private = NULL
;
1737 __glXFreeContext(oldGC
);
1741 __glXSetCurrentContext(gc
);
1742 #ifdef GLX_DIRECT_RENDERING
1743 if (!gc
->isDirect
) {
1745 IndirectAPI
= __glXNewIndirectAPI();
1746 _glapi_set_dispatch(IndirectAPI
);
1747 # ifdef GLX_USE_APPLEGL
1749 extern void XAppleDRIUseIndirectDispatch(void);
1750 XAppleDRIUseIndirectDispatch();
1755 /* if not direct rendering, always need indirect dispatch */
1757 IndirectAPI
= __glXNewIndirectAPI();
1758 _glapi_set_dispatch(IndirectAPI
);
1760 gc
->currentDpy
= dpy
;
1761 gc
->currentDrawable
= draw
;
1762 gc
->currentReadable
= read
;
1764 if ( ! gc
->isDirect
) {
1765 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1767 gc
->currentContextTag
= reply
.contextTag
;
1768 if ( state
->array_state
== NULL
) {
1769 (void) glGetString( GL_EXTENSIONS
);
1770 (void) glGetString( GL_VERSION
);
1771 __glXInitVertexArrayState(gc
);
1775 gc
->currentContextTag
= -1;
1778 __glXSetCurrentContext(&dummyContext
);
1779 #ifdef GLX_DIRECT_RENDERING
1780 _glapi_set_dispatch(NULL
); /* no-op functions */
1789 PUBLIC Bool
glXMakeCurrent(Display
*dpy
, GLXDrawable draw
, GLXContext gc
)
1791 return MakeContextCurrent( dpy
, draw
, draw
, gc
);
1794 PUBLIC
GLX_ALIAS(Bool
, glXMakeCurrentReadSGI
,
1795 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1796 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1798 PUBLIC
GLX_ALIAS(Bool
, glXMakeContextCurrent
,
1799 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1800 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1804 void __glXDumpDrawBuffer(__GLXcontext
*ctx
)
1806 GLubyte
*p
= ctx
->buf
;
1807 GLubyte
*end
= ctx
->pc
;
1808 GLushort opcode
, length
;
1812 opcode
= *((GLushort
*) p
);
1813 length
= *((GLushort
*) (p
+ 2));
1814 printf("%2x: %5d: ", opcode
, length
);
1817 while (length
> 0) {
1818 printf("%08x ", *((unsigned *) p
));
1827 #ifdef USE_SPARC_ASM
1829 * Used only when we are sparc, using sparc assembler.
1834 _glx_mesa_init_sparc_glapi_relocs(void)
1836 unsigned int *insn_ptr
, *end_ptr
;
1837 unsigned long disp_addr
;
1839 insn_ptr
= &_mesa_sparc_glapi_begin
;
1840 end_ptr
= &_mesa_sparc_glapi_end
;
1841 disp_addr
= (unsigned long) &_glapi_Dispatch
;
1844 * Verbatim from Mesa sparc.c. It's needed because there doesn't
1845 * seem to be a better way to do this:
1847 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1849 * This code is patching in the ADDRESS of the pointer to the
1850 * dispatch table. Hence, it must be called exactly once, because
1851 * that address is not going to change.
1853 * What it points to can change, but Mesa (and hence, we) assume
1854 * that there is only one pointer.
1857 while (insn_ptr
< end_ptr
) {
1858 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1860 This code patches for 64-bit addresses. This had better
1861 not happen for Sparc/Linux, no matter what architecture we
1862 are building for. So, don't do this.
1864 The 'defined(__linux_64__)' is used here as a placeholder for
1865 when we do do 64-bit usermode on sparc linux.
1867 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1868 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1869 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1870 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1871 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1872 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1875 insn_ptr
[0] |= (disp_addr
>> 10);
1876 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1877 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1882 #endif /* sparc ASM in use */