[mutter/wip/carlosg/drop-tesselator: 1/3] clutter/text: Drop usage of ClutterPath
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/carlosg/drop-tesselator: 1/3] clutter/text: Drop usage of ClutterPath
- Date: Sat, 14 Mar 2020 17:45:48 +0000 (UTC)
commit a0d500ab175c156bf788ce4684ee6a99335b9ed9
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Mar 14 18:06:47 2020 +0100
clutter/text: Drop usage of ClutterPath
In the unlikely case we have multiple rectangles in our selection
(selection spanning several lines, or across LTR/RTL bounds), paint each
of those instead of setting a CoglPath-based clip/fill.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1126
clutter/clutter/clutter-text.c | 109 +++++++++++++++++++++--------------------
1 file changed, 56 insertions(+), 53 deletions(-)
---
diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c
index 8efbfa07c..198fe5426 100644
--- a/clutter/clutter/clutter-text.c
+++ b/clutter/clutter/clutter-text.c
@@ -1897,14 +1897,6 @@ clutter_text_foreach_selection_rectangle (ClutterText *self,
g_free (utf8);
}
-static void
-add_selection_rectangle_to_path (ClutterText *text,
- const ClutterActorBox *box,
- gpointer user_data)
-{
- cogl_path_rectangle (user_data, box->x1, box->y1, box->x2, box->y2);
-}
-
static void
clutter_text_foreach_selection_rectangle_prescaled (ClutterText *self,
ClutterTextSelectionFunc func,
@@ -1913,6 +1905,60 @@ clutter_text_foreach_selection_rectangle_prescaled (ClutterText *se
clutter_text_foreach_selection_rectangle (self, 1.0f, func, user_data);
}
+static void
+paint_selection_rectangle (ClutterText *self,
+ const ClutterActorBox *box,
+ gpointer user_data)
+{
+ CoglFramebuffer *fb = user_data;
+ ClutterTextPrivate *priv = self->priv;
+ ClutterActor *actor = CLUTTER_ACTOR (self);
+ guint8 paint_opacity = clutter_actor_get_paint_opacity (actor);
+ CoglPipeline *color_pipeline = cogl_pipeline_copy (default_color_pipeline);
+ PangoLayout *layout = clutter_text_get_layout (self);
+ CoglColor cogl_color = { 0, };
+ const ClutterColor *color;
+
+ /* Paint selection background */
+ if (priv->selection_color_set)
+ color = &priv->selection_color;
+ else if (priv->cursor_color_set)
+ color = &priv->cursor_color;
+ else
+ color = &priv->text_color;
+
+ cogl_color_init_from_4ub (&cogl_color,
+ color->red,
+ color->green,
+ color->blue,
+ paint_opacity * color->alpha / 255);
+ cogl_color_premultiply (&cogl_color);
+ cogl_pipeline_set_color (color_pipeline, &cogl_color);
+
+ cogl_framebuffer_push_rectangle_clip (fb,
+ box->x1, box->y1,
+ box->x2, box->y2);
+ cogl_framebuffer_draw_rectangle (fb, color_pipeline,
+ box->x1, box->y1,
+ box->x2, box->y2);
+
+ if (priv->selected_text_color_set)
+ color = &priv->selected_text_color;
+ else
+ color = &priv->text_color;
+
+ cogl_color_init_from_4ub (&cogl_color,
+ color->red,
+ color->green,
+ color->blue,
+ paint_opacity * color->alpha / 255);
+
+ cogl_pango_show_layout (fb, layout, priv->text_x, 0, &cogl_color);
+
+ cogl_framebuffer_pop_clip (fb);
+ cogl_object_unref (color_pipeline);
+}
+
/* Draws the selected text, its background, and the cursor */
static void
selection_paint (ClutterText *self,
@@ -1955,52 +2001,9 @@ selection_paint (ClutterText *self,
}
else
{
- /* Paint selection background first */
- CoglPipeline *color_pipeline = cogl_pipeline_copy (default_color_pipeline);
- PangoLayout *layout = clutter_text_get_layout (self);
- CoglPath *selection_path = cogl_path_new ();
- CoglColor cogl_color = { 0, };
-
- /* Paint selection background */
- if (priv->selection_color_set)
- color = &priv->selection_color;
- else if (priv->cursor_color_set)
- color = &priv->cursor_color;
- else
- color = &priv->text_color;
-
- cogl_color_init_from_4ub (&cogl_color,
- color->red,
- color->green,
- color->blue,
- paint_opacity * color->alpha / 255);
- cogl_color_premultiply (&cogl_color);
- cogl_pipeline_set_color (color_pipeline, &cogl_color);
-
clutter_text_foreach_selection_rectangle_prescaled (self,
- add_selection_rectangle_to_path,
- selection_path);
-
- cogl_framebuffer_fill_path (fb, color_pipeline, selection_path);
-
- /* Paint selected text */
- cogl_framebuffer_push_path_clip (fb, selection_path);
- cogl_object_unref (selection_path);
-
- if (priv->selected_text_color_set)
- color = &priv->selected_text_color;
- else
- color = &priv->text_color;
-
- cogl_color_init_from_4ub (&cogl_color,
- color->red,
- color->green,
- color->blue,
- paint_opacity * color->alpha / 255);
-
- cogl_pango_show_layout (fb, layout, priv->text_x, 0, &cogl_color);
-
- cogl_framebuffer_pop_clip (fb);
+ paint_selection_rectangle,
+ fb);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]