mirror of
https://github.com/labwc/labwc.git
synced 2025-11-06 13:29:58 -05:00
buffer: reduce unnecessary painting to new cairo surfaces
Add buffer_adopt_cairo_surface(), which allows wrapping an existing cairo image surface in a struct lab_data_buffer. This is useful when loading PNGs since most will be loaded as ARGB32 already. Fix a memory leak in the non-ARGB32 PNG case, where we do still need to paint to a new image surface -- we were leaking the original surface. Eliminate an unnecessary temporary image surface in SVG loading and just render the SVG to the image surface held by the lab_data_buffer. I also cleaned up and clarified the buffer API a bit: - Add a pointer to the held cairo_surface_t (so we can still access it if there is no cairo_t). - Remove the free_on_destroy bool (it was always true). - Rename unscaled_width/height to logical_width/height and add an explanatory comment. It was unclear what "unscaled" meant. - Rename buffer_create_wrap() to buffer_create_from_data(). This is laying groundwork for some more icon fixes I am working on (making sure icons are loaded and rendered at the correct scale).
This commit is contained in:
parent
328f873db3
commit
d2b161bdf8
14 changed files with 123 additions and 84 deletions
|
|
@ -109,7 +109,7 @@ font_buffer_create(struct lab_data_buffer **buffer, int max_width,
|
|||
}
|
||||
|
||||
*buffer = buffer_create_cairo(text_extents.width + arrow_extents.width,
|
||||
text_extents.height, scale, true);
|
||||
text_extents.height, scale);
|
||||
if (!*buffer) {
|
||||
wlr_log(WLR_ERROR, "Failed to create font buffer");
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -125,8 +125,8 @@ get_cairo_surface_from_lab_data_buffer(struct lab_data_buffer *buffer)
|
|||
}
|
||||
|
||||
/* Handle DRM_FORMAT_ARGB8888 buffers */
|
||||
int w = buffer->unscaled_width;
|
||||
int h = buffer->unscaled_height;
|
||||
int w = buffer->logical_width;
|
||||
int h = buffer->logical_height;
|
||||
cairo_surface_t *surface =
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
|
||||
if (!surface) {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ _create_buffer(struct scaled_scene_buffer *scaled_buffer, double scale)
|
|||
wlr_log(WLR_ERROR, "font_buffer_create() failed");
|
||||
}
|
||||
|
||||
self->width = buffer ? buffer->unscaled_width : 0;
|
||||
self->height = buffer ? buffer->unscaled_height : 0;
|
||||
self->width = buffer ? buffer->logical_width : 0;
|
||||
self->height = buffer ? buffer->logical_height : 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,8 +72,8 @@ _update_buffer(struct scaled_scene_buffer *self, double scale)
|
|||
/* Ensure the buffer doesn't get deleted behind our back */
|
||||
wlr_buffer_lock(&buffer->base);
|
||||
}
|
||||
self->width = buffer ? buffer->unscaled_width : 0;
|
||||
self->height = buffer ? buffer->unscaled_height : 0;
|
||||
self->width = buffer ? buffer->logical_width : 0;
|
||||
self->height = buffer ? buffer->logical_height : 0;
|
||||
|
||||
/* Create or reuse cache entry */
|
||||
if (wl_list_length(&self->cache) < LAB_SCALED_BUFFER_MAX_CACHE) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue