scaled-scene-buffer: reduce unnecessary renderings

Prior to this commit, a backing buffer with scale 1 was always created for
a scaled_scene_buffer before showing it, and backing buffers for specific
scales were created on output_enter events.

This commit removes this redundant re-renderings by calling
wlr_scene_buffer_set_dest_size() upon scaled_scene_buffer creation just to
receive output_enter events and delaying the first rendering to the first
output_enter event.

I needed to add font_get_buffer_size() to obtain the size of a font buffer
without actually creating it.
This commit is contained in:
tokyo4j 2024-12-03 16:18:52 +09:00
parent 40c7350064
commit 4c4fe6a785
6 changed files with 69 additions and 23 deletions

View file

@ -116,21 +116,20 @@ scaled_font_buffer_update(struct scaled_font_buffer *self, const char *text,
memcpy(self->color, color, sizeof(self->color));
memcpy(self->bg_color, bg_color, sizeof(self->bg_color));
/* Invalidate cache and force a new render */
scaled_scene_buffer_invalidate_cache(self->scaled_buffer);
/* Ensure the height / width is up-to-date */
self->width = self->scaled_buffer->width;
self->height = self->scaled_buffer->height;
/* Calculate the size of font buffer and request re-rendering */
font_get_buffer_size(self->max_width, self->text, &self->font,
&self->width, &self->height);
scaled_scene_buffer_request_update(self->scaled_buffer,
self->width, self->height);
}
void
scaled_font_buffer_set_max_width(struct scaled_font_buffer *self, int max_width)
{
self->max_width = max_width;
scaled_scene_buffer_invalidate_cache(self->scaled_buffer);
/* Ensure the height / width is up-to-date */
self->width = self->scaled_buffer->width;
self->height = self->scaled_buffer->height;
font_get_buffer_size(self->max_width, self->text, &self->font,
&self->width, &self->height);
scaled_scene_buffer_request_update(self->scaled_buffer,
self->width, self->height);
}