clutter/backend: Stop re-allocating font_options

There is no real need to re-create a new cairo_font_options_t now that
the API is internal. Instead, create the font_options once and just
update it attributes.

Actors already register for the emitted font-changed signal to re-create
a new PangoContext.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4106>
This commit is contained in:
Bilal Elmoussaoui 2024-10-24 09:34:40 +02:00 committed by Marge Bot
parent 17e7f9be51
commit c5ea9562e1
3 changed files with 11 additions and 58 deletions

View File

@ -100,7 +100,4 @@ gboolean clutter_backend_is_display_server (ClutterBackend *backend);
CLUTTER_EXPORT CLUTTER_EXPORT
void clutter_backend_destroy (ClutterBackend *backend); void clutter_backend_destroy (ClutterBackend *backend);
void clutter_backend_set_font_options (ClutterBackend *backend,
const cairo_font_options_t *options);
G_END_DECLS G_END_DECLS

View File

@ -280,6 +280,13 @@ clutter_backend_init (ClutterBackend *self)
self->dummy_onscreen = NULL; self->dummy_onscreen = NULL;
self->fallback_resource_scale = 1.f; self->fallback_resource_scale = 1.f;
/* Default font options */
self->font_options = cairo_font_options_create ();
cairo_font_options_set_hint_metrics (self->font_options, CAIRO_HINT_METRICS_ON);
cairo_font_options_set_hint_style (self->font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_subpixel_order (self->font_options, CAIRO_SUBPIXEL_ORDER_DEFAULT);
cairo_font_options_set_antialias (self->font_options, CAIRO_ANTIALIAS_DEFAULT);
} }
ClutterStageWindow * ClutterStageWindow *
@ -377,41 +384,6 @@ clutter_backend_get_resolution (ClutterBackend *backend)
return resolution / 1024.0; return resolution / 1024.0;
} }
/**
* clutter_backend_set_font_options:
* @backend: a #ClutterBackend
* @options: Cairo font options for the backend, or %NULL
*
* Sets the new font options for @backend. The #ClutterBackend will
* copy the #cairo_font_options_t.
*
* If @options is %NULL, the first following call to
* [method@Clutter.Backend.get_font_options] will return the default font
* options for @backend.
*
* This function is intended for actors creating a Pango layout
* using the PangoCairo API.
*/
void
clutter_backend_set_font_options (ClutterBackend *backend,
const cairo_font_options_t *options)
{
g_return_if_fail (CLUTTER_IS_BACKEND (backend));
if (backend->font_options != options)
{
if (backend->font_options)
cairo_font_options_destroy (backend->font_options);
if (options)
backend->font_options = cairo_font_options_copy (options);
else
backend->font_options = NULL;
g_signal_emit (backend, backend_signals[FONT_CHANGED], 0);
}
}
/** /**
* clutter_backend_get_cogl_context: * clutter_backend_get_cogl_context:
* @backend: a #ClutterBackend * @backend: a #ClutterBackend

View File

@ -120,15 +120,11 @@ clutter_settings_update_font_options (ClutterSettings *self)
cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE; cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY; cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
cairo_font_options_t *options;
const char *clutter_font_hint_style = NULL, *clutter_font_subpixel_order = NULL; const char *clutter_font_hint_style = NULL, *clutter_font_subpixel_order = NULL;
if (self->backend == NULL) if (self->backend == NULL)
return; return;
options = cairo_font_options_create ();
cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
/* org.gnome.desktop.GDesktopFontAntialiasingMode */ /* org.gnome.desktop.GDesktopFontAntialiasingMode */
static const struct static const struct
{ {
@ -178,7 +174,7 @@ clutter_settings_update_font_options (ClutterSettings *self)
hint_style = hintings[i].cairo_hint_style; hint_style = hintings[i].cairo_hint_style;
clutter_font_hint_style = hintings[i].clutter_font_hint_style; clutter_font_hint_style = hintings[i].clutter_font_hint_style;
} }
cairo_font_options_set_hint_style (options, hint_style); cairo_font_options_set_hint_style (self->backend->font_options, hint_style);
i = g_settings_get_enum (settings, "font-rgba-order"); i = g_settings_get_enum (settings, "font-rgba-order");
if (i < G_N_ELEMENTS (rgba_orders)) if (i < G_N_ELEMENTS (rgba_orders))
@ -186,7 +182,7 @@ clutter_settings_update_font_options (ClutterSettings *self)
subpixel_order = rgba_orders[i].cairo_subpixel_order; subpixel_order = rgba_orders[i].cairo_subpixel_order;
clutter_font_subpixel_order = rgba_orders[i].clutter_font_subpixel_order; clutter_font_subpixel_order = rgba_orders[i].clutter_font_subpixel_order;
} }
cairo_font_options_set_subpixel_order (options, subpixel_order); cairo_font_options_set_subpixel_order (self->backend->font_options, subpixel_order);
i = g_settings_get_enum (settings, "font-antialiasing"); i = g_settings_get_enum (settings, "font-antialiasing");
if (i < G_N_ELEMENTS (antialiasings)) if (i < G_N_ELEMENTS (antialiasings))
@ -195,7 +191,7 @@ clutter_settings_update_font_options (ClutterSettings *self)
if (subpixel_order == CAIRO_SUBPIXEL_ORDER_DEFAULT) if (subpixel_order == CAIRO_SUBPIXEL_ORDER_DEFAULT)
antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL; antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
cairo_font_options_set_antialias (options, antialias_mode); cairo_font_options_set_antialias (self->backend->font_options, antialias_mode);
CLUTTER_NOTE (BACKEND, "New font options:\n" CLUTTER_NOTE (BACKEND, "New font options:\n"
" - font-name: %s\n" " - font-name: %s\n"
@ -209,8 +205,7 @@ clutter_settings_update_font_options (ClutterSettings *self)
clutter_font_hint_style != NULL ? clutter_font_hint_style : "<null>", clutter_font_hint_style != NULL ? clutter_font_hint_style : "<null>",
clutter_font_subpixel_order != NULL ? clutter_font_subpixel_order : "<null>"); clutter_font_subpixel_order != NULL ? clutter_font_subpixel_order : "<null>");
clutter_backend_set_font_options (self->backend, options); g_signal_emit_by_name (self->backend, "font-changed");
cairo_font_options_destroy (options);
} }
static void static void
@ -365,18 +360,7 @@ load_initial_settings (ClutterSettings *self)
schema = g_settings_schema_source_lookup (source, font_settings_path, TRUE); schema = g_settings_schema_source_lookup (source, font_settings_path, TRUE);
if (!schema) if (!schema)
{ {
cairo_font_options_t *font_options;
g_warning ("Failed to find schema: %s", font_settings_path); g_warning ("Failed to find schema: %s", font_settings_path);
/* Fallback to the default options */
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_subpixel_order (font_options, CAIRO_SUBPIXEL_ORDER_DEFAULT);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_DEFAULT);
clutter_backend_set_font_options (self->backend, font_options);
cairo_font_options_destroy (font_options);
} }
else else
{ {