panfrost: Start tracking inter-batch dependencies
[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 *cs;
76 void *samplers[3];
77 void *blend;
78
79 struct pipe_sampler_view *sampler_views[3];
80 struct {
81 struct vertex2f tl, br;
82 } src, dst;
83 struct vertex2f zw;
84 struct vertex4f colors[4];
85 enum vl_compositor_rotation rotate;
86 };
87
88 struct vl_compositor_state
89 {
90 struct pipe_context *pipe;
91
92 bool scissor_valid;
93 struct pipe_scissor_state scissor;
94 struct pipe_resource *shader_params;
95
96 union pipe_color_union clear_color;
97
98 unsigned used_layers:VL_COMPOSITOR_MAX_LAYERS;
99 struct vl_compositor_layer layers[VL_COMPOSITOR_MAX_LAYERS];
100 };
101
102 struct vl_compositor
103 {
104 struct pipe_context *pipe;
105
106 struct pipe_framebuffer_state fb_state;
107 struct pipe_vertex_buffer vertex_buf;
108
109 void *sampler_linear;
110 void *sampler_nearest;
111 void *blend_clear, *blend_add;
112 void *rast;
113 void *dsa;
114 void *vertex_elems_state;
115
116 void *vs;
117 void *fs_video_buffer;
118 void *fs_weave_rgb;
119 void *fs_rgba;
120 void *cs_video_buffer;
121 void *cs_weave_rgb;
122 void *cs_rgba;
123
124 bool pipe_cs_composit_supported;
125 bool pipe_gfx_supported;
126
127 struct {
128 struct {
129 void *y;
130 void *uv;
131 } weave;
132 struct {
133 void *y;
134 void *uv;
135 } bob;
136 } fs_yuv;
137
138 struct {
139 struct {
140 void *y;
141 void *uv;
142 } weave;
143 struct {
144 void *y;
145 void *uv;
146 } bob;
147 } cs_yuv;
148
149 struct {
150 void *rgb;
151 void *yuv;
152 } fs_palette;
153
154 struct {
155 void *y;
156 void *uv;
157 } fs_rgb_yuv;
158 };
159
160 /**
161 * initialize this compositor
162 */
163 bool
164 vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe);
165
166 /**
167 * init state bag
168 */
169 bool
170 vl_compositor_init_state(struct vl_compositor_state *state, struct pipe_context *pipe);
171
172 /**
173 * set yuv -> rgba conversion matrix
174 */
175 bool
176 vl_compositor_set_csc_matrix(struct vl_compositor_state *settings,
177 const vl_csc_matrix *matrix,
178 float luma_min, float luma_max);
179
180 /**
181 * reset dirty area, so it's cleared with the clear colour
182 */
183 void
184 vl_compositor_reset_dirty_area(struct u_rect *dirty);
185
186 /**
187 * set the clear color
188 */
189 void
190 vl_compositor_set_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color);
191
192 /**
193 * get the clear color
194 */
195 void
196 vl_compositor_get_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color);
197
198 /**
199 * set the destination clipping
200 */
201 void
202 vl_compositor_set_dst_clip(struct vl_compositor_state *settings, struct u_rect *dst_clip);
203
204 /**
205 * set overlay samplers
206 */
207 /*@{*/
208
209 /**
210 * reset all currently set layers
211 */
212 void
213 vl_compositor_clear_layers(struct vl_compositor_state *state);
214
215 /**
216 * set the blender used to render a layer
217 */
218 void
219 vl_compositor_set_layer_blend(struct vl_compositor_state *state,
220 unsigned layer, void *blend, bool is_clearing);
221
222 /**
223 * set the layer destination area
224 */
225 void
226 vl_compositor_set_layer_dst_area(struct vl_compositor_state *settings,
227 unsigned layer, struct u_rect *dst_area);
228
229 /**
230 * set a video buffer as a layer to render
231 */
232 void
233 vl_compositor_set_buffer_layer(struct vl_compositor_state *state,
234 struct vl_compositor *compositor,
235 unsigned layer,
236 struct pipe_video_buffer *buffer,
237 struct u_rect *src_rect,
238 struct u_rect *dst_rect,
239 enum vl_compositor_deinterlace deinterlace);
240
241 /**
242 * set a paletted sampler as a layer to render
243 */
244 void
245 vl_compositor_set_palette_layer(struct vl_compositor_state *state,
246 struct vl_compositor *compositor,
247 unsigned layer,
248 struct pipe_sampler_view *indexes,
249 struct pipe_sampler_view *palette,
250 struct u_rect *src_rect,
251 struct u_rect *dst_rect,
252 bool include_color_conversion);
253
254 /**
255 * set a rgba sampler as a layer to render
256 */
257 void
258 vl_compositor_set_rgba_layer(struct vl_compositor_state *state,
259 struct vl_compositor *compositor,
260 unsigned layer,
261 struct pipe_sampler_view *rgba,
262 struct u_rect *src_rect,
263 struct u_rect *dst_rect,
264 struct vertex4f *colors);
265
266 /**
267 * set the layer rotation
268 */
269 void
270 vl_compositor_set_layer_rotation(struct vl_compositor_state *state,
271 unsigned layer,
272 enum vl_compositor_rotation rotate);
273
274 /**
275 * deinterlace yuv buffer with full abilities
276 */
277 void
278 vl_compositor_yuv_deint_full(struct vl_compositor_state *state,
279 struct vl_compositor *compositor,
280 struct pipe_video_buffer *src,
281 struct pipe_video_buffer *dst,
282 struct u_rect *src_rect,
283 struct u_rect *dst_rect,
284 enum vl_compositor_deinterlace deinterlace);
285
286 /**
287 + * convert rgb to yuv
288 + */
289 void
290 vl_compositor_convert_rgb_to_yuv(struct vl_compositor_state *state,
291 struct vl_compositor *compositor,
292 unsigned layer,
293 struct pipe_resource *src_res,
294 struct pipe_video_buffer *dst,
295 struct u_rect *src_rect,
296 struct u_rect *dst_rect);
297
298 /*@}*/
299
300 /**
301 * render the layers to the frontbuffer
302 */
303 void
304 vl_compositor_render(struct vl_compositor_state *state,
305 struct vl_compositor *compositor,
306 struct pipe_surface *dst_surface,
307 struct u_rect *dirty_area,
308 bool clear_dirty);
309
310 /**
311 * destroy this compositor
312 */
313 void
314 vl_compositor_cleanup(struct vl_compositor *compositor);
315
316 /**
317 * destroy this state bag
318 */
319 void
320 vl_compositor_cleanup_state(struct vl_compositor_state *state);
321
322 #endif /* vl_compositor_h */