[gtk+/wip/matthiasc/fancy-overlay] Try to combine blur and color matrix filters
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/fancy-overlay] Try to combine blur and color matrix filters
- Date: Mon, 4 Sep 2017 01:50:07 +0000 (UTC)
commit ec46ac920e46e2188aa48a62ac7e29e8969d0a00
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Sep 3 21:48:46 2017 -0400
Try to combine blur and color matrix filters
This does not quite work yet, for some reason.
gtk/gtkcssfiltervalue.c | 85 ++++++++++++++++++++++++++--------------
gtk/gtkcssfiltervalueprivate.h | 4 --
2 files changed, 55 insertions(+), 34 deletions(-)
---
diff --git a/gtk/gtkcssfiltervalue.c b/gtk/gtkcssfiltervalue.c
index bcf6b13..e69c82f 100644
--- a/gtk/gtkcssfiltervalue.c
+++ b/gtk/gtkcssfiltervalue.c
@@ -145,7 +145,7 @@ gtk_css_filter_init_identity (GtkCssFilter *filter,
#define G 0.7152
#define B 0.0722
-static void
+static gboolean
gtk_css_filter_get_matrix (const GtkCssFilter *filter,
graphene_matrix_t *matrix,
graphene_vec4_t *offset)
@@ -244,30 +244,36 @@ gtk_css_filter_get_matrix (const GtkCssFilter *filter,
case GTK_CSS_FILTER_NONE:
case GTK_CSS_FILTER_BLUR:
case GTK_CSS_FILTER_DROP_SHADOW:
+ return FALSE;
default:
g_assert_not_reached ();
break;
}
+
+ return TRUE;
}
#undef R
#undef G
#undef B
-static void
+static int
gtk_css_filter_value_compute_matrix (const GtkCssValue *value,
+ int first,
graphene_matrix_t *matrix,
graphene_vec4_t *offset)
{
graphene_matrix_t m, m2;
graphene_vec4_t o, o2;
- guint i;
+ int i;
- gtk_css_filter_get_matrix (&value->filters[0], matrix, offset);
+ if (!gtk_css_filter_get_matrix (&value->filters[first], matrix, offset))
+ return first;
- for (i = 1; i < value->n_filters; i++)
+ for (i = first + 1; i < value->n_filters; i++)
{
- gtk_css_filter_get_matrix (&value->filters[i], &m, &o);
+ if (!gtk_css_filter_get_matrix (&value->filters[i], &m, &o))
+ return i;
graphene_matrix_multiply (matrix, &m, &m2);
graphene_matrix_transform_vec4 (&m, offset, &o2);
@@ -275,6 +281,8 @@ gtk_css_filter_value_compute_matrix (const GtkCssValue *value,
graphene_matrix_init_from_matrix (matrix, &m2);
graphene_vec4_add (&o, &o2, offset);
}
+
+ return value->n_filters;
}
static void
@@ -846,50 +854,67 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
return value;
}
-gboolean
-gtk_css_filter_value_get_color_matrix (const GtkCssValue *filter,
- graphene_matrix_t *matrix,
- graphene_vec4_t *offset)
-{
- g_return_val_if_fail (filter->class == >K_CSS_VALUE_FILTER, FALSE);
- g_return_val_if_fail (matrix != NULL, FALSE);
-
- gtk_css_filter_value_compute_matrix (filter, matrix, offset);
-
- return TRUE;
-}
-
void
gtk_css_filter_value_push_snapshot (const GtkCssValue *filter,
GtkSnapshot *snapshot)
{
graphene_matrix_t matrix;
graphene_vec4_t offset;
+ int i, j;
+ double radius;
if (gtk_css_filter_value_is_none (filter))
return;
- if (filter->filters[0].type == GTK_CSS_FILTER_BLUR)
+ i = 0;
+ while (i < filter->n_filters)
{
- double radius = _gtk_css_number_value_get (filter->filters[0].blur.value, 100.0);
- gtk_snapshot_push_blur (snapshot, radius, "CssFilter Blur<%g>", radius);
- return; /* FIXME */
- }
+ j = gtk_css_filter_value_compute_matrix (filter, i, &matrix, &offset);
+ if (i < j)
+ gtk_snapshot_push_color_matrix (snapshot,
+ &matrix,
+ &offset,
+ "CssFilter ColorMatrix<%d-%d>", i, j);
- gtk_css_filter_value_get_color_matrix (filter, &matrix, &offset);
+ if (j < filter->n_filters)
+ {
+ if (filter->filters[j].type == GTK_CSS_FILTER_BLUR)
+ {
+ radius = _gtk_css_number_value_get (filter->filters[j].blur.value, 100.0);
+ gtk_snapshot_push_blur (snapshot, radius, "CssFilter Blur<%d, radius %g>", j, radius);
+ }
+ else
+ g_warning ("Don't know how to handle filter type %d", filter->filters[j].type);
+ }
- gtk_snapshot_push_color_matrix (snapshot,
- &matrix,
- &offset,
- "CssFilter<%u>", filter->n_filters);
+ i = j + 1;
+ }
}
void
gtk_css_filter_value_pop_snapshot (const GtkCssValue *filter,
GtkSnapshot *snapshot)
{
+ int i, j;
+
if (gtk_css_filter_value_is_none (filter))
return;
- gtk_snapshot_pop (snapshot);
+ i = 0;
+ while (i < filter->n_filters)
+ {
+ for (j = i; j < filter->n_filters; j++)
+ {
+ if (filter->filters[j].type == GTK_CSS_FILTER_BLUR)
+ break;
+ }
+
+ if (i < j)
+ gtk_snapshot_pop (snapshot);
+
+ if (j < filter->n_filters)
+ gtk_snapshot_pop (snapshot);
+
+ i = j + 1;
+ }
}
diff --git a/gtk/gtkcssfiltervalueprivate.h b/gtk/gtkcssfiltervalueprivate.h
index 796ba42..b9eabaa 100644
--- a/gtk/gtkcssfiltervalueprivate.h
+++ b/gtk/gtkcssfiltervalueprivate.h
@@ -28,10 +28,6 @@ G_BEGIN_DECLS
GtkCssValue * gtk_css_filter_value_new_none (void);
GtkCssValue * gtk_css_filter_value_parse (GtkCssParser *parser);
-gboolean gtk_css_filter_value_get_color_matrix (const GtkCssValue *filter,
- graphene_matrix_t *matrix,
- graphene_vec4_t *offset);
-
void gtk_css_filter_value_push_snapshot (const GtkCssValue *filter,
GtkSnapshot *snapshot);
void gtk_css_filter_value_pop_snapshot (const GtkCssValue *filter,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]