Mesa (master): i915simple: Minimal fixup for introduction of struct pipe_transfer.

Michel Dänzer daenzer at kemper.freedesktop.org
Wed Feb 18 15:51:10 UTC 2009


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

Author: Michel Dänzer <daenzer at vmware.com>
Date:   Wed Feb 18 13:14:02 2009 +0100

i915simple: Minimal fixup for introduction of struct pipe_transfer.

---

 src/gallium/drivers/i915simple/i915_screen.c     |   90 +++++++++++++++++++---
 src/gallium/drivers/i915simple/i915_screen.h     |   19 +++++-
 src/gallium/drivers/i915simple/i915_state_emit.c |    6 +-
 src/gallium/drivers/i915simple/i915_surface.c    |   79 ++++++-------------
 src/gallium/drivers/i915simple/i915_texture.c    |    4 -
 5 files changed, 122 insertions(+), 76 deletions(-)

diff --git a/src/gallium/drivers/i915simple/i915_screen.c b/src/gallium/drivers/i915simple/i915_screen.c
index 39e4810..b7bd3b3 100644
--- a/src/gallium/drivers/i915simple/i915_screen.c
+++ b/src/gallium/drivers/i915simple/i915_screen.c
@@ -204,17 +204,79 @@ i915_destroy_screen( struct pipe_screen *screen )
 }
 
 
+static struct pipe_transfer*
+i915_get_tex_transfer(struct pipe_screen *screen,
+                      struct pipe_texture *texture,
+                      unsigned face, unsigned level, unsigned zslice,
+                      enum pipe_transfer_usage usage, unsigned x, unsigned y,
+                      unsigned w, unsigned h)
+{
+   struct i915_texture *tex = (struct i915_texture *)texture;
+   struct i915_transfer *trans;
+   unsigned offset;  /* in bytes */
+
+   if (texture->target == PIPE_TEXTURE_CUBE) {
+      offset = tex->image_offset[level][face];
+   }
+   else if (texture->target == PIPE_TEXTURE_3D) {
+      offset = tex->image_offset[level][zslice];
+   }
+   else {
+      offset = tex->image_offset[level][0];
+      assert(face == 0);
+      assert(zslice == 0);
+   }
+
+   trans = CALLOC_STRUCT(i915_transfer);
+   if (trans) {
+      trans->base.refcount = 1;
+      pipe_texture_reference(&trans->base.texture, texture);
+      trans->base.format = trans->base.format;
+      trans->base.width = w;
+      trans->base.height = h;
+      trans->base.block = texture->block;
+      trans->base.nblocksx = texture->nblocksx[level];
+      trans->base.nblocksy = texture->nblocksy[level];
+      trans->base.stride = tex->stride;
+      trans->offset = offset;
+      trans->base.usage = usage;
+   }
+   return &trans->base;
+}
+
+static void
+i915_tex_transfer_release(struct pipe_screen *screen,
+                          struct pipe_transfer **transfer)
+{
+   struct pipe_transfer *trans = *transfer;
+
+   if (--trans->refcount == 0) {
+      pipe_texture_reference(&trans->texture, NULL);
+      FREE(trans);
+   }
+
+   *transfer = NULL;
+}
+
 static void *
-i915_surface_map( struct pipe_screen *screen,
-                  struct pipe_surface *surface,
-                  unsigned flags )
+i915_transfer_map( struct pipe_screen *screen,
+                   struct pipe_transfer *transfer )
 {
-   struct i915_texture *tex = (struct i915_texture *)surface->texture;
-   char *map = pipe_buffer_map( screen, tex->buffer, flags );
+   struct i915_texture *tex = (struct i915_texture *)transfer->texture;
+   char *map;
+   unsigned flags = 0;
+
+   if (transfer->usage != PIPE_TRANSFER_WRITE)
+      flags |= PIPE_BUFFER_USAGE_CPU_READ;
+
+   if (transfer->usage != PIPE_TRANSFER_READ)
+      flags |= PIPE_BUFFER_USAGE_CPU_WRITE;
+
+   map = pipe_buffer_map( screen, tex->buffer, flags );
    if (map == NULL)
       return NULL;
 
-   if (surface->texture &&
+   if (transfer->texture &&
        (flags & PIPE_BUFFER_USAGE_CPU_WRITE)) 
    {
       /* Do something to notify contexts of a texture change.  
@@ -222,14 +284,16 @@ i915_surface_map( struct pipe_screen *screen,
       /* i915_screen(screen)->timestamp++; */
    }
    
-   return map + surface->offset;
+   return map + i915_transfer(transfer)->offset +
+      transfer->y / transfer->block.height * transfer->stride +
+      transfer->x / transfer->block.width * transfer->block.size;
 }
 
 static void
-i915_surface_unmap(struct pipe_screen *screen,
-                   struct pipe_surface *surface)
+i915_transfer_unmap(struct pipe_screen *screen,
+                    struct pipe_transfer *transfer)
 {
-   struct i915_texture *tex = (struct i915_texture *)surface->texture;
+   struct i915_texture *tex = (struct i915_texture *)transfer->texture;
    pipe_buffer_unmap( screen, tex->buffer );
 }
 
@@ -278,8 +342,10 @@ i915_create_screen(struct pipe_winsys *winsys, uint pci_id)
    i915screen->screen.get_param = i915_get_param;
    i915screen->screen.get_paramf = i915_get_paramf;
    i915screen->screen.is_format_supported = i915_is_format_supported;
-   i915screen->screen.surface_map = i915_surface_map;
-   i915screen->screen.surface_unmap = i915_surface_unmap;
+   i915screen->screen.get_tex_transfer = i915_get_tex_transfer;
+   i915screen->screen.tex_transfer_release = i915_tex_transfer_release;
+   i915screen->screen.transfer_map = i915_transfer_map;
+   i915screen->screen.transfer_unmap = i915_transfer_unmap;
 
    i915_init_screen_texture_functions(&i915screen->screen);
    u_simple_screen_init(&i915screen->screen);
diff --git a/src/gallium/drivers/i915simple/i915_screen.h b/src/gallium/drivers/i915simple/i915_screen.h
index 73b0ff0..a371663 100644
--- a/src/gallium/drivers/i915simple/i915_screen.h
+++ b/src/gallium/drivers/i915simple/i915_screen.h
@@ -50,13 +50,30 @@ struct i915_screen
 };
 
 
