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"
52 #include "indirect_init.h"
55 # include "Xthreads.h"
56 #elif defined(PTHREADS)
59 #include "glxextensions.h"
60 #include "glcontextmodes.h"
63 #ifdef GLX_DIRECT_RENDERING
74 void __glXDumpDrawBuffer(__GLXcontext
*ctx
);
79 * This is where our dispatch table's bounds are.
80 * And the static mesa_init is taken directly from
81 * Mesa's 'sparc.c' initializer.
83 * We need something like this here, because this version
84 * of openGL/glx never initializes a Mesa context, and so
85 * the address of the dispatch table pointer never gets stuffed
86 * into the dispatch jump table otherwise.
88 * It matters only on SPARC, and only if you are using assembler
89 * code instead of C-code indirect dispatch.
93 extern unsigned int _mesa_sparc_glapi_begin
;
94 extern unsigned int _mesa_sparc_glapi_end
;
95 extern void __glapi_sparc_icache_flush(unsigned int *);
96 static void _glx_mesa_init_sparc_glapi_relocs(void);
97 static int _mesa_sparc_needs_init
= 1;
98 #define INIT_MESA_SPARC { \
99 if(_mesa_sparc_needs_init) { \
100 _glx_mesa_init_sparc_glapi_relocs(); \
101 _mesa_sparc_needs_init = 0; \
105 #define INIT_MESA_SPARC
108 static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
109 GLXDrawable read
, GLXContext gc
);
112 ** We setup some dummy structures here so that the API can be used
113 ** even if no context is current.
116 static GLubyte dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
];
119 ** Dummy context used by small commands when there is no current context.
121 ** gl and glx entry points are designed to operate as nop's when using
122 ** the dummy context structure.
124 static __GLXcontext dummyContext
= {
128 &dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
],
134 ** All indirect rendering contexts will share the same indirect dispatch table.
136 static __GLapi
*IndirectAPI
= NULL
;
140 * Current context management and locking
143 #if defined( XTHREADS )
146 static GLboolean TSDinitialized
= GL_FALSE
;
147 static xthread_key_t ContextTSD
;
149 __GLXcontext
*__glXGetCurrentContext(void)
151 if (!TSDinitialized
) {
152 xthread_key_create(&ContextTSD
, NULL
);
153 TSDinitialized
= GL_TRUE
;
154 return &dummyContext
;
158 xthread_get_specific(ContextTSD
, &p
);
160 return &dummyContext
;
162 return (__GLXcontext
*) p
;
166 void __glXSetCurrentContext(__GLXcontext
*c
)
168 if (!TSDinitialized
) {
169 xthread_key_create(&ContextTSD
, NULL
);
170 TSDinitialized
= GL_TRUE
;
172 xthread_set_specific(ContextTSD
, c
);
176 /* Used by the __glXLock() and __glXUnlock() macros */
177 xmutex_rec __glXmutex
;
179 #elif defined( PTHREADS )
181 pthread_mutex_t __glXmutex
= PTHREAD_MUTEX_INITIALIZER
;
183 # if defined( GLX_USE_TLS )
186 * Per-thread GLX context pointer.
188 * \c __glXSetCurrentContext is written is such a way that this pointer can
189 * \b never be \c NULL. This is important! Because of this
190 * \c __glXGetCurrentContext can be implemented as trivial macro.
192 __thread
void * __glX_tls_Context
__attribute__((tls_model("initial-exec")))
195 void __glXSetCurrentContext( __GLXcontext
* c
)
197 __glX_tls_Context
= (c
!= NULL
) ? c
: &dummyContext
;
202 static pthread_once_t once_control
= PTHREAD_ONCE_INIT
;
205 * Per-thread data key.
207 * Once \c init_thread_data has been called, the per-thread data key will
208 * take a value of \c NULL. As each new thread is created the default
209 * value, in that thread, will be \c NULL.
211 static pthread_key_t ContextTSD
;
214 * Initialize the per-thread data key.
216 * This function is called \b exactly once per-process (not per-thread!) to
217 * initialize the per-thread data key. This is ideally done using the
218 * \c pthread_once mechanism.
220 static void init_thread_data( void )
222 if ( pthread_key_create( & ContextTSD
, NULL
) != 0 ) {
223 perror( "pthread_key_create" );
228 void __glXSetCurrentContext( __GLXcontext
* c
)
230 pthread_once( & once_control
, init_thread_data
);
231 pthread_setspecific( ContextTSD
, c
);
234 __GLXcontext
* __glXGetCurrentContext( void )
238 pthread_once( & once_control
, init_thread_data
);
240 v
= pthread_getspecific( ContextTSD
);
241 return (v
== NULL
) ? & dummyContext
: (__GLXcontext
*) v
;
244 # endif /* defined( GLX_USE_TLS ) */
246 #elif defined( THREADS )
248 #error Unknown threading method specified.
252 /* not thread safe */
253 __GLXcontext
*__glXcurrentContext
= &dummyContext
;
259 ** You can set this cell to 1 to force the gl drawing stuff to be
260 ** one command per packet
265 ** forward prototype declarations
267 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
);
269 static GLboolean
FillInVisuals( __GLXscreenConfigs
* psc
);
271 /************************************************************************/
273 /* Extension required boiler plate */
275 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
276 XExtensionInfo
*__glXExtensionInfo
= NULL
;
278 static /* const */ char *error_list
[] = {
280 "GLXBadContextState",
284 "GLXBadCurrentWindow",
285 "GLXBadRenderRequest",
286 "GLXBadLargeRequest",
287 "GLXUnsupportedPrivateRequest",
290 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
)
294 gc
= __glXGetCurrentContext();
295 if (dpy
== gc
->currentDpy
) {
296 __glXSetCurrentContext(&dummyContext
);
297 #ifdef GLX_DIRECT_RENDERING
298 _glapi_set_dispatch(NULL
); /* no-op functions */
300 __glXFreeContext(gc
);
303 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
307 static XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
308 __GLX_NUMBER_ERRORS
, error_list
)
310 static /* const */ XExtensionHooks __glXExtensionHooks
= {
311 NULL
, /* create_gc */
315 NULL
, /* create_font */
316 NULL
, /* free_font */
317 __glXCloseDisplay
, /* close_display */
318 NULL
, /* wire_to_event */
319 NULL
, /* event_to_wire */
321 __glXErrorString
, /* error_string */
325 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
326 __glXExtensionName
, &__glXExtensionHooks
,
327 __GLX_NUMBER_EVENTS
, NULL
)
329 /************************************************************************/
332 ** Free the per screen configs data as well as the array of
333 ** __glXScreenConfigs.
335 static void FreeScreenConfigs(__GLXdisplayPrivate
*priv
)
337 __GLXscreenConfigs
*psc
;
340 /* Free screen configuration information */
341 psc
= priv
->screenConfigs
;
342 screens
= ScreenCount(priv
->dpy
);
343 for (i
= 0; i
< screens
; i
++, psc
++) {
345 _gl_context_modes_destroy( psc
->configs
);
346 if(psc
->effectiveGLXexts
)
347 Xfree(psc
->effectiveGLXexts
);
349 if ( psc
->old_configs
!= NULL
) {
350 Xfree( psc
->old_configs
);
351 psc
->old_configs
= NULL
;
352 psc
->numOldConfigs
= 0;
355 psc
->configs
= NULL
; /* NOTE: just for paranoia */
358 #ifdef GLX_DIRECT_RENDERING
359 /* Free the direct rendering per screen data */
360 if (psc
->driScreen
.private)
361 (*psc
->driScreen
.destroyScreen
)(priv
->dpy
, i
,
362 psc
->driScreen
.private);
363 psc
->driScreen
.private = NULL
;
366 XFree((char*) priv
->screenConfigs
);
370 ** Release the private memory referred to in a display private
371 ** structure. The caller will free the extension structure.
373 static int __glXFreeDisplayPrivate(XExtData
*extension
)
375 __GLXdisplayPrivate
*priv
;
377 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
378 FreeScreenConfigs(priv
);
379 if(priv
->serverGLXvendor
) {
380 Xfree((char*)priv
->serverGLXvendor
);
381 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
383 if(priv
->serverGLXversion
) {
384 Xfree((char*)priv
->serverGLXversion
);
385 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
388 #if 0 /* GLX_DIRECT_RENDERING */
389 /* Free the direct rendering per display data */
390 if (priv
->driDisplay
.private)
391 (*priv
->driDisplay
.destroyDisplay
)(priv
->dpy
,
392 priv
->driDisplay
.private);
393 priv
->driDisplay
.private = NULL
;
396 #ifdef GLX_DIRECT_RENDERING
397 XFree(priv
->driDisplay
.createScreen
);
404 /************************************************************************/
407 ** Query the version of the GLX extension. This procedure works even if
408 ** the client extension is not completely set up.
410 static Bool
QueryVersion(Display
*dpy
, int opcode
, int *major
, int *minor
)
412 xGLXQueryVersionReq
*req
;
413 xGLXQueryVersionReply reply
;
415 /* Send the glXQueryVersion request */
417 GetReq(GLXQueryVersion
,req
);
418 req
->reqType
= opcode
;
419 req
->glxCode
= X_GLXQueryVersion
;
420 req
->majorVersion
= GLX_MAJOR_VERSION
;
421 req
->minorVersion
= GLX_MINOR_VERSION
;
422 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
426 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
428 ** The server does not support the same major release as this
433 *major
= reply
.majorVersion
;
434 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
440 * Determine if a \c __GLcontextModes structure has the right mojo to be
441 * converted to a \c __GLXvisualConfig to be sent to an "old" style DRI
444 #define MODE_HAS_MOJO(m) \
445 ((m)->visualID != GLX_DONT_CARE) \
446 && ((m)->sampleBuffers == 0) \
447 && ((m)->samples == 0) \
448 && (((m)->drawableType & GLX_WINDOW_BIT) != 0) \
449 && (((m)->xRenderable == GL_TRUE) \
450 || ((m)->xRenderable == GLX_DONT_CARE))
454 * Convert the FBConfigs associated with a screen into an array of
455 * \c __GLXvisualConfig structures. These structures are passed into DRI
456 * drivers that use the "old" interface. The old-style drivers had a fairly
457 * strict set of visual types that could be supported. FBConfigs that
458 * cannot be supported are not converted.
460 * \param psc Screen whose FBConfigs need to be swizzled.
463 * If memory could be allocated and at least one FBConfig could be converted
464 * to a \c __GLXvisualConfig structure, \c GL_TRUE is returned. Otherwise,
465 * \c GL_FALSE is returned.
468 * When the old DRI driver interface is no longer supported, this function
472 FillInVisuals( __GLXscreenConfigs
* psc
)
474 __GLcontextModes
*modes
;
475 int glx_visual_count
;
478 glx_visual_count
= 0;
479 for ( modes
= psc
->configs
; modes
!= NULL
; modes
= modes
->next
) {
480 if ( MODE_HAS_MOJO( modes
) ) {
485 psc
->old_configs
= (__GLXvisualConfig
*)
486 Xmalloc( sizeof( __GLXvisualConfig
) * glx_visual_count
);
487 if ( psc
->old_configs
== NULL
) {
491 glx_visual_count
= 0;
492 for ( modes
= psc
->configs
; modes
!= NULL
; modes
= modes
->next
) {
493 if ( MODE_HAS_MOJO( modes
) ) {
495 #define COPY_VALUE(src_tag,dst_tag) \
496 psc->old_configs[glx_visual_count]. dst_tag = modes-> src_tag
498 COPY_VALUE( visualID
, vid
);
499 COPY_VALUE( rgbMode
, rgba
);
500 COPY_VALUE( stereoMode
, stereo
);
501 COPY_VALUE( doubleBufferMode
, doubleBuffer
);
503 psc
->old_configs
[glx_visual_count
].class =
504 _gl_convert_to_x_visual_type( modes
->visualType
);
506 COPY_VALUE( level
, level
);
507 COPY_VALUE( numAuxBuffers
, auxBuffers
);
509 COPY_VALUE( redBits
, redSize
);
510 COPY_VALUE( greenBits
, greenSize
);
511 COPY_VALUE( blueBits
, blueSize
);
512 COPY_VALUE( alphaBits
, alphaSize
);
513 COPY_VALUE( rgbBits
, bufferSize
);
514 COPY_VALUE( accumRedBits
, accumRedSize
);
515 COPY_VALUE( accumGreenBits
, accumGreenSize
);
516 COPY_VALUE( accumBlueBits
, accumBlueSize
);
517 COPY_VALUE( accumAlphaBits
, accumAlphaSize
);
518 COPY_VALUE( depthBits
, depthSize
);
519 COPY_VALUE( stencilBits
, stencilSize
);
521 COPY_VALUE( visualRating
, visualRating
);
522 COPY_VALUE( transparentPixel
, transparentPixel
);
523 COPY_VALUE( transparentRed
, transparentRed
);
524 COPY_VALUE( transparentGreen
, transparentGreen
);
525 COPY_VALUE( transparentBlue
, transparentBlue
);
526 COPY_VALUE( transparentAlpha
, transparentAlpha
);
527 COPY_VALUE( transparentIndex
, transparentIndex
);
535 psc
->numOldConfigs
= glx_visual_count
;
536 if ( glx_visual_count
== 0 ) {
537 Xfree( psc
->old_configs
);
538 psc
->old_configs
= NULL
;
541 return (glx_visual_count
!= 0);
546 __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
, int count
,
547 const INT32
*bp
, Bool tagged_only
,
548 Bool fbconfig_style_tags
)
553 /* Copy in the first set of properties */
554 config
->visualID
= *bp
++;
556 config
->visualType
= _gl_convert_from_x_visual_type( *bp
++ );
558 config
->rgbMode
= *bp
++;
560 config
->redBits
= *bp
++;
561 config
->greenBits
= *bp
++;
562 config
->blueBits
= *bp
++;
563 config
->alphaBits
= *bp
++;
564 config
->accumRedBits
= *bp
++;
565 config
->accumGreenBits
= *bp
++;
566 config
->accumBlueBits
= *bp
++;
567 config
->accumAlphaBits
= *bp
++;
569 config
->doubleBufferMode
= *bp
++;
570 config
->stereoMode
= *bp
++;
572 config
->rgbBits
= *bp
++;
573 config
->depthBits
= *bp
++;
574 config
->stencilBits
= *bp
++;
575 config
->numAuxBuffers
= *bp
++;
576 config
->level
= *bp
++;
578 count
-= __GLX_MIN_CONFIG_PROPS
;
582 ** Additional properties may be in a list at the end
583 ** of the reply. They are in pairs of property type
584 ** and property value.
587 #define FETCH_OR_SET(tag) \
588 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
590 for (i
= 0; i
< count
; i
+= 2 ) {
593 FETCH_OR_SET( rgbMode
);
595 case GLX_BUFFER_SIZE
:
596 config
->rgbBits
= *bp
++;
599 config
->level
= *bp
++;
601 case GLX_DOUBLEBUFFER
:
602 FETCH_OR_SET( doubleBufferMode
);
605 FETCH_OR_SET( stereoMode
);
607 case GLX_AUX_BUFFERS
:
608 config
->numAuxBuffers
= *bp
++;
611 config
->redBits
= *bp
++;
614 config
->greenBits
= *bp
++;
617 config
->blueBits
= *bp
++;
620 config
->alphaBits
= *bp
++;
623 config
->depthBits
= *bp
++;
625 case GLX_STENCIL_SIZE
:
626 config
->stencilBits
= *bp
++;
628 case GLX_ACCUM_RED_SIZE
:
629 config
->accumRedBits
= *bp
++;
631 case GLX_ACCUM_GREEN_SIZE
:
632 config
->accumGreenBits
= *bp
++;
634 case GLX_ACCUM_BLUE_SIZE
:
635 config
->accumBlueBits
= *bp
++;
637 case GLX_ACCUM_ALPHA_SIZE
:
638 config
->accumAlphaBits
= *bp
++;
640 case GLX_VISUAL_CAVEAT_EXT
:
641 config
->visualRating
= *bp
++;
643 case GLX_X_VISUAL_TYPE
:
644 config
->visualType
= *bp
++;
646 case GLX_TRANSPARENT_TYPE
:
647 config
->transparentPixel
= *bp
++;
649 case GLX_TRANSPARENT_INDEX_VALUE
:
650 config
->transparentIndex
= *bp
++;
652 case GLX_TRANSPARENT_RED_VALUE
:
653 config
->transparentRed
= *bp
++;
655 case GLX_TRANSPARENT_GREEN_VALUE
:
656 config
->transparentGreen
= *bp
++;
658 case GLX_TRANSPARENT_BLUE_VALUE
:
659 config
->transparentBlue
= *bp
++;
661 case GLX_TRANSPARENT_ALPHA_VALUE
:
662 config
->transparentAlpha
= *bp
++;
665 config
->visualID
= *bp
++;
667 case GLX_DRAWABLE_TYPE
:
668 config
->drawableType
= *bp
++;
670 case GLX_RENDER_TYPE
:
671 config
->renderType
= *bp
++;
673 case GLX_X_RENDERABLE
:
674 config
->xRenderable
= *bp
++;
676 case GLX_FBCONFIG_ID
:
677 config
->fbconfigID
= *bp
++;
679 case GLX_MAX_PBUFFER_WIDTH
:
680 config
->maxPbufferWidth
= *bp
++;
682 case GLX_MAX_PBUFFER_HEIGHT
:
683 config
->maxPbufferHeight
= *bp
++;
685 case GLX_MAX_PBUFFER_PIXELS
:
686 config
->maxPbufferPixels
= *bp
++;
688 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
689 config
->optimalPbufferWidth
= *bp
++;
691 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
692 config
->optimalPbufferHeight
= *bp
++;
694 case GLX_VISUAL_SELECT_GROUP_SGIX
:
695 config
->visualSelectGroup
= *bp
++;
697 case GLX_SWAP_METHOD_OML
:
698 config
->swapMethod
= *bp
++;
700 case GLX_SAMPLE_BUFFERS_SGIS
:
701 config
->sampleBuffers
= *bp
++;
703 case GLX_SAMPLES_SGIS
:
704 config
->samples
= *bp
++;
714 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
716 config
->haveAccumBuffer
= ((config
->accumRedBits
+
717 config
->accumGreenBits
+
718 config
->accumBlueBits
+
719 config
->accumAlphaBits
) > 0);
720 config
->haveDepthBuffer
= (config
->depthBits
> 0);
721 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
725 #ifdef GLX_DIRECT_RENDERING
727 filter_modes( __GLcontextModes
** server_modes
,
728 const __GLcontextModes
* driver_modes
)
730 __GLcontextModes
* m
;
731 __GLcontextModes
** prev_next
;
732 const __GLcontextModes
* check
;
733 unsigned modes_count
= 0;
735 if ( driver_modes
== NULL
) {
736 fprintf(stderr
, "libGL warning: 3D driver returned no fbconfigs.\n");
740 /* For each mode in server_modes, check to see if a matching mode exists
741 * in driver_modes. If not, then the mode is not available.
744 prev_next
= server_modes
;
745 for ( m
= *prev_next
; m
!= NULL
; m
= *prev_next
) {
746 GLboolean do_delete
= GL_TRUE
;
748 for ( check
= driver_modes
; check
!= NULL
; check
= check
->next
) {
749 if ( _gl_context_modes_are_same( m
, check
) ) {
750 do_delete
= GL_FALSE
;
755 /* The 3D has to support all the modes that match the GLX visuals
756 * sent from the X server.
758 if ( do_delete
&& (m
->visualID
!= 0) ) {
759 do_delete
= GL_FALSE
;
761 fprintf(stderr
, "libGL warning: 3D driver claims to not support "
762 "visual 0x%02x\n", m
->visualID
);
766 *prev_next
= m
->next
;
769 _gl_context_modes_destroy( m
);
773 prev_next
= & m
->next
;
783 * Perform the required libGL-side initialization and call the client-side
784 * driver's \c __driCreateNewScreen function.
786 * \param dpy Display pointer.
787 * \param scrn Screen number on the display.
788 * \param psc DRI screen information.
789 * \param driDpy DRI display information.
790 * \param createNewScreen Pointer to the client-side driver's
791 * \c __driCreateNewScreen function.
792 * \returns A pointer to the \c __DRIscreenPrivate structure returned by
793 * the client-side driver on success, or \c NULL on failure.
795 * \todo This function needs to be modified to remove context-modes from the
796 * list stored in the \c __GLXscreenConfigsRec to match the list
797 * returned by the client-side driver.
800 CallCreateNewScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
801 __DRIdisplay
* driDpy
,
802 CreateNewScreenFunc createNewScreen
)
804 __DRIscreenPrivate
*psp
= NULL
;
805 #ifndef GLX_USE_APPLEGL
809 __DRIversion ddx_version
;
810 __DRIversion dri_version
;
811 __DRIversion drm_version
;
812 __DRIframebuffer framebuffer
;
815 const char * err_msg
;
816 const char * err_extra
;
817 int api_ver
= __glXGetInternalVersion();
820 dri_version
.major
= driDpy
->private->driMajor
;
821 dri_version
.minor
= driDpy
->private->driMinor
;
822 dri_version
.patch
= driDpy
->private->driPatch
;
825 err_msg
= "XF86DRIOpenConnection";
828 framebuffer
.dev_priv
= NULL
;
830 if (XF86DRIOpenConnection(dpy
, scrn
, &hSAREA
, &BusID
)) {
831 fd
= drmOpen(NULL
,BusID
);
832 Xfree(BusID
); /* No longer needed */
834 err_msg
= "open DRM";
835 err_extra
= strerror( -fd
);
840 err_msg
= "drmGetMagic";
843 if (!drmGetMagic(fd
, &magic
)) {
844 drmVersionPtr version
= drmGetVersion(fd
);
846 drm_version
.major
= version
->version_major
;
847 drm_version
.minor
= version
->version_minor
;
848 drm_version
.patch
= version
->version_patchlevel
;
849 drmFreeVersion(version
);
852 drm_version
.major
= -1;
853 drm_version
.minor
= -1;
854 drm_version
.patch
= -1;
857 err_msg
= "XF86DRIAuthConnection";
858 if (XF86DRIAuthConnection(dpy
, scrn
, magic
)) {
862 * Get device name (like "tdfx") and the ddx version numbers.
863 * We'll check the version in each DRI driver's "createScreen"
866 err_msg
= "XF86DRIGetClientDriverName";
867 if (XF86DRIGetClientDriverName(dpy
, scrn
,
875 /* No longer needed. */
880 * Get device-specific info. pDevPriv will point to a struct
881 * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h)
882 * that has information about the screen size, depth, pitch,
883 * ancilliary buffers, DRM mmap handles, etc.
885 err_msg
= "XF86DRIGetDeviceInfo";
886 if (XF86DRIGetDeviceInfo(dpy
, scrn
,
891 &framebuffer
.dev_priv_size
,
892 &framebuffer
.dev_priv
)) {
893 framebuffer
.width
= DisplayWidth(dpy
, scrn
);
894 framebuffer
.height
= DisplayHeight(dpy
, scrn
);
897 * Map the framebuffer region.
899 status
= drmMap(fd
, hFB
, framebuffer
.size
,
900 (drmAddressPtr
)&framebuffer
.base
);
902 err_msg
= "drmMap of framebuffer";
903 err_extra
= strerror( -status
);
907 * Map the SAREA region. Further mmap regions may be setup in
908 * each DRI driver's "createScreen" function.
910 status
= drmMap(fd
, hSAREA
, SAREA_MAX
,
913 err_msg
= "drmMap of sarea";
914 err_extra
= strerror( -status
);
917 __GLcontextModes
* driver_modes
= NULL
;
918 __GLXscreenConfigs
*configs
= psc
->screenConfigs
;
920 err_msg
= "InitDriver";
922 psp
= (*createNewScreen
)(dpy
, scrn
,
934 filter_modes( & configs
->configs
,
936 _gl_context_modes_destroy( driver_modes
);
947 if ( pSAREA
!= MAP_FAILED
) {
948 (void)drmUnmap(pSAREA
, SAREA_MAX
);
951 if ( framebuffer
.base
!= MAP_FAILED
) {
952 (void)drmUnmap((drmAddress
)framebuffer
.base
, framebuffer
.size
);
955 if ( framebuffer
.dev_priv
!= NULL
) {
956 Xfree(framebuffer
.dev_priv
);
963 (void)XF86DRICloseConnection(dpy
, scrn
);
965 if ( err_extra
!= NULL
) {
966 fprintf(stderr
, "libGL error: %s failed (%s)\n", err_msg
,
970 fprintf(stderr
, "libGL error: %s failed\n", err_msg
);
973 fprintf(stderr
, "libGL error: reverting to (slow) indirect rendering\n");
975 #endif /* !GLX_USE_APPLEGL */
979 #endif /* GLX_DIRECT_RENDERING */
983 ** Allocate the memory for the per screen configs for each screen.
984 ** If that works then fetch the per screen configs data.
986 static Bool
AllocAndFetchScreenConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
)
988 xGLXGetVisualConfigsReq
*req
;
989 xGLXGetFBConfigsReq
*fb_req
;
990 xGLXVendorPrivateWithReplyReq
*vpreq
;
991 xGLXGetFBConfigsSGIXReq
*sgi_req
;
992 xGLXGetVisualConfigsReply reply
;
993 __GLXscreenConfigs
*psc
;
994 __GLcontextModes
*config
;
995 GLint i
, j
, nprops
, screens
;
996 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
997 unsigned supported_request
= 0;
1001 ** First allocate memory for the array of per screen configs.
1003 screens
= ScreenCount(dpy
);
1004 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
1008 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
1009 priv
->screenConfigs
= psc
;
1011 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1012 X_GLXQueryServerString
,
1014 if ( priv
->serverGLXversion
== NULL
) {
1015 FreeScreenConfigs(priv
);
1019 if ( atof( priv
->serverGLXversion
) >= 1.3 ) {
1020 supported_request
= 1;
1024 ** Now fetch each screens configs structures. If a screen supports
1025 ** GL (by returning a numVisuals > 0) then allocate memory for our
1026 ** config structure and then fill it in.
1028 for (i
= 0; i
< screens
; i
++, psc
++) {
1029 if ( supported_request
!= 1 ) {
1030 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1031 X_GLXQueryServerString
,
1033 if ( strstr( psc
->serverGLXexts
, "GLX_SGIX_fbconfig" ) != NULL
) {
1034 supported_request
= 2;
1037 supported_request
= 3;
1043 switch( supported_request
) {
1045 GetReq(GLXGetFBConfigs
,fb_req
);
1046 fb_req
->reqType
= priv
->majorOpcode
;
1047 fb_req
->glxCode
= X_GLXGetFBConfigs
;
1052 GetReqExtra(GLXVendorPrivateWithReply
,
1053 sz_xGLXGetFBConfigsSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1054 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
1055 sgi_req
->reqType
= priv
->majorOpcode
;
1056 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
1057 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
1058 sgi_req
->screen
= i
;
1062 GetReq(GLXGetVisualConfigs
,req
);
1063 req
->reqType
= priv
->majorOpcode
;
1064 req
->glxCode
= X_GLXGetVisualConfigs
;
1069 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
)) {
1070 /* Something is busted. Punt. */
1072 FreeScreenConfigs(priv
);
1077 if (!reply
.numVisuals
) {
1078 /* This screen does not support GL rendering */
1083 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for
1086 /* Check number of properties */
1087 nprops
= reply
.numProps
;
1088 if ((nprops
< __GLX_MIN_CONFIG_PROPS
) ||
1089 (nprops
> __GLX_MAX_CONFIG_PROPS
)) {
1090 /* Huh? Not in protocol defined limits. Punt */
1093 FreeScreenConfigs(priv
);
1097 /* Allocate memory for our config structure */
1098 psc
->configs
= _gl_context_modes_create(reply
.numVisuals
,
1099 sizeof(__GLcontextModes
));
1100 if (!psc
->configs
) {
1103 FreeScreenConfigs(priv
);
1107 /* Allocate memory for the properties, if needed */
1108 if ( supported_request
!= 3 ) {
1112 prop_size
= nprops
* __GLX_SIZE_INT32
;
1114 if (prop_size
<= sizeof(buf
)) {
1117 props
= (INT32
*) Xmalloc(prop_size
);
1120 /* Read each config structure and convert it into our format */
1121 config
= psc
->configs
;
1122 for (j
= 0; j
< reply
.numVisuals
; j
++) {
1123 assert( config
!= NULL
);
1124 _XRead(dpy
, (char *)props
, prop_size
);
1126 if ( supported_request
!= 3 ) {
1127 config
->rgbMode
= GL_TRUE
;
1128 config
->drawableType
= GLX_WINDOW_BIT
;
1131 config
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
1134 __glXInitializeVisualConfigFromTags( config
, nprops
, props
,
1135 (supported_request
!= 3),
1137 if ( config
->fbconfigID
== GLX_DONT_CARE
) {
1138 config
->fbconfigID
= config
->visualID
;
1141 config
= config
->next
;
1144 Xfree((char *)props
);
1148 #ifdef GLX_DIRECT_RENDERING
1149 /* Initialize per screen dynamic client GLX extensions */
1150 psc
->ext_list_first_time
= GL_TRUE
;
1151 /* Initialize the direct rendering per screen data and functions */
1152 if (priv
->driDisplay
.private != NULL
) {
1153 if (priv
->driDisplay
.createNewScreen
&&
1154 priv
->driDisplay
.createNewScreen
[i
]) {
1156 psc
->driScreen
.screenConfigs
= (void *)psc
;
1157 psc
->driScreen
.private =
1158 CallCreateNewScreen(dpy
, i
, & psc
->driScreen
,
1160 priv
->driDisplay
.createNewScreen
[i
] );
1162 else if (priv
->driDisplay
.createScreen
&&
1163 priv
->driDisplay
.createScreen
[i
]) {
1164 /* screen initialization (bootstrap the driver) */
1165 if ( (psc
->old_configs
== NULL
)
1166 && !FillInVisuals(psc
) ) {
1167 FreeScreenConfigs(priv
);
1171 psc
->driScreen
.screenConfigs
= (void *)psc
;
1172 psc
->driScreen
.private =
1173 (*(priv
->driDisplay
.createScreen
[i
]))(dpy
, i
, &psc
->driScreen
,
1185 ** Initialize the client side extension code.
1187 __GLXdisplayPrivate
*__glXInitialize(Display
* dpy
)
1189 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1190 XExtData
**privList
, *private, *found
;
1191 __GLXdisplayPrivate
*dpyPriv
;
1192 XEDataObject dataObj
;
1195 #if defined(XTHREADS)
1197 static int firstCall
= 1;
1199 /* initialize the GLX mutexes */
1200 xmutex_init(&__glXmutex
);
1207 /* The one and only long long lock */
1210 if (!XextHasExtension(info
)) {
1211 /* No GLX extension supported by this server. Oh well. */
1213 XMissingExtension(dpy
, __glXExtensionName
);
1217 /* See if a display private already exists. If so, return it */
1218 dataObj
.display
= dpy
;
1219 privList
= XEHeadOfExtensionList(dataObj
);
1220 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1223 return (__GLXdisplayPrivate
*) found
->private_data
;
1226 /* See if the versions are compatible */
1227 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
1228 /* The client and server do not agree on versions. Punt. */
1234 ** Allocate memory for all the pieces needed for this buffer.
1236 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
1241 dpyPriv
= (__GLXdisplayPrivate
*) Xmalloc(sizeof(__GLXdisplayPrivate
));
1244 Xfree((char*) private);
1249 ** Init the display private and then read in the screen config
1250 ** structures from the server.
1252 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
1253 dpyPriv
->majorVersion
= major
;
1254 dpyPriv
->minorVersion
= minor
;
1257 dpyPriv
->serverGLXvendor
= 0x0;
1258 dpyPriv
->serverGLXversion
= 0x0;
1260 #ifdef GLX_DIRECT_RENDERING
1262 ** Initialize the direct rendering per display data and functions.
1263 ** Note: This _must_ be done before calling any other DRI routines
1264 ** (e.g., those called in AllocAndFetchScreenConfigs).
1266 if (getenv("LIBGL_ALWAYS_INDIRECT")) {
1267 /* Assinging zero here assures we'll never go direct */
1268 dpyPriv
->driDisplay
.private = 0;
1269 dpyPriv
->driDisplay
.destroyDisplay
= 0;
1270 dpyPriv
->driDisplay
.createScreen
= 0;
1273 dpyPriv
->driDisplay
.private =
1274 driCreateDisplay(dpy
, &dpyPriv
->driDisplay
);
1278 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
1280 Xfree((char*) dpyPriv
);
1281 Xfree((char*) private);
1286 ** Fill in the private structure. This is the actual structure that
1287 ** hangs off of the Display structure. Our private structure is
1288 ** referred to by this structure. Got that?
1290 private->number
= info
->codes
->extension
;
1292 private->free_private
= __glXFreeDisplayPrivate
;
1293 private->private_data
= (char *) dpyPriv
;
1294 XAddToExtensionList(privList
, private);
1296 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
1297 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
1305 ** Setup for sending a GLX command on dpy. Make sure the extension is
1306 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
1308 CARD8
__glXSetupForCommand(Display
*dpy
)
1311 __GLXdisplayPrivate
*priv
;
1313 /* If this thread has a current context, flush its rendering commands */
1314 gc
= __glXGetCurrentContext();
1315 if (gc
->currentDpy
) {
1316 /* Flush rendering buffer of the current context, if any */
1317 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
1319 if (gc
->currentDpy
== dpy
) {
1320 /* Use opcode from gc because its right */
1322 return gc
->majorOpcode
;
1325 ** Have to get info about argument dpy because it might be to
1326 ** a different server
1331 /* Forced to lookup extension via the slow initialize route */
1332 priv
= __glXInitialize(dpy
);
1336 return priv
->majorOpcode
;
1340 * Flush the drawing command transport buffer.
1342 * \param ctx Context whose transport buffer is to be flushed.
1343 * \param pc Pointer to first unused buffer location.
1346 * Modify this function to use \c ctx->pc instead of the explicit
1349 GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*ctx
, GLubyte
*pc
)
1351 Display
* const dpy
= ctx
->currentDpy
;
1353 const GLint size
= pc
- ctx
->buf
;
1355 if ( (dpy
!= NULL
) && (size
> 0) ) {
1356 /* Send the entire buffer as an X request */
1358 GetReq(GLXRender
,req
);
1359 req
->reqType
= ctx
->majorOpcode
;
1360 req
->glxCode
= X_GLXRender
;
1361 req
->contextTag
= ctx
->currentContextTag
;
1362 req
->length
+= (size
+ 3) >> 2;
1363 _XSend(dpy
, (char *)ctx
->buf
, size
);
1368 /* Reset pointer and return it */
1375 * Send a portion of a GLXRenderLarge command to the server. The advantage of
1376 * this function over \c __glXSendLargeCommand is that callers can use the
1377 * data buffer in the GLX context and may be able to avoid allocating an
1378 * extra buffer. The disadvantage is the clients will have to do more
1379 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
1381 * \sa __glXSendLargeCommand
1383 * \param gc GLX context
1384 * \param requestNumber Which part of the whole command is this? The first
1386 * \param totalRequests How many requests will there be?
1387 * \param data Command data.
1388 * \param dataLen Size, in bytes, of the command data.
1390 void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
1391 GLint totalRequests
,
1392 const GLvoid
* data
, GLint dataLen
)
1394 Display
*dpy
= gc
->currentDpy
;
1395 xGLXRenderLargeReq
*req
;
1397 if ( requestNumber
== 1 ) {
1401 GetReq(GLXRenderLarge
,req
);
1402 req
->reqType
= gc
->majorOpcode
;
1403 req
->glxCode
= X_GLXRenderLarge
;
1404 req
->contextTag
= gc
->currentContextTag
;
1405 req
->length
+= (dataLen
+ 3) >> 2;
1406 req
->requestNumber
= requestNumber
;
1407 req
->requestTotal
= totalRequests
;
1408 req
->dataBytes
= dataLen
;
1409 Data(dpy
, data
, dataLen
);
1411 if ( requestNumber
== totalRequests
) {
1419 * Send a command that is too large for the GLXRender protocol request.
1421 * Send a large command, one that is too large for some reason to
1422 * send using the GLXRender protocol request. One reason to send
1423 * a large command is to avoid copying the data.
1425 * \param ctx GLX context
1426 * \param header Header data.
1427 * \param headerLen Size, in bytes, of the header data. It is assumed that
1428 * the header data will always be small enough to fit in
1429 * a single X protocol packet.
1430 * \param data Command data.
1431 * \param dataLen Size, in bytes, of the command data.
1433 void __glXSendLargeCommand(__GLXcontext
*ctx
,
1434 const GLvoid
*header
, GLint headerLen
,
1435 const GLvoid
*data
, GLint dataLen
)
1438 GLint totalRequests
, requestNumber
;
1441 ** Calculate the maximum amount of data can be stuffed into a single
1442 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1443 ** packet size minus sz_xGLXRenderReq.
1445 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1446 totalRequests
= 1 + (dataLen
/ maxSize
);
1447 if (dataLen
% maxSize
) totalRequests
++;
1450 ** Send all of the command, except the large array, as one request.
1452 assert( headerLen
<= maxSize
);
1453 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1456 ** Send enough requests until the whole array is sent.
1458 for ( requestNumber
= 2 ; requestNumber
<= (totalRequests
- 1) ; requestNumber
++ ) {
1459 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1460 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1462 assert( dataLen
> 0 );
1465 assert( dataLen
<= maxSize
);
1466 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1469 /************************************************************************/
1471 GLXContext
glXGetCurrentContext(void)
1473 GLXContext cx
= __glXGetCurrentContext();
1475 if (cx
== &dummyContext
) {
1482 GLXDrawable
glXGetCurrentDrawable(void)
1484 GLXContext gc
= __glXGetCurrentContext();
1485 return gc
->currentDrawable
;
1489 /************************************************************************/
1491 #ifdef GLX_DIRECT_RENDERING
1492 /* Return the DRI per screen structure */
1493 __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
)
1495 __DRIscreen
*pDRIScreen
= NULL
;
1496 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1497 XExtData
**privList
, *found
;
1498 __GLXdisplayPrivate
*dpyPriv
;
1499 XEDataObject dataObj
;
1502 dataObj
.display
= dpy
;
1503 privList
= XEHeadOfExtensionList(dataObj
);
1504 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1508 dpyPriv
= (__GLXdisplayPrivate
*)found
->private_data
;
1509 pDRIScreen
= &dpyPriv
->screenConfigs
[scrn
].driScreen
;
1516 /************************************************************************/
1518 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1519 GLXContextID gc
, GLXContextTag old_gc
, GLXDrawable draw
, GLXDrawable read
,
1520 xGLXMakeCurrentReply
* reply
);
1523 * Sends a GLX protocol message to the specified display to make the context
1524 * and the drawables current.
1526 * \param dpy Display to send the message to.
1527 * \param opcode Major opcode value for the display.
1528 * \param gc_id Context tag for the context to be made current.
1529 * \param draw Drawable ID for the "draw" drawable.
1530 * \param read Drawable ID for the "read" drawable.
1531 * \param reply Space to store the X-server's reply.
1534 * This function assumes that \c dpy is locked with \c LockDisplay on entry.
1536 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1537 GLXContextID gc_id
, GLXContextTag gc_tag
,
1538 GLXDrawable draw
, GLXDrawable read
,
1539 xGLXMakeCurrentReply
* reply
)
1541 if ( draw
== read
) {
1542 xGLXMakeCurrentReq
*req
;
1544 GetReq(GLXMakeCurrent
,req
);
1545 req
->reqType
= opcode
;
1546 req
->glxCode
= X_GLXMakeCurrent
;
1547 req
->drawable
= draw
;
1548 req
->context
= gc_id
;
1549 req
->oldContextTag
= gc_tag
;
1552 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1554 /* If the server can support the GLX 1.3 version, we should
1555 * perfer that. Not only that, some servers support GLX 1.3 but
1556 * not the SGI extension.
1559 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1560 xGLXMakeContextCurrentReq
*req
;
1562 GetReq(GLXMakeContextCurrent
,req
);
1563 req
->reqType
= opcode
;
1564 req
->glxCode
= X_GLXMakeContextCurrent
;
1565 req
->drawable
= draw
;
1566 req
->readdrawable
= read
;
1567 req
->context
= gc_id
;
1568 req
->oldContextTag
= gc_tag
;
1571 xGLXVendorPrivateWithReplyReq
*vpreq
;
1572 xGLXMakeCurrentReadSGIReq
*req
;
1574 GetReqExtra(GLXVendorPrivateWithReply
,
1575 sz_xGLXMakeCurrentReadSGIReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1576 req
= (xGLXMakeCurrentReadSGIReq
*)vpreq
;
1577 req
->reqType
= opcode
;
1578 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1579 req
->vendorCode
= X_GLXvop_MakeCurrentReadSGI
;
1580 req
->drawable
= draw
;
1581 req
->readable
= read
;
1582 req
->context
= gc_id
;
1583 req
->oldContextTag
= gc_tag
;
1587 return _XReply(dpy
, (xReply
*) reply
, 0, False
);
1591 static Bool
BindContextWrapper( Display
*dpy
, GLXContext gc
,
1592 GLXDrawable draw
, GLXDrawable read
)
1594 #ifdef GLX_DIRECT_RENDERING
1595 if ( gc
->driContext
.bindContext3
!= NULL
) {
1596 return (*gc
->driContext
.bindContext3
)(dpy
, gc
->screen
, draw
, read
,
1599 #ifndef DRI_NEW_INTERFACE_ONLY
1601 return (*gc
->driContext
.bindContext2
)(dpy
, gc
->screen
, draw
, read
,
1610 static Bool
UnbindContextWrapper( Display
*dpy
, GLXContext gc
)
1612 #ifdef GLX_DIRECT_RENDERING
1613 if ( gc
->driContext
.unbindContext3
!= NULL
) {
1614 return (*gc
->driContext
.unbindContext3
)(dpy
, gc
->screen
,
1615 gc
->currentDrawable
,
1616 gc
->currentReadable
,
1619 #ifndef DRI_NEW_INTERFACE_ONLY
1621 return (*gc
->driContext
.unbindContext2
)(dpy
, gc
->screen
,
1622 gc
->currentDrawable
,
1623 gc
->currentReadable
, gc
);
1632 ** Make a particular context current.
1633 ** NOTE: this is in this file so that it can access dummyContext.
1635 USED
static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
1636 GLXDrawable read
, GLXContext gc
)
1638 xGLXMakeCurrentReply reply
;
1640 CARD8 opcode
, oldOpcode
;
1641 Bool sentRequestToOldDpy
= False
;
1642 Bool bindReturnValue
= True
;
1644 opcode
= __glXSetupForCommand(dpy
);
1650 ** Make sure that the new context has a nonzero ID. In the request,
1651 ** a zero context ID is used only to mean that we bind to no current
1654 if ((gc
!= NULL
) && (gc
->xid
== None
)) {
1658 oldGC
= __glXGetCurrentContext();
1659 oldOpcode
= (gc
== oldGC
) ? opcode
: __glXSetupForCommand(dpy
);
1664 if ((dpy
!= oldGC
->currentDpy
|| (gc
&& gc
->isDirect
)) &&
1665 !oldGC
->isDirect
&& oldGC
!= &dummyContext
) {
1667 ** We are either switching from one dpy to another and have to
1668 ** send a request to the previous dpy to unbind the previous
1669 ** context, or we are switching away from a indirect context to
1670 ** a direct context and have to send a request to the dpy to
1671 ** unbind the previous context.
1673 sentRequestToOldDpy
= True
;
1674 LockDisplay(oldGC
->currentDpy
);
1675 if ( ! SendMakeCurrentRequest( oldGC
->currentDpy
, oldOpcode
, None
,
1676 oldGC
->currentContextTag
, None
, None
,
1678 /* The make current failed. Just return GL_FALSE. */
1679 UnlockDisplay(oldGC
->currentDpy
);
1684 oldGC
->currentContextTag
= 0;
1687 #ifdef GLX_DIRECT_RENDERING
1688 /* Unbind the old direct rendering context */
1689 if (oldGC
->isDirect
) {
1690 if (oldGC
->driContext
.private) {
1691 if (! UnbindContextWrapper( oldGC
->currentDpy
, oldGC
)) {
1692 /* The make current failed. Just return GL_FALSE. */
1696 oldGC
->currentContextTag
= 0;
1699 /* Bind the direct rendering context to the drawable */
1700 if (gc
&& gc
->isDirect
) {
1701 if (gc
->driContext
.private) {
1702 bindReturnValue
= BindContextWrapper( dpy
, gc
, draw
, read
);
1706 _glapi_check_multithread();
1707 /* Send a glXMakeCurrent request to bind the new context. */
1710 bindReturnValue
= SendMakeCurrentRequest( dpy
, opcode
,
1711 gc
? gc
->xid
: None
,
1712 oldGC
->currentContextTag
,
1713 draw
, read
, &reply
);
1715 #ifdef GLX_DIRECT_RENDERING
1720 if (!bindReturnValue
) {
1721 /* The make current failed. */
1722 if (gc
&& !gc
->isDirect
) {
1726 #ifdef GLX_DIRECT_RENDERING
1727 /* If the old context was direct rendering, then re-bind to it. */
1728 if (oldGC
->isDirect
) {
1729 if (oldGC
->driContext
.private) {
1730 if (! BindContextWrapper( oldGC
->currentDpy
, oldGC
,
1731 oldGC
->currentDrawable
,
1732 oldGC
->currentReadable
)) {
1734 ** The request failed; this cannot happen with the
1735 ** current API. If in the future the API is
1736 ** extended to allow context sharing between
1737 ** clients, then this may fail (because another
1738 ** client may have grabbed the context); in that
1739 ** case, we cannot undo the previous request, and
1740 ** cannot adhere to the "no-op" behavior.
1747 ** If we had just sent a request to a previous dpy, we have to
1748 ** undo that request (because if a command fails, it should act
1749 ** like a no-op) by making current to the previous context and
1752 if (sentRequestToOldDpy
) {
1753 if ( !SendMakeCurrentRequest( oldGC
->currentDpy
, oldOpcode
,
1755 oldGC
->currentDrawable
,
1756 oldGC
->currentReadable
, &reply
) ) {
1757 UnlockDisplay(oldGC
->currentDpy
);
1760 ** The request failed; this cannot happen with the
1761 ** current API. If in the future the API is extended to
1762 ** allow context sharing between clients, then this may
1763 ** fail (because another client may have grabbed the
1764 ** context); in that case, we cannot undo the previous
1765 ** request, and cannot adhere to the "no-op" behavior.
1769 UnlockDisplay(oldGC
->currentDpy
);
1771 oldGC
->currentContextTag
= reply
.contextTag
;
1776 /* Update our notion of what is current */
1780 ** Even though the contexts are the same the drawable might have
1781 ** changed. Note that gc cannot be the dummy, and that oldGC
1782 ** cannot be NULL, therefore if they are the same, gc is not
1783 ** NULL and not the dummy.
1785 gc
->currentDrawable
= draw
;
1786 gc
->currentReadable
= read
;
1788 if (oldGC
!= &dummyContext
) {
1789 /* Old current context is no longer current to anybody */
1790 oldGC
->currentDpy
= 0;
1791 oldGC
->currentDrawable
= None
;
1792 oldGC
->currentReadable
= None
;
1793 oldGC
->currentContextTag
= 0;
1795 if (oldGC
->xid
== None
) {
1797 ** We are switching away from a context that was
1798 ** previously destroyed, so we need to free the memory
1799 ** for the old handle.
1801 #ifdef GLX_DIRECT_RENDERING
1802 /* Destroy the old direct rendering context */
1803 if (oldGC
->isDirect
) {
1804 if (oldGC
->driContext
.private) {
1805 (*oldGC
->driContext
.destroyContext
)
1806 (dpy
, oldGC
->screen
, oldGC
->driContext
.private);
1807 oldGC
->driContext
.private = NULL
;
1811 __glXFreeContext(oldGC
);
1815 __glXSetCurrentContext(gc
);
1816 #ifdef GLX_DIRECT_RENDERING
1817 if (!gc
->isDirect
) {
1819 IndirectAPI
= __glXNewIndirectAPI();
1820 _glapi_set_dispatch(IndirectAPI
);
1821 # ifdef GLX_USE_APPLEGL
1823 extern void XAppleDRIUseIndirectDispatch(void);
1824 XAppleDRIUseIndirectDispatch();
1829 /* if not direct rendering, always need indirect dispatch */
1831 IndirectAPI
= __glXNewIndirectAPI();
1832 _glapi_set_dispatch(IndirectAPI
);
1834 gc
->currentDpy
= dpy
;
1835 gc
->currentDrawable
= draw
;
1836 gc
->currentReadable
= read
;
1838 if ( ! gc
->isDirect
) {
1839 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1841 gc
->currentContextTag
= reply
.contextTag
;
1842 if ( state
->array_state
== NULL
) {
1843 (void) glGetString( GL_EXTENSIONS
);
1844 (void) glGetString( GL_VERSION
);
1845 __glXInitVertexArrayState(gc
);
1849 gc
->currentContextTag
= -1;
1852 __glXSetCurrentContext(&dummyContext
);
1853 #ifdef GLX_DIRECT_RENDERING
1854 _glapi_set_dispatch(NULL
); /* no-op functions */
1863 PUBLIC Bool
GLX_PREFIX(glXMakeCurrent
)(Display
*dpy
, GLXDrawable draw
,
1866 return MakeContextCurrent( dpy
, draw
, draw
, gc
);
1869 PUBLIC
GLX_ALIAS(Bool
, glXMakeCurrentReadSGI
,
1870 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1871 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1873 PUBLIC
GLX_ALIAS(Bool
, glXMakeContextCurrent
,
1874 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1875 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1879 void __glXDumpDrawBuffer(__GLXcontext
*ctx
)
1881 GLubyte
*p
= ctx
->buf
;
1882 GLubyte
*end
= ctx
->pc
;
1883 GLushort opcode
, length
;
1887 opcode
= *((GLushort
*) p
);
1888 length
= *((GLushort
*) (p
+ 2));
1889 printf("%2x: %5d: ", opcode
, length
);
1892 while (length
> 0) {
1893 printf("%08x ", *((unsigned *) p
));
1902 #ifdef USE_SPARC_ASM
1904 * Used only when we are sparc, using sparc assembler.
1909 _glx_mesa_init_sparc_glapi_relocs(void)
1911 unsigned int *insn_ptr
, *end_ptr
;
1912 unsigned long disp_addr
;
1914 insn_ptr
= &_mesa_sparc_glapi_begin
;
1915 end_ptr
= &_mesa_sparc_glapi_end
;
1916 disp_addr
= (unsigned long) &_glapi_Dispatch
;
1919 * Verbatim from Mesa sparc.c. It's needed because there doesn't
1920 * seem to be a better way to do this:
1922 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1924 * This code is patching in the ADDRESS of the pointer to the
1925 * dispatch table. Hence, it must be called exactly once, because
1926 * that address is not going to change.
1928 * What it points to can change, but Mesa (and hence, we) assume
1929 * that there is only one pointer.
1932 while (insn_ptr
< end_ptr
) {
1933 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1935 This code patches for 64-bit addresses. This had better
1936 not happen for Sparc/Linux, no matter what architecture we
1937 are building for. So, don't do this.
1939 The 'defined(__linux_64__)' is used here as a placeholder for
1940 when we do do 64-bit usermode on sparc linux.
1942 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1943 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1944 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1945 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1946 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1947 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1950 insn_ptr
[0] |= (disp_addr
>> 10);
1951 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1952 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1957 #endif /* sparc ASM in use */