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 (box
->x
== 0 && box
->width
== resource
->width0
) {
29 usage
|= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
;
31 usage
|= PIPE_TRANSFER_DISCARD_RANGE
;
34 map
= pipe
->transfer_map(pipe
,
42 if (resource
->target
== PIPE_BUFFER
) {
43 assert(box
->height
== 1);
44 assert(box
->depth
== 1);
46 memcpy(map
, data
, box
->width
);
49 const uint8_t *src_data
= data
;
53 transfer
->stride
, /* bytes */
54 transfer
->layer_stride
, /* bytes */
61 layer_stride
, /* bytes */
65 pipe_transfer_unmap(pipe
, transfer
);
69 boolean
u_default_resource_get_handle(struct pipe_screen
*screen
,
70 struct pipe_resource
*resource
,
71 struct winsys_handle
*handle
)
78 void u_default_transfer_flush_region( struct pipe_context
*pipe
,
79 struct pipe_transfer
*transfer
,
80 const struct pipe_box
*box
)
82 /* This is a no-op implementation, nothing to do.
86 void u_default_transfer_unmap( struct pipe_context
*pipe
,
87 struct pipe_transfer
*transfer
)
92 static INLINE
struct u_resource
*
93 u_resource( struct pipe_resource
*res
)
95 return (struct u_resource
*)res
;
98 boolean
u_resource_get_handle_vtbl(struct pipe_screen
*screen
,
99 struct pipe_resource
*resource
,
100 struct winsys_handle
*handle
)
102 struct u_resource
*ur
= u_resource(resource
);
103 return ur
->vtbl
->resource_get_handle(screen
, resource
, handle
);
106 void u_resource_destroy_vtbl(struct pipe_screen
*screen
,
107 struct pipe_resource
*resource
)
109 struct u_resource
*ur
= u_resource(resource
);
110 ur
->vtbl
->resource_destroy(screen
, resource
);
113 void *u_transfer_map_vtbl(struct pipe_context
*context
,
114 struct pipe_resource
*resource
,
117 const struct pipe_box
*box
,
118 struct pipe_transfer
**transfer
)
120 struct u_resource
*ur
= u_resource(resource
);
121 return ur
->vtbl
->transfer_map(context
, resource
, level
, usage
, box
,
125 void u_transfer_flush_region_vtbl( struct pipe_context
*pipe
,
126 struct pipe_transfer
*transfer
,
127 const struct pipe_box
*box
)
129 struct u_resource
*ur
= u_resource(transfer
->resource
);
130 ur
->vtbl
->transfer_flush_region(pipe
, transfer
, box
);
133 void u_transfer_unmap_vtbl( struct pipe_context
*pipe
,
134 struct pipe_transfer
*transfer
)
136 struct u_resource
*ur
= u_resource(transfer
->resource
);
137 ur
->vtbl
->transfer_unmap(pipe
, transfer
);
140 void u_transfer_inline_write_vtbl( struct pipe_context
*pipe
,
141 struct pipe_resource
*resource
,
144 const struct pipe_box
*box
,
147 unsigned layer_stride
)
149 struct u_resource
*ur
= u_resource(resource
);
150 ur
->vtbl
->transfer_inline_write(pipe
,