1 /**************************************************************************
3 * Copyright 2009 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
25 **************************************************************************/
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"
38 #include "cso_cache/cso_hash.h"
39 #include "cso_cache/cso_context.h"
46 struct st_renderbuffer {
47 enum pipe_format format;
48 struct pipe_surface *surface;
49 struct pipe_texture *texture;
53 struct st_framebuffer {
55 struct st_renderbuffer *strb;
56 struct st_renderbuffer *dsrb;
58 struct pipe_sampler_view *alpha_mask_view;
60 struct pipe_sampler_view *blend_texture_view;
63 struct st_framebuffer_iface *iface;
64 enum st_attachment_type strb_att;
70 VG_OBJECT_UNKNOWN = 0,
82 RASTERIZER_DIRTY = 1<<2,
83 VIEWPORT_DIRTY = 1<<3,
85 DEPTH_STENCIL_DIRTY = 1<<5,
86 ALL_DIRTY = BLEND_DIRTY | RASTERIZER_DIRTY |
87 VIEWPORT_DIRTY | VS_DIRTY | DEPTH_STENCIL_DIRTY
92 struct st_context_iface iface;
94 struct pipe_context *pipe;
99 struct pipe_blend_state blend;
100 struct pipe_rasterizer_state rasterizer;
101 struct pipe_shader_state vs_state;
102 struct pipe_depth_stencil_alpha_state dsa;
103 struct pipe_framebuffer_state fb;
110 struct st_framebuffer *draw_buffer;
111 int32_t draw_buffer_invalid;
113 struct cso_hash *owned_objects[VG_OBJECT_LAST];
116 struct pipe_shader_state vert_shader;
117 struct pipe_shader_state frag_shader;
118 struct pipe_rasterizer_state raster;
120 float vertices[4][2][4]; /**< vertex pos + color */
124 struct pipe_buffer *cbuf;
125 struct pipe_sampler_state sampler;
127 struct vg_shader *union_fs;
128 struct vg_shader *intersect_fs;
129 struct vg_shader *subtract_fs;
130 struct vg_shader *set_fs;
133 struct vg_shader *pass_through_depth_fs;
135 struct cso_context *cso_context;
137 struct pipe_buffer *stencil_quad;
138 VGfloat stencil_vertices[4][2][4];
140 struct renderer *renderer;
141 struct shaders_cache *sc;
142 struct shader *shader;
144 struct pipe_sampler_state blend_sampler;
146 struct pipe_buffer *buffer;
147 void *color_matrix_fs;
149 struct vg_paint *default_paint;
151 struct blit_state *blit;
153 struct vg_shader *plain_vs;
154 struct vg_shader *clear_vs;
155 struct vg_shader *texture_vs;
156 struct pipe_buffer *vs_const_buffer;
157 struct pipe_vertex_element velems[2];
161 enum vg_object_type type;
162 struct vg_context *ctx;
164 void vg_init_object(struct vg_object *obj, struct vg_context *ctx, enum vg_object_type type);
165 VGboolean vg_object_is_valid(void *ptr, enum vg_object_type type);
167 struct vg_context *vg_create_context(struct pipe_context *pipe,
169 struct vg_context *share);
170 void vg_destroy_context(struct vg_context *ctx);
171 struct vg_context *vg_current_context(void);
172 void vg_set_current_context(struct vg_context *ctx);
174 VGboolean vg_context_is_object_valid(struct vg_context *ctx,
175 enum vg_object_type type,
177 void vg_context_add_object(struct vg_context *ctx,
178 enum vg_object_type type,
180 void vg_context_remove_object(struct vg_context *ctx,
181 enum vg_object_type type,
184 void vg_validate_state(struct vg_context *ctx);
186 void vg_set_error(struct vg_context *ctx,
189 void vg_prepare_blend_surface(struct vg_context *ctx);
190 void vg_prepare_blend_surface_from_mask(struct vg_context *ctx);
193 static INLINE VGboolean is_aligned_to(const void *ptr, VGbyte alignment)
195 void *aligned = align_pointer(ptr, alignment);
196 return (ptr == aligned) ? VG_TRUE : VG_FALSE;
199 static INLINE VGboolean is_aligned(const void *ptr)
201 return is_aligned_to(ptr, 4);
204 static INLINE void vg_shift_rectx(VGfloat coords[4],
205 const VGfloat *bounds,
211 coords[2] = MIN2(coords[2], bounds[2]);
212 /* bound x/y + width/height */
213 if ((coords[0] + coords[2]) > (bounds[0] + bounds[2])) {
214 coords[2] = (bounds[0] + bounds[2]) - coords[0];
219 static INLINE void vg_shift_recty(VGfloat coords[4],
220 const VGfloat *bounds,
226 coords[3] = MIN2(coords[3], bounds[3]);
227 if ((coords[1] + coords[3]) > (bounds[1] + bounds[3])) {
228 coords[3] = (bounds[1] + bounds[3]) - coords[1];
233 static INLINE void vg_bound_rect(VGfloat coords[4],
234 const VGfloat bounds[4],
237 /* if outside the bounds */
238 if (coords[0] > (bounds[0] + bounds[2]) ||
239 coords[1] > (bounds[1] + bounds[3]) ||
240 (coords[0] + coords[2]) < bounds[0] ||
241 (coords[1] + coords[3]) < bounds[1]) {
252 if (coords[0] < bounds[0]) {
253 shift[0] = bounds[0] - coords[0];
254 coords[2] -= shift[0];
255 coords[0] = bounds[0];
260 if (coords[1] < bounds[1]) {
261 shift[1] = bounds[1] - coords[1];
262 coords[3] -= shift[1];
263 coords[1] = bounds[1];
267 shift[2] = bounds[2] - coords[2];
268 shift[3] = bounds[3] - coords[3];
269 /* bound width/height */
270 coords[2] = MIN2(coords[2], bounds[2]);
271 coords[3] = MIN2(coords[3], bounds[3]);
273 /* bound x/y + width/height */
274 if ((coords[0] + coords[2]) > (bounds[0] + bounds[2])) {
275 coords[2] = (bounds[0] + bounds[2]) - coords[0];
277 if ((coords[1] + coords[3]) > (bounds[1] + bounds[3])) {
278 coords[3] = (bounds[1] + bounds[3]) - coords[1];
281 /* if outside the bounds */
282 if ((coords[0] + coords[2]) < bounds[0] ||
283 (coords[1] + coords[3]) < bounds[1]) {
292 void *vg_plain_vs(struct vg_context *ctx);
293 void *vg_clear_vs(struct vg_context *ctx);
294 void *vg_texture_vs(struct vg_context *ctx);
299 void vg_set_viewport(struct vg_context *ctx, VegaOrientation orientation);