gallium/auxiliary/vl: Move dirty define to header file
[mesa.git] / src / gallium / auxiliary / vl / vl_compositor.h
1 /**************************************************************************
2 *
3 * Copyright 2009 Younes Manton.
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 VMWARE 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 #ifndef vl_compositor_h
29 #define vl_compositor_h
30
31 #include "pipe/p_state.h"
32 #include "pipe/p_video_codec.h"
33 #include "pipe/p_video_state.h"
34
35 #include "util/u_rect.h"
36
37 #include "vl_types.h"
38 #include "vl_csc.h"
39
40 struct pipe_context;
41
42 /**
43 * composing and displaying of image data
44 */
45
46 #define VL_COMPOSITOR_MAX_LAYERS 16
47 #define VL_COMPOSITOR_MIN_DIRTY (0)
48 #define VL_COMPOSITOR_MAX_DIRTY (1 << 15)
49
50 /* deinterlace allgorithem */
51 enum vl_compositor_deinterlace
52 {
53 VL_COMPOSITOR_WEAVE,
54 VL_COMPOSITOR_BOB_TOP,
55 VL_COMPOSITOR_BOB_BOTTOM
56 };
57
58 /* clockwise degree */
59 enum vl_compositor_rotation
60 {
61 VL_COMPOSITOR_ROTATE_0,
62 VL_COMPOSITOR_ROTATE_90,
63 VL_COMPOSITOR_ROTATE_180,
64 VL_COMPOSITOR_ROTATE_270
65 };
66
67 struct vl_compositor_layer
68 {
69 bool clearing;
70
71 bool viewport_valid;
72 struct pipe_viewport_state viewport;
73
74 void *fs;
75 void *samplers[3];
76 void *blend;
77
78 struct pipe_sampler_view *sampler_views[3];
79 struct {
80 struct vertex2f tl, br;
81 } src, dst;
82 struct vertex2f zw;
83 struct vertex4f colors[4];
84 enum vl_compositor_rotation rotate;
85 };
86
87 struct vl_compositor_state
88 {
89 struct pipe_context *pipe;
90
91 bool scissor_valid;
92 struct pipe_scissor_state scissor;
93 struct pipe_resource *csc_matrix;
94
95 union pipe_color_union clear_color;
96
97 unsigned used_layers:VL_COMPOSITOR_MAX_LAYERS;
98 struct vl_compositor_layer layers[VL_COMPOSITOR_MAX_LAYERS];
99 };
100
101 struct vl_compositor
102 {
103 struct pipe_context *pipe;
104
105 struct pipe_framebuffer_state fb_state;
106 struct pipe_vertex_buffer vertex_buf;
107
108 void *sampler_linear;
109 void *sampler_nearest;
110 void *blend_clear, *blend_add;
111 void *rast;
112 void *dsa;
113 void *vertex_elems_state;
114
115 void *vs;
116 void *fs_video_buffer;
117 void *fs_weave_rgb;
118 void *fs_rgba;
119
120 struct {
121 struct {
122 void *y;
123 void *uv;
124 } weave;
125 struct {
126 void *y;
127 void *uv;
128 } bob;
129 } fs_yuv;
130
131 struct {
132 void *rgb;
133 void *yuv;
134 } fs_palette;
135
136 struct {
137 void *y;
138 void *uv;
139 } fs_rgb_yuv;
140 };
141
142 /**
143 * initialize this compositor
144 */
145 bool
146 vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe);
147
148 /**
149 * init state bag
150 */
151 bool
152 vl_compositor_init_state(struct vl_compositor_state *state, struct pipe_context *pipe);
153
154 /**
155 * set yuv -> rgba conversion matrix
156 */
157 bool
158 vl_compositor_set_csc_matrix(struct vl_compositor_state *settings,
159 const vl_csc_matrix *matrix,
160 float luma_min, float luma_max);
161
162 /**
163 * reset dirty area, so it's cleared with the clear colour
164 */
165 void
166 vl_compositor_reset_dirty_area(struct u_rect *dirty);
167
168 /**
169 * set the clear color
170 */
171 void
172 vl_compositor_set_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color);
173
174 /**
175 * get the clear color
176 */
177 void
178 vl_compositor_get_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color);
179
180 /**
181 * set the destination clipping
182 */
183 void
184 vl_compositor_set_dst_clip(struct vl_compositor_state *settings, struct u_rect *dst_clip);
185
186 /**
187 * set overlay samplers
188 */
189 /*@{*/
190
191 /**
192 * reset all currently set layers
193 */
194 void
195 vl_compositor_clear_layers(struct vl_compositor_state *state);
196
197 /**
198 * set the blender used to render a layer
199 */
200 void
201 vl_compositor_set_layer_blend(struct vl_compositor_state *state,
202 unsigned layer, void *blend, bool is_clearing);
203
204 /**
205 * set the layer destination area
206 */
207 void
208 vl_compositor_set_layer_dst_area(struct vl_compositor_state *settings,
209 unsigned layer, struct u_rect *dst_area);
210
211 /**
212 * set a video buffer as a layer to render
213 */
214 void
215 vl_compositor_set_buffer_layer(struct vl_compositor_state *state,
216 struct vl_compositor *compositor,
217 unsigned layer,
218 struct pipe_video_buffer *buffer,
219 struct u_rect *src_rect,
220 struct u_rect *dst_rect,
221 enum vl_compositor_deinterlace deinterlace);
222
223 /**
224 * set a paletted sampler as a layer to render
225 */
226 void
227 vl_compositor_set_palette_layer(struct vl_compositor_state *state,
228 struct vl_compositor *compositor,
229 unsigned layer,
230 struct pipe_sampler_view *indexes,
231 struct pipe_sampler_view *palette,
232 struct u_rect *src_rect,
233 struct u_rect *dst_rect,
234 bool include_color_conversion);
235
236 /**
237 * set a rgba sampler as a layer to render
238 */
239 void
240 vl_compositor_set_rgba_layer(struct vl_compositor_state *state,
241 struct vl_compositor *compositor,
242 unsigned layer,
243 struct pipe_sampler_view *rgba,
244 struct u_rect *src_rect,
245 struct u_rect *dst_rect,
246 struct vertex4f *colors);
247
248 /**
249 * set the layer rotation
250 */
251 void
252 vl_compositor_set_layer_rotation(struct vl_compositor_state *state,
253 unsigned layer,
254 enum vl_compositor_rotation rotate);
255
256 /**
257 * deinterlace yuv buffer with full abilities
258 */
259 void
260 vl_compositor_yuv_deint_full(struct vl_compositor_state *state,
261 struct vl_compositor *compositor,
262 struct pipe_video_buffer *src,
263 struct pipe_video_buffer *dst,
264 struct u_rect *src_rect,
265 struct u_rect *dst_rect,
266 enum vl_compositor_deinterlace deinterlace);
267
268 /**
269 + * convert rgb to yuv
270 + */
271 void
272 vl_compositor_convert_rgb_to_yuv(struct vl_compositor_state *state,
273 struct vl_compositor *compositor,
274 unsigned layer,
275 struct pipe_resource *src_res,
276 struct pipe_video_buffer *dst,
277 struct u_rect *src_rect,
278 struct u_rect *dst_rect);
279
280 /*@}*/
281
282 /**
283 * render the layers to the frontbuffer
284 */
285 void
286 vl_compositor_render(struct vl_compositor_state *state,
287 struct vl_compositor *compositor,
288 struct pipe_surface *dst_surface,
289 struct u_rect *dirty_area,
290 bool clear_dirty);
291
292 /**
293 * destroy this compositor
294 */
295 void
296 vl_compositor_cleanup(struct vl_compositor *compositor);
297
298 /**
299 * destroy this state bag
300 */
301 void
302 vl_compositor_cleanup_state(struct vl_compositor_state *state);
303
304 #endif /* vl_compositor_h */