1 /* $XFree86: xc/lib/GL/glx/glxext.c,v 1.22 2003/12/08 17:35:28 dawes Exp $ */
4 ** License Applicability. Except to the extent portions of this file are
5 ** made subject to an alternative license as permitted in the SGI Free
6 ** Software License B, Version 1.1 (the "License"), the contents of this
7 ** file are subject only to the provisions of the License. You may not use
8 ** this file except in compliance with the License. You may obtain a copy
9 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
10 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
12 ** http://oss.sgi.com/projects/FreeB
14 ** Note that, as provided in the License, the Software is distributed on an
15 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
16 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
17 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
18 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
20 ** Original Code. The Original Code is: OpenGL Sample Implementation,
21 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
22 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
23 ** Copyright in any portions created by third parties is as indicated
24 ** elsewhere herein. All Rights Reserved.
26 ** Additional Notice Provisions: The application programming interfaces
27 ** established by SGI in conjunction with the Original Code are The
28 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
29 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
30 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
31 ** Window System(R) (Version 1.3), released October 19, 1998. This software
32 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
33 ** published by SGI, but has not been independently verified as being
34 ** compliant with the OpenGL(R) version 1.2.1 Specification.
40 * GLX protocol interface boot-strap code.
42 * Direct rendering support added by Precision Insight, Inc.
44 * \author Kevin E. Martin <kevin@precisioninsight.com>
47 #include "glxclient.h"
49 #include <X11/extensions/Xext.h>
50 #include <X11/extensions/extutil.h>
52 #include "indirect_init.h"
54 #include "glxextensions.h"
55 #include "glcontextmodes.h"
58 #ifdef GLX_DIRECT_RENDERING
67 #include <X11/Xlib-xcb.h>
75 void __glXDumpDrawBuffer(__GLXcontext
*ctx
);
80 * This is where our dispatch table's bounds are.
81 * And the static mesa_init is taken directly from
82 * Mesa's 'sparc.c' initializer.
84 * We need something like this here, because this version
85 * of openGL/glx never initializes a Mesa context, and so
86 * the address of the dispatch table pointer never gets stuffed
87 * into the dispatch jump table otherwise.
89 * It matters only on SPARC, and only if you are using assembler
90 * code instead of C-code indirect dispatch.
94 extern unsigned int _mesa_sparc_glapi_begin
;
95 extern unsigned int _mesa_sparc_glapi_end
;
96 extern void __glapi_sparc_icache_flush(unsigned int *);
97 static void _glx_mesa_init_sparc_glapi_relocs(void);
98 static int _mesa_sparc_needs_init
= 1;
99 #define INIT_MESA_SPARC { \
100 if(_mesa_sparc_needs_init) { \
101 _glx_mesa_init_sparc_glapi_relocs(); \
102 _mesa_sparc_needs_init = 0; \
106 #define INIT_MESA_SPARC
109 #ifdef GLX_DIRECT_RENDERING
110 static __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
);
111 #endif /* GLX_DIRECT_RENDERING */
113 static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
114 GLXDrawable read
, GLXContext gc
);
117 ** We setup some dummy structures here so that the API can be used
118 ** even if no context is current.
121 static GLubyte dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
];
124 ** Dummy context used by small commands when there is no current context.
126 ** gl and glx entry points are designed to operate as nop's when using
127 ** the dummy context structure.
129 static __GLXcontext dummyContext
= {
133 &dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
],
139 ** All indirect rendering contexts will share the same indirect dispatch table.
141 static __GLapi
*IndirectAPI
= NULL
;
145 * Current context management and locking
148 #if defined( USE_XTHREADS )
151 static GLboolean TSDinitialized
= GL_FALSE
;
152 static xthread_key_t ContextTSD
;
154 __GLXcontext
*__glXGetCurrentContext(void)
156 if (!TSDinitialized
) {
157 xthread_key_create(&ContextTSD
, NULL
);
158 TSDinitialized
= GL_TRUE
;
159 return &dummyContext
;
163 xthread_get_specific(ContextTSD
, &p
);
165 return &dummyContext
;
167 return (__GLXcontext
*) p
;
171 void __glXSetCurrentContext(__GLXcontext
*c
)
173 if (!TSDinitialized
) {
174 xthread_key_create(&ContextTSD
, NULL
);
175 TSDinitialized
= GL_TRUE
;
177 xthread_set_specific(ContextTSD
, c
);
181 /* Used by the __glXLock() and __glXUnlock() macros */
182 xmutex_rec __glXmutex
;
184 #elif defined( PTHREADS )
186 pthread_mutex_t __glXmutex
= PTHREAD_MUTEX_INITIALIZER
;
188 # if defined( GLX_USE_TLS )
191 * Per-thread GLX context pointer.
193 * \c __glXSetCurrentContext is written is such a way that this pointer can
194 * \b never be \c NULL. This is important! Because of this
195 * \c __glXGetCurrentContext can be implemented as trivial macro.
197 __thread
void * __glX_tls_Context
__attribute__((tls_model("initial-exec")))
200 void __glXSetCurrentContext( __GLXcontext
* c
)
202 __glX_tls_Context
= (c
!= NULL
) ? c
: &dummyContext
;
207 static pthread_once_t once_control
= PTHREAD_ONCE_INIT
;
210 * Per-thread data key.
212 * Once \c init_thread_data has been called, the per-thread data key will
213 * take a value of \c NULL. As each new thread is created the default
214 * value, in that thread, will be \c NULL.
216 static pthread_key_t ContextTSD
;
219 * Initialize the per-thread data key.
221 * This function is called \b exactly once per-process (not per-thread!) to
222 * initialize the per-thread data key. This is ideally done using the
223 * \c pthread_once mechanism.
225 static void init_thread_data( void )
227 if ( pthread_key_create( & ContextTSD
, NULL
) != 0 ) {
228 perror( "pthread_key_create" );
233 void __glXSetCurrentContext( __GLXcontext
* c
)
235 pthread_once( & once_control
, init_thread_data
);
236 pthread_setspecific( ContextTSD
, c
);
239 __GLXcontext
* __glXGetCurrentContext( void )
243 pthread_once( & once_control
, init_thread_data
);
245 v
= pthread_getspecific( ContextTSD
);
246 return (v
== NULL
) ? & dummyContext
: (__GLXcontext
*) v
;
249 # endif /* defined( GLX_USE_TLS ) */
251 #elif defined( THREADS )
253 #error Unknown threading method specified.
257 /* not thread safe */
258 __GLXcontext
*__glXcurrentContext
= &dummyContext
;
264 ** You can set this cell to 1 to force the gl drawing stuff to be
265 ** one command per packet
270 ** forward prototype declarations
272 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
);
275 /************************************************************************/
277 /* Extension required boiler plate */
279 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
280 XExtensionInfo
*__glXExtensionInfo
= NULL
;
282 static /* const */ char *error_list
[] = {
284 "GLXBadContextState",
288 "GLXBadCurrentWindow",
289 "GLXBadRenderRequest",
290 "GLXBadLargeRequest",
291 "GLXUnsupportedPrivateRequest",
294 "GLXBadCurrentDrawable",
298 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
)
302 gc
= __glXGetCurrentContext();
303 if (dpy
== gc
->currentDpy
) {
304 __glXSetCurrentContext(&dummyContext
);
305 #ifdef GLX_DIRECT_RENDERING
306 _glapi_set_dispatch(NULL
); /* no-op functions */
308 __glXFreeContext(gc
);
311 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
315 static XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
316 __GLX_NUMBER_ERRORS
, error_list
)
318 static /* const */ XExtensionHooks __glXExtensionHooks
= {
319 NULL
, /* create_gc */
323 NULL
, /* create_font */
324 NULL
, /* free_font */
325 __glXCloseDisplay
, /* close_display */
326 NULL
, /* wire_to_event */
327 NULL
, /* event_to_wire */
329 __glXErrorString
, /* error_string */
333 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
334 __glXExtensionName
, &__glXExtensionHooks
,
335 __GLX_NUMBER_EVENTS
, NULL
)
337 /************************************************************************/
340 ** Free the per screen configs data as well as the array of
341 ** __glXScreenConfigs.
343 static void FreeScreenConfigs(__GLXdisplayPrivate
*priv
)
345 __GLXscreenConfigs
*psc
;
348 /* Free screen configuration information */
349 psc
= priv
->screenConfigs
;
350 screens
= ScreenCount(priv
->dpy
);
351 for (i
= 0; i
< screens
; i
++, psc
++) {
353 _gl_context_modes_destroy( psc
->configs
);
354 if(psc
->effectiveGLXexts
)
355 Xfree(psc
->effectiveGLXexts
);
357 psc
->configs
= NULL
; /* NOTE: just for paranoia */
359 Xfree((char*) psc
->serverGLXexts
);
361 #ifdef GLX_DIRECT_RENDERING
362 /* Free the direct rendering per screen data */
363 if (psc
->driScreen
.private)
364 (*psc
->driScreen
.destroyScreen
)(priv
->dpy
, i
,
365 psc
->driScreen
.private);
366 psc
->driScreen
.private = NULL
;
369 XFree((char*) priv
->screenConfigs
);
373 ** Release the private memory referred to in a display private
374 ** structure. The caller will free the extension structure.
376 static int __glXFreeDisplayPrivate(XExtData
*extension
)
378 __GLXdisplayPrivate
*priv
;
380 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
381 FreeScreenConfigs(priv
);
382 if(priv
->serverGLXvendor
) {
383 Xfree((char*)priv
->serverGLXvendor
);
384 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
386 if(priv
->serverGLXversion
) {
387 Xfree((char*)priv
->serverGLXversion
);
388 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
391 #ifdef GLX_DIRECT_RENDERING
392 /* Free the direct rendering per display data */
393 if (priv
->driDisplay
.private)
394 (*priv
->driDisplay
.destroyDisplay
)(priv
->dpy
,
395 priv
->driDisplay
.private);
396 priv
->driDisplay
.private = NULL
;
403 /************************************************************************/
406 ** Query the version of the GLX extension. This procedure works even if
407 ** the client extension is not completely set up.
409 static Bool
QueryVersion(Display
*dpy
, int opcode
, int *major
, int *minor
)
411 xGLXQueryVersionReq
*req
;
412 xGLXQueryVersionReply reply
;
414 /* Send the glXQueryVersion request */
416 GetReq(GLXQueryVersion
,req
);
417 req
->reqType
= opcode
;
418 req
->glxCode
= X_GLXQueryVersion
;
419 req
->majorVersion
= GLX_MAJOR_VERSION
;
420 req
->minorVersion
= GLX_MINOR_VERSION
;
421 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
425 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
427 ** The server does not support the same major release as this
432 *major
= reply
.majorVersion
;
433 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
439 __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
, int count
,
440 const INT32
*bp
, Bool tagged_only
,
441 Bool fbconfig_style_tags
)
446 /* Copy in the first set of properties */
447 config
->visualID
= *bp
++;
449 config
->visualType
= _gl_convert_from_x_visual_type( *bp
++ );
451 config
->rgbMode
= *bp
++;
453 config
->redBits
= *bp
++;
454 config
->greenBits
= *bp
++;
455 config
->blueBits
= *bp
++;
456 config
->alphaBits
= *bp
++;
457 config
->accumRedBits
= *bp
++;
458 config
->accumGreenBits
= *bp
++;
459 config
->accumBlueBits
= *bp
++;
460 config
->accumAlphaBits
= *bp
++;
462 config
->doubleBufferMode
= *bp
++;
463 config
->stereoMode
= *bp
++;
465 config
->rgbBits
= *bp
++;
466 config
->depthBits
= *bp
++;
467 config
->stencilBits
= *bp
++;
468 config
->numAuxBuffers
= *bp
++;
469 config
->level
= *bp
++;
471 count
-= __GLX_MIN_CONFIG_PROPS
;
475 ** Additional properties may be in a list at the end
476 ** of the reply. They are in pairs of property type
477 ** and property value.
480 #define FETCH_OR_SET(tag) \
481 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
483 for (i
= 0; i
< count
; i
+= 2 ) {
486 FETCH_OR_SET( rgbMode
);
488 case GLX_BUFFER_SIZE
:
489 config
->rgbBits
= *bp
++;
492 config
->level
= *bp
++;
494 case GLX_DOUBLEBUFFER
:
495 FETCH_OR_SET( doubleBufferMode
);
498 FETCH_OR_SET( stereoMode
);
500 case GLX_AUX_BUFFERS
:
501 config
->numAuxBuffers
= *bp
++;
504 config
->redBits
= *bp
++;
507 config
->greenBits
= *bp
++;
510 config
->blueBits
= *bp
++;
513 config
->alphaBits
= *bp
++;
516 config
->depthBits
= *bp
++;
518 case GLX_STENCIL_SIZE
:
519 config
->stencilBits
= *bp
++;
521 case GLX_ACCUM_RED_SIZE
:
522 config
->accumRedBits
= *bp
++;
524 case GLX_ACCUM_GREEN_SIZE
:
525 config
->accumGreenBits
= *bp
++;
527 case GLX_ACCUM_BLUE_SIZE
:
528 config
->accumBlueBits
= *bp
++;
530 case GLX_ACCUM_ALPHA_SIZE
:
531 config
->accumAlphaBits
= *bp
++;
533 case GLX_VISUAL_CAVEAT_EXT
:
534 config
->visualRating
= *bp
++;
536 case GLX_X_VISUAL_TYPE
:
537 config
->visualType
= *bp
++;
539 case GLX_TRANSPARENT_TYPE
:
540 config
->transparentPixel
= *bp
++;
542 case GLX_TRANSPARENT_INDEX_VALUE
:
543 config
->transparentIndex
= *bp
++;
545 case GLX_TRANSPARENT_RED_VALUE
:
546 config
->transparentRed
= *bp
++;
548 case GLX_TRANSPARENT_GREEN_VALUE
:
549 config
->transparentGreen
= *bp
++;
551 case GLX_TRANSPARENT_BLUE_VALUE
:
552 config
->transparentBlue
= *bp
++;
554 case GLX_TRANSPARENT_ALPHA_VALUE
:
555 config
->transparentAlpha
= *bp
++;
558 config
->visualID
= *bp
++;
560 case GLX_DRAWABLE_TYPE
:
561 config
->drawableType
= *bp
++;
563 case GLX_RENDER_TYPE
:
564 config
->renderType
= *bp
++;
566 case GLX_X_RENDERABLE
:
567 config
->xRenderable
= *bp
++;
569 case GLX_FBCONFIG_ID
:
570 config
->fbconfigID
= *bp
++;
572 case GLX_MAX_PBUFFER_WIDTH
:
573 config
->maxPbufferWidth
= *bp
++;
575 case GLX_MAX_PBUFFER_HEIGHT
:
576 config
->maxPbufferHeight
= *bp
++;
578 case GLX_MAX_PBUFFER_PIXELS
:
579 config
->maxPbufferPixels
= *bp
++;
581 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
582 config
->optimalPbufferWidth
= *bp
++;
584 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
585 config
->optimalPbufferHeight
= *bp
++;
587 case GLX_VISUAL_SELECT_GROUP_SGIX
:
588 config
->visualSelectGroup
= *bp
++;
590 case GLX_SWAP_METHOD_OML
:
591 config
->swapMethod
= *bp
++;
593 case GLX_SAMPLE_BUFFERS_SGIS
:
594 config
->sampleBuffers
= *bp
++;
596 case GLX_SAMPLES_SGIS
:
597 config
->samples
= *bp
++;
599 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
600 config
->bindToTextureRgb
= *bp
++;
602 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
603 config
->bindToTextureRgba
= *bp
++;
605 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
606 config
->bindToMipmapTexture
= *bp
++;
608 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
609 config
->bindToTextureTargets
= *bp
++;
611 case GLX_Y_INVERTED_EXT
:
612 config
->yInverted
= *bp
++;
622 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
624 config
->haveAccumBuffer
= ((config
->accumRedBits
+
625 config
->accumGreenBits
+
626 config
->accumBlueBits
+
627 config
->accumAlphaBits
) > 0);
628 config
->haveDepthBuffer
= (config
->depthBits
> 0);
629 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
633 #ifdef GLX_DIRECT_RENDERING
635 filter_modes( __GLcontextModes
** server_modes
,
636 const __GLcontextModes
* driver_modes
)
638 __GLcontextModes
* m
;
639 __GLcontextModes
** prev_next
;
640 const __GLcontextModes
* check
;
641 unsigned modes_count
= 0;
643 if ( driver_modes
== NULL
) {
644 fprintf(stderr
, "libGL warning: 3D driver returned no fbconfigs.\n");
648 /* For each mode in server_modes, check to see if a matching mode exists
649 * in driver_modes. If not, then the mode is not available.
652 prev_next
= server_modes
;
653 for ( m
= *prev_next
; m
!= NULL
; m
= *prev_next
) {
654 GLboolean do_delete
= GL_TRUE
;
656 for ( check
= driver_modes
; check
!= NULL
; check
= check
->next
) {
657 if ( _gl_context_modes_are_same( m
, check
) ) {
658 do_delete
= GL_FALSE
;
663 /* The 3D has to support all the modes that match the GLX visuals
664 * sent from the X server.
666 if ( do_delete
&& (m
->visualID
!= 0) ) {
667 do_delete
= GL_FALSE
;
669 fprintf(stderr
, "libGL warning: 3D driver claims to not support "
670 "visual 0x%02x\n", m
->visualID
);
674 *prev_next
= m
->next
;
677 _gl_context_modes_destroy( m
);
681 prev_next
= & m
->next
;
690 * Implement \c __DRIinterfaceMethods::getProcAddress.
692 static __DRIfuncPtr
get_proc_address( const char * proc_name
)
694 if (strcmp( proc_name
, "glxEnableExtension" ) == 0) {
695 return (__DRIfuncPtr
) __glXScrEnableExtension
;
703 * Table of functions exported by the loader to the driver.
705 static const __DRIinterfaceMethods interface_methods
= {
708 _gl_context_modes_create
,
709 _gl_context_modes_destroy
,
714 XF86DRICreateContextWithConfig
,
715 XF86DRIDestroyContext
,
717 XF86DRICreateDrawable
,
718 XF86DRIDestroyDrawable
,
719 XF86DRIGetDrawableInfo
,
727 * Perform the required libGL-side initialization and call the client-side
728 * driver's \c __driCreateNewScreen function.
730 * \param dpy Display pointer.
731 * \param scrn Screen number on the display.
732 * \param psc DRI screen information.
733 * \param driDpy DRI display information.
734 * \param createNewScreen Pointer to the client-side driver's
735 * \c __driCreateNewScreen function.
736 * \returns A pointer to the \c __DRIscreenPrivate structure returned by
737 * the client-side driver on success, or \c NULL on failure.
739 * \todo This function needs to be modified to remove context-modes from the
740 * list stored in the \c __GLXscreenConfigsRec to match the list
741 * returned by the client-side driver.
744 CallCreateNewScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
745 __DRIdisplay
* driDpy
,
746 PFNCREATENEWSCREENFUNC createNewScreen
)
748 __DRIscreenPrivate
*psp
= NULL
;
749 #ifndef GLX_USE_APPLEGL
751 drmAddress pSAREA
= MAP_FAILED
;
753 __DRIversion ddx_version
;
754 __DRIversion dri_version
;
755 __DRIversion drm_version
;
756 __DRIframebuffer framebuffer
;
759 const char * err_msg
;
760 const char * err_extra
;
761 int api_ver
= __glXGetInternalVersion();
764 dri_version
.major
= driDpy
->private->driMajor
;
765 dri_version
.minor
= driDpy
->private->driMinor
;
766 dri_version
.patch
= driDpy
->private->driPatch
;
769 err_msg
= "XF86DRIOpenConnection";
772 framebuffer
.base
= MAP_FAILED
;
773 framebuffer
.dev_priv
= NULL
;
775 if (XF86DRIOpenConnection(dpy
, scrn
, &hSAREA
, &BusID
)) {
776 fd
= drmOpen(NULL
,BusID
);
777 Xfree(BusID
); /* No longer needed */
779 err_msg
= "open DRM";
780 err_extra
= strerror( -fd
);
785 err_msg
= "drmGetMagic";
788 if (!drmGetMagic(fd
, &magic
)) {
789 drmVersionPtr version
= drmGetVersion(fd
);
791 drm_version
.major
= version
->version_major
;
792 drm_version
.minor
= version
->version_minor
;
793 drm_version
.patch
= version
->version_patchlevel
;
794 drmFreeVersion(version
);
797 drm_version
.major
= -1;
798 drm_version
.minor
= -1;
799 drm_version
.patch
= -1;
802 err_msg
= "XF86DRIAuthConnection";
803 if (XF86DRIAuthConnection(dpy
, scrn
, magic
)) {
807 * Get device name (like "tdfx") and the ddx version
808 * numbers. We'll check the version in each DRI driver's
809 * "createNewScreen" function.
811 err_msg
= "XF86DRIGetClientDriverName";
812 if (XF86DRIGetClientDriverName(dpy
, scrn
,
820 /* No longer needed. */
825 * Get device-specific info. pDevPriv will point to a struct
826 * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h)
827 * that has information about the screen size, depth, pitch,
828 * ancilliary buffers, DRM mmap handles, etc.
830 err_msg
= "XF86DRIGetDeviceInfo";
831 if (XF86DRIGetDeviceInfo(dpy
, scrn
,
836 &framebuffer
.dev_priv_size
,
837 &framebuffer
.dev_priv
)) {
838 framebuffer
.width
= DisplayWidth(dpy
, scrn
);
839 framebuffer
.height
= DisplayHeight(dpy
, scrn
);
842 * Map the framebuffer region.
844 status
= drmMap(fd
, hFB
, framebuffer
.size
,
845 (drmAddressPtr
)&framebuffer
.base
);
847 err_msg
= "drmMap of framebuffer";
848 err_extra
= strerror( -status
);
852 * Map the SAREA region. Further mmap regions
853 * may be setup in each DRI driver's
854 * "createNewScreen" function.
856 status
= drmMap(fd
, hSAREA
, SAREA_MAX
,
859 err_msg
= "drmMap of sarea";
860 err_extra
= strerror( -status
);
863 __GLcontextModes
* driver_modes
= NULL
;
864 __GLXscreenConfigs
*configs
= psc
->screenConfigs
;
866 err_msg
= "InitDriver";
868 psp
= (*createNewScreen
)(dpy
, scrn
,
881 filter_modes( & configs
->configs
,
883 _gl_context_modes_destroy( driver_modes
);
894 if ( pSAREA
!= MAP_FAILED
) {
895 (void)drmUnmap(pSAREA
, SAREA_MAX
);
898 if ( framebuffer
.base
!= MAP_FAILED
) {
899 (void)drmUnmap((drmAddress
)framebuffer
.base
, framebuffer
.size
);
902 if ( framebuffer
.dev_priv
!= NULL
) {
903 Xfree(framebuffer
.dev_priv
);
910 (void)XF86DRICloseConnection(dpy
, scrn
);
912 if ( err_extra
!= NULL
) {
913 fprintf(stderr
, "libGL error: %s failed (%s)\n", err_msg
,
917 fprintf(stderr
, "libGL error: %s failed\n", err_msg
);
920 fprintf(stderr
, "libGL error: reverting to (slow) indirect rendering\n");
922 #endif /* !GLX_USE_APPLEGL */
926 #endif /* GLX_DIRECT_RENDERING */
930 ** Allocate the memory for the per screen configs for each screen.
931 ** If that works then fetch the per screen configs data.
933 static Bool
AllocAndFetchScreenConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
)
935 xGLXGetVisualConfigsReq
*req
;
936 xGLXGetFBConfigsReq
*fb_req
;
937 xGLXVendorPrivateWithReplyReq
*vpreq
;
938 xGLXGetFBConfigsSGIXReq
*sgi_req
;
939 xGLXGetVisualConfigsReply reply
;
940 __GLXscreenConfigs
*psc
;
941 __GLcontextModes
*config
;
942 GLint i
, j
, nprops
, screens
;
943 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
944 unsigned supported_request
= 0;
948 ** First allocate memory for the array of per screen configs.
950 screens
= ScreenCount(dpy
);
951 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
955 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
956 priv
->screenConfigs
= psc
;
958 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
959 X_GLXQueryServerString
,
961 if ( priv
->serverGLXversion
== NULL
) {
962 FreeScreenConfigs(priv
);
966 if ( atof( priv
->serverGLXversion
) >= 1.3 ) {
967 supported_request
= 1;
971 ** Now fetch each screens configs structures. If a screen supports
972 ** GL (by returning a numVisuals > 0) then allocate memory for our
973 ** config structure and then fill it in.
975 for (i
= 0; i
< screens
; i
++, psc
++) {
976 if ( supported_request
!= 1 ) {
977 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
978 X_GLXQueryServerString
,
980 if ( strstr( psc
->serverGLXexts
, "GLX_SGIX_fbconfig" ) != NULL
) {
981 supported_request
= 2;
984 supported_request
= 3;
990 switch( supported_request
) {
992 GetReq(GLXGetFBConfigs
,fb_req
);
993 fb_req
->reqType
= priv
->majorOpcode
;
994 fb_req
->glxCode
= X_GLXGetFBConfigs
;
999 GetReqExtra(GLXVendorPrivateWithReply
,
1000 sz_xGLXGetFBConfigsSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1001 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
1002 sgi_req
->reqType
= priv
->majorOpcode
;
1003 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
1004 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
1005 sgi_req
->screen
= i
;
1009 GetReq(GLXGetVisualConfigs
,req
);
1010 req
->reqType
= priv
->majorOpcode
;
1011 req
->glxCode
= X_GLXGetVisualConfigs
;
1016 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
)) {
1017 /* Something is busted. Punt. */
1019 FreeScreenConfigs(priv
);
1024 if (!reply
.numVisuals
) {
1025 /* This screen does not support GL rendering */
1030 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for
1033 /* Check number of properties */
1034 nprops
= reply
.numProps
;
1035 if ((nprops
< __GLX_MIN_CONFIG_PROPS
) ||
1036 (nprops
> __GLX_MAX_CONFIG_PROPS
)) {
1037 /* Huh? Not in protocol defined limits. Punt */
1040 FreeScreenConfigs(priv
);
1044 /* Allocate memory for our config structure */
1045 psc
->configs
= _gl_context_modes_create(reply
.numVisuals
,
1046 sizeof(__GLcontextModes
));
1047 if (!psc
->configs
) {
1050 FreeScreenConfigs(priv
);
1054 /* Allocate memory for the properties, if needed */
1055 if ( supported_request
!= 3 ) {
1059 prop_size
= nprops
* __GLX_SIZE_INT32
;
1061 if (prop_size
<= sizeof(buf
)) {
1064 props
= (INT32
*) Xmalloc(prop_size
);
1067 /* Read each config structure and convert it into our format */
1068 config
= psc
->configs
;
1069 for (j
= 0; j
< reply
.numVisuals
; j
++) {
1070 assert( config
!= NULL
);
1071 _XRead(dpy
, (char *)props
, prop_size
);
1073 if ( supported_request
!= 3 ) {
1074 config
->rgbMode
= GL_TRUE
;
1075 config
->drawableType
= GLX_WINDOW_BIT
;
1078 config
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
1081 __glXInitializeVisualConfigFromTags( config
, nprops
, props
,
1082 (supported_request
!= 3),
1084 if ( config
->fbconfigID
== GLX_DONT_CARE
) {
1085 config
->fbconfigID
= config
->visualID
;
1088 config
= config
->next
;
1091 Xfree((char *)props
);
1095 #ifdef GLX_DIRECT_RENDERING
1096 /* Initialize per screen dynamic client GLX extensions */
1097 psc
->ext_list_first_time
= GL_TRUE
;
1098 /* Initialize the direct rendering per screen data and functions */
1099 if (priv
->driDisplay
.private != NULL
) {
1100 /* FIXME: Should it be some sort of an error if createNewScreen[i]
1103 if (priv
->driDisplay
.createNewScreen
&&
1104 priv
->driDisplay
.createNewScreen
[i
]) {
1106 psc
->driScreen
.screenConfigs
= (void *)psc
;
1107 psc
->driScreen
.private =
1108 CallCreateNewScreen(dpy
, i
, & psc
->driScreen
,
1110 priv
->driDisplay
.createNewScreen
[i
] );
1120 ** Initialize the client side extension code.
1122 __GLXdisplayPrivate
*__glXInitialize(Display
* dpy
)
1124 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1125 XExtData
**privList
, *private, *found
;
1126 __GLXdisplayPrivate
*dpyPriv
;
1127 XEDataObject dataObj
;
1130 #if defined(USE_XTHREADS)
1132 static int firstCall
= 1;
1134 /* initialize the GLX mutexes */
1135 xmutex_init(&__glXmutex
);
1142 /* The one and only long long lock */
1145 if (!XextHasExtension(info
)) {
1146 /* No GLX extension supported by this server. Oh well. */
1148 XMissingExtension(dpy
, __glXExtensionName
);
1152 /* See if a display private already exists. If so, return it */
1153 dataObj
.display
= dpy
;
1154 privList
= XEHeadOfExtensionList(dataObj
);
1155 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1158 return (__GLXdisplayPrivate
*) found
->private_data
;
1161 /* See if the versions are compatible */
1162 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
1163 /* The client and server do not agree on versions. Punt. */
1169 ** Allocate memory for all the pieces needed for this buffer.
1171 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
1176 dpyPriv
= (__GLXdisplayPrivate
*) Xmalloc(sizeof(__GLXdisplayPrivate
));
1179 Xfree((char*) private);
1184 ** Init the display private and then read in the screen config
1185 ** structures from the server.
1187 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
1188 dpyPriv
->majorVersion
= major
;
1189 dpyPriv
->minorVersion
= minor
;
1192 dpyPriv
->serverGLXvendor
= 0x0;
1193 dpyPriv
->serverGLXversion
= 0x0;
1195 #ifdef GLX_DIRECT_RENDERING
1197 ** Initialize the direct rendering per display data and functions.
1198 ** Note: This _must_ be done before calling any other DRI routines
1199 ** (e.g., those called in AllocAndFetchScreenConfigs).
1201 if (getenv("LIBGL_ALWAYS_INDIRECT")) {
1202 /* Assinging zero here assures we'll never go direct */
1203 dpyPriv
->driDisplay
.private = 0;
1204 dpyPriv
->driDisplay
.destroyDisplay
= 0;
1207 dpyPriv
->driDisplay
.private =
1208 driCreateDisplay(dpy
, &dpyPriv
->driDisplay
);
1212 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
1214 Xfree((char*) dpyPriv
);
1215 Xfree((char*) private);
1220 ** Fill in the private structure. This is the actual structure that
1221 ** hangs off of the Display structure. Our private structure is
1222 ** referred to by this structure. Got that?
1224 private->number
= info
->codes
->extension
;
1226 private->free_private
= __glXFreeDisplayPrivate
;
1227 private->private_data
= (char *) dpyPriv
;
1228 XAddToExtensionList(privList
, private);
1230 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
1231 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
1239 ** Setup for sending a GLX command on dpy. Make sure the extension is
1240 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
1242 CARD8
__glXSetupForCommand(Display
*dpy
)
1245 __GLXdisplayPrivate
*priv
;
1247 /* If this thread has a current context, flush its rendering commands */
1248 gc
= __glXGetCurrentContext();
1249 if (gc
->currentDpy
) {
1250 /* Flush rendering buffer of the current context, if any */
1251 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
1253 if (gc
->currentDpy
== dpy
) {
1254 /* Use opcode from gc because its right */
1256 return gc
->majorOpcode
;
1259 ** Have to get info about argument dpy because it might be to
1260 ** a different server
1265 /* Forced to lookup extension via the slow initialize route */
1266 priv
= __glXInitialize(dpy
);
1270 return priv
->majorOpcode
;
1274 * Flush the drawing command transport buffer.
1276 * \param ctx Context whose transport buffer is to be flushed.
1277 * \param pc Pointer to first unused buffer location.
1280 * Modify this function to use \c ctx->pc instead of the explicit
1283 GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*ctx
, GLubyte
*pc
)
1285 Display
* const dpy
= ctx
->currentDpy
;
1287 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1290 #endif /* USE_XCB */
1291 const GLint size
= pc
- ctx
->buf
;
1293 if ( (dpy
!= NULL
) && (size
> 0) ) {
1295 xcb_glx_render(c
, ctx
->currentContextTag
, size
, (char *)ctx
->buf
);
1297 /* Send the entire buffer as an X request */
1299 GetReq(GLXRender
,req
);
1300 req
->reqType
= ctx
->majorOpcode
;
1301 req
->glxCode
= X_GLXRender
;
1302 req
->contextTag
= ctx
->currentContextTag
;
1303 req
->length
+= (size
+ 3) >> 2;
1304 _XSend(dpy
, (char *)ctx
->buf
, size
);
1310 /* Reset pointer and return it */
1317 * Send a portion of a GLXRenderLarge command to the server. The advantage of
1318 * this function over \c __glXSendLargeCommand is that callers can use the
1319 * data buffer in the GLX context and may be able to avoid allocating an
1320 * extra buffer. The disadvantage is the clients will have to do more
1321 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
1323 * \sa __glXSendLargeCommand
1325 * \param gc GLX context
1326 * \param requestNumber Which part of the whole command is this? The first
1328 * \param totalRequests How many requests will there be?
1329 * \param data Command data.
1330 * \param dataLen Size, in bytes, of the command data.
1332 void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
1333 GLint totalRequests
,
1334 const GLvoid
* data
, GLint dataLen
)
1336 Display
*dpy
= gc
->currentDpy
;
1338 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1339 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
, totalRequests
, dataLen
, data
);
1341 xGLXRenderLargeReq
*req
;
1343 if ( requestNumber
== 1 ) {
1347 GetReq(GLXRenderLarge
,req
);
1348 req
->reqType
= gc
->majorOpcode
;
1349 req
->glxCode
= X_GLXRenderLarge
;
1350 req
->contextTag
= gc
->currentContextTag
;
1351 req
->length
+= (dataLen
+ 3) >> 2;
1352 req
->requestNumber
= requestNumber
;
1353 req
->requestTotal
= totalRequests
;
1354 req
->dataBytes
= dataLen
;
1355 Data(dpy
, data
, dataLen
);
1357 if ( requestNumber
== totalRequests
) {
1361 #endif /* USE_XCB */
1366 * Send a command that is too large for the GLXRender protocol request.
1368 * Send a large command, one that is too large for some reason to
1369 * send using the GLXRender protocol request. One reason to send
1370 * a large command is to avoid copying the data.
1372 * \param ctx GLX context
1373 * \param header Header data.
1374 * \param headerLen Size, in bytes, of the header data. It is assumed that
1375 * the header data will always be small enough to fit in
1376 * a single X protocol packet.
1377 * \param data Command data.
1378 * \param dataLen Size, in bytes, of the command data.
1380 void __glXSendLargeCommand(__GLXcontext
*ctx
,
1381 const GLvoid
*header
, GLint headerLen
,
1382 const GLvoid
*data
, GLint dataLen
)
1385 GLint totalRequests
, requestNumber
;
1388 ** Calculate the maximum amount of data can be stuffed into a single
1389 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1390 ** packet size minus sz_xGLXRenderReq.
1392 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1393 totalRequests
= 1 + (dataLen
/ maxSize
);
1394 if (dataLen
% maxSize
) totalRequests
++;
1397 ** Send all of the command, except the large array, as one request.
1399 assert( headerLen
<= maxSize
);
1400 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1403 ** Send enough requests until the whole array is sent.
1405 for ( requestNumber
= 2 ; requestNumber
<= (totalRequests
- 1) ; requestNumber
++ ) {
1406 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1407 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1409 assert( dataLen
> 0 );
1412 assert( dataLen
<= maxSize
);
1413 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1416 /************************************************************************/
1418 GLXContext
glXGetCurrentContext(void)
1420 GLXContext cx
= __glXGetCurrentContext();
1422 if (cx
== &dummyContext
) {
1429 GLXDrawable
glXGetCurrentDrawable(void)
1431 GLXContext gc
= __glXGetCurrentContext();
1432 return gc
->currentDrawable
;
1436 /************************************************************************/
1438 #ifdef GLX_DIRECT_RENDERING
1439 /* Return the DRI per screen structure */
1440 __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
)
1442 __DRIscreen
*pDRIScreen
= NULL
;
1443 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1444 XExtData
**privList
, *found
;
1445 __GLXdisplayPrivate
*dpyPriv
;
1446 XEDataObject dataObj
;
1449 dataObj
.display
= dpy
;
1450 privList
= XEHeadOfExtensionList(dataObj
);
1451 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1455 dpyPriv
= (__GLXdisplayPrivate
*)found
->private_data
;
1456 pDRIScreen
= &dpyPriv
->screenConfigs
[scrn
].driScreen
;
1463 /************************************************************************/
1465 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1466 GLXContextID gc
, GLXContextTag old_gc
, GLXDrawable draw
, GLXDrawable read
,
1467 xGLXMakeCurrentReply
* reply
);
1470 * Sends a GLX protocol message to the specified display to make the context
1471 * and the drawables current.
1473 * \param dpy Display to send the message to.
1474 * \param opcode Major opcode value for the display.
1475 * \param gc_id Context tag for the context to be made current.
1476 * \param draw Drawable ID for the "draw" drawable.
1477 * \param read Drawable ID for the "read" drawable.
1478 * \param reply Space to store the X-server's reply.
1481 * This function assumes that \c dpy is locked with \c LockDisplay on entry.
1483 static Bool
SendMakeCurrentRequest(Display
*dpy
, CARD8 opcode
,
1484 GLXContextID gc_id
, GLXContextTag gc_tag
,
1485 GLXDrawable draw
, GLXDrawable read
,
1486 xGLXMakeCurrentReply
*reply
)
1494 xGLXMakeCurrentReq
*req
;
1496 GetReq(GLXMakeCurrent
,req
);
1497 req
->reqType
= opcode
;
1498 req
->glxCode
= X_GLXMakeCurrent
;
1499 req
->drawable
= draw
;
1500 req
->context
= gc_id
;
1501 req
->oldContextTag
= gc_tag
;
1504 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1506 /* If the server can support the GLX 1.3 version, we should
1507 * perfer that. Not only that, some servers support GLX 1.3 but
1508 * not the SGI extension.
1511 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1512 xGLXMakeContextCurrentReq
*req
;
1514 GetReq(GLXMakeContextCurrent
,req
);
1515 req
->reqType
= opcode
;
1516 req
->glxCode
= X_GLXMakeContextCurrent
;
1517 req
->drawable
= draw
;
1518 req
->readdrawable
= read
;
1519 req
->context
= gc_id
;
1520 req
->oldContextTag
= gc_tag
;
1523 xGLXVendorPrivateWithReplyReq
*vpreq
;
1524 xGLXMakeCurrentReadSGIReq
*req
;
1526 GetReqExtra(GLXVendorPrivateWithReply
,
1527 sz_xGLXMakeCurrentReadSGIReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1528 req
= (xGLXMakeCurrentReadSGIReq
*)vpreq
;
1529 req
->reqType
= opcode
;
1530 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1531 req
->vendorCode
= X_GLXvop_MakeCurrentReadSGI
;
1532 req
->drawable
= draw
;
1533 req
->readable
= read
;
1534 req
->context
= gc_id
;
1535 req
->oldContextTag
= gc_tag
;
1539 ret
= _XReply(dpy
, (xReply
*) reply
, 0, False
);
1548 #ifdef GLX_DIRECT_RENDERING
1549 static Bool
BindContextWrapper( Display
*dpy
, GLXContext gc
,
1550 GLXDrawable draw
, GLXDrawable read
)
1552 return (*gc
->driContext
.bindContext
)(dpy
, gc
->screen
, draw
, read
,
1557 static Bool
UnbindContextWrapper( GLXContext gc
)
1559 return (*gc
->driContext
.unbindContext
)(gc
->currentDpy
, gc
->screen
,
1560 gc
->currentDrawable
,
1561 gc
->currentReadable
,
1564 #endif /* GLX_DIRECT_RENDERING */
1568 * Make a particular context current.
1570 * \note This is in this file so that it can access dummyContext.
1572 USED
static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
1573 GLXDrawable read
, GLXContext gc
)
1575 xGLXMakeCurrentReply reply
;
1576 const GLXContext oldGC
= __glXGetCurrentContext();
1577 const CARD8 opcode
= __glXSetupForCommand(dpy
);
1578 const CARD8 oldOpcode
= ((gc
== oldGC
) || (oldGC
== &dummyContext
))
1579 ? opcode
: __glXSetupForCommand(oldGC
->currentDpy
);
1580 Bool bindReturnValue
;
1583 if (!opcode
|| !oldOpcode
) {
1587 /* Make sure that the new context has a nonzero ID. In the request,
1588 * a zero context ID is used only to mean that we bind to no current
1591 if ((gc
!= NULL
) && (gc
->xid
== None
)) {
1595 #ifndef GLX_DIRECT_RENDERING
1596 if (gc
&& gc
->isDirect
) {
1601 _glapi_check_multithread();
1603 #ifdef GLX_DIRECT_RENDERING
1604 /* Bind the direct rendering context to the drawable */
1605 if (gc
&& gc
->isDirect
) {
1606 bindReturnValue
= (gc
->driContext
.private)
1607 ? BindContextWrapper(dpy
, gc
, draw
, read
)
1612 /* Send a glXMakeCurrent request to bind the new context. */
1614 SendMakeCurrentRequest(dpy
, opcode
, gc
? gc
->xid
: None
,
1615 (dpy
!= oldGC
->currentDpy
)
1616 ? None
: oldGC
->currentContextTag
,
1617 draw
, read
, &reply
);
1621 if (!bindReturnValue
) {
1625 if ((dpy
!= oldGC
->currentDpy
|| (gc
&& gc
->isDirect
)) &&
1626 !oldGC
->isDirect
&& oldGC
!= &dummyContext
) {
1627 xGLXMakeCurrentReply dummy_reply
;
1629 /* We are either switching from one dpy to another and have to
1630 * send a request to the previous dpy to unbind the previous
1631 * context, or we are switching away from a indirect context to
1632 * a direct context and have to send a request to the dpy to
1633 * unbind the previous context.
1635 (void) SendMakeCurrentRequest(oldGC
->currentDpy
, oldOpcode
, None
,
1636 oldGC
->currentContextTag
, None
, None
,
1639 #ifdef GLX_DIRECT_RENDERING
1640 else if (oldGC
->isDirect
&& oldGC
->driContext
.private) {
1641 (void) UnbindContextWrapper(oldGC
);
1646 /* Update our notion of what is current */
1649 /* Even though the contexts are the same the drawable might have
1650 * changed. Note that gc cannot be the dummy, and that oldGC
1651 * cannot be NULL, therefore if they are the same, gc is not
1652 * NULL and not the dummy.
1654 gc
->currentDrawable
= draw
;
1655 gc
->currentReadable
= read
;
1657 if (oldGC
!= &dummyContext
) {
1658 /* Old current context is no longer current to anybody */
1659 oldGC
->currentDpy
= 0;
1660 oldGC
->currentDrawable
= None
;
1661 oldGC
->currentReadable
= None
;
1662 oldGC
->currentContextTag
= 0;
1664 if (oldGC
->xid
== None
) {
1665 /* We are switching away from a context that was
1666 * previously destroyed, so we need to free the memory
1667 * for the old handle.
1669 #ifdef GLX_DIRECT_RENDERING
1670 /* Destroy the old direct rendering context */
1671 if (oldGC
->isDirect
) {
1672 if (oldGC
->driContext
.private) {
1673 (*oldGC
->driContext
.destroyContext
)
1674 (dpy
, oldGC
->screen
, oldGC
->driContext
.private);
1675 oldGC
->driContext
.private = NULL
;
1679 __glXFreeContext(oldGC
);
1683 __glXSetCurrentContext(gc
);
1685 gc
->currentDpy
= dpy
;
1686 gc
->currentDrawable
= draw
;
1687 gc
->currentReadable
= read
;
1689 if (!gc
->isDirect
) {
1691 IndirectAPI
= __glXNewIndirectAPI();
1692 _glapi_set_dispatch(IndirectAPI
);
1694 #ifdef GLX_USE_APPLEGL
1696 extern void XAppleDRIUseIndirectDispatch(void);
1697 XAppleDRIUseIndirectDispatch();
1701 __GLXattribute
*state
=
1702 (__GLXattribute
*)(gc
->client_state_private
);
1704 gc
->currentContextTag
= reply
.contextTag
;
1705 if (state
->array_state
== NULL
) {
1706 (void) glGetString(GL_EXTENSIONS
);
1707 (void) glGetString(GL_VERSION
);
1708 __glXInitVertexArrayState(gc
);
1712 gc
->currentContextTag
= -1;
1715 __glXSetCurrentContext(&dummyContext
);
1716 #ifdef GLX_DIRECT_RENDERING
1717 _glapi_set_dispatch(NULL
); /* no-op functions */
1726 PUBLIC Bool
glXMakeCurrent(Display
*dpy
, GLXDrawable draw
, GLXContext gc
)
1728 return MakeContextCurrent( dpy
, draw
, draw
, gc
);
1731 PUBLIC
GLX_ALIAS(Bool
, glXMakeCurrentReadSGI
,
1732 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1733 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1735 PUBLIC
GLX_ALIAS(Bool
, glXMakeContextCurrent
,
1736 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1737 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1741 void __glXDumpDrawBuffer(__GLXcontext
*ctx
)
1743 GLubyte
*p
= ctx
->buf
;
1744 GLubyte
*end
= ctx
->pc
;
1745 GLushort opcode
, length
;
1749 opcode
= *((GLushort
*) p
);
1750 length
= *((GLushort
*) (p
+ 2));
1751 printf("%2x: %5d: ", opcode
, length
);
1754 while (length
> 0) {
1755 printf("%08x ", *((unsigned *) p
));
1764 #ifdef USE_SPARC_ASM
1766 * Used only when we are sparc, using sparc assembler.
1771 _glx_mesa_init_sparc_glapi_relocs(void)
1773 unsigned int *insn_ptr
, *end_ptr
;
1774 unsigned long disp_addr
;
1776 insn_ptr
= &_mesa_sparc_glapi_begin
;
1777 end_ptr
= &_mesa_sparc_glapi_end
;
1778 disp_addr
= (unsigned long) &_glapi_Dispatch
;
1781 * Verbatim from Mesa sparc.c. It's needed because there doesn't
1782 * seem to be a better way to do this:
1784 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1786 * This code is patching in the ADDRESS of the pointer to the
1787 * dispatch table. Hence, it must be called exactly once, because
1788 * that address is not going to change.
1790 * What it points to can change, but Mesa (and hence, we) assume
1791 * that there is only one pointer.
1794 while (insn_ptr
< end_ptr
) {
1795 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1797 This code patches for 64-bit addresses. This had better
1798 not happen for Sparc/Linux, no matter what architecture we
1799 are building for. So, don't do this.
1801 The 'defined(__linux_64__)' is used here as a placeholder for
1802 when we do do 64-bit usermode on sparc linux.
1804 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1805 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1806 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1807 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1808 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1809 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1812 insn_ptr
[0] |= (disp_addr
>> 10);
1813 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1814 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1819 #endif /* sparc ASM in use */