gallium: make p_winsys internal
[mesa.git] / src / gallium / drivers / i915simple / i915_screen.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "util/u_memory.h"
30 #include "pipe/internal/p_winsys_screen.h"
31 #include "pipe/p_inlines.h"
32 #include "util/u_string.h"
33
34 #include "i915_reg.h"
35 #include "i915_context.h"
36 #include "i915_screen.h"
37 #include "i915_texture.h"
38
39
40 static const char *
41 i915_get_vendor( struct pipe_screen *pscreen )
42 {
43 return "Tungsten Graphics, Inc.";
44 }
45
46
47 static const char *
48 i915_get_name( struct pipe_screen *pscreen )
49 {
50 static char buffer[128];
51 const char *chipset;
52
53 switch (i915_screen(pscreen)->pci_id) {
54 case PCI_CHIP_I915_G:
55 chipset = "915G";
56 break;
57 case PCI_CHIP_I915_GM:
58 chipset = "915GM";
59 break;
60 case PCI_CHIP_I945_G:
61 chipset = "945G";
62 break;
63 case PCI_CHIP_I945_GM:
64 chipset = "945GM";
65 break;
66 case PCI_CHIP_I945_GME:
67 chipset = "945GME";
68 break;
69 case PCI_CHIP_G33_G:
70 chipset = "G33";
71 break;
72 case PCI_CHIP_Q35_G:
73 chipset = "Q35";
74 break;
75 case PCI_CHIP_Q33_G:
76 chipset = "Q33";
77 break;
78 default:
79 chipset = "unknown";
80 break;
81 }
82
83 util_snprintf(buffer, sizeof(buffer), "i915 (chipset: %s)", chipset);
84 return buffer;
85 }
86
87
88 static int
89 i915_get_param(struct pipe_screen *screen, int param)
90 {
91 switch (param) {
92 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
93 return 8;
94 case PIPE_CAP_NPOT_TEXTURES:
95 return 1;
96 case PIPE_CAP_TWO_SIDED_STENCIL:
97 return 1;
98 case PIPE_CAP_GLSL:
99 return 0;
100 case PIPE_CAP_S3TC:
101 return 0;
102 case PIPE_CAP_ANISOTROPIC_FILTER:
103 return 0;
104 case PIPE_CAP_POINT_SPRITE:
105 return 0;
106 case PIPE_CAP_MAX_RENDER_TARGETS:
107 return 1;
108 case PIPE_CAP_OCCLUSION_QUERY:
109 return 0;
110 case PIPE_CAP_TEXTURE_SHADOW_MAP:
111 return 1;
112 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
113 return 11; /* max 1024x1024 */
114 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
115 return 8; /* max 128x128x128 */
116 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
117 return 11; /* max 1024x1024 */
118 default:
119 return 0;
120 }
121 }
122
123
124 static float
125 i915_get_paramf(struct pipe_screen *screen, int param)
126 {
127 switch (param) {
128 case PIPE_CAP_MAX_LINE_WIDTH:
129 /* fall-through */
130 case PIPE_CAP_MAX_LINE_WIDTH_AA:
131 return 7.5;
132
133 case PIPE_CAP_MAX_POINT_WIDTH:
134 /* fall-through */
135 case PIPE_CAP_MAX_POINT_WIDTH_AA:
136 return 255.0;
137
138 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
139 return 4.0;
140
141 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
142 return 16.0;
143
144 default:
145 return 0;
146 }
147 }
148
149
150 static boolean
151 i915_is_format_supported( struct pipe_screen *screen,
152 enum pipe_format format,
153 enum pipe_texture_target target,
154 unsigned tex_usage,
155 unsigned geom_flags )
156 {
157 static const enum pipe_format tex_supported[] = {
158 PIPE_FORMAT_R8G8B8A8_UNORM,
159 PIPE_FORMAT_A8R8G8B8_UNORM,
160 PIPE_FORMAT_R5G6B5_UNORM,
161 PIPE_FORMAT_L8_UNORM,
162 PIPE_FORMAT_A8_UNORM,
163 PIPE_FORMAT_I8_UNORM,
164 PIPE_FORMAT_A8L8_UNORM,
165 PIPE_FORMAT_YCBCR,
166 PIPE_FORMAT_YCBCR_REV,
167 PIPE_FORMAT_S8Z24_UNORM,
168 PIPE_FORMAT_NONE /* list terminator */
169 };
170 static const enum pipe_format surface_supported[] = {
171 PIPE_FORMAT_A8R8G8B8_UNORM,
172 PIPE_FORMAT_R5G6B5_UNORM,
173 PIPE_FORMAT_S8Z24_UNORM,
174 /*PIPE_FORMAT_R16G16B16A16_SNORM,*/
175 PIPE_FORMAT_NONE /* list terminator */
176 };
177 const enum pipe_format *list;
178 uint i;
179
180 if(tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET)
181 list = surface_supported;
182 else
183 list = tex_supported;
184
185 for (i = 0; list[i] != PIPE_FORMAT_NONE; i++) {
186 if (list[i] == format)
187 return TRUE;
188 }
189
190 return FALSE;
191 }
192
193
194 static void
195 i915_destroy_screen( struct pipe_screen *screen )
196 {
197 struct pipe_winsys *winsys = screen->winsys;
198
199 if(winsys->destroy)
200 winsys->destroy(winsys);
201
202 FREE(screen);
203 }
204
205
206 static void *
207 i915_surface_map( struct pipe_screen *screen,
208 struct pipe_surface *surface,
209 unsigned flags )
210 {
211 char *map = pipe_buffer_map( screen, surface->buffer, flags );
212 if (map == NULL)
213 return NULL;
214
215 if (surface->texture &&
216 (flags & PIPE_BUFFER_USAGE_CPU_WRITE))
217 {
218 /* Do something to notify contexts of a texture change.
219 */
220 /* i915_screen(screen)->timestamp++; */
221 }
222
223 return map + surface->offset;
224 }
225
226 static void
227 i915_surface_unmap(struct pipe_screen *screen,
228 struct pipe_surface *surface)
229 {
230 pipe_buffer_unmap( screen, surface->buffer );
231 }
232
233
234
235 /**
236 * Create a new i915_screen object
237 */
238 struct pipe_screen *
239 i915_create_screen(struct pipe_winsys *winsys, uint pci_id)
240 {
241 struct i915_screen *i915screen = CALLOC_STRUCT(i915_screen);
242
243 if (!i915screen)
244 return NULL;
245
246 switch (pci_id) {
247 case PCI_CHIP_I915_G:
248 case PCI_CHIP_I915_GM:
249 i915screen->is_i945 = FALSE;
250 break;
251
252 case PCI_CHIP_I945_G:
253 case PCI_CHIP_I945_GM:
254 case PCI_CHIP_I945_GME:
255 case PCI_CHIP_G33_G:
256 case PCI_CHIP_Q33_G:
257 case PCI_CHIP_Q35_G:
258 i915screen->is_i945 = TRUE;
259 break;
260
261 default:
262 debug_printf("%s: unknown pci id 0x%x, cannot create screen\n",
263 __FUNCTION__, pci_id);
264 return NULL;
265 }
266
267 i915screen->pci_id = pci_id;
268
269 i915screen->screen.winsys = winsys;
270
271 i915screen->screen.destroy = i915_destroy_screen;
272
273 i915screen->screen.get_name = i915_get_name;
274 i915screen->screen.get_vendor = i915_get_vendor;
275 i915screen->screen.get_param = i915_get_param;
276 i915screen->screen.get_paramf = i915_get_paramf;
277 i915screen->screen.is_format_supported = i915_is_format_supported;
278 i915screen->screen.surface_map = i915_surface_map;
279 i915screen->screen.surface_unmap = i915_surface_unmap;
280
281 i915_init_screen_texture_functions(&i915screen->screen);
282
283 return &i915screen->screen;
284 }