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