From 9a0fbbfa81d7461208e430ced971daadff00b8e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 7 Jun 2024 23:40:49 +0200 Subject: [PATCH] cogl/pango: Add argument to supply extra snippet This will be applied to the pipeline used for drawing, and can be used to include color state transformation snippets. Part-of: --- clutter/clutter/clutter-paint-nodes.c | 3 ++- clutter/clutter/clutter-text.c | 4 +-- cogl/cogl-pango/cogl-pango-display-list.c | 23 +++++++++++------ cogl/cogl-pango/cogl-pango-display-list.h | 7 +++--- cogl/cogl-pango/cogl-pango-render.c | 30 +++++++++++++---------- cogl/cogl-pango/cogl-pango.h | 16 ++++++------ 6 files changed, 49 insertions(+), 34 deletions(-) diff --git a/clutter/clutter/clutter-paint-nodes.c b/clutter/clutter/clutter-paint-nodes.c index 24db87c8d..02b70bd64 100644 --- a/clutter/clutter/clutter-paint-nodes.c +++ b/clutter/clutter/clutter-paint-nodes.c @@ -771,7 +771,8 @@ clutter_text_node_draw (ClutterPaintNode *node, tnode->layout, op->op.texrect[0], op->op.texrect[1], - &tnode->color); + &tnode->color, + NULL); if (clipped) cogl_framebuffer_pop_clip (fb); diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c index 42a3430a8..b6294c626 100644 --- a/clutter/clutter/clutter-text.c +++ b/clutter/clutter/clutter-text.c @@ -1951,7 +1951,7 @@ paint_selection_rectangle (ClutterText *self, color->blue / 255.0f, paint_opacity / 255.0f * color->alpha / 255.0f); - cogl_pango_show_layout (fb, layout, priv->text_x, 0, &cogl_color); + cogl_pango_show_layout (fb, layout, priv->text_x, 0, &cogl_color, NULL); cogl_framebuffer_pop_clip (fb); g_object_unref (color_pipeline); @@ -2758,7 +2758,7 @@ clutter_text_paint (ClutterActor *self, priv->text_color.green / 255.0f, priv->text_color.blue / 255.0f, real_opacity / 255.0f); - cogl_pango_show_layout (fb, layout, priv->text_x, priv->text_y, &color); + cogl_pango_show_layout (fb, layout, priv->text_x, priv->text_y, &color, NULL); selection_paint (text, fb); diff --git a/cogl/cogl-pango/cogl-pango-display-list.c b/cogl/cogl-pango/cogl-pango-display-list.c index badbfd514..1f454b759 100644 --- a/cogl/cogl-pango/cogl-pango-display-list.c +++ b/cogl/cogl-pango/cogl-pango-display-list.c @@ -391,9 +391,10 @@ _cogl_framebuffer_draw_display_list_texture (CoglFramebuffer *fb, } void -_cogl_pango_display_list_render (CoglFramebuffer *fb, - CoglPangoDisplayList *dl, - const CoglColor *color) +cogl_pango_display_list_render (CoglFramebuffer *fb, + CoglPangoDisplayList *dl, + CoglSnippet *extra_snippet, + const CoglColor *color) { GSList *l; @@ -401,6 +402,7 @@ _cogl_pango_display_list_render (CoglFramebuffer *fb, { CoglPangoDisplayListNode *node = l->data; CoglColor draw_color; + g_autoptr (CoglPipeline) pipeline = NULL; if (node->pipeline == NULL) { @@ -414,6 +416,8 @@ _cogl_pango_display_list_render (CoglFramebuffer *fb, NULL); } + pipeline = cogl_pipeline_copy (node->pipeline); + if (node->color_override) /* Use the override color but preserve the alpha from the draw color */ @@ -427,17 +431,20 @@ _cogl_pango_display_list_render (CoglFramebuffer *fb, draw_color = *color; cogl_color_premultiply (&draw_color); - cogl_pipeline_set_color (node->pipeline, &draw_color); + cogl_pipeline_set_color (pipeline, &draw_color); + + if (extra_snippet) + cogl_pipeline_add_snippet (pipeline, extra_snippet); switch (node->type) { case COGL_PANGO_DISPLAY_LIST_TEXTURE: - _cogl_framebuffer_draw_display_list_texture (fb, node->pipeline, node); + _cogl_framebuffer_draw_display_list_texture (fb, pipeline, node); break; case COGL_PANGO_DISPLAY_LIST_RECTANGLE: cogl_framebuffer_draw_rectangle (fb, - node->pipeline, + pipeline, node->d.rectangle.x_1, node->d.rectangle.y_1, node->d.rectangle.x_2, @@ -445,9 +452,9 @@ _cogl_pango_display_list_render (CoglFramebuffer *fb, break; case COGL_PANGO_DISPLAY_LIST_TRAPEZOID: - cogl_primitive_draw (node->d.trapezoid.primitive, + cogl_primitive_draw (node->d.trapezoid.primitive, fb, - node->pipeline); + pipeline); break; } } diff --git a/cogl/cogl-pango/cogl-pango-display-list.h b/cogl/cogl-pango/cogl-pango-display-list.h index 6a956e828..550d0e408 100644 --- a/cogl/cogl-pango/cogl-pango-display-list.h +++ b/cogl/cogl-pango/cogl-pango-display-list.h @@ -69,9 +69,10 @@ _cogl_pango_display_list_add_trapezoid (CoglPangoDisplayList *dl, float x_22); void -_cogl_pango_display_list_render (CoglFramebuffer *framebuffer, - CoglPangoDisplayList *dl, - const CoglColor *color); +cogl_pango_display_list_render (CoglFramebuffer *framebuffer, + CoglPangoDisplayList *dl, + CoglSnippet *extra_snippet, + 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 eed629fb3..e88e87eec 100644 --- a/cogl/cogl-pango/cogl-pango-render.c +++ b/cogl/cogl-pango/cogl-pango-render.c @@ -358,10 +358,11 @@ cogl_pango_render_qdata_destroy (CoglPangoLayoutQdata *qdata) void cogl_pango_show_layout (CoglFramebuffer *fb, - PangoLayout *layout, - float x, - float y, - const CoglColor *color) + PangoLayout *layout, + float x, + float y, + const CoglColor *color, + CoglSnippet *extra_snippet) { PangoContext *context; CoglPangoRenderer *priv; @@ -423,9 +424,10 @@ cogl_pango_show_layout (CoglFramebuffer *fb, cogl_framebuffer_push_matrix (fb); cogl_framebuffer_translate (fb, x, y, 0); - _cogl_pango_display_list_render (fb, - qdata->display_list, - color); + cogl_pango_display_list_render (fb, + qdata->display_list, + extra_snippet, + color); cogl_framebuffer_pop_matrix (fb); @@ -446,9 +448,10 @@ cogl_pango_show_layout (CoglFramebuffer *fb, void cogl_pango_show_layout_line (CoglFramebuffer *fb, PangoLayoutLine *line, - float x, - float y, - const CoglColor *color) + float x, + float y, + const CoglColor *color, + CoglSnippet *extra_snippet) { PangoContext *context; CoglPangoRenderer *priv; @@ -472,9 +475,10 @@ cogl_pango_show_layout_line (CoglFramebuffer *fb, pango_renderer_draw_layout_line (PANGO_RENDERER (priv), line, pango_x, pango_y); - _cogl_pango_display_list_render (fb, - priv->display_list, - color); + cogl_pango_display_list_render (fb, + priv->display_list, + extra_snippet, + color); _cogl_pango_display_list_free (priv->display_list); priv->display_list = NULL; diff --git a/cogl/cogl-pango/cogl-pango.h b/cogl/cogl-pango/cogl-pango.h index 1c23821f0..99b970db1 100644 --- a/cogl/cogl-pango/cogl-pango.h +++ b/cogl/cogl-pango/cogl-pango.h @@ -152,10 +152,11 @@ cogl_pango_font_map_get_renderer (CoglPangoFontMap *font_map); */ COGL_EXPORT void cogl_pango_show_layout (CoglFramebuffer *framebuffer, - PangoLayout *layout, - float x, - float y, - const CoglColor *color); + PangoLayout *layout, + float x, + float y, + const CoglColor *color, + CoglSnippet *extra_snippet); /** * cogl_pango_show_layout_line: (skip) @@ -171,9 +172,10 @@ cogl_pango_show_layout (CoglFramebuffer *framebuffer, COGL_EXPORT void cogl_pango_show_layout_line (CoglFramebuffer *framebuffer, PangoLayoutLine *line, - float x, - float y, - const CoglColor *color); + float x, + float y, + const CoglColor *color, + CoglSnippet *extra_snippet); #define COGL_PANGO_TYPE_RENDERER (cogl_pango_renderer_get_type ())