Module: Mesa
Branch: gallium-resources
Commit: 072957aab25affecf0702e925310e46c694a5ee4
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=072957aab25affecf0702e925310e46c694a5ee4

Author: Keith Whitwell <[email protected]>
Date:   Sun Mar 14 09:42:46 2010 +0000

util: helpers for inline transfers

---

 src/gallium/auxiliary/Makefile          |    3 +-
 src/gallium/auxiliary/util/u_transfer.c |   98 +++++++++++++++++++++++++++++++
 src/gallium/auxiliary/util/u_transfer.h |   25 ++++++++
 3 files changed, 125 insertions(+), 1 deletions(-)

diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile
index d1dcb7b..ccc8338 100644
--- a/src/gallium/auxiliary/Makefile
+++ b/src/gallium/auxiliary/Makefile
@@ -127,14 +127,15 @@ C_SOURCES = \
        util/u_surface.c \
        util/u_texture.c \
        util/u_tile.c \
+       util/u_transfer.c \
        util/u_upload_mgr.c \
+       target-helpers/wrap_screen.c
        # Disabling until pipe-video branch gets merged in
        #vl/vl_bitstream_parser.c \
        #vl/vl_mpeg12_mc_renderer.c \
        #vl/vl_compositor.c \
        #vl/vl_csc.c \
        #vl/vl_shader_build.c \
-       target-helpers/wrap_screen.c
 
 GALLIVM_SOURCES = \
         gallivm/lp_bld_alpha.c \
diff --git a/src/gallium/auxiliary/util/u_transfer.c 
b/src/gallium/auxiliary/util/u_transfer.c
new file mode 100644
index 0000000..d0ea89f
--- /dev/null
+++ b/src/gallium/auxiliary/util/u_transfer.c
@@ -0,0 +1,98 @@
+#include "pipe/p_context.h"
+#include "util/u_rect.h"
+#include "util/u_inlines.h"
+#include "util/u_transfer.h"
+
+/* One-shot transfer operation with data supplied in a user
+ * pointer.  XXX: strides??
+ */
+void u_transfer_inline_write( struct pipe_context *pipe,
+                              struct pipe_resource *resource,
+                              struct pipe_subresource sr,
+                              enum pipe_transfer_usage usage,
+                              const struct pipe_box *box,
+                              const void *data )
+{
+   struct pipe_transfer *transfer = NULL;
+   uint8_t *map = NULL;
+
+   transfer = pipe->get_transfer(pipe, 
+                                resource,
+                                sr,
+                                usage,
+                                box );
+   if (transfer == NULL)
+      goto out;
+
+   map = pipe_transfer_map(pipe, transfer);
+   if (map == NULL)
+      goto out;
+
+   assert(box->depth == 1);    /* XXX: fix me */
+   
+   util_copy_rect(map,
+                 resource->format,
+                 transfer->stride, /* bytes? */
+                 0, 0,
+                 box->width,
+                 box->height,
+                 data,
+                 box->width,   /* bytes? texels? */
+                 0, 0);
+
+out:
+   if (map)
+      pipe_transfer_unmap(pipe, transfer);
+
+   if (transfer)
+      pipe_transfer_destroy(pipe, transfer);
+}
+
+
+
+/* One-shot read transfer operation with data returned in a user
+ * pointer.  XXX: strides??
+ */
+void u_transfer_inline_read( struct pipe_context *pipe,
+                             struct pipe_resource *resource,
+                             struct pipe_subresource sr,
+                             enum pipe_transfer_usage usage,
+                             const struct pipe_box *box,
+                             void *data )
+{
+   struct pipe_transfer *transfer = NULL;
+   uint8_t *map = NULL;
+
+   transfer = pipe->get_transfer(pipe, 
+                                resource,
+                                sr,
+                                usage,
+                                box );
+   if (transfer == NULL)
+      goto out;
+
+   map = pipe_transfer_map(pipe, transfer);
+   if (map == NULL)
+      goto out;
+
+   assert(box->depth == 1);    /* XXX: fix me */
+   
+   util_copy_rect(data,
+                 resource->format,
+                 transfer->stride, /* bytes? */
+                 0, 0,
+                 box->width,
+                 box->height,
+                 map,
+                 box->width,   /* bytes? texels? */
+                 0, 0);
+
+
+out:
+   if (map)
+      pipe_transfer_unmap(pipe, transfer);
+
+   if (transfer)
+      pipe_transfer_destroy(pipe, transfer);
+}
+
diff --git a/src/gallium/auxiliary/util/u_transfer.h 
b/src/gallium/auxiliary/util/u_transfer.h
new file mode 100644
index 0000000..eeef88d
--- /dev/null
+++ b/src/gallium/auxiliary/util/u_transfer.h
@@ -0,0 +1,25 @@
+
+#ifndef U_TRANSFER_H
+#define U_TRANSFER_H
+
+/* Fallback implementations for inline read/writes which just go back
+ * to the regular transfer behaviour.
+ */
+#include "pipe/p_state.h"
+
+struct pipe_context;
+
+
+void u_transfer_inline_write( struct pipe_context *pipe,
+                              struct pipe_resource *resource,
+                              struct pipe_subresource sr,
+                              enum pipe_transfer_usage usage,
+                              const struct pipe_box *box,
+                             const void *data );
+void u_transfer_inline_read( struct pipe_context *pipe,
+                             struct pipe_resource *resource,
+                             struct pipe_subresource sr,
+                             enum pipe_transfer_usage usage,
+                             const struct pipe_box *box,
+                            void *data );
+#endif

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to