st_api: Remove st_context::is_visual_supported.
[mesa.git] / src / gallium / state_trackers / vega / vg_context.h
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 **************************************************************************/
26
27 #ifndef VG_CONTEXT_H
28 #define VG_CONTEXT_H
29
30 #include "vg_state.h"
31
32 #include "pipe/p_format.h"
33 #include "pipe/p_state.h"
34 #include "util/u_pointer.h"
35 #include "util/u_math.h"
36 #include "state_tracker/st_api.h"
37
38 #include "cso_cache/cso_hash.h"
39 #include "cso_cache/cso_context.h"
40
41 struct renderer;
42 struct shaders_cache;
43 struct shader;
44 struct vg_shader;
45 struct mapi_table;
46
47 struct st_renderbuffer {
48 enum pipe_format format;
49 struct pipe_surface *surface;
50 struct pipe_resource *texture;
51 VGint width, height;
52 };
53
54 struct st_framebuffer {
55 VGint width, height;
56 struct st_renderbuffer *strb;
57 struct st_renderbuffer *dsrb;
58
59 struct pipe_sampler_view *alpha_mask_view;
60
61 struct pipe_sampler_view *blend_texture_view;
62
63
64 struct st_framebuffer_iface *iface;
65 enum st_attachment_type strb_att;
66
67 void *privateData;
68 };
69
70 enum vg_object_type {
71 VG_OBJECT_UNKNOWN = 0,
72 VG_OBJECT_PAINT,
73 VG_OBJECT_IMAGE,
74 VG_OBJECT_MASK,
75 VG_OBJECT_FONT,
76 VG_OBJECT_PATH,
77
78 VG_OBJECT_LAST
79 };
80 enum dirty_state {
81 NONE_DIRTY = 0<<0,
82 BLEND_DIRTY = 1<<1,
83 RASTERIZER_DIRTY = 1<<2,
84 VIEWPORT_DIRTY = 1<<3,
85 VS_DIRTY = 1<<4,
86 DEPTH_STENCIL_DIRTY = 1<<5,
87 ALL_DIRTY = BLEND_DIRTY | RASTERIZER_DIRTY |
88 VIEWPORT_DIRTY | VS_DIRTY | DEPTH_STENCIL_DIRTY
89 };
90
91 struct vg_context
92 {
93 struct st_context_iface iface;
94 struct mapi_table *dispatch;
95
96 struct pipe_context *pipe;
97 enum pipe_format ds_format;
98
99 struct {
100 struct vg_state vg;
101 struct {
102 struct pipe_blend_state blend;
103 struct pipe_rasterizer_state rasterizer;
104 struct pipe_shader_state vs_state;
105 struct pipe_depth_stencil_alpha_state dsa;
106 struct pipe_framebuffer_state fb;
107 } g3d;
108 VGbitfield dirty;
109 } state;
110
111 VGErrorCode _error;
112
113 struct st_framebuffer *draw_buffer;
114 int32_t draw_buffer_invalid;
115
116 struct cso_hash *owned_objects[VG_OBJECT_LAST];
117
118 struct {
119 struct pipe_shader_state vert_shader;
120 struct pipe_shader_state frag_shader;
121 struct pipe_rasterizer_state raster;
122 void *fs;
123 float vertices[4][2][4]; /**< vertex pos + color */
124 } clear;
125
126 struct {
127 struct pipe_resource *cbuf;
128 struct pipe_sampler_state sampler;
129
130 struct vg_shader *union_fs;
131 struct vg_shader *intersect_fs;
132 struct vg_shader *subtract_fs;
133 struct vg_shader *set_fs;
134 } mask;
135
136 struct vg_shader *pass_through_depth_fs;
137
138 struct cso_context *cso_context;
139
140 struct pipe_resource *stencil_quad;
141 VGfloat stencil_vertices[4][2][4];
142
143 struct renderer *renderer;
144 struct shaders_cache *sc;
145 struct shader *shader;
146
147 struct pipe_sampler_state blend_sampler;
148 struct {
149 struct pipe_resource *buffer;
150 void *color_matrix_fs;
151 } filter;
152 struct vg_paint *default_paint;
153
154 struct blit_state *blit;
155
156 struct vg_shader *plain_vs;
157 struct vg_shader *clear_vs;
158 struct vg_shader *texture_vs;
159 struct pipe_resource *vs_const_buffer;
160 struct pipe_vertex_element velems[2];
161 };
162
163 struct vg_object {
164 enum vg_object_type type;
165 struct vg_context *ctx;
166 };
167 void vg_init_object(struct vg_object *obj, struct vg_context *ctx, enum vg_object_type type);
168 VGboolean vg_object_is_valid(void *ptr, enum vg_object_type type);
169
170 struct vg_context *vg_create_context(struct pipe_context *pipe,
171 const void *visual,
172 struct vg_context *share);
173 void vg_destroy_context(struct vg_context *ctx);
174 struct vg_context *vg_current_context(void);
175 void vg_set_current_context(struct vg_context *ctx);
176
177 VGboolean vg_context_is_object_valid(struct vg_context *ctx,
178 enum vg_object_type type,
179 void *ptr);
180 void vg_context_add_object(struct vg_context *ctx,
181 enum vg_object_type type,
182 void *ptr);
183 void vg_context_remove_object(struct vg_context *ctx,
184 enum vg_object_type type,
185 void *ptr);
186
187 void vg_validate_state(struct vg_context *ctx);
188
189 void vg_set_error(struct vg_context *ctx,
190 VGErrorCode code);
191
192 void vg_prepare_blend_surface(struct vg_context *ctx);
193 void vg_prepare_blend_surface_from_mask(struct vg_context *ctx);
194
195
196 static INLINE VGboolean is_aligned_to(const void *ptr, VGbyte alignment)
197 {
198 void *aligned = align_pointer(ptr, alignment);
199 return (ptr == aligned) ? VG_TRUE : VG_FALSE;
200 }
201
202 static INLINE VGboolean is_aligned(const void *ptr)
203 {
204 return is_aligned_to(ptr, 4);
205 }
206
207 static INLINE void vg_shift_rectx(VGfloat coords[4],
208 const VGfloat *bounds,
209 const VGfloat shift)
210 {
211 coords[0] += shift;
212 coords[2] -= shift;
213 if (bounds) {
214 coords[2] = MIN2(coords[2], bounds[2]);
215 /* bound x/y + width/height */
216 if ((coords[0] + coords[2]) > (bounds[0] + bounds[2])) {
217 coords[2] = (bounds[0] + bounds[2]) - coords[0];
218 }
219 }
220 }
221
222 static INLINE void vg_shift_recty(VGfloat coords[4],
223 const VGfloat *bounds,
224 const VGfloat shift)
225 {
226 coords[1] += shift;
227 coords[3] -= shift;
228 if (bounds) {
229 coords[3] = MIN2(coords[3], bounds[3]);
230 if ((coords[1] + coords[3]) > (bounds[1] + bounds[3])) {
231 coords[3] = (bounds[1] + bounds[3]) - coords[1];
232 }
233 }
234 }
235
236 static INLINE void vg_bound_rect(VGfloat coords[4],
237 const VGfloat bounds[4],
238 VGfloat shift[4])
239 {
240 /* if outside the bounds */
241 if (coords[0] > (bounds[0] + bounds[2]) ||
242 coords[1] > (bounds[1] + bounds[3]) ||
243 (coords[0] + coords[2]) < bounds[0] ||
244 (coords[1] + coords[3]) < bounds[1]) {
245 coords[0] = 0.f;
246 coords[1] = 0.f;
247 coords[2] = 0.f;
248 coords[3] = 0.f;
249 shift[0] = 0.f;
250 shift[1] = 0.f;
251 return;
252 }
253
254 /* bound x */
255 if (coords[0] < bounds[0]) {
256 shift[0] = bounds[0] - coords[0];
257 coords[2] -= shift[0];
258 coords[0] = bounds[0];
259 } else
260 shift[0] = 0.f;
261
262 /* bound y */
263 if (coords[1] < bounds[1]) {
264 shift[1] = bounds[1] - coords[1];
265 coords[3] -= shift[1];
266 coords[1] = bounds[1];
267 } else
268 shift[1] = 0.f;
269
270 shift[2] = bounds[2] - coords[2];
271 shift[3] = bounds[3] - coords[3];
272 /* bound width/height */
273 coords[2] = MIN2(coords[2], bounds[2]);
274 coords[3] = MIN2(coords[3], bounds[3]);
275
276 /* bound x/y + width/height */
277 if ((coords[0] + coords[2]) > (bounds[0] + bounds[2])) {
278 coords[2] = (bounds[0] + bounds[2]) - coords[0];
279 }
280 if ((coords[1] + coords[3]) > (bounds[1] + bounds[3])) {
281 coords[3] = (bounds[1] + bounds[3]) - coords[1];
282 }
283
284 /* if outside the bounds */
285 if ((coords[0] + coords[2]) < bounds[0] ||
286 (coords[1] + coords[3]) < bounds[1]) {
287 coords[0] = 0.f;
288 coords[1] = 0.f;
289 coords[2] = 0.f;
290 coords[3] = 0.f;
291 return;
292 }
293 }
294
295 void *vg_plain_vs(struct vg_context *ctx);
296 void *vg_clear_vs(struct vg_context *ctx);
297 void *vg_texture_vs(struct vg_context *ctx);
298 typedef enum {
299 VEGA_Y0_TOP,
300 VEGA_Y0_BOTTOM
301 } VegaOrientation;
302 void vg_set_viewport(struct vg_context *ctx, VegaOrientation orientation);
303
304 #endif