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