From 388218a3f9bc500ac081a76514035f2d237da6a1 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 25 Sep 2024 18:09:57 +0200 Subject: [PATCH] os/surface.h: support windowed surface access This patch eases the vertical organization of multiple surfaces within one larger surface, which is the case when keeping front/back buffers within one compounding GUI buffer. Issue #5351 --- repos/os/include/os/surface.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/repos/os/include/os/surface.h b/repos/os/include/os/surface.h index f61befa53b..9f31250b92 100644 --- a/repos/os/include/os/surface.h +++ b/repos/os/include/os/surface.h @@ -22,6 +22,8 @@ namespace Genode { class Surface_base; template class Surface; + + struct Surface_window { unsigned y, h; }; } @@ -133,6 +135,23 @@ class Genode::Surface : public Surface_base */ Surface(PT *addr, Area size) : Surface_base(size, PT::format()), _addr(addr) { } + + /** + * Call 'fn' with a sub-window surface as argument + * + * This method is useful for managing multiple surfaces within one + * larger surface, for example for organizing a back buffer and a front + * buffer within one virtual framebuffer. + */ + void with_window(Surface_window const win, auto const &fn) const + { + /* clip window coordinates against surface boundaries */ + Rect const rect = Rect::intersect({ { 0, 0 }, { 1, size().h } }, + { { 0, int(win.y) }, { 1, win.h } }); + + Surface surface { _addr + rect.y1()*size().w, { size().w, rect.h() } }; + fn(surface); + } }; #endif /* _INCLUDE__OS__SURFACE_H_ */