1 #include "pipe/p_context.h"
2 #include "util/u_surface.h"
3 #include "util/u_inlines.h"
4 #include "util/u_transfer.h"
5 #include "util/u_memory.h"
7 /* One-shot transfer operation with data supplied in a user
8 * pointer. XXX: strides??
10 void u_default_transfer_inline_write( struct pipe_context
*pipe
,
11 struct pipe_resource
*resource
,
14 const struct pipe_box
*box
,
17 unsigned layer_stride
)
19 struct pipe_transfer
*transfer
= NULL
;
22 assert(!(usage
& PIPE_TRANSFER_READ
));
24 /* the write flag is implicit by the nature of transfer_inline_write */
25 usage
|= PIPE_TRANSFER_WRITE
;
27 /* transfer_inline_write implicitly discards the rewritten buffer range */
28 if (resource
->target
== PIPE_BUFFER
&&
29 box
->x
== 0 && box
->width
== resource
->width0
) {
30 usage
|= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
;
32 usage
|= PIPE_TRANSFER_DISCARD_RANGE
;
35 map
= pipe
->transfer_map(pipe
,
43 if (resource
->target
== PIPE_BUFFER
) {
44 assert(box
->height
== 1);
45 assert(box
->depth
== 1);
47 memcpy(map
, data
, box
->width
);
50 const uint8_t *src_data
= data
;
54 transfer
->stride
, /* bytes */
55 transfer
->layer_stride
, /* bytes */
62 layer_stride
, /* bytes */
66 pipe_transfer_unmap(pipe
, transfer
);
70 boolean
u_default_resource_get_handle(struct pipe_screen
*screen
,
71 struct pipe_resource
*resource
,
72 struct winsys_handle
*handle
)
79 void u_default_transfer_flush_region( struct pipe_context
*pipe
,
80 struct pipe_transfer
*transfer
,
81 const struct pipe_box
*box
)
83 /* This is a no-op implementation, nothing to do.
87 void u_default_transfer_unmap( struct pipe_context
*pipe
,
88 struct pipe_transfer
*transfer
)
93 static inline struct u_resource
*
94 u_resource( struct pipe_resource
*res
)
96 return (struct u_resource
*)res
;
99 boolean
u_resource_get_handle_vtbl(struct pipe_screen
*screen
,
100 struct pipe_resource
*resource
,
101 struct winsys_handle
*handle
)
103 struct u_resource
*ur
= u_resource(resource
);
104 return ur
->vtbl
->resource_get_handle(screen
, resource
, handle
);
107 void u_resource_destroy_vtbl(struct pipe_screen
*screen
,
108 struct pipe_resource
*resource
)
110 struct u_resource
*ur
= u_resource(resource
);
111 ur
->vtbl
->resource_destroy(screen
, resource
);
114 void *u_transfer_map_vtbl(struct pipe_context
*context
,
115 struct pipe_resource
*resource
,
118 const struct pipe_box
*box
,
119 struct pipe_transfer
**transfer
)
121 struct u_resource
*ur
= u_resource(resource
);
122 return ur
->vtbl
->transfer_map(context
, resource
, level
, usage
, box
,
126 void u_transfer_flush_region_vtbl( struct pipe_context
*pipe
,
127 struct pipe_transfer
*transfer
,
128 const struct pipe_box
*box
)
130 struct u_resource
*ur
= u_resource(transfer
->resource
);
131 ur
->vtbl
->transfer_flush_region(pipe
, transfer
, box
);
134 void u_transfer_unmap_vtbl( struct pipe_context
*pipe
,
135 struct pipe_transfer
*transfer
)
137 struct u_resource
*ur
= u_resource(transfer
->resource
);
138 ur
->vtbl
->transfer_unmap(pipe
, transfer
);
141 void u_transfer_inline_write_vtbl( struct pipe_context
*pipe
,
142 struct pipe_resource
*resource
,
145 const struct pipe_box
*box
,
148 unsigned layer_stride
)
150 struct u_resource
*ur
= u_resource(resource
);
151 ur
->vtbl
->transfer_inline_write(pipe
,