Unify copy_rect helpers.
authorMichel Dänzer <michel@tungstengraphics.com>
Fri, 18 Jan 2008 18:08:30 +0000 (19:08 +0100)
committerMichel Dänzer <michel@tungstengraphics.com>
Fri, 18 Jan 2008 18:11:30 +0000 (19:11 +0100)
Some of the copies were buggy.

src/mesa/pipe/i915simple/i915_surface.c
src/mesa/pipe/i965simple/brw_surface.c
src/mesa/pipe/p_util.h
src/mesa/pipe/softpipe/sp_surface.c
src/mesa/pipe/util/p_util.c [new file with mode: 0644]
src/mesa/sources

index 72a65e0fb4b0a83ef64ac34afc94efc33760a6b7..e625f5a68c84e34efc9773acdaab7fa7b8ddc644 100644 (file)
@@ -77,41 +77,6 @@ i915_get_tex_surface(struct pipe_context *pipe,
 }
 
 
-static void
-copy_rect(ubyte * dst,
-          unsigned cpp,
-          unsigned dst_pitch,
-          unsigned dst_x,
-          unsigned dst_y,
-          unsigned width,
-          unsigned height,
-          const ubyte *src,
-          unsigned src_pitch,
-          unsigned src_x, 
-          unsigned src_y)
-{
-   unsigned i;
-
-   dst_pitch *= cpp;
-   src_pitch *= cpp;
-   dst += dst_x * cpp;
-   src += src_x * cpp;
-   dst += dst_y * dst_pitch;
-   src += src_y * dst_pitch;
-   width *= cpp;
-
-   if (width == dst_pitch && width == src_pitch)
-      memcpy(dst, src, height * width);
-   else {
-      for (i = 0; i < height; i++) {
-         memcpy(dst, src, width);
-         dst += dst_pitch;
-         src += src_pitch;
-      }
-   }
-}
-
-
 /* Upload data to a rectangular sub-region.  Lots of choices how to do this:
  *
  * - memcpy by span to current destination
@@ -126,9 +91,9 @@ i915_surface_data(struct pipe_context *pipe,
                  const void *src, unsigned src_pitch,
                  unsigned srcx, unsigned srcy, unsigned width, unsigned height)
 {
-   copy_rect(pipe_surface_map(dst),
-             dst->cpp, dst->pitch,
-             dstx, dsty, width, height, src, src_pitch, srcx, srcy);
+   pipe_copy_rect(pipe_surface_map(dst),
+                  dst->cpp, dst->pitch,
+                  dstx, dsty, width, height, src, src_pitch, srcx, srcy);
 
    pipe_surface_unmap(dst);
 }
@@ -148,14 +113,14 @@ i915_surface_copy(struct pipe_context *pipe,
    assert( dst->cpp == src->cpp );
 
    if (0) {
-      copy_rect(pipe_surface_map(dst),
-                     dst->cpp,
-                     dst->pitch,
-                     dstx, dsty, 
-                     width, height, 
-                     pipe_surface_map(src), 
-                     src->pitch, 
-                     srcx, srcy);
+      pipe_copy_rect(pipe_surface_map(dst),
+                     dst->cpp,
+                     dst->pitch,
+                     dstx, dsty, 
+                     width, height, 
+                     pipe_surface_map(src), 
+                     src->pitch, 
+                     srcx, srcy);
 
       pipe_surface_unmap(src);
       pipe_surface_unmap(dst);
index 4eacbdf82bf116f57784a3cbedee9a30f9e0c34b..76b8c73d5c2e02f876321735bfbf820a997381ae 100644 (file)
@@ -76,40 +76,6 @@ brw_get_tex_surface(struct pipe_context *pipe,
 }
 
 
-static void
-copy_rect(ubyte * dst,
-          unsigned cpp,
-          unsigned dst_pitch,
-          unsigned dst_x,
-          unsigned dst_y,
-          unsigned width,
-          unsigned height,
-          const ubyte *src,
-          unsigned src_pitch,
-          unsigned src_x,
-          unsigned src_y)
-{
-   unsigned i;
-
-   dst_pitch *= cpp;
-   src_pitch *= cpp;
-   dst += dst_x * cpp;
-   src += src_x * cpp;
-   dst += dst_y * dst_pitch;
-   src += src_y * dst_pitch;
-   width *= cpp;
-
-   if (width == dst_pitch && width == src_pitch)
-      memcpy(dst, src, height * width);
-   else {
-      for (i = 0; i < height; i++) {
-         memcpy(dst, src, width);
-         dst += dst_pitch;
-         src += src_pitch;
-      }
-   }
-}
-
 /* Upload data to a rectangular sub-region.  Lots of choices how to do this:
  *
  * - memcpy by span to current destination
@@ -124,9 +90,9 @@ brw_surface_data(struct pipe_context *pipe,
                  const void *src, unsigned src_pitch,
                  unsigned srcx, unsigned srcy, unsigned width, unsigned height)
 {
-   copy_rect(pipe_surface_map(dst) + dst->offset,
-             dst->cpp, dst->pitch,
-             dstx, dsty, width, height, src, src_pitch, srcx, srcy);
+   pipe_copy_rect(pipe_surface_map(dst) + dst->offset,
+                  dst->cpp, dst->pitch,
+                  dstx, dsty, width, height, src, src_pitch, srcx, srcy);
 
    pipe_surface_unmap(dst);
 }
@@ -146,14 +112,14 @@ brw_surface_copy(struct pipe_context *pipe,
    assert(dst->cpp == src->cpp);
 
    if (0) {
-      copy_rect(pipe_surface_map(dst) + dst->offset,
-                     dst->cpp,
-                     dst->pitch,
-                     dstx, dsty,
-                     width, height,
-                     pipe_surface_map(src) + src->offset,
-                     src->pitch,
-                     srcx, srcy);
+      pipe_copy_rect(pipe_surface_map(dst) + dst->offset,
+                     dst->cpp,
+                     dst->pitch,
+                     dstx, dsty,
+                     width, height,
+                     pipe_surface_map(src) + src->offset,
+                     src->pitch,
+                     srcx, srcy);
 
       pipe_surface_unmap(src);
       pipe_surface_unmap(dst);
index 573fef9b83af3bb43437734f8166614032b25627..a2bc330424d9d07a379eb99d7837695d7c6904a7 100644 (file)
@@ -383,4 +383,13 @@ static INLINE int align(int value, int alignment)
  */
 extern void _mesa_printf(const char *str, ...);
 
