snapshot: Reorder color matrix nodes containing a transform node

A color matrix node that contains a transform node can also be expressed
the other way around, as a transform node containing a color matrix
node.

In the general case, the color matrix node will have to draw its
child to a texture so it can color every pixel of that texture, but the
renderers can short-cut this if the child of the color matrix node is
already a texture node. So if we have a node tree like

Color Matrix
    - Transform
        - Texture

The renderer would have to either check the grandchild of the color
matrix or simply fall back to rendering the transform node to a texture.

In the new configuration:

Transform
    - Color Matrix
        - Texture

The renderer can easily see that the child node of the color matrix node
is a texture, and skip rendering it to a texture.

This is for example happening in current Adwaita for spinners, which are
rotated symbolics.
This commit is contained in:
Timm Bäder 2019-11-29 09:14:55 +01:00
parent bc7b37d307
commit 05e9a9b572

View File

@ -433,7 +433,6 @@ merge_color_matrix_nodes (const graphene_matrix_t *matrix2,
const graphene_vec4_t *offset2,
GskRenderNode *child)
{
GskRenderNode *grandchild = gsk_render_node_ref (gsk_color_matrix_node_get_child (child));
const graphene_matrix_t *mat1 = gsk_color_matrix_node_peek_color_matrix (child);
const graphene_vec4_t *offset1 = gsk_color_matrix_node_peek_color_offset (child);
graphene_matrix_t mat2 = *matrix2;
@ -454,11 +453,9 @@ merge_color_matrix_nodes (const graphene_matrix_t *matrix2,
graphene_vec4_add (&off2, offset1, &off2);
graphene_matrix_multiply (mat1, &mat2, &mat2);
gsk_render_node_unref (child);
child = NULL;
result = gsk_color_matrix_node_new (grandchild, &mat2, &off2);
gsk_render_node_unref (grandchild);
result = gsk_color_matrix_node_new (gsk_color_matrix_node_get_child (child),
&mat2, &off2);
return result;
}
@ -480,6 +477,30 @@ gtk_snapshot_collect_color_matrix (GtkSnapshot *snapshot,
result = merge_color_matrix_nodes (&state->data.color_matrix.matrix,
&state->data.color_matrix.offset,
node);
gsk_render_node_unref (node);
}
else if (gsk_render_node_get_node_type (node) == GSK_TRANSFORM_NODE)
{
GskRenderNode *transform_child = gsk_transform_node_get_child (node);
GskRenderNode *color_matrix;
if (gsk_render_node_get_node_type (transform_child) == GSK_COLOR_MATRIX_NODE)
{
color_matrix = merge_color_matrix_nodes (&state->data.color_matrix.matrix,
&state->data.color_matrix.offset,
transform_child);
}
else
{
color_matrix = gsk_color_matrix_node_new (transform_child,
&state->data.color_matrix.matrix,
&state->data.color_matrix.offset);
}
result = gsk_transform_node_new (color_matrix,
gsk_transform_node_get_transform (node));
gsk_render_node_unref (color_matrix);
gsk_render_node_unref (node);
node = NULL;
}
else
{