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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4004>
This commit is contained in:
Bilal Elmoussaoui
2024-09-04 23:43:06 +02:00
committed by Marge Bot
parent de7eb11ed8
commit 269c3723be
6 changed files with 28 additions and 88 deletions

View File

@ -737,27 +737,6 @@ clutter_text_node_pre_draw (ClutterPaintNode *node,
return tnode->layout != NULL; 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 static void
clutter_text_node_draw (ClutterPaintNode *node, clutter_text_node_draw (ClutterPaintNode *node,
ClutterPaintContext *paint_context) ClutterPaintContext *paint_context)
@ -770,16 +749,10 @@ clutter_text_node_draw (ClutterPaintNode *node,
PangoRectangle extents; PangoRectangle extents;
CoglFramebuffer *fb; CoglFramebuffer *fb;
guint i; guint i;
PangoPipelineData pango_pipeline_data = {};
if (node->operations == NULL) if (node->operations == NULL)
return; return;
pango_pipeline_data = (PangoPipelineData) {
.color_state = color_state,
.target_color_state = target_color_state,
};
fb = get_target_framebuffer (node, paint_context); fb = get_target_framebuffer (node, paint_context);
pango_layout_get_pixel_extents (tnode->layout, NULL, &extents); 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[0],
op->op.texrect[1], op->op.texrect[1],
&tnode->color, &tnode->color,
setup_pango_pipeline, color_state,
&pango_pipeline_data); target_color_state);
if (clipped) if (clipped)
cogl_framebuffer_pop_clip (fb); cogl_framebuffer_pop_clip (fb);

View File

