mirror of
https://github.com/labwc/labwc.git
synced 2026-02-27 01:40:30 -05:00
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:
parent
cc838e79ed
commit
5db953aa89
6 changed files with 69 additions and 23 deletions
|
|
@ -79,6 +79,18 @@ font_width(struct font *font, const char *string)
|
|||
return rectangle.width;
|
||||
}
|
||||
|
||||
void
|
||||
font_get_buffer_size(int max_width, const char *text, struct font *font,
|
||||
int *width, int *height)
|
||||
{
|
||||
PangoRectangle text_extents = font_extents(font, text);
|
||||
if (max_width > 0 && text_extents.width > max_width) {
|
||||
text_extents.width = max_width;
|
||||
}
|
||||
*width = text_extents.width;
|
||||
*height = text_extents.height;
|
||||
}
|
||||
|
||||
void
|
||||
font_buffer_create(struct lab_data_buffer **buffer, int max_width,
|
||||
const char *text, struct font *font, const float *color,
|
||||
|
|
@ -88,13 +100,10 @@ font_buffer_create(struct lab_data_buffer **buffer, int max_width,
|
|||
return;
|
||||
}
|
||||
|
||||
PangoRectangle text_extents = font_extents(font, text);
|
||||
int width, height;
|
||||
font_get_buffer_size(max_width, text, font, &width, &height);
|
||||
|
||||
if (max_width > 0 && text_extents.width > max_width) {
|
||||
text_extents.width = max_width;
|
||||
}
|
||||
|
||||
*buffer = buffer_create_cairo(text_extents.width, text_extents.height, scale);
|
||||
*buffer = buffer_create_cairo(width, height, scale);
|
||||
if (!*buffer) {
|
||||
wlr_log(WLR_ERROR, "Failed to create font buffer");
|
||||
return;
|
||||
|
|
@ -127,7 +136,7 @@ font_buffer_create(struct lab_data_buffer **buffer, int max_width,
|
|||
|
||||
PangoLayout *layout = pango_cairo_create_layout(cairo);
|
||||
pango_context_set_round_glyph_positions(pango_layout_get_context(layout), false);
|
||||
pango_layout_set_width(layout, text_extents.width * PANGO_SCALE);
|
||||
pango_layout_set_width(layout, width * PANGO_SCALE);
|
||||
pango_layout_set_text(layout, text, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue