Mesa (master): st/vega: Create drawing surface mask as needed.

Chia-I Wu olv at kemper.freedesktop.org
Wed Dec 1 12:22:40 UTC 2010


Module: Mesa
Branch: master
Commit: c91c38601234dc67fa356160cbe3bd389cac083a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c91c38601234dc67fa356160cbe3bd389cac083a

Author: Chia-I Wu <olv at lunarg.com>
Date:   Wed Dec  1 17:51:41 2010 +0800

st/vega: Create drawing surface mask as needed.

As the blend texture, a drawing surface mask is used when masking is
enabled.  It should be created as needed.

s/alpha_mask/surface_mask/ to follow OpenVG 1.1 naming.

---

 src/gallium/state_trackers/vega/mask.c       |   38 +++++++++++---------------
 src/gallium/state_trackers/vega/vg_context.c |   31 +++++++++++++--------
 src/gallium/state_trackers/vega/vg_context.h |    4 ++-
 3 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/src/gallium/state_trackers/vega/mask.c b/src/gallium/state_trackers/vega/mask.c
index 0a800b2..8431e1b 100644
--- a/src/gallium/state_trackers/vega/mask.c
+++ b/src/gallium/state_trackers/vega/mask.c
@@ -48,17 +48,6 @@ struct vg_mask_layer {
    struct pipe_sampler_view *sampler_view;
 };
 
