From 269c3723be58d2070adc6a038eb6a06c1c1d49c8 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 4 Sep 2024 23:43:06 +0200 Subject: [PATCH] clutter/pango: Simplify show_layout As it is a private function now, make it take the color & target color states De-duplicating the setup function between ClutterText & ClutterTextNode Part-of: --- clutter/clutter/clutter-paint-nodes.c | 31 +--------------- clutter/clutter/clutter-text.c | 37 +------------------ .../clutter/pango/cogl-pango-display-list.c | 9 +++-- .../clutter/pango/cogl-pango-display-list.h | 4 +- clutter/clutter/pango/cogl-pango-private.h | 19 ++++------ clutter/clutter/pango/cogl-pango-render.c | 16 ++++---- 6 files changed, 28 insertions(+), 88 deletions(-) diff --git a/clutter/clutter/clutter-paint-nodes.c b/clutter/clutter/clutter-paint-nodes.c index e4798b697..281b12ef5 100644 --- a/clutter/clutter/clutter-paint-nodes.c +++ b/clutter/clutter/clutter-paint-nodes.c @@ -737,27 +737,6 @@ clutter_text_node_pre_draw (ClutterPaintNode *node, return tnode->layout != NULL; } -typedef struct -{ - ClutterColorState *color_state; - ClutterColorState *target_color_state; -} PangoPipelineData; - -static void -setup_pango_pipeline (CoglPipeline *pipeline, - gpointer user_data) -{ - PangoPipelineData *pango_pipeline_data = user_data; - ClutterColorState *color_state = - pango_pipeline_data->color_state; - ClutterColorState *target_color_state = - pango_pipeline_data->target_color_state; - - clutter_color_state_add_pipeline_transform (color_state, - target_color_state, - pipeline); -} - static void clutter_text_node_draw (ClutterPaintNode *node, ClutterPaintContext *paint_context) @@ -770,16 +749,10 @@ clutter_text_node_draw (ClutterPaintNode *node, PangoRectangle extents; CoglFramebuffer *fb; guint i; - PangoPipelineData pango_pipeline_data = {}; if (node->operations == NULL) return; - pango_pipeline_data = (PangoPipelineData) { - .color_state = color_state, - .target_color_state = target_color_state, - }; - fb = get_target_framebuffer (node, paint_context); pango_layout_get_pixel_extents (tnode->layout, NULL, &extents); @@ -818,8 +791,8 @@ clutter_text_node_draw (ClutterPaintNode *node, op->op.texrect[0], op->op.texrect[1], &tnode->color, - setup_pango_pipeline, - &pango_pipeline_data); + color_state, + target_color_state); if (clipped) cogl_framebuffer_pop_clip (fb); diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c index c15fdb082..0de768572 100644 --- a/clutter/clutter/clutter-text.c +++ b/clutter/clutter/clutter-text.c @@ -1945,27 +1945,6 @@ clutter_text_foreach_selection_rectangle_prescaled (ClutterText *se clutter_text_foreach_selection_rectangle (self, 1.0f, func, paint_context, user_data); } -typedef struct -{ - ClutterColorState *color_state; - ClutterColorState *target_color_state; -} PangoPipelineData; - -static void -setup_pango_pipeline (CoglPipeline *pipeline, - gpointer user_data) -{ - PangoPipelineData *pango_pipeline_data = user_data; - ClutterColorState *color_state = - pango_pipeline_data->color_state; - ClutterColorState *target_color_state = - pango_pipeline_data->target_color_state; - - clutter_color_state_add_pipeline_transform (color_state, - target_color_state, - pipeline); -} - static void paint_selection_rectangle (ClutterText *self, const ClutterActorBox *box, @@ -1987,7 +1966,6 @@ paint_selection_rectangle (ClutterText *self, clutter_paint_context_get_target_color_state (paint_context); CoglColor cogl_color = { 0, }; const CoglColor *color; - PangoPipelineData pango_pipeline_data = {}; /* Paint selection background */ if (priv->selection_color_set) @@ -2005,10 +1983,6 @@ paint_selection_rectangle (ClutterText *self, cogl_color_premultiply (&cogl_color); cogl_pipeline_set_color (color_pipeline, &cogl_color); - pango_pipeline_data = (PangoPipelineData) { - .color_state = color_state, - .target_color_state = target_color_state, - }; clutter_color_state_add_pipeline_transform (color_state, target_color_state, color_pipeline); @@ -2032,8 +2006,7 @@ paint_selection_rectangle (ClutterText *self, paint_opacity / 255.0f * color->alpha / 255.0f); clutter_show_layout (fb, layout, priv->text_x, 0, &cogl_color, - setup_pango_pipeline, - &pango_pipeline_data); + color_state, target_color_state); cogl_framebuffer_pop_clip (fb); g_object_unref (color_pipeline); @@ -2707,7 +2680,6 @@ clutter_text_paint (ClutterActor *self, float alloc_width; float alloc_height; float resource_scale; - PangoPipelineData pango_pipeline_data = {}; fb = clutter_paint_context_get_framebuffer (paint_context); @@ -2860,13 +2832,8 @@ clutter_text_paint (ClutterActor *self, priv->text_color.blue / 255.0f, real_opacity / 255.0f); - pango_pipeline_data = (PangoPipelineData) { - .color_state = color_state, - .target_color_state = target_color_state, - }; clutter_show_layout (fb, layout, priv->text_x, priv->text_y, &color, - setup_pango_pipeline, - &pango_pipeline_data); + color_state, target_color_state); selection_paint (text, fb, paint_context); diff --git a/clutter/clutter/pango/cogl-pango-display-list.c b/clutter/clutter/pango/cogl-pango-display-list.c index c832e5cfa..b4a447728 100644 --- a/clutter/clutter/pango/cogl-pango-display-list.c +++ b/clutter/clutter/pango/cogl-pango-display-list.c @@ -393,8 +393,8 @@ _cogl_framebuffer_draw_display_list_texture (CoglFramebuffer *fb, void cogl_pango_display_list_render (CoglFramebuffer *fb, CoglPangoDisplayList *dl, - ClutterPipelineSetup pipeline_setup, - gpointer pipeline_setup_user_data, + ClutterColorState *color_state, + ClutterColorState *target_color_state, const CoglColor *color) { GSList *l; @@ -434,7 +434,10 @@ cogl_pango_display_list_render (CoglFramebuffer *fb, cogl_pipeline_set_color (pipeline, &draw_color); - pipeline_setup (pipeline, pipeline_setup_user_data); + + clutter_color_state_add_pipeline_transform (color_state, + target_color_state, + pipeline); switch (node->type) { diff --git a/clutter/clutter/pango/cogl-pango-display-list.h b/clutter/clutter/pango/cogl-pango-display-list.h index 31b02f961..bc91f4a43 100644 --- a/clutter/clutter/pango/cogl-pango-display-list.h +++ b/clutter/clutter/pango/cogl-pango-display-list.h @@ -73,8 +73,8 @@ _cogl_pango_display_list_add_trapezoid (CoglPangoDisplayList *dl, void cogl_pango_display_list_render (CoglFramebuffer *framebuffer, CoglPangoDisplayList *dl, - ClutterPipelineSetup pipeline_setup, - gpointer pipeline_setup_user_data, + ClutterColorState *color_state, + ClutterColorState *target_color_state, const CoglColor *color); void diff --git a/clutter/clutter/pango/cogl-pango-private.h b/clutter/clutter/pango/cogl-pango-private.h index 7118e4712..9876616eb 100644 --- a/clutter/clutter/pango/cogl-pango-private.h +++ b/clutter/clutter/pango/cogl-pango-private.h @@ -37,6 +37,7 @@ #include +#include "clutter/clutter-color-state.h" #include "cogl/cogl.h" G_BEGIN_DECLS @@ -57,10 +58,6 @@ _cogl_pango_renderer_new (CoglContext *context); void clutter_ensure_glyph_cache_for_layout (PangoLayout *layout); - -typedef void (* ClutterPipelineSetup) (CoglPipeline *pipeline, - gpointer user_data); - /** * clutter_show_layout: (skip) * @framebuffer: A #CoglFramebuffer to draw too. @@ -73,13 +70,13 @@ typedef void (* ClutterPipelineSetup) (CoglPipeline *pipeline, * @y) within the `framebuffer`'s current model-view coordinate space. */ void -clutter_show_layout (CoglFramebuffer *framebuffer, - PangoLayout *layout, - float x, - float y, - const CoglColor *color, - ClutterPipelineSetup pipeline_setup, - gpointer pipeline_setup_userdata); +clutter_show_layout (CoglFramebuffer *framebuffer, + PangoLayout *layout, + float x, + float y, + const CoglColor *color, + ClutterColorState *color_state, + ClutterColorState *target_color_state); G_DEFINE_AUTOPTR_CLEANUP_FUNC (PangoRenderer, g_object_unref) diff --git a/clutter/clutter/pango/cogl-pango-render.c b/clutter/clutter/pango/cogl-pango-render.c index 9fc8d6e2c..12f63f7f3 100644 --- a/clutter/clutter/pango/cogl-pango-render.c +++ b/clutter/clutter/pango/cogl-pango-render.c @@ -258,13 +258,13 @@ cogl_pango_render_qdata_destroy (CoglPangoLayoutQdata *qdata) } void -clutter_show_layout (CoglFramebuffer *fb, - PangoLayout *layout, - float x, - float y, - const CoglColor *color, - ClutterPipelineSetup pipeline_setup, - gpointer pipeline_setup_userdata) +clutter_show_layout (CoglFramebuffer *fb, + PangoLayout *layout, + float x, + float y, + const CoglColor *color, + ClutterColorState *color_state, + ClutterColorState *target_color_state) { CoglPangoRenderer *renderer; CoglPangoLayoutQdata *qdata; @@ -321,7 +321,7 @@ clutter_show_layout (CoglFramebuffer *fb, cogl_pango_display_list_render (fb, qdata->display_list, - pipeline_setup, pipeline_setup_userdata, + color_state, target_color_state, color); cogl_framebuffer_pop_matrix (fb);