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"
54 #include "glxextensions.h"
55 #include "glcontextmodes.h"
58 #ifdef GLX_DIRECT_RENDERING
68 #include <X11/XCB/xcb.h>
69 #include <X11/XCB/glx.h>
75 void __glXDumpDrawBuffer(__GLXcontext
*ctx
);
80 * This is where our dispatch table's bounds are.
81 * And the static mesa_init is taken directly from
82 * Mesa's 'sparc.c' initializer.
84 * We need something like this here, because this version
85 * of openGL/glx never initializes a Mesa context, and so
86 * the address of the dispatch table pointer never gets stuffed
87 * into the dispatch jump table otherwise.
89 * It matters only on SPARC, and only if you are using assembler
90 * code instead of C-code indirect dispatch.
94 extern unsigned int _mesa_sparc_glapi_begin
;
95 extern unsigned int _mesa_sparc_glapi_end
;
96 extern void __glapi_sparc_icache_flush(unsigned int *);
97 static void _glx_mesa_init_sparc_glapi_relocs(void);
98 static int _mesa_sparc_needs_init
= 1;
99 #define INIT_MESA_SPARC { \
100 if(_mesa_sparc_needs_init) { \
101 _glx_mesa_init_sparc_glapi_relocs(); \
102 _mesa_sparc_needs_init = 0; \
106 #define INIT_MESA_SPARC
109 #ifdef GLX_DIRECT_RENDERING
110 static __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
);
111 #endif /* GLX_DIRECT_RENDERING */
113 static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
114 GLXDrawable read
, GLXContext gc
);
117 ** We setup some dummy structures here so that the API can be used
118 ** even if no context is current.
121 static GLubyte dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
];
124 ** Dummy context used by small commands when there is no current context.
126 ** gl and glx entry points are designed to operate as nop's when using
127 ** the dummy context structure.
129 static __GLXcontext dummyContext
= {
133 &dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
],
139 ** All indirect rendering contexts will share the same indirect dispatch table.
141 static __GLapi
*IndirectAPI
= NULL
;
145 * Current context management and locking
148 #if defined( USE_XTHREADS )
151 static GLboolean TSDinitialized
= GL_FALSE
;
152 static xthread_key_t ContextTSD
;
154 __GLXcontext
*__glXGetCurrentContext(void)
156 if (!TSDinitialized
) {
157 xthread_key_create(&ContextTSD
, NULL
);
158 TSDinitialized
= GL_TRUE
;
159 return &dummyContext
;
163 xthread_get_specific(ContextTSD
, &p
);
165 return &dummyContext
;
167 return (__GLXcontext
*) p
;
171 void __glXSetCurrentContext(__GLXcontext
*c
)
173 if (!TSDinitialized
) {
174 xthread_key_create(&ContextTSD
, NULL
);
175 TSDinitialized
= GL_TRUE
;
177 xthread_set_specific(ContextTSD
, c
);
181 /* Used by the __glXLock() and __glXUnlock() macros */
182 xmutex_rec __glXmutex
;
184 #elif defined( PTHREADS )
186 pthread_mutex_t __glXmutex
= PTHREAD_MUTEX_INITIALIZER
;
188 # if defined( GLX_USE_TLS )
191 * Per-thread GLX context pointer.
193 * \c __glXSetCurrentContext is written is such a way that this pointer can
194 * \b never be \c NULL. This is important! Because of this
195 * \c __glXGetCurrentContext can be implemented as trivial macro.
197 __thread
void * __glX_tls_Context
__attribute__((tls_model("initial-exec")))
200 void __glXSetCurrentContext( __GLXcontext
* c
)
202 __glX_tls_Context
= (c
!= NULL
) ? c
: &dummyContext
;
207 static pthread_once_t once_control
= PTHREAD_ONCE_INIT
;
210 * Per-thread data key.
212 * Once \c init_thread_data has been called, the per-thread data key will
213 * take a value of \c NULL. As each new thread is created the default
214 * value, in that thread, will be \c NULL.
216 static pthread_key_t ContextTSD
;
219 * Initialize the per-thread data key.
221 * This function is called \b exactly once per-process (not per-thread!) to
222 * initialize the per-thread data key. This is ideally done using the
223 * \c pthread_once mechanism.
225 static void init_thread_data( void )
227 if ( pthread_key_create( & ContextTSD
, NULL
) != 0 ) {
228 perror( "pthread_key_create" );
233 void __glXSetCurrentContext( __GLXcontext
* c
)
235 pthread_once( & once_control
, init_thread_data
);
236 pthread_setspecific( ContextTSD
, c
);
239 __GLXcontext
* __glXGetCurrentContext( void )
243 pthread_once( & once_control
, init_thread_data
);
245 v
= pthread_getspecific( ContextTSD
);
246 return (v
== NULL
) ? & dummyContext
: (__GLXcontext
*) v
;
249 # endif /* defined( GLX_USE_TLS ) */
251 #elif defined( THREADS )
253 #error Unknown threading method specified.
257 /* not thread safe */
258 __GLXcontext
*__glXcurrentContext
= &dummyContext
;
264 ** You can set this cell to 1 to force the gl drawing stuff to be
265 ** one command per packet
270 ** forward prototype declarations
272 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
);
275 /************************************************************************/
277 /* Extension required boiler plate */
279 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
280 XExtensionInfo
*__glXExtensionInfo
= NULL
;
282 static /* const */ char *error_list
[] = {
284 "GLXBadContextState",
288 "GLXBadCurrentWindow",
289 "GLXBadRenderRequest",
290 "GLXBadLargeRequest",
291 "GLXUnsupportedPrivateRequest",
294 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
)
298 gc
= __glXGetCurrentContext();
299 if (dpy
== gc
->currentDpy
) {
300 __glXSetCurrentContext(&dummyContext
);
301 #ifdef GLX_DIRECT_RENDERING
302 _glapi_set_dispatch(NULL
); /* no-op functions */
304 __glXFreeContext(gc
);
307 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
311 static XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
312 __GLX_NUMBER_ERRORS
, error_list
)
314 static /* const */ XExtensionHooks __glXExtensionHooks
= {
315 NULL
, /* create_gc */
319 NULL
, /* create_font */
320 NULL
, /* free_font */
321 __glXCloseDisplay
, /* close_display */
322 NULL
, /* wire_to_event */
323 NULL
, /* event_to_wire */
325 __glXErrorString
, /* error_string */
329 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
330 __glXExtensionName
, &__glXExtensionHooks
,
331 __GLX_NUMBER_EVENTS
, NULL
)
333 /************************************************************************/
336 ** Free the per screen configs data as well as the array of
337 ** __glXScreenConfigs.
339 static void FreeScreenConfigs(__GLXdisplayPrivate
*priv
)
341 __GLXscreenConfigs
*psc
;
344 /* Free screen configuration information */
345 psc
= priv
->screenConfigs
;
346 screens
= ScreenCount(priv
->dpy
);
347 for (i
= 0; i
< screens
; i
++, psc
++) {
349 _gl_context_modes_destroy( psc
->configs
);
350 if(psc
->effectiveGLXexts
)
351 Xfree(psc
->effectiveGLXexts
);
353 psc
->configs
= NULL
; /* NOTE: just for paranoia */
356 #ifdef GLX_DIRECT_RENDERING
357 /* Free the direct rendering per screen data */
358 if (psc
->driScreen
.private)
359 (*psc
->driScreen
.destroyScreen
)(priv
->dpy
, i
,
360 psc
->driScreen
.private);
361 psc
->driScreen
.private = NULL
;
364 XFree((char*) priv
->screenConfigs
);
368 ** Release the private memory referred to in a display private
369 ** structure. The caller will free the extension structure.
371 static int __glXFreeDisplayPrivate(XExtData
*extension
)
373 __GLXdisplayPrivate
*priv
;
375 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
376 FreeScreenConfigs(priv
);
377 if(priv
->serverGLXvendor
) {
378 Xfree((char*)priv
->serverGLXvendor
);
379 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
381 if(priv
->serverGLXversion
) {
382 Xfree((char*)priv
->serverGLXversion
);
383 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
386 #if 0 /* GLX_DIRECT_RENDERING */
387 /* Free the direct rendering per display data */
388 if (priv
->driDisplay
.private)
389 (*priv
->driDisplay
.destroyDisplay
)(priv
->dpy
,
390 priv
->driDisplay
.private);
391 priv
->driDisplay
.private = NULL
;
398 /************************************************************************/
401 ** Query the version of the GLX extension. This procedure works even if
402 ** the client extension is not completely set up.
404 static Bool
QueryVersion(Display
*dpy
, int opcode
, int *major
, int *minor
)
406 xGLXQueryVersionReq
*req
;
407 xGLXQueryVersionReply reply
;
409 /* Send the glXQueryVersion request */
411 GetReq(GLXQueryVersion
,req
);
412 req
->reqType
= opcode
;
413 req
->glxCode
= X_GLXQueryVersion
;
414 req
->majorVersion
= GLX_MAJOR_VERSION
;
415 req
->minorVersion
= GLX_MINOR_VERSION
;
416 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
420 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
422 ** The server does not support the same major release as this
427 *major
= reply
.majorVersion
;
428 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
434 __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
, int count
,
435 const INT32
*bp
, Bool tagged_only
,
436 Bool fbconfig_style_tags
)
441 /* Copy in the first set of properties */
442 config
->visualID
= *bp
++;
444 config
->visualType
= _gl_convert_from_x_visual_type( *bp
++ );
446 config
->rgbMode
= *bp
++;
448 config
->redBits
= *bp
++;
449 config
->greenBits
= *bp
++;
450 config
->blueBits
= *bp
++;
451 config
->alphaBits
= *bp
++;
452 config
->accumRedBits
= *bp
++;
453 config
->accumGreenBits
= *bp
++;
454 config
->accumBlueBits
= *bp
++;
455 config
->accumAlphaBits
= *bp
++;
457 config
->doubleBufferMode
= *bp
++;
458 config
->stereoMode
= *bp
++;
460 config
->rgbBits
= *bp
++;
461 config
->depthBits
= *bp
++;
462 config
->stencilBits
= *bp
++;
463 config
->numAuxBuffers
= *bp
++;
464 config
->level
= *bp
++;
466 count
-= __GLX_MIN_CONFIG_PROPS
;
470 ** Additional properties may be in a list at the end
471 ** of the reply. They are in pairs of property type
472 ** and property value.
475 #define FETCH_OR_SET(tag) \
476 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
478 for (i
= 0; i
< count
; i
+= 2 ) {
481 FETCH_OR_SET( rgbMode
);
483 case GLX_BUFFER_SIZE
:
484 config
->rgbBits
= *bp
++;
487 config
->level
= *bp
++;
489 case GLX_DOUBLEBUFFER
:
490 FETCH_OR_SET( doubleBufferMode
);
493 FETCH_OR_SET( stereoMode
);
495 case GLX_AUX_BUFFERS
:
496 config
->numAuxBuffers
= *bp
++;
499 config
->redBits
= *bp
++;
502 config
->greenBits
= *bp
++;
505 config
->blueBits
= *bp
++;
508 config
->alphaBits
= *bp
++;
511 config
->depthBits
= *bp
++;
513 case GLX_STENCIL_SIZE
:
514 config
->stencilBits
= *bp
++;
516 case GLX_ACCUM_RED_SIZE
:
517 config
->accumRedBits
= *bp
++;
519 case GLX_ACCUM_GREEN_SIZE
:
520 config
->accumGreenBits
= *bp
++;
522 case GLX_ACCUM_BLUE_SIZE
:
523 config
->accumBlueBits
= *bp
++;
525 case GLX_ACCUM_ALPHA_SIZE
:
526 config
->accumAlphaBits
= *bp
++;
528 case GLX_VISUAL_CAVEAT_EXT
:
529 config
->visualRating
= *bp
++;
531 case GLX_X_VISUAL_TYPE
:
532 config
->visualType
= *bp
++;
534 case GLX_TRANSPARENT_TYPE
:
535 config
->transparentPixel
= *bp
++;
537 case GLX_TRANSPARENT_INDEX_VALUE
:
538 config
->transparentIndex
= *bp
++;
540 case GLX_TRANSPARENT_RED_VALUE
:
541 config
->transparentRed
= *bp
++;
543 case GLX_TRANSPARENT_GREEN_VALUE
:
544 config
->transparentGreen
= *bp
++;
546 case GLX_TRANSPARENT_BLUE_VALUE
:
547 config
->transparentBlue
= *bp
++;
549 case GLX_TRANSPARENT_ALPHA_VALUE
:
550 config
->transparentAlpha
= *bp
++;
553 config
->visualID
= *bp
++;
555 case GLX_DRAWABLE_TYPE
:
556 config
->drawableType
= *bp
++;
558 case GLX_RENDER_TYPE
:
559 config
->renderType
= *bp
++;
561 case GLX_X_RENDERABLE
:
562 config
->xRenderable
= *bp
++;
564 case GLX_FBCONFIG_ID
:
565 config
->fbconfigID
= *bp
++;
567 case GLX_MAX_PBUFFER_WIDTH
:
568 config
->maxPbufferWidth
= *bp
++;
570 case GLX_MAX_PBUFFER_HEIGHT
:
571 config
->maxPbufferHeight
= *bp
++;
573 case GLX_MAX_PBUFFER_PIXELS
:
574 config
->maxPbufferPixels
= *bp
++;
576 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
577 config
->optimalPbufferWidth
= *bp
++;
579 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
580 config
->optimalPbufferHeight
= *bp
++;
582 case GLX_VISUAL_SELECT_GROUP_SGIX
:
583 config
->visualSelectGroup
= *bp
++;
585 case GLX_SWAP_METHOD_OML
:
586 config
->swapMethod
= *bp
++;
588 case GLX_SAMPLE_BUFFERS_SGIS
:
589 config
->sampleBuffers
= *bp
++;
591 case GLX_SAMPLES_SGIS
:
592 config
->samples
= *bp
++;
602 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
604 config
->haveAccumBuffer
= ((config
->accumRedBits
+
605 config
->accumGreenBits
+
606 config
->accumBlueBits
+
607 config
->accumAlphaBits
) > 0);
608 config
->haveDepthBuffer
= (config
->depthBits
> 0);
609 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
613 #ifdef GLX_DIRECT_RENDERING
615 filter_modes( __GLcontextModes
** server_modes
,
616 const __GLcontextModes
* driver_modes
)
618 __GLcontextModes
* m
;
619 __GLcontextModes
** prev_next
;
620 const __GLcontextModes
* check
;
621 unsigned modes_count
= 0;
623 if ( driver_modes
== NULL
) {
624 fprintf(stderr
, "libGL warning: 3D driver returned no fbconfigs.\n");
628 /* For each mode in server_modes, check to see if a matching mode exists
629 * in driver_modes. If not, then the mode is not available.
632 prev_next
= server_modes
;
633 for ( m
= *prev_next
; m
!= NULL
; m
= *prev_next
) {
634 GLboolean do_delete
= GL_TRUE
;
636 for ( check
= driver_modes
; check
!= NULL
; check
= check
->next
) {
637 if ( _gl_context_modes_are_same( m
, check
) ) {
638 do_delete
= GL_FALSE
;
643 /* The 3D has to support all the modes that match the GLX visuals
644 * sent from the X server.
646 if ( do_delete
&& (m
->visualID
!= 0) ) {
647 do_delete
= GL_FALSE
;
649 fprintf(stderr
, "libGL warning: 3D driver claims to not support "
650 "visual 0x%02x\n", m
->visualID
);
654 *prev_next
= m
->next
;
657 _gl_context_modes_destroy( m
);
661 prev_next
= & m
->next
;
670 * Implement \c __DRIinterfaceMethods::getProcAddress.
672 static __DRIfuncPtr
get_proc_address( const char * proc_name
)
674 if (strcmp( proc_name
, "glxEnableExtension" ) == 0) {
675 return (__DRIfuncPtr
) __glXScrEnableExtension
;
683 * Table of functions exported by the loader to the driver.
685 static const __DRIinterfaceMethods interface_methods
= {
688 _gl_context_modes_create
,
689 _gl_context_modes_destroy
,
694 XF86DRICreateContextWithConfig
,
695 XF86DRIDestroyContext
,
697 XF86DRICreateDrawable
,
698 XF86DRIDestroyDrawable
,
699 XF86DRIGetDrawableInfo
,
707 * Perform the required libGL-side initialization and call the client-side
708 * driver's \c __driCreateNewScreen function.
710 * \param dpy Display pointer.
711 * \param scrn Screen number on the display.
712 * \param psc DRI screen information.
713 * \param driDpy DRI display information.
714 * \param createNewScreen Pointer to the client-side driver's
715 * \c __driCreateNewScreen function.
716 * \returns A pointer to the \c __DRIscreenPrivate structure returned by
717 * the client-side driver on success, or \c NULL on failure.
719 * \todo This function needs to be modified to remove context-modes from the
720 * list stored in the \c __GLXscreenConfigsRec to match the list
721 * returned by the client-side driver.
724 CallCreateNewScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
725 __DRIdisplay
* driDpy
,
726 PFNCREATENEWSCREENFUNC createNewScreen
)
728 __DRIscreenPrivate
*psp
= NULL
;
729 #ifndef GLX_USE_APPLEGL
733 __DRIversion ddx_version
;
734 __DRIversion dri_version
;
735 __DRIversion drm_version
;
736 __DRIframebuffer framebuffer
;
739 const char * err_msg
;
740 const char * err_extra
;
741 int api_ver
= __glXGetInternalVersion();
744 dri_version
.major
= driDpy
->private->driMajor
;
745 dri_version
.minor
= driDpy
->private->driMinor
;
746 dri_version
.patch
= driDpy
->private->driPatch
;
749 err_msg
= "XF86DRIOpenConnection";
752 framebuffer
.dev_priv
= NULL
;
754 if (XF86DRIOpenConnection(dpy
, scrn
, &hSAREA
, &BusID
)) {
755 fd
= drmOpen(NULL
,BusID
);
756 Xfree(BusID
); /* No longer needed */
758 err_msg
= "open DRM";
759 err_extra
= strerror( -fd
);
764 err_msg
= "drmGetMagic";
767 if (!drmGetMagic(fd
, &magic
)) {
768 drmVersionPtr version
= drmGetVersion(fd
);
770 drm_version
.major
= version
->version_major
;
771 drm_version
.minor
= version
->version_minor
;
772 drm_version
.patch
= version
->version_patchlevel
;
773 drmFreeVersion(version
);
776 drm_version
.major
= -1;
777 drm_version
.minor
= -1;
778 drm_version
.patch
= -1;
781 err_msg
= "XF86DRIAuthConnection";
782 if (XF86DRIAuthConnection(dpy
, scrn
, magic
)) {
786 * Get device name (like "tdfx") and the ddx version
787 * numbers. We'll check the version in each DRI driver's
788 * "createNewScreen" function.
790 err_msg
= "XF86DRIGetClientDriverName";
791 if (XF86DRIGetClientDriverName(dpy
, scrn
,
799 /* No longer needed. */
804 * Get device-specific info. pDevPriv will point to a struct
805 * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h)
806 * that has information about the screen size, depth, pitch,
807 * ancilliary buffers, DRM mmap handles, etc.
809 err_msg
= "XF86DRIGetDeviceInfo";
810 if (XF86DRIGetDeviceInfo(dpy
, scrn
,
815 &framebuffer
.dev_priv_size
,
816 &framebuffer
.dev_priv
)) {
817 framebuffer
.width
= DisplayWidth(dpy
, scrn
);
818 framebuffer
.height
= DisplayHeight(dpy
, scrn
);
821 * Map the framebuffer region.
823 status
= drmMap(fd
, hFB
, framebuffer
.size
,
824 (drmAddressPtr
)&framebuffer
.base
);
826 err_msg
= "drmMap of framebuffer";
827 err_extra
= strerror( -status
);
831 * Map the SAREA region. Further mmap regions
832 * may be setup in each DRI driver's
833 * "createNewScreen" function.
835 status
= drmMap(fd
, hSAREA
, SAREA_MAX
,
838 err_msg
= "drmMap of sarea";
839 err_extra
= strerror( -status
);
842 __GLcontextModes
* driver_modes
= NULL
;
843 __GLXscreenConfigs
*configs
= psc
->screenConfigs
;
845 err_msg
= "InitDriver";
847 psp
= (*createNewScreen
)(dpy
, scrn
,
860 filter_modes( & configs
->configs
,
862 _gl_context_modes_destroy( driver_modes
);
873 if ( pSAREA
!= MAP_FAILED
) {
874 (void)drmUnmap(pSAREA
, SAREA_MAX
);
877 if ( framebuffer
.base
!= MAP_FAILED
) {
878 (void)drmUnmap((drmAddress
)framebuffer
.base
, framebuffer
.size
);
881 if ( framebuffer
.dev_priv
!= NULL
) {
882 Xfree(framebuffer
.dev_priv
);
889 (void)XF86DRICloseConnection(dpy
, scrn
);
891 if ( err_extra
!= NULL
) {
892 fprintf(stderr
, "libGL error: %s failed (%s)\n", err_msg
,
896 fprintf(stderr
, "libGL error: %s failed\n", err_msg
);
899 fprintf(stderr
, "libGL error: reverting to (slow) indirect rendering\n");
901 #endif /* !GLX_USE_APPLEGL */
905 #endif /* GLX_DIRECT_RENDERING */
909 ** Allocate the memory for the per screen configs for each screen.
910 ** If that works then fetch the per screen configs data.
912 static Bool
AllocAndFetchScreenConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
)
914 xGLXGetVisualConfigsReq
*req
;
915 xGLXGetFBConfigsReq
*fb_req
;
916 xGLXVendorPrivateWithReplyReq
*vpreq
;
917 xGLXGetFBConfigsSGIXReq
*sgi_req
;
918 xGLXGetVisualConfigsReply reply
;
919 __GLXscreenConfigs
*psc
;
920 __GLcontextModes
*config
;
921 GLint i
, j
, nprops
, screens
;
922 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
923 unsigned supported_request
= 0;
927 ** First allocate memory for the array of per screen configs.
929 screens
= ScreenCount(dpy
);
930 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
934 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
935 priv
->screenConfigs
= psc
;
937 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
938 X_GLXQueryServerString
,
940 if ( priv
->serverGLXversion
== NULL
) {
941 FreeScreenConfigs(priv
);
945 if ( atof( priv
->serverGLXversion
) >= 1.3 ) {
946 supported_request
= 1;
950 ** Now fetch each screens configs structures. If a screen supports
951 ** GL (by returning a numVisuals > 0) then allocate memory for our
952 ** config structure and then fill it in.
954 for (i
= 0; i
< screens
; i
++, psc
++) {
955 if ( supported_request
!= 1 ) {
956 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
957 X_GLXQueryServerString
,
959 if ( strstr( psc
->serverGLXexts
, "GLX_SGIX_fbconfig" ) != NULL
) {
960 supported_request
= 2;
963 supported_request
= 3;
969 switch( supported_request
) {
971 GetReq(GLXGetFBConfigs
,fb_req
);
972 fb_req
->reqType
= priv
->majorOpcode
;
973 fb_req
->glxCode
= X_GLXGetFBConfigs
;
978 GetReqExtra(GLXVendorPrivateWithReply
,
979 sz_xGLXGetFBConfigsSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
980 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
981 sgi_req
->reqType
= priv
->majorOpcode
;
982 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
983 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
988 GetReq(GLXGetVisualConfigs
,req
);
989 req
->reqType
= priv
->majorOpcode
;
990 req
->glxCode
= X_GLXGetVisualConfigs
;
995 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
)) {
996 /* Something is busted. Punt. */
998 FreeScreenConfigs(priv
);
1003 if (!reply
.numVisuals
) {
1004 /* This screen does not support GL rendering */
1009 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for
1012 /* Check number of properties */
1013 nprops
= reply
.numProps
;
1014 if ((nprops
< __GLX_MIN_CONFIG_PROPS
) ||
1015 (nprops
> __GLX_MAX_CONFIG_PROPS
)) {
1016 /* Huh? Not in protocol defined limits. Punt */
1019 FreeScreenConfigs(priv
);
1023 /* Allocate memory for our config structure */
1024 psc
->configs
= _gl_context_modes_create(reply
.numVisuals
,
1025 sizeof(__GLcontextModes
));
1026 if (!psc
->configs
) {
1029 FreeScreenConfigs(priv
);
1033 /* Allocate memory for the properties, if needed */
1034 if ( supported_request
!= 3 ) {
1038 prop_size
= nprops
* __GLX_SIZE_INT32
;
1040 if (prop_size
<= sizeof(buf
)) {
1043 props
= (INT32
*) Xmalloc(prop_size
);
1046 /* Read each config structure and convert it into our format */
1047 config
= psc
->configs
;
1048 for (j
= 0; j
< reply
.numVisuals
; j
++) {
1049 assert( config
!= NULL
);
1050 _XRead(dpy
, (char *)props
, prop_size
);
1052 if ( supported_request
!= 3 ) {
1053 config
->rgbMode
= GL_TRUE
;
1054 config
->drawableType
= GLX_WINDOW_BIT
;
1057 config
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
1060 __glXInitializeVisualConfigFromTags( config
, nprops
, props
,
1061 (supported_request
!= 3),
1063 if ( config
->fbconfigID
== GLX_DONT_CARE
) {
1064 config
->fbconfigID
= config
->visualID
;
1067 config
= config
->next
;
1070 Xfree((char *)props
);
1074 #ifdef GLX_DIRECT_RENDERING
1075 /* Initialize per screen dynamic client GLX extensions */
1076 psc
->ext_list_first_time
= GL_TRUE
;
1077 /* Initialize the direct rendering per screen data and functions */
1078 if (priv
->driDisplay
.private != NULL
) {
1079 /* FIXME: Should it be some sort of an error if createNewScreen[i]
1082 if (priv
->driDisplay
.createNewScreen
&&
1083 priv
->driDisplay
.createNewScreen
[i
]) {
1085 psc
->driScreen
.screenConfigs
= (void *)psc
;
1086 psc
->driScreen
.private =
1087 CallCreateNewScreen(dpy
, i
, & psc
->driScreen
,
1089 priv
->driDisplay
.createNewScreen
[i
] );
1099 ** Initialize the client side extension code.
1101 __GLXdisplayPrivate
*__glXInitialize(Display
* dpy
)
1103 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1104 XExtData
**privList
, *private, *found
;
1105 __GLXdisplayPrivate
*dpyPriv
;
1106 XEDataObject dataObj
;
1109 #if defined(USE_XTHREADS)
1111 static int firstCall
= 1;
1113 /* initialize the GLX mutexes */
1114 xmutex_init(&__glXmutex
);
1121 /* The one and only long long lock */
1124 if (!XextHasExtension(info
)) {
1125 /* No GLX extension supported by this server. Oh well. */
1127 XMissingExtension(dpy
, __glXExtensionName
);
1131 /* See if a display private already exists. If so, return it */
1132 dataObj
.display
= dpy
;
1133 privList
= XEHeadOfExtensionList(dataObj
);
1134 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1137 return (__GLXdisplayPrivate
*) found
->private_data
;
1140 /* See if the versions are compatible */
1141 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
1142 /* The client and server do not agree on versions. Punt. */
1148 ** Allocate memory for all the pieces needed for this buffer.
1150 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
1155 dpyPriv
= (__GLXdisplayPrivate
*) Xmalloc(sizeof(__GLXdisplayPrivate
));
1158 Xfree((char*) private);
1163 ** Init the display private and then read in the screen config
1164 ** structures from the server.
1166 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
1167 dpyPriv
->majorVersion
= major
;
1168 dpyPriv
->minorVersion
= minor
;
1171 dpyPriv
->serverGLXvendor
= 0x0;
1172 dpyPriv
->serverGLXversion
= 0x0;
1174 #ifdef GLX_DIRECT_RENDERING
1176 ** Initialize the direct rendering per display data and functions.
1177 ** Note: This _must_ be done before calling any other DRI routines
1178 ** (e.g., those called in AllocAndFetchScreenConfigs).
1180 if (getenv("LIBGL_ALWAYS_INDIRECT")) {
1181 /* Assinging zero here assures we'll never go direct */
1182 dpyPriv
->driDisplay
.private = 0;
1183 dpyPriv
->driDisplay
.destroyDisplay
= 0;
1186 dpyPriv
->driDisplay
.private =
1187 driCreateDisplay(dpy
, &dpyPriv
->driDisplay
);
1191 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
1193 Xfree((char*) dpyPriv
);
1194 Xfree((char*) private);
1199 ** Fill in the private structure. This is the actual structure that
1200 ** hangs off of the Display structure. Our private structure is
1201 ** referred to by this structure. Got that?
1203 private->number
= info
->codes
->extension
;
1205 private->free_private
= __glXFreeDisplayPrivate
;
1206 private->private_data
= (char *) dpyPriv
;
1207 XAddToExtensionList(privList
, private);
1209 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
1210 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
1218 ** Setup for sending a GLX command on dpy. Make sure the extension is
1219 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
1221 CARD8
__glXSetupForCommand(Display
*dpy
)
1224 __GLXdisplayPrivate
*priv
;
1226 /* If this thread has a current context, flush its rendering commands */
1227 gc
= __glXGetCurrentContext();
1228 if (gc
->currentDpy
) {
1229 /* Flush rendering buffer of the current context, if any */
1230 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
1232 if (gc
->currentDpy
== dpy
) {
1233 /* Use opcode from gc because its right */
1235 return gc
->majorOpcode
;
1238 ** Have to get info about argument dpy because it might be to
1239 ** a different server
1244 /* Forced to lookup extension via the slow initialize route */
1245 priv
= __glXInitialize(dpy
);
1249 return priv
->majorOpcode
;
1253 * Flush the drawing command transport buffer.
1255 * \param ctx Context whose transport buffer is to be flushed.
1256 * \param pc Pointer to first unused buffer location.
1259 * Modify this function to use \c ctx->pc instead of the explicit
1262 GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*ctx
, GLubyte
*pc
)
1264 Display
* const dpy
= ctx
->currentDpy
;
1266 XCBConnection
*c
= XCBConnectionOfDisplay(dpy
);
1269 #endif /* USE_XCB */
1270 const GLint size
= pc
- ctx
->buf
;
1272 if ( (dpy
!= NULL
) && (size
> 0) ) {
1274 XCBGlxRender(c
, ctx
->currentContextTag
, size
, (char *)ctx
->buf
);
1276 /* Send the entire buffer as an X request */
1278 GetReq(GLXRender
,req
);
1279 req
->reqType
= ctx
->majorOpcode
;
1280 req
->glxCode
= X_GLXRender
;
1281 req
->contextTag
= ctx
->currentContextTag
;
1282 req
->length
+= (size
+ 3) >> 2;
1283 _XSend(dpy
, (char *)ctx
->buf
, size
);
1289 /* Reset pointer and return it */
1296 * Send a portion of a GLXRenderLarge command to the server. The advantage of
1297 * this function over \c __glXSendLargeCommand is that callers can use the
1298 * data buffer in the GLX context and may be able to avoid allocating an
1299 * extra buffer. The disadvantage is the clients will have to do more
1300 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
1302 * \sa __glXSendLargeCommand
1304 * \param gc GLX context
1305 * \param requestNumber Which part of the whole command is this? The first
1307 * \param totalRequests How many requests will there be?
1308 * \param data Command data.
1309 * \param dataLen Size, in bytes, of the command data.
1311 void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
1312 GLint totalRequests
,
1313 const GLvoid
* data
, GLint dataLen
)
1315 Display
*dpy
= gc
->currentDpy
;
1317 XCBConnection
*c
= XCBConnectionOfDisplay(dpy
);
1318 XCBGlxRenderLarge(c
, gc
->currentContextTag
, requestNumber
, totalRequests
, dataLen
, data
);
1320 xGLXRenderLargeReq
*req
;
1322 if ( requestNumber
== 1 ) {
1326 GetReq(GLXRenderLarge
,req
);
1327 req
->reqType
= gc
->majorOpcode
;
1328 req
->glxCode
= X_GLXRenderLarge
;
1329 req
->contextTag
= gc
->currentContextTag
;
1330 req
->length
+= (dataLen
+ 3) >> 2;
1331 req
->requestNumber
= requestNumber
;
1332 req
->requestTotal
= totalRequests
;
1333 req
->dataBytes
= dataLen
;
1334 Data(dpy
, data
, dataLen
);
1336 if ( requestNumber
== totalRequests
) {
1340 #endif /* USE_XCB */
1345 * Send a command that is too large for the GLXRender protocol request.
1347 * Send a large command, one that is too large for some reason to
1348 * send using the GLXRender protocol request. One reason to send
1349 * a large command is to avoid copying the data.
1351 * \param ctx GLX context
1352 * \param header Header data.
1353 * \param headerLen Size, in bytes, of the header data. It is assumed that
1354 * the header data will always be small enough to fit in
1355 * a single X protocol packet.
1356 * \param data Command data.
1357 * \param dataLen Size, in bytes, of the command data.
1359 void __glXSendLargeCommand(__GLXcontext
*ctx
,
1360 const GLvoid
*header
, GLint headerLen
,
1361 const GLvoid
*data
, GLint dataLen
)
1364 GLint totalRequests
, requestNumber
;
1367 ** Calculate the maximum amount of data can be stuffed into a single
1368 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1369 ** packet size minus sz_xGLXRenderReq.
1371 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1372 totalRequests
= 1 + (dataLen
/ maxSize
);
1373 if (dataLen
% maxSize
) totalRequests
++;
1376 ** Send all of the command, except the large array, as one request.
1378 assert( headerLen
<= maxSize
);
1379 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1382 ** Send enough requests until the whole array is sent.
1384 for ( requestNumber
= 2 ; requestNumber
<= (totalRequests
- 1) ; requestNumber
++ ) {
1385 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1386 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1388 assert( dataLen
> 0 );
1391 assert( dataLen
<= maxSize
);
1392 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1395 /************************************************************************/
1397 GLXContext
glXGetCurrentContext(void)
1399 GLXContext cx
= __glXGetCurrentContext();
1401 if (cx
== &dummyContext
) {
1408 GLXDrawable
glXGetCurrentDrawable(void)
1410 GLXContext gc
= __glXGetCurrentContext();
1411 return gc
->currentDrawable
;
1415 /************************************************************************/
1417 #ifdef GLX_DIRECT_RENDERING
1418 /* Return the DRI per screen structure */
1419 __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
)
1421 __DRIscreen
*pDRIScreen
= NULL
;
1422 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1423 XExtData
**privList
, *found
;
1424 __GLXdisplayPrivate
*dpyPriv
;
1425 XEDataObject dataObj
;
1428 dataObj
.display
= dpy
;
1429 privList
= XEHeadOfExtensionList(dataObj
);
1430 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1434 dpyPriv
= (__GLXdisplayPrivate
*)found
->private_data
;
1435 pDRIScreen
= &dpyPriv
->screenConfigs
[scrn
].driScreen
;
1442 /************************************************************************/
1444 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1445 GLXContextID gc
, GLXContextTag old_gc
, GLXDrawable draw
, GLXDrawable read
,
1446 xGLXMakeCurrentReply
* reply
);
1449 * Sends a GLX protocol message to the specified display to make the context
1450 * and the drawables current.
1452 * \param dpy Display to send the message to.
1453 * \param opcode Major opcode value for the display.
1454 * \param gc_id Context tag for the context to be made current.
1455 * \param draw Drawable ID for the "draw" drawable.
1456 * \param read Drawable ID for the "read" drawable.
1457 * \param reply Space to store the X-server's reply.
1460 * This function assumes that \c dpy is locked with \c LockDisplay on entry.
1462 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1463 GLXContextID gc_id
, GLXContextTag gc_tag
,
1464 GLXDrawable draw
, GLXDrawable read
,
1465 xGLXMakeCurrentReply
* reply
)
1467 if ( draw
== read
) {
1468 xGLXMakeCurrentReq
*req
;
1470 GetReq(GLXMakeCurrent
,req
);
1471 req
->reqType
= opcode
;
1472 req
->glxCode
= X_GLXMakeCurrent
;
1473 req
->drawable
= draw
;
1474 req
->context
= gc_id
;
1475 req
->oldContextTag
= gc_tag
;
1478 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1480 /* If the server can support the GLX 1.3 version, we should
1481 * perfer that. Not only that, some servers support GLX 1.3 but
1482 * not the SGI extension.
1485 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1486 xGLXMakeContextCurrentReq
*req
;
1488 GetReq(GLXMakeContextCurrent
,req
);
1489 req
->reqType
= opcode
;
1490 req
->glxCode
= X_GLXMakeContextCurrent
;
1491 req
->drawable
= draw
;
1492 req
->readdrawable
= read
;
1493 req
->context
= gc_id
;
1494 req
->oldContextTag
= gc_tag
;
1497 xGLXVendorPrivateWithReplyReq
*vpreq
;
1498 xGLXMakeCurrentReadSGIReq
*req
;
1500 GetReqExtra(GLXVendorPrivateWithReply
,
1501 sz_xGLXMakeCurrentReadSGIReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1502 req
= (xGLXMakeCurrentReadSGIReq
*)vpreq
;
1503 req
->reqType
= opcode
;
1504 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1505 req
->vendorCode
= X_GLXvop_MakeCurrentReadSGI
;
1506 req
->drawable
= draw
;
1507 req
->readable
= read
;
1508 req
->context
= gc_id
;
1509 req
->oldContextTag
= gc_tag
;
1513 return _XReply(dpy
, (xReply
*) reply
, 0, False
);
1517 #ifdef GLX_DIRECT_RENDERING
1518 static Bool
BindContextWrapper( Display
*dpy
, GLXContext gc
,
1519 GLXDrawable draw
, GLXDrawable read
)
1521 return (*gc
->driContext
.bindContext
)(dpy
, gc
->screen
, draw
, read
,
1526 static Bool
UnbindContextWrapper( GLXContext gc
)
1528 return (*gc
->driContext
.unbindContext
)(gc
->currentDpy
, gc
->screen
,
1529 gc
->currentDrawable
,
1530 gc
->currentReadable
,
1533 #endif /* GLX_DIRECT_RENDERING */
1537 ** Make a particular context current.
1538 ** NOTE: this is in this file so that it can access dummyContext.
1540 USED
static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
1541 GLXDrawable read
, GLXContext gc
)
1543 xGLXMakeCurrentReply reply
;
1545 CARD8 opcode
, oldOpcode
;
1546 Bool sentRequestToOldDpy
= False
;
1547 Bool bindReturnValue
= True
;
1549 opcode
= __glXSetupForCommand(dpy
);
1555 ** Make sure that the new context has a nonzero ID. In the request,
1556 ** a zero context ID is used only to mean that we bind to no current
1559 if ((gc
!= NULL
) && (gc
->xid
== None
)) {
1563 oldGC
= __glXGetCurrentContext();
1564 oldOpcode
= (gc
== oldGC
) ? opcode
: __glXSetupForCommand(dpy
);
1569 if ((dpy
!= oldGC
->currentDpy
|| (gc
&& gc
->isDirect
)) &&
1570 !oldGC
->isDirect
&& oldGC
!= &dummyContext
) {
1572 ** We are either switching from one dpy to another and have to
1573 ** send a request to the previous dpy to unbind the previous
1574 ** context, or we are switching away from a indirect context to
1575 ** a direct context and have to send a request to the dpy to
1576 ** unbind the previous context.
1578 sentRequestToOldDpy
= True
;
1579 LockDisplay(oldGC
->currentDpy
);
1580 if ( ! SendMakeCurrentRequest( oldGC
->currentDpy
, oldOpcode
, None
,
1581 oldGC
->currentContextTag
, None
, None
,
1583 /* The make current failed. Just return GL_FALSE. */
1584 UnlockDisplay(oldGC
->currentDpy
);
1589 oldGC
->currentContextTag
= 0;
1592 #ifdef GLX_DIRECT_RENDERING
1593 /* Unbind the old direct rendering context */
1594 if (oldGC
->isDirect
) {
1595 if (oldGC
->driContext
.private) {
1596 if (! UnbindContextWrapper( oldGC
)) {
1597 /* The make current failed. Just return GL_FALSE. */
1601 oldGC
->currentContextTag
= 0;
1604 /* Bind the direct rendering context to the drawable */
1605 if (gc
&& gc
->isDirect
) {
1606 if (gc
->driContext
.private) {
1607 bindReturnValue
= BindContextWrapper( dpy
, gc
, draw
, read
);
1611 _glapi_check_multithread();
1612 /* Send a glXMakeCurrent request to bind the new context. */
1615 bindReturnValue
= SendMakeCurrentRequest( dpy
, opcode
,
1616 gc
? gc
->xid
: None
,
1617 oldGC
->currentContextTag
,
1618 draw
, read
, &reply
);
1620 #ifdef GLX_DIRECT_RENDERING
1625 if (!bindReturnValue
) {
1626 /* The make current failed. */
1627 if (gc
&& !gc
->isDirect
) {
1631 #ifdef GLX_DIRECT_RENDERING
1632 /* If the old context was direct rendering, then re-bind to it. */
1633 if (oldGC
->isDirect
) {
1634 if (oldGC
->driContext
.private) {
1635 if (! BindContextWrapper( oldGC
->currentDpy
, oldGC
,
1636 oldGC
->currentDrawable
,
1637 oldGC
->currentReadable
)) {
1639 ** The request failed; this cannot happen with the
1640 ** current API. If in the future the API is
1641 ** extended to allow context sharing between
1642 ** clients, then this may fail (because another
1643 ** client may have grabbed the context); in that
1644 ** case, we cannot undo the previous request, and
1645 ** cannot adhere to the "no-op" behavior.
1652 ** If we had just sent a request to a previous dpy, we have to
1653 ** undo that request (because if a command fails, it should act
1654 ** like a no-op) by making current to the previous context and
1657 if (sentRequestToOldDpy
) {
1658 if ( !SendMakeCurrentRequest( oldGC
->currentDpy
, oldOpcode
,
1660 oldGC
->currentDrawable
,
1661 oldGC
->currentReadable
, &reply
) ) {
1662 UnlockDisplay(oldGC
->currentDpy
);
1665 ** The request failed; this cannot happen with the
1666 ** current API. If in the future the API is extended to
1667 ** allow context sharing between clients, then this may
1668 ** fail (because another client may have grabbed the
1669 ** context); in that case, we cannot undo the previous
1670 ** request, and cannot adhere to the "no-op" behavior.
1674 UnlockDisplay(oldGC
->currentDpy
);
1676 oldGC
->currentContextTag
= reply
.contextTag
;
1681 /* Update our notion of what is current */
1685 ** Even though the contexts are the same the drawable might have
1686 ** changed. Note that gc cannot be the dummy, and that oldGC
1687 ** cannot be NULL, therefore if they are the same, gc is not
1688 ** NULL and not the dummy.
1690 gc
->currentDrawable
= draw
;
1691 gc
->currentReadable
= read
;
1693 if (oldGC
!= &dummyContext
) {
1694 /* Old current context is no longer current to anybody */
1695 oldGC
->currentDpy
= 0;
1696 oldGC
->currentDrawable
= None
;
1697 oldGC
->currentReadable
= None
;
1698 oldGC
->currentContextTag
= 0;
1700 if (oldGC
->xid
== None
) {
1702 ** We are switching away from a context that was
1703 ** previously destroyed, so we need to free the memory
1704 ** for the old handle.
1706 #ifdef GLX_DIRECT_RENDERING
1707 /* Destroy the old direct rendering context */
1708 if (oldGC
->isDirect
) {
1709 if (oldGC
->driContext
.private) {
1710 (*oldGC
->driContext
.destroyContext
)
1711 (dpy
, oldGC
->screen
, oldGC
->driContext
.private);
1712 oldGC
->driContext
.private = NULL
;
1716 __glXFreeContext(oldGC
);
1720 __glXSetCurrentContext(gc
);
1721 #ifdef GLX_DIRECT_RENDERING
1722 if (!gc
->isDirect
) {
1724 IndirectAPI
= __glXNewIndirectAPI();
1725 _glapi_set_dispatch(IndirectAPI
);
1726 # ifdef GLX_USE_APPLEGL
1728 extern void XAppleDRIUseIndirectDispatch(void);
1729 XAppleDRIUseIndirectDispatch();
1734 /* if not direct rendering, always need indirect dispatch */
1736 IndirectAPI
= __glXNewIndirectAPI();
1737 _glapi_set_dispatch(IndirectAPI
);
1739 gc
->currentDpy
= dpy
;
1740 gc
->currentDrawable
= draw
;
1741 gc
->currentReadable
= read
;
1743 if ( ! gc
->isDirect
) {
1744 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1746 gc
->currentContextTag
= reply
.contextTag
;
1747 if ( state
->array_state
== NULL
) {
1748 (void) glGetString( GL_EXTENSIONS
);
1749 (void) glGetString( GL_VERSION
);
1750 __glXInitVertexArrayState(gc
);
1754 gc
->currentContextTag
= -1;
1757 __glXSetCurrentContext(&dummyContext
);
1758 #ifdef GLX_DIRECT_RENDERING
1759 _glapi_set_dispatch(NULL
); /* no-op functions */
1768 PUBLIC Bool
glXMakeCurrent(Display
*dpy
, GLXDrawable draw
, GLXContext gc
)
1770 return MakeContextCurrent( dpy
, draw
, draw
, gc
);
1773 PUBLIC
GLX_ALIAS(Bool
, glXMakeCurrentReadSGI
,
1774 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1775 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1777 PUBLIC
GLX_ALIAS(Bool
, glXMakeContextCurrent
,
1778 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1779 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1783 void __glXDumpDrawBuffer(__GLXcontext
*ctx
)
1785 GLubyte
*p
= ctx
->buf
;
1786 GLubyte
*end
= ctx
->pc
;
1787 GLushort opcode
, length
;
1791 opcode
= *((GLushort
*) p
);
1792 length
= *((GLushort
*) (p
+ 2));
1793 printf("%2x: %5d: ", opcode
, length
);
1796 while (length
> 0) {
1797 printf("%08x ", *((unsigned *) p
));
1806 #ifdef USE_SPARC_ASM
1808 * Used only when we are sparc, using sparc assembler.
1813 _glx_mesa_init_sparc_glapi_relocs(void)
1815 unsigned int *insn_ptr
, *end_ptr
;
1816 unsigned long disp_addr
;
1818 insn_ptr
= &_mesa_sparc_glapi_begin
;
1819 end_ptr
= &_mesa_sparc_glapi_end
;
1820 disp_addr
= (unsigned long) &_glapi_Dispatch
;
1823 * Verbatim from Mesa sparc.c. It's needed because there doesn't
1824 * seem to be a better way to do this:
1826 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1828 * This code is patching in the ADDRESS of the pointer to the
1829 * dispatch table. Hence, it must be called exactly once, because
1830 * that address is not going to change.
1832 * What it points to can change, but Mesa (and hence, we) assume
1833 * that there is only one pointer.
1836 while (insn_ptr
< end_ptr
) {
1837 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1839 This code patches for 64-bit addresses. This had better
1840 not happen for Sparc/Linux, no matter what architecture we
1841 are building for. So, don't do this.
1843 The 'defined(__linux_64__)' is used here as a placeholder for
1844 when we do do 64-bit usermode on sparc linux.
1846 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1847 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1848 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1849 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1850 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1851 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1854 insn_ptr
[0] |= (disp_addr
>> 10);
1855 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1856 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1861 #endif /* sparc ASM in use */