render/allocator: add wlr_allocator.buffer_caps

This allows users to know the capabilities of the buffers that
will be allocated. The buffer capability is important to
know when negotiating buffer formats.
master
Simon Ser 4 years ago committed by Simon Zeni
parent 5c30cf3d94
commit 766a24fa77

@ -19,6 +19,9 @@ struct wlr_allocator_interface {
struct wlr_allocator { struct wlr_allocator {
const struct wlr_allocator_interface *impl; const struct wlr_allocator_interface *impl;
// Capabilites of the buffers created with this allocator
uint32_t buffer_caps;
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
} events; } events;
@ -44,7 +47,7 @@ struct wlr_buffer *wlr_allocator_create_buffer(struct wlr_allocator *alloc,
// For wlr_allocator implementors // For wlr_allocator implementors
void wlr_allocator_init(struct wlr_allocator *alloc, void wlr_allocator_init(struct wlr_allocator *alloc,
const struct wlr_allocator_interface *impl); const struct wlr_allocator_interface *impl, uint32_t buffer_caps);
struct wlr_allocator *allocator_autocreate_with_drm_fd( struct wlr_allocator *allocator_autocreate_with_drm_fd(
struct wlr_backend *backend, struct wlr_renderer *renderer, int drm_fd); struct wlr_backend *backend, struct wlr_renderer *renderer, int drm_fd);

@ -11,9 +11,10 @@
#include "types/wlr_buffer.h" #include "types/wlr_buffer.h"
void wlr_allocator_init(struct wlr_allocator *alloc, void wlr_allocator_init(struct wlr_allocator *alloc,
const struct wlr_allocator_interface *impl) { const struct wlr_allocator_interface *impl, uint32_t buffer_caps) {
assert(impl && impl->destroy && impl->create_buffer); assert(impl && impl->destroy && impl->create_buffer);
alloc->impl = impl; alloc->impl = impl;
alloc->buffer_caps = buffer_caps;
wl_signal_init(&alloc->events.destroy); wl_signal_init(&alloc->events.destroy);
} }
@ -74,5 +75,19 @@ void wlr_allocator_destroy(struct wlr_allocator *alloc) {
struct wlr_buffer *wlr_allocator_create_buffer(struct wlr_allocator *alloc, struct wlr_buffer *wlr_allocator_create_buffer(struct wlr_allocator *alloc,
int width, int height, const struct wlr_drm_format *format) { int width, int height, const struct wlr_drm_format *format) {
return alloc->impl->create_buffer(alloc, width, height, format); struct wlr_buffer *buffer =
alloc->impl->create_buffer(alloc, width, height, format);
if (buffer == NULL) {
return NULL;
}
if (alloc->buffer_caps & WLR_BUFFER_CAP_DATA_PTR) {
assert(buffer->impl->get_data_ptr);
}
if (alloc->buffer_caps & WLR_BUFFER_CAP_DMABUF) {
assert(buffer->impl->get_dmabuf);
}
if (alloc->buffer_caps & WLR_BUFFER_CAP_SHM) {
assert(buffer->impl->get_shm);
}
return buffer;
} }

@ -15,6 +15,7 @@
#include "render/drm_dumb_allocator.h" #include "render/drm_dumb_allocator.h"
#include "render/pixel_format.h" #include "render/pixel_format.h"
#include "types/wlr_buffer.h"
static const struct wlr_buffer_impl buffer_impl; static const struct wlr_buffer_impl buffer_impl;
@ -127,7 +128,7 @@ create_err:
return NULL; return NULL;
} }
static bool buffer_get_data_ptr(struct wlr_buffer *wlr_buffer, void **data, static bool drm_dumb_buffer_get_data_ptr(struct wlr_buffer *wlr_buffer, void **data,
uint32_t *format, size_t *stride) { uint32_t *format, size_t *stride) {
struct wlr_drm_dumb_buffer *buf = drm_dumb_buffer_from_buffer(wlr_buffer); struct wlr_drm_dumb_buffer *buf = drm_dumb_buffer_from_buffer(wlr_buffer);
*data = buf->data; *data = buf->data;
@ -152,7 +153,7 @@ static void buffer_destroy(struct wlr_buffer *wlr_buffer) {
static const struct wlr_buffer_impl buffer_impl = { static const struct wlr_buffer_impl buffer_impl = {
.destroy = buffer_destroy, .destroy = buffer_destroy,
.get_dmabuf = buffer_get_dmabuf, .get_dmabuf = buffer_get_dmabuf,
.get_data_ptr = buffer_get_data_ptr, .get_data_ptr = drm_dumb_buffer_get_data_ptr,
}; };
static const struct wlr_allocator_interface allocator_impl; static const struct wlr_allocator_interface allocator_impl;
@ -231,7 +232,8 @@ struct wlr_allocator *wlr_drm_dumb_allocator_create(int fd) {
free(path); free(path);
return NULL; return NULL;
} }
wlr_allocator_init(&alloc->base, &allocator_impl); wlr_allocator_init(&alloc->base, &allocator_impl,
WLR_BUFFER_CAP_DATA_PTR | WLR_BUFFER_CAP_DMABUF);
alloc->drm_fd = drm_fd; alloc->drm_fd = drm_fd;
wl_list_init(&alloc->buffers); wl_list_init(&alloc->buffers);

@ -7,6 +7,7 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <xf86drm.h> #include <xf86drm.h>
#include "render/gbm_allocator.h" #include "render/gbm_allocator.h"
#include "types/wlr_buffer.h"
static const struct wlr_buffer_impl buffer_impl; static const struct wlr_buffer_impl buffer_impl;
@ -181,7 +182,7 @@ struct wlr_allocator *wlr_gbm_allocator_create(int drm_fd) {
if (alloc == NULL) { if (alloc == NULL) {
return NULL; return NULL;
} }
wlr_allocator_init(&alloc->base, &allocator_impl); wlr_allocator_init(&alloc->base, &allocator_impl, WLR_BUFFER_CAP_DMABUF);
alloc->fd = fd; alloc->fd = fd;
wl_list_init(&alloc->buffers); wl_list_init(&alloc->buffers);

@ -7,6 +7,7 @@
#include "render/pixel_format.h" #include "render/pixel_format.h"
#include "render/shm_allocator.h" #include "render/shm_allocator.h"
#include "util/shm.h" #include "util/shm.h"
#include "types/wlr_buffer.h"
static const struct wlr_buffer_impl buffer_impl; static const struct wlr_buffer_impl buffer_impl;
@ -30,7 +31,7 @@ static bool buffer_get_shm(struct wlr_buffer *wlr_buffer,
return true; return true;
} }
static bool buffer_get_data_ptr(struct wlr_buffer *wlr_buffer, void **data, static bool shm_buffer_get_data_ptr(struct wlr_buffer *wlr_buffer, void **data,
uint32_t *format, size_t *stride) { uint32_t *format, size_t *stride) {
struct wlr_shm_buffer *buffer = shm_buffer_from_buffer(wlr_buffer); struct wlr_shm_buffer *buffer = shm_buffer_from_buffer(wlr_buffer);
*data = buffer->data; *data = buffer->data;
@ -42,7 +43,7 @@ static bool buffer_get_data_ptr(struct wlr_buffer *wlr_buffer, void **data,
static const struct wlr_buffer_impl buffer_impl = { static const struct wlr_buffer_impl buffer_impl = {
.destroy = buffer_destroy, .destroy = buffer_destroy,
.get_shm = buffer_get_shm, .get_shm = buffer_get_shm,
.get_data_ptr = buffer_get_data_ptr, .get_data_ptr = shm_buffer_get_data_ptr,
}; };
static struct wlr_buffer *allocator_create_buffer( static struct wlr_buffer *allocator_create_buffer(
@ -103,7 +104,8 @@ struct wlr_allocator *wlr_shm_allocator_create(void) {
if (allocator == NULL) { if (allocator == NULL) {
return NULL; return NULL;
} }
wlr_allocator_init(&allocator->base, &allocator_impl); wlr_allocator_init(&allocator->base, &allocator_impl,
WLR_BUFFER_CAP_DATA_PTR | WLR_BUFFER_CAP_SHM);
wlr_log(WLR_DEBUG, "Created shm allocator"); wlr_log(WLR_DEBUG, "Created shm allocator");
return &allocator->base; return &allocator->base;

Loading…
Cancel
Save