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
49static struct pipe_screen *
50pipe_i915_create_screen(int fd)
51{
52#if _EGL_PIPE_I915
53   struct i915_winsys *iws;
54   struct pipe_screen *screen;
55
56   iws = i915_drm_winsys_create(fd);
57   if (!iws)
58      return NULL;
59
60   screen = i915_screen_create(iws);
61   if (!screen)
62      return NULL;
63
64   screen = debug_screen_wrap(screen);
65
66   return screen;
67#else
68   return NULL;
69#endif
70}
71
72static struct pipe_screen *
73pipe_nouveau_create_screen(int fd)
74{
75#if _EGL_PIPE_NOUVEAU
76   struct pipe_screen *screen;
77
78   screen = nouveau_drm_screen_create(fd);
79   if (!screen)
80      return NULL;
81
82   screen = debug_screen_wrap(screen);
83
84   return screen;
85#else
86   return NULL;
87#endif
88}
89
90static struct pipe_screen *
91pipe_r300_create_screen(int fd)
92{
93#if _EGL_PIPE_R300
94   struct radeon_winsys *sws;
95   struct pipe_screen *screen;
96
97   sws = radeon_drm_winsys_create(fd);
98   if (!sws)
99      return NULL;
100
101   screen = r300_screen_create(sws);
102   if (!screen)
103      return NULL;
104
105   screen = debug_screen_wrap(screen);
106
107   return screen;
108#else
109   return NULL;
110#endif
111}
112
113static struct pipe_screen *
114pipe_r600_create_screen(int fd)
115{
116#if _EGL_PIPE_R600
117   struct radeon_winsys *rw;
118   struct pipe_screen *screen;
119
120   rw = radeon_drm_winsys_create(fd);
121   if (!rw)
122      return NULL;
123
124   screen = r600_screen_create(rw);
125   if (!screen)
126      return NULL;
127
128   screen = debug_screen_wrap(screen);
129
130   return screen;
131#else
132   return NULL;
133#endif
134}
135
136static struct pipe_screen *
137pipe_radeonsi_create_screen(int fd)
138{
139#if _EGL_PIPE_RADEONSI
140   struct radeon_winsys *rw;
141   struct pipe_screen *screen;
142
143   rw = radeon_drm_winsys_create(fd);
144   if (!rw)
145      return NULL;
146
147   screen = radeonsi_screen_create(rw);
148   if (!screen)
149      return NULL;
150
151   screen = debug_screen_wrap(screen);
152
153   return screen;
154#else
155   return NULL;
156#endif
157}
158
159static struct pipe_screen *
160pipe_vmwgfx_create_screen(int fd)
161{
162#if _EGL_PIPE_VMWGFX
163   struct svga_winsys_screen *sws;
164   struct pipe_screen *screen;
165
166   sws = svga_drm_winsys_screen_create(fd);
167   if (!sws)
168      return NULL;
169
170   screen = svga_screen_create(sws);
171   if (!screen)
172      return NULL;
173
174   screen = debug_screen_wrap(screen);
175
176   return screen;
177#else
178   return NULL;
179#endif
180}
181
182struct pipe_screen *
183egl_pipe_create_drm_screen(const char *name, int fd)
184{
185   if (strcmp(name, "i915") == 0)
186      return pipe_i915_create_screen(fd);
187   else if (strcmp(name, "nouveau") == 0)
188      return pipe_nouveau_create_screen(fd);
189   else if (strcmp(name, "r300") == 0)
190      return pipe_r300_create_screen(fd);
191   else if (strcmp(name, "r600") == 0)
192      return pipe_r600_create_screen(fd);
193   else if (strcmp(name, "radeonsi") == 0)
194      return pipe_radeonsi_create_screen(fd);
195   else if (strcmp(name, "vmwgfx") == 0)
196      return pipe_vmwgfx_create_screen(fd);
197   else
198      return NULL;
199}
200
201struct pipe_screen *
202egl_pipe_create_swrast_screen(struct sw_winsys *ws)
203{
204   struct pipe_screen *screen;
205
206   screen = sw_screen_create(ws);
207   if (screen)
208      screen = debug_screen_wrap(screen);
209
210   return screen;
211}
212