+
+/* util/p_util.c
+ */
+extern void pipe_copy_rect(ubyte * dst, unsigned cpp, unsigned dst_pitch,
+                           unsigned dst_x, unsigned dst_y, unsigned width,
+                           unsigned height, const ubyte * src,
+                           unsigned src_pitch, unsigned src_x, unsigned src_y);
+
+
 #endif
index a580fb3e8204616e5386c2156c894185ab2cc233..d5119654edb25a88514b054987c3fd1a0a2a2dae 100644 (file)
@@ -72,45 +72,6 @@ softpipe_get_tex_surface(struct pipe_context *pipe,
 }
 
 
-/**
- * Copy 2D rect from one place to another.
- * Position and sizes are in pixels.
- */
-static void
-copy_rect(ubyte * dst,
-          unsigned cpp,
-          unsigned dst_pitch,
-          unsigned dst_x,
-          unsigned dst_y,
-          unsigned width,
-          unsigned height,
-          const ubyte * src,
-          unsigned src_pitch,
-          unsigned src_x, 
-          unsigned src_y)
-{
-   unsigned i;
-
-   dst_pitch *= cpp;
-   src_pitch *= cpp;
-   dst += dst_x * cpp;
-   src += src_x * cpp;
-   dst += dst_y * dst_pitch;
-   src += src_y * src_pitch;
-   width *= cpp;
-
-   if (width == dst_pitch && width == src_pitch)
-      memcpy(dst, src, height * width);
-   else {
-      for (i = 0; i < height; i++) {
-         memcpy(dst, src, width);
-         dst += dst_pitch;
-         src += src_pitch;
-      }
-   }
-}
-
-
 /* Upload data to a rectangular sub-region.  Lots of choices how to do this:
  *
  * - memcpy by span to current destination
@@ -125,10 +86,10 @@ sp_surface_data(struct pipe_context *pipe,
                const void *src, unsigned src_pitch,
                unsigned srcx, unsigned srcy, unsigned width, unsigned height)
 {
-   copy_rect(pipe_surface_map(dst),
-             dst->cpp,
-             dst->pitch,
-             dstx, dsty, width, height, src, src_pitch, srcx, srcy);
+   pipe_copy_rect(pipe_surface_map(dst),
+                  dst->cpp,
+                  dst->pitch,
+                  dstx, dsty, width, height, src, src_pitch, srcx, srcy);
 
    pipe_surface_unmap(dst);
 }
@@ -145,14 +106,14 @@ sp_surface_copy(struct pipe_context *pipe,
 {
    assert( dst->cpp == src->cpp );
 
-   copy_rect(pipe_surface_map(dst),
-             dst->cpp,
-             dst->pitch,
-             dstx, dsty,
-             width, height,
-             pipe_surface_map(src),
-             src->pitch,
-             srcx, srcy);
+   pipe_copy_rect(pipe_surface_map(dst),
+                  dst->cpp,
+                  dst->pitch,
+                  dstx, dsty,
+                  width, height,
+                  pipe_surface_map(src),
+                  src->pitch,
+                  srcx, srcy);
 
    pipe_surface_unmap(src);
    pipe_surface_unmap(dst);
diff --git a/src/mesa/pipe/util/p_util.c b/src/mesa/pipe/util/p_util.c
new file mode 100644 (file)
index 0000000..c4882b7
--- /dev/null
@@ -0,0 +1,73 @@
+/**************************************************************************
+ * 
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ **************************************************************************/
+
+/**
+ * Miscellaneous utility functions.
+ */
+
+
+#include "pipe/p_defines.h"
+#include "pipe/p_util.h"
+
+
+/**
+ * Copy 2D rect from one place to another.
+ * Position and sizes are in pixels.
+ */
+void
+pipe_copy_rect(ubyte * dst,
+               unsigned cpp,
+               unsigned dst_pitch,
+               unsigned dst_x,
+               unsigned dst_y,
+               unsigned width,
+               unsigned height,
+               const ubyte * src,
+               unsigned src_pitch,
+               unsigned src_x, 
+               unsigned src_y)
+{
+   unsigned i;
+
+   dst_pitch *= cpp;
+   src_pitch *= cpp;
+   dst += dst_x * cpp;
+   src += src_x * cpp;
+   dst += dst_y * dst_pitch;
+   src += src_y * src_pitch;
+   width *= cpp;
+
+   if (width == dst_pitch && width == src_pitch)
+      memcpy(dst, src, height * width);
+   else {
+      for (i = 0; i < height; i++) {
+         memcpy(dst, src, width);
+         dst += dst_pitch;
+         src += src_pitch;
+      }
+   }
+}
index 90ce9ce3702ffcc541e7ed3d9c35f8710597944b..d8760ba134e41674f64eeba3bb3d3e6a997a0e3e 100644 (file)
@@ -191,7 +191,8 @@ STATECACHE_SOURCES = \
        pipe/cso_cache/cso_cache.c
 
 PIPEUTIL_SOURCES = \
-       pipe/util/p_tile.c
+       pipe/util/p_tile.c \
+       pipe/util/p_util.c
 
 STATETRACKER_SOURCES = \
        state_tracker/st_atom.c \