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

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

View File

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

View File

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

View File

@ -37,6 +37,7 @@
#include <pango/pango.h>
#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)

View File

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