aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2021-02-09 21:07:10 +0100
committerSimon Ser <contact@emersion.fr>2021-04-17 09:54:39 +0200
commit6c61de996c14047c5f82ee9f29ddb90b341c160a (patch)
tree999572b4abdaeeb5dfd76a5da37ad6383e870a42
parent0b9288ec0b8885ba0a76e54fc8949c563d39cabd (diff)
buffer: introduce wlr_buffer_get_shm
References: https://github.com/swaywm/wlroots/issues/2399#issuecomment-769408708
-rw-r--r--include/wlr/types/wlr_buffer.h19
-rw-r--r--types/wlr_buffer.c8
2 files changed, 27 insertions, 0 deletions
diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h
index 59996fce..ca94e93c 100644
--- a/include/wlr/types/wlr_buffer.h
+++ b/include/wlr/types/wlr_buffer.h
@@ -15,12 +15,21 @@
struct wlr_buffer;
+struct wlr_shm_attributes {
+ int fd;
+ uint32_t format;
+ int width, height, stride;
+ off_t offset;
+};
+
struct wlr_buffer_impl {
void (*destroy)(struct wlr_buffer *buffer);
bool (*get_dmabuf)(struct wlr_buffer *buffer,
struct wlr_dmabuf_attributes *attribs);
bool (*get_data_ptr)(struct wlr_buffer *buffer, void **data,
size_t *stride);
+ bool (*get_shm)(struct wlr_buffer *buffer,
+ struct wlr_shm_attributes *attribs);
};
/**
@@ -78,6 +87,16 @@ void wlr_buffer_unlock(struct wlr_buffer *buffer);
*/
bool wlr_buffer_get_dmabuf(struct wlr_buffer *buffer,
struct wlr_dmabuf_attributes *attribs);
+/**
+ * Read shared memory attributes of the buffer. If this buffer isn't shared
+ * memory, returns false.
+ *
+ * The returned shared memory attributes are valid for the lifetime of the
+ * wlr_buffer. The caller isn't responsible for cleaning up the shared memory
+ * attributes.
+ */
+bool wlr_buffer_get_shm(struct wlr_buffer *buffer,
+ struct wlr_shm_attributes *attribs);
/**
* A client buffer.
diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c
index cc20af59..73d770d0 100644
--- a/types/wlr_buffer.c
+++ b/types/wlr_buffer.c
@@ -74,6 +74,14 @@ bool buffer_get_data_ptr(struct wlr_buffer *buffer, void **data,
return buffer->impl->get_data_ptr(buffer, data, size);
}
+bool wlr_buffer_get_shm(struct wlr_buffer *buffer,
+ struct wlr_shm_attributes *attribs) {
+ if (!buffer->impl->get_shm) {
+ return false;
+ }
+ return buffer->impl->get_shm(buffer, attribs);
+}
+
bool wlr_resource_is_buffer(struct wl_resource *resource) {
return strcmp(wl_resource_get_class(resource), wl_buffer_interface.name) == 0;
}