From 40dc151e82970b487b8855572426fde38fab8d81 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 4 Sep 2024 15:00:11 +0200 Subject: [PATCH] clutter/pango: Remove FontMap type It was created just to keep an instance of the corresponding renderer / context Instead, move those fields into ClutterContext. Part-of: --- clutter/clutter/clutter-context-private.h | 3 + clutter/clutter/clutter-context.c | 13 ++- clutter/clutter/clutter-main.h | 10 --- clutter/clutter/pango/cogl-pango-fontmap.c | 95 ---------------------- clutter/clutter/pango/cogl-pango-private.h | 14 ---- clutter/clutter/pango/cogl-pango-render.c | 63 ++++++-------- 6 files changed, 39 insertions(+), 159 deletions(-) delete mode 100644 clutter/clutter/pango/cogl-pango-fontmap.c diff --git a/clutter/clutter/clutter-context-private.h b/clutter/clutter/clutter-context-private.h index 5ea942f16..b6740476c 100644 --- a/clutter/clutter/clutter-context-private.h +++ b/clutter/clutter/clutter-context-private.h @@ -35,6 +35,7 @@ struct _ClutterContext * ordered from least recently added to most recently added */ GList *event_filters; + PangoRenderer *font_renderer; PangoFontMap *font_map; GSList *current_event; @@ -50,3 +51,5 @@ struct _ClutterContext ClutterStageManager * clutter_context_get_stage_manager (ClutterContext *context); gboolean clutter_context_get_show_fps (ClutterContext *context); + +PangoRenderer * clutter_context_get_font_renderer (ClutterContext *context); diff --git a/clutter/clutter/clutter-context.c b/clutter/clutter/clutter-context.c index b79d35ad1..6f2527b98 100644 --- a/clutter/clutter/clutter-context.c +++ b/clutter/clutter/clutter-context.c @@ -309,6 +309,7 @@ PangoFontMap * clutter_context_get_pango_fontmap (ClutterContext *context) { PangoFontMap *font_map; + PangoRenderer *font_renderer; gdouble resolution; ClutterBackend *backend; CoglContext *cogl_context; @@ -318,13 +319,15 @@ clutter_context_get_pango_fontmap (ClutterContext *context) backend = clutter_context_get_backend (context); cogl_context = clutter_backend_get_cogl_context (backend); - font_map = cogl_pango_font_map_new (cogl_context); + font_map = pango_cairo_font_map_new (); + font_renderer = _cogl_pango_renderer_new (cogl_context); resolution = clutter_backend_get_resolution (context->backend); pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (font_map), resolution); context->font_map = font_map; + context->font_renderer = font_renderer; return context->font_map; } @@ -388,3 +391,11 @@ clutter_context_get_settings (ClutterContext *context) return context->settings; } + +PangoRenderer * +clutter_context_get_font_renderer (ClutterContext *context) +{ + g_return_val_if_fail (CLUTTER_IS_CONTEXT (context), NULL); + + return context->font_renderer; +} diff --git a/clutter/clutter/clutter-main.h b/clutter/clutter/clutter-main.h index 82e4bdedf..548fff8b7 100644 --- a/clutter/clutter/clutter-main.h +++ b/clutter/clutter/clutter-main.h @@ -163,16 +163,6 @@ ClutterTextDirection clutter_get_text_direction (void); typedef void (* ClutterPipelineSetup) (CoglPipeline *pipeline, gpointer user_data); -/** - * clutter_font_map_new: - * - * Creates a new font map. - * - * Return value: (transfer full): the newly created #PangoFontMap - */ -CLUTTER_EXPORT PangoFontMap * -clutter_font_map_new (CoglContext *context); - /** * clutter_ensure_glyph_cache_for_layout: * @layout: A #PangoLayout diff --git a/clutter/clutter/pango/cogl-pango-fontmap.c b/clutter/clutter/pango/cogl-pango-fontmap.c deleted file mode 100644 index bc02b7e6a..000000000 --- a/clutter/clutter/pango/cogl-pango-fontmap.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Cogl - * - * A Low Level GPU Graphics and Utilities API - * - * Copyright (C) 2008 OpenedHand - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "config.h" - -#include -#include -#include - -#include "clutter/pango/cogl-pango-private.h" -#include "cogl/cogl.h" - -static GQuark cogl_pango_font_map_get_priv_key (void) G_GNUC_CONST; - -typedef struct _CoglPangoFontMapPriv -{ - CoglContext *ctx; - PangoRenderer *renderer; -} CoglPangoFontMapPriv; - -static void -free_priv (gpointer data) -{ - CoglPangoFontMapPriv *priv = data; - - g_object_unref (priv->ctx); - g_object_unref (priv->renderer); - - g_free (priv); -} - -PangoFontMap * -cogl_pango_font_map_new (CoglContext *context) -{ - PangoFontMap *fm = pango_cairo_font_map_new (); - g_autofree CoglPangoFontMapPriv *priv = g_new0 (CoglPangoFontMapPriv, 1); - - priv->ctx = g_object_ref (context); - - /* XXX: The public pango api doesn't let us sub-class - * PangoCairoFontMap so we attach our own private data using qdata - * for now. */ - g_object_set_qdata_full (G_OBJECT (fm), - cogl_pango_font_map_get_priv_key (), - g_steal_pointer (&priv), - free_priv); - - return fm; -} - -PangoRenderer * -cogl_pango_font_map_get_renderer (PangoFontMap *fm) -{ - CoglPangoFontMapPriv *priv = g_object_get_qdata (G_OBJECT (fm), - cogl_pango_font_map_get_priv_key ()); - if (G_UNLIKELY (!priv->renderer)) - priv->renderer = _cogl_pango_renderer_new (priv->ctx); - return priv->renderer; -} - -static GQuark -cogl_pango_font_map_get_priv_key (void) -{ - static GQuark priv_key = 0; - - if (G_UNLIKELY (priv_key == 0)) - priv_key = g_quark_from_static_string ("CoglPangoFontMap"); - - return priv_key; -} diff --git a/clutter/clutter/pango/cogl-pango-private.h b/clutter/clutter/pango/cogl-pango-private.h index d300696f5..6a2fae2b9 100644 --- a/clutter/clutter/pango/cogl-pango-private.h +++ b/clutter/clutter/pango/cogl-pango-private.h @@ -44,20 +44,6 @@ G_BEGIN_DECLS PangoRenderer * _cogl_pango_renderer_new (CoglContext *context); -PangoFontMap * -cogl_pango_font_map_new (CoglContext *context); - -/** - * cogl_pango_font_map_get_renderer: - * @font_map: a #PangoFontMap - * - * Retrieves the [class@CoglPango.Renderer] for the passed @font_map. - * - * Return value: (transfer none): a #PangoRenderer - */ -PangoRenderer * -cogl_pango_font_map_get_renderer (PangoFontMap *font_map); - G_DEFINE_AUTOPTR_CLEANUP_FUNC (PangoRenderer, g_object_unref) G_END_DECLS diff --git a/clutter/clutter/pango/cogl-pango-render.c b/clutter/clutter/pango/cogl-pango-render.c index dc615f065..d632ee3b7 100644 --- a/clutter/clutter/pango/cogl-pango-render.c +++ b/clutter/clutter/pango/cogl-pango-render.c @@ -42,6 +42,8 @@ #include #include "clutter/clutter-debug.h" +#include "clutter/clutter-context-private.h" +#include "clutter/clutter-private.h" #include "clutter/pango/cogl-pango-private.h" #include "clutter/pango/cogl-pango-glyph-cache.h" #include "clutter/pango/cogl-pango-display-list.h" @@ -245,22 +247,6 @@ cogl_pango_renderer_finalize (GObject *object) G_OBJECT_CLASS (cogl_pango_renderer_parent_class)->finalize (object); } -static CoglPangoRenderer * -cogl_pango_get_renderer_from_context (PangoContext *context) -{ - PangoFontMap *font_map; - PangoRenderer *renderer; - - font_map = pango_context_get_font_map (context); - g_return_val_if_fail (PANGO_IS_FONT_MAP (font_map), NULL); - - renderer = cogl_pango_font_map_get_renderer (font_map); - - g_return_val_if_fail (COGL_PANGO_IS_RENDERER (renderer), NULL); - - return COGL_PANGO_RENDERER (renderer); -} - static GQuark cogl_pango_layout_get_qdata_key (void) { @@ -310,13 +296,13 @@ clutter_show_layout (CoglFramebuffer *fb, ClutterPipelineSetup pipeline_setup, gpointer pipeline_setup_userdata) { - PangoContext *context; - CoglPangoRenderer *priv; + CoglPangoRenderer *renderer; CoglPangoLayoutQdata *qdata; + ClutterContext *context; - context = pango_layout_get_context (layout); - priv = cogl_pango_get_renderer_from_context (context); - if (G_UNLIKELY (!priv)) + context = _clutter_context_get_default (); + renderer = COGL_PANGO_RENDERER (clutter_context_get_font_renderer (context)); + if (G_UNLIKELY (!renderer)) return; qdata = g_object_get_qdata (G_OBJECT (layout), @@ -325,7 +311,7 @@ clutter_show_layout (CoglFramebuffer *fb, if (qdata == NULL) { qdata = g_new0 (CoglPangoLayoutQdata, 1); - qdata->renderer = priv; + qdata->renderer = renderer; g_object_set_qdata_full (G_OBJECT (layout), cogl_pango_layout_get_qdata_key (), qdata, @@ -339,14 +325,14 @@ clutter_show_layout (CoglFramebuffer *fb, if (qdata->display_list && ((qdata->first_line && qdata->first_line->layout != layout) || - qdata->mipmapping_used != priv->use_mipmapping)) + qdata->mipmapping_used != renderer->use_mipmapping)) cogl_pango_layout_qdata_forget_display_list (qdata); if (qdata->display_list == NULL) { - CoglPangoRendererCaches *caches = priv->use_mipmapping ? - &priv->mipmap_caches : - &priv->no_mipmap_caches; + CoglPangoRendererCaches *caches = renderer->use_mipmapping ? + &renderer->mipmap_caches : + &renderer->no_mipmap_caches; clutter_ensure_glyph_cache_for_layout (layout); @@ -360,11 +346,11 @@ clutter_show_layout (CoglFramebuffer *fb, (GHookFunc) cogl_pango_layout_qdata_forget_display_list, qdata); - priv->display_list = qdata->display_list; - pango_renderer_draw_layout (PANGO_RENDERER (priv), layout, 0, 0); - priv->display_list = NULL; + renderer->display_list = qdata->display_list; + pango_renderer_draw_layout (PANGO_RENDERER (renderer), layout, 0, 0); + renderer->display_list = NULL; - qdata->mipmapping_used = priv->use_mipmapping; + qdata->mipmapping_used = renderer->use_mipmapping; } cogl_framebuffer_push_matrix (fb); @@ -506,13 +492,12 @@ cogl_pango_renderer_set_dirty_glyph (PangoFont *font, static void _cogl_pango_ensure_glyph_cache_for_layout_line_internal (PangoLayoutLine *line) { - PangoContext *context; + ClutterContext *context; PangoRenderer *renderer; GSList *l; - context = pango_layout_get_context (line->layout); - renderer = - PANGO_RENDERER (cogl_pango_get_renderer_from_context (context)); + context = _clutter_context_get_default (); + renderer = clutter_context_get_font_renderer (context); for (l = line->runs; l; l = l->next) { @@ -549,12 +534,12 @@ _cogl_pango_set_dirty_glyphs (CoglPangoRenderer *priv) void clutter_ensure_glyph_cache_for_layout (PangoLayout *layout) { - PangoContext *context; - CoglPangoRenderer *priv; + ClutterContext *context; + PangoRenderer *renderer; PangoLayoutIter *iter; - context = pango_layout_get_context (layout); - priv = cogl_pango_get_renderer_from_context (context); + context = _clutter_context_get_default (); + renderer = clutter_context_get_font_renderer (context); g_return_if_fail (PANGO_IS_LAYOUT (layout)); @@ -575,7 +560,7 @@ clutter_ensure_glyph_cache_for_layout (PangoLayout *layout) /* Now that we know all of the positions are settled we'll fill in any dirty glyphs */ - _cogl_pango_set_dirty_glyphs (priv); + _cogl_pango_set_dirty_glyphs (COGL_PANGO_RENDERER (renderer)); } static void