aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wlr/types/wlr_buffer.h14
-rw-r--r--types/wlr_buffer.c22
2 files changed, 36 insertions, 0 deletions
diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h
index edf53144..5dc8271d 100644
--- a/include/wlr/types/wlr_buffer.h
+++ b/include/wlr/types/wlr_buffer.h
@@ -69,6 +69,12 @@ struct wlr_buffer {
} events;
};
+struct wlr_buffer_resource_interface {
+ const char *name;
+ bool (*is_instance)(struct wl_resource *resource);
+ struct wlr_buffer *(*from_resource)(struct wl_resource *resource);
+};
+
/**
* Initialize a buffer. This function should be called by producers. The
* initialized buffer is referenced: once the producer is done with the buffer
@@ -113,6 +119,14 @@ bool wlr_buffer_get_dmabuf(struct wlr_buffer *buffer,
bool wlr_buffer_get_shm(struct wlr_buffer *buffer,
struct wlr_shm_attributes *attribs);
/**
+ * Allows the registration of a wl_resource implementation.
+ *
+ * The matching function will be called for the wl_resource when creating a
+ * wlr_buffer from a wl_resource.
+ */
+void wlr_buffer_register_resource_interface(
+ const struct wlr_buffer_resource_interface *iface);
+/**
* Transforms a wl_resource into a wlr_buffer and locks it. Once the caller is
* done with the buffer, they must call wlr_buffer_unlock.
*
diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c
index c7f78fd7..dca4c81a 100644
--- a/types/wlr_buffer.c
+++ b/types/wlr_buffer.c
@@ -159,6 +159,28 @@ static bool buffer_is_shm_client_buffer(struct wlr_buffer *buffer);
static struct wlr_shm_client_buffer *shm_client_buffer_from_buffer(
struct wlr_buffer *buffer);
+/* struct wlr_buffer_resource_interface */
+static struct wl_array buffer_resource_interfaces = {0};
+
+void wlr_buffer_register_resource_interface(
+ const struct wlr_buffer_resource_interface *iface) {
+ assert(iface);
+ assert(iface->is_instance);
+ assert(iface->from_resource);
+
+ const struct wlr_buffer_resource_interface **iface_ptr;
+ wl_array_for_each(iface_ptr, &buffer_resource_interfaces) {
+ if (*iface_ptr == iface) {
+ wlr_log(WLR_DEBUG, "wlr_resource_buffer_interface %s has already"
+ "been registered", iface->name);
+ return;
+ }
+ }
+
+ iface_ptr = wl_array_add(&buffer_resource_interfaces, sizeof(iface));
+ *iface_ptr = iface;
+}
+
struct wlr_buffer *wlr_buffer_from_resource(struct wl_resource *resource) {
assert(resource && wlr_resource_is_buffer(resource));