1 /* $XFree86: xc/lib/GL/glx/glxext.c,v 1.22 2003/12/08 17:35:28 dawes Exp $ */
4 ** License Applicability. Except to the extent portions of this file are
5 ** made subject to an alternative license as permitted in the SGI Free
6 ** Software License B, Version 1.1 (the "License"), the contents of this
7 ** file are subject only to the provisions of the License. You may not use
8 ** this file except in compliance with the License. You may obtain a copy
9 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
10 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
12 ** http://oss.sgi.com/projects/FreeB
14 ** Note that, as provided in the License, the Software is distributed on an
15 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
16 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
17 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
18 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
20 ** Original Code. The Original Code is: OpenGL Sample Implementation,
21 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
22 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
23 ** Copyright in any portions created by third parties is as indicated
24 ** elsewhere herein. All Rights Reserved.
26 ** Additional Notice Provisions: The application programming interfaces
27 ** established by SGI in conjunction with the Original Code are The
28 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
29 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
30 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
31 ** Window System(R) (Version 1.3), released October 19, 1998. This software
32 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
33 ** published by SGI, but has not been independently verified as being
34 ** compliant with the OpenGL(R) version 1.2.1 Specification.
40 * GLX protocol interface boot-strap code.
42 * Direct rendering support added by Precision Insight, Inc.
44 * \author Kevin E. Martin <kevin@precisioninsight.com>
47 #include "glxclient.h"
52 #include "indirect_init.h"
55 # include "Xthreads.h"
56 #elif defined(PTHREADS)
59 #include "glxextensions.h"
60 #include "glcontextmodes.h"
63 #ifdef GLX_DIRECT_RENDERING
73 #include <X11/XCB/xcb.h>
74 #include <X11/XCB/glx.h>
80 void __glXDumpDrawBuffer(__GLXcontext
*ctx
);
85 * This is where our dispatch table's bounds are.
86 * And the static mesa_init is taken directly from
87 * Mesa's 'sparc.c' initializer.
89 * We need something like this here, because this version
90 * of openGL/glx never initializes a Mesa context, and so
91 * the address of the dispatch table pointer never gets stuffed
92 * into the dispatch jump table otherwise.
94 * It matters only on SPARC, and only if you are using assembler
95 * code instead of C-code indirect dispatch.
99 extern unsigned int _mesa_sparc_glapi_begin
;
100 extern unsigned int _mesa_sparc_glapi_end
;
101 extern void __glapi_sparc_icache_flush(unsigned int *);
102 static void _glx_mesa_init_sparc_glapi_relocs(void);
103 static int _mesa_sparc_needs_init
= 1;
104 #define INIT_MESA_SPARC { \
105 if(_mesa_sparc_needs_init) { \
106 _glx_mesa_init_sparc_glapi_relocs(); \
107 _mesa_sparc_needs_init = 0; \
111 #define INIT_MESA_SPARC
114 #ifdef GLX_DIRECT_RENDERING
115 static __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
);
116 #endif /* GLX_DIRECT_RENDERING */
118 static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
119 GLXDrawable read
, GLXContext gc
);
122 ** We setup some dummy structures here so that the API can be used
123 ** even if no context is current.
126 static GLubyte dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
];
129 ** Dummy context used by small commands when there is no current context.
131 ** gl and glx entry points are designed to operate as nop's when using
132 ** the dummy context structure.
134 static __GLXcontext dummyContext
= {
138 &dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
],
144 ** All indirect rendering contexts will share the same indirect dispatch table.
146 static __GLapi
*IndirectAPI
= NULL
;
150 * Current context management and locking
153 #if defined( XTHREADS )
156 static GLboolean TSDinitialized
= GL_FALSE
;
157 static xthread_key_t ContextTSD
;
159 __GLXcontext
*__glXGetCurrentContext(void)
161 if (!TSDinitialized
) {
162 xthread_key_create(&ContextTSD
, NULL
);
163 TSDinitialized
= GL_TRUE
;
164 return &dummyContext
;
168 xthread_get_specific(ContextTSD
, &p
);
170 return &dummyContext
;
172 return (__GLXcontext
*) p
;
176 void __glXSetCurrentContext(__GLXcontext
*c
)
178 if (!TSDinitialized
) {
179 xthread_key_create(&ContextTSD
, NULL
);
180 TSDinitialized
= GL_TRUE
;
182 xthread_set_specific(ContextTSD
, c
);
186 /* Used by the __glXLock() and __glXUnlock() macros */
187 xmutex_rec __glXmutex
;
189 #elif defined( PTHREADS )
191 pthread_mutex_t __glXmutex
= PTHREAD_MUTEX_INITIALIZER
;
193 # if defined( GLX_USE_TLS )
196 * Per-thread GLX context pointer.
198 * \c __glXSetCurrentContext is written is such a way that this pointer can
199 * \b never be \c NULL. This is important! Because of this
200 * \c __glXGetCurrentContext can be implemented as trivial macro.
202 __thread
void * __glX_tls_Context
__attribute__((tls_model("initial-exec")))
205 void __glXSetCurrentContext( __GLXcontext
* c
)
207 __glX_tls_Context
= (c
!= NULL
) ? c
: &dummyContext
;
212 static pthread_once_t once_control
= PTHREAD_ONCE_INIT
;
215 * Per-thread data key.
217 * Once \c init_thread_data has been called, the per-thread data key will
218 * take a value of \c NULL. As each new thread is created the default
219 * value, in that thread, will be \c NULL.
221 static pthread_key_t ContextTSD
;
224 * Initialize the per-thread data key.
226 * This function is called \b exactly once per-process (not per-thread!) to
227 * initialize the per-thread data key. This is ideally done using the
228 * \c pthread_once mechanism.
230 static void init_thread_data( void )
232 if ( pthread_key_create( & ContextTSD
, NULL
) != 0 ) {
233 perror( "pthread_key_create" );
238 void __glXSetCurrentContext( __GLXcontext
* c
)
240 pthread_once( & once_control
, init_thread_data
);
241 pthread_setspecific( ContextTSD
, c
);
244 __GLXcontext
* __glXGetCurrentContext( void )
248 pthread_once( & once_control
, init_thread_data
);
250 v
= pthread_getspecific( ContextTSD
);
251 return (v
== NULL
) ? & dummyContext
: (__GLXcontext
*) v
;
254 # endif /* defined( GLX_USE_TLS ) */
256 #elif defined( THREADS )
258 #error Unknown threading method specified.
262 /* not thread safe */
263 __GLXcontext
*__glXcurrentContext
= &dummyContext
;
269 ** You can set this cell to 1 to force the gl drawing stuff to be
270 ** one command per packet
275 ** forward prototype declarations
277 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
);
280 /************************************************************************/
282 /* Extension required boiler plate */
284 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
285 XExtensionInfo
*__glXExtensionInfo
= NULL
;
287 static /* const */ char *error_list
[] = {
289 "GLXBadContextState",
293 "GLXBadCurrentWindow",
294 "GLXBadRenderRequest",
295 "GLXBadLargeRequest",
296 "GLXUnsupportedPrivateRequest",
299 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
)
303 gc
= __glXGetCurrentContext();
304 if (dpy
== gc
->currentDpy
) {
305 __glXSetCurrentContext(&dummyContext
);
306 #ifdef GLX_DIRECT_RENDERING
307 _glapi_set_dispatch(NULL
); /* no-op functions */
309 __glXFreeContext(gc
);
312 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
316 static XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
317 __GLX_NUMBER_ERRORS
, error_list
)
319 static /* const */ XExtensionHooks __glXExtensionHooks
= {
320 NULL
, /* create_gc */
324 NULL
, /* create_font */
325 NULL
, /* free_font */
326 __glXCloseDisplay
, /* close_display */
327 NULL
, /* wire_to_event */
328 NULL
, /* event_to_wire */
330 __glXErrorString
, /* error_string */
334 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
335 __glXExtensionName
, &__glXExtensionHooks
,
336 __GLX_NUMBER_EVENTS
, NULL
)
338 /************************************************************************/
341 ** Free the per screen configs data as well as the array of
342 ** __glXScreenConfigs.
344 static void FreeScreenConfigs(__GLXdisplayPrivate
*priv
)
346 __GLXscreenConfigs
*psc
;
349 /* Free screen configuration information */
350 psc
= priv
->screenConfigs
;
351 screens
= ScreenCount(priv
->dpy
);
352 for (i
= 0; i
< screens
; i
++, psc
++) {
354 _gl_context_modes_destroy( psc
->configs
);
355 if(psc
->effectiveGLXexts
)
356 Xfree(psc
->effectiveGLXexts
);
358 psc
->configs
= NULL
; /* NOTE: just for paranoia */
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 #if 0 /* 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
++;
607 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
609 config
->haveAccumBuffer
= ((config
->accumRedBits
+
610 config
->accumGreenBits
+
611 config
->accumBlueBits
+
612 config
->accumAlphaBits
) > 0);
613 config
->haveDepthBuffer
= (config
->depthBits
> 0);
614 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
618 #ifdef GLX_DIRECT_RENDERING
620 filter_modes( __GLcontextModes
** server_modes
,
621 const __GLcontextModes
* driver_modes
)
623 __GLcontextModes
* m
;
624 __GLcontextModes
** prev_next
;
625 const __GLcontextModes
* check
;
626 unsigned modes_count
= 0;
628 if ( driver_modes
== NULL
) {
629 fprintf(stderr
, "libGL warning: 3D driver returned no fbconfigs.\n");
633 /* For each mode in server_modes, check to see if a matching mode exists
634 * in driver_modes. If not, then the mode is not available.
637 prev_next
= server_modes
;
638 for ( m
= *prev_next
; m
!= NULL
; m
= *prev_next
) {
639 GLboolean do_delete
= GL_TRUE
;
641 for ( check
= driver_modes
; check
!= NULL
; check
= check
->next
) {
642 if ( _gl_context_modes_are_same( m
, check
) ) {
643 do_delete
= GL_FALSE
;
648 /* The 3D has to support all the modes that match the GLX visuals
649 * sent from the X server.
651 if ( do_delete
&& (m
->visualID
!= 0) ) {
652 do_delete
= GL_FALSE
;
654 fprintf(stderr
, "libGL warning: 3D driver claims to not support "
655 "visual 0x%02x\n", m
->visualID
);
659 *prev_next
= m
->next
;
662 _gl_context_modes_destroy( m
);
666 prev_next
= & m
->next
;
675 * Implement \c __DRIinterfaceMethods::getProcAddress.
677 static __DRIfuncPtr
get_proc_address( const char * proc_name
)
679 if (strcmp( proc_name
, "glxEnableExtension" ) == 0) {
680 return (__DRIfuncPtr
) __glXScrEnableExtension
;
688 * Table of functions exported by the loader to the driver.
690 static const __DRIinterfaceMethods interface_methods
= {
693 _gl_context_modes_create
,
694 _gl_context_modes_destroy
,
699 XF86DRICreateContextWithConfig
,
700 XF86DRIDestroyContext
,
702 XF86DRICreateDrawable
,
703 XF86DRIDestroyDrawable
,
704 XF86DRIGetDrawableInfo
,
712 * Perform the required libGL-side initialization and call the client-side
713 * driver's \c __driCreateNewScreen function.
715 * \param dpy Display pointer.
716 * \param scrn Screen number on the display.
717 * \param psc DRI screen information.
718 * \param driDpy DRI display information.
719 * \param createNewScreen Pointer to the client-side driver's
720 * \c __driCreateNewScreen function.
721 * \returns A pointer to the \c __DRIscreenPrivate structure returned by
722 * the client-side driver on success, or \c NULL on failure.
724 * \todo This function needs to be modified to remove context-modes from the
725 * list stored in the \c __GLXscreenConfigsRec to match the list
726 * returned by the client-side driver.
729 CallCreateNewScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
730 __DRIdisplay
* driDpy
,
731 PFNCREATENEWSCREENFUNC createNewScreen
)
733 __DRIscreenPrivate
*psp
= NULL
;
734 #ifndef GLX_USE_APPLEGL
738 __DRIversion ddx_version
;
739 __DRIversion dri_version
;
740 __DRIversion drm_version
;
741 __DRIframebuffer framebuffer
;
744 const char * err_msg
;
745 const char * err_extra
;
746 int api_ver
= __glXGetInternalVersion();
749 dri_version
.major
= driDpy
->private->driMajor
;
750 dri_version
.minor
= driDpy
->private->driMinor
;
751 dri_version
.patch
= driDpy
->private->driPatch
;
754 err_msg
= "XF86DRIOpenConnection";
757 framebuffer
.dev_priv
= NULL
;
759 if (XF86DRIOpenConnection(dpy
, scrn
, &hSAREA
, &BusID
)) {
760 fd
= drmOpen(NULL
,BusID
);
761 Xfree(BusID
); /* No longer needed */
763 err_msg
= "open DRM";
764 err_extra
= strerror( -fd
);
769 err_msg
= "drmGetMagic";
772 if (!drmGetMagic(fd
, &magic
)) {
773 drmVersionPtr version
= drmGetVersion(fd
);
775 drm_version
.major
= version
->version_major
;
776 drm_version
.minor
= version
->version_minor
;
777 drm_version
.patch
= version
->version_patchlevel
;
778 drmFreeVersion(version
);
781 drm_version
.major
= -1;
782 drm_version
.minor
= -1;
783 drm_version
.patch
= -1;
786 err_msg
= "XF86DRIAuthConnection";
787 if (XF86DRIAuthConnection(dpy
, scrn
, magic
)) {
791 * Get device name (like "tdfx") and the ddx version
792 * numbers. We'll check the version in each DRI driver's
793 * "createNewScreen" function.
795 err_msg
= "XF86DRIGetClientDriverName";
796 if (XF86DRIGetClientDriverName(dpy
, scrn
,
804 /* No longer needed. */
809 * Get device-specific info. pDevPriv will point to a struct
810 * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h)
811 * that has information about the screen size, depth, pitch,
812 * ancilliary buffers, DRM mmap handles, etc.
814 err_msg
= "XF86DRIGetDeviceInfo";
815 if (XF86DRIGetDeviceInfo(dpy
, scrn
,
820 &framebuffer
.dev_priv_size
,
821 &framebuffer
.dev_priv
)) {
822 framebuffer
.width
= DisplayWidth(dpy
, scrn
);
823 framebuffer
.height
= DisplayHeight(dpy
, scrn
);
826 * Map the framebuffer region.
828 status
= drmMap(fd
, hFB
, framebuffer
.size
,
829 (drmAddressPtr
)&framebuffer
.base
);
831 err_msg
= "drmMap of framebuffer";
832 err_extra
= strerror( -status
);
836 * Map the SAREA region. Further mmap regions
837 * may be setup in each DRI driver's
838 * "createNewScreen" function.
840 status
= drmMap(fd
, hSAREA
, SAREA_MAX
,
843 err_msg
= "drmMap of sarea";
844 err_extra
= strerror( -status
);
847 __GLcontextModes
* driver_modes
= NULL
;
848 __GLXscreenConfigs
*configs
= psc
->screenConfigs
;
850 err_msg
= "InitDriver";
852 psp
= (*createNewScreen
)(dpy
, scrn
,
865 filter_modes( & configs
->configs
,
867 _gl_context_modes_destroy( driver_modes
);
878 if ( pSAREA
!= MAP_FAILED
) {
879 (void)drmUnmap(pSAREA
, SAREA_MAX
);
882 if ( framebuffer
.base
!= MAP_FAILED
) {
883 (void)drmUnmap((drmAddress
)framebuffer
.base
, framebuffer
.size
);
886 if ( framebuffer
.dev_priv
!= NULL
) {
887 Xfree(framebuffer
.dev_priv
);
894 (void)XF86DRICloseConnection(dpy
, scrn
);
896 if ( err_extra
!= NULL
) {
897 fprintf(stderr
, "libGL error: %s failed (%s)\n", err_msg
,
901 fprintf(stderr
, "libGL error: %s failed\n", err_msg
);
904 fprintf(stderr
, "libGL error: reverting to (slow) indirect rendering\n");
906 #endif /* !GLX_USE_APPLEGL */
910 #endif /* GLX_DIRECT_RENDERING */
914 ** Allocate the memory for the per screen configs for each screen.
915 ** If that works then fetch the per screen configs data.
917 static Bool
AllocAndFetchScreenConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
)
919 xGLXGetVisualConfigsReq
*req
;
920 xGLXGetFBConfigsReq
*fb_req
;
921 xGLXVendorPrivateWithReplyReq
*vpreq
;
922 xGLXGetFBConfigsSGIXReq
*sgi_req
;
923 xGLXGetVisualConfigsReply reply
;
924 __GLXscreenConfigs
*psc
;
925 __GLcontextModes
*config
;
926 GLint i
, j
, nprops
, screens
;
927 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
928 unsigned supported_request
= 0;
932 ** First allocate memory for the array of per screen configs.
934 screens
= ScreenCount(dpy
);
935 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
939 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
940 priv
->screenConfigs
= psc
;
942 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
943 X_GLXQueryServerString
,
945 if ( priv
->serverGLXversion
== NULL
) {
946 FreeScreenConfigs(priv
);
950 if ( atof( priv
->serverGLXversion
) >= 1.3 ) {
951 supported_request
= 1;
955 ** Now fetch each screens configs structures. If a screen supports
956 ** GL (by returning a numVisuals > 0) then allocate memory for our
957 ** config structure and then fill it in.
959 for (i
= 0; i
< screens
; i
++, psc
++) {
960 if ( supported_request
!= 1 ) {
961 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
962 X_GLXQueryServerString
,
964 if ( strstr( psc
->serverGLXexts
, "GLX_SGIX_fbconfig" ) != NULL
) {
965 supported_request
= 2;
968 supported_request
= 3;
974 switch( supported_request
) {
976 GetReq(GLXGetFBConfigs
,fb_req
);
977 fb_req
->reqType
= priv
->majorOpcode
;
978 fb_req
->glxCode
= X_GLXGetFBConfigs
;
983 GetReqExtra(GLXVendorPrivateWithReply
,
984 sz_xGLXGetFBConfigsSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
985 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
986 sgi_req
->reqType
= priv
->majorOpcode
;
987 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
988 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
993 GetReq(GLXGetVisualConfigs
,req
);
994 req
->reqType
= priv
->majorOpcode
;
995 req
->glxCode
= X_GLXGetVisualConfigs
;
1000 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
)) {
1001 /* Something is busted. Punt. */
1003 FreeScreenConfigs(priv
);
1008 if (!reply
.numVisuals
) {
1009 /* This screen does not support GL rendering */
1014 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for
1017 /* Check number of properties */
1018 nprops
= reply
.numProps
;
1019 if ((nprops
< __GLX_MIN_CONFIG_PROPS
) ||
1020 (nprops
> __GLX_MAX_CONFIG_PROPS
)) {
1021 /* Huh? Not in protocol defined limits. Punt */
1024 FreeScreenConfigs(priv
);
1028 /* Allocate memory for our config structure */
1029 psc
->configs
= _gl_context_modes_create(reply
.numVisuals
,
1030 sizeof(__GLcontextModes
));
1031 if (!psc
->configs
) {
1034 FreeScreenConfigs(priv
);
1038 /* Allocate memory for the properties, if needed */
1039 if ( supported_request
!= 3 ) {
1043 prop_size
= nprops
* __GLX_SIZE_INT32
;
1045 if (prop_size
<= sizeof(buf
)) {
1048 props
= (INT32
*) Xmalloc(prop_size
);
1051 /* Read each config structure and convert it into our format */
1052 config
= psc
->configs
;
1053 for (j
= 0; j
< reply
.numVisuals
; j
++) {
1054 assert( config
!= NULL
);
1055 _XRead(dpy
, (char *)props
, prop_size
);
1057 if ( supported_request
!= 3 ) {
1058 config
->rgbMode
= GL_TRUE
;
1059 config
->drawableType
= GLX_WINDOW_BIT
;
1062 config
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
1065 __glXInitializeVisualConfigFromTags( config
, nprops
, props
,
1066 (supported_request
!= 3),
1068 if ( config
->fbconfigID
== GLX_DONT_CARE
) {
1069 config
->fbconfigID
= config
->visualID
;
1072 config
= config
->next
;
1075 Xfree((char *)props
);
1079 #ifdef GLX_DIRECT_RENDERING
1080 /* Initialize per screen dynamic client GLX extensions */
1081 psc
->ext_list_first_time
= GL_TRUE
;
1082 /* Initialize the direct rendering per screen data and functions */
1083 if (priv
->driDisplay
.private != NULL
) {
1084 /* FIXME: Should it be some sort of an error if createNewScreen[i]
1087 if (priv
->driDisplay
.createNewScreen
&&
1088 priv
->driDisplay
.createNewScreen
[i
]) {
1090 psc
->driScreen
.screenConfigs
= (void *)psc
;
1091 psc
->driScreen
.private =
1092 CallCreateNewScreen(dpy
, i
, & psc
->driScreen
,
1094 priv
->driDisplay
.createNewScreen
[i
] );
1104 ** Initialize the client side extension code.
1106 __GLXdisplayPrivate
*__glXInitialize(Display
* dpy
)
1108 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1109 XExtData
**privList
, *private, *found
;
1110 __GLXdisplayPrivate
*dpyPriv
;
1111 XEDataObject dataObj
;
1114 #if defined(XTHREADS)
1116 static int firstCall
= 1;
1118 /* initialize the GLX mutexes */
1119 xmutex_init(&__glXmutex
);
1126 /* The one and only long long lock */
1129 if (!XextHasExtension(info
)) {
1130 /* No GLX extension supported by this server. Oh well. */
1132 XMissingExtension(dpy
, __glXExtensionName
);
1136 /* See if a display private already exists. If so, return it */
1137 dataObj
.display
= dpy
;
1138 privList
= XEHeadOfExtensionList(dataObj
);
1139 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1142 return (__GLXdisplayPrivate
*) found
->private_data
;
1145 /* See if the versions are compatible */
1146 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
1147 /* The client and server do not agree on versions. Punt. */
1153 ** Allocate memory for all the pieces needed for this buffer.
1155 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
1160 dpyPriv
= (__GLXdisplayPrivate
*) Xmalloc(sizeof(__GLXdisplayPrivate
));
1163 Xfree((char*) private);
1168 ** Init the display private and then read in the screen config
1169 ** structures from the server.
1171 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
1172 dpyPriv
->majorVersion
= major
;
1173 dpyPriv
->minorVersion
= minor
;
1176 dpyPriv
->serverGLXvendor
= 0x0;
1177 dpyPriv
->serverGLXversion
= 0x0;
1179 #ifdef GLX_DIRECT_RENDERING
1181 ** Initialize the direct rendering per display data and functions.
1182 ** Note: This _must_ be done before calling any other DRI routines
1183 ** (e.g., those called in AllocAndFetchScreenConfigs).
1185 if (getenv("LIBGL_ALWAYS_INDIRECT")) {
1186 /* Assinging zero here assures we'll never go direct */
1187 dpyPriv
->driDisplay
.private = 0;
1188 dpyPriv
->driDisplay
.destroyDisplay
= 0;
1191 dpyPriv
->driDisplay
.private =
1192 driCreateDisplay(dpy
, &dpyPriv
->driDisplay
);
1196 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
1198 Xfree((char*) dpyPriv
);
1199 Xfree((char*) private);
1204 ** Fill in the private structure. This is the actual structure that
1205 ** hangs off of the Display structure. Our private structure is
1206 ** referred to by this structure. Got that?
1208 private->number
= info
->codes
->extension
;
1210 private->free_private
= __glXFreeDisplayPrivate
;
1211 private->private_data
= (char *) dpyPriv
;
1212 XAddToExtensionList(privList
, private);
1214 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
1215 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
1223 ** Setup for sending a GLX command on dpy. Make sure the extension is
1224 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
1226 CARD8
__glXSetupForCommand(Display
*dpy
)
1229 __GLXdisplayPrivate
*priv
;
1231 /* If this thread has a current context, flush its rendering commands */
1232 gc
= __glXGetCurrentContext();
1233 if (gc
->currentDpy
) {
1234 /* Flush rendering buffer of the current context, if any */
1235 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
1237 if (gc
->currentDpy
== dpy
) {
1238 /* Use opcode from gc because its right */
1240 return gc
->majorOpcode
;
1243 ** Have to get info about argument dpy because it might be to
1244 ** a different server
1249 /* Forced to lookup extension via the slow initialize route */
1250 priv
= __glXInitialize(dpy
);
1254 return priv
->majorOpcode
;
1258 * Flush the drawing command transport buffer.
1260 * \param ctx Context whose transport buffer is to be flushed.
1261 * \param pc Pointer to first unused buffer location.
1264 * Modify this function to use \c ctx->pc instead of the explicit
1267 GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*ctx
, GLubyte
*pc
)
1269 Display
* const dpy
= ctx
->currentDpy
;
1271 XCBConnection
*c
= XCBConnectionOfDisplay(dpy
);
1274 #endif /* USE_XCB */
1275 const GLint size
= pc
- ctx
->buf
;
1277 if ( (dpy
!= NULL
) && (size
> 0) ) {
1279 XCBGlxRender(c
, ctx
->currentContextTag
, size
, (char *)ctx
->buf
);
1281 /* Send the entire buffer as an X request */
1283 GetReq(GLXRender
,req
);
1284 req
->reqType
= ctx
->majorOpcode
;
1285 req
->glxCode
= X_GLXRender
;
1286 req
->contextTag
= ctx
->currentContextTag
;
1287 req
->length
+= (size
+ 3) >> 2;
1288 _XSend(dpy
, (char *)ctx
->buf
, size
);
1294 /* Reset pointer and return it */
1301 * Send a portion of a GLXRenderLarge command to the server. The advantage of
1302 * this function over \c __glXSendLargeCommand is that callers can use the
1303 * data buffer in the GLX context and may be able to avoid allocating an
1304 * extra buffer. The disadvantage is the clients will have to do more
1305 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
1307 * \sa __glXSendLargeCommand
1309 * \param gc GLX context
1310 * \param requestNumber Which part of the whole command is this? The first
1312 * \param totalRequests How many requests will there be?
1313 * \param data Command data.
1314 * \param dataLen Size, in bytes, of the command data.
1316 void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
1317 GLint totalRequests
,
1318 const GLvoid
* data
, GLint dataLen
)
1320 Display
*dpy
= gc
->currentDpy
;
1322 XCBConnection
*c
= XCBConnectionOfDisplay(dpy
);
1323 XCBGlxRenderLarge(c
, gc
->currentContextTag
, requestNumber
, totalRequests
, dataLen
, data
);
1325 xGLXRenderLargeReq
*req
;
1327 if ( requestNumber
== 1 ) {
1331 GetReq(GLXRenderLarge
,req
);
1332 req
->reqType
= gc
->majorOpcode
;
1333 req
->glxCode
= X_GLXRenderLarge
;
1334 req
->contextTag
= gc
->currentContextTag
;
1335 req
->length
+= (dataLen
+ 3) >> 2;
1336 req
->requestNumber
= requestNumber
;
1337 req
->requestTotal
= totalRequests
;
1338 req
->dataBytes
= dataLen
;
1339 Data(dpy
, data
, dataLen
);
1341 if ( requestNumber
== totalRequests
) {
1345 #endif /* USE_XCB */
1350 * Send a command that is too large for the GLXRender protocol request.
1352 * Send a large command, one that is too large for some reason to
1353 * send using the GLXRender protocol request. One reason to send
1354 * a large command is to avoid copying the data.
1356 * \param ctx GLX context
1357 * \param header Header data.
1358 * \param headerLen Size, in bytes, of the header data. It is assumed that
1359 * the header data will always be small enough to fit in
1360 * a single X protocol packet.
1361 * \param data Command data.
1362 * \param dataLen Size, in bytes, of the command data.
1364 void __glXSendLargeCommand(__GLXcontext
*ctx
,
1365 const GLvoid
*header
, GLint headerLen
,
1366 const GLvoid
*data
, GLint dataLen
)
1369 GLint totalRequests
, requestNumber
;
1372 ** Calculate the maximum amount of data can be stuffed into a single
1373 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1374 ** packet size minus sz_xGLXRenderReq.
1376 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1377 totalRequests
= 1 + (dataLen
/ maxSize
);
1378 if (dataLen
% maxSize
) totalRequests
++;
1381 ** Send all of the command, except the large array, as one request.
1383 assert( headerLen
<= maxSize
);
1384 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1387 ** Send enough requests until the whole array is sent.
1389 for ( requestNumber
= 2 ; requestNumber
<= (totalRequests
- 1) ; requestNumber
++ ) {
1390 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1391 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1393 assert( dataLen
> 0 );
1396 assert( dataLen
<= maxSize
);
1397 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1400 /************************************************************************/
1402 GLXContext
glXGetCurrentContext(void)
1404 GLXContext cx
= __glXGetCurrentContext();
1406 if (cx
== &dummyContext
) {
1413 GLXDrawable
glXGetCurrentDrawable(void)
1415 GLXContext gc
= __glXGetCurrentContext();
1416 return gc
->currentDrawable
;
1420 /************************************************************************/
1422 #ifdef GLX_DIRECT_RENDERING
1423 /* Return the DRI per screen structure */
1424 __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
)
1426 __DRIscreen
*pDRIScreen
= NULL
;
1427 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1428 XExtData
**privList
, *found
;
1429 __GLXdisplayPrivate
*dpyPriv
;
1430 XEDataObject dataObj
;
1433 dataObj
.display
= dpy
;
1434 privList
= XEHeadOfExtensionList(dataObj
);
1435 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1439 dpyPriv
= (__GLXdisplayPrivate
*)found
->private_data
;
1440 pDRIScreen
= &dpyPriv
->screenConfigs
[scrn
].driScreen
;
1447 /************************************************************************/
1449 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1450 GLXContextID gc
, GLXContextTag old_gc
, GLXDrawable draw
, GLXDrawable read
,
1451 xGLXMakeCurrentReply
* reply
);
1454 * Sends a GLX protocol message to the specified display to make the context
1455 * and the drawables current.
1457 * \param dpy Display to send the message to.
1458 * \param opcode Major opcode value for the display.
1459 * \param gc_id Context tag for the context to be made current.
1460 * \param draw Drawable ID for the "draw" drawable.
1461 * \param read Drawable ID for the "read" drawable.
1462 * \param reply Space to store the X-server's reply.
1465 * This function assumes that \c dpy is locked with \c LockDisplay on entry.
1467 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1468 GLXContextID gc_id
, GLXContextTag gc_tag
,
1469 GLXDrawable draw
, GLXDrawable read
,
1470 xGLXMakeCurrentReply
* reply
)
1472 if ( draw
== read
) {
1473 xGLXMakeCurrentReq
*req
;
1475 GetReq(GLXMakeCurrent
,req
);
1476 req
->reqType
= opcode
;
1477 req
->glxCode
= X_GLXMakeCurrent
;
1478 req
->drawable
= draw
;
1479 req
->context
= gc_id
;
1480 req
->oldContextTag
= gc_tag
;
1483 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1485 /* If the server can support the GLX 1.3 version, we should
1486 * perfer that. Not only that, some servers support GLX 1.3 but
1487 * not the SGI extension.
1490 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1491 xGLXMakeContextCurrentReq
*req
;
1493 GetReq(GLXMakeContextCurrent
,req
);
1494 req
->reqType
= opcode
;
1495 req
->glxCode
= X_GLXMakeContextCurrent
;
1496 req
->drawable
= draw
;
1497 req
->readdrawable
= read
;
1498 req
->context
= gc_id
;
1499 req
->oldContextTag
= gc_tag
;
1502 xGLXVendorPrivateWithReplyReq
*vpreq
;
1503 xGLXMakeCurrentReadSGIReq
*req
;
1505 GetReqExtra(GLXVendorPrivateWithReply
,
1506 sz_xGLXMakeCurrentReadSGIReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1507 req
= (xGLXMakeCurrentReadSGIReq
*)vpreq
;
1508 req
->reqType
= opcode
;
1509 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1510 req
->vendorCode
= X_GLXvop_MakeCurrentReadSGI
;
1511 req
->drawable
= draw
;
1512 req
->readable
= read
;
1513 req
->context
= gc_id
;
1514 req
->oldContextTag
= gc_tag
;
1518 return _XReply(dpy
, (xReply
*) reply
, 0, False
);
1522 #ifdef GLX_DIRECT_RENDERING
1523 static Bool
BindContextWrapper( Display
*dpy
, GLXContext gc
,
1524 GLXDrawable draw
, GLXDrawable read
)
1526 return (*gc
->driContext
.bindContext
)(dpy
, gc
->screen
, draw
, read
,
1531 static Bool
UnbindContextWrapper( GLXContext gc
)
1533 return (*gc
->driContext
.unbindContext
)(gc
->currentDpy
, gc
->screen
,
1534 gc
->currentDrawable
,
1535 gc
->currentReadable
,
1538 #endif /* GLX_DIRECT_RENDERING */
1542 ** Make a particular context current.
1543 ** NOTE: this is in this file so that it can access dummyContext.
1545 USED
static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
1546 GLXDrawable read
, GLXContext gc
)
1548 xGLXMakeCurrentReply reply
;
1550 CARD8 opcode
, oldOpcode
;
1551 Bool sentRequestToOldDpy
= False
;
1552 Bool bindReturnValue
= True
;
1554 opcode
= __glXSetupForCommand(dpy
);
1560 ** Make sure that the new context has a nonzero ID. In the request,
1561 ** a zero context ID is used only to mean that we bind to no current
1564 if ((gc
!= NULL
) && (gc
->xid
== None
)) {
1568 oldGC
= __glXGetCurrentContext();
1569 oldOpcode
= (gc
== oldGC
) ? opcode
: __glXSetupForCommand(dpy
);
1574 if ((dpy
!= oldGC
->currentDpy
|| (gc
&& gc
->isDirect
)) &&
1575 !oldGC
->isDirect
&& oldGC
!= &dummyContext
) {
1577 ** We are either switching from one dpy to another and have to
1578 ** send a request to the previous dpy to unbind the previous
1579 ** context, or we are switching away from a indirect context to
1580 ** a direct context and have to send a request to the dpy to
1581 ** unbind the previous context.
1583 sentRequestToOldDpy
= True
;
1584 LockDisplay(oldGC
->currentDpy
);
1585 if ( ! SendMakeCurrentRequest( oldGC
->currentDpy
, oldOpcode
, None
,
1586 oldGC
->currentContextTag
, None
, None
,
1588 /* The make current failed. Just return GL_FALSE. */
1589 UnlockDisplay(oldGC
->currentDpy
);
1594 oldGC
->currentContextTag
= 0;
1597 #ifdef GLX_DIRECT_RENDERING
1598 /* Unbind the old direct rendering context */
1599 if (oldGC
->isDirect
) {
1600 if (oldGC
->driContext
.private) {
1601 if (! UnbindContextWrapper( oldGC
)) {
1602 /* The make current failed. Just return GL_FALSE. */
1606 oldGC
->currentContextTag
= 0;
1609 /* Bind the direct rendering context to the drawable */
1610 if (gc
&& gc
->isDirect
) {
1611 if (gc
->driContext
.private) {
1612 bindReturnValue
= BindContextWrapper( dpy
, gc
, draw
, read
);
1616 _glapi_check_multithread();
1617 /* Send a glXMakeCurrent request to bind the new context. */
1620 bindReturnValue
= SendMakeCurrentRequest( dpy
, opcode
,
1621 gc
? gc
->xid
: None
,
1622 oldGC
->currentContextTag
,
1623 draw
, read
, &reply
);
1625 #ifdef GLX_DIRECT_RENDERING
1630 if (!bindReturnValue
) {
1631 /* The make current failed. */
1632 if (gc
&& !gc
->isDirect
) {
1636 #ifdef GLX_DIRECT_RENDERING
1637 /* If the old context was direct rendering, then re-bind to it. */
1638 if (oldGC
->isDirect
) {
1639 if (oldGC
->driContext
.private) {
1640 if (! BindContextWrapper( oldGC
->currentDpy
, oldGC
,
1641 oldGC
->currentDrawable
,
1642 oldGC
->currentReadable
)) {
1644 ** The request failed; this cannot happen with the
1645 ** current API. If in the future the API is
1646 ** extended to allow context sharing between
1647 ** clients, then this may fail (because another
1648 ** client may have grabbed the context); in that
1649 ** case, we cannot undo the previous request, and
1650 ** cannot adhere to the "no-op" behavior.
1657 ** If we had just sent a request to a previous dpy, we have to
1658 ** undo that request (because if a command fails, it should act
1659 ** like a no-op) by making current to the previous context and
1662 if (sentRequestToOldDpy
) {
1663 if ( !SendMakeCurrentRequest( oldGC
->currentDpy
, oldOpcode
,
1665 oldGC
->currentDrawable
,
1666 oldGC
->currentReadable
, &reply
) ) {
1667 UnlockDisplay(oldGC
->currentDpy
);
1670 ** The request failed; this cannot happen with the
1671 ** current API. If in the future the API is extended to
1672 ** allow context sharing between clients, then this may
1673 ** fail (because another client may have grabbed the
1674 ** context); in that case, we cannot undo the previous
1675 ** request, and cannot adhere to the "no-op" behavior.
1679 UnlockDisplay(oldGC
->currentDpy
);
1681 oldGC
->currentContextTag
= reply
.contextTag
;
1686 /* Update our notion of what is current */
1690 ** Even though the contexts are the same the drawable might have
1691 ** changed. Note that gc cannot be the dummy, and that oldGC
1692 ** cannot be NULL, therefore if they are the same, gc is not
1693 ** NULL and not the dummy.
1695 gc
->currentDrawable
= draw
;
1696 gc
->currentReadable
= read
;
1698 if (oldGC
!= &dummyContext
) {
1699 /* Old current context is no longer current to anybody */
1700 oldGC
->currentDpy
= 0;
1701 oldGC
->currentDrawable
= None
;
1702 oldGC
->currentReadable
= None
;
1703 oldGC
->currentContextTag
= 0;
1705 if (oldGC
->xid
== None
) {
1707 ** We are switching away from a context that was
1708 ** previously destroyed, so we need to free the memory
1709 ** for the old handle.
1711 #ifdef GLX_DIRECT_RENDERING
1712 /* Destroy the old direct rendering context */
1713 if (oldGC
->isDirect
) {
1714 if (oldGC
->driContext
.private) {
1715 (*oldGC
->driContext
.destroyContext
)
1716 (dpy
, oldGC
->screen
, oldGC
->driContext
.private);
1717 oldGC
->driContext
.private = NULL
;
1721 __glXFreeContext(oldGC
);
1725 __glXSetCurrentContext(gc
);
1726 #ifdef GLX_DIRECT_RENDERING
1727 if (!gc
->isDirect
) {
1729 IndirectAPI
= __glXNewIndirectAPI();
1730 _glapi_set_dispatch(IndirectAPI
);
1731 # ifdef GLX_USE_APPLEGL
1733 extern void XAppleDRIUseIndirectDispatch(void);
1734 XAppleDRIUseIndirectDispatch();
1739 /* if not direct rendering, always need indirect dispatch */
1741 IndirectAPI
= __glXNewIndirectAPI();
1742 _glapi_set_dispatch(IndirectAPI
);
1744 gc
->currentDpy
= dpy
;
1745 gc
->currentDrawable
= draw
;
1746 gc
->currentReadable
= read
;
1748 if ( ! gc
->isDirect
) {
1749 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1751 gc
->currentContextTag
= reply
.contextTag
;
1752 if ( state
->array_state
== NULL
) {
1753 (void) glGetString( GL_EXTENSIONS
);
1754 (void) glGetString( GL_VERSION
);
1755 __glXInitVertexArrayState(gc
);
1759 gc
->currentContextTag
= -1;
1762 __glXSetCurrentContext(&dummyContext
);
1763 #ifdef GLX_DIRECT_RENDERING
1764 _glapi_set_dispatch(NULL
); /* no-op functions */
1773 PUBLIC Bool
glXMakeCurrent(Display
*dpy
, GLXDrawable draw
, GLXContext gc
)
1775 return MakeContextCurrent( dpy
, draw
, draw
, gc
);
1778 PUBLIC
GLX_ALIAS(Bool
, glXMakeCurrentReadSGI
,
1779 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1780 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1782 PUBLIC
GLX_ALIAS(Bool
, glXMakeContextCurrent
,
1783 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1784 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1788 void __glXDumpDrawBuffer(__GLXcontext
*ctx
)
1790 GLubyte
*p
= ctx
->buf
;
1791 GLubyte
*end
= ctx
->pc
;
1792 GLushort opcode
, length
;
1796 opcode
= *((GLushort
*) p
);
1797 length
= *((GLushort
*) (p
+ 2));
1798 printf("%2x: %5d: ", opcode
, length
);
1801 while (length
> 0) {
1802 printf("%08x ", *((unsigned *) p
));
1811 #ifdef USE_SPARC_ASM
1813 * Used only when we are sparc, using sparc assembler.
1818 _glx_mesa_init_sparc_glapi_relocs(void)
1820 unsigned int *insn_ptr
, *end_ptr
;
1821 unsigned long disp_addr
;
1823 insn_ptr
= &_mesa_sparc_glapi_begin
;
1824 end_ptr
= &_mesa_sparc_glapi_end
;
1825 disp_addr
= (unsigned long) &_glapi_Dispatch
;
1828 * Verbatim from Mesa sparc.c. It's needed because there doesn't
1829 * seem to be a better way to do this:
1831 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1833 * This code is patching in the ADDRESS of the pointer to the
1834 * dispatch table. Hence, it must be called exactly once, because
1835 * that address is not going to change.
1837 * What it points to can change, but Mesa (and hence, we) assume
1838 * that there is only one pointer.
1841 while (insn_ptr
< end_ptr
) {
1842 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1844 This code patches for 64-bit addresses. This had better
1845 not happen for Sparc/Linux, no matter what architecture we
1846 are building for. So, don't do this.
1848 The 'defined(__linux_64__)' is used here as a placeholder for
1849 when we do do 64-bit usermode on sparc linux.
1851 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1852 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1853 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1854 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1855 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1856 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1859 insn_ptr
[0] |= (disp_addr
>> 10);
1860 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1861 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1866 #endif /* sparc ASM in use */