gallium: start removing pipe_context->get_name/vendor/param/paramf
[mesa.git] / src / gallium / drivers / i965simple / brw_context.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 #include "brw_context.h"
34 #include "brw_defines.h"
35 #include "brw_draw.h"
36 #include "brw_vs.h"
37 #include "brw_tex_layout.h"
38 #include "brw_winsys.h"
39
40 #include "pipe/p_winsys.h"
41 #include "pipe/p_context.h"
42 #include "pipe/p_util.h"
43 #include "pipe/p_screen.h"
44
45
46 #ifndef BRW_DEBUG
47 int BRW_DEBUG = (0);
48 #endif
49
50
51 static void brw_destroy(struct pipe_context *pipe)
52 {
53 struct brw_context *brw = brw_context(pipe);
54
55 FREE(brw);
56 }
57
58
59 static void brw_clear(struct pipe_context *pipe, struct pipe_surface *ps,
60 unsigned clearValue)
61 {
62 int x, y, w, h;
63 /* FIXME: corny... */
64
65 x = 0;
66 y = 0;
67 w = ps->width;
68 h = ps->height;
69
70 pipe->surface_fill(pipe, ps, x, y, w, h, clearValue);
71 }
72
73
74 static boolean
75 brw_is_format_supported( struct pipe_context *pipe,
76 enum pipe_format format, uint type )
77 {
78 #if 0
79 /* XXX: This is broken -- rewrite if still needed. */
80 static const unsigned tex_supported[] = {
81 PIPE_FORMAT_U_R8_G8_B8_A8,
82 PIPE_FORMAT_U_A8_R8_G8_B8,
83 PIPE_FORMAT_U_R5_G6_B5,
84 PIPE_FORMAT_U_L8,
85 PIPE_FORMAT_U_A8,
86 PIPE_FORMAT_U_I8,
87 PIPE_FORMAT_U_L8_A8,
88 PIPE_FORMAT_YCBCR,
89 PIPE_FORMAT_YCBCR_REV,
90 PIPE_FORMAT_S8_Z24,
91 };
92
93
94 /* Actually a lot more than this - add later:
95 */
96 static const unsigned render_supported[] = {
97 PIPE_FORMAT_U_A8_R8_G8_B8,
98 PIPE_FORMAT_U_R5_G6_B5,
99 };
100
101 /*
102 */
103 static const unsigned z_stencil_supported[] = {
104 PIPE_FORMAT_U_Z16,
105 PIPE_FORMAT_U_Z32,
106 PIPE_FORMAT_S8_Z24,
107 };
108
109 switch (type) {
110 case PIPE_RENDER_FORMAT:
111 *numFormats = Elements(render_supported);
112 return render_supported;
113
114 case PIPE_TEX_FORMAT:
115 *numFormats = Elements(tex_supported);
116 return render_supported;
117
118 case PIPE_Z_STENCIL_FORMAT:
119 *numFormats = Elements(render_supported);
120 return render_supported;
121
122 default:
123 *numFormats = 0;
124 return NULL;
125 }
126 #else
127 switch (format) {
128 case PIPE_FORMAT_A8R8G8B8_UNORM:
129 case PIPE_FORMAT_R5G6B5_UNORM:
130 case PIPE_FORMAT_S8Z24_UNORM:
131 return TRUE;
132 default:
133 return FALSE;
134 };
135 return FALSE;
136 #endif
137 }
138
139
140
141
142 struct pipe_context *brw_create(struct pipe_screen *screen,
143 struct brw_winsys *brw_winsys,
144 unsigned pci_id)
145 {
146 struct brw_context *brw;
147
148 screen->winsys->printf(screen->winsys,
149 "%s: creating brw_context with pci id 0x%x\n",
150 __FUNCTION__, pci_id);
151
152 brw = CALLOC_STRUCT(brw_context);
153 if (brw == NULL)
154 return NULL;
155
156 brw->winsys = brw_winsys;
157 brw->pipe.winsys = screen->winsys;
158 brw->pipe.screen = screen;
159
160 brw->pipe.destroy = brw_destroy;
161 brw->pipe.is_format_supported = brw_is_format_supported;
162 brw->pipe.clear = brw_clear;
163
164 brw_init_surface_functions(brw);
165 brw_init_texture_functions(brw);
166 brw_init_state_functions(brw);
167 brw_init_flush_functions(brw);
168 brw_init_draw_functions( brw );
169
170
171 brw_init_state( brw );
172
173 brw->pci_id = pci_id;
174 brw->dirty = ~0;
175 brw->hardware_dirty = ~0;
176
177 memset(&brw->wm.bind, ~0, sizeof(brw->wm.bind));
178
179 return &brw->pipe;
180 }
181