@ -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); 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 static void
paint_selection_rectangle (ClutterText *self, paint_selection_rectangle (ClutterText *self,
const ClutterActorBox *box, const ClutterActorBox *box,
@ -1987,7 +1966,6 @@ paint_selection_rectangle (ClutterText *self,
clutter_paint_context_get_target_color_state (paint_context); clutter_paint_context_get_target_color_state (paint_context);
CoglColor cogl_color = { 0, }; CoglColor cogl_color = { 0, };
const CoglColor *color; const CoglColor *color;
PangoPipelineData pango_pipeline_data = {};
/* Paint selection background */ /* Paint selection background */
if (priv->selection_color_set) if (priv->selection_color_set)
@ -2005,10 +1983,6 @@ paint_selection_rectangle (ClutterText *self,
cogl_color_premultiply (&cogl_color); cogl_color_premultiply (&cogl_color);
cogl_pipeline_set_color (color_pipeline, &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, clutter_color_state_add_pipeline_transform (color_state,
target_color_state, target_color_state,
color_pipeline); color_pipeline);
@ -2032,8 +2006,7 @@ paint_selection_rectangle (ClutterText *self,
paint_opacity / 255.0f * color->alpha / 255.0f); paint_opacity / 255.0f * color->alpha / 255.0f);
clutter_show_layout (fb, layout, priv->text_x, 0, &cogl_color, clutter_show_layout (fb, layout, priv->text_x, 0, &cogl_color,
setup_pango_pipeline, color_state, target_color_state);
&pango_pipeline_data);
cogl_framebuffer_pop_clip (fb); cogl_framebuffer_pop_clip (fb);
g_object_unref (color_pipeline); g_object_unref (color_pipeline);
@ -2707,7 +2680,6 @@ clutter_text_paint (ClutterActor *self,
float alloc_width; float alloc_width;
float alloc_height; float alloc_height;
float resource_scale; float resource_scale;
PangoPipelineData pango_pipeline_data = {};
fb = clutter_paint_context_get_framebuffer (paint_context); fb = clutter_paint_context_get_framebuffer (paint_context);
@ -2860,13 +2832,8 @@ clutter_text_paint (ClutterActor *self,
priv->text_color.blue / 255.0f, priv->text_color.blue / 255.0f,
real_opacity / 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, clutter_show_layout (fb, layout, priv->text_x, priv->text_y, &color,
setup_pango_pipeline, color_state, target_color_state);
&pango_pipeline_data);
selection_paint (text, fb, paint_context); selection_paint (text, fb, paint_context);

View File

@ -393,8 +393,8 @@ _cogl_framebuffer_draw_display_list_texture (CoglFramebuffer *fb,
void void
cogl_pango_display_list_render (CoglFramebuffer *fb, cogl_pango_display_list_render (CoglFramebuffer *fb,
CoglPangoDisplayList *dl, CoglPangoDisplayList *dl,
ClutterPipelineSetup pipeline_setup, ClutterColorState *color_state,
gpointer pipeline_setup_user_data, ClutterColorState *target_color_state,
const CoglColor *color) const CoglColor *color)
{ {
GSList *l; GSList *l;
@ -434,7 +434,10 @@ cogl_pango_display_list_render (CoglFramebuffer *fb,
cogl_pipeline_set_color (pipeline, &draw_color); 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) switch (node->type)
{ {

View File

@ -73,8 +73,8 @@ _cogl_pango_display_list_add_trapezoid (CoglPangoDisplayList *dl,
void void
cogl_pango_display_list_render (CoglFramebuffer *framebuffer, cogl_pango_display_list_render (CoglFramebuffer *framebuffer,
CoglPangoDisplayList *dl, CoglPangoDisplayList *dl,
ClutterPipelineSetup pipeline_setup, ClutterColorState *color_state,
gpointer pipeline_setup_user_data, ClutterColorState *target_color_state,
const CoglColor *color); const CoglColor *color);
void void

View File

@ -37,6 +37,7 @@
#include <pango/pango.h> #include <pango/pango.h>
#include "clutter/clutter-color-state.h"
#include "cogl/cogl.h" #include "cogl/cogl.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -57,10 +58,6 @@ _cogl_pango_renderer_new (CoglContext *context);
void void
clutter_ensure_glyph_cache_for_layout (PangoLayout *layout); clutter_ensure_glyph_cache_for_layout (PangoLayout *layout);
typedef void (* ClutterPipelineSetup) (CoglPipeline *pipeline,
gpointer user_data);
/** /**
* clutter_show_layout: (skip) * clutter_show_layout: (skip)
* @framebuffer: A #CoglFramebuffer to draw too. * @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. * @y) within the `framebuffer`'s current model-view coordinate space.
*/ */
void void
clutter_show_layout (CoglFramebuffer *framebuffer, clutter_show_layout (CoglFramebuffer *framebuffer,
PangoLayout *layout, PangoLayout *layout,
float x, float x,
float y, float y,
const CoglColor *color, const CoglColor *color,
ClutterPipelineSetup pipeline_setup, ClutterColorState *color_state,
gpointer pipeline_setup_userdata); ClutterColorState *target_color_state);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PangoRenderer, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (PangoRenderer, g_object_unref)

View File

@ -258,13 +258,13 @@ cogl_pango_render_qdata_destroy (CoglPangoLayoutQdata *qdata)
} }
void void
clutter_show_layout (CoglFramebuffer *fb, clutter_show_layout (CoglFramebuffer *fb,
PangoLayout *layout, PangoLayout *layout,
float x, float x,
float y, float y,
const CoglColor *color, const CoglColor *color,
ClutterPipelineSetup pipeline_setup, ClutterColorState *color_state,
gpointer pipeline_setup_userdata) ClutterColorState *target_color_state)
{ {
CoglPangoRenderer *renderer; CoglPangoRenderer *renderer;
CoglPangoLayoutQdata *qdata; CoglPangoLayoutQdata *qdata;
@ -321,7 +321,7 @@ clutter_show_layout (CoglFramebuffer *fb,
cogl_pango_display_list_render (fb, cogl_pango_display_list_render (fb,
qdata->display_list, qdata->display_list,
pipeline_setup, pipeline_setup_userdata, color_state, target_color_state,
color); color);
cogl_framebuffer_pop_matrix (fb); cogl_framebuffer_pop_matrix (fb);