target-helpers: remove swrast_xlib.c helper
[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 #include "pipe/p_compiler.h"
34 #include "state_tracker/xlib_sw_winsys.h"
35 #include "util/u_debug.h"
36 #include "softpipe/sp_public.h"
37 #include "llvmpipe/lp_public.h"
38 #include "cell/ppu/cell_public.h"
39 #include "target-helpers/wrap_screen.h"
40 #include "xm_public.h"
41
42 /* advertise OpenGL support */
43 PUBLIC const int st_api_OpenGL = 1;
44
45
46 /* Helper function to build a subset of a driver stack consisting of
47 * one of the software rasterizers (cell, llvmpipe, softpipe) and the
48 * xlib winsys.
49 *
50 * This function could be shared, but currently causes headaches for
51 * the build systems, particularly scons if we try. Long term, want
52 * to avoid having global #defines for things like GALLIUM_LLVMPIPE,
53 * GALLIUM_CELL, etc. Scons already eliminates those #defines, so
54 * things that are painful for it now are likely to be painful for
55 * other build systems in the future.
56 */
57 static struct pipe_screen *
58 swrast_xlib_create_screen( Display *display )
59 {
60 struct sw_winsys *winsys;
61 struct pipe_screen *screen = NULL;
62
63 /* Create the underlying winsys, which performs presents to Xlib
64 * drawables:
65 */
66 winsys = xlib_create_sw_winsys( display );
67 if (winsys == NULL)
68 return NULL;
69
70 /* Create a software rasterizer on top of that winsys:
71 */
72 #if defined(GALLIUM_CELL)
73 if (screen == NULL &&
74 !debug_get_bool_option("GALLIUM_NO_CELL", FALSE))
75 screen = cell_create_screen( winsys );
76 #endif
77
78 #if defined(GALLIUM_LLVMPIPE)
79 if (screen == NULL &&
80 !debug_get_bool_option("GALLIUM_NO_LLVM", FALSE))
81 screen = llvmpipe_create_screen( winsys );
82 #endif
83
84 if (screen == NULL)
85 screen = softpipe_create_screen( winsys );
86
87 if (screen == NULL)
88 goto fail;
89
90 /* Inject any wrapping layers we want to here:
91 */
92 return gallium_wrap_screen( screen );
93
94 fail:
95 if (winsys)
96 winsys->destroy( winsys );
97
98 return NULL;
99 }
100
101 struct xm_driver xlib_driver =
102 {
103 .create_pipe_screen = swrast_xlib_create_screen,
104 };
105
106
107 /* Build the rendering stack.
108 */
109 static void _init( void ) __attribute__((constructor));
110 static void _init( void )
111 {
112 /* Initialize the xlib libgl code, pass in the winsys:
113 */
114 xmesa_set_driver( &xlib_driver );
115 }
116
117
118 /***********************************************************************
119 *
120 * Butt-ugly hack to convince the linker not to throw away public GL
121 * symbols (they are all referenced from getprocaddress, I guess).
122 */
123 extern void (*linker_foo(const unsigned char *procName))();
124 extern void (*glXGetProcAddress(const unsigned char *procName))();
125
126 extern void (*linker_foo(const unsigned char *procName))()
127 {
128 return glXGetProcAddress(procName);
129 }
130
131
132 /**
133 * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in
134 * libglapi.a. We need to define them here.
135 */
136 #ifdef GLX_INDIRECT_RENDERING
137
138 #define GL_GLEXT_PROTOTYPES
139 #include "GL/gl.h"
140 #include "glapi/glapi.h"
141 #include "glapi/glapitable.h"
142 #include "glapi/glapidispatch.h"
143
144 #if defined(USE_MGL_NAMESPACE)
145 #define NAME(func) mgl##func
146 #else
147 #define NAME(func) gl##func
148 #endif
149
150 #define DISPATCH(FUNC, ARGS, MESSAGE) \
151 CALL_ ## FUNC(GET_DISPATCH(), ARGS);
152
153 #define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \
154 return CALL_ ## FUNC(GET_DISPATCH(), ARGS);
155
156 /* skip normal ones */
157 #define _GLAPI_SKIP_NORMAL_ENTRY_POINTS
158 #include "glapi/glapitemp.h"
159
160 #endif /* GLX_INDIRECT_RENDERING */