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 187 /** 188 * initialize this compositor 189 */ 190 bool 191 vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe); 192 193 /** 194 * init state bag 195 */ 196 bool 197 vl_compositor_init_state(struct vl_compositor_state *state, struct pipe_context *pipe); 198 199 /** 200 * set yuv -> rgba conversion matrix 201 */ 202 bool 203 vl_compositor_set_csc_matrix(struct vl_compositor_state *settings, 204 const vl_csc_matrix *matrix, 205 float luma_min, float luma_max); 206 207 /** 208 * reset dirty area, so it's cleared with the clear colour 209 */ 210 void 211 vl_compositor_reset_dirty_area(struct u_rect *dirty); 212 213 /** 214 * set the clear color 215 */ 216 void 217 vl_compositor_set_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color); 218 219 /** 220 * get the clear color 221 */ 222 void 223 vl_compositor_get_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color); 224 225 /** 226 * set the destination clipping 227 */ 228 void 229 vl_compositor_set_dst_clip(struct vl_compositor_state *settings, struct u_rect *dst_clip); 230 231 /** 232 * set overlay samplers 233 */ 234 /*@{*/ 235 236 /** 237 * reset all currently set layers 238 */ 239 void 240 vl_compositor_clear_layers(struct vl_compositor_state *state); 241 242 /** 243 * set the blender used to render a layer 244 */ 245 void 246 vl_compositor_set_layer_blend(struct vl_compositor_state *state, 247 unsigned layer, void *blend, bool is_clearing); 248 249 /** 250 * set the layer destination area 251 */ 252 void 253 vl_compositor_set_layer_dst_area(struct vl_compositor_state *settings, 254 unsigned layer, struct u_rect *dst_area); 255 256 /** 257 * set a video buffer as a layer to render 258 */ 259 void 260 vl_compositor_set_buffer_layer(struct vl_compositor_state *state, 261 struct vl_compositor *compositor, 262 unsigned layer, 263 struct pipe_video_buffer *buffer, 264 struct u_rect *src_rect, 265 struct u_rect *dst_rect, 266 enum vl_compositor_deinterlace deinterlace); 267 268 /** 269 * set a paletted sampler as a layer to render 270 */ 271 void 272 vl_compositor_set_palette_layer(struct vl_compositor_state *state, 273 struct vl_compositor *compositor, 274 unsigned layer, 275 struct pipe_sampler_view *indexes, 276 struct pipe_sampler_view *palette, 277 struct u_rect *src_rect, 278 struct u_rect *dst_rect, 279 bool include_color_conversion); 280 281 /** 282 * set a rgba sampler as a layer to render 283 */ 284 void 285 vl_compositor_set_rgba_layer(struct vl_compositor_state *state, 286 struct vl_compositor *compositor, 287 unsigned layer, 288 struct pipe_sampler_view *rgba, 289 struct u_rect *src_rect, 290 struct u_rect *dst_rect, 291 struct vertex4f *colors); 292 293 /** 294 * set the layer rotation 295 */ 296 void 297 vl_compositor_set_layer_rotation(struct vl_compositor_state *state, 298 unsigned layer, 299 enum vl_compositor_rotation rotate); 300 301 /** 302 * deinterlace yuv buffer with full abilities 303 */ 304 void 305 vl_compositor_yuv_deint_full(struct vl_compositor_state *state, 306 struct vl_compositor *compositor, 307 struct pipe_video_buffer *src, 308 struct pipe_video_buffer *dst, 309 struct u_rect *src_rect, 310 struct u_rect *dst_rect, 311 enum vl_compositor_deinterlace deinterlace); 312 313 /** 314 + * convert rgb to yuv 315 + */ 316 void 317 vl_compositor_convert_rgb_to_yuv(struct vl_compositor_state *state, 318 struct vl_compositor *compositor, 319 unsigned layer, 320 struct pipe_resource *src_res, 321 struct pipe_video_buffer *dst, 322 struct u_rect *src_rect, 323 struct u_rect *dst_rect); 324 325 /*@}*/ 326 327 /** 328 * render the layers to the frontbuffer 329 */ 330 void 331 vl_compositor_render(struct vl_compositor_state *state, 332 struct vl_compositor *compositor, 333 struct pipe_surface *dst_surface, 334 struct u_rect *dirty_area, 335 bool clear_dirty); 336 337 /** 338 * destroy this compositor 339 */ 340 void 341 vl_compositor_cleanup(struct vl_compositor *compositor); 342 343 /** 344 * destroy this state bag 345 */ 346 void 347 vl_compositor_cleanup_state(struct vl_compositor_state *state); 348 349 #endif /* vl_compositor_h */ 350