• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define VL_COMPOSITOR_VB_STRIDE (sizeof(struct vertex2f) + sizeof(struct vertex4f) * 2)
51 
52 /* deinterlace allgorithem */
53 enum vl_compositor_deinterlace
54 {
55    VL_COMPOSITOR_NONE,
56    VL_COMPOSITOR_WEAVE,
57    VL_COMPOSITOR_BOB_TOP,
58    VL_COMPOSITOR_BOB_BOTTOM,
59    VL_COMPOSITOR_MOTION_ADAPTIVE
60 };
61 
62 /* clockwise degree */
63 enum vl_compositor_rotation
64 {
65    VL_COMPOSITOR_ROTATE_0,
66    VL_COMPOSITOR_ROTATE_90,
67    VL_COMPOSITOR_ROTATE_180,
68    VL_COMPOSITOR_ROTATE_270
69 };
70 
71 enum vl_compositor_mirror
72 {
73    VL_COMPOSITOR_MIRROR_NONE,
74    VL_COMPOSITOR_MIRROR_HORIZONTAL,
75    VL_COMPOSITOR_MIRROR_VERTICAL
76 };
77 
78 /* chroma sample location */
79 enum vl_compositor_chroma_location
80 {
81    VL_COMPOSITOR_LOCATION_NONE               = 0,
82    VL_COMPOSITOR_LOCATION_VERTICAL_TOP       = (1 << 0),
83    VL_COMPOSITOR_LOCATION_VERTICAL_CENTER    = (1 << 1),
84    VL_COMPOSITOR_LOCATION_VERTICAL_BOTTOM    = (1 << 2),
85    VL_COMPOSITOR_LOCATION_HORIZONTAL_LEFT    = (1 << 3),
86    VL_COMPOSITOR_LOCATION_HORIZONTAL_CENTER  = (1 << 4)
87 };
88 
89 enum vl_compositor_plane
90 {
91    VL_COMPOSITOR_PLANE_NONE  = 0,
92    VL_COMPOSITOR_PLANE_Y     = (1 << 0),
93    VL_COMPOSITOR_PLANE_U     = (1 << 1),
94    VL_COMPOSITOR_PLANE_V     = (1 << 2),
95    VL_COMPOSITOR_PLANE_UV    = VL_COMPOSITOR_PLANE_U | VL_COMPOSITOR_PLANE_V
96 };
97 
98 struct vl_compositor_layer
99 {
100    bool clearing;
101 
102    bool viewport_valid;
103    struct pipe_viewport_state viewport;
104 
105    void *fs;
106    void *cs;
107    void *samplers[3];
108    void *blend;
109 
110    struct pipe_sampler_view *sampler_views[3];
111    struct {
112       struct vertex2f tl, br;
113    } src, dst;
114    struct vertex2f zw;
115    struct vertex4f colors[4];
116    enum vl_compositor_rotation rotate;
117    enum vl_compositor_mirror mirror;
118 };
119 
120 struct vl_compositor_state
121 {
122    struct pipe_context *pipe;
123 
124    bool scissor_valid;
125    struct pipe_scissor_state scissor;
126    struct pipe_resource *shader_params;
127 
128    union pipe_color_union clear_color;
129 
130    unsigned used_layers:VL_COMPOSITOR_MAX_LAYERS;
131    struct vl_compositor_layer layers[VL_COMPOSITOR_MAX_LAYERS];
132    bool interlaced;
133    unsigned chroma_location;
134 
135    vl_csc_matrix csc_matrix;
136    float luma_min, luma_max;
137 };
138 
139 struct vl_compositor
140 {
141    struct pipe_context *pipe;
142 
143    struct pipe_framebuffer_state fb_state;
144    struct pipe_vertex_buffer vertex_buf;
145 
146    void *sampler_linear;
147    void *sampler_nearest;
148    void *blend_clear, *blend_add;
149    void *rast;
150    void *dsa;
151    void *vertex_elems_state;
152 
153    void *vs;
154    void *fs_video_buffer;
155    void *fs_weave_rgb;
156    void *fs_rgba;
157    void *cs_video_buffer;
158    void *cs_weave_rgb;
159    void *cs_rgba;
160 
161    bool pipe_cs_composit_supported;
162    bool pipe_gfx_supported;
163 
164    enum vl_compositor_deinterlace deinterlace;
165 
166    struct {
167       struct {
168          void *y;
169          void *uv;
170       } weave;
171       struct {
172          void *y;
173          void *uv;
174       } bob;
175    } fs_yuv;
176 
177    struct {
178       struct {
179          void *y;
180          void *uv;
181       } weave;
182       struct {
183          void *y;
184          void *uv;
185          void *u;
186          void *v;
187       } progressive;
188    } cs_yuv;
189 
190    struct {
191       void *rgb;
192       void *yuv;
193    } fs_palette;
194 
195    struct {
196       void *y;
197       void *uv;
198    } fs_rgb_yuv;
199 
200    struct {
201       void *y;
202       void *uv;
203       void *u;
204       void *v;
205    } cs_rgb_yuv;
206 
207    bool shaders_initialized;
208 };
209 
210 /**
211  * initialize this compositor
212  */
213 bool
214 vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe, bool compute_only);
215 
216 /**
217  * init state bag
218  */
219 bool
220 vl_compositor_init_state(struct vl_compositor_state *state, struct pipe_context *pipe);
221 
222 /**
223  * set yuv -> rgba conversion matrix
224  */
225 bool
226 vl_compositor_set_csc_matrix(struct vl_compositor_state *settings,
227                              const vl_csc_matrix *matrix,
228                              float luma_min, float luma_max);
229 
230 /**
231  * reset dirty area, so it's cleared with the clear colour
232  */
233 void
234 vl_compositor_reset_dirty_area(struct u_rect *dirty);
235 
236 /**
237  * set the clear color
238  */
239 void
240 vl_compositor_set_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color);
241 
242 /**
243  * get the clear color
244  */
245 void
246 vl_compositor_get_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color);
247 
248 /**
249  * set the destination clipping
250  */
251 void
252 vl_compositor_set_dst_clip(struct vl_compositor_state *settings, struct u_rect *dst_clip);
253 
254 /**
255  * set overlay samplers
256  */
257 /*@{*/
258 
259 /**
260  * reset all currently set layers
261  */
262 void
263 vl_compositor_clear_layers(struct vl_compositor_state *state);
264 
265 /**
266  * set the blender used to render a layer
267  */
268 void
269 vl_compositor_set_layer_blend(struct vl_compositor_state *state,
270                               unsigned layer, void *blend, bool is_clearing);
271 
272 /**
273  * set the layer destination area
274  */
275 void
276 vl_compositor_set_layer_dst_area(struct vl_compositor_state *settings,
277                                  unsigned layer, struct u_rect *dst_area);
278 
279 /**
280  * set a video buffer as a layer to render
281  */
282 void
283 vl_compositor_set_buffer_layer(struct vl_compositor_state *state,
284                                struct vl_compositor *compositor,
285                                unsigned layer,
286                                struct pipe_video_buffer *buffer,
287                                struct u_rect *src_rect,
288                                struct u_rect *dst_rect,
289                                enum vl_compositor_deinterlace deinterlace);
290 
291 /**
292  * set a paletted sampler as a layer to render
293  */
294 void
295 vl_compositor_set_palette_layer(struct vl_compositor_state *state,
296                                 struct vl_compositor *compositor,
297                                 unsigned layer,
298                                 struct pipe_sampler_view *indexes,
299                                 struct pipe_sampler_view *palette,
300                                 struct u_rect *src_rect,
301                                 struct u_rect *dst_rect,
302                                 bool include_color_conversion);
303 
304 /**
305  * set a rgba sampler as a layer to render
306  */
307 void
308 vl_compositor_set_rgba_layer(struct vl_compositor_state *state,
309                              struct vl_compositor *compositor,
310                              unsigned layer,
311                              struct pipe_sampler_view *rgba,
312                              struct u_rect *src_rect,
313                              struct u_rect *dst_rect,
314                              struct vertex4f *colors);
315 
316 /**
317  * set the layer rotation
318  */
319 void
320 vl_compositor_set_layer_rotation(struct vl_compositor_state *state,
321                                  unsigned layer,
322                                  enum vl_compositor_rotation rotate);
323 
324 /**
325  * set the layer mirror
326  */
327 void
328 vl_compositor_set_layer_mirror(struct vl_compositor_state *state,
329                                unsigned layer,
330                                enum vl_compositor_mirror mirror);
331 
332 /**
333  * deinterlace yuv buffer with full abilities
334  */
335 void
336 vl_compositor_yuv_deint_full(struct vl_compositor_state *state,
337                              struct vl_compositor *compositor,
338                              struct pipe_video_buffer *src,
339                              struct pipe_video_buffer *dst,
340                              struct u_rect *src_rect,
341                              struct u_rect *dst_rect,
342                              enum vl_compositor_deinterlace deinterlace);
343 
344 /**
345 + * convert rgb to yuv
346 + */
347 void
348 vl_compositor_convert_rgb_to_yuv(struct vl_compositor_state *state,
349                                  struct vl_compositor *compositor,
350                                  unsigned layer,
351                                  struct pipe_resource *src_res,
352                                  struct pipe_video_buffer *dst,
353                                  struct u_rect *src_rect,
354                                  struct u_rect *dst_rect);
355 
356 /*@}*/
357 
358 /**
359  * render the layers to the frontbuffer
360  */
361 void
362 vl_compositor_render(struct vl_compositor_state *state,
363                      struct vl_compositor       *compositor,
364                      struct pipe_surface        *dst_surface,
365                      struct u_rect              *dirty_area,
366                      bool                        clear_dirty);
367 
368 /**
369  * destroy this compositor
370  */
371 void
372 vl_compositor_cleanup(struct vl_compositor *compositor);
373 
374 /**
375  * destroy this state bag
376  */
377 void
378 vl_compositor_cleanup_state(struct vl_compositor_state *state);
379 
380 #endif /* vl_compositor_h */
381