-static INLINE struct pipe_surface *
-alpha_mask_surface(struct vg_context *ctx, int usage)
-{
-   struct pipe_screen *screen = ctx->pipe->screen;
-   struct st_framebuffer *stfb = ctx->draw_buffer;
-   return screen->get_tex_surface(screen,
-                                  stfb->alpha_mask_view->texture,
-                                  0, 0, 0,
-                                  usage);
-}
-
 static INLINE VGboolean
 intersect_rectangles(VGint dwidth, VGint dheight,
                      VGint swidth, VGint sheight,
@@ -289,7 +278,8 @@ static void mask_using_texture(struct pipe_sampler_view *sampler_view,
                                VGint width, VGint height)
 {
    struct vg_context *ctx = vg_current_context();
-   struct pipe_resource *dst = ctx->draw_buffer->alpha_mask_view->texture;
+   struct pipe_sampler_view *dst_view = vg_get_surface_mask(ctx);
+   struct pipe_resource *dst = dst_view->texture;
    struct pipe_resource *texture = sampler_view->texture;
    const struct pipe_sampler_state *samplers[2];
    struct pipe_sampler_view *views[2];
@@ -310,6 +300,7 @@ static void mask_using_texture(struct pipe_sampler_view *sampler_view,
                 loc[1], loc[2], loc[3]);
 #endif
 
+
    sampler = ctx->mask.sampler;
    sampler.normalized_coords = 1;
    samplers[0] = &sampler;
@@ -408,7 +399,7 @@ void mask_copy(struct vg_mask_layer *layer,
                VGint width, VGint height)
 {
    struct vg_context *ctx = vg_current_context();
-   struct pipe_sampler_view *src = ctx->draw_buffer->alpha_mask_view;
+   struct pipe_sampler_view *src = vg_get_surface_mask(ctx);
    struct pipe_surface *surf;
 
    /* get the destination surface */
@@ -433,10 +424,13 @@ static void mask_layer_render_to(struct vg_mask_layer *layer,
                                  VGbitfield paint_modes)
 {
    struct vg_context *ctx = vg_current_context();
+   struct pipe_screen *screen = ctx->pipe->screen;
+   struct pipe_sampler_view *view = vg_get_surface_mask(ctx);
    struct matrix *mat = &ctx->state.vg.path_user_to_surface_matrix;
    struct pipe_surface *surf;
 
-   surf = alpha_mask_surface(ctx, PIPE_BIND_RENDER_TARGET);
+   surf = screen->get_tex_surface(screen, view->texture,
+                                  0, 0, 0, PIPE_BIND_RENDER_TARGET);
 
    renderer_validate_for_mask_rendering(ctx->renderer, surf);
 
@@ -447,6 +441,8 @@ static void mask_layer_render_to(struct vg_mask_layer *layer,
    if (paint_modes & VG_STROKE_PATH){
       path_stroke(path, mat);
    }
+
+   pipe_surface_reference(&surf, NULL);
 }
 
 void mask_render_to(struct path *path,
@@ -454,12 +450,12 @@ void mask_render_to(struct path *path,
                     VGMaskOperation operation)
 {
    struct vg_context *ctx = vg_current_context();
-   struct st_framebuffer *fb_buffers = ctx->draw_buffer;
+   struct st_framebuffer *stfb = ctx->draw_buffer;
    struct vg_mask_layer *temp_layer;
    VGint width, height;
 
-   width = fb_buffers->alpha_mask_view->texture->width0;
-   height = fb_buffers->alpha_mask_view->texture->height0;
+   width = stfb->width;
+   height = stfb->height;
 
    temp_layer = mask_layer_create(width, height);
    mask_layer_fill(temp_layer, 0, 0, width, height, 0.0f);
@@ -506,6 +502,7 @@ void mask_fill(VGint x, VGint y, VGint width, VGint height,
                VGfloat value)
 {
    struct vg_context *ctx = vg_current_context();
+   struct pipe_sampler_view *view = vg_get_surface_mask(ctx);
 
 #if DEBUG_MASKS
    debug_printf("mask_fill(%d, %d, %d, %d) with  rgba(%f, %f, %f, %f)\n",
@@ -513,8 +510,7 @@ void mask_fill(VGint x, VGint y, VGint width, VGint height,
                 0.0f, 0.0f, 0.0f, value);
 #endif
 
-   mask_resource_fill(ctx->draw_buffer->alpha_mask_view->texture,
-                      x, y, width, height, value);
+   mask_resource_fill(view->texture, x, y, width, height, value);
 }
 
 VGint mask_bind_samplers(struct pipe_sampler_state **samplers,
@@ -523,10 +519,8 @@ VGint mask_bind_samplers(struct pipe_sampler_state **samplers,
    struct vg_context *ctx = vg_current_context();
 
    if (ctx->state.vg.masking) {
-      struct st_framebuffer *fb_buffers = ctx->draw_buffer;
-
       samplers[1] = &ctx->mask.sampler;
-      sampler_views[1] = fb_buffers->alpha_mask_view;
+      sampler_views[1] = vg_get_surface_mask(ctx);
       return 1;
    } else
       return 0;
diff --git a/src/gallium/state_trackers/vega/vg_context.c b/src/gallium/state_trackers/vega/vg_context.c
index b7d59a5..beb5f06 100644
--- a/src/gallium/state_trackers/vega/vg_context.c
+++ b/src/gallium/state_trackers/vega/vg_context.c
@@ -276,11 +276,11 @@ create_tex_and_view(struct pipe_context *pipe, enum pipe_format format,
 }
 
 static void
-vg_context_update_alpha_mask_view(struct vg_context *ctx,
-                                  uint width, uint height)
+vg_context_update_surface_mask_view(struct vg_context *ctx,
+                                    uint width, uint height)
 {
    struct st_framebuffer *stfb = ctx->draw_buffer;
-   struct pipe_sampler_view *old_sampler_view = stfb->alpha_mask_view;
+   struct pipe_sampler_view *old_sampler_view = stfb->surface_mask_view;
    struct pipe_context *pipe = ctx->pipe;
 
    if (old_sampler_view &&
@@ -293,10 +293,10 @@ vg_context_update_alpha_mask_view(struct vg_context *ctx,
      this texture and use it as a sampler, so while this wastes some
      space it makes both of those a lot simpler
    */
-   stfb->alpha_mask_view = create_tex_and_view(pipe,
+   stfb->surface_mask_view = create_tex_and_view(pipe,
          PIPE_FORMAT_B8G8R8A8_UNORM, width, height);
 
-   if (!stfb->alpha_mask_view) {
+   if (!stfb->surface_mask_view) {
       if (old_sampler_view)
          pipe_sampler_view_reference(&old_sampler_view, NULL);
       return;
@@ -316,16 +316,16 @@ vg_context_update_alpha_mask_view(struct vg_context *ctx,
       subold_surf.face = 0;
       subold_surf.level = 0;
       pipe->resource_copy_region(pipe,
-                                 stfb->alpha_mask_view->texture,
+                                 stfb->surface_mask_view->texture,
                                  subsurf,
                                  0, 0, 0,
                                  old_sampler_view->texture,
                                  subold_surf,
                                  0, 0, 0,
                                  MIN2(old_sampler_view->texture->width0,
-                                      stfb->alpha_mask_view->texture->width0),
+                                      stfb->surface_mask_view->texture->width0),
                                  MIN2(old_sampler_view->texture->height0,
-                                      stfb->alpha_mask_view->texture->height0));
+                                      stfb->surface_mask_view->texture->height0));
    }
 
    /* Free the old texture
@@ -404,9 +404,6 @@ void vg_validate_state(struct vg_context *ctx)
    if (vg_context_update_depth_stencil_rb(ctx, stfb->width, stfb->height))
       ctx->state.dirty |= DEPTH_STENCIL_DIRTY;
 
-   /* TODO create as needed */
-   vg_context_update_alpha_mask_view(ctx, stfb->width, stfb->height);
-
    renderer_validate(ctx->renderer, ctx->state.dirty,
          ctx->draw_buffer, &ctx->state.vg);
 
@@ -484,11 +481,21 @@ struct pipe_sampler_view *vg_prepare_blend_surface_from_mask(struct vg_context *
 
    vg_validate_state(ctx);
 
-   vg_prepare_blend_texture(ctx, stfb->alpha_mask_view);
+   vg_context_update_surface_mask_view(ctx, stfb->width, stfb->height);
+   vg_prepare_blend_texture(ctx, stfb->surface_mask_view);
 
    return stfb->blend_texture_view;
 }
 
+struct pipe_sampler_view *vg_get_surface_mask(struct vg_context *ctx)
+{
+   struct st_framebuffer *stfb = ctx->draw_buffer;
+
+   vg_context_update_surface_mask_view(ctx, stfb->width, stfb->height);
+
+   return stfb->surface_mask_view;
+}
+
 /**
  * A transformation from window coordinates to paint coordinates.
  */
diff --git a/src/gallium/state_trackers/vega/vg_context.h b/src/gallium/state_trackers/vega/vg_context.h
index 32996f4..7e92115 100644
--- a/src/gallium/state_trackers/vega/vg_context.h
+++ b/src/gallium/state_trackers/vega/vg_context.h
@@ -56,7 +56,7 @@ struct st_framebuffer {
    struct st_renderbuffer *strb;
    struct st_renderbuffer *dsrb;
 
-   struct pipe_sampler_view *alpha_mask_view;
+   struct pipe_sampler_view *surface_mask_view;
 
    struct pipe_sampler_view *blend_texture_view;
 
@@ -162,6 +162,8 @@ void vg_set_error(struct vg_context *ctx,
 struct pipe_sampler_view *vg_prepare_blend_surface(struct vg_context *ctx);
 struct pipe_sampler_view *vg_prepare_blend_surface_from_mask(struct vg_context *ctx);
 
+struct pipe_sampler_view *vg_get_surface_mask(struct vg_context *ctx);
+
 VGboolean vg_get_paint_matrix(struct vg_context *ctx,
                               const struct matrix *paint_to_user,
                               const struct matrix *user_to_surface,




More information about the mesa-commit mailing list