u_transfer.c 2.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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);
}