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"
57 #include "glxextensions.h"
58 #include "glcontextmodes.h"
61 #ifdef GLX_DIRECT_RENDERING
72 void __glXDumpDrawBuffer(__GLXcontext
*ctx
);
77 * This is where our dispatch table's bounds are.
78 * And the static mesa_init is taken directly from
79 * Mesa's 'sparc.c' initializer.
81 * We need something like this here, because this version
82 * of openGL/glx never initializes a Mesa context, and so
83 * the address of the dispatch table pointer never gets stuffed
84 * into the dispatch jump table otherwise.
86 * It matters only on SPARC, and only if you are using assembler
87 * code instead of C-code indirect dispatch.
91 extern unsigned int _mesa_sparc_glapi_begin
;
92 extern unsigned int _mesa_sparc_glapi_end
;
93 extern void __glapi_sparc_icache_flush(unsigned int *);
94 static void _glx_mesa_init_sparc_glapi_relocs(void);
95 static int _mesa_sparc_needs_init
= 1;
96 #define INIT_MESA_SPARC { \
97 if(_mesa_sparc_needs_init) { \
98 _glx_mesa_init_sparc_glapi_relocs(); \
99 _mesa_sparc_needs_init = 0; \
103 #define INIT_MESA_SPARC
106 static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
107 GLXDrawable read
, GLXContext gc
);
110 ** We setup some dummy structures here so that the API can be used
111 ** even if no context is current.
114 static GLubyte dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
];
117 ** Dummy context used by small commands when there is no current context.
119 ** gl and glx entry points are designed to operate as nop's when using
120 ** the dummy context structure.
122 static __GLXcontext dummyContext
= {
126 &dummyBuffer
[__GLX_BUFFER_LIMIT_SIZE
],
132 ** All indirect rendering contexts will share the same indirect dispatch table.
134 static __GLapi
*IndirectAPI
= NULL
;
138 * Current context management and locking
141 #if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS)
144 static GLboolean TSDinitialized
= GL_FALSE
;
145 static xthread_key_t ContextTSD
;
147 __GLXcontext
*__glXGetCurrentContext(void)
149 if (!TSDinitialized
) {
150 xthread_key_create(&ContextTSD
, NULL
);
151 TSDinitialized
= GL_TRUE
;
152 return &dummyContext
;
156 xthread_get_specific(ContextTSD
, &p
);
158 return &dummyContext
;
160 return (__GLXcontext
*) p
;
164 void __glXSetCurrentContext(__GLXcontext
*c
)
166 if (!TSDinitialized
) {
167 xthread_key_create(&ContextTSD
, NULL
);
168 TSDinitialized
= GL_TRUE
;
170 xthread_set_specific(ContextTSD
, c
);
174 /* Used by the __glXLock() and __glXUnlock() macros */
175 xmutex_rec __glXmutex
;
179 /* not thread safe */
180 __GLXcontext
*__glXcurrentContext
= &dummyContext
;
186 ** You can set this cell to 1 to force the gl drawing stuff to be
187 ** one command per packet
192 ** forward prototype declarations
194 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
);
196 static GLboolean
FillInVisuals( __GLXscreenConfigs
* psc
);
198 /************************************************************************/
200 /* Extension required boiler plate */
202 static char *__glXExtensionName
= GLX_EXTENSION_NAME
;
203 XExtensionInfo
*__glXExtensionInfo
= NULL
;
205 static /* const */ char *error_list
[] = {
207 "GLXBadContextState",
211 "GLXBadCurrentWindow",
212 "GLXBadRenderRequest",
213 "GLXBadLargeRequest",
214 "GLXUnsupportedPrivateRequest",
217 int __glXCloseDisplay(Display
*dpy
, XExtCodes
*codes
)
221 gc
= __glXGetCurrentContext();
222 if (dpy
== gc
->currentDpy
) {
223 __glXSetCurrentContext(&dummyContext
);
224 #ifdef GLX_DIRECT_RENDERING
225 _glapi_set_dispatch(NULL
); /* no-op functions */
227 __glXFreeContext(gc
);
230 return XextRemoveDisplay(__glXExtensionInfo
, dpy
);
234 static XEXT_GENERATE_ERROR_STRING(__glXErrorString
, __glXExtensionName
,
235 __GLX_NUMBER_ERRORS
, error_list
)
237 static /* const */ XExtensionHooks __glXExtensionHooks
= {
238 NULL
, /* create_gc */
242 NULL
, /* create_font */
243 NULL
, /* free_font */
244 __glXCloseDisplay
, /* close_display */
245 NULL
, /* wire_to_event */
246 NULL
, /* event_to_wire */
248 __glXErrorString
, /* error_string */
252 XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay
, __glXExtensionInfo
,
253 __glXExtensionName
, &__glXExtensionHooks
,
254 __GLX_NUMBER_EVENTS
, NULL
)
256 /************************************************************************/
259 ** Free the per screen configs data as well as the array of
260 ** __glXScreenConfigs.
262 static void FreeScreenConfigs(__GLXdisplayPrivate
*priv
)
264 __GLXscreenConfigs
*psc
;
267 /* Free screen configuration information */
268 psc
= priv
->screenConfigs
;
269 screens
= ScreenCount(priv
->dpy
);
270 for (i
= 0; i
< screens
; i
++, psc
++) {
272 _gl_context_modes_destroy( psc
->configs
);
273 if(psc
->effectiveGLXexts
)
274 Xfree(psc
->effectiveGLXexts
);
276 if ( psc
->old_configs
!= NULL
) {
277 Xfree( psc
->old_configs
);
278 psc
->old_configs
= NULL
;
279 psc
->numOldConfigs
= 0;
282 psc
->configs
= NULL
; /* NOTE: just for paranoia */
285 #ifdef GLX_DIRECT_RENDERING
286 /* Free the direct rendering per screen data */
287 if (psc
->driScreen
.private)
288 (*psc
->driScreen
.destroyScreen
)(priv
->dpy
, i
,
289 psc
->driScreen
.private);
290 psc
->driScreen
.private = NULL
;
293 XFree((char*) priv
->screenConfigs
);
297 ** Release the private memory referred to in a display private
298 ** structure. The caller will free the extension structure.
300 static int __glXFreeDisplayPrivate(XExtData
*extension
)
302 __GLXdisplayPrivate
*priv
;
304 priv
= (__GLXdisplayPrivate
*) extension
->private_data
;
305 FreeScreenConfigs(priv
);
306 if(priv
->serverGLXvendor
) {
307 Xfree((char*)priv
->serverGLXvendor
);
308 priv
->serverGLXvendor
= 0x0; /* to protect against double free's */
310 if(priv
->serverGLXversion
) {
311 Xfree((char*)priv
->serverGLXversion
);
312 priv
->serverGLXversion
= 0x0; /* to protect against double free's */
315 #if 0 /* GLX_DIRECT_RENDERING */
316 /* Free the direct rendering per display data */
317 if (priv
->driDisplay
.private)
318 (*priv
->driDisplay
.destroyDisplay
)(priv
->dpy
,
319 priv
->driDisplay
.private);
320 priv
->driDisplay
.private = NULL
;
323 #ifdef GLX_DIRECT_RENDERING
324 XFree(priv
->driDisplay
.createScreen
);
331 /************************************************************************/
334 ** Query the version of the GLX extension. This procedure works even if
335 ** the client extension is not completely set up.
337 static Bool
QueryVersion(Display
*dpy
, int opcode
, int *major
, int *minor
)
339 xGLXQueryVersionReq
*req
;
340 xGLXQueryVersionReply reply
;
342 /* Send the glXQueryVersion request */
344 GetReq(GLXQueryVersion
,req
);
345 req
->reqType
= opcode
;
346 req
->glxCode
= X_GLXQueryVersion
;
347 req
->majorVersion
= GLX_MAJOR_VERSION
;
348 req
->minorVersion
= GLX_MINOR_VERSION
;
349 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
353 if (reply
.majorVersion
!= GLX_MAJOR_VERSION
) {
355 ** The server does not support the same major release as this
360 *major
= reply
.majorVersion
;
361 *minor
= min(reply
.minorVersion
, GLX_MINOR_VERSION
);
367 * Determine if a \c __GLcontextModes structure has the right mojo to be
368 * converted to a \c __GLXvisualConfig to be sent to an "old" style DRI
371 #define MODE_HAS_MOJO(m) \
372 ((m)->visualID != GLX_DONT_CARE) \
373 && ((m)->sampleBuffers == 0) \
374 && ((m)->samples == 0) \
375 && (((m)->drawableType & GLX_WINDOW_BIT) != 0) \
376 && (((m)->xRenderable == GL_TRUE) \
377 || ((m)->xRenderable == GLX_DONT_CARE))
381 * Convert the FBConfigs associated with a screen into an array of
382 * \c __GLXvisualConfig structures. These structures are passed into DRI
383 * drivers that use the "old" interface. The old-style drivers had a fairly
384 * strict set of visual types that could be supported. FBConfigs that
385 * cannot be supported are not converted.
387 * \param psc Screen whose FBConfigs need to be swizzled.
390 * If memory could be allocated and at least one FBConfig could be converted
391 * to a \c __GLXvisualConfig structure, \c GL_TRUE is returned. Otherwise,
392 * \c GL_FALSE is returned.
395 * When the old DRI driver interface is no longer supported, this function
399 FillInVisuals( __GLXscreenConfigs
* psc
)
401 __GLcontextModes
*modes
;
402 int glx_visual_count
;
405 glx_visual_count
= 0;
406 for ( modes
= psc
->configs
; modes
!= NULL
; modes
= modes
->next
) {
407 if ( MODE_HAS_MOJO( modes
) ) {
412 psc
->old_configs
= (__GLXvisualConfig
*)
413 Xmalloc( sizeof( __GLXvisualConfig
) * glx_visual_count
);
414 if ( psc
->old_configs
== NULL
) {
418 glx_visual_count
= 0;
419 for ( modes
= psc
->configs
; modes
!= NULL
; modes
= modes
->next
) {
420 if ( MODE_HAS_MOJO( modes
) ) {
422 #define COPY_VALUE(src_tag,dst_tag) \
423 psc->old_configs[glx_visual_count]. dst_tag = modes-> src_tag
425 COPY_VALUE( visualID
, vid
);
426 COPY_VALUE( rgbMode
, rgba
);
427 COPY_VALUE( stereoMode
, stereo
);
428 COPY_VALUE( doubleBufferMode
, doubleBuffer
);
430 psc
->old_configs
[glx_visual_count
].class =
431 _gl_convert_to_x_visual_type( modes
->visualType
);
433 COPY_VALUE( level
, level
);
434 COPY_VALUE( numAuxBuffers
, auxBuffers
);
436 COPY_VALUE( redBits
, redSize
);
437 COPY_VALUE( greenBits
, greenSize
);
438 COPY_VALUE( blueBits
, blueSize
);
439 COPY_VALUE( alphaBits
, alphaSize
);
440 COPY_VALUE( rgbBits
, bufferSize
);
441 COPY_VALUE( accumRedBits
, accumRedSize
);
442 COPY_VALUE( accumGreenBits
, accumGreenSize
);
443 COPY_VALUE( accumBlueBits
, accumBlueSize
);
444 COPY_VALUE( accumAlphaBits
, accumAlphaSize
);
445 COPY_VALUE( depthBits
, depthSize
);
446 COPY_VALUE( stencilBits
, stencilSize
);
448 COPY_VALUE( visualRating
, visualRating
);
449 COPY_VALUE( transparentPixel
, transparentPixel
);
450 COPY_VALUE( transparentRed
, transparentRed
);
451 COPY_VALUE( transparentGreen
, transparentGreen
);
452 COPY_VALUE( transparentBlue
, transparentBlue
);
453 COPY_VALUE( transparentAlpha
, transparentAlpha
);
454 COPY_VALUE( transparentIndex
, transparentIndex
);
462 psc
->numOldConfigs
= glx_visual_count
;
463 if ( glx_visual_count
== 0 ) {
464 Xfree( psc
->old_configs
);
465 psc
->old_configs
= NULL
;
468 return (glx_visual_count
!= 0);
473 __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
, int count
,
474 const INT32
*bp
, Bool tagged_only
,
475 Bool fbconfig_style_tags
)
480 /* Copy in the first set of properties */
481 config
->visualID
= *bp
++;
483 config
->visualType
= _gl_convert_from_x_visual_type( *bp
++ );
485 config
->rgbMode
= *bp
++;
487 config
->redBits
= *bp
++;
488 config
->greenBits
= *bp
++;
489 config
->blueBits
= *bp
++;
490 config
->alphaBits
= *bp
++;
491 config
->accumRedBits
= *bp
++;
492 config
->accumGreenBits
= *bp
++;
493 config
->accumBlueBits
= *bp
++;
494 config
->accumAlphaBits
= *bp
++;
496 config
->doubleBufferMode
= *bp
++;
497 config
->stereoMode
= *bp
++;
499 config
->rgbBits
= *bp
++;
500 config
->depthBits
= *bp
++;
501 config
->stencilBits
= *bp
++;
502 config
->numAuxBuffers
= *bp
++;
503 config
->level
= *bp
++;
505 count
-= __GLX_MIN_CONFIG_PROPS
;
509 ** Additional properties may be in a list at the end
510 ** of the reply. They are in pairs of property type
511 ** and property value.
514 #define FETCH_OR_SET(tag) \
515 config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1
517 for (i
= 0; i
< count
; i
+= 2 ) {
520 FETCH_OR_SET( rgbMode
);
522 case GLX_BUFFER_SIZE
:
523 config
->rgbBits
= *bp
++;
526 config
->level
= *bp
++;
528 case GLX_DOUBLEBUFFER
:
529 FETCH_OR_SET( doubleBufferMode
);
532 FETCH_OR_SET( stereoMode
);
534 case GLX_AUX_BUFFERS
:
535 config
->numAuxBuffers
= *bp
++;
538 config
->redBits
= *bp
++;
541 config
->greenBits
= *bp
++;
544 config
->blueBits
= *bp
++;
547 config
->alphaBits
= *bp
++;
550 config
->depthBits
= *bp
++;
552 case GLX_STENCIL_SIZE
:
553 config
->stencilBits
= *bp
++;
555 case GLX_ACCUM_RED_SIZE
:
556 config
->accumRedBits
= *bp
++;
558 case GLX_ACCUM_GREEN_SIZE
:
559 config
->accumGreenBits
= *bp
++;
561 case GLX_ACCUM_BLUE_SIZE
:
562 config
->accumBlueBits
= *bp
++;
564 case GLX_ACCUM_ALPHA_SIZE
:
565 config
->accumAlphaBits
= *bp
++;
567 case GLX_VISUAL_CAVEAT_EXT
:
568 config
->visualRating
= *bp
++;
570 case GLX_X_VISUAL_TYPE
:
571 config
->visualType
= *bp
++;
573 case GLX_TRANSPARENT_TYPE
:
574 config
->transparentPixel
= *bp
++;
576 case GLX_TRANSPARENT_INDEX_VALUE
:
577 config
->transparentIndex
= *bp
++;
579 case GLX_TRANSPARENT_RED_VALUE
:
580 config
->transparentRed
= *bp
++;
582 case GLX_TRANSPARENT_GREEN_VALUE
:
583 config
->transparentGreen
= *bp
++;
585 case GLX_TRANSPARENT_BLUE_VALUE
:
586 config
->transparentBlue
= *bp
++;
588 case GLX_TRANSPARENT_ALPHA_VALUE
:
589 config
->transparentAlpha
= *bp
++;
592 config
->visualID
= *bp
++;
594 case GLX_DRAWABLE_TYPE
:
595 config
->drawableType
= *bp
++;
597 case GLX_RENDER_TYPE
:
598 config
->renderType
= *bp
++;
600 case GLX_X_RENDERABLE
:
601 config
->xRenderable
= *bp
++;
603 case GLX_FBCONFIG_ID
:
604 config
->fbconfigID
= *bp
++;
606 case GLX_MAX_PBUFFER_WIDTH
:
607 config
->maxPbufferWidth
= *bp
++;
609 case GLX_MAX_PBUFFER_HEIGHT
:
610 config
->maxPbufferHeight
= *bp
++;
612 case GLX_MAX_PBUFFER_PIXELS
:
613 config
->maxPbufferPixels
= *bp
++;
615 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
616 config
->optimalPbufferWidth
= *bp
++;
618 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
619 config
->optimalPbufferHeight
= *bp
++;
621 case GLX_VISUAL_SELECT_GROUP_SGIX
:
622 config
->visualSelectGroup
= *bp
++;
624 case GLX_SWAP_METHOD_OML
:
625 config
->swapMethod
= *bp
++;
627 case GLX_SAMPLE_BUFFERS_SGIS
:
628 config
->sampleBuffers
= *bp
++;
630 case GLX_SAMPLES_SGIS
:
631 config
->samples
= *bp
++;
641 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
643 config
->haveAccumBuffer
= ((config
->accumRedBits
+
644 config
->accumGreenBits
+
645 config
->accumBlueBits
+
646 config
->accumAlphaBits
) > 0);
647 config
->haveDepthBuffer
= (config
->depthBits
> 0);
648 config
->haveStencilBuffer
= (config
->stencilBits
> 0);
652 #ifdef GLX_DIRECT_RENDERING
654 filter_modes( __GLcontextModes
** server_modes
,
655 const __GLcontextModes
* driver_modes
)
657 __GLcontextModes
* m
;
658 __GLcontextModes
** prev_next
;
659 const __GLcontextModes
* check
;
660 unsigned modes_count
= 0;
662 if ( driver_modes
== NULL
) {
663 fprintf(stderr
, "libGL warning: 3D driver returned no fbconfigs.\n");
667 /* For each mode in server_modes, check to see if a matching mode exists
668 * in driver_modes. If not, then the mode is not available.
671 prev_next
= server_modes
;
672 for ( m
= *prev_next
; m
!= NULL
; m
= *prev_next
) {
673 GLboolean do_delete
= GL_TRUE
;
675 for ( check
= driver_modes
; check
!= NULL
; check
= check
->next
) {
676 if ( _gl_context_modes_are_same( m
, check
) ) {
677 do_delete
= GL_FALSE
;
682 /* The 3D has to support all the modes that match the GLX visuals
683 * sent from the X server.
685 if ( do_delete
&& (m
->visualID
!= 0) ) {
686 do_delete
= GL_FALSE
;
688 fprintf(stderr
, "libGL warning: 3D driver claims to not support "
689 "visual 0x%02x\n", m
->visualID
);
693 *prev_next
= m
->next
;
696 _gl_context_modes_destroy( m
);
700 prev_next
= & m
->next
;
710 * Perform the required libGL-side initialization and call the client-side
711 * driver's \c __driCreateNewScreen function.
713 * \param dpy Display pointer.
714 * \param scrn Screen number on the display.
715 * \param psc DRI screen information.
716 * \param driDpy DRI display information.
717 * \param createNewScreen Pointer to the client-side driver's
718 * \c __driCreateNewScreen function.
719 * \returns A pointer to the \c __DRIscreenPrivate structure returned by
720 * the client-side driver on success, or \c NULL on failure.
722 * \todo This function needs to be modified to remove context-modes from the
723 * list stored in the \c __GLXscreenConfigsRec to match the list
724 * returned by the client-side driver.
727 CallCreateNewScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
728 __DRIdisplay
* driDpy
,
729 CreateNewScreenFunc createNewScreen
)
731 __DRIscreenPrivate
*psp
= NULL
;
732 #ifndef GLX_USE_APPLEGL
736 __DRIversion ddx_version
;
737 __DRIversion dri_version
;
738 __DRIversion drm_version
;
739 __DRIframebuffer framebuffer
;
742 const char * err_msg
;
743 const char * err_extra
;
744 int api_ver
= __glXGetInternalVersion();
747 dri_version
.major
= driDpy
->private->driMajor
;
748 dri_version
.minor
= driDpy
->private->driMinor
;
749 dri_version
.patch
= driDpy
->private->driPatch
;
752 err_msg
= "XF86DRIOpenConnection";
755 framebuffer
.dev_priv
= NULL
;
757 if (XF86DRIOpenConnection(dpy
, scrn
, &hSAREA
, &BusID
)) {
758 fd
= drmOpen(NULL
,BusID
);
759 Xfree(BusID
); /* No longer needed */
761 err_msg
= "open DRM";
762 err_extra
= strerror( -fd
);
767 err_msg
= "drmGetMagic";
770 if (!drmGetMagic(fd
, &magic
)) {
771 drmVersionPtr version
= drmGetVersion(fd
);
773 drm_version
.major
= version
->version_major
;
774 drm_version
.minor
= version
->version_minor
;
775 drm_version
.patch
= version
->version_patchlevel
;
776 drmFreeVersion(version
);
779 drm_version
.major
= -1;
780 drm_version
.minor
= -1;
781 drm_version
.patch
= -1;
784 err_msg
= "XF86DRIAuthConnection";
785 if (XF86DRIAuthConnection(dpy
, scrn
, magic
)) {
789 * Get device name (like "tdfx") and the ddx version numbers.
790 * We'll check the version in each DRI driver's "createScreen"
793 err_msg
= "XF86DRIGetClientDriverName";
794 if (XF86DRIGetClientDriverName(dpy
, scrn
,
802 /* No longer needed. */
807 * Get device-specific info. pDevPriv will point to a struct
808 * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h)
809 * that has information about the screen size, depth, pitch,
810 * ancilliary buffers, DRM mmap handles, etc.
812 err_msg
= "XF86DRIGetDeviceInfo";
813 if (XF86DRIGetDeviceInfo(dpy
, scrn
,
818 &framebuffer
.dev_priv_size
,
819 &framebuffer
.dev_priv
)) {
820 framebuffer
.width
= DisplayWidth(dpy
, scrn
);
821 framebuffer
.height
= DisplayHeight(dpy
, scrn
);
824 * Map the framebuffer region.
826 status
= drmMap(fd
, hFB
, framebuffer
.size
,
827 (drmAddressPtr
)&framebuffer
.base
);
829 err_msg
= "drmMap of framebuffer";
830 err_extra
= strerror( -status
);
834 * Map the SAREA region. Further mmap regions may be setup in
835 * each DRI driver's "createScreen" function.
837 status
= drmMap(fd
, hSAREA
, SAREA_MAX
,
840 err_msg
= "drmMap of sarea";
841 err_extra
= strerror( -status
);
844 __GLcontextModes
* driver_modes
= NULL
;
845 __GLXscreenConfigs
*configs
= psc
->screenConfigs
;
847 err_msg
= "InitDriver";
849 psp
= (*createNewScreen
)(dpy
, scrn
,
861 filter_modes( & configs
->configs
,
863 _gl_context_modes_destroy( driver_modes
);
874 if ( pSAREA
!= MAP_FAILED
) {
875 (void)drmUnmap(pSAREA
, SAREA_MAX
);
878 if ( framebuffer
.base
!= MAP_FAILED
) {
879 (void)drmUnmap((drmAddress
)framebuffer
.base
, framebuffer
.size
);
882 if ( framebuffer
.dev_priv
!= NULL
) {
883 Xfree(framebuffer
.dev_priv
);
890 (void)XF86DRICloseConnection(dpy
, scrn
);
892 if ( err_extra
!= NULL
) {
893 fprintf(stderr
, "libGL error: %s failed (%s)\n", err_msg
,
897 fprintf(stderr
, "libGL error: %s failed\n", err_msg
);
900 fprintf(stderr
, "libGL error: reverting to (slow) indirect rendering\n");
902 #endif /* !GLX_USE_APPLEGL */
906 #endif /* GLX_DIRECT_RENDERING */
910 ** Allocate the memory for the per screen configs for each screen.
911 ** If that works then fetch the per screen configs data.
913 static Bool
AllocAndFetchScreenConfigs(Display
*dpy
, __GLXdisplayPrivate
*priv
)
915 xGLXGetVisualConfigsReq
*req
;
916 xGLXGetFBConfigsReq
*fb_req
;
917 xGLXVendorPrivateWithReplyReq
*vpreq
;
918 xGLXGetFBConfigsSGIXReq
*sgi_req
;
919 xGLXGetVisualConfigsReply reply
;
920 __GLXscreenConfigs
*psc
;
921 __GLcontextModes
*config
;
922 GLint i
, j
, nprops
, screens
;
923 INT32 buf
[__GLX_TOTAL_CONFIG
], *props
;
924 unsigned supported_request
= 0;
928 ** First allocate memory for the array of per screen configs.
930 screens
= ScreenCount(dpy
);
931 psc
= (__GLXscreenConfigs
*) Xmalloc(screens
* sizeof(__GLXscreenConfigs
));
935 memset(psc
, 0, screens
* sizeof(__GLXscreenConfigs
));
936 priv
->screenConfigs
= psc
;
938 priv
->serverGLXversion
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
939 X_GLXQueryServerString
,
941 if ( priv
->serverGLXversion
== NULL
) {
942 FreeScreenConfigs(priv
);
946 if ( atof( priv
->serverGLXversion
) >= 1.3 ) {
947 supported_request
= 1;
951 ** Now fetch each screens configs structures. If a screen supports
952 ** GL (by returning a numVisuals > 0) then allocate memory for our
953 ** config structure and then fill it in.
955 for (i
= 0; i
< screens
; i
++, psc
++) {
956 if ( supported_request
!= 1 ) {
957 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
958 X_GLXQueryServerString
,
960 if ( strstr( psc
->serverGLXexts
, "GLX_SGIX_fbconfig" ) != NULL
) {
961 supported_request
= 2;
964 supported_request
= 3;
970 switch( supported_request
) {
972 GetReq(GLXGetFBConfigs
,fb_req
);
973 fb_req
->reqType
= priv
->majorOpcode
;
974 fb_req
->glxCode
= X_GLXGetFBConfigs
;
979 GetReqExtra(GLXVendorPrivateWithReply
,
980 sz_xGLXGetFBConfigsSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
981 sgi_req
= (xGLXGetFBConfigsSGIXReq
*) vpreq
;
982 sgi_req
->reqType
= priv
->majorOpcode
;
983 sgi_req
->glxCode
= X_GLXVendorPrivateWithReply
;
984 sgi_req
->vendorCode
= X_GLXvop_GetFBConfigsSGIX
;
989 GetReq(GLXGetVisualConfigs
,req
);
990 req
->reqType
= priv
->majorOpcode
;
991 req
->glxCode
= X_GLXGetVisualConfigs
;
996 if (!_XReply(dpy
, (xReply
*) &reply
, 0, False
)) {
997 /* Something is busted. Punt. */
999 FreeScreenConfigs(priv
);
1004 if (!reply
.numVisuals
) {
1005 /* This screen does not support GL rendering */
1010 /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for
1013 /* Check number of properties */
1014 nprops
= reply
.numProps
;
1015 if ((nprops
< __GLX_MIN_CONFIG_PROPS
) ||
1016 (nprops
> __GLX_MAX_CONFIG_PROPS
)) {
1017 /* Huh? Not in protocol defined limits. Punt */
1020 FreeScreenConfigs(priv
);
1024 /* Allocate memory for our config structure */
1025 psc
->configs
= _gl_context_modes_create(reply
.numVisuals
,
1026 sizeof(__GLcontextModes
));
1027 if (!psc
->configs
) {
1030 FreeScreenConfigs(priv
);
1034 /* Allocate memory for the properties, if needed */
1035 if ( supported_request
!= 3 ) {
1039 prop_size
= nprops
* __GLX_SIZE_INT32
;
1041 if (prop_size
<= sizeof(buf
)) {
1044 props
= (INT32
*) Xmalloc(prop_size
);
1047 /* Read each config structure and convert it into our format */
1048 config
= psc
->configs
;
1049 for (j
= 0; j
< reply
.numVisuals
; j
++) {
1050 assert( config
!= NULL
);
1051 _XRead(dpy
, (char *)props
, prop_size
);
1053 if ( supported_request
!= 3 ) {
1054 config
->rgbMode
= GL_TRUE
;
1055 config
->drawableType
= GLX_WINDOW_BIT
;
1058 config
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
1061 __glXInitializeVisualConfigFromTags( config
, nprops
, props
,
1062 (supported_request
!= 3),
1064 if ( config
->fbconfigID
== GLX_DONT_CARE
) {
1065 config
->fbconfigID
= config
->visualID
;
1068 config
= config
->next
;
1071 Xfree((char *)props
);
1075 #ifdef GLX_DIRECT_RENDERING
1076 /* Initialize per screen dynamic client GLX extensions */
1077 psc
->ext_list_first_time
= GL_TRUE
;
1078 /* Initialize the direct rendering per screen data and functions */
1079 if (priv
->driDisplay
.private != NULL
) {
1080 if (priv
->driDisplay
.createNewScreen
&&
1081 priv
->driDisplay
.createNewScreen
[i
]) {
1083 psc
->driScreen
.screenConfigs
= (void *)psc
;
1084 psc
->driScreen
.private =
1085 CallCreateNewScreen(dpy
, i
, & psc
->driScreen
,
1087 priv
->driDisplay
.createNewScreen
[i
] );
1089 else if (priv
->driDisplay
.createScreen
&&
1090 priv
->driDisplay
.createScreen
[i
]) {
1091 /* screen initialization (bootstrap the driver) */
1092 if ( (psc
->old_configs
== NULL
)
1093 && !FillInVisuals(psc
) ) {
1094 FreeScreenConfigs(priv
);
1098 psc
->driScreen
.screenConfigs
= (void *)psc
;
1099 psc
->driScreen
.private =
1100 (*(priv
->driDisplay
.createScreen
[i
]))(dpy
, i
, &psc
->driScreen
,
1112 ** Initialize the client side extension code.
1114 __GLXdisplayPrivate
*__glXInitialize(Display
* dpy
)
1116 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1117 XExtData
**privList
, *private, *found
;
1118 __GLXdisplayPrivate
*dpyPriv
;
1119 XEDataObject dataObj
;
1122 #if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS)
1124 static int firstCall
= 1;
1126 /* initialize the GLX mutexes */
1127 xmutex_init(&__glXmutex
);
1134 /* The one and only long long lock */
1137 if (!XextHasExtension(info
)) {
1138 /* No GLX extension supported by this server. Oh well. */
1140 XMissingExtension(dpy
, __glXExtensionName
);
1144 /* See if a display private already exists. If so, return it */
1145 dataObj
.display
= dpy
;
1146 privList
= XEHeadOfExtensionList(dataObj
);
1147 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1150 return (__GLXdisplayPrivate
*) found
->private_data
;
1153 /* See if the versions are compatible */
1154 if (!QueryVersion(dpy
, info
->codes
->major_opcode
, &major
, &minor
)) {
1155 /* The client and server do not agree on versions. Punt. */
1161 ** Allocate memory for all the pieces needed for this buffer.
1163 private = (XExtData
*) Xmalloc(sizeof(XExtData
));
1168 dpyPriv
= (__GLXdisplayPrivate
*) Xmalloc(sizeof(__GLXdisplayPrivate
));
1171 Xfree((char*) private);
1176 ** Init the display private and then read in the screen config
1177 ** structures from the server.
1179 dpyPriv
->majorOpcode
= info
->codes
->major_opcode
;
1180 dpyPriv
->majorVersion
= major
;
1181 dpyPriv
->minorVersion
= minor
;
1184 dpyPriv
->serverGLXvendor
= 0x0;
1185 dpyPriv
->serverGLXversion
= 0x0;
1187 #ifdef GLX_DIRECT_RENDERING
1189 ** Initialize the direct rendering per display data and functions.
1190 ** Note: This _must_ be done before calling any other DRI routines
1191 ** (e.g., those called in AllocAndFetchScreenConfigs).
1193 if (getenv("LIBGL_ALWAYS_INDIRECT")) {
1194 /* Assinging zero here assures we'll never go direct */
1195 dpyPriv
->driDisplay
.private = 0;
1196 dpyPriv
->driDisplay
.destroyDisplay
= 0;
1197 dpyPriv
->driDisplay
.createScreen
= 0;
1200 dpyPriv
->driDisplay
.private =
1201 driCreateDisplay(dpy
, &dpyPriv
->driDisplay
);
1205 if (!AllocAndFetchScreenConfigs(dpy
, dpyPriv
)) {
1207 Xfree((char*) dpyPriv
);
1208 Xfree((char*) private);
1213 ** Fill in the private structure. This is the actual structure that
1214 ** hangs off of the Display structure. Our private structure is
1215 ** referred to by this structure. Got that?
1217 private->number
= info
->codes
->extension
;
1219 private->free_private
= __glXFreeDisplayPrivate
;
1220 private->private_data
= (char *) dpyPriv
;
1221 XAddToExtensionList(privList
, private);
1223 if (dpyPriv
->majorVersion
== 1 && dpyPriv
->minorVersion
>= 1) {
1224 __glXClientInfo(dpy
, dpyPriv
->majorOpcode
);
1232 ** Setup for sending a GLX command on dpy. Make sure the extension is
1233 ** initialized. Try to avoid calling __glXInitialize as its kinda slow.
1235 CARD8
__glXSetupForCommand(Display
*dpy
)
1238 __GLXdisplayPrivate
*priv
;
1240 /* If this thread has a current context, flush its rendering commands */
1241 gc
= __glXGetCurrentContext();
1242 if (gc
->currentDpy
) {
1243 /* Flush rendering buffer of the current context, if any */
1244 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
1246 if (gc
->currentDpy
== dpy
) {
1247 /* Use opcode from gc because its right */
1249 return gc
->majorOpcode
;
1252 ** Have to get info about argument dpy because it might be to
1253 ** a different server
1258 /* Forced to lookup extension via the slow initialize route */
1259 priv
= __glXInitialize(dpy
);
1263 return priv
->majorOpcode
;
1267 * Flush the drawing command transport buffer.
1269 * \param ctx Context whose transport buffer is to be flushed.
1270 * \param pc Pointer to first unused buffer location.
1273 * Modify this function to use \c ctx->pc instead of the explicit
1276 GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*ctx
, GLubyte
*pc
)
1278 Display
* const dpy
= ctx
->currentDpy
;
1280 const GLint size
= pc
- ctx
->buf
;
1282 if ( (dpy
!= NULL
) && (size
> 0) ) {
1283 /* Send the entire buffer as an X request */
1285 GetReq(GLXRender
,req
);
1286 req
->reqType
= ctx
->majorOpcode
;
1287 req
->glxCode
= X_GLXRender
;
1288 req
->contextTag
= ctx
->currentContextTag
;
1289 req
->length
+= (size
+ 3) >> 2;
1290 _XSend(dpy
, (char *)ctx
->buf
, size
);
1295 /* Reset pointer and return it */
1302 * Send a portion of a GLXRenderLarge command to the server. The advantage of
1303 * this function over \c __glXSendLargeCommand is that callers can use the
1304 * data buffer in the GLX context and may be able to avoid allocating an
1305 * extra buffer. The disadvantage is the clients will have to do more
1306 * GLX protocol work (i.e., calculating \c totalRequests, etc.).
1308 * \sa __glXSendLargeCommand
1310 * \param gc GLX context
1311 * \param requestNumber Which part of the whole command is this? The first
1313 * \param totalRequests How many requests will there be?
1314 * \param data Command data.
1315 * \param dataLen Size, in bytes, of the command data.
1317 void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
1318 GLint totalRequests
,
1319 const GLvoid
* data
, GLint dataLen
)
1321 Display
*dpy
= gc
->currentDpy
;
1322 xGLXRenderLargeReq
*req
;
1324 if ( requestNumber
== 1 ) {
1328 GetReq(GLXRenderLarge
,req
);
1329 req
->reqType
= gc
->majorOpcode
;
1330 req
->glxCode
= X_GLXRenderLarge
;
1331 req
->contextTag
= gc
->currentContextTag
;
1332 req
->length
+= (dataLen
+ 3) >> 2;
1333 req
->requestNumber
= requestNumber
;
1334 req
->requestTotal
= totalRequests
;
1335 req
->dataBytes
= dataLen
;
1336 Data(dpy
, data
, dataLen
);
1338 if ( requestNumber
== totalRequests
) {
1346 * Send a command that is too large for the GLXRender protocol request.
1348 * Send a large command, one that is too large for some reason to
1349 * send using the GLXRender protocol request. One reason to send
1350 * a large command is to avoid copying the data.
1352 * \param ctx GLX context
1353 * \param header Header data.
1354 * \param headerLen Size, in bytes, of the header data. It is assumed that
1355 * the header data will always be small enough to fit in
1356 * a single X protocol packet.
1357 * \param data Command data.
1358 * \param dataLen Size, in bytes, of the command data.
1360 void __glXSendLargeCommand(__GLXcontext
*ctx
,
1361 const GLvoid
*header
, GLint headerLen
,
1362 const GLvoid
*data
, GLint dataLen
)
1365 GLint totalRequests
, requestNumber
;
1368 ** Calculate the maximum amount of data can be stuffed into a single
1369 ** packet. sz_xGLXRenderReq is added because bufSize is the maximum
1370 ** packet size minus sz_xGLXRenderReq.
1372 maxSize
= (ctx
->bufSize
+ sz_xGLXRenderReq
) - sz_xGLXRenderLargeReq
;
1373 totalRequests
= 1 + (dataLen
/ maxSize
);
1374 if (dataLen
% maxSize
) totalRequests
++;
1377 ** Send all of the command, except the large array, as one request.
1379 assert( headerLen
<= maxSize
);
1380 __glXSendLargeChunk(ctx
, 1, totalRequests
, header
, headerLen
);
1383 ** Send enough requests until the whole array is sent.
1385 for ( requestNumber
= 2 ; requestNumber
<= (totalRequests
- 1) ; requestNumber
++ ) {
1386 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, maxSize
);
1387 data
= (const GLvoid
*) (((const GLubyte
*) data
) + maxSize
);
1389 assert( dataLen
> 0 );
1392 assert( dataLen
<= maxSize
);
1393 __glXSendLargeChunk(ctx
, requestNumber
, totalRequests
, data
, dataLen
);
1396 /************************************************************************/
1398 GLXContext
glXGetCurrentContext(void)
1400 GLXContext cx
= __glXGetCurrentContext();
1402 if (cx
== &dummyContext
) {
1409 GLXDrawable
glXGetCurrentDrawable(void)
1411 GLXContext gc
= __glXGetCurrentContext();
1412 return gc
->currentDrawable
;
1416 /************************************************************************/
1418 #ifdef GLX_DIRECT_RENDERING
1419 /* Return the DRI per screen structure */
1420 __DRIscreen
*__glXFindDRIScreen(__DRInativeDisplay
*dpy
, int scrn
)
1422 __DRIscreen
*pDRIScreen
= NULL
;
1423 XExtDisplayInfo
*info
= __glXFindDisplay(dpy
);
1424 XExtData
**privList
, *found
;
1425 __GLXdisplayPrivate
*dpyPriv
;
1426 XEDataObject dataObj
;
1429 dataObj
.display
= dpy
;
1430 privList
= XEHeadOfExtensionList(dataObj
);
1431 found
= XFindOnExtensionList(privList
, info
->codes
->extension
);
1435 dpyPriv
= (__GLXdisplayPrivate
*)found
->private_data
;
1436 pDRIScreen
= &dpyPriv
->screenConfigs
[scrn
].driScreen
;
1443 /************************************************************************/
1445 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1446 GLXContextID gc
, GLXContextTag old_gc
, GLXDrawable draw
, GLXDrawable read
,
1447 xGLXMakeCurrentReply
* reply
);
1450 * Sends a GLX protocol message to the specified display to make the context
1451 * and the drawables current.
1453 * \param dpy Display to send the message to.
1454 * \param opcode Major opcode value for the display.
1455 * \param gc_id Context tag for the context to be made current.
1456 * \param draw Drawable ID for the "draw" drawable.
1457 * \param read Drawable ID for the "read" drawable.
1458 * \param reply Space to store the X-server's reply.
1461 * This function assumes that \c dpy is locked with \c LockDisplay on entry.
1463 static Bool
SendMakeCurrentRequest( Display
*dpy
, CARD8 opcode
,
1464 GLXContextID gc_id
, GLXContextTag gc_tag
,
1465 GLXDrawable draw
, GLXDrawable read
,
1466 xGLXMakeCurrentReply
* reply
)
1468 if ( draw
== read
) {
1469 xGLXMakeCurrentReq
*req
;
1471 GetReq(GLXMakeCurrent
,req
);
1472 req
->reqType
= opcode
;
1473 req
->glxCode
= X_GLXMakeCurrent
;
1474 req
->drawable
= draw
;
1475 req
->context
= gc_id
;
1476 req
->oldContextTag
= gc_tag
;
1479 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1481 /* If the server can support the GLX 1.3 version, we should
1482 * perfer that. Not only that, some servers support GLX 1.3 but
1483 * not the SGI extension.
1486 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1487 xGLXMakeContextCurrentReq
*req
;
1489 GetReq(GLXMakeContextCurrent
,req
);
1490 req
->reqType
= opcode
;
1491 req
->glxCode
= X_GLXMakeContextCurrent
;
1492 req
->drawable
= draw
;
1493 req
->readdrawable
= read
;
1494 req
->context
= gc_id
;
1495 req
->oldContextTag
= gc_tag
;
1498 xGLXVendorPrivateWithReplyReq
*vpreq
;
1499 xGLXMakeCurrentReadSGIReq
*req
;
1501 GetReqExtra(GLXVendorPrivateWithReply
,
1502 sz_xGLXMakeCurrentReadSGIReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
1503 req
= (xGLXMakeCurrentReadSGIReq
*)vpreq
;
1504 req
->reqType
= opcode
;
1505 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1506 req
->vendorCode
= X_GLXvop_MakeCurrentReadSGI
;
1507 req
->drawable
= draw
;
1508 req
->readable
= read
;
1509 req
->context
= gc_id
;
1510 req
->oldContextTag
= gc_tag
;
1514 return _XReply(dpy
, (xReply
*) reply
, 0, False
);
1518 static Bool
BindContextWrapper( Display
*dpy
, GLXContext gc
,
1519 GLXDrawable draw
, GLXDrawable read
)
1521 #ifdef GLX_DIRECT_RENDERING
1522 if ( gc
->driContext
.bindContext3
!= NULL
) {
1523 return (*gc
->driContext
.bindContext3
)(dpy
, gc
->screen
, draw
, read
,
1527 return (*gc
->driContext
.bindContext2
)(dpy
, gc
->screen
, draw
, read
,
1536 static Bool
UnbindContextWrapper( Display
*dpy
, GLXContext gc
)
1538 #ifdef GLX_DIRECT_RENDERING
1539 if ( gc
->driContext
.unbindContext3
!= NULL
) {
1540 return (*gc
->driContext
.unbindContext3
)(dpy
, gc
->screen
,
1541 gc
->currentDrawable
,
1542 gc
->currentReadable
,
1546 return (*gc
->driContext
.unbindContext2
)(dpy
, gc
->screen
,
1547 gc
->currentDrawable
,
1548 gc
->currentReadable
, gc
);
1557 ** Make a particular context current.
1558 ** NOTE: this is in this file so that it can access dummyContext.
1560 USED
static Bool
MakeContextCurrent(Display
*dpy
, GLXDrawable draw
,
1561 GLXDrawable read
, GLXContext gc
)
1563 xGLXMakeCurrentReply reply
;
1565 CARD8 opcode
, oldOpcode
;
1566 Bool sentRequestToOldDpy
= False
;
1567 Bool bindReturnValue
= True
;
1569 opcode
= __glXSetupForCommand(dpy
);
1575 ** Make sure that the new context has a nonzero ID. In the request,
1576 ** a zero context ID is used only to mean that we bind to no current
1579 if ((gc
!= NULL
) && (gc
->xid
== None
)) {
1583 oldGC
= __glXGetCurrentContext();
1584 oldOpcode
= (gc
== oldGC
) ? opcode
: __glXSetupForCommand(dpy
);
1589 if ((dpy
!= oldGC
->currentDpy
|| (gc
&& gc
->isDirect
)) &&
1590 !oldGC
->isDirect
&& oldGC
!= &dummyContext
) {
1592 ** We are either switching from one dpy to another and have to
1593 ** send a request to the previous dpy to unbind the previous
1594 ** context, or we are switching away from a indirect context to
1595 ** a direct context and have to send a request to the dpy to
1596 ** unbind the previous context.
1598 sentRequestToOldDpy
= True
;
1599 LockDisplay(oldGC
->currentDpy
);
1600 if ( ! SendMakeCurrentRequest( oldGC
->currentDpy
, oldOpcode
, None
,
1601 oldGC
->currentContextTag
, None
, None
,
1603 /* The make current failed. Just return GL_FALSE. */
1604 UnlockDisplay(oldGC
->currentDpy
);
1609 oldGC
->currentContextTag
= 0;
1612 #ifdef GLX_DIRECT_RENDERING
1613 /* Unbind the old direct rendering context */
1614 if (oldGC
->isDirect
) {
1615 if (oldGC
->driContext
.private) {
1616 if (! UnbindContextWrapper( oldGC
->currentDpy
, oldGC
)) {
1617 /* The make current failed. Just return GL_FALSE. */
1621 oldGC
->currentContextTag
= 0;
1624 /* Bind the direct rendering context to the drawable */
1625 if (gc
&& gc
->isDirect
) {
1626 if (gc
->driContext
.private) {
1627 bindReturnValue
= BindContextWrapper( dpy
, gc
, draw
, read
);
1631 _glapi_check_multithread();
1632 /* Send a glXMakeCurrent request to bind the new context. */
1635 bindReturnValue
= SendMakeCurrentRequest( dpy
, opcode
,
1636 gc
? gc
->xid
: None
,
1637 oldGC
->currentContextTag
,
1638 draw
, read
, &reply
);
1640 #ifdef GLX_DIRECT_RENDERING
1645 if (!bindReturnValue
) {
1646 /* The make current failed. */
1647 if (gc
&& !gc
->isDirect
) {
1651 #ifdef GLX_DIRECT_RENDERING
1652 /* If the old context was direct rendering, then re-bind to it. */
1653 if (oldGC
->isDirect
) {
1654 if (oldGC
->driContext
.private) {
1655 if (! BindContextWrapper( oldGC
->currentDpy
, oldGC
,
1656 oldGC
->currentDrawable
,
1657 oldGC
->currentReadable
)) {
1659 ** The request failed; this cannot happen with the
1660 ** current API. If in the future the API is
1661 ** extended to allow context sharing between
1662 ** clients, then this may fail (because another
1663 ** client may have grabbed the context); in that
1664 ** case, we cannot undo the previous request, and
1665 ** cannot adhere to the "no-op" behavior.
1672 ** If we had just sent a request to a previous dpy, we have to
1673 ** undo that request (because if a command fails, it should act
1674 ** like a no-op) by making current to the previous context and
1677 if (sentRequestToOldDpy
) {
1678 if ( !SendMakeCurrentRequest( oldGC
->currentDpy
, oldOpcode
,
1680 oldGC
->currentDrawable
,
1681 oldGC
->currentReadable
, &reply
) ) {
1682 UnlockDisplay(oldGC
->currentDpy
);
1685 ** The request failed; this cannot happen with the
1686 ** current API. If in the future the API is extended to
1687 ** allow context sharing between clients, then this may
1688 ** fail (because another client may have grabbed the
1689 ** context); in that case, we cannot undo the previous
1690 ** request, and cannot adhere to the "no-op" behavior.
1694 UnlockDisplay(oldGC
->currentDpy
);
1696 oldGC
->currentContextTag
= reply
.contextTag
;
1701 /* Update our notion of what is current */
1705 ** Even though the contexts are the same the drawable might have
1706 ** changed. Note that gc cannot be the dummy, and that oldGC
1707 ** cannot be NULL, therefore if they are the same, gc is not
1708 ** NULL and not the dummy.
1710 gc
->currentDrawable
= draw
;
1711 gc
->currentReadable
= read
;
1713 if (oldGC
!= &dummyContext
) {
1714 /* Old current context is no longer current to anybody */
1715 oldGC
->currentDpy
= 0;
1716 oldGC
->currentDrawable
= None
;
1717 oldGC
->currentReadable
= None
;
1718 oldGC
->currentContextTag
= 0;
1720 if (oldGC
->xid
== None
) {
1722 ** We are switching away from a context that was
1723 ** previously destroyed, so we need to free the memory
1724 ** for the old handle.
1726 #ifdef GLX_DIRECT_RENDERING
1727 /* Destroy the old direct rendering context */
1728 if (oldGC
->isDirect
) {
1729 if (oldGC
->driContext
.private) {
1730 (*oldGC
->driContext
.destroyContext
)
1731 (dpy
, oldGC
->screen
, oldGC
->driContext
.private);
1732 oldGC
->driContext
.private = NULL
;
1736 __glXFreeContext(oldGC
);
1740 __glXSetCurrentContext(gc
);
1741 #ifdef GLX_DIRECT_RENDERING
1742 if (!gc
->isDirect
) {
1744 IndirectAPI
= __glXNewIndirectAPI();
1745 _glapi_set_dispatch(IndirectAPI
);
1746 # ifdef GLX_USE_APPLEGL
1748 extern void XAppleDRIUseIndirectDispatch(void);
1749 XAppleDRIUseIndirectDispatch();
1754 /* if not direct rendering, always need indirect dispatch */
1756 IndirectAPI
= __glXNewIndirectAPI();
1757 _glapi_set_dispatch(IndirectAPI
);
1759 gc
->currentDpy
= dpy
;
1760 gc
->currentDrawable
= draw
;
1761 gc
->currentReadable
= read
;
1762 #ifdef GLX_DIRECT_RENDERING
1763 if (gc
->isDirect
) reply
.contextTag
= -1;
1765 gc
->currentContextTag
= reply
.contextTag
;
1767 __glXSetCurrentContext(&dummyContext
);
1768 #ifdef GLX_DIRECT_RENDERING
1769 _glapi_set_dispatch(NULL
); /* no-op functions */
1778 PUBLIC Bool
GLX_PREFIX(glXMakeCurrent
)(Display
*dpy
, GLXDrawable draw
,
1781 return MakeContextCurrent( dpy
, draw
, draw
, gc
);
1784 PUBLIC
GLX_ALIAS(Bool
, glXMakeCurrentReadSGI
,
1785 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1786 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1788 PUBLIC
GLX_ALIAS(Bool
, glXMakeContextCurrent
,
1789 (Display
*dpy
, GLXDrawable d
, GLXDrawable r
, GLXContext ctx
),
1790 (dpy
, d
, r
, ctx
), MakeContextCurrent
)
1794 void __glXDumpDrawBuffer(__GLXcontext
*ctx
)
1796 GLubyte
*p
= ctx
->buf
;
1797 GLubyte
*end
= ctx
->pc
;
1798 GLushort opcode
, length
;
1802 opcode
= *((GLushort
*) p
);
1803 length
= *((GLushort
*) (p
+ 2));
1804 printf("%2x: %5d: ", opcode
, length
);
1807 while (length
> 0) {
1808 printf("%08x ", *((unsigned *) p
));
1817 #ifdef USE_SPARC_ASM
1819 * Used only when we are sparc, using sparc assembler.
1824 _glx_mesa_init_sparc_glapi_relocs(void)
1826 unsigned int *insn_ptr
, *end_ptr
;
1827 unsigned long disp_addr
;
1829 insn_ptr
= &_mesa_sparc_glapi_begin
;
1830 end_ptr
= &_mesa_sparc_glapi_end
;
1831 disp_addr
= (unsigned long) &_glapi_Dispatch
;
1834 * Verbatim from Mesa sparc.c. It's needed because there doesn't
1835 * seem to be a better way to do this:
1837 * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
1839 * This code is patching in the ADDRESS of the pointer to the
1840 * dispatch table. Hence, it must be called exactly once, because
1841 * that address is not going to change.
1843 * What it points to can change, but Mesa (and hence, we) assume
1844 * that there is only one pointer.
1847 while (insn_ptr
< end_ptr
) {
1848 #if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
1850 This code patches for 64-bit addresses. This had better
1851 not happen for Sparc/Linux, no matter what architecture we
1852 are building for. So, don't do this.
1854 The 'defined(__linux_64__)' is used here as a placeholder for
1855 when we do do 64-bit usermode on sparc linux.
1857 insn_ptr
[0] |= (disp_addr
>> (32 + 10));
1858 insn_ptr
[1] |= ((disp_addr
& 0xffffffff) >> 10);
1859 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1860 insn_ptr
[2] |= ((disp_addr
>> 32) & ((1 << 10) - 1));
1861 insn_ptr
[3] |= (disp_addr
& ((1 << 10) - 1));
1862 __glapi_sparc_icache_flush(&insn_ptr
[2]);
1865 insn_ptr
[0] |= (disp_addr
>> 10);
1866 insn_ptr
[1] |= (disp_addr
& ((1 << 10) - 1));
1867 __glapi_sparc_icache_flush(&insn_ptr
[0]);
1872 #endif /* sparc ASM in use */