freedreno: gallium driver for adreno
[mesa.git] / src / gallium / targets / egl-static / egl_pipe.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.10
4 *
5 * Copyright (C) 2011 LunarG Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Chia-I Wu <olv@lunarg.com>
27 */
28 #include "target-helpers/inline_debug_helper.h"
29 #include "target-helpers/inline_sw_helper.h"
30 #include "egl_pipe.h"
31
32 /* for i915 */
33 #include "i915/drm/i915_drm_public.h"
34 #include "i915/i915_public.h"
35 #include "target-helpers/inline_wrapper_sw_helper.h"
36 /* for nouveau */
37 #include "nouveau/drm/nouveau_drm_public.h"
38 /* for r300 */
39 #include "radeon/drm/radeon_drm_public.h"
40 #include "r300/r300_public.h"
41 /* for r600 */
42 #include "r600/r600_public.h"
43 /* for radeonsi */
44 #include "radeonsi/radeonsi_public.h"
45 /* for vmwgfx */
46 #include "svga/drm/svga_drm_public.h"
47 #include "svga/svga_public.h"
48 /* for freedreno */
49 #include "freedreno/drm/freedreno_drm_public.h"
50
51 static struct pipe_screen *
52 pipe_i915_create_screen(int fd)
53 {
54 #if _EGL_PIPE_I915
55 struct i915_winsys *iws;
56 struct pipe_screen *screen;
57
58 iws = i915_drm_winsys_create(fd);
59 if (!iws)
60 return NULL;
61
62 screen = i915_screen_create(iws);
63 if (!screen)
64 return NULL;
65
66 screen = debug_screen_wrap(screen);
67
68 return screen;
69 #else
70 return NULL;
71 #endif
72 }
73
74 static struct pipe_screen *
75 pipe_nouveau_create_screen(int fd)
76 {
77 #if _EGL_PIPE_NOUVEAU
78 struct pipe_screen *screen;
79
80 screen = nouveau_drm_screen_create(fd);
81 if (!screen)
82 return NULL;
83
84 screen = debug_screen_wrap(screen);
85
86 return screen;
87 #else
88 return NULL;
89 #endif
90 }
91
92 static struct pipe_screen *
93 pipe_r300_create_screen(int fd)
94 {
95 #if _EGL_PIPE_R300
96 struct radeon_winsys *sws;
97 struct pipe_screen *screen;
98
99 sws = radeon_drm_winsys_create(fd);
100 if (!sws)
101 return NULL;
102
103 screen = r300_screen_create(sws);
104 if (!screen)
105 return NULL;
106
107 screen = debug_screen_wrap(screen);
108
109 return screen;
110 #else
111 return NULL;
112 #endif
113 }
114
115 static struct pipe_screen *
116 pipe_r600_create_screen(int fd)
117 {
118 #if _EGL_PIPE_R600
119 struct radeon_winsys *rw;
120 struct pipe_screen *screen;
121
122 rw = radeon_drm_winsys_create(fd);
123 if (!rw)
124 return NULL;
125
126 screen = r600_screen_create(rw);
127 if (!screen)
128 return NULL;
129
130 screen = debug_screen_wrap(screen);
131
132 return screen;
133 #else
134 return NULL;
135 #endif
136 }
137
138 static struct pipe_screen *
139 pipe_radeonsi_create_screen(int fd)
140 {
141 #if _EGL_PIPE_RADEONSI
142 struct radeon_winsys *rw;
143 struct pipe_screen *screen;
144
145 rw = radeon_drm_winsys_create(fd);
146 if (!rw)
147 return NULL;
148
149 screen = radeonsi_screen_create(rw);
150 if (!screen)
151 return NULL;
152
153 screen = debug_screen_wrap(screen);
154
155 return screen;
156 #else
157 return NULL;
158 #endif
159 }
160
161 static struct pipe_screen *
162 pipe_vmwgfx_create_screen(int fd)
163 {
164 #if _EGL_PIPE_VMWGFX
165 struct svga_winsys_screen *sws;
166 struct pipe_screen *screen;
167
168 sws = svga_drm_winsys_screen_create(fd);
169 if (!sws)
170 return NULL;
171
172 screen = svga_screen_create(sws);
173 if (!screen)
174 return NULL;
175
176 screen = debug_screen_wrap(screen);
177
178 return screen;
179 #else
180 return NULL;
181 #endif
182 }
183
184 static struct pipe_screen *
185 pipe_freedreno_create_screen(int fd)
186 {
187 #if _EGL_PIPE_FREEDRENO
188 struct pipe_screen *screen;
189
190 screen = fd_drm_screen_create(fd);
191 if (!screen)
192 return NULL;
193
194 screen = debug_screen_wrap(screen);
195
196 return screen;
197 #else
198 return NULL;
199 #endif
200 }
201
202 struct pipe_screen *
203 egl_pipe_create_drm_screen(const char *name, int fd)
204 {
205 if (strcmp(name, "i915") == 0)
206 return pipe_i915_create_screen(fd);
207 else if (strcmp(name, "nouveau") == 0)
208 return pipe_nouveau_create_screen(fd);
209 else if (strcmp(name, "r300") == 0)
210 return pipe_r300_create_screen(fd);
211 else if (strcmp(name, "r600") == 0)
212 return pipe_r600_create_screen(fd);
213 else if (strcmp(name, "radeonsi") == 0)
214 return pipe_radeonsi_create_screen(fd);
215 else if (strcmp(name, "vmwgfx") == 0)
216 return pipe_vmwgfx_create_screen(fd);
217 else if (strcmp(name, "kgsl") == 0)
218 return pipe_freedreno_create_screen(fd);
219 else
220 return NULL;
221 }
222
223 struct pipe_screen *
224 egl_pipe_create_swrast_screen(struct sw_winsys *ws)
225 {
226 struct pipe_screen *screen;
227
228 screen = sw_screen_create(ws);
229 if (screen)
230 screen = debug_screen_wrap(screen);
231
232 return screen;
233 }