[Mesa-dev] [PATCH 4/4] util: Add util_copy_box helper.

jfonseca at vmware.com jfonseca at vmware.com
Thu Dec 6 05:17:09 PST 2012


From: José Fonseca <jfonseca at vmware.com>

Must users of util_copy_rect() need or should deal with volumes.
---
 src/gallium/auxiliary/util/u_surface.c  |   55 +++++++++++++++++++++++--------
 src/gallium/auxiliary/util/u_surface.h  |   10 ++++++
 src/gallium/auxiliary/util/u_transfer.c |   28 ++++++++--------
 3 files changed, 64 insertions(+), 29 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c
index b17dd74..2c197c3 100644
--- a/src/gallium/auxiliary/util/u_surface.c
+++ b/src/gallium/auxiliary/util/u_surface.c
@@ -168,6 +168,39 @@ util_copy_rect(ubyte * dst,
 }
 
 
+/**
+ * Copy 3D box from one place to another.
+ * Position and sizes are in pixels.
+ */
+void
+util_copy_box(ubyte * dst,
+              enum pipe_format format,
+              unsigned dst_stride, unsigned dst_slice_stride,
+              unsigned dst_x, unsigned dst_y, unsigned dst_z,
+              unsigned width, unsigned height, unsigned depth,
+              const ubyte * src,
+              int src_stride, unsigned src_slice_stride,
+              unsigned src_x, unsigned src_y, unsigned src_z)
+{
+   unsigned z;
+   dst += dst_z * dst_slice_stride;
+   src += src_z * src_slice_stride;
+   for (z = 0; z < depth; ++z) {
+      util_copy_rect(dst,
+                     format,
+                     dst_stride,
+                     dst_x, dst_y,
+                     width, height,
+                     src,
+                     src_stride,
+                     src_x, src_y);
+
+      dst += dst_slice_stride;
+      src += src_slice_stride;
+   }
+}
+
+
 void
 util_fill_rect(ubyte * dst,
                enum pipe_format format,
@@ -257,7 +290,6 @@ util_resource_copy_region(struct pipe_context *pipe,
    const uint8_t *src_map;
    enum pipe_format src_format, dst_format;
    struct pipe_box dst_box;
-   int z;
 
    assert(src && dst);
    if (!src || !dst)
@@ -305,19 +337,14 @@ util_resource_copy_region(struct pipe_context *pipe,
       assert(src_box->depth == 1);
       memcpy(dst_map, src_map, src_box->width);
    } else {
-      for (z = 0; z < src_box->depth; ++z) {
-         util_copy_rect(dst_map,
-                        dst_format,
-                        dst_trans->stride,
-                        0, 0,
-                        src_box->width, src_box->height,
-                        src_map,
-                        src_trans->stride,
-                        0, 0);
-
-         dst_map += dst_trans->layer_stride;
-         src_map += src_trans->layer_stride;
-      }
+      util_copy_box(dst_map,
+                    dst_format,
+                    dst_trans->stride, dst_trans->layer_stride,
+                    0, 0, 0,
+                    src_box->width, src_box->height, src_box->depth,
+                    src_map,
+                    src_trans->stride, src_trans->layer_stride,
+                    0, 0, 0);
    }
 
    pipe->transfer_unmap(pipe, dst_trans);
diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h
index db3fd8b..dd4d578 100644
--- a/src/gallium/auxiliary/util/u_surface.h
+++ b/src/gallium/auxiliary/util/u_surface.h
@@ -58,6 +58,16 @@ util_copy_rect(ubyte * dst, enum pipe_format format,
                int src_stride, unsigned src_x, unsigned src_y);
 
 extern void
+util_copy_box(ubyte * dst,
+              enum pipe_format format,
+              unsigned dst_stride, unsigned dst_slice_stride,
+              unsigned dst_x, unsigned dst_y, unsigned dst_z,
+              unsigned width, unsigned height, unsigned depth,
+              const ubyte * src,
+              int src_stride, unsigned src_slice_stride,
+              unsigned src_x, unsigned src_y, unsigned src_z);
+
+extern void
 util_fill_rect(ubyte * dst, enum pipe_format format,
                unsigned dst_stride, unsigned dst_x, unsigned dst_y,
                unsigned width, unsigned height, union util_color *uc);
diff --git a/src/gallium/auxiliary/util/u_transfer.c b/src/gallium/auxiliary/util/u_transfer.c
index 8b4c365..8616825 100644
--- a/src/gallium/auxiliary/util/u_transfer.c
+++ b/src/gallium/auxiliary/util/u_transfer.c
@@ -1,5 +1,5 @@
 #include "pipe/p_context.h"
-#include "util/u_rect.h"
+#include "util/u_surface.h"
 #include "util/u_inlines.h"
 #include "util/u_transfer.h"
 #include "util/u_memory.h"
@@ -47,21 +47,19 @@ void u_default_transfer_inline_write( struct pipe_context *pipe,
    }
    else {
       const uint8_t *src_data = data;
-      unsigned i;
 
-      for (i = 0; i < box->depth; i++) {
-         util_copy_rect(map,
-                        resource->format,
-                        transfer->stride, /* bytes */
-                        0, 0,
-                        box->width,
-                        box->height,
-                        src_data,
-                        stride,       /* bytes */
-                        0, 0);
-         map += transfer->layer_stride;
-         src_data += layer_stride;
-      }
+      util_copy_box(map,
+		    resource->format,
+		    transfer->stride, /* bytes */
+		    transfer->layer_stride, /* bytes */
+                    0, 0, 0,
+		    box->width,
+		    box->height,
+		    box->depth,
+		    src_data,
+		    stride,       /* bytes */
+		    layer_stride, /* bytes */
+		    0, 0, 0);
    }
 
    pipe_transfer_unmap(pipe, transfer);
-- 
1.7.9.5



More information about the mesa-dev mailing list