shared/cairo-util: Re-use the PangoContext for layout creation
Rather than creating a new PangoContext each time the menu redraw handler is triggered re-use it if one was created previously. All toytoolkit clients do create a layout (and implicitly a PangoContext) but only those that have menu redraw handler installed will create a new layout for each redraw of the menu, effectively creating a new PangoContext each time. Reported-by: Pekka Paalanen <pekka.paalanen@collabora.com> Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
This commit is contained in:
parent
60b307e3ce
commit
cfe35b591f
@ -480,6 +480,10 @@ theme_create(void)
|
||||
void
|
||||
theme_destroy(struct theme *t)
|
||||
{
|
||||
#ifdef HAVE_PANGO
|
||||
if (t->pango_context)
|
||||
g_object_unref(t->pango_context);
|
||||
#endif
|
||||
cairo_surface_destroy(t->active_frame);
|
||||
cairo_surface_destroy(t->inactive_frame);
|
||||
cairo_surface_destroy(t->shadow);
|
||||
@ -488,21 +492,21 @@ theme_destroy(struct theme *t)
|
||||
|
||||
#ifdef HAVE_PANGO
|
||||
static PangoLayout *
|
||||
create_layout(cairo_t *cr, const char *title)
|
||||
create_layout(struct theme *t, cairo_t *cr, const char *title)
|
||||
{
|
||||
PangoFontMap *fontmap;
|
||||
PangoContext *context;
|
||||
PangoLayout *layout;
|
||||
PangoFontDescription *desc;
|
||||
|
||||
fontmap = pango_cairo_font_map_new();
|
||||
context = pango_font_map_create_context(fontmap);
|
||||
g_object_unref(fontmap);
|
||||
pango_cairo_font_map_set_default(NULL);
|
||||
pango_cairo_update_context(cr, context);
|
||||
layout = pango_layout_new(context);
|
||||
g_object_unref(context);
|
||||
if (!t->pango_context) {
|
||||
PangoFontMap *fontmap;
|
||||
|
||||
fontmap = pango_cairo_font_map_new();
|
||||
t->pango_context = pango_font_map_create_context(fontmap);
|
||||
g_object_unref(fontmap);
|
||||
}
|
||||
|
||||
pango_cairo_update_context(cr, t->pango_context);
|
||||
layout = pango_layout_new(t->pango_context);
|
||||
if (title) {
|
||||
pango_layout_set_text(layout, title, -1);
|
||||
desc = pango_font_description_from_string("sans-serif Bold 10");
|
||||
@ -577,7 +581,7 @@ theme_render_frame(struct theme *t,
|
||||
PangoLayout *title_layout;
|
||||
PangoRectangle logical;
|
||||
|
||||
title_layout = create_layout(cr, title);
|
||||
title_layout = create_layout(t, cr, title);
|
||||
|
||||
pango_layout_get_pixel_extents (title_layout, NULL, &logical);
|
||||
text_width = MIN(title_rect->width, logical.width);
|
||||
|
@ -28,6 +28,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cairo.h>
|
||||
#ifdef HAVE_PANGO
|
||||
#include <pango/pangocairo.h>
|
||||
#endif
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-util.h>
|
||||
@ -57,6 +60,9 @@ struct theme {
|
||||
int margin;
|
||||
int width;
|
||||
int titlebar_height;
|
||||
#ifdef HAVE_PANGO
|
||||
PangoContext *pango_context;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct theme *
|
||||
|
@ -26,7 +26,7 @@ dep_names_xwayland = [
|
||||
'cairo-xcb',
|
||||
]
|
||||
|
||||
deps_xwayland = [ dep_libweston_public, dep_xcb_xwayland ]
|
||||
deps_xwayland = [ dep_libweston_public, dep_xcb_xwayland, dep_lib_cairo_shared ]
|
||||
|
||||
foreach name : dep_names_xwayland
|
||||
d = dependency(name, required: false)
|
||||
@ -39,7 +39,6 @@ endforeach
|
||||
plugin_xwayland = shared_library(
|
||||
'xwayland',
|
||||
srcs_xwayland,
|
||||
link_with: lib_cairo_shared,
|
||||
include_directories: common_inc,
|
||||
dependencies: deps_xwayland,
|
||||
name_prefix: '',
|
||||
|
Loading…
Reference in New Issue
Block a user