vl/compositor: add support for per layer dst areas
authorChristian König <deathsimple@vodafone.de>
Wed, 29 Feb 2012 14:54:56 +0000 (15:54 +0100)
committerChristian König <deathsimple@vodafone.de>
Fri, 2 Mar 2012 12:14:21 +0000 (13:14 +0100)
Signed-off-by: Christian König <deathsimple@vodafone.de>
src/gallium/auxiliary/vl/vl_compositor.c
src/gallium/auxiliary/vl/vl_compositor.h
src/gallium/state_trackers/vdpau/mixer.c
src/gallium/state_trackers/vdpau/output.c
src/gallium/state_trackers/xvmc/surface.c

index 1e8d37f2be9954312d07c7f558aefd680f407de0..94d937714baf33f339413b752909620389f21622 100644 (file)
@@ -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;
 
index f86a3f5f8dbbd98b0a9f879199c472bc63fe03b4..f8f3dc0de9855ed7f18f3b4e761c8e9edc339a95 100644 (file)
@@ -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
  */
index 066d60974f186b6a9637c475834de8587abab1b4..9a97501e456cf3bd9a1070d435f5b714192b338e 100644 (file)
@@ -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);
 
index 9113e2574e293a83048fd646f23bb85f8b5a8a72..b2c89620d29bdd5072a0da1f20a719e918233623 100644 (file)
@@ -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);
index fcf6e619166f08e1ef4c8bca3ad3f25eeed488cc..615fd08d2a1e565f619d5842ba5647f30ff273ba 100644 (file)
@@ -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);