ws/xlib: remove self-knowledge about users of xlib winsys
[mesa.git] / src / gallium / targets / libgl-xlib / xlib.c
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
34 #include "state_tracker/xlib_sw_winsys.h"
35 #include "xm_winsys.h"
36 #include "util/u_debug.h"
37 #include "softpipe/sp_public.h"
38 #include "llvmpipe/lp_public.h"
39 #include "cell/ppu/cell_public.h"
40
41 /* advertise OpenGL support */
42 PUBLIC const int st_api_OpenGL = 1;
43
44
45 static struct pipe_screen *
46 create_screen( struct sw_winsys *winsys )
47 {
48 #if defined(GALLIUM_CELL)
49 if (!getenv("GALLIUM_NOCELL"))
50 return cell_create_screen( winsys );
51 #endif
52
53 #if defined(GALLIUM_LLVMPIPE)
54 return llvmpipe_create_screen( winsys );
55 #endif
56
57 return softpipe_create_screen( winsys );
58 }
59
60
61
62 static struct pipe_screen *
63 xlib_create_screen( Display *display )
64 {
65 struct sw_winsys *winsys;
66 struct pipe_screen *screen;
67
68 winsys = xlib_create_sw_winsys( display );
69 if (winsys == NULL)
70 return NULL;
71
72 screen = create_screen(winsys);
73 if (screen == NULL)
74 goto fail;
75
76 return screen;
77
78 fail:
79 if (winsys)
80 winsys->destroy( winsys );
81
82 return NULL;
83 }
84
85
86 struct xm_driver xlib_driver =
87 {
88 .create_pipe_screen = xlib_create_screen,
89 };
90
91
92
93
94 /* Build the rendering stack.
95 */
96 static void _init( void ) __attribute__((constructor));
97 static void _init( void )
98 {
99 /* Initialize the xlib libgl code, pass in the winsys:
100 */
101 xmesa_set_driver( &xlib_driver );
102 }
103
104
105 /***********************************************************************
106 *
107 * Butt-ugly hack to convince the linker not to throw away public GL
108 * symbols (they are all referenced from getprocaddress, I guess).
109 */
110 extern void (*linker_foo(const unsigned char *procName))();
111 extern void (*glXGetProcAddress(const unsigned char *procName))();
112
113 extern void (*linker_foo(const unsigned char *procName))()
114 {
115 return glXGetProcAddress(procName);
116 }
117
118
119 /**
120 * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in
121 * libglapi.a. We need to define them here.
122 */
123 #ifdef GLX_INDIRECT_RENDERING
124
125 #define GL_GLEXT_PROTOTYPES
126 #include "GL/gl.h"
127 #include "glapi/glapi.h"
128 #include "glapi/glapitable.h"
129 #include "glapi/glapidispatch.h"
130
131 #if defined(USE_MGL_NAMESPACE)
132 #define NAME(func) mgl##func
133 #else
134 #define NAME(func) gl##func
135 #endif
136
137 #define DISPATCH(FUNC, ARGS, MESSAGE) \
138 CALL_ ## FUNC(GET_DISPATCH(), ARGS);
139
140 #define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \
141 return CALL_ ## FUNC(GET_DISPATCH(), ARGS);
142
143 /* skip normal ones */
144 #define _GLAPI_SKIP_NORMAL_ENTRY_POINTS
145 #include "glapi/glapitemp.h"
146
147 #endif /* GLX_INDIRECT_RENDERING */