aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-06-16 13:43:14 -0700
committerGitHub <noreply@github.com>2018-06-16 13:43:14 -0700
commitfb118ac9966bbb663ddb9964f54c879a0bb88fba (patch)
treedade760bc2597c17f82ba7df48ffdb2f6c7726f8 /include
parentac0f9acb063262f00a949e9d43aa51c84cf1ea97 (diff)
parent225aa815b00502c2d91897c1ac2c4c5c65f82ca5 (diff)
Merge pull request #1062 from emersion/wlr-buffer-comeback
Add back wlr_buffer
Diffstat (limited to 'include')
-rw-r--r--include/wlr/types/wlr_buffer.h63
-rw-r--r--include/wlr/types/wlr_surface.h15
2 files changed, 77 insertions, 1 deletions
diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h
new file mode 100644
index 00000000..eabc8b51
--- /dev/null
+++ b/include/wlr/types/wlr_buffer.h
@@ -0,0 +1,63 @@
+#ifndef WLR_TYPES_WLR_BUFFER_H
+#define WLR_TYPES_WLR_BUFFER_H
+
+#include <pixman.h>
+#include <wayland-server.h>
+
+/**
+ * A client buffer.
+ */
+struct wlr_buffer {
+ /**
+ * The buffer resource, if any. Will be NULL if the client destroys it.
+ */
+ struct wl_resource *resource;
+ /**
+ * The buffer's texture, if any. A buffer will not have a texture if the
+ * client destroys the buffer before it has been released.
+ */
+ struct wlr_texture *texture;
+ bool released;
+ size_t n_refs;
+
+ struct wl_listener resource_destroy;
+};
+
+struct wlr_renderer;
+
+/**
+ * Check if a resource is a wl_buffer resource.
+ */
+bool wlr_resource_is_buffer(struct wl_resource *resource);
+/**
+ * Get the size of a wl_buffer resource.
+ */
+bool wlr_buffer_get_resource_size(struct wl_resource *resource,
+ struct wlr_renderer *renderer, int *width, int *height);
+
+/**
+ * Upload a buffer to the GPU and reference it.
+ */
+struct wlr_buffer *wlr_buffer_create(struct wlr_renderer *renderer,
+ struct wl_resource *resource);
+/**
+ * Reference the buffer.
+ */
+struct wlr_buffer *wlr_buffer_ref(struct wlr_buffer *buffer);
+/**
+ * Unreference the buffer. After this call, `buffer` may not be accessed
+ * anymore.
+ */
+void wlr_buffer_unref(struct wlr_buffer *buffer);
+/**
+ * Try to update the buffer's content. On success, returns the updated buffer
+ * and destroys the provided `buffer`. On error, `buffer` is intact and NULL is
+ * returned.
+ *
+ * Fails if there's more than one reference to the buffer or if the texture
+ * isn't mutable.
+ */
+struct wlr_buffer *wlr_buffer_apply_damage(struct wlr_buffer *buffer,
+ struct wl_resource *resource, pixman_region32_t *damage);
+
+#endif
diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h
index 526e4e2c..8517934a 100644
--- a/include/wlr/types/wlr_surface.h
+++ b/include/wlr/types/wlr_surface.h
@@ -69,7 +69,13 @@ struct wlr_subsurface {
struct wlr_surface {
struct wl_resource *resource;
struct wlr_renderer *renderer;
- struct wlr_texture *texture;
+ /**
+ * The surface's buffer, if any. A surface has an attached buffer when it
+ * commits with a non-null buffer in its pending state. A surface will not
+ * have a buffer if it has never committed one, has committed a null buffer,
+ * or something went wrong with uploading the buffer.
+ */
+ struct wlr_buffer *buffer;
struct wlr_surface_state *current, *pending;
const char *role; // the lifetime-bound role or null
@@ -125,6 +131,13 @@ int wlr_surface_set_role(struct wlr_surface *surface, const char *role,
bool wlr_surface_has_buffer(struct wlr_surface *surface);
/**
+ * Get the texture of the buffer currently attached to this surface. Returns
+ * NULL if no buffer is currently attached or if something went wrong with
+ * uploading the buffer.
+ */
+struct wlr_texture *wlr_surface_get_texture(struct wlr_surface *surface);
+
+/**
* Create a new subsurface resource with the provided new ID. If `resource_list`
* is non-NULL, adds the subsurface's resource to the list.
*/