types/buffer: make {begin,end}_data_ptr_access part of the public API

This commit is contained in:
Simon Zeni 2021-09-10 13:25:42 -04:00 committed by Simon Ser
parent 6cb25ebad7
commit 9579d62a16
5 changed files with 43 additions and 43 deletions

View File

@ -69,31 +69,4 @@ struct wlr_dmabuf_buffer *dmabuf_buffer_create(
*/ */
bool dmabuf_buffer_drop(struct wlr_dmabuf_buffer *buffer); 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 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, uint32_t flags,
void **data, uint32_t *format, size_t *stride);
void buffer_end_data_ptr_access(struct wlr_buffer *buffer);
#endif #endif

View File

@ -137,6 +137,33 @@ void wlr_buffer_register_resource_interface(
*/ */
struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource); struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource);
/**
* 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 the
* operations specified in the flags. The returned pointer is only valid up to
* the next buffer_end_data_ptr_access call.
*/
bool wlr_buffer_begin_data_ptr_access(struct wlr_buffer *buffer, uint32_t flags,
void **data, uint32_t *format, size_t *stride);
void wlr_buffer_end_data_ptr_access(struct wlr_buffer *buffer);
/** /**
* A client buffer. * A client buffer.
*/ */

View File

@ -346,11 +346,11 @@ struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer,
struct wlr_dmabuf_attributes dmabuf; struct wlr_dmabuf_attributes dmabuf;
if (wlr_buffer_get_dmabuf(buffer, &dmabuf)) { if (wlr_buffer_get_dmabuf(buffer, &dmabuf)) {
return gles2_texture_from_dmabuf_buffer(renderer, buffer, &dmabuf); return gles2_texture_from_dmabuf_buffer(renderer, buffer, &dmabuf);
} else if (buffer_begin_data_ptr_access(buffer, } else if (wlr_buffer_begin_data_ptr_access(buffer,
WLR_BUFFER_DATA_PTR_ACCESS_READ, &data, &format, &stride)) { WLR_BUFFER_DATA_PTR_ACCESS_READ, &data, &format, &stride)) {
struct wlr_texture *tex = gles2_texture_from_pixels(wlr_renderer, struct wlr_texture *tex = gles2_texture_from_pixels(wlr_renderer,
format, stride, buffer->width, buffer->height, data); format, stride, buffer->width, buffer->height, data);
buffer_end_data_ptr_access(buffer); wlr_buffer_end_data_ptr_access(buffer);
return tex; return tex;
} else { } else {
return NULL; return NULL;

View File

@ -96,13 +96,13 @@ static struct wlr_pixman_buffer *create_buffer(
void *data = NULL; void *data = NULL;
uint32_t drm_format; uint32_t drm_format;
size_t stride; size_t stride;
if (!buffer_begin_data_ptr_access(wlr_buffer, if (!wlr_buffer_begin_data_ptr_access(wlr_buffer,
WLR_BUFFER_DATA_PTR_ACCESS_READ | WLR_BUFFER_DATA_PTR_ACCESS_WRITE, WLR_BUFFER_DATA_PTR_ACCESS_READ | WLR_BUFFER_DATA_PTR_ACCESS_WRITE,
&data, &drm_format, &stride)) { &data, &drm_format, &stride)) {
wlr_log(WLR_ERROR, "Failed to get buffer data"); wlr_log(WLR_ERROR, "Failed to get buffer data");
goto error_buffer; goto error_buffer;
} }
buffer_end_data_ptr_access(wlr_buffer); wlr_buffer_end_data_ptr_access(wlr_buffer);
pixman_format_code_t format = get_pixman_format_from_drm(drm_format); pixman_format_code_t format = get_pixman_format_from_drm(drm_format);
if (format == 0) { if (format == 0) {
@ -145,7 +145,7 @@ static void pixman_begin(struct wlr_renderer *wlr_renderer, uint32_t width,
void *data = NULL; void *data = NULL;
uint32_t drm_format; uint32_t drm_format;
size_t stride; size_t stride;
buffer_begin_data_ptr_access(buffer->buffer, wlr_buffer_begin_data_ptr_access(buffer->buffer,
WLR_BUFFER_DATA_PTR_ACCESS_READ | WLR_BUFFER_DATA_PTR_ACCESS_WRITE, WLR_BUFFER_DATA_PTR_ACCESS_READ | WLR_BUFFER_DATA_PTR_ACCESS_WRITE,
&data, &drm_format, &stride); &data, &drm_format, &stride);
@ -166,7 +166,7 @@ static void pixman_end(struct wlr_renderer *wlr_renderer) {
assert(renderer->current_buffer != NULL); assert(renderer->current_buffer != NULL);
buffer_end_data_ptr_access(renderer->current_buffer->buffer); wlr_buffer_end_data_ptr_access(renderer->current_buffer->buffer);
} }
static void pixman_clear(struct wlr_renderer *wlr_renderer, static void pixman_clear(struct wlr_renderer *wlr_renderer,
@ -233,7 +233,7 @@ static bool pixman_render_subtexture_with_matrix(
void *data; void *data;
uint32_t drm_format; uint32_t drm_format;
size_t stride; size_t stride;
if (!buffer_begin_data_ptr_access(texture->buffer, if (!wlr_buffer_begin_data_ptr_access(texture->buffer,
WLR_BUFFER_DATA_PTR_ACCESS_READ, &data, &drm_format, &stride)) { WLR_BUFFER_DATA_PTR_ACCESS_READ, &data, &drm_format, &stride)) {
return false; return false;
} }
@ -272,7 +272,7 @@ static bool pixman_render_subtexture_with_matrix(
renderer->height); renderer->height);
if (texture->buffer != NULL) { if (texture->buffer != NULL) {
buffer_end_data_ptr_access(texture->buffer); wlr_buffer_end_data_ptr_access(texture->buffer);
} }
pixman_image_unref(mask); pixman_image_unref(mask);
@ -380,11 +380,11 @@ static struct wlr_texture *pixman_texture_from_buffer(
void *data = NULL; void *data = NULL;
uint32_t drm_format; uint32_t drm_format;
size_t stride; size_t stride;
if (!buffer_begin_data_ptr_access(buffer, WLR_BUFFER_DATA_PTR_ACCESS_READ, if (!wlr_buffer_begin_data_ptr_access(buffer, WLR_BUFFER_DATA_PTR_ACCESS_READ,
&data, &drm_format, &stride)) { &data, &drm_format, &stride)) {
return NULL; return NULL;
} }
buffer_end_data_ptr_access(buffer); wlr_buffer_end_data_ptr_access(buffer);
struct wlr_pixman_texture *texture = pixman_texture_create(renderer, struct wlr_pixman_texture *texture = pixman_texture_create(renderer,
drm_format, buffer->width, buffer->height); drm_format, buffer->width, buffer->height);

View File

@ -75,7 +75,7 @@ bool wlr_buffer_get_dmabuf(struct wlr_buffer *buffer,
return buffer->impl->get_dmabuf(buffer, attribs); return buffer->impl->get_dmabuf(buffer, attribs);
} }
bool buffer_begin_data_ptr_access(struct wlr_buffer *buffer, uint32_t flags, bool wlr_buffer_begin_data_ptr_access(struct wlr_buffer *buffer, uint32_t flags,
void **data, uint32_t *format, size_t *stride) { void **data, uint32_t *format, size_t *stride) {
assert(!buffer->accessing_data_ptr); assert(!buffer->accessing_data_ptr);
if (!buffer->impl->begin_data_ptr_access) { if (!buffer->impl->begin_data_ptr_access) {
@ -88,7 +88,7 @@ bool buffer_begin_data_ptr_access(struct wlr_buffer *buffer, uint32_t flags,
return true; return true;
} }
void buffer_end_data_ptr_access(struct wlr_buffer *buffer) { void wlr_buffer_end_data_ptr_access(struct wlr_buffer *buffer) {
assert(buffer->accessing_data_ptr); assert(buffer->accessing_data_ptr);
buffer->impl->end_data_ptr_access(buffer); buffer->impl->end_data_ptr_access(buffer);
buffer->accessing_data_ptr = false; buffer->accessing_data_ptr = false;
@ -292,14 +292,14 @@ bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer,
void *data; void *data;
uint32_t format; uint32_t format;
size_t stride; size_t stride;
if (!buffer_begin_data_ptr_access(next, WLR_BUFFER_DATA_PTR_ACCESS_READ, if (!wlr_buffer_begin_data_ptr_access(next, WLR_BUFFER_DATA_PTR_ACCESS_READ,
&data, &format, &stride)) { &data, &format, &stride)) {
return false; return false;
} }
if (format != client_buffer->shm_source_format) { if (format != client_buffer->shm_source_format) {
// Uploading to textures can't change the format // Uploading to textures can't change the format
buffer_end_data_ptr_access(next); wlr_buffer_end_data_ptr_access(next);
return false; return false;
} }
@ -310,12 +310,12 @@ bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer,
if (!wlr_texture_write_pixels(client_buffer->texture, stride, if (!wlr_texture_write_pixels(client_buffer->texture, stride,
r->x2 - r->x1, r->y2 - r->y1, r->x1, r->y1, r->x2 - r->x1, r->y2 - r->y1, r->x1, r->y1,
r->x1, r->y1, data)) { r->x1, r->y1, data)) {
buffer_end_data_ptr_access(next); wlr_buffer_end_data_ptr_access(next);
return false; return false;
} }
} }
buffer_end_data_ptr_access(next); wlr_buffer_end_data_ptr_access(next);
return true; return true;
} }