1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2009 Younes Manton.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#ifndef vl_compositor_h
29bf215546Sopenharmony_ci#define vl_compositor_h
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "pipe/p_state.h"
32bf215546Sopenharmony_ci#include "pipe/p_video_codec.h"
33bf215546Sopenharmony_ci#include "pipe/p_video_state.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#include "util/u_rect.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "vl_types.h"
38bf215546Sopenharmony_ci#include "vl_csc.h"
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_cistruct pipe_context;
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci/**
43bf215546Sopenharmony_ci * composing and displaying of image data
44bf215546Sopenharmony_ci */
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci#define VL_COMPOSITOR_MAX_LAYERS 16
47bf215546Sopenharmony_ci#define VL_COMPOSITOR_MIN_DIRTY (0)
48bf215546Sopenharmony_ci#define VL_COMPOSITOR_MAX_DIRTY (1 << 15)
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci/* deinterlace allgorithem */
51bf215546Sopenharmony_cienum vl_compositor_deinterlace
52bf215546Sopenharmony_ci{
53bf215546Sopenharmony_ci   VL_COMPOSITOR_NONE,
54bf215546Sopenharmony_ci   VL_COMPOSITOR_WEAVE,
55bf215546Sopenharmony_ci   VL_COMPOSITOR_BOB_TOP,
56bf215546Sopenharmony_ci   VL_COMPOSITOR_BOB_BOTTOM,
57bf215546Sopenharmony_ci   VL_COMPOSITOR_MOTION_ADAPTIVE
58bf215546Sopenharmony_ci};
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci/* clockwise degree */
61bf215546Sopenharmony_cienum vl_compositor_rotation
62bf215546Sopenharmony_ci{
63bf215546Sopenharmony_ci   VL_COMPOSITOR_ROTATE_0,
64bf215546Sopenharmony_ci   VL_COMPOSITOR_ROTATE_90,
65bf215546Sopenharmony_ci   VL_COMPOSITOR_ROTATE_180,
66bf215546Sopenharmony_ci   VL_COMPOSITOR_ROTATE_270
67bf215546Sopenharmony_ci};
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_cistruct vl_compositor_layer
70bf215546Sopenharmony_ci{
71bf215546Sopenharmony_ci   bool clearing;
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci   bool viewport_valid;
74bf215546Sopenharmony_ci   struct pipe_viewport_state viewport;
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci   void *fs;
77bf215546Sopenharmony_ci   void *cs;
78bf215546Sopenharmony_ci   void *samplers[3];
79bf215546Sopenharmony_ci   void *blend;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   struct pipe_sampler_view *sampler_views[3];
82bf215546Sopenharmony_ci   struct {
83bf215546Sopenharmony_ci      struct vertex2f tl, br;
84bf215546Sopenharmony_ci   } src, dst;
85bf215546Sopenharmony_ci   struct vertex2f zw;
86bf215546Sopenharmony_ci   struct vertex4f colors[4];
87bf215546Sopenharmony_ci   enum vl_compositor_rotation rotate;
88bf215546Sopenharmony_ci};
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_cistruct vl_compositor_state
91bf215546Sopenharmony_ci{
92bf215546Sopenharmony_ci   struct pipe_context *pipe;
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci   bool scissor_valid;
95bf215546Sopenharmony_ci   struct pipe_scissor_state scissor;
96bf215546Sopenharmony_ci   struct pipe_resource *shader_params;
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci   union pipe_color_union clear_color;
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci   unsigned used_layers:VL_COMPOSITOR_MAX_LAYERS;
101bf215546Sopenharmony_ci   struct vl_compositor_layer layers[VL_COMPOSITOR_MAX_LAYERS];
102bf215546Sopenharmony_ci   bool interlaced;
103bf215546Sopenharmony_ci};
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_cistruct vl_compositor
106bf215546Sopenharmony_ci{
107bf215546Sopenharmony_ci   struct pipe_context *pipe;
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci   struct pipe_framebuffer_state fb_state;
110bf215546Sopenharmony_ci   struct pipe_vertex_buffer vertex_buf;
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci   void *sampler_linear;
113bf215546Sopenharmony_ci   void *sampler_nearest;
114bf215546Sopenharmony_ci   void *blend_clear, *blend_add;
115bf215546Sopenharmony_ci   void *rast;
116bf215546Sopenharmony_ci   void *dsa;
117bf215546Sopenharmony_ci   void *vertex_elems_state;
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci   void *vs;
120bf215546Sopenharmony_ci   void *fs_video_buffer;
121bf215546Sopenharmony_ci   void *fs_weave_rgb;
122bf215546Sopenharmony_ci   void *fs_rgba;
123bf215546Sopenharmony_ci   void *cs_video_buffer;
124bf215546Sopenharmony_ci   void *cs_weave_rgb;
125bf215546Sopenharmony_ci   void *cs_rgba;
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci   bool pipe_cs_composit_supported;
128bf215546Sopenharmony_ci   bool pipe_gfx_supported;
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci   enum vl_compositor_deinterlace deinterlace;
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci   struct {
133bf215546Sopenharmony_ci      struct {
134bf215546Sopenharmony_ci         void *y;
135bf215546Sopenharmony_ci         void *uv;
136bf215546Sopenharmony_ci      } weave;
137bf215546Sopenharmony_ci      struct {
138bf215546Sopenharmony_ci         void *y;
139bf215546Sopenharmony_ci         void *uv;
140bf215546Sopenharmony_ci      } bob;
141bf215546Sopenharmony_ci   } fs_yuv;
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci   struct {
144bf215546Sopenharmony_ci      struct {
145bf215546Sopenharmony_ci         void *y;
146bf215546Sopenharmony_ci         void *uv;
147bf215546Sopenharmony_ci      } weave;
148bf215546Sopenharmony_ci      struct {
149bf215546Sopenharmony_ci         void *y;
150bf215546Sopenharmony_ci         void *uv;
151bf215546Sopenharmony_ci      } bob;
152bf215546Sopenharmony_ci   } cs_yuv;
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_ci   struct {
155bf215546Sopenharmony_ci      void *rgb;
156bf215546Sopenharmony_ci      void *yuv;
157bf215546Sopenharmony_ci   } fs_palette;
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   struct {
160bf215546Sopenharmony_ci      void *y;
161bf215546Sopenharmony_ci      void *uv;
162bf215546Sopenharmony_ci   } fs_rgb_yuv;
163bf215546Sopenharmony_ci};
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci/**
166bf215546Sopenharmony_ci * initialize this compositor
167bf215546Sopenharmony_ci */
168bf215546Sopenharmony_cibool
169bf215546Sopenharmony_civl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe);
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci/**
172bf215546Sopenharmony_ci * init state bag
173bf215546Sopenharmony_ci */
174bf215546Sopenharmony_cibool
175bf215546Sopenharmony_civl_compositor_init_state(struct vl_compositor_state *state, struct pipe_context *pipe);
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci/**
178bf215546Sopenharmony_ci * set yuv -> rgba conversion matrix
179bf215546Sopenharmony_ci */
180bf215546Sopenharmony_cibool
181bf215546Sopenharmony_civl_compositor_set_csc_matrix(struct vl_compositor_state *settings,
182bf215546Sopenharmony_ci                             const vl_csc_matrix *matrix,
183bf215546Sopenharmony_ci                             float luma_min, float luma_max);
184bf215546Sopenharmony_ci
185bf215546Sopenharmony_ci/**
186bf215546Sopenharmony_ci * reset dirty area, so it's cleared with the clear colour
187bf215546Sopenharmony_ci */
188bf215546Sopenharmony_civoid
189bf215546Sopenharmony_civl_compositor_reset_dirty_area(struct u_rect *dirty);
190bf215546Sopenharmony_ci
191bf215546Sopenharmony_ci/**
192bf215546Sopenharmony_ci * set the clear color
193bf215546Sopenharmony_ci */
194bf215546Sopenharmony_civoid
195bf215546Sopenharmony_civl_compositor_set_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color);
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_ci/**
198bf215546Sopenharmony_ci * get the clear color
199bf215546Sopenharmony_ci */
200bf215546Sopenharmony_civoid
201bf215546Sopenharmony_civl_compositor_get_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color);
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_ci/**
204bf215546Sopenharmony_ci * set the destination clipping
205bf215546Sopenharmony_ci */
206bf215546Sopenharmony_civoid
207bf215546Sopenharmony_civl_compositor_set_dst_clip(struct vl_compositor_state *settings, struct u_rect *dst_clip);
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_ci/**
210bf215546Sopenharmony_ci * set overlay samplers
211bf215546Sopenharmony_ci */
212bf215546Sopenharmony_ci/*@{*/
213bf215546Sopenharmony_ci
214bf215546Sopenharmony_ci/**
215bf215546Sopenharmony_ci * reset all currently set layers
216bf215546Sopenharmony_ci */
217bf215546Sopenharmony_civoid
218bf215546Sopenharmony_civl_compositor_clear_layers(struct vl_compositor_state *state);
219bf215546Sopenharmony_ci
220bf215546Sopenharmony_ci/**
221bf215546Sopenharmony_ci * set the blender used to render a layer
222bf215546Sopenharmony_ci */
223bf215546Sopenharmony_civoid
224bf215546Sopenharmony_civl_compositor_set_layer_blend(struct vl_compositor_state *state,
225bf215546Sopenharmony_ci                              unsigned layer, void *blend, bool is_clearing);
226bf215546Sopenharmony_ci
227bf215546Sopenharmony_ci/**
228bf215546Sopenharmony_ci * set the layer destination area
229bf215546Sopenharmony_ci */
230bf215546Sopenharmony_civoid
231bf215546Sopenharmony_civl_compositor_set_layer_dst_area(struct vl_compositor_state *settings,
232bf215546Sopenharmony_ci                                 unsigned layer, struct u_rect *dst_area);
233bf215546Sopenharmony_ci
234bf215546Sopenharmony_ci/**
235bf215546Sopenharmony_ci * set a video buffer as a layer to render
236bf215546Sopenharmony_ci */
237bf215546Sopenharmony_civoid
238bf215546Sopenharmony_civl_compositor_set_buffer_layer(struct vl_compositor_state *state,
239bf215546Sopenharmony_ci                               struct vl_compositor *compositor,
240bf215546Sopenharmony_ci                               unsigned layer,
241bf215546Sopenharmony_ci                               struct pipe_video_buffer *buffer,
242bf215546Sopenharmony_ci                               struct u_rect *src_rect,
243bf215546Sopenharmony_ci                               struct u_rect *dst_rect,
244bf215546Sopenharmony_ci                               enum vl_compositor_deinterlace deinterlace);
245bf215546Sopenharmony_ci
246bf215546Sopenharmony_ci/**
247bf215546Sopenharmony_ci * set a paletted sampler as a layer to render
248bf215546Sopenharmony_ci */
249bf215546Sopenharmony_civoid
250bf215546Sopenharmony_civl_compositor_set_palette_layer(struct vl_compositor_state *state,
251bf215546Sopenharmony_ci                                struct vl_compositor *compositor,
252bf215546Sopenharmony_ci                                unsigned layer,
253bf215546Sopenharmony_ci                                struct pipe_sampler_view *indexes,
254bf215546Sopenharmony_ci                                struct pipe_sampler_view *palette,
255bf215546Sopenharmony_ci                                struct u_rect *src_rect,
256bf215546Sopenharmony_ci                                struct u_rect *dst_rect,
257bf215546Sopenharmony_ci                                bool include_color_conversion);
258bf215546Sopenharmony_ci
259bf215546Sopenharmony_ci/**
260bf215546Sopenharmony_ci * set a rgba sampler as a layer to render
261bf215546Sopenharmony_ci */
262bf215546Sopenharmony_civoid
263bf215546Sopenharmony_civl_compositor_set_rgba_layer(struct vl_compositor_state *state,
264bf215546Sopenharmony_ci                             struct vl_compositor *compositor,
265bf215546Sopenharmony_ci                             unsigned layer,
266bf215546Sopenharmony_ci                             struct pipe_sampler_view *rgba,
267bf215546Sopenharmony_ci                             struct u_rect *src_rect,
268bf215546Sopenharmony_ci                             struct u_rect *dst_rect,
269bf215546Sopenharmony_ci                             struct vertex4f *colors);
270bf215546Sopenharmony_ci
271bf215546Sopenharmony_ci/**
272bf215546Sopenharmony_ci * set the layer rotation
273bf215546Sopenharmony_ci */
274bf215546Sopenharmony_civoid
275bf215546Sopenharmony_civl_compositor_set_layer_rotation(struct vl_compositor_state *state,
276bf215546Sopenharmony_ci                                 unsigned layer,
277bf215546Sopenharmony_ci                                 enum vl_compositor_rotation rotate);
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_ci/**
280bf215546Sopenharmony_ci * deinterlace yuv buffer with full abilities
281bf215546Sopenharmony_ci */
282bf215546Sopenharmony_civoid
283bf215546Sopenharmony_civl_compositor_yuv_deint_full(struct vl_compositor_state *state,
284bf215546Sopenharmony_ci                             struct vl_compositor *compositor,
285bf215546Sopenharmony_ci                             struct pipe_video_buffer *src,
286bf215546Sopenharmony_ci                             struct pipe_video_buffer *dst,
287bf215546Sopenharmony_ci                             struct u_rect *src_rect,
288bf215546Sopenharmony_ci                             struct u_rect *dst_rect,
289bf215546Sopenharmony_ci                             enum vl_compositor_deinterlace deinterlace);
290bf215546Sopenharmony_ci
291bf215546Sopenharmony_ci/**
292bf215546Sopenharmony_ci+ * convert rgb to yuv
293bf215546Sopenharmony_ci+ */
294bf215546Sopenharmony_civoid
295bf215546Sopenharmony_civl_compositor_convert_rgb_to_yuv(struct vl_compositor_state *state,
296bf215546Sopenharmony_ci                                 struct vl_compositor *compositor,
297bf215546Sopenharmony_ci                                 unsigned layer,
298bf215546Sopenharmony_ci                                 struct pipe_resource *src_res,
299bf215546Sopenharmony_ci                                 struct pipe_video_buffer *dst,
300bf215546Sopenharmony_ci                                 struct u_rect *src_rect,
301bf215546Sopenharmony_ci                                 struct u_rect *dst_rect);
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci/*@}*/
304bf215546Sopenharmony_ci
305bf215546Sopenharmony_ci/**
306bf215546Sopenharmony_ci * render the layers to the frontbuffer
307bf215546Sopenharmony_ci */
308bf215546Sopenharmony_civoid
309bf215546Sopenharmony_civl_compositor_render(struct vl_compositor_state *state,
310bf215546Sopenharmony_ci                     struct vl_compositor       *compositor,
311bf215546Sopenharmony_ci                     struct pipe_surface        *dst_surface,
312bf215546Sopenharmony_ci                     struct u_rect              *dirty_area,
313bf215546Sopenharmony_ci                     bool                        clear_dirty);
314bf215546Sopenharmony_ci
315bf215546Sopenharmony_ci/**
316bf215546Sopenharmony_ci * destroy this compositor
317bf215546Sopenharmony_ci */
318bf215546Sopenharmony_civoid
319bf215546Sopenharmony_civl_compositor_cleanup(struct vl_compositor *compositor);
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci/**
322bf215546Sopenharmony_ci * destroy this state bag
323bf215546Sopenharmony_ci */
324bf215546Sopenharmony_civoid
325bf215546Sopenharmony_civl_compositor_cleanup_state(struct vl_compositor_state *state);
326bf215546Sopenharmony_ci
327bf215546Sopenharmony_ci#endif /* vl_compositor_h */
328