-/** cast wrapper */
+/**
+ * Subclass of pipe_transfer
+ */
+struct i915_transfer
+{
+   struct pipe_transfer base;
+
+   unsigned offset;
+};
+
+
+/** cast wrappers */
 static INLINE struct i915_screen *
 i915_screen(struct pipe_screen *pscreen)
 {
    return (struct i915_screen *) pscreen;
 }
 
+static INLINE struct i915_transfer *
+i915_transfer( struct pipe_transfer *transfer )
+{
+   return (struct i915_transfer *)transfer;
+}
+
 
 extern struct pipe_screen *
 i915_create_screen(struct pipe_winsys *winsys, uint pci_id);
diff --git a/src/gallium/drivers/i915simple/i915_state_emit.c b/src/gallium/drivers/i915simple/i915_state_emit.c
index 6558cf1..26e03f5 100644
--- a/src/gallium/drivers/i915simple/i915_state_emit.c
+++ b/src/gallium/drivers/i915simple/i915_state_emit.c
@@ -211,7 +211,6 @@ i915_emit_hardware_state(struct i915_context *i915 )
       struct pipe_surface *depth_surface = i915->framebuffer.zsbuf;
 
       if (cbuf_surface) {
-	 unsigned cpitch = cbuf_surface->stride;
 	 unsigned ctile = BUF_3D_USE_FENCE;
          struct i915_texture *tex = (struct i915_texture *)
                                     cbuf_surface->texture;
@@ -225,7 +224,7 @@ i915_emit_hardware_state(struct i915_context *i915 )
 	 OUT_BATCH(_3DSTATE_BUF_INFO_CMD);
 
 	 OUT_BATCH(BUF_3D_ID_COLOR_BACK |
-		   BUF_3D_PITCH(cpitch) |  /* pitch in bytes */
+		   BUF_3D_PITCH(tex->stride) |  /* pitch in bytes */
 		   ctile);
 
 	 OUT_RELOC(tex->buffer,
@@ -236,7 +235,6 @@ i915_emit_hardware_state(struct i915_context *i915 )
       /* What happens if no zbuf??
        */
       if (depth_surface) {
-	 unsigned zpitch = depth_surface->stride;
 	 unsigned ztile = BUF_3D_USE_FENCE;
          struct i915_texture *tex = (struct i915_texture *)
                                     depth_surface->texture;
@@ -250,7 +248,7 @@ i915_emit_hardware_state(struct i915_context *i915 )
 	 OUT_BATCH(_3DSTATE_BUF_INFO_CMD);
 
 	 OUT_BATCH(BUF_3D_ID_DEPTH |
-		   BUF_3D_PITCH(zpitch) |  /* pitch in bytes */
+		   BUF_3D_PITCH(tex->stride) |  /* pitch in bytes */
 		   ztile);
 
 	 OUT_RELOC(tex->buffer,
diff --git a/src/gallium/drivers/i915simple/i915_surface.c b/src/gallium/drivers/i915simple/i915_surface.c
index 94e2dea..7eec649 100644
--- a/src/gallium/drivers/i915simple/i915_surface.c
+++ b/src/gallium/drivers/i915simple/i915_surface.c
@@ -47,44 +47,22 @@ i915_surface_copy(struct pipe_context *pipe,
 		  struct pipe_surface *src,
 		  unsigned srcx, unsigned srcy, unsigned width, unsigned height)
 {
-   assert( dst != src );
-   assert( dst->block.size == src->block.size );
-   assert( dst->block.width == src->block.height );
-   assert( dst->block.height == src->block.height );
+   struct i915_texture *dst_tex = (struct i915_texture *)dst->texture;
+   struct i915_texture *src_tex = (struct i915_texture *)src->texture;
 
-   if (0) {
-      void *dst_map = pipe->screen->surface_map( pipe->screen,
-                                                 dst,
-                                                 PIPE_BUFFER_USAGE_CPU_WRITE );
-      
-      const void *src_map = pipe->screen->surface_map( pipe->screen,
-                                                       src,
-                                                       PIPE_BUFFER_USAGE_CPU_READ );
-      
-      pipe_copy_rect(dst_map,
-                     &dst->block,
-                     dst->stride,
-                     dstx, dsty,
-                     width, height,
-                     src_map,
-                     do_flip ? -(int) src->stride : src->stride,
-                     srcx, do_flip ? height - 1 - srcy : srcy);
+   assert( dst != src );
+   assert( dst_tex->base.block.size == src_tex->base.block.size );
+   assert( dst_tex->base.block.width == src_tex->base.block.height );
+   assert( dst_tex->base.block.height == src_tex->base.block.height );
+   assert( dst_tex->base.block.width == 1 );
+   assert( dst_tex->base.block.height == 1 );
 
-      pipe->screen->surface_unmap(pipe->screen, src);
-      pipe->screen->surface_unmap(pipe->screen, dst);
-   }
-   else {
-      struct i915_texture *dst_tex = (struct i915_texture *)dst->texture;
-      struct i915_texture *src_tex = (struct i915_texture *)src->texture;
-      assert(dst->block.width == 1);
-      assert(dst->block.height == 1);
-      i915_copy_blit( i915_context(pipe),
-                      do_flip,
-                      dst->block.size,
-		      (unsigned short) src->stride, src_tex->buffer, src->offset,
-		      (unsigned short) dst->stride, dst_tex->buffer, dst->offset,
-		      (short) srcx, (short) srcy, (short) dstx, (short) dsty, (short) width, (short) height );
-   }
+   i915_copy_blit( i915_context(pipe),
+                   do_flip,
+                   dst_tex->base.block.size,
+                   (unsigned short) src_tex->stride, src_tex->buffer, src->offset,
+                   (unsigned short) dst_tex->stride, dst_tex->buffer, dst->offset,
+                   (short) srcx, (short) srcy, (short) dstx, (short) dsty, (short) width, (short) height );
 }
 
 
@@ -94,27 +72,18 @@ i915_surface_fill(struct pipe_context *pipe,
 		  unsigned dstx, unsigned dsty,
 		  unsigned width, unsigned height, unsigned value)
 {
-   if (0) {
-      void *dst_map = pipe->screen->surface_map( pipe->screen,
-                                                 dst,
-                                                 PIPE_BUFFER_USAGE_CPU_WRITE );
+   struct i915_texture *tex = (struct i915_texture *)dst->texture;
 
-      pipe_fill_rect(dst_map, &dst->block, dst->stride, dstx, dsty, width, height, value);
+   assert(tex->base.block.width == 1);
+   assert(tex->base.block.height == 1);
 
-      pipe->screen->surface_unmap(pipe->screen, dst);
-   }
-   else {
-      struct i915_texture *tex = (struct i915_texture *)dst->texture;
-      assert(dst->block.width == 1);
-      assert(dst->block.height == 1);
-      i915_fill_blit( i915_context(pipe),
-		      dst->block.size,
-		      (unsigned short) dst->stride,
-		      tex->buffer, dst->offset,
-		      (short) dstx, (short) dsty,
-		      (short) width, (short) height,
-		      value );
-   }
+   i915_fill_blit( i915_context(pipe),
+                   tex->base.block.size,
+                   (unsigned short) tex->stride,
+                   tex->buffer, dst->offset,
+                   (short) dstx, (short) dsty,
+                   (short) width, (short) height,
+                   value );
 }
 
 
diff --git a/src/gallium/drivers/i915simple/i915_texture.c b/src/gallium/drivers/i915simple/i915_texture.c
index b2ca3a2..9577265 100644
--- a/src/gallium/drivers/i915simple/i915_texture.c
+++ b/src/gallium/drivers/i915simple/i915_texture.c
@@ -686,10 +686,6 @@ i915_get_tex_surface(struct pipe_screen *screen,
       ps->format = pt->format;
       ps->width = pt->width[level];
       ps->height = pt->height[level];
-      ps->block = pt->block;
-      ps->nblocksx = pt->nblocksx[level];
-      ps->nblocksy = pt->nblocksy[level];
-      ps->stride = tex->stride;
       ps->offset = offset;
       ps->usage = flags;
       ps->status = PIPE_SURFACE_STATUS_DEFINED;




More information about the mesa-commit mailing list