diff options
author | Benjamin Otte <otte@redhat.com> | 2016-12-13 00:11:06 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2016-12-20 18:01:10 +0100 |
commit | 67fb129ed7db377bd179757a77514c9ce0d3557f (patch) | |
tree | c4e1edd4635e05e8f2064a3f6433ed232fd9d94c /gsk/gskrendernodeimpl.c | |
parent | 19753062c4e593507472638ae8a3bc0bd435e6f2 (diff) | |
download | gtk+-67fb129ed7db377bd179757a77514c9ce0d3557f.tar.gz |
gsk: gsk_render_node_set_transform() => GskTransformNode
Instead of having a setter for the transform, have a GskTransformNode.
Most of the oprations that GTK does do not require a transform, so it
doesn't make sense to have it as a primary attribute.
Also, changing the transform requires updating the uniforms of the GL
renderer, so we're happy if we can avoid that.
Diffstat (limited to 'gsk/gskrendernodeimpl.c')
-rw-r--r-- | gsk/gskrendernodeimpl.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c index 40c2ad6365..e719a1d6e9 100644 --- a/gsk/gskrendernodeimpl.c +++ b/gsk/gskrendernodeimpl.c @@ -424,3 +424,112 @@ gsk_container_node_get_child (GskRenderNode *node, return g_ptr_array_index (container->children, idx); } +/*** GSK_TRANSFORM_NODE ***/ + +typedef struct _GskTransformNode GskTransformNode; + +struct _GskTransformNode +{ + GskRenderNode render_node; + + GskRenderNode *child; + graphene_matrix_t transform; +}; + +static void +gsk_transform_node_finalize (GskRenderNode *node) +{ + GskTransformNode *self = (GskTransformNode *) node; + + gsk_render_node_unref (self->child); +} + +static void +gsk_transform_node_make_immutable (GskRenderNode *node) +{ + GskTransformNode *self = (GskTransformNode *) node; + + gsk_render_node_make_immutable (self->child); +} + +static void +gsk_transform_node_get_bounds (GskRenderNode *node, + graphene_rect_t *bounds) +{ + GskTransformNode *self = (GskTransformNode *) node; + graphene_rect_t child_bounds; + + gsk_render_node_get_bounds (self->child, &child_bounds); + + graphene_matrix_transform_bounds (&self->transform, + &child_bounds, + bounds); +} + +static const GskRenderNodeClass GSK_TRANSFORM_NODE_CLASS = { + GSK_TRANSFORM_NODE, + sizeof (GskTransformNode), + "GskTransformNode", + gsk_transform_node_finalize, + gsk_transform_node_make_immutable, + gsk_transform_node_get_bounds +}; + +/** + * gsk_transform_node_new: + * @child: The node to transform + * @transform: The transform to apply + * + * Creates a #GskRenderNode that will transform the given @child + * with the given @transform. + * + * Returns: A new #GskRenderNode + * + * Since: 3.90 + */ +GskRenderNode * +gsk_transform_node_new (GskRenderNode *child, + const graphene_matrix_t *transform) +{ + GskTransformNode *self; + + g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL); + g_return_val_if_fail (transform != NULL, NULL); + + self = (GskTransformNode *) gsk_render_node_new (&GSK_TRANSFORM_NODE_CLASS); + + self->child = gsk_render_node_ref (child); + graphene_matrix_init_from_matrix (&self->transform, transform); + + return &self->render_node; +} + +/** + * gsk_transform_node_get_child: + * @node: a transform @GskRenderNode + * + * Gets the child node that is getting transformed by the given @node. + * + * Returns: (transfer none): The child that is getting transformed + **/ +GskRenderNode * +gsk_transform_node_get_child (GskRenderNode *node) +{ + GskTransformNode *self = (GskTransformNode *) node; + + g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_TRANSFORM_NODE), NULL); + + return self->child; +} + +void +gsk_transform_node_get_transform (GskRenderNode *node, + graphene_matrix_t *transform) +{ + GskTransformNode *self = (GskTransformNode *) node; + + g_return_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_TRANSFORM_NODE)); + + graphene_matrix_init_from_matrix (transform, &self->transform); +} + |