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>
51 #include <X11/extensions/Xfixes.h>
52 #include <X11/extensions/Xdamage.h>
54 #include "indirect_init.h"
56 #include "glxextensions.h"
57 #include "glcontextmodes.h"
60 #ifdef GLX_DIRECT_RENDERING
69 #include <X11/Xlib-xcb.h>
77 void __glXDumpDrawBuffer(__GLXcontext
*ctx
);
82 * This is where our dispatch table's bounds are.
83 * And the static mesa_init is taken directly from
84 * Mesa's 'sparc.c' initializer.
86 * We need something like this here, because this version
87 * of openGL/glx never initializes a Mesa context, and so
88 * the address of the dispatch table pointer never gets stuffed
89 * into the dispatch jump table otherwise.
91 * It matters only on SPARC, and only if you are using assembler
92 * code instead of C-code indirect dispatch.
96 extern unsigned int _mesa_sparc_glapi_begin
;
97 extern unsigned int _mesa_sparc_glapi_end
;
98 extern void __glapi_sparc_icache_flush(unsigned int *);
99 static void _glx_mesa_init_sparc_glapi_relocs(void);
100 static int _mesa_sparc_needs_init
= 1;
101 #define INIT_MESA_SPARC { \
102 if(_mesa_sparc_needs_init) { \
103 _glx_mesa_init_sparc_glapi_relocs(); \
104 _mesa_sparc_needs_init = 0; \
108 #define INIT_MESA_SPARC
111 #ifdef GLX_DIRECT_RENDERING
112 static __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
);
113 #endif /* GLX_DIRECT_RENDERING */
115 static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
116 GLXDrawable read
, GLXContext gc
);
119 ** We setup some dummy structures here so that the API can be used
120 ** even if no context is current.
123 static GLubyte dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
];
126 ** Dummy context used by small commands when there is no current context.
128 ** gl and glx entry points are designed to operate as nop's when using
129 ** the dummy context structure.
131 static __GLXcontext dummyContext
= {
135 &dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
],
141 ** All indirect rendering contexts will share the same indirect dispatch table.
143 static __GLapi
*IndirectAPI
= NULL
;
147 * Current context management and locking
150 #if defined( USE_XTHREADS )
153 static GLboolean TSDinitialized
= GL_FALSE
;
154 static xthread_key_t ContextTSD
;
156 __GLXcontext
*__glXGetCurrentContext(void)
158 if (!TSDinitialized
) {
159 xthread_key_create(&ContextTSD
, NULL
);
160 TSDinitialized
= GL_TRUE
;
161 return &dummyContext
;
165 xthread_get_specific(ContextTSD
, &p
);
167 return &dummyContext
;
169 return (__GLXcontext
*) p
;
173 void __glXSetCurrentContext(__GLXcontext
*c
)
175 if (!TSDinitialized
) {
176 xthread_key_create(&ContextTSD
, NULL
);
177 TSDinitialized
= GL_TRUE
;
179 xthread_set_specific(ContextTSD
, c
);
183 /* Used by the __glXLock() and __glXUnlock() macros */
184 xmutex_rec __glXmutex
;
186 #elif defined( PTHREADS )
188 pthread_mutex_t __glXmutex
= PTHREAD_MUTEX_INITIALIZER
;
190 # if defined( GLX_USE_TLS )
193 * Per-thread GLX context pointer.
195 * \c __glXSetCurrentContext is written is such a way that this pointer can
196 * \b never be \c NULL. This is important! Because of this
197 * \c __glXGetCurrentContext can be implemented as trivial macro.
199 __thread
void * __glX_tls_Context
__attribute__((tls_model("initial-exec")))
202 void __glXSetCurrentContext( __GLXcontext
* c
)
204 __glX_tls_Context
= (c
!= NULL
) ? c
: &dummyContext
;
209 static pthread_once_t once_control
= PTHREAD_ONCE_INIT
;
212 * Per-thread data key.
214 * Once \c init_thread_data has been called, the per-thread data key will
215 * take a value of \c NULL. As each new thread is created the default
216 * value, in that thread, will be \c NULL.
218 static pthread_key_t ContextTSD
;
221 * Initialize the per-thread data key.
223 * This function is called \b exactly once per-process (not per-thread!) to
224 * initialize the per-thread data key. This is ideally done using the
225 * \c pthread_once mechanism.
227 static void init_thread_data( void )
229 if ( pthread_key_create( & ContextTSD
, NULL
) != 0 ) {
230 perror( "pthread_key_create" );
235 void __glXSetCurrentContext( __GLXcontext
* c
)
237 pthread_once( & once_control
, init_thread_data
);
238 pthread_setspecific( ContextTSD
, c
);
241 __GLXcontext
* __glXGetCurrentContext( void )
245 pthread_once( & once_control
, init_thread_data
);
247 v
= pthread_getspecific( ContextTSD
);
248 return (v
== NULL
) ? & dummyContext
: (__GLXcontext
*) v
;
251 # endif /* defined( GLX_USE_TLS ) */
253 #elif defined( THREADS )
255 #error Unknown threading method specified.
259 /* not thread safe */
260 __GLXcontext
*__glXcurrentContext
= &dummyContext
;
266 ** You can set this cell to 1 to force the gl drawing stuff to be
267 ** one command per packet
272 ** forward prototype declarations
274 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
);
277 /************************************************************************/
279 /* Extension required boiler plate */
281 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
282 XExtensionInfo
*__glXExtensionInfo
= NULL
;
284 static /* const */ char *error_list
[] = {
286 "GLXBadContextState",
290 "GLXBadCurrentWindow",
291 "GLXBadRenderRequest",
292 "GLXBadLargeRequest",
293 "GLXUnsupportedPrivateRequest",
296 "GLXBadCurrentDrawable",
300 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
)
304 gc
= __glXGetCurrentContext();
305 if (dpy
== gc
->currentDpy
) {
306 __glXSetCurrentContext(&dummyContext
);
307 #ifdef GLX_DIRECT_RENDERING
308 _glapi_set_dispatch(NULL
); /* no-op functions */
310 __glXFreeContext(gc
);
313 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
317 static XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
318 __GLX_NUMBER_ERRORS
, error_list
)
320 static /* const */ XExtensionHooks __glXExtensionHooks
= {
321 NULL
, /* create_gc */
325 NULL
, /* create_font */
326 NULL
, /* free_font */
327 __glXCloseDisplay
, /* close_display */
328 NULL
, /* wire_to_event */
329 NULL
, /* event_to_wire */
331 __glXErrorString
, /* error_string */
335 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
336 __glXExtensionName
, &__glXExtensionHooks
,
337 __GLX_NUMBER_EVENTS
, NULL
)
339 /************************************************************************/
342 ** Free the per screen configs data as well as the array of
343 ** __glXScreenConfigs.
345 static void FreeScreenConfigs(__GLXdisplayPrivate
*priv
)
347 __GLXscreenConfigs
*psc
;
350 /* Free screen configuration information */
351 psc
= priv
->screenConfigs
;
352 screens
= ScreenCount(priv
->dpy
);
353 for (i
= 0; i
< screens
; i
++, psc
++) {
355 _gl_context_modes_destroy( psc
->configs
);
356 if(psc
->effectiveGLXexts
)
357 Xfree(psc
->effectiveGLXexts
);
359 psc
->configs
= NULL
; /* NOTE: just for paranoia */
361 Xfree((char*) psc
->serverGLXexts
);
363 #ifdef GLX_DIRECT_RENDERING
364 /* Free the direct rendering per screen data */
365 if (psc
->driScreen
.private)
366 (*psc
->driScreen
.destroyScreen
)(priv
->dpy
, i
,
367 psc
->driScreen
.private);
368 psc
->driScreen
.private = NULL
;
371 XFree((char*) priv
->screenConfigs
);
375 ** Release the private memory referred to in a display private
376 ** structure. The caller will free the extension structure.
378 static int __glXFreeDisplayPrivate(XExtData
*extension
)
380 __GLXdisplayPrivate
*priv
;
382 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
383 FreeScreenConfigs(priv
);
384 if(priv
->serverGLXvendor
) {
385 Xfree((char*)priv
->serverGLXvendor
);
386 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
388 if(priv
->serverGLXversion
) {
389 Xfree((char*)priv
->serverGLXversion
);
390 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
393 #ifdef GLX_DIRECT_RENDERING
394 /* Free the direct rendering per display data */
395 if (priv
->driDisplay
.private)
396 (*priv
->driDisplay
.destroyDisplay
)(priv
->dpy
,
397 priv
->driDisplay
.private);
398 priv
->driDisplay
.private = NULL
;
405 /************************************************************************/
408 ** Query the version of the GLX extension. This procedure works even if
409 ** the client extension is not completely set up.
411 static Bool
QueryVersion(Display
*dpy
, int opcode
, int *major
, int *minor
)
413 xGLXQueryVersionReq
*req
;
414 xGLXQueryVersionReply reply
;
416 /* Send the glXQueryVersion request */
418 GetReq(GLXQueryVersion
,req
);
419 req
->reqType
= opcode
;
420 req
->glxCode
= X_GLXQueryVersion
;
421 req
->majorVersion
= GLX_MAJOR_VERSION
;
422 req
->minorVersion
= GLX_MINOR_VERSION
;
423 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
427 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
429 ** The server does not support the same major release as this
434 *major
= reply
.majorVersion
;
435 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
441 __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
, int count
,
442 const INT32
*bp
, Bool tagged_only
,
443 Bool fbconfig_style_tags
)
448 /* Copy in the first set of properties */
449 config
->visualID
= *bp
++;
451 config
->visualType
= _gl_convert_from_x_visual_type( *bp
++ );
453 config
->rgbMode
= *bp
++;
455 config
->redBits
= *bp
++;
456 config
->greenBits
= *bp
++;
457 config
->blueBits
= *bp
++;
458 config
->alphaBits
= *bp
++;
459 config
->accumRedBits
= *bp
++;
460 config
->accumGreenBits
= *bp
++;
461 config
->accumBlueBits
= *bp
++;
462 config
->accumAlphaBits
= *bp
++;
464 config
->doubleBufferMode
= *bp
++;
465 config
->stereoMode
= *bp
++;
467 config
->rgbBits
= *bp
++;
468 config
->depthBits
= *bp
++;
469 config
->stencilBits
= *bp
++;
470 config
->numAuxBuffers
= *bp
++;
471 config
->level
= *bp
++;
473 count
-= __GLX_MIN_CONFIG_PROPS
;
477 ** Additional properties may be in a list at the end
478 ** of the reply. They are in pairs of property type
479 ** and property value.
482 #define FETCH_OR_SET(tag) \
483 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
485 for (i
= 0; i
< count
; i
+= 2 ) {
488 FETCH_OR_SET( rgbMode
);
490 case GLX_BUFFER_SIZE
:
491 config
->rgbBits
= *bp
++;
494 config
->level
= *bp
++;
496 case GLX_DOUBLEBUFFER
:
497 FETCH_OR_SET( doubleBufferMode
);
500 FETCH_OR_SET( stereoMode
);
502 case GLX_AUX_BUFFERS
:
503 config
->numAuxBuffers
= *bp
++;
506 config
->redBits
= *bp
++;
509 config
->greenBits
= *bp
++;
512 config
->blueBits
= *bp
++;
515 config
->alphaBits
= *bp
++;
518 config
->depthBits
= *bp
++;
520 case GLX_STENCIL_SIZE
:
521 config
->stencilBits
= *bp
++;
523 case GLX_ACCUM_RED_SIZE
:
524 config
->accumRedBits
= *bp
++;
526 case GLX_ACCUM_GREEN_SIZE
:
527 config
->accumGreenBits
= *bp
++;
529 case GLX_ACCUM_BLUE_SIZE
:
530 config
->accumBlueBits
= *bp
++;
532 case GLX_ACCUM_ALPHA_SIZE
:
533 config
->accumAlphaBits
= *bp
++;
535 case GLX_VISUAL_CAVEAT_EXT
:
536 config
->visualRating
= *bp
++;
538 case GLX_X_VISUAL_TYPE
:
539 config
->visualType
= *bp
++;
541 case GLX_TRANSPARENT_TYPE
:
542 config
->transparentPixel
= *bp
++;
544 case GLX_TRANSPARENT_INDEX_VALUE
:
545 config
->transparentIndex
= *bp
++;
547 case GLX_TRANSPARENT_RED_VALUE
:
548 config
->transparentRed
= *bp
++;
550 case GLX_TRANSPARENT_GREEN_VALUE
:
551 config
->transparentGreen
= *bp
++;
553 case GLX_TRANSPARENT_BLUE_VALUE
:
554 config
->transparentBlue
= *bp
++;
556 case GLX_TRANSPARENT_ALPHA_VALUE
:
557 config
->transparentAlpha
= *bp
++;
560 config
->visualID
= *bp
++;
562 case GLX_DRAWABLE_TYPE
:
563 config
->drawableType
= *bp
++;
565 case GLX_RENDER_TYPE
:
566 config
->renderType
= *bp
++;
568 case GLX_X_RENDERABLE
:
569 config
->xRenderable
= *bp
++;
571 case GLX_FBCONFIG_ID
:
572 config
->fbconfigID
= *bp
++;
574 case GLX_MAX_PBUFFER_WIDTH
:
575 config
->maxPbufferWidth
= *bp
++;
577 case GLX_MAX_PBUFFER_HEIGHT
:
578 config
->maxPbufferHeight
= *bp
++;
580 case GLX_MAX_PBUFFER_PIXELS
:
581 config
->maxPbufferPixels
= *bp
++;
583 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
584 config
->optimalPbufferWidth
= *bp
++;
586 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
587 config
->optimalPbufferHeight
= *bp
++;
589 case GLX_VISUAL_SELECT_GROUP_SGIX
:
590 config
->visualSelectGroup
= *bp
++;
592 case GLX_SWAP_METHOD_OML
:
593 config
->swapMethod
= *bp
++;
595 case GLX_SAMPLE_BUFFERS_SGIS
:
596 config
->sampleBuffers
= *bp
++;
598 case GLX_SAMPLES_SGIS
:
599 config
->samples
= *bp
++;
601 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
602 config
->bindToTextureRgb
= *bp
++;
604 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
605 config
->bindToTextureRgba
= *bp
++;
607 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
608 config
->bindToMipmapTexture
= *bp
++;
610 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
611 config
->bindToTextureTargets
= *bp
++;
613 case GLX_Y_INVERTED_EXT
:
614 config
->yInverted
= *bp
++;
624 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
626 config
->haveAccumBuffer
= ((config
->accumRedBits
+
627 config
->accumGreenBits
+
628 config
->accumBlueBits
+
629 config
->accumAlphaBits
) > 0);
630 config
->haveDepthBuffer
= (config
->depthBits
> 0);
631 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
635 #ifdef GLX_DIRECT_RENDERING
637 filter_modes( __GLcontextModes
** server_modes
,
638 const __GLcontextModes
* driver_modes
)
640 __GLcontextModes
* m
;
641 __GLcontextModes
** prev_next
;
642 const __GLcontextModes
* check
;
643 unsigned modes_count
= 0;
645 if ( driver_modes
== NULL
) {
646 fprintf(stderr
, "libGL warning: 3D driver returned no fbconfigs.\n");
650 /* For each mode in server_modes, check to see if a matching mode exists
651 * in driver_modes. If not, then the mode is not available.
654 prev_next
= server_modes
;
655 for ( m
= *prev_next
; m
!= NULL
; m
= *prev_next
) {
656 GLboolean do_delete
= GL_TRUE
;
658 for ( check
= driver_modes
; check
!= NULL
; check
= check
->next
) {
659 if ( _gl_context_modes_are_same( m
, check
) ) {
660 do_delete
= GL_FALSE
;
665 /* The 3D has to support all the modes that match the GLX visuals
666 * sent from the X server.
668 if ( do_delete
&& (m
->visualID
!= 0) ) {
669 do_delete
= GL_FALSE
;
671 fprintf(stderr
, "libGL warning: 3D driver claims to not support "
672 "visual 0x%02x\n", m
->visualID
);
676 *prev_next
= m
->next
;
679 _gl_context_modes_destroy( m
);
683 prev_next
= & m
->next
;
692 * Implement \c __DRIinterfaceMethods::getProcAddress.
694 static __DRIfuncPtr
get_proc_address( const char * proc_name
)
696 if (strcmp( proc_name
, "glxEnableExtension" ) == 0) {
697 return (__DRIfuncPtr
) __glXScrEnableExtension
;
703 #ifdef XDAMAGE_1_1_INTERFACE
704 static GLboolean
has_damage_post(__DRInativeDisplay
*dpy
)
706 static GLboolean inited
= GL_FALSE
;
707 static GLboolean has_damage
;
712 if (XDamageQueryVersion(dpy
, &major
, &minor
) &&
713 major
== 1 && minor
>= 1)
715 has_damage
= GL_TRUE
;
717 has_damage
= GL_FALSE
;
724 #endif /* XDAMAGE_1_1_INTERFACE */
726 static void __glXReportDamage(__DRInativeDisplay
*dpy
, int screen
,
729 drm_clip_rect_t
*rects
, int num_rects
,
730 GLboolean front_buffer
)
732 #ifdef XDAMAGE_1_1_INTERFACE
734 XserverRegion region
;
738 if (!has_damage_post(dpy
))
744 drawable
= RootWindow(dpy
, screen
);
750 xrects
= malloc(sizeof(XRectangle
) * num_rects
);
754 for (i
= 0; i
< num_rects
; i
++) {
755 xrects
[i
].x
= rects
[i
].x1
+ x_off
;
756 xrects
[i
].y
= rects
[i
].y1
+ y_off
;
757 xrects
[i
].width
= rects
[i
].x2
- rects
[i
].x1
;
758 xrects
[i
].height
= rects
[i
].y2
- rects
[i
].y1
;
760 region
= XFixesCreateRegion(dpy
, xrects
, num_rects
);
761 XDamageAdd(dpy
, drawable
, region
);
762 XFixesDestroyRegion(dpy
, region
);
767 * Table of functions exported by the loader to the driver.
769 static const __DRIinterfaceMethods interface_methods
= {
772 _gl_context_modes_create
,
773 _gl_context_modes_destroy
,
778 XF86DRICreateContextWithConfig
,
779 XF86DRIDestroyContext
,
781 XF86DRICreateDrawable
,
782 XF86DRIDestroyDrawable
,
783 XF86DRIGetDrawableInfo
,
794 * Perform the required libGL-side initialization and call the client-side
795 * driver's \c __driCreateNewScreen function.
797 * \param dpy Display pointer.
798 * \param scrn Screen number on the display.
799 * \param psc DRI screen information.
800 * \param driDpy DRI display information.
801 * \param createNewScreen Pointer to the client-side driver's
802 * \c __driCreateNewScreen function.
803 * \returns A pointer to the \c __DRIscreenPrivate structure returned by
804 * the client-side driver on success, or \c NULL on failure.
806 * \todo This function needs to be modified to remove context-modes from the
807 * list stored in the \c __GLXscreenConfigsRec to match the list
808 * returned by the client-side driver.
811 CallCreateNewScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
812 __DRIdisplay
* driDpy
,
813 PFNCREATENEWSCREENFUNC createNewScreen
)
815 __DRIscreenPrivate
*psp
= NULL
;
816 #ifndef GLX_USE_APPLEGL
818 drmAddress pSAREA
= MAP_FAILED
;
820 __DRIversion ddx_version
;
821 __DRIversion dri_version
;
822 __DRIversion drm_version
;
823 __DRIframebuffer framebuffer
;
826 const char * err_msg
;
827 const char * err_extra
;
828 int api_ver
= __glXGetInternalVersion();
831 dri_version
.major
= driDpy
->private->driMajor
;
832 dri_version
.minor
= driDpy
->private->driMinor
;
833 dri_version
.patch
= driDpy
->private->driPatch
;
836 err_msg
= "XF86DRIOpenConnection";
839 framebuffer
.base
= MAP_FAILED
;
840 framebuffer
.dev_priv
= NULL
;
842 if (XF86DRIOpenConnection(dpy
, scrn
, &hSAREA
, &BusID
)) {
844 fd
= drmOpenOnce(NULL
,BusID
, &newlyopened
);
845 Xfree(BusID
); /* No longer needed */
847 err_msg
= "open DRM";
848 err_extra
= strerror( -fd
);
853 err_msg
= "drmGetMagic";
856 if (!drmGetMagic(fd
, &magic
)) {
857 drmVersionPtr version
= drmGetVersion(fd
);
859 drm_version
.major
= version
->version_major
;
860 drm_version
.minor
= version
->version_minor
;
861 drm_version
.patch
= version
->version_patchlevel
;
862 drmFreeVersion(version
);
865 drm_version
.major
= -1;
866 drm_version
.minor
= -1;
867 drm_version
.patch
= -1;
870 err_msg
= "XF86DRIAuthConnection";
871 if (!newlyopened
|| XF86DRIAuthConnection(dpy
, scrn
, magic
)) {
875 * Get device name (like "tdfx") and the ddx version
876 * numbers. We'll check the version in each DRI driver's
877 * "createNewScreen" function.
879 err_msg
= "XF86DRIGetClientDriverName";
880 if (XF86DRIGetClientDriverName(dpy
, scrn
,
888 /* No longer needed. */
893 * Get device-specific info. pDevPriv will point to a struct
894 * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h)
895 * that has information about the screen size, depth, pitch,
896 * ancilliary buffers, DRM mmap handles, etc.
898 err_msg
= "XF86DRIGetDeviceInfo";
899 if (XF86DRIGetDeviceInfo(dpy
, scrn
,
904 &framebuffer
.dev_priv_size
,
905 &framebuffer
.dev_priv
)) {
906 framebuffer
.width
= DisplayWidth(dpy
, scrn
);
907 framebuffer
.height
= DisplayHeight(dpy
, scrn
);
910 * Map the framebuffer region.
912 status
= drmMap(fd
, hFB
, framebuffer
.size
,
913 (drmAddressPtr
)&framebuffer
.base
);
915 err_msg
= "drmMap of framebuffer";
916 err_extra
= strerror( -status
);
920 * Map the SAREA region. Further mmap regions
921 * may be setup in each DRI driver's
922 * "createNewScreen" function.
924 status
= drmMap(fd
, hSAREA
, SAREA_MAX
,
927 err_msg
= "drmMap of sarea";
928 err_extra
= strerror( -status
);
931 __GLcontextModes
* driver_modes
= NULL
;
932 __GLXscreenConfigs
*configs
= psc
->screenConfigs
;
934 err_msg
= "InitDriver";
936 psp
= (*createNewScreen
)(dpy
, scrn
,
949 filter_modes( & configs
->configs
,
951 _gl_context_modes_destroy( driver_modes
);
962 if ( pSAREA
!= MAP_FAILED
) {
963 (void)drmUnmap(pSAREA
, SAREA_MAX
);
966 if ( framebuffer
.base
!= MAP_FAILED
) {
967 (void)drmUnmap((drmAddress
)framebuffer
.base
, framebuffer
.size
);
970 if ( framebuffer
.dev_priv
!= NULL
) {
971 Xfree(framebuffer
.dev_priv
);
975 (void)drmCloseOnce(fd
);
978 (void)XF86DRICloseConnection(dpy
, scrn
);
980 if ( err_extra
!= NULL
) {
981 fprintf(stderr
, "libGL error: %s failed (%s)\n", err_msg
,
985 fprintf(stderr
, "libGL error: %s failed\n", err_msg
);
988 fprintf(stderr
, "libGL error: reverting to (slow) indirect rendering\n");
990 #endif /* !GLX_USE_APPLEGL */
994 #endif /* GLX_DIRECT_RENDERING */
998 ** Allocate the memory for the per screen configs for each screen.
999 ** If that works then fetch the per screen configs data.
1001 static Bool
AllocAndFetchScreenConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
)
1003 xGLXGetVisualConfigsReq
*req
;
1004 xGLXGetFBConfigsReq
*fb_req
;
1005 xGLXVendorPrivateWithReplyReq
*vpreq
;
1006 xGLXGetFBConfigsSGIXReq
*sgi_req
;
1007 xGLXGetVisualConfigsReply reply
;
1008 __GLXscreenConfigs
*psc
;
1009 __GLcontextModes
*config
;
1010 GLint i
, j
, nprops
, screens
;
1011 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
1012 unsigned supported_request
= 0;
1016 ** First allocate memory for the array of per screen configs.
1018 screens
= ScreenCount(dpy
);
1019 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
1023 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
1024 priv
->screenConfigs
= psc
;
1026 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1027 X_GLXQueryServerString
,
1029 if ( priv
->serverGLXversion
== NULL
) {
1030 FreeScreenConfigs(priv
);
1034 if ( atof( priv
->serverGLXversion
) >= 1.3 ) {
1035 supported_request
= 1;
1039 ** Now fetch each screens configs structures. If a screen supports
1040 ** GL (by returning a numVisuals > 0) then allocate memory for our
1041 ** config structure and then fill it in.
1043 for (i
= 0; i
< screens
; i
++, psc
++) {
1044 if ( supported_request
!= 1 ) {
1045 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1046 X_GLXQueryServerString
,
1048 if ( strstr( psc
->serverGLXexts
, "GLX_SGIX_fbconfig" ) != NULL
) {
1049 supported_request
= 2;
1052 supported_request
= 3;
1058 switch( supported_request
) {
1060 GetReq(GLXGetFBConfigs
,fb_req
);
1061 fb_req
->reqType
= priv
->majorOpcode
;
1062 fb_req
->glxCode
= X_GLXGetFBConfigs
;
1067 GetReqExtra(GLXVendorPrivateWithReply
,
1068 sz_xGLXGetFBConfigsSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1069 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
1070 sgi_req
->reqType
= priv
->majorOpcode
;
1071 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
1072 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
1073 sgi_req
->screen
= i
;
1077 GetReq(GLXGetVisualConfigs
,req
);
1078 req
->reqType
= priv
->majorOpcode
;
1079 req
->glxCode
= X_GLXGetVisualConfigs
;
1084 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
)) {
1085 /* Something is busted. Punt. */
1088 FreeScreenConfigs(priv
);
1092 if (!reply
.numVisuals
) {
1093 /* This screen does not support GL rendering */
1098 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for
1101 /* Check number of properties */
1102 nprops
= reply
.numProps
;
1103 if ((nprops
< __GLX_MIN_CONFIG_PROPS
) ||
1104 (nprops
> __GLX_MAX_CONFIG_PROPS
)) {
1105 /* Huh? Not in protocol defined limits. Punt */
1108 FreeScreenConfigs(priv
);
1112 /* Allocate memory for our config structure */
1113 psc
->configs
= _gl_context_modes_create(reply
.numVisuals
,
1114 sizeof(__GLcontextModes
));
1115 if (!psc
->configs
) {
1118 FreeScreenConfigs(priv
);
1122 /* Allocate memory for the properties, if needed */
1123 if ( supported_request
!= 3 ) {
1127 prop_size
= nprops
* __GLX_SIZE_INT32
;
1129 if (prop_size
<= sizeof(buf
)) {
1132 props
= (INT32
*) Xmalloc(prop_size
);
1135 /* Read each config structure and convert it into our format */
1136 config
= psc
->configs
;
1137 for (j
= 0; j
< reply
.numVisuals
; j
++) {
1138 assert( config
!= NULL
);
1139 _XRead(dpy
, (char *)props
, prop_size
);
1141 if ( supported_request
!= 3 ) {
1142 config
->rgbMode
= GL_TRUE
;
1143 config
->drawableType
= GLX_WINDOW_BIT
;
1146 config
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
1149 __glXInitializeVisualConfigFromTags( config
, nprops
, props
,
1150 (supported_request
!= 3),
1152 if ( config
->fbconfigID
== GLX_DONT_CARE
) {
1153 config
->fbconfigID
= config
->visualID
;
1156 config
= config
->next
;
1159 Xfree((char *)props
);
1163 #ifdef GLX_DIRECT_RENDERING
1164 /* Initialize per screen dynamic client GLX extensions */
1165 psc
->ext_list_first_time
= GL_TRUE
;
1166 /* Initialize the direct rendering per screen data and functions */
1167 if (priv
->driDisplay
.private != NULL
) {
1168 /* FIXME: Should it be some sort of an error if createNewScreen[i]
1171 if (priv
->driDisplay
.createNewScreen
&&
1172 priv
->driDisplay
.createNewScreen
[i
]) {
1174 psc
->driScreen
.screenConfigs
= (void *)psc
;
1175 psc
->driScreen
.private =
1176 CallCreateNewScreen(dpy
, i
, & psc
->driScreen
,
1178 priv
->driDisplay
.createNewScreen
[i
] );
1188 ** Initialize the client side extension code.
1190 __GLXdisplayPrivate
*__glXInitialize(Display
* dpy
)
1192 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1193 XExtData
**privList
, *private, *found
;
1194 __GLXdisplayPrivate
*dpyPriv
;
1195 XEDataObject dataObj
;
1198 #if defined(USE_XTHREADS)
1200 static int firstCall
= 1;
1202 /* initialize the GLX mutexes */
1203 xmutex_init(&__glXmutex
);
1210 /* The one and only long long lock */
1213 if (!XextHasExtension(info
)) {
1214 /* No GLX extension supported by this server. Oh well. */
1216 XMissingExtension(dpy
, __glXExtensionName
);
1220 /* See if a display private already exists. If so, return it */
1221 dataObj
.display
= dpy
;
1222 privList
= XEHeadOfExtensionList(dataObj
);
1223 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1226 return (__GLXdisplayPrivate
*) found
->private_data
;
1229 /* See if the versions are compatible */
1230 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
1231 /* The client and server do not agree on versions. Punt. */
1237 ** Allocate memory for all the pieces needed for this buffer.
1239 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
1244 dpyPriv
= (__GLXdisplayPrivate
*) Xmalloc(sizeof(__GLXdisplayPrivate
));
1247 Xfree((char*) private);
1252 ** Init the display private and then read in the screen config
1253 ** structures from the server.
1255 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
1256 dpyPriv
->majorVersion
= major
;
1257 dpyPriv
->minorVersion
= minor
;
1260 dpyPriv
->serverGLXvendor
= 0x0;
1261 dpyPriv
->serverGLXversion
= 0x0;
1263 #ifdef GLX_DIRECT_RENDERING
1265 ** Initialize the direct rendering per display data and functions.
1266 ** Note: This _must_ be done before calling any other DRI routines
1267 ** (e.g., those called in AllocAndFetchScreenConfigs).
1269 if (getenv("LIBGL_ALWAYS_INDIRECT")) {
1270 /* Assinging zero here assures we'll never go direct */
1271 dpyPriv
->driDisplay
.private = 0;
1272 dpyPriv
->driDisplay
.destroyDisplay
= 0;
1275 dpyPriv
->driDisplay
.private =
1276 driCreateDisplay(dpy
, &dpyPriv
->driDisplay
);
1280 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
1282 Xfree((char*) dpyPriv
);
1283 Xfree((char*) private);
1288 ** Fill in the private structure. This is the actual structure that
1289 ** hangs off of the Display structure. Our private structure is
1290 ** referred to by this structure. Got that?
1292 private->number
= info
->codes
->extension
;
1294 private->free_private
= __glXFreeDisplayPrivate
;
1295 private->private_data
= (char *) dpyPriv
;
1296 XAddToExtensionList(privList
, private);
1298 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
1299 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
1307 ** Setup for sending a GLX command on dpy. Make sure the extension is
1308 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
1310 CARD8
__glXSetupForCommand(Display
*dpy
)
1313 __GLXdisplayPrivate
*priv
;
1315 /* If this thread has a current context, flush its rendering commands */
1316 gc
= __glXGetCurrentContext();
1317 if (gc
->currentDpy
) {
1318 /* Flush rendering buffer of the current context, if any */
1319 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
1321 if (gc
->currentDpy
== dpy
) {
1322 /* Use opcode from gc because its right */
1324 return gc
->majorOpcode
;
1327 ** Have to get info about argument dpy because it might be to
1328 ** a different server
1333 /* Forced to lookup extension via the slow initialize route */
1334 priv
= __glXInitialize(dpy
);
1338 return priv
->majorOpcode
;
1342 * Flush the drawing command transport buffer.
1344 * \param ctx Context whose transport buffer is to be flushed.
1345 * \param pc Pointer to first unused buffer location.
1348 * Modify this function to use \c ctx->pc instead of the explicit
1351 GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*ctx
, GLubyte
*pc
)
1353 Display
* const dpy
= ctx
->currentDpy
;
1355 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1358 #endif /* USE_XCB */
1359 const GLint size
= pc
- ctx
->buf
;
1361 if ( (dpy
!= NULL
) && (size
> 0) ) {
1363 xcb_glx_render(c
, ctx
->currentContextTag
, size
, (char *)ctx
->buf
);
1365 /* Send the entire buffer as an X request */
1367 GetReq(GLXRender
,req
);
1368 req
->reqType
= ctx
->majorOpcode
;
1369 req
->glxCode
= X_GLXRender
;
1370 req
->contextTag
= ctx
->currentContextTag
;
1371 req
->length
+= (size
+ 3) >> 2;
1372 _XSend(dpy
, (char *)ctx
->buf
, size
);
1378 /* Reset pointer and return it */
1385 * Send a portion of a GLXRenderLarge command to the server. The advantage of
1386 * this function over \c __glXSendLargeCommand is that callers can use the
1387 * data buffer in the GLX context and may be able to avoid allocating an
1388 * extra buffer. The disadvantage is the clients will have to do more
1389 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
1391 * \sa __glXSendLargeCommand
1393 * \param gc GLX context
1394 * \param requestNumber Which part of the whole command is this? The first
1396 * \param totalRequests How many requests will there be?
1397 * \param data Command data.
1398 * \param dataLen Size, in bytes, of the command data.
1400 void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
1401 GLint totalRequests
,
1402 const GLvoid
* data
, GLint dataLen
)
1404 Display
*dpy
= gc
->currentDpy
;
1406 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1407 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
, totalRequests
, dataLen
, data
);
1409 xGLXRenderLargeReq
*req
;
1411 if ( requestNumber
== 1 ) {
1415 GetReq(GLXRenderLarge
,req
);
1416 req
->reqType
= gc
->majorOpcode
;
1417 req
->glxCode
= X_GLXRenderLarge
;
1418 req
->contextTag
= gc
->currentContextTag
;
1419 req
->length
+= (dataLen
+ 3) >> 2;
1420 req
->requestNumber
= requestNumber
;
1421 req
->requestTotal
= totalRequests
;
1422 req
->dataBytes
= dataLen
;
1423 Data(dpy
, data
, dataLen
);
1425 if ( requestNumber
== totalRequests
) {
1429 #endif /* USE_XCB */
1434 * Send a command that is too large for the GLXRender protocol request.
1436 * Send a large command, one that is too large for some reason to
1437 * send using the GLXRender protocol request. One reason to send
1438 * a large command is to avoid copying the data.
1440 * \param ctx GLX context
1441 * \param header Header data.
1442 * \param headerLen Size, in bytes, of the header data. It is assumed that
1443 * the header data will always be small enough to fit in
1444 * a single X protocol packet.
1445 * \param data Command data.
1446 * \param dataLen Size, in bytes, of the command data.
1448 void __glXSendLargeCommand(__GLXcontext
*ctx
,
1449 const GLvoid
*header
, GLint headerLen
,
1450 const GLvoid
*data
, GLint dataLen
)
1453 GLint totalRequests
, requestNumber
;
1456 ** Calculate the maximum amount of data can be stuffed into a single
1457 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1458 ** packet size minus sz_xGLXRenderReq.
1460 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1461 totalRequests
= 1 + (dataLen
/ maxSize
);
1462 if (dataLen
% maxSize
) totalRequests
++;
1465 ** Send all of the command, except the large array, as one request.
1467 assert( headerLen
<= maxSize
);
1468 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1471 ** Send enough requests until the whole array is sent.
1473 for ( requestNumber
= 2 ; requestNumber
<= (totalRequests
- 1) ; requestNumber
++ ) {
1474 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1475 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1477 assert( dataLen
> 0 );
1480 assert( dataLen
<= maxSize
);
1481 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1484 /************************************************************************/
1486 GLXContext
glXGetCurrentContext(void)
1488 GLXContext cx
= __glXGetCurrentContext();
1490 if (cx
== &dummyContext
) {
1497 GLXDrawable
glXGetCurrentDrawable(void)
1499 GLXContext gc
= __glXGetCurrentContext();
1500 return gc
->currentDrawable
;
1504 /************************************************************************/
1506 #ifdef GLX_DIRECT_RENDERING
1507 /* Return the DRI per screen structure */
1508 __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
)
1510 __DRIscreen
*pDRIScreen
= NULL
;
1511 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1512 XExtData
**privList
, *found
;
1513 __GLXdisplayPrivate
*dpyPriv
;
1514 XEDataObject dataObj
;
1517 dataObj
.display
= dpy
;
1518 privList
= XEHeadOfExtensionList(dataObj
);
1519 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1523 dpyPriv
= (__GLXdisplayPrivate
*)found
->private_data
;
1524 pDRIScreen
= &dpyPriv
->screenConfigs
[scrn
].driScreen
;
1531 /************************************************************************/
1533 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1534 GLXContextID gc
, GLXContextTag old_gc
, GLXDrawable draw
, GLXDrawable read
,
1535 xGLXMakeCurrentReply
* reply
);
1538 * Sends a GLX protocol message to the specified display to make the context
1539 * and the drawables current.
1541 * \param dpy Display to send the message to.
1542 * \param opcode Major opcode value for the display.
1543 * \param gc_id Context tag for the context to be made current.
1544 * \param draw Drawable ID for the "draw" drawable.
1545 * \param read Drawable ID for the "read" drawable.
1546 * \param reply Space to store the X-server's reply.
1549 * This function assumes that \c dpy is locked with \c LockDisplay on entry.
1551 static Bool
SendMakeCurrentRequest(Display
*dpy
, CARD8 opcode
,
1552 GLXContextID gc_id
, GLXContextTag gc_tag
,
1553 GLXDrawable draw
, GLXDrawable read
,
1554 xGLXMakeCurrentReply
*reply
)
1562 xGLXMakeCurrentReq
*req
;
1564 GetReq(GLXMakeCurrent
,req
);
1565 req
->reqType
= opcode
;
1566 req
->glxCode
= X_GLXMakeCurrent
;
1567 req
->drawable
= draw
;
1568 req
->context
= gc_id
;
1569 req
->oldContextTag
= gc_tag
;
1572 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1574 /* If the server can support the GLX 1.3 version, we should
1575 * perfer that. Not only that, some servers support GLX 1.3 but
1576 * not the SGI extension.
1579 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1580 xGLXMakeContextCurrentReq
*req
;
1582 GetReq(GLXMakeContextCurrent
,req
);
1583 req
->reqType
= opcode
;
1584 req
->glxCode
= X_GLXMakeContextCurrent
;
1585 req
->drawable
= draw
;
1586 req
->readdrawable
= read
;
1587 req
->context
= gc_id
;
1588 req
->oldContextTag
= gc_tag
;
1591 xGLXVendorPrivateWithReplyReq
*vpreq
;
1592 xGLXMakeCurrentReadSGIReq
*req
;
1594 GetReqExtra(GLXVendorPrivateWithReply
,
1595 sz_xGLXMakeCurrentReadSGIReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1596 req
= (xGLXMakeCurrentReadSGIReq
*)vpreq
;
1597 req
->reqType
= opcode
;
1598 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1599 req
->vendorCode
= X_GLXvop_MakeCurrentReadSGI
;
1600 req
->drawable
= draw
;
1601 req
->readable
= read
;
1602 req
->context
= gc_id
;
1603 req
->oldContextTag
= gc_tag
;
1607 ret
= _XReply(dpy
, (xReply
*) reply
, 0, False
);
1616 #ifdef GLX_DIRECT_RENDERING
1617 static Bool
BindContextWrapper( Display
*dpy
, GLXContext gc
,
1618 GLXDrawable draw
, GLXDrawable read
)
1620 return (*gc
->driContext
.bindContext
)(dpy
, gc
->screen
, draw
, read
,
1625 static Bool
UnbindContextWrapper( GLXContext gc
)
1627 return (*gc
->driContext
.unbindContext
)(gc
->currentDpy
, gc
->screen
,
1628 gc
->currentDrawable
,
1629 gc
->currentReadable
,
1632 #endif /* GLX_DIRECT_RENDERING */
1636 * Make a particular context current.
1638 * \note This is in this file so that it can access dummyContext.
1640 USED
static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
1641 GLXDrawable read
, GLXContext gc
)
1643 xGLXMakeCurrentReply reply
;
1644 const GLXContext oldGC
= __glXGetCurrentContext();
1645 const CARD8 opcode
= __glXSetupForCommand(dpy
);
1646 const CARD8 oldOpcode
= ((gc
== oldGC
) || (oldGC
== &dummyContext
))
1647 ? opcode
: __glXSetupForCommand(oldGC
->currentDpy
);
1648 Bool bindReturnValue
;
1651 if (!opcode
|| !oldOpcode
) {
1655 /* Make sure that the new context has a nonzero ID. In the request,
1656 * a zero context ID is used only to mean that we bind to no current
1659 if ((gc
!= NULL
) && (gc
->xid
== None
)) {
1663 #ifndef GLX_DIRECT_RENDERING
1664 if (gc
&& gc
->isDirect
) {
1669 _glapi_check_multithread();
1671 #ifdef GLX_DIRECT_RENDERING
1672 /* Bind the direct rendering context to the drawable */
1673 if (gc
&& gc
->isDirect
) {
1674 bindReturnValue
= (gc
->driContext
.private)
1675 ? BindContextWrapper(dpy
, gc
, draw
, read
)
1680 /* Send a glXMakeCurrent request to bind the new context. */
1682 SendMakeCurrentRequest(dpy
, opcode
, gc
? gc
->xid
: None
,
1683 ((dpy
!= oldGC
->currentDpy
) || oldGC
->isDirect
)
1684 ? None
: oldGC
->currentContextTag
,
1685 draw
, read
, &reply
);
1689 if (!bindReturnValue
) {
1693 if ((dpy
!= oldGC
->currentDpy
|| (gc
&& gc
->isDirect
)) &&
1694 !oldGC
->isDirect
&& oldGC
!= &dummyContext
) {
1695 xGLXMakeCurrentReply dummy_reply
;
1697 /* We are either switching from one dpy to another and have to
1698 * send a request to the previous dpy to unbind the previous
1699 * context, or we are switching away from a indirect context to
1700 * a direct context and have to send a request to the dpy to
1701 * unbind the previous context.
1703 (void) SendMakeCurrentRequest(oldGC
->currentDpy
, oldOpcode
, None
,
1704 oldGC
->currentContextTag
, None
, None
,
1707 #ifdef GLX_DIRECT_RENDERING
1708 else if (oldGC
->isDirect
&& oldGC
->driContext
.private) {
1709 (void) UnbindContextWrapper(oldGC
);
1714 /* Update our notion of what is current */
1717 /* Even though the contexts are the same the drawable might have
1718 * changed. Note that gc cannot be the dummy, and that oldGC
1719 * cannot be NULL, therefore if they are the same, gc is not
1720 * NULL and not the dummy.
1722 gc
->currentDrawable
= draw
;
1723 gc
->currentReadable
= read
;
1725 if (oldGC
!= &dummyContext
) {
1726 /* Old current context is no longer current to anybody */
1727 oldGC
->currentDpy
= 0;
1728 oldGC
->currentDrawable
= None
;
1729 oldGC
->currentReadable
= None
;
1730 oldGC
->currentContextTag
= 0;
1732 if (oldGC
->xid
== None
) {
1733 /* We are switching away from a context that was
1734 * previously destroyed, so we need to free the memory
1735 * for the old handle.
1737 #ifdef GLX_DIRECT_RENDERING
1738 /* Destroy the old direct rendering context */
1739 if (oldGC
->isDirect
) {
1740 if (oldGC
->driContext
.private) {
1741 (*oldGC
->driContext
.destroyContext
)
1742 (dpy
, oldGC
->screen
, oldGC
->driContext
.private);
1743 oldGC
->driContext
.private = NULL
;
1747 __glXFreeContext(oldGC
);
1751 __glXSetCurrentContext(gc
);
1753 gc
->currentDpy
= dpy
;
1754 gc
->currentDrawable
= draw
;
1755 gc
->currentReadable
= read
;
1757 if (!gc
->isDirect
) {
1759 IndirectAPI
= __glXNewIndirectAPI();
1760 _glapi_set_dispatch(IndirectAPI
);
1762 #ifdef GLX_USE_APPLEGL
1764 extern void XAppleDRIUseIndirectDispatch(void);
1765 XAppleDRIUseIndirectDispatch();
1769 __GLXattribute
*state
=
1770 (__GLXattribute
*)(gc
->client_state_private
);
1772 gc
->currentContextTag
= reply
.contextTag
;
1773 if (state
->array_state
== NULL
) {
1774 (void) glGetString(GL_EXTENSIONS
);
1775 (void) glGetString(GL_VERSION
);
1776 __glXInitVertexArrayState(gc
);
1780 gc
->currentContextTag
= -1;
1783 __glXSetCurrentContext(&dummyContext
);
1784 #ifdef GLX_DIRECT_RENDERING
1785 _glapi_set_dispatch(NULL
); /* no-op functions */
1794 PUBLIC Bool
glXMakeCurrent(Display
*dpy
, GLXDrawable draw
, GLXContext gc
)
1796 return MakeContextCurrent( dpy
, draw
, draw
, gc
);
1799 PUBLIC
GLX_ALIAS(Bool
, glXMakeCurrentReadSGI
,
1800 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1801 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1803 PUBLIC
GLX_ALIAS(Bool
, glXMakeContextCurrent
,
1804 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1805 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1809 void __glXDumpDrawBuffer(__GLXcontext
*ctx
)
1811 GLubyte
*p
= ctx
->buf
;
1812 GLubyte
*end
= ctx
->pc
;
1813 GLushort opcode
, length
;
1817 opcode
= *((GLushort
*) p
);
1818 length
= *((GLushort
*) (p
+ 2));
1819 printf("%2x: %5d: ", opcode
, length
);
1822 while (length
> 0) {
1823 printf("%08x ", *((unsigned *) p
));
1832 #ifdef USE_SPARC_ASM
1834 * Used only when we are sparc, using sparc assembler.
1839 _glx_mesa_init_sparc_glapi_relocs(void)
1841 unsigned int *insn_ptr
, *end_ptr
;
1842 unsigned long disp_addr
;
1844 insn_ptr
= &_mesa_sparc_glapi_begin
;
1845 end_ptr
= &_mesa_sparc_glapi_end
;
1846 disp_addr
= (unsigned long) &_glapi_Dispatch
;
1849 * Verbatim from Mesa sparc.c. It's needed because there doesn't
1850 * seem to be a better way to do this:
1852 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1854 * This code is patching in the ADDRESS of the pointer to the
1855 * dispatch table. Hence, it must be called exactly once, because
1856 * that address is not going to change.
1858 * What it points to can change, but Mesa (and hence, we) assume
1859 * that there is only one pointer.
1862 while (insn_ptr
< end_ptr
) {
1863 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1865 This code patches for 64-bit addresses. This had better
1866 not happen for Sparc/Linux, no matter what architecture we
1867 are building for. So, don't do this.
1869 The 'defined(__linux_64__)' is used here as a placeholder for
1870 when we do do 64-bit usermode on sparc linux.
1872 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1873 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1874 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1875 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1876 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1877 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1880 insn_ptr
[0] |= (disp_addr
>> 10);
1881 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1882 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1887 #endif /* sparc ASM in use */