scene: Optimize rendering of single-pixel buffers

The single-pixel buffer protocol is used to allow wayland clients to
easily draw solid-color rectangles by presenting a 1x1-pixel buffer and
scaling it to the desired size.  This patch improves how these buffers
are then handled in the scene-tree renderer.

We already ignore opaque black rectangles at the very bottom (and
anything under them) because we assume we'll be rendering on a black
background.  This patch detects black opaque single-pixel buffers and
handles them in the same way as black opaque rectangles.  It also
renders single-pixel buffers as rectangles rather than buffers because
this is probably more efficient in the underlying renderer.

In wlr_scene_surface we cache whether the attached buffer is a
single-pixel buffer.  This is done because the
wlr_single_pixel_buffer_v1 will be destroyed after texture upload, after
which it becomes much more annoying to check if the buffer is a
single-pixel buffer.
This commit is contained in:
David Turner 2025-04-07 13:28:51 +01:00
parent 5563d23b81
commit 792bee9657
3 changed files with 65 additions and 0 deletions

View file

@ -132,6 +132,12 @@ struct wlr_scene_surface {
struct wl_listener frame_done;
struct wl_listener surface_destroy;
struct wl_listener surface_commit;
// True if the underlying buffer is a wlr_single_pixel_buffer_v1
bool is_single_pixel_buffer;
// If is_single_pixel_buffer is set, contains the color of the buffer
// as {R, G, B, A} where the max value of each component is UINT32_MAX
uint32_t single_pixel_buffer_color[4];
} WLR_PRIVATE;
};