From 3359b6768638b93a30021f2f42968dbdde6de920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 15 Jul 2024 11:30:16 +0200 Subject: [PATCH] clutter/color-state: Handle adding snippet to pipeline While no functional changes right now, this allows us to add extra hooks like adding uniforms. Part-of: --- clutter/clutter/clutter-color-state.c | 22 +++++-- clutter/clutter/clutter-color-state.h | 5 +- clutter/clutter/clutter-paint-nodes.c | 51 ++++++++++------ clutter/clutter/clutter-stage-view.c | 8 +-- clutter/clutter/clutter-text.c | 59 +++++++++++++------ cogl/cogl-pango/cogl-pango-display-list.c | 12 ++-- cogl/cogl-pango/cogl-pango-display-list.h | 11 ++-- cogl/cogl-pango/cogl-pango-render.c | 31 +++++----- cogl/cogl-pango/cogl-pango.h | 29 +++++---- .../native/meta-cursor-renderer-native.c | 9 +-- src/compositor/meta-shaped-texture.c | 8 +-- src/tests/clutter/conform/pipeline-cache.c | 44 ++++++-------- 12 files changed, 168 insertions(+), 121 deletions(-) diff --git a/clutter/clutter/clutter-color-state.c b/clutter/clutter/clutter-color-state.c index 546cbdb54..e1121a835 100644 --- a/clutter/clutter/clutter-color-state.c +++ b/clutter/clutter/clutter-color-state.c @@ -690,10 +690,7 @@ get_color_space_mapping_matrix (ClutterColorState *color_state, g_assert_not_reached (); } -/** - * clutter_color_state_get_transform_snippet: (skip) - */ -CoglSnippet * +static CoglSnippet * clutter_color_state_get_transform_snippet (ClutterColorState *color_state, ClutterColorState *target_color_state) { @@ -708,8 +705,6 @@ clutter_color_state_get_transform_snippet (ClutterColorState *color_state, g_autoptr (GString) globals_source = NULL; g_autoptr (GString) snippet_source = NULL; - g_return_val_if_fail (CLUTTER_IS_COLOR_STATE (target_color_state), NULL); - priv = clutter_color_state_get_instance_private (color_state); color_manager = clutter_context_get_color_manager (priv->context); @@ -810,6 +805,21 @@ clutter_color_state_get_transform_snippet (ClutterColorState *color_state, return snippet; } +void +clutter_color_state_add_pipeline_transform (ClutterColorState *color_state, + ClutterColorState *target_color_state, + CoglPipeline *pipeline) +{ + g_autoptr (CoglSnippet) snippet = NULL; + + g_return_if_fail (CLUTTER_IS_COLOR_STATE (color_state)); + g_return_if_fail (CLUTTER_IS_COLOR_STATE (target_color_state)); + + snippet = clutter_color_state_get_transform_snippet (color_state, + target_color_state); + cogl_pipeline_add_snippet (pipeline, snippet); +} + gboolean clutter_color_state_equals (ClutterColorState *color_state, ClutterColorState *other_color_state) diff --git a/clutter/clutter/clutter-color-state.h b/clutter/clutter/clutter-color-state.h index 9f105e290..7ae617dd3 100644 --- a/clutter/clutter/clutter-color-state.h +++ b/clutter/clutter/clutter-color-state.h @@ -50,8 +50,9 @@ CLUTTER_EXPORT ClutterTransferFunction clutter_color_state_get_transfer_function (ClutterColorState *color_state); CLUTTER_EXPORT -CoglSnippet * clutter_color_state_get_transform_snippet (ClutterColorState *color_state, - ClutterColorState *target_color_state); +void clutter_color_state_add_pipeline_transform (ClutterColorState *color_state, + ClutterColorState *target_color_state, + CoglPipeline *pipeline); CLUTTER_EXPORT gboolean clutter_color_state_equals (ClutterColorState *color_state, diff --git a/clutter/clutter/clutter-paint-nodes.c b/clutter/clutter/clutter-paint-nodes.c index b076681df..8e3597667 100644 --- a/clutter/clutter/clutter-paint-nodes.c +++ b/clutter/clutter/clutter-paint-nodes.c @@ -406,13 +406,10 @@ clutter_pipeline_node_draw (ClutterPaintNode *node, clutter_paint_context_get_color_state (paint_context); ClutterColorState *target_color_state = clutter_paint_context_get_target_color_state (paint_context); - g_autoptr (CoglSnippet) color_snippet = NULL; - color_snippet = - clutter_color_state_get_transform_snippet (color_state, - target_color_state); - if (color_snippet) - cogl_pipeline_add_snippet (pnode->pipeline, color_snippet); + clutter_color_state_add_pipeline_transform (color_state, + target_color_state, + pnode->pipeline); } if (!cogl_pipeline_get_name (pnode->pipeline)) @@ -739,6 +736,27 @@ 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) @@ -748,17 +766,18 @@ clutter_text_node_draw (ClutterPaintNode *node, clutter_paint_context_get_color_state (paint_context); ClutterColorState *target_color_state = clutter_paint_context_get_target_color_state (paint_context); - g_autoptr (CoglSnippet) color_snippet = NULL; PangoRectangle extents; CoglFramebuffer *fb; guint i; + PangoPipelineData pango_pipeline_data = {}; if (node->operations == NULL) return; - color_snippet = - clutter_color_state_get_transform_snippet (color_state, - target_color_state); + pango_pipeline_data = (PangoPipelineData) { + .color_state = color_state, + .target_color_state = target_color_state, + }; fb = get_target_framebuffer (node, paint_context); @@ -798,7 +817,8 @@ clutter_text_node_draw (ClutterPaintNode *node, op->op.texrect[0], op->op.texrect[1], &tnode->color, - color_snippet); + setup_pango_pipeline, + &pango_pipeline_data); if (clipped) cogl_framebuffer_pop_clip (fb); @@ -1228,17 +1248,14 @@ clutter_layer_node_post_draw (ClutterPaintNode *node, { ClutterColorState *color_state; ClutterColorState *target_color_state; - g_autoptr (CoglSnippet) color_snippet = NULL; color_state = clutter_paint_context_get_color_state (paint_context); target_color_state = clutter_paint_context_get_target_color_state (paint_context); - color_snippet = - clutter_color_state_get_transform_snippet (color_state, - target_color_state); - if (color_snippet) - cogl_pipeline_add_snippet (pipeline, color_snippet); + clutter_color_state_add_pipeline_transform (color_state, + target_color_state, + pipeline); } for (i = 0; i < node->operations->len; i++) diff --git a/clutter/clutter/clutter-stage-view.c b/clutter/clutter/clutter-stage-view.c index 14fa06230..5b1bf2fdc 100644 --- a/clutter/clutter/clutter-stage-view.c +++ b/clutter/clutter/clutter-stage-view.c @@ -190,7 +190,6 @@ clutter_stage_view_ensure_offscreen_blit_pipeline (ClutterStageView *view) clutter_stage_view_get_instance_private (view); ClutterStageViewClass *view_class = CLUTTER_STAGE_VIEW_GET_CLASS (view); - g_autoptr (CoglSnippet) snippet = NULL; g_assert (priv->offscreen != NULL); @@ -203,10 +202,9 @@ clutter_stage_view_ensure_offscreen_blit_pipeline (ClutterStageView *view) if (view_class->setup_offscreen_transform) view_class->setup_offscreen_transform (view, priv->offscreen_pipeline); - snippet = clutter_color_state_get_transform_snippet (priv->color_state, - priv->output_color_state); - if (snippet) - cogl_pipeline_add_snippet (priv->offscreen_pipeline, snippet); + clutter_color_state_add_pipeline_transform (priv->color_state, + priv->output_color_state, + priv->offscreen_pipeline); } void diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c index 02c164c20..f8eac82ee 100644 --- a/clutter/clutter/clutter-text.c +++ b/clutter/clutter/clutter-text.c @@ -1906,6 +1906,27 @@ 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, @@ -1924,7 +1945,7 @@ paint_selection_rectangle (ClutterText *self, clutter_paint_context_get_target_color_state (paint_context); CoglColor cogl_color = { 0, }; const CoglColor *color; - g_autoptr (CoglSnippet) color_snippet = NULL; + PangoPipelineData pango_pipeline_data = {}; /* Paint selection background */ if (priv->selection_color_set) @@ -1942,11 +1963,13 @@ paint_selection_rectangle (ClutterText *self, cogl_color_premultiply (&cogl_color); cogl_pipeline_set_color (color_pipeline, &cogl_color); - color_snippet = - clutter_color_state_get_transform_snippet (color_state, - target_color_state); - if (color_snippet) - cogl_pipeline_add_snippet (color_pipeline, color_snippet); + 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); cogl_framebuffer_push_rectangle_clip (fb, box->x1, box->y1, @@ -1967,7 +1990,8 @@ paint_selection_rectangle (ClutterText *self, paint_opacity / 255.0f * color->alpha / 255.0f); cogl_pango_show_layout (fb, layout, priv->text_x, 0, &cogl_color, - color_snippet); + setup_pango_pipeline, + &pango_pipeline_data); cogl_framebuffer_pop_clip (fb); g_object_unref (color_pipeline); @@ -1995,7 +2019,6 @@ selection_paint (ClutterText *self, clutter_paint_context_get_target_color_state (paint_context); CoglPipeline *color_pipeline = create_color_pipeline (); CoglColor cogl_color; - g_autoptr (CoglSnippet) color_snippet = NULL; /* No selection, just draw the cursor */ if (priv->cursor_color_set) @@ -2012,11 +2035,9 @@ selection_paint (ClutterText *self, cogl_color_premultiply (&cogl_color); cogl_pipeline_set_color (color_pipeline, &cogl_color); - color_snippet = - clutter_color_state_get_transform_snippet (color_state, - target_color_state); - if (color_snippet) - cogl_pipeline_add_snippet (color_pipeline, color_snippet); + clutter_color_state_add_pipeline_transform (color_state, + target_color_state, + color_pipeline); cogl_framebuffer_draw_rectangle (fb, color_pipeline, @@ -2641,6 +2662,7 @@ 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); @@ -2793,12 +2815,13 @@ clutter_text_paint (ClutterActor *self, priv->text_color.blue / 255.0f, real_opacity / 255.0f); - color_snippet = - clutter_color_state_get_transform_snippet (color_state, - target_color_state); - + pango_pipeline_data = (PangoPipelineData) { + .color_state = color_state, + .target_color_state = target_color_state, + }; cogl_pango_show_layout (fb, layout, priv->text_x, priv->text_y, &color, - color_snippet); + setup_pango_pipeline, + &pango_pipeline_data); selection_paint (text, fb, paint_context); diff --git a/cogl/cogl-pango/cogl-pango-display-list.c b/cogl/cogl-pango/cogl-pango-display-list.c index 1f454b759..481ff967d 100644 --- a/cogl/cogl-pango/cogl-pango-display-list.c +++ b/cogl/cogl-pango/cogl-pango-display-list.c @@ -391,10 +391,11 @@ _cogl_framebuffer_draw_display_list_texture (CoglFramebuffer *fb, } void -cogl_pango_display_list_render (CoglFramebuffer *fb, - CoglPangoDisplayList *dl, - CoglSnippet *extra_snippet, - const CoglColor *color) +cogl_pango_display_list_render (CoglFramebuffer *fb, + CoglPangoDisplayList *dl, + CoglPangoPipelineSetup pipeline_setup, + gpointer pipeline_setup_user_data, + const CoglColor *color) { GSList *l; @@ -433,8 +434,7 @@ cogl_pango_display_list_render (CoglFramebuffer *fb, cogl_pipeline_set_color (pipeline, &draw_color); - if (extra_snippet) - cogl_pipeline_add_snippet (pipeline, extra_snippet); + pipeline_setup (pipeline, pipeline_setup_user_data); switch (node->type) { diff --git a/cogl/cogl-pango/cogl-pango-display-list.h b/cogl/cogl-pango/cogl-pango-display-list.h index 550d0e408..de6eec0c6 100644 --- a/cogl/cogl-pango/cogl-pango-display-list.h +++ b/cogl/cogl-pango/cogl-pango-display-list.h @@ -32,6 +32,8 @@ #include "cogl-pango/cogl-pango-pipeline-cache.h" +#include "cogl-pango/cogl-pango.h" + G_BEGIN_DECLS typedef struct _CoglPangoDisplayList CoglPangoDisplayList; @@ -69,10 +71,11 @@ _cogl_pango_display_list_add_trapezoid (CoglPangoDisplayList *dl, float x_22); void -cogl_pango_display_list_render (CoglFramebuffer *framebuffer, - CoglPangoDisplayList *dl, - CoglSnippet *extra_snippet, - const CoglColor *color); +cogl_pango_display_list_render (CoglFramebuffer *framebuffer, + CoglPangoDisplayList *dl, + CoglPangoPipelineSetup pipeline_setup, + gpointer pipeline_setup_user_data, + const CoglColor *color); void _cogl_pango_display_list_free (CoglPangoDisplayList *dl); diff --git a/cogl/cogl-pango/cogl-pango-render.c b/cogl/cogl-pango/cogl-pango-render.c index 03fbda839..91f1d6d66 100644 --- a/cogl/cogl-pango/cogl-pango-render.c +++ b/cogl/cogl-pango/cogl-pango-render.c @@ -357,12 +357,13 @@ cogl_pango_render_qdata_destroy (CoglPangoLayoutQdata *qdata) } void -cogl_pango_show_layout (CoglFramebuffer *fb, - PangoLayout *layout, - float x, - float y, - const CoglColor *color, - CoglSnippet *extra_snippet) +cogl_pango_show_layout (CoglFramebuffer *fb, + PangoLayout *layout, + float x, + float y, + const CoglColor *color, + CoglPangoPipelineSetup pipeline_setup, + gpointer pipeline_setup_userdata) { PangoContext *context; CoglPangoRenderer *priv; @@ -426,7 +427,7 @@ cogl_pango_show_layout (CoglFramebuffer *fb, cogl_pango_display_list_render (fb, qdata->display_list, - extra_snippet, + pipeline_setup, pipeline_setup_userdata, color); cogl_framebuffer_pop_matrix (fb); @@ -446,12 +447,13 @@ cogl_pango_show_layout (CoglFramebuffer *fb, } void -cogl_pango_show_layout_line (CoglFramebuffer *fb, - PangoLayoutLine *line, - float x, - float y, - const CoglColor *color, - CoglSnippet *extra_snippet) +cogl_pango_show_layout_line (CoglFramebuffer *fb, + PangoLayoutLine *line, + float x, + float y, + const CoglColor *color, + CoglPangoPipelineSetup pipeline_setup, + gpointer pipeline_setup_userdata) { PangoContext *context; CoglPangoRenderer *priv; @@ -477,7 +479,8 @@ cogl_pango_show_layout_line (CoglFramebuffer *fb, cogl_pango_display_list_render (fb, priv->display_list, - extra_snippet, + pipeline_setup, + pipeline_setup_userdata, color); _cogl_pango_display_list_free (priv->display_list); diff --git a/cogl/cogl-pango/cogl-pango.h b/cogl/cogl-pango/cogl-pango.h index cf16ebd56..354f9013e 100644 --- a/cogl/cogl-pango/cogl-pango.h +++ b/cogl/cogl-pango/cogl-pango.h @@ -65,6 +65,9 @@ G_BEGIN_DECLS typedef PangoCairoFontMap CoglPangoFontMap; +typedef void (* CoglPangoPipelineSetup) (CoglPipeline *pipeline, + gpointer user_data); + /** * cogl_pango_font_map_new: * @@ -151,12 +154,13 @@ cogl_pango_font_map_get_renderer (CoglPangoFontMap *font_map); * @y) within the `framebuffer`'s current model-view coordinate space. */ COGL_EXPORT void -cogl_pango_show_layout (CoglFramebuffer *framebuffer, - PangoLayout *layout, - float x, - float y, - const CoglColor *color, - CoglSnippet *extra_snippet); +cogl_pango_show_layout (CoglFramebuffer *framebuffer, + PangoLayout *layout, + float x, + float y, + const CoglColor *color, + CoglPangoPipelineSetup pipeline_setup, + gpointer pipeline_setup_userdata); /** * cogl_pango_show_layout_line: (skip) @@ -170,12 +174,13 @@ cogl_pango_show_layout (CoglFramebuffer *framebuffer, * @y) within the `framebuffer`'s current model-view coordinate space. */ COGL_EXPORT void -cogl_pango_show_layout_line (CoglFramebuffer *framebuffer, - PangoLayoutLine *line, - float x, - float y, - const CoglColor *color, - CoglSnippet *extra_snippet); +cogl_pango_show_layout_line (CoglFramebuffer *framebuffer, + PangoLayoutLine *line, + float x, + float y, + const CoglColor *color, + CoglPangoPipelineSetup pipeline_setup, + gpointer pipeline_setup_userdata); #define COGL_PANGO_TYPE_RENDERER (cogl_pango_renderer_get_type ()) diff --git a/src/backends/native/meta-cursor-renderer-native.c b/src/backends/native/meta-cursor-renderer-native.c index ac1f6ca09..d2474b659 100644 --- a/src/backends/native/meta-cursor-renderer-native.c +++ b/src/backends/native/meta-cursor-renderer-native.c @@ -786,7 +786,6 @@ scale_and_transform_cursor_sprite_cpu (MetaCursorRendererNative *cursor_renderer graphene_matrix_t matrix; MetaMonitorTransform pipeline_transform; ClutterColorState *color_state; - g_autoptr (CoglSnippet) color_snippet = NULL; int dst_width; int dst_height; @@ -819,11 +818,9 @@ scale_and_transform_cursor_sprite_cpu (MetaCursorRendererNative *cursor_renderer cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix); color_state = meta_cursor_sprite_get_color_state (cursor_sprite); - color_snippet = - clutter_color_state_get_transform_snippet (color_state, - target_color_state); - if (color_snippet) - cogl_pipeline_add_snippet (pipeline, color_snippet); + clutter_color_state_add_pipeline_transform (color_state, + target_color_state, + pipeline); cogl_framebuffer_clear4f (COGL_FRAMEBUFFER (offscreen), COGL_BUFFER_BIT_COLOR, diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c index b10ab1fe1..110cafcdd 100644 --- a/src/compositor/meta-shaped-texture.c +++ b/src/compositor/meta-shaped-texture.c @@ -467,12 +467,10 @@ attach_and_save_color_snippet (MetaShapedTexture *stex, { ClutterPipelineCache *pipeline_cache = clutter_context_get_pipeline_cache (stex->clutter_context); - g_autoptr (CoglSnippet) color_snippet = NULL; - color_snippet = - clutter_color_state_get_transform_snippet (color_state, target_color_state); - if (color_snippet) - cogl_pipeline_add_snippet (pipeline, color_snippet); + clutter_color_state_add_pipeline_transform (color_state, + target_color_state, + pipeline); clutter_pipeline_cache_set_pipeline (pipeline_cache, stex, diff --git a/src/tests/clutter/conform/pipeline-cache.c b/src/tests/clutter/conform/pipeline-cache.c index 2e53391f4..19492bb3a 100644 --- a/src/tests/clutter/conform/pipeline-cache.c +++ b/src/tests/clutter/conform/pipeline-cache.c @@ -5,14 +5,6 @@ #include "tests/clutter-test-utils.h" -static void -take_snippet (CoglPipeline *pipeline, - CoglSnippet *snippet) -{ - cogl_pipeline_add_snippet (pipeline, snippet); - g_object_unref (snippet); -} - static void pipeline_cache_group_pipelines (void) { @@ -53,18 +45,18 @@ pipeline_cache_group_pipelines (void) bt2020_pq_to_bt2020_linear = cogl_pipeline_new (cogl_context); srgb_linear_to_srgb_srgb = cogl_pipeline_new (cogl_context); - take_snippet (srgb_srgb_to_bt2020_linear, - clutter_color_state_get_transform_snippet (srgb_srgb, - bt2020_linear)); - take_snippet (bt2020_linear_to_bt2020_pq, - clutter_color_state_get_transform_snippet (bt2020_linear, - bt2020_pq)); - take_snippet (bt2020_pq_to_bt2020_linear, - clutter_color_state_get_transform_snippet (bt2020_pq, - bt2020_linear)); - take_snippet (srgb_linear_to_srgb_srgb, - clutter_color_state_get_transform_snippet (srgb_linear, - srgb_srgb)); + clutter_color_state_add_pipeline_transform (srgb_srgb, + bt2020_linear, + srgb_srgb_to_bt2020_linear); + clutter_color_state_add_pipeline_transform (bt2020_linear, + bt2020_pq, + bt2020_linear_to_bt2020_pq); + clutter_color_state_add_pipeline_transform (bt2020_pq, + bt2020_linear, + bt2020_pq_to_bt2020_linear); + clutter_color_state_add_pipeline_transform (srgb_linear, + srgb_srgb, + srgb_linear_to_srgb_srgb); /* Check that it's all empty. */ g_assert_null (clutter_pipeline_cache_get_pipeline (pipeline_cache, group1, 0, @@ -138,9 +130,9 @@ pipeline_cache_replace_pipeline (void) g_object_add_weak_pointer (G_OBJECT (srgb_srgb_to_bt2020_linear), (gpointer *) &srgb_srgb_to_bt2020_linear); - take_snippet (srgb_srgb_to_bt2020_linear, - clutter_color_state_get_transform_snippet (srgb_srgb, - bt2020_linear)); + clutter_color_state_add_pipeline_transform (srgb_srgb, + bt2020_linear, + srgb_srgb_to_bt2020_linear); clutter_pipeline_cache_set_pipeline (pipeline_cache, group, 0, srgb_srgb, bt2020_linear, @@ -149,9 +141,9 @@ pipeline_cache_replace_pipeline (void) g_object_unref (srgb_srgb_to_bt2020_linear); g_assert_nonnull (srgb_srgb_to_bt2020_linear); - take_snippet (srgb_srgb_to_bt2020_linear_copy, - clutter_color_state_get_transform_snippet (srgb_srgb, - bt2020_linear)); + clutter_color_state_add_pipeline_transform (srgb_srgb, + bt2020_linear, + srgb_srgb_to_bt2020_linear_copy); clutter_pipeline_cache_set_pipeline (pipeline_cache, group, 0, srgb_srgb, bt2020_linear, srgb_srgb_to_bt2020_linear_copy);