From f6f1dfb55d934014256954eade149115dbf231a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Wed, 6 Dec 2017 15:53:15 +0100 Subject: [PATCH] snapshot: Collapse color matrix nodes Color matrix nodes as the child of other color matrix nodes can happen quite frequently as a result of CSS. To ease the renderer implementations, collapse chains of color matrix nodes into one. --- gtk/gtksnapshot.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index 702ea036a6..a9882db151 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -404,14 +404,45 @@ gtk_snapshot_collect_color_matrix (GtkSnapshot *snapshot, if (node == NULL) return NULL; - color_matrix_node = gsk_color_matrix_node_new (node, - &state->data.color_matrix.matrix, - &state->data.color_matrix.offset); + if (gsk_render_node_get_node_type (node) == GSK_COLOR_MATRIX_NODE) + { + GskRenderNode *child = gsk_render_node_ref (gsk_color_matrix_node_get_child (node)); + const graphene_matrix_t *mat1 = gsk_color_matrix_node_peek_color_matrix (node); + graphene_matrix_t mat2; + graphene_vec4_t offset2; + + /* color matrix node: color = mat * p + offset; for a pixel p. + * color = mat1 * (mat2 * p + offset2) + offset1; + * = mat1 * mat2 * p + offset2 * mat1 + offset1 + * = (mat1 * mat2) * p + (offset2 * mat1 + offset1) + * Which this code does. + * mat1 and offset1 come from @child. + */ + + mat2 = state->data.color_matrix.matrix; + offset2 = state->data.color_matrix.offset; + graphene_matrix_transform_vec4 (mat1, &offset2, &offset2); + graphene_vec4_add (&offset2, gsk_color_matrix_node_peek_color_offset (node), &offset2); + + graphene_matrix_multiply (mat1, &mat2, &mat2); + + gsk_render_node_unref (node); + node = NULL; + color_matrix_node = gsk_color_matrix_node_new (child, &mat2, &offset2); + + gsk_render_node_unref (child); + } + else + { + color_matrix_node = gsk_color_matrix_node_new (node, + &state->data.color_matrix.matrix, + &state->data.color_matrix.offset); + gsk_render_node_unref (node); + } + if (name) gsk_render_node_set_name (color_matrix_node, name); - gsk_render_node_unref (node); - return color_matrix_node; }