aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/render/allocator.h5
-rw-r--r--render/allocator.c19
-rw-r--r--render/drm_dumb_allocator.c8
-rw-r--r--render/gbm_allocator.c3
-rw-r--r--render/shm_allocator.c8
5 files changed, 33 insertions, 10 deletions
diff --git a/include/render/allocator.h b/include/render/allocator.h
index 4f1cbd0f..c33ab126 100644
--- a/include/render/allocator.h
+++ b/include/render/allocator.h
@@ -19,6 +19,9 @@ struct wlr_allocator_interface {
struct wlr_allocator {
const struct wlr_allocator_interface *impl;
+ // Capabilites of the buffers created with this allocator
+ uint32_t buffer_caps;
+
struct {
struct wl_signal destroy;
} events;
@@ -44,7 +47,7 @@ struct wlr_buffer *wlr_allocator_create_buffer(struct wlr_allocator *alloc,
// For wlr_allocator implementors
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_backend *backend, struct wlr_renderer *renderer, int drm_fd);
diff --git a/render/allocator.c b/render/allocator.c
index f06049ab..4f87d95a 100644
--- a/render/allocator.c
+++ b/render/allocator.c
@@ -11,9 +11,10 @@
#include "types/wlr_buffer.h"
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);
alloc->impl = impl;
+ alloc->buffer_caps = buffer_caps;
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,
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;
}
diff --git a/render/drm_dumb_allocator.c b/render/drm_dumb_allocator.c
index c0605593..9e14e38e 100644
--- a/render/drm_dumb_allocator.c
+++ b/render/drm_dumb_allocator.c
@@ -15,6 +15,7 @@
#include "render/drm_dumb_allocator.h"
#include "render/pixel_format.h"
+#include "types/wlr_buffer.h"
static const struct wlr_buffer_impl buffer_impl;
@@ -127,7 +128,7 @@ create_err:
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) {
struct wlr_drm_dumb_buffer *buf = drm_dumb_buffer_from_buffer(wlr_buffer);
*data = buf->data;
@@ -152,7 +153,7 @@ static void buffer_destroy(struct wlr_buffer *wlr_buffer) {
static const struct wlr_buffer_impl buffer_impl = {
.destroy = buffer_destroy,
.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;
@@ -231,7 +232,8 @@ struct wlr_allocator *wlr_drm_dumb_allocator_create(int fd) {
free(path);
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;
wl_list_init(&alloc->buffers);
diff --git a/render/gbm_allocator.c b/render/gbm_allocator.c
index cbdd2640..8dd7b49c 100644
--- a/render/gbm_allocator.c
+++ b/render/gbm_allocator.c
@@ -7,6 +7,7 @@
#include <wlr/util/log.h>
#include <xf86drm.h>
#include "render/gbm_allocator.h"
+#include "types/wlr_buffer.h"
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) {
return NULL;
}
- wlr_allocator_init(&alloc->base, &allocator_impl);
+ wlr_allocator_init(&alloc->base, &allocator_impl, WLR_BUFFER_CAP_DMABUF);
alloc->fd = fd;
wl_list_init(&alloc->buffers);
diff --git a/render/shm_allocator.c b/render/shm_allocator.c
index 16d0e5c9..e1a3d9e5 100644
--- a/render/shm_allocator.c
+++ b/render/shm_allocator.c
@@ -7,6 +7,7 @@
#include "render/pixel_format.h"
#include "render/shm_allocator.h"
#include "util/shm.h"
+#include "types/wlr_buffer.h"
static const struct wlr_buffer_impl buffer_impl;
@@ -30,7 +31,7 @@ static bool buffer_get_shm(struct wlr_buffer *wlr_buffer,
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) {
struct wlr_shm_buffer *buffer = shm_buffer_from_buffer(wlr_buffer);
*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 = {
.destroy = buffer_destroy,
.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(
@@ -103,7 +104,8 @@ struct wlr_allocator *wlr_shm_allocator_create(void) {
if (allocator == 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");
return &allocator->base;