From 74a4e9089488e7f341d21053bbf2d4aa52b99b70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christian=20K=C3=B6nig?= Date: Wed, 29 Feb 2012 15:54:56 +0100 Subject: [PATCH] vl/compositor: add support for per layer dst areas MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- src/gallium/auxiliary/vl/vl_compositor.c | 65 ++++++++++++----------- src/gallium/auxiliary/vl/vl_compositor.h | 19 ++++--- src/gallium/state_trackers/vdpau/mixer.c | 4 +- src/gallium/state_trackers/vdpau/output.c | 4 +- src/gallium/state_trackers/xvmc/surface.c | 3 +- 5 files changed, 51 insertions(+), 44 deletions(-) diff --git a/src/gallium/auxiliary/vl/vl_compositor.c b/src/gallium/auxiliary/vl/vl_compositor.c index 1e8d37f2be9..94d937714ba 100644 --- a/src/gallium/auxiliary/vl/vl_compositor.c +++ b/src/gallium/auxiliary/vl/vl_compositor.c @@ -641,10 +641,10 @@ calc_drawn_area(struct vl_compositor_state *s, struct vl_compositor_layer *layer struct u_rect result; // scale - result.x0 = layer->dst.tl.x * s->viewport.scale[0] + s->viewport.translate[0]; - result.y0 = layer->dst.tl.y * s->viewport.scale[1] + s->viewport.translate[1]; - result.x1 = layer->dst.br.x * s->viewport.scale[0] + s->viewport.translate[0]; - result.y1 = layer->dst.br.y * s->viewport.scale[1] + s->viewport.translate[1]; + result.x0 = layer->dst.tl.x * layer->viewport.scale[0] + layer->viewport.translate[0]; + result.y0 = layer->dst.tl.y * layer->viewport.scale[1] + layer->viewport.translate[1]; + result.x1 = layer->dst.br.x * layer->viewport.scale[0] + layer->viewport.translate[0]; + result.y1 = layer->dst.br.y * layer->viewport.scale[1] + layer->viewport.translate[1]; // and clip result.x0 = MAX2(result.x0, s->scissor.minx); @@ -681,6 +681,13 @@ gen_vertex_data(struct vl_compositor *c, struct vl_compositor_state *s, struct u gen_rect_verts(vb, layer); vb += 20; + if (!layer->viewport_valid) { + layer->viewport.scale[0] = c->fb_state.width; + layer->viewport.scale[1] = c->fb_state.height; + layer->viewport.translate[0] = 0; + layer->viewport.translate[1] = 0; + } + if (dirty && layer->clearing) { struct u_rect drawn = calc_drawn_area(s, layer); if ( @@ -715,6 +722,7 @@ draw_layers(struct vl_compositor *c, struct vl_compositor_state *s, struct u_rec void *blend = layer->blend ? layer->blend : i ? c->blend_add : c->blend_clear; c->pipe->bind_blend_state(c->pipe, blend); + c->pipe->set_viewport_state(c->pipe, &layer->viewport); c->pipe->bind_fs_state(c->pipe, layer->fs); c->pipe->bind_fragment_sampler_states(c->pipe, num_sampler_views, layer->samplers); c->pipe->set_fragment_sampler_views(c->pipe, num_sampler_views, samplers); @@ -773,6 +781,11 @@ vl_compositor_clear_layers(struct vl_compositor_state *s) s->layers[i].clearing = i ? false : true; s->layers[i].blend = NULL; s->layers[i].fs = NULL; + s->layers[i].viewport.scale[2] = 1; + s->layers[i].viewport.scale[3] = 1; + s->layers[i].viewport.translate[2] = 0; + s->layers[i].viewport.translate[3] = 0; + for ( j = 0; j < 3; j++) pipe_sampler_view_reference(&s->layers[i].sampler_views[j], NULL); for ( j = 0; j < 4; ++j) @@ -809,20 +822,6 @@ vl_compositor_set_csc_matrix(struct vl_compositor_state *s, const float matrix[1 pipe_buffer_unmap(s->pipe, buf_transfer); } -void -vl_compositor_set_dst_area(struct vl_compositor_state *s, struct u_rect *dst_area) -{ - assert(s); - - s->viewport_valid = dst_area != NULL; - if (dst_area) { - s->viewport.scale[0] = dst_area->x1 - dst_area->x0; - s->viewport.scale[1] = dst_area->y1 - dst_area->y0; - s->viewport.translate[0] = dst_area->x0; - s->viewport.translate[1] = dst_area->y0; - } -} - void vl_compositor_set_dst_clip(struct vl_compositor_state *s, struct u_rect *dst_clip) { @@ -850,6 +849,23 @@ vl_compositor_set_layer_blend(struct vl_compositor_state *s, s->layers[layer].blend = blend; } +void +vl_compositor_set_layer_dst_area(struct vl_compositor_state *s, + unsigned layer, struct u_rect *dst_area) +{ + assert(s); + + assert(layer < VL_COMPOSITOR_MAX_LAYERS); + + s->layers[layer].viewport_valid = dst_area != NULL; + if (dst_area) { + s->layers[layer].viewport.scale[0] = dst_area->x1 - dst_area->x0; + s->layers[layer].viewport.scale[1] = dst_area->y1 - dst_area->y0; + s->layers[layer].viewport.translate[0] = dst_area->x0; + s->layers[layer].viewport.translate[1] = dst_area->y0; + } +} + void vl_compositor_set_buffer_layer(struct vl_compositor_state *s, struct vl_compositor *c, @@ -978,13 +994,6 @@ vl_compositor_render(struct vl_compositor_state *s, c->fb_state.height = dst_surface->height; c->fb_state.cbufs[0] = dst_surface; - if (!s->viewport_valid) { - s->viewport.scale[0] = dst_surface->width; - s->viewport.scale[1] = dst_surface->height; - s->viewport.translate[0] = 0; - s->viewport.translate[1] = 0; - } - if (!s->scissor_valid) { s->scissor.minx = 0; s->scissor.miny = 0; @@ -1005,7 +1014,6 @@ vl_compositor_render(struct vl_compositor_state *s, c->pipe->set_scissor_state(c->pipe, &s->scissor); c->pipe->set_framebuffer_state(c->pipe, &c->fb_state); - c->pipe->set_viewport_state(c->pipe, &s->viewport); c->pipe->bind_vs_state(c->pipe, c->vs); c->pipe->set_vertex_buffers(c->pipe, 1, &c->vertex_buf); c->pipe->bind_vertex_elements_state(c->pipe, c->vertex_elems_state); @@ -1052,11 +1060,6 @@ vl_compositor_init_state(struct vl_compositor_state *s, struct pipe_context *pip s->pipe = pipe; - s->viewport.scale[2] = 1; - s->viewport.scale[3] = 1; - s->viewport.translate[2] = 0; - s->viewport.translate[3] = 0; - s->clear_color.f[0] = s->clear_color.f[1] = 0.0f; s->clear_color.f[2] = s->clear_color.f[3] = 0.0f; diff --git a/src/gallium/auxiliary/vl/vl_compositor.h b/src/gallium/auxiliary/vl/vl_compositor.h index f86a3f5f8db..f8f3dc0de98 100644 --- a/src/gallium/auxiliary/vl/vl_compositor.h +++ b/src/gallium/auxiliary/vl/vl_compositor.h @@ -56,6 +56,9 @@ struct vl_compositor_layer { bool clearing; + bool viewport_valid; + struct pipe_viewport_state viewport; + void *fs; void *samplers[3]; void *blend; @@ -72,8 +75,7 @@ struct vl_compositor_state { struct pipe_context *pipe; - bool viewport_valid, scissor_valid; - struct pipe_viewport_state viewport; + bool scissor_valid; struct pipe_scissor_state scissor; struct pipe_resource *csc_matrix; @@ -144,12 +146,6 @@ vl_compositor_set_clear_color(struct vl_compositor_state *settings, union pipe_c void vl_compositor_get_clear_color(struct vl_compositor_state *settings, union pipe_color_union *color); -/** - * set the destination area - */ -void -vl_compositor_set_dst_area(struct vl_compositor_state *settings, struct u_rect *dst_area); - /** * set the destination clipping */ @@ -174,6 +170,13 @@ void vl_compositor_set_layer_blend(struct vl_compositor_state *state, unsigned layer, void *blend, bool is_clearing); +/** + * set the layer destination area + */ +void +vl_compositor_set_layer_dst_area(struct vl_compositor_state *settings, + unsigned layer, struct u_rect *dst_area); + /** * set a video buffer as a layer to render */ diff --git a/src/gallium/state_trackers/vdpau/mixer.c b/src/gallium/state_trackers/vdpau/mixer.c index 066d60974f1..9a97501e456 100644 --- a/src/gallium/state_trackers/vdpau/mixer.c +++ b/src/gallium/state_trackers/vdpau/mixer.c @@ -265,9 +265,9 @@ VdpStatus vlVdpVideoMixerRender(VdpVideoMixer mixer, default: return VDP_STATUS_INVALID_VIDEO_MIXER_PICTURE_STRUCTURE; }; - vl_compositor_set_buffer_layer(&vmixer->cstate, compositor, layer++, surf->video_buffer, + vl_compositor_set_buffer_layer(&vmixer->cstate, compositor, layer, surf->video_buffer, RectToPipe(video_source_rect, &src_rect), NULL, deinterlace); - vl_compositor_set_dst_area(&vmixer->cstate, RectToPipe(destination_video_rect, &dst_rect)); + vl_compositor_set_layer_dst_area(&vmixer->cstate, layer++, RectToPipe(destination_video_rect, &dst_rect)); vl_compositor_set_dst_clip(&vmixer->cstate, RectToPipe(destination_rect, &dst_clip)); vl_compositor_render(&vmixer->cstate, compositor, dst->surface, &dst->dirty_area); diff --git a/src/gallium/state_trackers/vdpau/output.c b/src/gallium/state_trackers/vdpau/output.c index 9113e2574e2..b2c89620d29 100644 --- a/src/gallium/state_trackers/vdpau/output.c +++ b/src/gallium/state_trackers/vdpau/output.c @@ -310,7 +310,7 @@ vlVdpOutputSurfacePutBitsIndexed(VdpOutputSurface surface, vl_compositor_clear_layers(cstate); vl_compositor_set_palette_layer(cstate, compositor, 0, sv_idx, sv_tbl, NULL, NULL, false); - vl_compositor_set_dst_area(cstate, RectToPipe(destination_rect, &dst_rect)); + vl_compositor_set_layer_dst_area(cstate, 0, RectToPipe(destination_rect, &dst_rect)); vl_compositor_render(cstate, compositor, vlsurface->surface, NULL); pipe_sampler_view_reference(&sv_idx, NULL); @@ -473,7 +473,7 @@ vlVdpOutputSurfaceRenderOutputSurface(VdpOutputSurface destination_surface, vl_compositor_set_layer_blend(cstate, 0, blend, false); vl_compositor_set_rgba_layer(cstate, compositor, 0, src_vlsurface->sampler_view, RectToPipe(source_rect, &src_rect), NULL, NULL); - vl_compositor_set_dst_area(cstate, RectToPipe(destination_rect, &dst_rect)); + vl_compositor_set_layer_dst_area(cstate, 0, RectToPipe(destination_rect, &dst_rect)); vl_compositor_render(cstate, compositor, dst_vlsurface->surface, NULL); context->delete_blend_state(context, blend); diff --git a/src/gallium/state_trackers/xvmc/surface.c b/src/gallium/state_trackers/xvmc/surface.c index fcf6e619166..615fd08d2a1 100644 --- a/src/gallium/state_trackers/xvmc/surface.c +++ b/src/gallium/state_trackers/xvmc/surface.c @@ -432,7 +432,8 @@ Status XvMCPutSurface(Display *dpy, XvMCSurface *surface, Drawable drawable, // Workaround for r600g, there seems to be a bug in the fence refcounting code pipe->screen->fence_reference(pipe->screen, &surface_priv->fence, NULL); - vl_compositor_set_dst_area(cstate, &dst_rect); + vl_compositor_set_layer_dst_area(cstate, 0, &dst_rect); + vl_compositor_set_layer_dst_area(cstate, 1, &dst_rect); vl_compositor_render(cstate, compositor, surf, dirty_area); pipe->flush(pipe, &surface_priv->fence); -- 2.30.2