mirror of
https://github.com/labwc/labwc.git
synced 2025-11-06 13:29:58 -05:00
scaled-font-buffer: apply buffer sharing mechanism
scaled_font_buffer.{width,height} are no longer set in _create_buffer()
since that function is not called when the buffer is reused from the
cache.
This commit is contained in:
parent
c893878aca
commit
c2928027be
1 changed files with 38 additions and 4 deletions
|
|
@ -7,10 +7,14 @@
|
|||
#include <wlr/util/log.h>
|
||||
#include "buffer.h"
|
||||
#include "common/font.h"
|
||||
#include "common/list.h"
|
||||
#include "common/mem.h"
|
||||
#include "common/scaled-scene-buffer.h"
|
||||
#include "common/scaled-font-buffer.h"
|
||||
|
||||
/* This holds all the scaled-font-buffers and used for sharing backing buffers */
|
||||
static struct wl_list cached_buffers = WL_LIST_INIT(&cached_buffers);
|
||||
|
||||
static struct lab_data_buffer *
|
||||
_create_buffer(struct scaled_scene_buffer *scaled_buffer, double scale)
|
||||
{
|
||||
|
|
@ -25,8 +29,6 @@ _create_buffer(struct scaled_scene_buffer *scaled_buffer, double scale)
|
|||
wlr_log(WLR_ERROR, "font_buffer_create() failed");
|
||||
}
|
||||
|
||||
self->width = buffer ? buffer->logical_width : 0;
|
||||
self->height = buffer ? buffer->logical_height : 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
@ -42,9 +44,33 @@ _destroy(struct scaled_scene_buffer *scaled_buffer)
|
|||
free(self);
|
||||
}
|
||||
|
||||
static bool str_equal(const char *a, const char *b)
|
||||
{
|
||||
return a == b || (a && b && !strcmp(a, b));
|
||||
}
|
||||
|
||||
static bool
|
||||
_equal(struct scaled_scene_buffer *scaled_buffer_a,
|
||||
struct scaled_scene_buffer *scaled_buffer_b)
|
||||
{
|
||||
struct scaled_font_buffer *a = scaled_buffer_a->data;
|
||||
struct scaled_font_buffer *b = scaled_buffer_b->data;
|
||||
|
||||
return str_equal(a->text, b->text)
|
||||
&& a->max_width == b->max_width
|
||||
&& str_equal(a->font.name, b->font.name)
|
||||
&& a->font.size == b->font.size
|
||||
&& a->font.slant == b->font.slant
|
||||
&& a->font.weight == b->font.weight
|
||||
&& !memcmp(a->color, b->color, sizeof(a->color))
|
||||
&& !memcmp(a->bg_color, b->bg_color, sizeof(a->bg_color))
|
||||
&& str_equal(a->arrow, b->arrow);
|
||||
}
|
||||
|
||||
static const struct scaled_scene_buffer_impl impl = {
|
||||
.create_buffer = _create_buffer,
|
||||
.destroy = _destroy
|
||||
.destroy = _destroy,
|
||||
.equal = _equal,
|
||||
};
|
||||
|
||||
/* Public API */
|
||||
|
|
@ -54,7 +80,7 @@ scaled_font_buffer_create(struct wlr_scene_tree *parent)
|
|||
assert(parent);
|
||||
struct scaled_font_buffer *self = znew(*self);
|
||||
struct scaled_scene_buffer *scaled_buffer = scaled_scene_buffer_create(
|
||||
parent, &impl, NULL, /* drop_buffer */ true);
|
||||
parent, &impl, &cached_buffers, /* drop_buffer */ true);
|
||||
if (!scaled_buffer) {
|
||||
free(self);
|
||||
return NULL;
|
||||
|
|
@ -96,6 +122,10 @@ scaled_font_buffer_update(struct scaled_font_buffer *self, const char *text,
|
|||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -103,4 +133,8 @@ 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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue