st/vega: Delay blend texture creation until needed.
authorChia-I Wu <olv@lunarg.com>
Wed, 1 Dec 2010 09:38:57 +0000 (17:38 +0800)
committerChia-I Wu <olv@lunarg.com>
Wed, 1 Dec 2010 09:46:34 +0000 (17:46 +0800)
It is used for more advanced blending or mask update.  It might not be
ever needed for some applications.

src/gallium/state_trackers/vega/mask.c
src/gallium/state_trackers/vega/shader.c
src/gallium/state_trackers/vega/vg_context.c
src/gallium/state_trackers/vega/vg_context.h

index e3aec98..0a800b2 100644 (file)
@@ -316,9 +316,8 @@ static void mask_using_texture(struct pipe_sampler_view *sampler_view,
    views[0] = sampler_view;
 
    /* prepare our blend surface */
-   vg_prepare_blend_surface_from_mask(ctx);
    samplers[1] = &ctx->mask.sampler;
-   views[1] = ctx->draw_buffer->blend_texture_view;
+   views[1] = vg_prepare_blend_surface_from_mask(ctx);
 
    fs = setup_mask_operation(operation);
 
index 483ff15..3d397f9 100644 (file)
@@ -137,12 +137,8 @@ static VGint blend_bind_samplers(struct vg_context *ctx,
        bmode == VG_BLEND_SCREEN ||
        bmode == VG_BLEND_DARKEN ||
        bmode == VG_BLEND_LIGHTEN) {
-      struct st_framebuffer *stfb = ctx->draw_buffer;
-
-      vg_prepare_blend_surface(ctx);
-
       samplers[2] = &ctx->blend_sampler;
-      sampler_views[2] = stfb->blend_texture_view;
+      sampler_views[2] = vg_prepare_blend_surface(ctx);
 
       if (!samplers[0] || !sampler_views[0]) {
          samplers[0] = samplers[2];
index 6ca80e7..b7d59a5 100644 (file)
@@ -406,7 +406,6 @@ void vg_validate_state(struct vg_context *ctx)
 
    /* TODO create as needed */
    vg_context_update_alpha_mask_view(ctx, stfb->width, stfb->height);
-   vg_context_update_blend_texture_view(ctx, stfb->width, stfb->height);
 
    renderer_validate(ctx->renderer, ctx->state.dirty,
          ctx->draw_buffer, &ctx->state.vg);
@@ -438,75 +437,56 @@ void vg_set_error(struct vg_context *ctx,
       ctx->_error = code;
 }
 
-void vg_prepare_blend_surface(struct vg_context *ctx)
+static void vg_prepare_blend_texture(struct vg_context *ctx,
+                                     struct pipe_sampler_view *src)
+{
+   struct st_framebuffer *stfb = ctx->draw_buffer;
+   struct pipe_surface *surf;
+
+   vg_context_update_blend_texture_view(ctx, stfb->width, stfb->height);
+
+   surf = ctx->pipe->screen->get_tex_surface(ctx->pipe->screen,
+         stfb->blend_texture_view->texture, 0, 0, 0, PIPE_BIND_RENDER_TARGET);
+   if (surf) {
+      util_blit_pixels_tex(ctx->blit,
+                           src, 0, 0, stfb->width, stfb->height,
+                           surf, 0, 0, stfb->width, stfb->height,
+                           0.0, PIPE_TEX_MIPFILTER_NEAREST);
+
+      pipe_surface_reference(&surf, NULL);
+   }
+}
+
+struct pipe_sampler_view *vg_prepare_blend_surface(struct vg_context *ctx)
 {
-   struct pipe_surface *dest_surface = NULL;
    struct pipe_context *pipe = ctx->pipe;
    struct pipe_sampler_view *view;
    struct pipe_sampler_view view_templ;
    struct st_framebuffer *stfb = ctx->draw_buffer;
    struct st_renderbuffer *strb = stfb->strb;
 
-   /* first finish all pending rendering */
-   vgFinish();
+   vg_validate_state(ctx);
 
    u_sampler_view_default_template(&view_templ, strb->texture, strb->texture->format);
    view = pipe->create_sampler_view(pipe, strb->texture, &view_templ);
 
-   dest_surface = pipe->screen->get_tex_surface(pipe->screen,
-                                                stfb->blend_texture_view->texture,
-                                                0, 0, 0,
-                                                PIPE_BIND_RENDER_TARGET);
-   util_blit_pixels_tex(ctx->blit,
-                        view,
-                        0, 0,
-                        strb->width, strb->height,
-                        dest_surface,
-                        0, 0,
-                        strb->width, strb->height,
-                        0.0, PIPE_TEX_MIPFILTER_NEAREST);
-
-   if (dest_surface)
-      pipe_surface_reference(&dest_surface, NULL);
-
-   /* make sure it's complete */
-   vgFinish();
+   vg_prepare_blend_texture(ctx, view);
 
    pipe_sampler_view_reference(&view, NULL);
+
+   return stfb->blend_texture_view;
 }
 
 
-void vg_prepare_blend_surface_from_mask(struct vg_context *ctx)
+struct pipe_sampler_view *vg_prepare_blend_surface_from_mask(struct vg_context *ctx)
 {
-   struct pipe_surface *dest_surface = NULL;
-   struct pipe_context *pipe = ctx->pipe;
    struct st_framebuffer *stfb = ctx->draw_buffer;
-   struct st_renderbuffer *strb = stfb->strb;
 
    vg_validate_state(ctx);
 
-   /* first finish all pending rendering */
-   vgFinish();
-
-   dest_surface = pipe->screen->get_tex_surface(pipe->screen,
-                                                stfb->blend_texture_view->texture,
-                                                0, 0, 0,
-                                                PIPE_BIND_RENDER_TARGET);
-
-   util_blit_pixels_tex(ctx->blit,
-                        stfb->alpha_mask_view,
-                        0, 0,
-                        strb->width, strb->height,
-                        dest_surface,
-                        0, 0,
-                        strb->width, strb->height,
-                        0.0, PIPE_TEX_MIPFILTER_NEAREST);
-
-   /* make sure it's complete */
-   vgFinish();
+   vg_prepare_blend_texture(ctx, stfb->alpha_mask_view);
 
-   if (dest_surface)
-      pipe_surface_reference(&dest_surface, NULL);
+   return stfb->blend_texture_view;
 }
 
 /**
index 5d0bca3..32996f4 100644 (file)
@@ -159,8 +159,8 @@ void vg_validate_state(struct vg_context *ctx);
 void vg_set_error(struct vg_context *ctx,
                   VGErrorCode code);
 
-void vg_prepare_blend_surface(struct vg_context *ctx);
-void vg_prepare_blend_surface_from_mask(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);
 
 VGboolean vg_get_paint_matrix(struct vg_context *ctx,
                               const struct matrix *paint_to_user,