3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
11 ** http://oss.sgi.com/projects/FreeB
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
39 * GLX protocol interface boot-strap code.
41 * Direct rendering support added by Precision Insight, Inc.
43 * \author Kevin E. Martin <kevin@precisioninsight.com>
46 #include "glxclient.h"
48 #include <X11/extensions/Xext.h>
49 #include <X11/extensions/extutil.h>
50 #include <X11/extensions/Xfixes.h>
51 #include <X11/extensions/Xdamage.h>
53 #include "indirect_init.h"
55 #include "glxextensions.h"
56 #include "glcontextmodes.h"
59 #ifdef GLX_DIRECT_RENDERING
68 #include <X11/Xlib-xcb.h>
76 void __glXDumpDrawBuffer(__GLXcontext
*ctx
);
81 * This is where our dispatch table's bounds are.
82 * And the static mesa_init is taken directly from
83 * Mesa's 'sparc.c' initializer.
85 * We need something like this here, because this version
86 * of openGL/glx never initializes a Mesa context, and so
87 * the address of the dispatch table pointer never gets stuffed
88 * into the dispatch jump table otherwise.
90 * It matters only on SPARC, and only if you are using assembler
91 * code instead of C-code indirect dispatch.
95 extern unsigned int _mesa_sparc_glapi_begin
;
96 extern unsigned int _mesa_sparc_glapi_end
;
97 extern void __glapi_sparc_icache_flush(unsigned int *);
98 static void _glx_mesa_init_sparc_glapi_relocs(void);
99 static int _mesa_sparc_needs_init
= 1;
100 #define INIT_MESA_SPARC { \
101 if(_mesa_sparc_needs_init) { \
102 _glx_mesa_init_sparc_glapi_relocs(); \
103 _mesa_sparc_needs_init = 0; \
107 #define INIT_MESA_SPARC
110 #ifdef GLX_DIRECT_RENDERING
111 static __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
);
112 #endif /* GLX_DIRECT_RENDERING */
114 static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
115 GLXDrawable read
, GLXContext gc
);
118 ** We setup some dummy structures here so that the API can be used
119 ** even if no context is current.
122 static GLubyte dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
];
125 ** Dummy context used by small commands when there is no current context.
127 ** gl and glx entry points are designed to operate as nop's when using
128 ** the dummy context structure.
130 static __GLXcontext dummyContext
= {
134 &dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
],
140 ** All indirect rendering contexts will share the same indirect dispatch table.
142 static __GLapi
*IndirectAPI
= NULL
;
146 * Current context management and locking
149 #if defined( USE_XTHREADS )
152 static GLboolean TSDinitialized
= GL_FALSE
;
153 static xthread_key_t ContextTSD
;
155 __GLXcontext
*__glXGetCurrentContext(void)
157 if (!TSDinitialized
) {
158 xthread_key_create(&ContextTSD
, NULL
);
159 TSDinitialized
= GL_TRUE
;
160 return &dummyContext
;
164 xthread_get_specific(ContextTSD
, &p
);
166 return &dummyContext
;
168 return (__GLXcontext
*) p
;
172 void __glXSetCurrentContext(__GLXcontext
*c
)
174 if (!TSDinitialized
) {
175 xthread_key_create(&ContextTSD
, NULL
);
176 TSDinitialized
= GL_TRUE
;
178 xthread_set_specific(ContextTSD
, c
);
182 /* Used by the __glXLock() and __glXUnlock() macros */
183 xmutex_rec __glXmutex
;
185 #elif defined( PTHREADS )
187 pthread_mutex_t __glXmutex
= PTHREAD_MUTEX_INITIALIZER
;
189 # if defined( GLX_USE_TLS )
192 * Per-thread GLX context pointer.
194 * \c __glXSetCurrentContext is written is such a way that this pointer can
195 * \b never be \c NULL. This is important! Because of this
196 * \c __glXGetCurrentContext can be implemented as trivial macro.
198 __thread
void * __glX_tls_Context
__attribute__((tls_model("initial-exec")))
201 void __glXSetCurrentContext( __GLXcontext
* c
)
203 __glX_tls_Context
= (c
!= NULL
) ? c
: &dummyContext
;
208 static pthread_once_t once_control
= PTHREAD_ONCE_INIT
;
211 * Per-thread data key.
213 * Once \c init_thread_data has been called, the per-thread data key will
214 * take a value of \c NULL. As each new thread is created the default
215 * value, in that thread, will be \c NULL.
217 static pthread_key_t ContextTSD
;
220 * Initialize the per-thread data key.
222 * This function is called \b exactly once per-process (not per-thread!) to
223 * initialize the per-thread data key. This is ideally done using the
224 * \c pthread_once mechanism.
226 static void init_thread_data( void )
228 if ( pthread_key_create( & ContextTSD
, NULL
) != 0 ) {
229 perror( "pthread_key_create" );
234 void __glXSetCurrentContext( __GLXcontext
* c
)
236 pthread_once( & once_control
, init_thread_data
);
237 pthread_setspecific( ContextTSD
, c
);
240 __GLXcontext
* __glXGetCurrentContext( void )
244 pthread_once( & once_control
, init_thread_data
);
246 v
= pthread_getspecific( ContextTSD
);
247 return (v
== NULL
) ? & dummyContext
: (__GLXcontext
*) v
;
250 # endif /* defined( GLX_USE_TLS ) */
252 #elif defined( THREADS )
254 #error Unknown threading method specified.
258 /* not thread safe */
259 __GLXcontext
*__glXcurrentContext
= &dummyContext
;
265 ** You can set this cell to 1 to force the gl drawing stuff to be
266 ** one command per packet
271 ** forward prototype declarations
273 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
);
276 /************************************************************************/
278 /* Extension required boiler plate */
280 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
281 XExtensionInfo
*__glXExtensionInfo
= NULL
;
283 static /* const */ char *error_list
[] = {
285 "GLXBadContextState",
289 "GLXBadCurrentWindow",
290 "GLXBadRenderRequest",
291 "GLXBadLargeRequest",
292 "GLXUnsupportedPrivateRequest",
295 "GLXBadCurrentDrawable",
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 */
360 Xfree((char*) psc
->serverGLXexts
);
362 #ifdef GLX_DIRECT_RENDERING
363 /* Free the direct rendering per screen data */
364 if (psc
->driScreen
.private)
365 (*psc
->driScreen
.destroyScreen
)(priv
->dpy
, i
,
366 psc
->driScreen
.private);
367 psc
->driScreen
.private = NULL
;
370 XFree((char*) priv
->screenConfigs
);
374 ** Release the private memory referred to in a display private
375 ** structure. The caller will free the extension structure.
377 static int __glXFreeDisplayPrivate(XExtData
*extension
)
379 __GLXdisplayPrivate
*priv
;
381 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
382 FreeScreenConfigs(priv
);
383 if(priv
->serverGLXvendor
) {
384 Xfree((char*)priv
->serverGLXvendor
);
385 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
387 if(priv
->serverGLXversion
) {
388 Xfree((char*)priv
->serverGLXversion
);
389 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
392 #ifdef GLX_DIRECT_RENDERING
393 /* Free the direct rendering per display data */
394 if (priv
->driDisplay
.private)
395 (*priv
->driDisplay
.destroyDisplay
)(priv
->dpy
,
396 priv
->driDisplay
.private);
397 priv
->driDisplay
.private = NULL
;
398 if (priv
->driDisplay
.createNewScreen
) {
399 Xfree(priv
->driDisplay
.createNewScreen
); /* free array of ptrs */
400 priv
->driDisplay
.createNewScreen
= NULL
;
408 /************************************************************************/
411 ** Query the version of the GLX extension. This procedure works even if
412 ** the client extension is not completely set up.
414 static Bool
QueryVersion(Display
*dpy
, int opcode
, int *major
, int *minor
)
416 xGLXQueryVersionReq
*req
;
417 xGLXQueryVersionReply reply
;
419 /* Send the glXQueryVersion request */
421 GetReq(GLXQueryVersion
,req
);
422 req
->reqType
= opcode
;
423 req
->glxCode
= X_GLXQueryVersion
;
424 req
->majorVersion
= GLX_MAJOR_VERSION
;
425 req
->minorVersion
= GLX_MINOR_VERSION
;
426 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
430 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
432 ** The server does not support the same major release as this
437 *major
= reply
.majorVersion
;
438 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
444 __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
, int count
,
445 const INT32
*bp
, Bool tagged_only
,
446 Bool fbconfig_style_tags
)
451 /* Copy in the first set of properties */
452 config
->visualID
= *bp
++;
454 config
->visualType
= _gl_convert_from_x_visual_type( *bp
++ );
456 config
->rgbMode
= *bp
++;
458 config
->redBits
= *bp
++;
459 config
->greenBits
= *bp
++;
460 config
->blueBits
= *bp
++;
461 config
->alphaBits
= *bp
++;
462 config
->accumRedBits
= *bp
++;
463 config
->accumGreenBits
= *bp
++;
464 config
->accumBlueBits
= *bp
++;
465 config
->accumAlphaBits
= *bp
++;
467 config
->doubleBufferMode
= *bp
++;
468 config
->stereoMode
= *bp
++;
470 config
->rgbBits
= *bp
++;
471 config
->depthBits
= *bp
++;
472 config
->stencilBits
= *bp
++;
473 config
->numAuxBuffers
= *bp
++;
474 config
->level
= *bp
++;
476 count
-= __GLX_MIN_CONFIG_PROPS
;
480 ** Additional properties may be in a list at the end
481 ** of the reply. They are in pairs of property type
482 ** and property value.
485 #define FETCH_OR_SET(tag) \
486 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
488 for (i
= 0; i
< count
; i
+= 2 ) {
491 FETCH_OR_SET( rgbMode
);
493 case GLX_BUFFER_SIZE
:
494 config
->rgbBits
= *bp
++;
497 config
->level
= *bp
++;
499 case GLX_DOUBLEBUFFER
:
500 FETCH_OR_SET( doubleBufferMode
);
503 FETCH_OR_SET( stereoMode
);
505 case GLX_AUX_BUFFERS
:
506 config
->numAuxBuffers
= *bp
++;
509 config
->redBits
= *bp
++;
512 config
->greenBits
= *bp
++;
515 config
->blueBits
= *bp
++;
518 config
->alphaBits
= *bp
++;
521 config
->depthBits
= *bp
++;
523 case GLX_STENCIL_SIZE
:
524 config
->stencilBits
= *bp
++;
526 case GLX_ACCUM_RED_SIZE
:
527 config
->accumRedBits
= *bp
++;
529 case GLX_ACCUM_GREEN_SIZE
:
530 config
->accumGreenBits
= *bp
++;
532 case GLX_ACCUM_BLUE_SIZE
:
533 config
->accumBlueBits
= *bp
++;
535 case GLX_ACCUM_ALPHA_SIZE
:
536 config
->accumAlphaBits
= *bp
++;
538 case GLX_VISUAL_CAVEAT_EXT
:
539 config
->visualRating
= *bp
++;
541 case GLX_X_VISUAL_TYPE
:
542 config
->visualType
= *bp
++;
544 case GLX_TRANSPARENT_TYPE
:
545 config
->transparentPixel
= *bp
++;
547 case GLX_TRANSPARENT_INDEX_VALUE
:
548 config
->transparentIndex
= *bp
++;
550 case GLX_TRANSPARENT_RED_VALUE
:
551 config
->transparentRed
= *bp
++;
553 case GLX_TRANSPARENT_GREEN_VALUE
:
554 config
->transparentGreen
= *bp
++;
556 case GLX_TRANSPARENT_BLUE_VALUE
:
557 config
->transparentBlue
= *bp
++;
559 case GLX_TRANSPARENT_ALPHA_VALUE
:
560 config
->transparentAlpha
= *bp
++;
563 config
->visualID
= *bp
++;
565 case GLX_DRAWABLE_TYPE
:
566 config
->drawableType
= *bp
++;
568 case GLX_RENDER_TYPE
:
569 config
->renderType
= *bp
++;
571 case GLX_X_RENDERABLE
:
572 config
->xRenderable
= *bp
++;
574 case GLX_FBCONFIG_ID
:
575 config
->fbconfigID
= *bp
++;
577 case GLX_MAX_PBUFFER_WIDTH
:
578 config
->maxPbufferWidth
= *bp
++;
580 case GLX_MAX_PBUFFER_HEIGHT
:
581 config
->maxPbufferHeight
= *bp
++;
583 case GLX_MAX_PBUFFER_PIXELS
:
584 config
->maxPbufferPixels
= *bp
++;
586 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
587 config
->optimalPbufferWidth
= *bp
++;
589 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
590 config
->optimalPbufferHeight
= *bp
++;
592 case GLX_VISUAL_SELECT_GROUP_SGIX
:
593 config
->visualSelectGroup
= *bp
++;
595 case GLX_SWAP_METHOD_OML
:
596 config
->swapMethod
= *bp
++;
598 case GLX_SAMPLE_BUFFERS_SGIS
:
599 config
->sampleBuffers
= *bp
++;
601 case GLX_SAMPLES_SGIS
:
602 config
->samples
= *bp
++;
604 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
605 config
->bindToTextureRgb
= *bp
++;
607 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
608 config
->bindToTextureRgba
= *bp
++;
610 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
611 config
->bindToMipmapTexture
= *bp
++;
613 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
614 config
->bindToTextureTargets
= *bp
++;
616 case GLX_Y_INVERTED_EXT
:
617 config
->yInverted
= *bp
++;
627 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
629 config
->haveAccumBuffer
= ((config
->accumRedBits
+
630 config
->accumGreenBits
+
631 config
->accumBlueBits
+
632 config
->accumAlphaBits
) > 0);
633 config
->haveDepthBuffer
= (config
->depthBits
> 0);
634 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
638 #ifdef GLX_DIRECT_RENDERING
640 filter_modes( __GLcontextModes
** server_modes
,
641 const __GLcontextModes
* driver_modes
)
643 __GLcontextModes
* m
;
644 __GLcontextModes
** prev_next
;
645 const __GLcontextModes
* check
;
646 unsigned modes_count
= 0;
648 if ( driver_modes
== NULL
) {
649 fprintf(stderr
, "libGL warning: 3D driver returned no fbconfigs.\n");
653 /* For each mode in server_modes, check to see if a matching mode exists
654 * in driver_modes. If not, then the mode is not available.
657 prev_next
= server_modes
;
658 for ( m
= *prev_next
; m
!= NULL
; m
= *prev_next
) {
659 GLboolean do_delete
= GL_TRUE
;
661 for ( check
= driver_modes
; check
!= NULL
; check
= check
->next
) {
662 if ( _gl_context_modes_are_same( m
, check
) ) {
663 do_delete
= GL_FALSE
;
668 /* The 3D has to support all the modes that match the GLX visuals
669 * sent from the X server.
671 if ( do_delete
&& (m
->visualID
!= 0) ) {
672 do_delete
= GL_FALSE
;
674 fprintf(stderr
, "libGL warning: 3D driver claims to not support "
675 "visual 0x%02x\n", m
->visualID
);
679 *prev_next
= m
->next
;
682 _gl_context_modes_destroy( m
);
686 prev_next
= & m
->next
;
695 * Implement \c __DRIinterfaceMethods::getProcAddress.
697 static __DRIfuncPtr
get_proc_address( const char * proc_name
)
699 if (strcmp( proc_name
, "glxEnableExtension" ) == 0) {
700 return (__DRIfuncPtr
) __glXScrEnableExtension
;
706 #ifdef XDAMAGE_1_1_INTERFACE
707 static GLboolean
has_damage_post(__DRInativeDisplay
*dpy
)
709 static GLboolean inited
= GL_FALSE
;
710 static GLboolean has_damage
;
715 if (XDamageQueryVersion(dpy
, &major
, &minor
) &&
716 major
== 1 && minor
>= 1)
718 has_damage
= GL_TRUE
;
720 has_damage
= GL_FALSE
;
727 #endif /* XDAMAGE_1_1_INTERFACE */
729 static void __glXReportDamage(__DRInativeDisplay
*dpy
, int screen
,
732 drm_clip_rect_t
*rects
, int num_rects
,
733 GLboolean front_buffer
)
735 #ifdef XDAMAGE_1_1_INTERFACE
737 XserverRegion region
;
741 if (!has_damage_post(dpy
))
747 drawable
= RootWindow(dpy
, screen
);
753 xrects
= malloc(sizeof(XRectangle
) * num_rects
);
757 for (i
= 0; i
< num_rects
; i
++) {
758 xrects
[i
].x
= rects
[i
].x1
+ x_off
;
759 xrects
[i
].y
= rects
[i
].y1
+ y_off
;
760 xrects
[i
].width
= rects
[i
].x2
- rects
[i
].x1
;
761 xrects
[i
].height
= rects
[i
].y2
- rects
[i
].y1
;
763 region
= XFixesCreateRegion(dpy
, xrects
, num_rects
);
765 XDamageAdd(dpy
, drawable
, region
);
766 XFixesDestroyRegion(dpy
, region
);
771 * Table of functions exported by the loader to the driver.
773 static const __DRIinterfaceMethods interface_methods
= {
776 _gl_context_modes_create
,
777 _gl_context_modes_destroy
,
782 XF86DRICreateContextWithConfig
,
783 XF86DRIDestroyContext
,
785 XF86DRICreateDrawable
,
786 XF86DRIDestroyDrawable
,
787 XF86DRIGetDrawableInfo
,
798 * Perform the required libGL-side initialization and call the client-side
799 * driver's \c __driCreateNewScreen function.
801 * \param dpy Display pointer.
802 * \param scrn Screen number on the display.
803 * \param psc DRI screen information.
804 * \param driDpy DRI display information.
805 * \param createNewScreen Pointer to the client-side driver's
806 * \c __driCreateNewScreen function.
807 * \returns A pointer to the \c __DRIscreenPrivate structure returned by
808 * the client-side driver on success, or \c NULL on failure.
810 * \todo This function needs to be modified to remove context-modes from the
811 * list stored in the \c __GLXscreenConfigsRec to match the list
812 * returned by the client-side driver.
815 CallCreateNewScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
816 __DRIdisplay
* driDpy
,
817 PFNCREATENEWSCREENFUNC createNewScreen
)
819 __DRIscreenPrivate
*psp
= NULL
;
820 #ifndef GLX_USE_APPLEGL
822 drmAddress pSAREA
= MAP_FAILED
;
824 __DRIversion ddx_version
;
825 __DRIversion dri_version
;
826 __DRIversion drm_version
;
827 __DRIframebuffer framebuffer
;
830 const char * err_msg
;
831 const char * err_extra
;
832 int api_ver
= __glXGetInternalVersion();
835 dri_version
.major
= driDpy
->private->driMajor
;
836 dri_version
.minor
= driDpy
->private->driMinor
;
837 dri_version
.patch
= driDpy
->private->driPatch
;
840 err_msg
= "XF86DRIOpenConnection";
843 framebuffer
.base
= MAP_FAILED
;
844 framebuffer
.dev_priv
= NULL
;
846 if (XF86DRIOpenConnection(dpy
, scrn
, &hSAREA
, &BusID
)) {
848 fd
= drmOpenOnce(NULL
,BusID
, &newlyopened
);
849 Xfree(BusID
); /* No longer needed */
851 err_msg
= "open DRM";
852 err_extra
= strerror( -fd
);
857 err_msg
= "drmGetMagic";
860 if (!drmGetMagic(fd
, &magic
)) {
861 drmVersionPtr version
= drmGetVersion(fd
);
863 drm_version
.major
= version
->version_major
;
864 drm_version
.minor
= version
->version_minor
;
865 drm_version
.patch
= version
->version_patchlevel
;
866 drmFreeVersion(version
);
869 drm_version
.major
= -1;
870 drm_version
.minor
= -1;
871 drm_version
.patch
= -1;
874 err_msg
= "XF86DRIAuthConnection";
875 if (!newlyopened
|| XF86DRIAuthConnection(dpy
, scrn
, magic
)) {
879 * Get device name (like "tdfx") and the ddx version
880 * numbers. We'll check the version in each DRI driver's
881 * "createNewScreen" function.
883 err_msg
= "XF86DRIGetClientDriverName";
884 if (XF86DRIGetClientDriverName(dpy
, scrn
,
892 /* No longer needed. */
897 * Get device-specific info. pDevPriv will point to a struct
898 * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h)
899 * that has information about the screen size, depth, pitch,
900 * ancilliary buffers, DRM mmap handles, etc.
902 err_msg
= "XF86DRIGetDeviceInfo";
903 if (XF86DRIGetDeviceInfo(dpy
, scrn
,
908 &framebuffer
.dev_priv_size
,
909 &framebuffer
.dev_priv
)) {
910 framebuffer
.width
= DisplayWidth(dpy
, scrn
);
911 framebuffer
.height
= DisplayHeight(dpy
, scrn
);
914 * Map the framebuffer region.
916 status
= drmMap(fd
, hFB
, framebuffer
.size
,
917 (drmAddressPtr
)&framebuffer
.base
);
919 err_msg
= "drmMap of framebuffer";
920 err_extra
= strerror( -status
);
924 * Map the SAREA region. Further mmap regions
925 * may be setup in each DRI driver's
926 * "createNewScreen" function.
928 status
= drmMap(fd
, hSAREA
, SAREA_MAX
,
931 err_msg
= "drmMap of sarea";
932 err_extra
= strerror( -status
);
935 __GLcontextModes
* driver_modes
= NULL
;
936 __GLXscreenConfigs
*configs
= psc
->screenConfigs
;
938 err_msg
= "InitDriver";
940 psp
= (*createNewScreen
)(dpy
, scrn
,
953 filter_modes( & configs
->configs
,
955 _gl_context_modes_destroy( driver_modes
);
966 if ( pSAREA
!= MAP_FAILED
) {
967 (void)drmUnmap(pSAREA
, SAREA_MAX
);
970 if ( framebuffer
.base
!= MAP_FAILED
) {
971 (void)drmUnmap((drmAddress
)framebuffer
.base
, framebuffer
.size
);
974 if ( framebuffer
.dev_priv
!= NULL
) {
975 Xfree(framebuffer
.dev_priv
);
979 (void)drmCloseOnce(fd
);
982 (void)XF86DRICloseConnection(dpy
, scrn
);
984 if ( err_extra
!= NULL
) {
985 fprintf(stderr
, "libGL error: %s failed (%s)\n", err_msg
,
989 fprintf(stderr
, "libGL error: %s failed\n", err_msg
);
992 fprintf(stderr
, "libGL error: reverting to (slow) indirect rendering\n");
994 #endif /* !GLX_USE_APPLEGL */
998 #endif /* GLX_DIRECT_RENDERING */
1002 ** Allocate the memory for the per screen configs for each screen.
1003 ** If that works then fetch the per screen configs data.
1005 static Bool
AllocAndFetchScreenConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
)
1007 xGLXGetVisualConfigsReq
*req
;
1008 xGLXGetFBConfigsReq
*fb_req
;
1009 xGLXVendorPrivateWithReplyReq
*vpreq
;
1010 xGLXGetFBConfigsSGIXReq
*sgi_req
;
1011 xGLXGetVisualConfigsReply reply
;
1012 __GLXscreenConfigs
*psc
;
1013 __GLcontextModes
*config
;
1014 GLint i
, j
, nprops
, screens
;
1015 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
1016 unsigned supported_request
= 0;
1020 ** First allocate memory for the array of per screen configs.
1022 screens
= ScreenCount(dpy
);
1023 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
1027 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
1028 priv
->screenConfigs
= psc
;
1030 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1031 X_GLXQueryServerString
,
1033 if ( priv
->serverGLXversion
== NULL
) {
1034 FreeScreenConfigs(priv
);
1038 if ( atof( priv
->serverGLXversion
) >= 1.3 ) {
1039 supported_request
= 1;
1043 ** Now fetch each screens configs structures. If a screen supports
1044 ** GL (by returning a numVisuals > 0) then allocate memory for our
1045 ** config structure and then fill it in.
1047 for (i
= 0; i
< screens
; i
++, psc
++) {
1048 if ( supported_request
!= 1 ) {
1049 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1050 X_GLXQueryServerString
,
1052 if ( strstr( psc
->serverGLXexts
, "GLX_SGIX_fbconfig" ) != NULL
) {
1053 supported_request
= 2;
1056 supported_request
= 3;
1062 switch( supported_request
) {
1064 GetReq(GLXGetFBConfigs
,fb_req
);
1065 fb_req
->reqType
= priv
->majorOpcode
;
1066 fb_req
->glxCode
= X_GLXGetFBConfigs
;
1071 GetReqExtra(GLXVendorPrivateWithReply
,
1072 sz_xGLXGetFBConfigsSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1073 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
1074 sgi_req
->reqType
= priv
->majorOpcode
;
1075 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
1076 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
1077 sgi_req
->screen
= i
;
1081 GetReq(GLXGetVisualConfigs
,req
);
1082 req
->reqType
= priv
->majorOpcode
;
1083 req
->glxCode
= X_GLXGetVisualConfigs
;
1088 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
)) {
1089 /* Something is busted. Punt. */
1092 FreeScreenConfigs(priv
);
1096 if (!reply
.numVisuals
) {
1097 /* This screen does not support GL rendering */
1102 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for
1105 /* Check number of properties */
1106 nprops
= reply
.numProps
;
1107 if ((nprops
< __GLX_MIN_CONFIG_PROPS
) ||
1108 (nprops
> __GLX_MAX_CONFIG_PROPS
)) {
1109 /* Huh? Not in protocol defined limits. Punt */
1112 FreeScreenConfigs(priv
);
1116 /* Allocate memory for our config structure */
1117 psc
->configs
= _gl_context_modes_create(reply
.numVisuals
,
1118 sizeof(__GLcontextModes
));
1119 if (!psc
->configs
) {
1122 FreeScreenConfigs(priv
);
1126 /* Allocate memory for the properties, if needed */
1127 if ( supported_request
!= 3 ) {
1131 prop_size
= nprops
* __GLX_SIZE_INT32
;
1133 if (prop_size
<= sizeof(buf
)) {
1136 props
= (INT32
*) Xmalloc(prop_size
);
1139 /* Read each config structure and convert it into our format */
1140 config
= psc
->configs
;
1141 for (j
= 0; j
< reply
.numVisuals
; j
++) {
1142 assert( config
!= NULL
);
1143 _XRead(dpy
, (char *)props
, prop_size
);
1145 if ( supported_request
!= 3 ) {
1146 config
->rgbMode
= GL_TRUE
;
1147 config
->drawableType
= GLX_WINDOW_BIT
;
1150 config
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
1153 __glXInitializeVisualConfigFromTags( config
, nprops
, props
,
1154 (supported_request
!= 3),
1156 if ( config
->fbconfigID
== GLX_DONT_CARE
) {
1157 config
->fbconfigID
= config
->visualID
;
1160 config
= config
->next
;
1163 Xfree((char *)props
);
1167 #ifdef GLX_DIRECT_RENDERING
1168 /* Initialize per screen dynamic client GLX extensions */
1169 psc
->ext_list_first_time
= GL_TRUE
;
1170 /* Initialize the direct rendering per screen data and functions */
1171 if (priv
->driDisplay
.private != NULL
) {
1172 /* FIXME: Should it be some sort of an error if createNewScreen[i]
1175 if (priv
->driDisplay
.createNewScreen
&&
1176 priv
->driDisplay
.createNewScreen
[i
]) {
1178 psc
->driScreen
.screenConfigs
= (void *)psc
;
1179 psc
->driScreen
.private =
1180 CallCreateNewScreen(dpy
, i
, & psc
->driScreen
,
1182 priv
->driDisplay
.createNewScreen
[i
] );
1192 ** Initialize the client side extension code.
1194 __GLXdisplayPrivate
*__glXInitialize(Display
* dpy
)
1196 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1197 XExtData
**privList
, *private, *found
;
1198 __GLXdisplayPrivate
*dpyPriv
;
1199 XEDataObject dataObj
;
1202 #if defined(USE_XTHREADS)
1204 static int firstCall
= 1;
1206 /* initialize the GLX mutexes */
1207 xmutex_init(&__glXmutex
);
1214 /* The one and only long long lock */
1217 if (!XextHasExtension(info
)) {
1218 /* No GLX extension supported by this server. Oh well. */
1220 XMissingExtension(dpy
, __glXExtensionName
);
1224 /* See if a display private already exists. If so, return it */
1225 dataObj
.display
= dpy
;
1226 privList
= XEHeadOfExtensionList(dataObj
);
1227 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1230 return (__GLXdisplayPrivate
*) found
->private_data
;
1233 /* See if the versions are compatible */
1234 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
1235 /* The client and server do not agree on versions. Punt. */
1241 ** Allocate memory for all the pieces needed for this buffer.
1243 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
1248 dpyPriv
= (__GLXdisplayPrivate
*) Xcalloc(1, sizeof(__GLXdisplayPrivate
));
1251 Xfree((char*) private);
1256 ** Init the display private and then read in the screen config
1257 ** structures from the server.
1259 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
1260 dpyPriv
->majorVersion
= major
;
1261 dpyPriv
->minorVersion
= minor
;
1264 dpyPriv
->serverGLXvendor
= 0x0;
1265 dpyPriv
->serverGLXversion
= 0x0;
1267 #ifdef GLX_DIRECT_RENDERING
1269 ** Initialize the direct rendering per display data and functions.
1270 ** Note: This _must_ be done before calling any other DRI routines
1271 ** (e.g., those called in AllocAndFetchScreenConfigs).
1273 if (getenv("LIBGL_ALWAYS_INDIRECT") == NULL
) {
1274 dpyPriv
->driDisplay
.private =
1275 driCreateDisplay(dpy
, &dpyPriv
->driDisplay
);
1279 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
1281 Xfree((char*) dpyPriv
);
1282 Xfree((char*) private);
1287 ** Fill in the private structure. This is the actual structure that
1288 ** hangs off of the Display structure. Our private structure is
1289 ** referred to by this structure. Got that?
1291 private->number
= info
->codes
->extension
;
1293 private->free_private
= __glXFreeDisplayPrivate
;
1294 private->private_data
= (char *) dpyPriv
;
1295 XAddToExtensionList(privList
, private);
1297 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
1298 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
1306 ** Setup for sending a GLX command on dpy. Make sure the extension is
1307 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
1309 CARD8
__glXSetupForCommand(Display
*dpy
)
1312 __GLXdisplayPrivate
*priv
;
1314 /* If this thread has a current context, flush its rendering commands */
1315 gc
= __glXGetCurrentContext();
1316 if (gc
->currentDpy
) {
1317 /* Flush rendering buffer of the current context, if any */
1318 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
1320 if (gc
->currentDpy
== dpy
) {
1321 /* Use opcode from gc because its right */
1323 return gc
->majorOpcode
;
1326 ** Have to get info about argument dpy because it might be to
1327 ** a different server
1332 /* Forced to lookup extension via the slow initialize route */
1333 priv
= __glXInitialize(dpy
);
1337 return priv
->majorOpcode
;
1341 * Flush the drawing command transport buffer.
1343 * \param ctx Context whose transport buffer is to be flushed.
1344 * \param pc Pointer to first unused buffer location.
1347 * Modify this function to use \c ctx->pc instead of the explicit
1350 GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*ctx
, GLubyte
*pc
)
1352 Display
* const dpy
= ctx
->currentDpy
;
1354 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1357 #endif /* USE_XCB */
1358 const GLint size
= pc
- ctx
->buf
;
1360 if ( (dpy
!= NULL
) && (size
> 0) ) {
1362 xcb_glx_render(c
, ctx
->currentContextTag
, size
, (char *)ctx
->buf
);
1364 /* Send the entire buffer as an X request */
1366 GetReq(GLXRender
,req
);
1367 req
->reqType
= ctx
->majorOpcode
;
1368 req
->glxCode
= X_GLXRender
;
1369 req
->contextTag
= ctx
->currentContextTag
;
1370 req
->length
+= (size
+ 3) >> 2;
1371 _XSend(dpy
, (char *)ctx
->buf
, size
);
1377 /* Reset pointer and return it */
1384 * Send a portion of a GLXRenderLarge command to the server. The advantage of
1385 * this function over \c __glXSendLargeCommand is that callers can use the
1386 * data buffer in the GLX context and may be able to avoid allocating an
1387 * extra buffer. The disadvantage is the clients will have to do more
1388 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
1390 * \sa __glXSendLargeCommand
1392 * \param gc GLX context
1393 * \param requestNumber Which part of the whole command is this? The first
1395 * \param totalRequests How many requests will there be?
1396 * \param data Command data.
1397 * \param dataLen Size, in bytes, of the command data.
1399 void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
1400 GLint totalRequests
,
1401 const GLvoid
* data
, GLint dataLen
)
1403 Display
*dpy
= gc
->currentDpy
;
1405 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1406 xcb_glx_render_large(c
, gc
->currentContextTag
, requestNumber
, totalRequests
, dataLen
, data
);
1408 xGLXRenderLargeReq
*req
;
1410 if ( requestNumber
== 1 ) {
1414 GetReq(GLXRenderLarge
,req
);
1415 req
->reqType
= gc
->majorOpcode
;
1416 req
->glxCode
= X_GLXRenderLarge
;
1417 req
->contextTag
= gc
->currentContextTag
;
1418 req
->length
+= (dataLen
+ 3) >> 2;
1419 req
->requestNumber
= requestNumber
;
1420 req
->requestTotal
= totalRequests
;
1421 req
->dataBytes
= dataLen
;
1422 Data(dpy
, data
, dataLen
);
1424 if ( requestNumber
== totalRequests
) {
1428 #endif /* USE_XCB */
1433 * Send a command that is too large for the GLXRender protocol request.
1435 * Send a large command, one that is too large for some reason to
1436 * send using the GLXRender protocol request. One reason to send
1437 * a large command is to avoid copying the data.
1439 * \param ctx GLX context
1440 * \param header Header data.
1441 * \param headerLen Size, in bytes, of the header data. It is assumed that
1442 * the header data will always be small enough to fit in
1443 * a single X protocol packet.
1444 * \param data Command data.
1445 * \param dataLen Size, in bytes, of the command data.
1447 void __glXSendLargeCommand(__GLXcontext
*ctx
,
1448 const GLvoid
*header
, GLint headerLen
,
1449 const GLvoid
*data
, GLint dataLen
)
1452 GLint totalRequests
, requestNumber
;
1455 ** Calculate the maximum amount of data can be stuffed into a single
1456 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1457 ** packet size minus sz_xGLXRenderReq.
1459 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1460 totalRequests
= 1 + (dataLen
/ maxSize
);
1461 if (dataLen
% maxSize
) totalRequests
++;
1464 ** Send all of the command, except the large array, as one request.
1466 assert( headerLen
<= maxSize
);
1467 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1470 ** Send enough requests until the whole array is sent.
1472 for ( requestNumber
= 2 ; requestNumber
<= (totalRequests
- 1) ; requestNumber
++ ) {
1473 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1474 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1476 assert( dataLen
> 0 );
1479 assert( dataLen
<= maxSize
);
1480 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1483 /************************************************************************/
1485 PUBLIC GLXContext
glXGetCurrentContext(void)
1487 GLXContext cx
= __glXGetCurrentContext();
1489 if (cx
== &dummyContext
) {
1496 PUBLIC GLXDrawable
glXGetCurrentDrawable(void)
1498 GLXContext gc
= __glXGetCurrentContext();
1499 return gc
->currentDrawable
;
1503 /************************************************************************/
1505 #ifdef GLX_DIRECT_RENDERING
1506 /* Return the DRI per screen structure */
1507 __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
)
1509 __DRIscreen
*pDRIScreen
= NULL
;
1510 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1511 XExtData
**privList
, *found
;
1512 __GLXdisplayPrivate
*dpyPriv
;
1513 XEDataObject dataObj
;
1516 dataObj
.display
= dpy
;
1517 privList
= XEHeadOfExtensionList(dataObj
);
1518 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1522 dpyPriv
= (__GLXdisplayPrivate
*)found
->private_data
;
1523 pDRIScreen
= &dpyPriv
->screenConfigs
[scrn
].driScreen
;
1530 /************************************************************************/
1532 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1533 GLXContextID gc
, GLXContextTag old_gc
, GLXDrawable draw
, GLXDrawable read
,
1534 xGLXMakeCurrentReply
* reply
);
1537 * Sends a GLX protocol message to the specified display to make the context
1538 * and the drawables current.
1540 * \param dpy Display to send the message to.
1541 * \param opcode Major opcode value for the display.
1542 * \param gc_id Context tag for the context to be made current.
1543 * \param draw Drawable ID for the "draw" drawable.
1544 * \param read Drawable ID for the "read" drawable.
1545 * \param reply Space to store the X-server's reply.
1548 * This function assumes that \c dpy is locked with \c LockDisplay on entry.
1550 static Bool
SendMakeCurrentRequest(Display
*dpy
, CARD8 opcode
,
1551 GLXContextID gc_id
, GLXContextTag gc_tag
,
1552 GLXDrawable draw
, GLXDrawable read
,
1553 xGLXMakeCurrentReply
*reply
)
1561 xGLXMakeCurrentReq
*req
;
1563 GetReq(GLXMakeCurrent
,req
);
1564 req
->reqType
= opcode
;
1565 req
->glxCode
= X_GLXMakeCurrent
;
1566 req
->drawable
= draw
;
1567 req
->context
= gc_id
;
1568 req
->oldContextTag
= gc_tag
;
1571 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1573 /* If the server can support the GLX 1.3 version, we should
1574 * perfer that. Not only that, some servers support GLX 1.3 but
1575 * not the SGI extension.
1578 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1579 xGLXMakeContextCurrentReq
*req
;
1581 GetReq(GLXMakeContextCurrent
,req
);
1582 req
->reqType
= opcode
;
1583 req
->glxCode
= X_GLXMakeContextCurrent
;
1584 req
->drawable
= draw
;
1585 req
->readdrawable
= read
;
1586 req
->context
= gc_id
;
1587 req
->oldContextTag
= gc_tag
;
1590 xGLXVendorPrivateWithReplyReq
*vpreq
;
1591 xGLXMakeCurrentReadSGIReq
*req
;
1593 GetReqExtra(GLXVendorPrivateWithReply
,
1594 sz_xGLXMakeCurrentReadSGIReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1595 req
= (xGLXMakeCurrentReadSGIReq
*)vpreq
;
1596 req
->reqType
= opcode
;
1597 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1598 req
->vendorCode
= X_GLXvop_MakeCurrentReadSGI
;
1599 req
->drawable
= draw
;
1600 req
->readable
= read
;
1601 req
->context
= gc_id
;
1602 req
->oldContextTag
= gc_tag
;
1606 ret
= _XReply(dpy
, (xReply
*) reply
, 0, False
);
1615 #ifdef GLX_DIRECT_RENDERING
1616 static Bool
BindContextWrapper( Display
*dpy
, GLXContext gc
,
1617 GLXDrawable draw
, GLXDrawable read
)
1619 return (*gc
->driContext
.bindContext
)(dpy
, gc
->screen
, draw
, read
,
1624 static Bool
UnbindContextWrapper( GLXContext gc
)
1626 return (*gc
->driContext
.unbindContext
)(gc
->currentDpy
, gc
->screen
,
1627 gc
->currentDrawable
,
1628 gc
->currentReadable
,
1631 #endif /* GLX_DIRECT_RENDERING */
1635 * Make a particular context current.
1637 * \note This is in this file so that it can access dummyContext.
1639 USED
static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
1640 GLXDrawable read
, GLXContext gc
)
1642 xGLXMakeCurrentReply reply
;
1643 const GLXContext oldGC
= __glXGetCurrentContext();
1644 const CARD8 opcode
= __glXSetupForCommand(dpy
);
1645 const CARD8 oldOpcode
= ((gc
== oldGC
) || (oldGC
== &dummyContext
))
1646 ? opcode
: __glXSetupForCommand(oldGC
->currentDpy
);
1647 Bool bindReturnValue
;
1650 if (!opcode
|| !oldOpcode
) {
1654 /* Make sure that the new context has a nonzero ID. In the request,
1655 * a zero context ID is used only to mean that we bind to no current
1658 if ((gc
!= NULL
) && (gc
->xid
== None
)) {
1662 #ifndef GLX_DIRECT_RENDERING
1663 if (gc
&& gc
->isDirect
) {
1668 _glapi_check_multithread();
1670 #ifdef GLX_DIRECT_RENDERING
1671 /* Bind the direct rendering context to the drawable */
1672 if (gc
&& gc
->isDirect
) {
1673 bindReturnValue
= (gc
->driContext
.private)
1674 ? BindContextWrapper(dpy
, gc
, draw
, read
)
1679 /* Send a glXMakeCurrent request to bind the new context. */
1681 SendMakeCurrentRequest(dpy
, opcode
, gc
? gc
->xid
: None
,
1682 ((dpy
!= oldGC
->currentDpy
) || oldGC
->isDirect
)
1683 ? None
: oldGC
->currentContextTag
,
1684 draw
, read
, &reply
);
1688 if (!bindReturnValue
) {
1692 if ((dpy
!= oldGC
->currentDpy
|| (gc
&& gc
->isDirect
)) &&
1693 !oldGC
->isDirect
&& oldGC
!= &dummyContext
) {
1694 xGLXMakeCurrentReply dummy_reply
;
1696 /* We are either switching from one dpy to another and have to
1697 * send a request to the previous dpy to unbind the previous
1698 * context, or we are switching away from a indirect context to
1699 * a direct context and have to send a request to the dpy to
1700 * unbind the previous context.
1702 (void) SendMakeCurrentRequest(oldGC
->currentDpy
, oldOpcode
, None
,
1703 oldGC
->currentContextTag
, None
, None
,
1706 #ifdef GLX_DIRECT_RENDERING
1707 else if (oldGC
->isDirect
&& oldGC
->driContext
.private) {
1708 (void) UnbindContextWrapper(oldGC
);
1713 /* Update our notion of what is current */
1716 /* Even though the contexts are the same the drawable might have
1717 * changed. Note that gc cannot be the dummy, and that oldGC
1718 * cannot be NULL, therefore if they are the same, gc is not
1719 * NULL and not the dummy.
1721 gc
->currentDrawable
= draw
;
1722 gc
->currentReadable
= read
;
1724 if (oldGC
!= &dummyContext
) {
1725 /* Old current context is no longer current to anybody */
1726 oldGC
->currentDpy
= 0;
1727 oldGC
->currentDrawable
= None
;
1728 oldGC
->currentReadable
= None
;
1729 oldGC
->currentContextTag
= 0;
1731 if (oldGC
->xid
== None
) {
1732 /* We are switching away from a context that was
1733 * previously destroyed, so we need to free the memory
1734 * for the old handle.
1736 #ifdef GLX_DIRECT_RENDERING
1737 /* Destroy the old direct rendering context */
1738 if (oldGC
->isDirect
) {
1739 if (oldGC
->driContext
.private) {
1740 (*oldGC
->driContext
.destroyContext
)
1741 (dpy
, oldGC
->screen
, oldGC
->driContext
.private);
1742 oldGC
->driContext
.private = NULL
;
1746 __glXFreeContext(oldGC
);
1750 __glXSetCurrentContext(gc
);
1752 gc
->currentDpy
= dpy
;
1753 gc
->currentDrawable
= draw
;
1754 gc
->currentReadable
= read
;
1756 if (!gc
->isDirect
) {
1758 IndirectAPI
= __glXNewIndirectAPI();
1759 _glapi_set_dispatch(IndirectAPI
);
1761 #ifdef GLX_USE_APPLEGL
1763 extern void XAppleDRIUseIndirectDispatch(void);
1764 XAppleDRIUseIndirectDispatch();
1768 __GLXattribute
*state
=
1769 (__GLXattribute
*)(gc
->client_state_private
);
1771 gc
->currentContextTag
= reply
.contextTag
;
1772 if (state
->array_state
== NULL
) {
1773 (void) glGetString(GL_EXTENSIONS
);
1774 (void) glGetString(GL_VERSION
);
1775 __glXInitVertexArrayState(gc
);
1779 gc
->currentContextTag
= -1;
1782 __glXSetCurrentContext(&dummyContext
);
1783 #ifdef GLX_DIRECT_RENDERING
1784 _glapi_set_dispatch(NULL
); /* no-op functions */
1793 PUBLIC Bool
glXMakeCurrent(Display
*dpy
, GLXDrawable draw
, GLXContext gc
)
1795 return MakeContextCurrent( dpy
, draw
, draw
, gc
);
1798 PUBLIC
GLX_ALIAS(Bool
, glXMakeCurrentReadSGI
,
1799 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1800 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1802 PUBLIC
GLX_ALIAS(Bool
, glXMakeContextCurrent
,
1803 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1804 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1808 void __glXDumpDrawBuffer(__GLXcontext
*ctx
)
1810 GLubyte
*p
= ctx
->buf
;
1811 GLubyte
*end
= ctx
->pc
;
1812 GLushort opcode
, length
;
1816 opcode
= *((GLushort
*) p
);
1817 length
= *((GLushort
*) (p
+ 2));
1818 printf("%2x: %5d: ", opcode
, length
);
1821 while (length
> 0) {
1822 printf("%08x ", *((unsigned *) p
));
1831 #ifdef USE_SPARC_ASM
1833 * Used only when we are sparc, using sparc assembler.
1838 _glx_mesa_init_sparc_glapi_relocs(void)
1840 unsigned int *insn_ptr
, *end_ptr
;
1841 unsigned long disp_addr
;
1843 insn_ptr
= &_mesa_sparc_glapi_begin
;
1844 end_ptr
= &_mesa_sparc_glapi_end
;
1845 disp_addr
= (unsigned long) &_glapi_Dispatch
;
1848 * Verbatim from Mesa sparc.c. It's needed because there doesn't
1849 * seem to be a better way to do this:
1851 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1853 * This code is patching in the ADDRESS of the pointer to the
1854 * dispatch table. Hence, it must be called exactly once, because
1855 * that address is not going to change.
1857 * What it points to can change, but Mesa (and hence, we) assume
1858 * that there is only one pointer.
1861 while (insn_ptr
< end_ptr
) {
1862 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1864 This code patches for 64-bit addresses. This had better
1865 not happen for Sparc/Linux, no matter what architecture we
1866 are building for. So, don't do this.
1868 The 'defined(__linux_64__)' is used here as a placeholder for
1869 when we do do 64-bit usermode on sparc linux.
1871 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1872 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1873 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1874 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1875 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1876 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1879 insn_ptr
[0] |= (disp_addr
>> 10);
1880 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1881 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1886 #endif /* sparc ASM in use */