Tizen 2.0 Release
[profile/ivi/osmesa.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 /* for i965 */
36 #include "target-helpers/inline_wrapper_sw_helper.h"
37 #include "i965/drm/i965_drm_public.h"
38 #include "i965/brw_public.h"
39 /* for nouveau */
40 #include "nouveau/drm/nouveau_drm_public.h"
41 /* for r300 */
42 #include "radeon/drm/radeon_drm_public.h"
43 #include "r300/r300_public.h"
44 /* for r600 */
45 #include "r600/drm/r600_drm_public.h"
46 #include "r600/r600_public.h"
47 /* for vmwgfx */
48 #include "svga/drm/svga_drm_public.h"
49 #include "svga/svga_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_i965_create_screen(int fd)
76 {
77 #if _EGL_PIPE_I965
78    struct brw_winsys_screen *bws;
79    struct pipe_screen *screen;
80
81    bws = i965_drm_winsys_screen_create(fd);
82    if (!bws)
83       return NULL;
84
85    screen = brw_screen_create(bws);
86    if (!screen)
87       return NULL;
88
89    screen = sw_screen_wrap(screen);
90
91    screen = debug_screen_wrap(screen);
92
93    return screen;
94 #else
95    return NULL;
96 #endif
97 }
98
99 static struct pipe_screen *
100 pipe_nouveau_create_screen(int fd)
101 {
102 #if _EGL_PIPE_NOUVEAU
103    struct pipe_screen *screen;
104
105    screen = nouveau_drm_screen_create(fd);
106    if (!screen)
107       return NULL;
108
109    screen = debug_screen_wrap(screen);
110
111    return screen;
112 #else
113    return NULL;
114 #endif
115 }
116
117 static struct pipe_screen *
118 pipe_r300_create_screen(int fd)
119 {
120 #if _EGL_PIPE_R300
121    struct radeon_winsys *sws;
122    struct pipe_screen *screen;
123
124    sws = radeon_drm_winsys_create(fd);
125    if (!sws)
126       return NULL;
127
128    screen = r300_screen_create(sws);
129    if (!screen)
130       return NULL;
131
132    screen = debug_screen_wrap(screen);
133
134    return screen;
135 #else
136    return NULL;
137 #endif
138 }
139
140 static struct pipe_screen *
141 pipe_r600_create_screen(int fd)
142 {
143 #if _EGL_PIPE_R600
144    struct radeon *rw;
145    struct pipe_screen *screen;
146
147    rw = r600_drm_winsys_create(fd);
148    if (!rw)
149       return NULL;
150
151    screen = r600_screen_create(rw);
152    if (!screen)
153       return NULL;
154
155    screen = debug_screen_wrap(screen);
156
157    return screen;
158 #else
159    return NULL;
160 #endif
161 }
162
163 static struct pipe_screen *
164 pipe_vmwgfx_create_screen(int fd)
165 {
166 #if _EGL_PIPE_VMWGFX
167    struct svga_winsys_screen *sws;
168    struct pipe_screen *screen;
169
170    sws = svga_drm_winsys_screen_create(fd);
171    if (!sws)
172       return NULL;
173
174    screen = svga_screen_create(sws);
175    if (!screen)
176       return NULL;
177
178    screen = debug_screen_wrap(screen);
179
180    return screen;
181 #else
182    return NULL;
183 #endif
184 }
185
186 struct pipe_screen *
187 egl_pipe_create_drm_screen(const char *name, int fd)
188 {
189    if (strcmp(name, "i915") == 0)
190       return pipe_i915_create_screen(fd);
191    else if (strcmp(name, "i965") == 0)
192       return pipe_i965_create_screen(fd);
193    else if (strcmp(name, "nouveau") == 0)
194       return pipe_nouveau_create_screen(fd);
195    else if (strcmp(name, "r300") == 0)
196       return pipe_r300_create_screen(fd);
197    else if (strcmp(name, "r600") == 0)
198       return pipe_r600_create_screen(fd);
199    else if (strcmp(name, "vmwgfx") == 0)
200       return pipe_vmwgfx_create_screen(fd);
201    else
202       return NULL;
203 }
204
205 struct pipe_screen *
206 egl_pipe_create_swrast_screen(struct sw_winsys *ws)
207 {
208    struct pipe_screen *screen;
209
210    screen = sw_screen_create(ws);
211    if (screen)
212       screen = debug_screen_wrap(screen);
213
214    return screen;
215 }