util: Add util_copy_box helper.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 5 Dec 2012 20:15:40 +0000 (20:15 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 6 Dec 2012 17:12:31 +0000 (17:12 +0000)
Must users of util_copy_rect() need or should deal with volumes.

Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/auxiliary/util/u_surface.c
src/gallium/auxiliary/util/u_surface.h
src/gallium/auxiliary/util/u_transfer.c

index b17dd74fd375d9b8af4d637678662f990138d469..2c197c3df6ae8d5a36a3ab6d9deaaab4e31b566a 100644 (file)
@@ -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);
index db3fd8b11fee2c43a0e9c945a477bcc942f61927..dd4d5785e4015f8b0e9118be23a577a58fcc1457 100644 (file)
@@ -57,6 +57,16 @@ util_copy_rect(ubyte * dst, enum pipe_format format,
                unsigned width, unsigned height, const ubyte * src,
                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,
index 8b4c3659253681917c5a0fb6d9685993d514158e..86168255325c8dc5dbd8773aa176717b1871909b 100644 (file)
@@ -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);