mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 12:55:58 +01:00
buffer: add data_ptr access flags
This allows callers to specify the operations they'll perform on the returned data pointer. The motivations for this are: - The upcoming Linux MAP_NOSIGBUS flag may only be usable on read-only mappings. - gbm_bo_map with GBM_BO_TRANSFER_READ hurts performance.
This commit is contained in:
parent
105fdecd0c
commit
4e7a8707cc
7 changed files with 46 additions and 22 deletions
|
@ -69,17 +69,31 @@ struct wlr_dmabuf_buffer *dmabuf_buffer_create(
|
|||
*/
|
||||
bool dmabuf_buffer_drop(struct wlr_dmabuf_buffer *buffer);
|
||||
|
||||
/**
|
||||
* Buffer data pointer access flags.
|
||||
*/
|
||||
enum wlr_buffer_data_ptr_access_flag {
|
||||
/**
|
||||
* The buffer contents can be read back.
|
||||
*/
|
||||
WLR_BUFFER_DATA_PTR_ACCESS_READ = 1 << 0,
|
||||
/**
|
||||
* The buffer contents can be written to.
|
||||
*/
|
||||
WLR_BUFFER_DATA_PTR_ACCESS_WRITE = 1 << 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a pointer to a region of memory referring to the buffer's underlying
|
||||
* storage. The format and stride can be used to interpret the memory region
|
||||
* contents.
|
||||
*
|
||||
* The returned pointer should be pointing to a valid memory region for read
|
||||
* and write operations. The returned pointer is only valid up to the next
|
||||
* buffer_end_data_ptr_access call.
|
||||
* The returned pointer should be pointing to a valid memory region for the
|
||||
* operations specified in the flags. The returned pointer is only valid up to
|
||||
* the next buffer_end_data_ptr_access call.
|
||||
*/
|
||||
bool buffer_begin_data_ptr_access(struct wlr_buffer *buffer, void **data,
|
||||
uint32_t *format, size_t *stride);
|
||||
bool buffer_begin_data_ptr_access(struct wlr_buffer *buffer, uint32_t flags,
|
||||
void **data, uint32_t *format, size_t *stride);
|
||||
void buffer_end_data_ptr_access(struct wlr_buffer *buffer);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,8 +30,8 @@ struct wlr_buffer_impl {
|
|||
struct wlr_dmabuf_attributes *attribs);
|
||||
bool (*get_shm)(struct wlr_buffer *buffer,
|
||||
struct wlr_shm_attributes *attribs);
|
||||
bool (*begin_data_ptr_access)(struct wlr_buffer *buffer, void **data,
|
||||
uint32_t *format, size_t *stride);
|
||||
bool (*begin_data_ptr_access)(struct wlr_buffer *buffer, uint32_t flags,
|
||||
void **data, uint32_t *format, size_t *stride);
|
||||
void (*end_data_ptr_access)(struct wlr_buffer *buffer);
|
||||
};
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ create_err:
|
|||
}
|
||||
|
||||
static bool drm_dumb_buffer_begin_data_ptr_access(struct wlr_buffer *wlr_buffer,
|
||||
void **data, uint32_t *format, size_t *stride) {
|
||||
uint32_t flags, void **data, uint32_t *format, size_t *stride) {
|
||||
struct wlr_drm_dumb_buffer *buf = drm_dumb_buffer_from_buffer(wlr_buffer);
|
||||
*data = buf->data;
|
||||
*stride = buf->stride;
|
||||
|
|
|
@ -31,7 +31,7 @@ static bool buffer_get_shm(struct wlr_buffer *wlr_buffer,
|
|||
}
|
||||
|
||||
static bool shm_buffer_begin_data_ptr_access(struct wlr_buffer *wlr_buffer,
|
||||
void **data, uint32_t *format, size_t *stride) {
|
||||
uint32_t flags, void **data, uint32_t *format, size_t *stride) {
|
||||
struct wlr_shm_buffer *buffer = shm_buffer_from_buffer(wlr_buffer);
|
||||
*data = buffer->data;
|
||||
*format = buffer->shm.format;
|
||||
|
|
|
@ -346,7 +346,8 @@ struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer,
|
|||
struct wlr_dmabuf_attributes dmabuf;
|
||||
if (wlr_buffer_get_dmabuf(buffer, &dmabuf)) {
|
||||
return gles2_texture_from_dmabuf_buffer(renderer, buffer, &dmabuf);
|
||||
} else if (buffer_begin_data_ptr_access(buffer, &data, &format, &stride)) {
|
||||
} else if (buffer_begin_data_ptr_access(buffer,
|
||||
WLR_BUFFER_DATA_PTR_ACCESS_READ, &data, &format, &stride)) {
|
||||
struct wlr_texture *tex = gles2_texture_from_pixels(wlr_renderer,
|
||||
format, stride, buffer->width, buffer->height, data);
|
||||
buffer_end_data_ptr_access(buffer);
|
||||
|
|
|
@ -96,7 +96,9 @@ static struct wlr_pixman_buffer *create_buffer(
|
|||
void *data = NULL;
|
||||
uint32_t drm_format;
|
||||
size_t stride;
|
||||
if (!buffer_begin_data_ptr_access(wlr_buffer, &data, &drm_format, &stride)) {
|
||||
if (!buffer_begin_data_ptr_access(wlr_buffer,
|
||||
WLR_BUFFER_DATA_PTR_ACCESS_READ | WLR_BUFFER_DATA_PTR_ACCESS_WRITE,
|
||||
&data, &drm_format, &stride)) {
|
||||
wlr_log(WLR_ERROR, "Failed to get buffer data");
|
||||
goto error_buffer;
|
||||
}
|
||||
|
@ -143,7 +145,9 @@ static void pixman_begin(struct wlr_renderer *wlr_renderer, uint32_t width,
|
|||
void *data = NULL;
|
||||
uint32_t drm_format;
|
||||
size_t stride;
|
||||
buffer_begin_data_ptr_access(buffer->buffer, &data, &drm_format, &stride);
|
||||
buffer_begin_data_ptr_access(buffer->buffer,
|
||||
WLR_BUFFER_DATA_PTR_ACCESS_READ | WLR_BUFFER_DATA_PTR_ACCESS_WRITE,
|
||||
&data, &drm_format, &stride);
|
||||
|
||||
// If the data pointer has changed, re-create the Pixman image. This can
|
||||
// happen if it's a client buffer and the wl_shm_pool has been resized.
|
||||
|
@ -229,8 +233,8 @@ static bool pixman_render_subtexture_with_matrix(
|
|||
void *data;
|
||||
uint32_t drm_format;
|
||||
size_t stride;
|
||||
if (!buffer_begin_data_ptr_access(texture->buffer, &data, &drm_format,
|
||||
&stride)) {
|
||||
if (!buffer_begin_data_ptr_access(texture->buffer,
|
||||
WLR_BUFFER_DATA_PTR_ACCESS_READ, &data, &drm_format, &stride)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -376,7 +380,8 @@ static struct wlr_texture *pixman_texture_from_buffer(
|
|||
void *data = NULL;
|
||||
uint32_t drm_format;
|
||||
size_t stride;
|
||||
if (!buffer_begin_data_ptr_access(buffer, &data, &drm_format, &stride)) {
|
||||
if (!buffer_begin_data_ptr_access(buffer, WLR_BUFFER_DATA_PTR_ACCESS_READ,
|
||||
&data, &drm_format, &stride)) {
|
||||
return NULL;
|
||||
}
|
||||
buffer_end_data_ptr_access(buffer);
|
||||
|
|
|
@ -75,13 +75,13 @@ bool wlr_buffer_get_dmabuf(struct wlr_buffer *buffer,
|
|||
return buffer->impl->get_dmabuf(buffer, attribs);
|
||||
}
|
||||
|
||||
bool buffer_begin_data_ptr_access(struct wlr_buffer *buffer, void **data,
|
||||
uint32_t *format, size_t *stride) {
|
||||
bool buffer_begin_data_ptr_access(struct wlr_buffer *buffer, uint32_t flags,
|
||||
void **data, uint32_t *format, size_t *stride) {
|
||||
assert(!buffer->accessing_data_ptr);
|
||||
if (!buffer->impl->begin_data_ptr_access) {
|
||||
return false;
|
||||
}
|
||||
if (!buffer->impl->begin_data_ptr_access(buffer, data, format, stride)) {
|
||||
if (!buffer->impl->begin_data_ptr_access(buffer, flags, data, format, stride)) {
|
||||
return false;
|
||||
}
|
||||
buffer->accessing_data_ptr = true;
|
||||
|
@ -292,7 +292,8 @@ bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer,
|
|||
void *data;
|
||||
uint32_t format;
|
||||
size_t stride;
|
||||
if (!buffer_begin_data_ptr_access(next, &data, &format, &stride)) {
|
||||
if (!buffer_begin_data_ptr_access(next, WLR_BUFFER_DATA_PTR_ACCESS_READ,
|
||||
&data, &format, &stride)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -343,7 +344,7 @@ static void shm_client_buffer_destroy(struct wlr_buffer *wlr_buffer) {
|
|||
}
|
||||
|
||||
static bool shm_client_buffer_begin_data_ptr_access(struct wlr_buffer *wlr_buffer,
|
||||
void **data, uint32_t *format, size_t *stride) {
|
||||
uint32_t flags, void **data, uint32_t *format, size_t *stride) {
|
||||
struct wlr_shm_client_buffer *buffer =
|
||||
shm_client_buffer_from_buffer(wlr_buffer);
|
||||
*format = buffer->format;
|
||||
|
@ -454,13 +455,16 @@ static void readonly_data_buffer_destroy(struct wlr_buffer *wlr_buffer) {
|
|||
}
|
||||
|
||||
static bool readonly_data_buffer_begin_data_ptr_access(struct wlr_buffer *wlr_buffer,
|
||||
void **data, uint32_t *format, size_t *stride) {
|
||||
uint32_t flags, void **data, uint32_t *format, size_t *stride) {
|
||||
struct wlr_readonly_data_buffer *buffer =
|
||||
readonly_data_buffer_from_buffer(wlr_buffer);
|
||||
if (buffer->data == NULL) {
|
||||
return false;
|
||||
}
|
||||
*data = (void*)buffer->data;
|
||||
if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) {
|
||||
return false;
|
||||
}
|
||||
*data = (void *)buffer->data;
|
||||
*format = buffer->format;
|
||||
*stride = buffer->stride;
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue