summaryrefslogtreecommitdiff
path: root/src/platform/x11
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 17:12:10 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 17:12:10 +0300
commitb7944e4bbfa64a6bb1a1d9e1f172827dde53aed2 (patch)
treed73ff8e368039f67f824ad2dc9130643ef4947ae /src/platform/x11
parentac6f9f5e7711521455b83ceb843a25e091646d43 (diff)
Read back the last presented CPU frame
wsap_term writes PNG screenshots for its debug server and keeps its own copy of the frame because YASL had no readback. yasl_surface_read_pixels() copies the frame from the last successful present, or reports its extent when the buffer is too small. X11 and Cocoa keep it in their single CPU target until the next draw starts; X11 now also forgets it when a resize replaces the target, and Cocoa records the presented extent because a resize can change the size before the next draw. Wayland remembers which buffer it committed and forgets it when a draw reuses that buffer. The backend test checks the copy on Wayland and X11, and that draws that never present do not show through. The Cocoa path is not built or run here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'src/platform/x11')
-rw-r--r--src/platform/x11/window.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/platform/x11/window.c b/src/platform/x11/window.c
index 724987f..765d83c 100644
--- a/src/platform/x11/window.c
+++ b/src/platform/x11/window.c
@@ -473,6 +473,8 @@ static bool resize(struct x11_surface *s, struct yasl_vector2i size)
return true;
}
uint64_t start = yasl_loop_now_ns();
+ /* The presented frame goes with the old pixels. */
+ s->presented = false;
if (s->shm_active) {
XShmDetach(d->native, &s->shm_info);
@@ -1883,6 +1885,15 @@ static int double_click_ms(const struct yasl_display *base)
return portal_double_click_ms();
}
+static bool read_pixels(struct yasl_surface *base, uint32_t *out, size_t cap,
+ struct yasl_vector2i *size)
+{
+ struct x11_surface *s = (struct x11_surface *)base;
+ /* presented stays set from the last draw until the next one starts. */
+ if (s->destroyed || s->drawing || !s->presented || !s->pixels) return false;
+ return yasl_copy_frame(s->pixels, s->size, out, cap, size);
+}
+
static bool bell(struct yasl_surface *base)
{
struct x11_surface *s = (struct x11_surface *)base;
@@ -2138,6 +2149,7 @@ const struct yasl_backend_ops yasl_x11_backend = {
.surface_drag_carry = drag_carry,
.surface_place_under_pointer = place,
.surface_bell = bell,
+ .surface_read_pixels = read_pixels,
.display_double_click_ms = double_click_ms,
.surface_start_interactive_move = interactive_move,
.surface_start_interactive_resize = interactive_resize,