gallium: split driver-independent code out of xlib winsys
[mesa.git] / src / gallium / winsys / 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 "xlib_trace.h"
35 #include "xlib_softpipe.h"
36 #include "xlib_brw.h"
37 #include "xm_winsys.h"
38
39 #include <stdlib.h>
40 #include <assert.h>
41
42 /* Todo, replace all this with callback-structs provided by the
43 * individual implementations.
44 */
45
46 enum mode {
47 MODE_TRACE,
48 MODE_BRW,
49 MODE_CELL,
50 MODE_SOFTPIPE
51 };
52
53 static enum mode xlib_mode;
54
55 static enum mode get_mode()
56 {
57 if (getenv("XMESA_TRACE"))
58 return MODE_TRACE;
59
60 if (getenv("XMESA_BRW"))
61 return MODE_BRW;
62
63 #ifdef GALLIUM_CELL
64 if (!getenv("GALLIUM_NOCELL"))
65 return MODE_CELL;
66 #endif
67
68 return MODE_SOFTPIPE;
69 }
70
71
72 struct pipe_winsys *
73 xmesa_create_pipe_winsys( void )
74 {
75 xlib_mode = get_mode();
76
77 switch (xlib_mode) {
78 case MODE_TRACE:
79 return xlib_create_trace_winsys();
80 case MODE_BRW:
81 return xlib_create_brw_winsys();
82 case MODE_CELL:
83 return xlib_create_cell_winsys();
84 case MODE_SOFTPIPE:
85 return xlib_create_softpipe_winsys();
86 default:
87 assert(0);
88 return NULL;
89 }
90 }
91
92 struct pipe_screen *
93 xmesa_create_pipe_screen( struct pipe_winsys *winsys )
94 {
95 switch (xlib_mode) {
96 case MODE_TRACE:
97 return xlib_create_trace_screen( winsys );
98 case MODE_BRW:
99 return xlib_create_brw_screen( winsys );
100 case MODE_CELL:
101 return xlib_create_cell_screen( winsys );
102 case MODE_SOFTPIPE:
103 return xlib_create_softpipe_screen( winsys );
104 default:
105 assert(0);
106 return NULL;
107 }
108 }
109
110 struct pipe_context *
111 xmesa_create_pipe_context( struct pipe_screen *screen,
112 void *priv )
113 {
114 switch (xlib_mode) {
115 case MODE_TRACE:
116 return xlib_create_trace_context( screen, priv );
117 case MODE_BRW:
118 return xlib_create_brw_context( screen, priv );
119 case MODE_CELL:
120 return xlib_create_cell_context( screen, priv );
121 case MODE_SOFTPIPE:
122 return xlib_create_softpipe_context( screen, priv );
123 default:
124 assert(0);
125 return NULL;
126 }
127 }
128
129 void
130 xmesa_display_surface( struct xmesa_buffer *buffer,
131 struct pipe_surface *surf )
132 {
133 switch (xlib_mode) {
134 case MODE_TRACE:
135 xlib_trace_display_surface( buffer, surf );
136 break;
137 case MODE_BRW:
138 xlib_brw_display_surface( buffer, surf );
139 break;
140 case MODE_CELL:
141 xlib_cell_display_surface( buffer, surf );
142 break;
143 case MODE_SOFTPIPE:
144 xlib_softpipe_display_surface( buffer, surf );
145 break;
146 default:
147 assert(0);
148 break;
149 }
150 }
151
152
153
154 /***********************************************************************
155 *
156 * Butt-ugly hack to convince the linker not to throw away public GL
157 * symbols (they are all referenced from getprocaddress, I guess).
158 */
159 extern void (*linker_foo(const unsigned char *procName))();
160 extern void (*glXGetProcAddress(const unsigned char *procName))();
161
162 extern void (*linker_foo(const unsigned char *procName))()
163 {
164 return glXGetProcAddress(procName);
165 }