gallium: unify transfer functions
[mesa.git] / src / gallium / auxiliary / util / u_transfer.c
1 #include "pipe/p_context.h"
2 #include "util/u_rect.h"
3 #include "util/u_inlines.h"
4 #include "util/u_transfer.h"
5 #include "util/u_memory.h"
6
7 /* One-shot transfer operation with data supplied in a user
8 * pointer. XXX: strides??
9 */
10 void u_default_transfer_inline_write( struct pipe_context *pipe,
11 struct pipe_resource *resource,
12 unsigned level,
13 unsigned usage,
14 const struct pipe_box *box,
15 const void *data,
16 unsigned stride,
17 unsigned layer_stride)
18 {
19 struct pipe_transfer *transfer = NULL;
20 uint8_t *map = NULL;
21
22 assert(!(usage & PIPE_TRANSFER_READ));
23
24 /* the write flag is implicit by the nature of transfer_inline_write */
25 usage |= PIPE_TRANSFER_WRITE;
26
27 /* transfer_inline_write implicitly discards the rewritten buffer range */
28 if (box->x == 0 && box->width == resource->width0) {
29 usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
30 } else {
31 usage |= PIPE_TRANSFER_DISCARD_RANGE;
32 }
33
34 map = pipe->transfer_map(pipe,
35 resource,
36 level,
37 usage,
38 box, &transfer);
39 if (map == NULL)
40 return;
41
42 if (resource->target == PIPE_BUFFER) {
43 assert(box->height == 1);
44 assert(box->depth == 1);
45
46 memcpy(map, data, box->width);
47 }
48 else {
49 const uint8_t *src_data = data;
50 unsigned i;
51
52 for (i = 0; i < box->depth; i++) {
53 util_copy_rect(map,
54 resource->format,
55 transfer->stride, /* bytes */
56 0, 0,
57 box->width,
58 box->height,
59 src_data,
60 stride, /* bytes */
61 0, 0);
62 map += transfer->layer_stride;
63 src_data += layer_stride;
64 }
65 }
66
67 pipe_transfer_unmap(pipe, transfer);
68 }
69
70
71 boolean u_default_resource_get_handle(struct pipe_screen *screen,
72 struct pipe_resource *resource,
73 struct winsys_handle *handle)
74 {
75 return FALSE;
76 }
77
78
79
80 void u_default_transfer_flush_region( struct pipe_context *pipe,
81 struct pipe_transfer *transfer,
82 const struct pipe_box *box)
83 {
84 /* This is a no-op implementation, nothing to do.
85 */
86 }
87
88 void u_default_transfer_unmap( struct pipe_context *pipe,
89 struct pipe_transfer *transfer )
90 {
91 }