1
0
Fork 0

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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4004>
This commit is contained in:
Bilal Elmoussaoui 2024-09-04 15:00:11 +02:00 committed by Marge Bot
parent fe3192169a
commit 40dc151e82
6 changed files with 39 additions and 159 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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

View file

@ -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 <pango/pango-fontmap.h>
#include <pango/pangocairo.h>
#include <pango/pango-renderer.h>
#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;
}

View file

@ -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

View file

@ -42,6 +42,8 @@
#include <cairo-ft.h>
#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