1 /************************************************************************** 2 * 3 * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 * USE OR OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * The above copyright notice and this permission notice (including the 23 * next paragraph) shall be included in all copies or substantial portions 24 * of the Software. 25 * 26 * 27 **************************************************************************/ 28 29 /* 30 * Authors: 31 * Keith Whitwell 32 */ 33 #include "pipe/p_compiler.h" 34 #include "util/u_debug.h" 35 #include "state_tracker/xlib_sw_winsys.h" 36 #include "xm_public.h" 37 38 #include "state_tracker/st_gl_api.h" 39 #include "target-helpers/inline_sw_helper.h" 40 #include "target-helpers/inline_debug_helper.h" 41 42 43 44 /* Helper function to build a subset of a driver stack consisting of 45 * one of the software rasterizers (llvmpipe, softpipe) and the 46 * xlib winsys. 47 */ 48 static struct pipe_screen * 49 swrast_xlib_create_screen( Display *display ) 50 { 51 struct sw_winsys *winsys; 52 struct pipe_screen *screen = NULL; 53 54 /* Create the underlying winsys, which performs presents to Xlib 55 * drawables: 56 */ 57 winsys = xlib_create_sw_winsys( display ); 58 if (winsys == NULL) 59 return NULL; 60 61 /* Create a software rasterizer on top of that winsys: 62 */ 63 screen = sw_screen_create( winsys ); 64 if (screen == NULL) 65 goto fail; 66 67 /* Inject any wrapping layers we want to here: 68 */ 69 return debug_screen_wrap( screen ); 70 71 fail: 72 if (winsys) 73 winsys->destroy( winsys ); 74 75 return NULL; 76 } 77 78 static struct xm_driver xlib_driver = 79 { 80 .create_pipe_screen = swrast_xlib_create_screen, 81 .create_st_api = st_gl_api_create, 82 }; 83 84 85 /* Build the rendering stack. 86 */ 87 static void _init( void ) __attribute__((constructor)); 88 static void _init( void ) 89 { 90 /* Initialize the xlib libgl code, pass in the winsys: 91 */ 92 xmesa_set_driver( &xlib_driver ); 93 } 94 95 96 /*********************************************************************** 97 * 98 * Butt-ugly hack to convince the linker not to throw away public GL 99 * symbols (they are all referenced from getprocaddress, I guess). 100 */ 101 extern void (*linker_foo(const unsigned char *procName))(); 102 extern void (*glXGetProcAddress(const unsigned char *procName))(); 103 104 extern void (*linker_foo(const unsigned char *procName))() 105 { 106 return glXGetProcAddress(procName); 107 } 108 109 110 /** 111 * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in 112 * libglapi.a. We need to define them here. 113 */ 114 #ifdef GLX_INDIRECT_RENDERING 115 116 #define GL_GLEXT_PROTOTYPES 117 #include "GL/gl.h" 118 #include "glapi/glapi.h" 119 #include "glapi/glapitable.h" 120 121 #if defined(USE_MGL_NAMESPACE) 122 #define NAME(func) mgl##func 123 #else 124 #define NAME(func) gl##func 125 #endif 126 127 #define DISPATCH(FUNC, ARGS, MESSAGE) \ 128 GET_DISPATCH()->FUNC ARGS 129 130 #define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \ 131 return GET_DISPATCH()->FUNC ARGS 132 133 /* skip normal ones */ 134 #define _GLAPI_SKIP_NORMAL_ENTRY_POINTS 135 #include "glapi/glapitemp.h" 136 137 #endif /* GLX_INDIRECT_RENDERING */ 138