static void
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->surface_mask_view;
   struct pipe_context *pipe = ctx->pipe;

   if (old_sampler_view &&
       old_sampler_view->texture->width0 == width &&
       old_sampler_view->texture->height0 == height)
      return;

   /*
     we use PIPE_FORMAT_B8G8R8A8_UNORM because we want to render to
     this texture and use it as a sampler, so while this wastes some
     space it makes both of those a lot simpler
   */
   stfb->surface_mask_view = create_tex_and_view(pipe,
         PIPE_FORMAT_B8G8R8A8_UNORM, width, height);

   if (!stfb->surface_mask_view) {
      if (old_sampler_view)
         pipe_sampler_view_reference(&old_sampler_view, NULL);
      return;
   }

   /* XXX could this call be avoided? */
   vg_validate_state(ctx);

   /* alpha mask starts with 1.f alpha */
   mask_fill(0, 0, width, height, 1.f);

   /* if we had an old surface copy it over */
   if (old_sampler_view) {
      struct pipe_box src_box;
      u_box_origin_2d(MIN2(old_sampler_view->texture->width0,
                           stfb->surface_mask_view->texture->width0),
                      MIN2(old_sampler_view->texture->height0,
                           stfb->surface_mask_view->texture->height0),
                      &src_box);

      pipe->resource_copy_region(pipe,
                                 stfb->surface_mask_view->texture,
                                 0, 0, 0, 0,
                                 old_sampler_view->texture,
                                 0, &src_box);
   }

   /* Free the old texture
    */
   if (old_sampler_view)
      pipe_sampler_view_reference(&old_sampler_view, NULL);
}
コード例 #2
0
static void
setup_new_alpha_mask(struct vg_context *ctx, struct st_framebuffer *stfb)
{
   struct pipe_context *pipe = ctx->pipe;
   struct pipe_sampler_view *old_sampler_view = stfb->alpha_mask_view;

   /*
     we use PIPE_FORMAT_B8G8R8A8_UNORM because we want to render to
     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,
         PIPE_FORMAT_B8G8R8A8_UNORM, stfb->width, stfb->height);

   if (!stfb->alpha_mask_view) {
      if (old_sampler_view)
         pipe_sampler_view_reference(&old_sampler_view, NULL);
      return;
   }

   /* XXX could this call be avoided? */
   vg_validate_state(ctx);

   /* alpha mask starts with 1.f alpha */
   mask_fill(0, 0, stfb->width, stfb->height, 1.f);

   /* if we had an old surface copy it over */
   if (old_sampler_view) {
      struct pipe_subresource subsurf, subold_surf;
      subsurf.face = 0;
      subsurf.level = 0;
      subold_surf.face = 0;
      subold_surf.level = 0;
      pipe->resource_copy_region(pipe,
                                 stfb->alpha_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),
                                 MIN2(old_sampler_view->texture->height0,
                                      stfb->alpha_mask_view->texture->height0));
   }

   /* Free the old texture
    */
   if (old_sampler_view)
      pipe_sampler_view_reference(&old_sampler_view, NULL);
}
static void
vg_context_update_blend_texture_view(struct vg_context *ctx,
                                     uint width, uint height)
{
   struct pipe_context *pipe = ctx->pipe;
   struct st_framebuffer *stfb = ctx->draw_buffer;
   struct pipe_sampler_view *old = stfb->blend_texture_view;

   if (old &&
       old->texture->width0 == width &&
       old->texture->height0 == height)
      return;

   stfb->blend_texture_view = create_tex_and_view(pipe,
         PIPE_FORMAT_B8G8R8A8_UNORM, width, height);

   pipe_sampler_view_reference(&old, NULL);
}
コード例 #4
0
static void
vg_context_update_draw_buffer(struct vg_context *ctx, struct pipe_resource *pt)
{
   struct st_framebuffer *stfb = ctx->draw_buffer;
   boolean new_cbuf, new_zsbuf, new_size;

   new_cbuf = vg_context_update_color_rb(ctx, pt);
   new_zsbuf =
      vg_context_update_depth_stencil_rb(ctx, pt->width0, pt->height0);

   new_size = (stfb->width != pt->width0 || stfb->height != pt->height0);
   stfb->width = pt->width0;
   stfb->height = pt->height0;

   if (new_cbuf || new_zsbuf || new_size) {
      struct pipe_framebuffer_state *state = &ctx->state.g3d.fb;

      memset(state, 0, sizeof(struct pipe_framebuffer_state));
      state->width  = stfb->width;
      state->height = stfb->height;
      state->nr_cbufs = 1;
      state->cbufs[0] = stfb->strb->surface;
      state->zsbuf = stfb->dsrb->surface;

      cso_set_framebuffer(ctx->cso_context, state);
   }

   if (new_zsbuf || new_size) {
      ctx->state.dirty |= VIEWPORT_DIRTY;
      ctx->state.dirty |= DEPTH_STENCIL_DIRTY;/*to reset the scissors*/

      ctx->pipe->clear(ctx->pipe, PIPE_CLEAR_DEPTHSTENCIL, NULL, 0.0, 0);

      /* we need all the other state already set */

      setup_new_alpha_mask(ctx, stfb);

      pipe_sampler_view_reference( &stfb->blend_texture_view, NULL);
      stfb->blend_texture_view = create_tex_and_view(ctx->pipe,
            PIPE_FORMAT_B8G8R8A8_UNORM, stfb->width, stfb->height);
   }
}