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