aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-12-12 11:36:11 +0100
committerSimon Ser <contact@emersion.fr>2023-12-25 11:47:15 +0100
commit34d5af41727c1879188caf3a00fc1db9f480b1fd (patch)
tree3a702960a605d5a2caa584bd3d2a6369d56993fe
parent43734f7c6286ede7fbfe9a20e6b95fe7207dcc50 (diff)
compositor: add wlr_surface_state_has_buffer()
-rw-r--r--include/wlr/types/wlr_compositor.h13
-rw-r--r--types/wlr_compositor.c6
2 files changed, 18 insertions, 1 deletions
diff --git a/include/wlr/types/wlr_compositor.h b/include/wlr/types/wlr_compositor.h
index 95128ea7..eb870b7b 100644
--- a/include/wlr/types/wlr_compositor.h
+++ b/include/wlr/types/wlr_compositor.h
@@ -284,6 +284,19 @@ void wlr_surface_unmap(struct wlr_surface *surface);
bool wlr_surface_has_buffer(struct wlr_surface *surface);
/**
+ * Check whether this surface state has an attached buffer.
+ *
+ * A surface has an attached buffer when the client commits with a non-null
+ * buffer. A surface will not have a buffer if the client never committed one,
+ * or committed a null buffer.
+ *
+ * Note that wlr_surface_state.buffer may be NULL even if this function returns
+ * true: the buffer field is reset after commit, to allow the buffer to be
+ * released to the client. Additionally, the buffer import or upload may fail.
+ */
+bool wlr_surface_state_has_buffer(const struct wlr_surface_state *state);
+
+/**
* 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.
diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c
index bbae8129..91996037 100644
--- a/types/wlr_compositor.c
+++ b/types/wlr_compositor.c
@@ -720,7 +720,11 @@ struct wlr_texture *wlr_surface_get_texture(struct wlr_surface *surface) {
}
bool wlr_surface_has_buffer(struct wlr_surface *surface) {
- return surface->current.buffer_width > 0 && surface->current.buffer_height > 0;
+ return wlr_surface_state_has_buffer(&surface->current);
+}
+
+bool wlr_surface_state_has_buffer(const struct wlr_surface_state *state) {
+ return state->buffer_width > 0 && state->buffer_height > 0;
}
void wlr_surface_map(struct wlr_surface *surface) {