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 40struct pipe_context; 41 42/** 43 * composing and displaying of image data 44 */ 45 46#define VL_COMPOSITOR_MAX_LAYERS 16 47 48/* deinterlace allgorithem */ 49enum vl_compositor_deinterlace 50{ 51 VL_COMPOSITOR_WEAVE, 52 VL_COMPOSITOR_BOB_TOP, 53 VL_COMPOSITOR_BOB_BOTTOM 54}; 55 56/* clockwise degree */ 57enum vl_compositor_rotation 58{ 59 VL_COMPOSITOR_ROTATE_0, 60 VL_COMPOSITOR_ROTATE_90, 61 VL_COMPOSITOR_ROTATE_180, 62 VL_COMPOSITOR_ROTATE_270 63}; 64 65struct vl_compositor_layer 66{ 67 bool clearing; 68 69 bool viewport_valid; 70 struct pipe_viewport_state viewport; 71 72 void *fs; 73 void *samplers[3]; 74 void *blend; 75 76 struct pipe_sampler_view *sampler_views[3]; 77 struct { 78 struct vertex2f tl, br; 79 } src, dst; 80 struct vertex2f zw; 81 struct vertex4f colors[4]; 82 enum vl_compositor_rotation rotate; 83}; 84 85struct vl_compositor_state 86{ 87 struct pipe_context *pipe; 88 89 bool scissor_valid; 90 struct pipe_scissor_state scissor; 91 struct pipe_resource *csc_matrix; 92 93 union pipe_color_union clear_color; 94 95 unsigned used_layers:VL_COMPOSITOR_MAX_LAYERS; 96 struct vl_compositor_layer layers[VL_COMPOSITOR_MAX_LAYERS]; 97}; 98 99struct vl_compositor 100{ 101 struct pipe_context *pipe; 102 struct u_upload_mgr *upload; 103 104 struct pipe_framebuffer_state fb_state; 105 struct pipe_vertex_buffer vertex_buf; 106 107 void *sampler_linear; 108 void *sampler_nearest; 109 void *blend_clear, *blend_add; 110 void *rast; 111 void *dsa; 112 void *vertex_elems_state; 113 114 void *vs; 115 void *fs_video_buffer; 116 void *fs_weave_rgb; 117 void *fs_rgba; 118 119 struct { 120 void *y; 121 void *uv; 122 } fs_weave_yuv; 123 124 struct { 125 void *rgb; 126 void *yuv; 127 } fs_palette; 128}; 129 130/** 131 * initialize this compositor 132 */ 133bool 134vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe); 135 136/** 137 * init state bag 138 */ 139bool 140vl_compositor_init_state(struct vl_compositor_state *state, struct pipe_context *pipe); 141 142/** 143 * set yuv -> rgba conversion matrix 144 */ 145bool 146vl_compositor_set_csc_matrix(struct vl_compositor_state *settings, 147 const vl_csc_matrix *matrix, 148 float luma_min, float luma_max); 149 150/** 151 * reset dirty area, so it's cleared with the clear colour 152 */ 153void 154vl_compositor_reset_dirty_area(struct u_rect *dirty); 155 156/** 157 * set the clear color 158 */ 159void 160vl_compositor_set_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color); 161 162/** 163 * get the clear color 164 */ 165void 166vl_compositor_get_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color); 167 168/** 169 * set the destination clipping 170 */ 171void 172vl_compositor_set_dst_clip(struct vl_compositor_state *settings, struct u_rect *dst_clip); 173 174/** 175 * set overlay samplers 176 */ 177/*@{*/ 178 179/** 180 * reset all currently set layers 181 */ 182void 183vl_compositor_clear_layers(struct vl_compositor_state *state); 184 185/** 186 * set the blender used to render a layer 187 */ 188void 189vl_compositor_set_layer_blend(struct vl_compositor_state *state, 190 unsigned layer, void *blend, bool is_clearing); 191 192/** 193 * set the layer destination area 194 */ 195void 196vl_compositor_set_layer_dst_area(struct vl_compositor_state *settings, 197 unsigned layer, struct u_rect *dst_area); 198 199/** 200 * set a video buffer as a layer to render 201 */ 202void 203vl_compositor_set_buffer_layer(struct vl_compositor_state *state, 204 struct vl_compositor *compositor, 205 unsigned layer, 206 struct pipe_video_buffer *buffer, 207 struct u_rect *src_rect, 208 struct u_rect *dst_rect, 209 enum vl_compositor_deinterlace deinterlace); 210 211/** 212 * set a paletted sampler as a layer to render 213 */ 214void 215vl_compositor_set_palette_layer(struct vl_compositor_state *state, 216 struct vl_compositor *compositor, 217 unsigned layer, 218 struct pipe_sampler_view *indexes, 219 struct pipe_sampler_view *palette, 220 struct u_rect *src_rect, 221 struct u_rect *dst_rect, 222 bool include_color_conversion); 223 224/** 225 * set a rgba sampler as a layer to render 226 */ 227void 228vl_compositor_set_rgba_layer(struct vl_compositor_state *state, 229 struct vl_compositor *compositor, 230 unsigned layer, 231 struct pipe_sampler_view *rgba, 232 struct u_rect *src_rect, 233 struct u_rect *dst_rect, 234 struct vertex4f *colors); 235 236/** 237 * set the layer rotation 238 */ 239void 240vl_compositor_set_layer_rotation(struct vl_compositor_state *state, 241 unsigned layer, 242 enum vl_compositor_rotation rotate); 243 244/** 245 * set a layer of y or uv to render 246 */ 247void 248vl_compositor_set_yuv_layer(struct vl_compositor_state *s, 249 struct vl_compositor *c, 250 unsigned layer, 251 struct pipe_video_buffer *buffer, 252 struct u_rect *src_rect, 253 struct u_rect *dst_rect, 254 bool y); 255 256/*@}*/ 257 258/** 259 * render the layers to the frontbuffer 260 */ 261void 262vl_compositor_render(struct vl_compositor_state *state, 263 struct vl_compositor *compositor, 264 struct pipe_surface *dst_surface, 265 struct u_rect *dirty_area, 266 bool clear_dirty); 267 268/** 269 * destroy this compositor 270 */ 271void 272vl_compositor_cleanup(struct vl_compositor *compositor); 273 274/** 275 * destroy this state bag 276 */ 277void 278vl_compositor_cleanup_state(struct vl_compositor_state *state); 279 280#endif /* vl_compositor_h */ 281