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