gsk: Add gsk_clip_node_new()

The node is a simple clipping node: It does a rectangular clip of its
contents.
This commit is contained in:
Benjamin Otte 2016-12-13 09:37:51 +01:00
parent 68a54ae81f
commit 1f988d8b05
6 changed files with 142 additions and 1 deletions

View File

@ -45,6 +45,8 @@ gsk_transform_node_new
gsk_transform_node_get_child
gsk_opacity_node_new
gsk_opacity_node_get_child
gsk_clip_node_new
gsk_clip_node_get_child
<SUBSECTION Standard>
GSK_IS_RENDER_NODE
GSK_RENDER_NODE

View File

@ -32,6 +32,7 @@
* @GSK_TRANSFORM_NODE: A node that renders its child after applying a
* matrix transform
* @GSK_OPACITY_NODE: A node that changes the opacity of its child
* @GSK_CLIP_NODE: A node that clips its child to a rectangular area
*
* The type of a node determines what the node is rendering.
*
@ -44,7 +45,8 @@ typedef enum {
GSK_COLOR_NODE,
GSK_TEXTURE_NODE,
GSK_TRANSFORM_NODE,
GSK_OPACITY_NODE
GSK_OPACITY_NODE,
GSK_CLIP_NODE
} GskRenderNodeType;
/**

View File

@ -79,6 +79,12 @@ GskRenderNode * gsk_opacity_node_new (GskRenderNode
GDK_AVAILABLE_IN_3_90
GskRenderNode * gsk_opacity_node_get_child (GskRenderNode *node);
GDK_AVAILABLE_IN_3_90
GskRenderNode * gsk_clip_node_new (GskRenderNode *child,
const graphene_rect_t *clip);
GDK_AVAILABLE_IN_3_90
GskRenderNode * gsk_clip_node_get_child (GskRenderNode *node);
GDK_AVAILABLE_IN_3_90
void gsk_render_node_set_blend_mode (GskRenderNode *node,
GskBlendMode blend_mode);

View File

@ -819,3 +819,128 @@ gsk_opacity_node_get_opacity (GskRenderNode *node)
return self->opacity;
}
/*** GSK_CLIP_NODE ***/
typedef struct _GskClipNode GskClipNode;
struct _GskClipNode
{
GskRenderNode render_node;
GskRenderNode *child;
graphene_rect_t clip;
};
static void
gsk_clip_node_finalize (GskRenderNode *node)
{
GskClipNode *self = (GskClipNode *) node;
gsk_render_node_unref (self->child);
}
static void
gsk_clip_node_make_immutable (GskRenderNode *node)
{
GskClipNode *self = (GskClipNode *) node;
gsk_render_node_make_immutable (self->child);
}
static void
gsk_clip_node_draw (GskRenderNode *node,
cairo_t *cr)
{
GskClipNode *self = (GskClipNode *) node;
cairo_save (cr);
cairo_rectangle (cr,
self->clip.origin.x, self->clip.origin.y,
self->clip.size.width, self->clip.size.height);
cairo_clip (cr);
gsk_render_node_draw (self->child, cr);
cairo_restore (cr);
}
static void
gsk_clip_node_get_bounds (GskRenderNode *node,
graphene_rect_t *bounds)
{
GskClipNode *self = (GskClipNode *) node;
graphene_rect_t child_bounds;
gsk_render_node_get_bounds (self->child, &child_bounds);
graphene_rect_intersection (&self->clip, &child_bounds, bounds);
}
static const GskRenderNodeClass GSK_CLIP_NODE_CLASS = {
GSK_CLIP_NODE,
sizeof (GskClipNode),
"GskClipNode",
gsk_clip_node_finalize,
gsk_clip_node_make_immutable,
gsk_clip_node_draw,
gsk_clip_node_get_bounds
};
/**
* gsk_clip_node_new:
* @child: The node to draw
* @clip: The clip to apply
*
* Creates a #GskRenderNode that will clip the @child to the area
* given by @clip.
*
* Returns: A new #GskRenderNode
*
* Since: 3.90
*/
GskRenderNode *
gsk_clip_node_new (GskRenderNode *child,
const graphene_rect_t *clip)
{
GskClipNode *self;
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
g_return_val_if_fail (clip != NULL, NULL);
self = (GskClipNode *) gsk_render_node_new (&GSK_CLIP_NODE_CLASS);
self->child = gsk_render_node_ref (child);
graphene_rect_normalize_r (clip, &self->clip);
return &self->render_node;
}
/**
* gsk_clip_node_get_child:
* @node: a clip @GskRenderNode
*
* Gets the child node that is getting clipped by the given @node.
*
* Returns: (transfer none): The child that is getting clipped
**/
GskRenderNode *
gsk_clip_node_get_child (GskRenderNode *node)
{
GskClipNode *self = (GskClipNode *) node;
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CLIP_NODE), NULL);
return self->child;
}
const graphene_rect_t *
gsk_clip_node_peek_clip (GskRenderNode *node)
{
GskClipNode *self = (GskClipNode *) node;
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CLIP_NODE), NULL);
return &self->clip;
}

View File

@ -60,6 +60,8 @@ GskTexture *gsk_texture_node_get_texture (GskRenderNode *node);
const GdkRGBA *gsk_color_node_peek_color (GskRenderNode *node);
const graphene_rect_t * gsk_clip_node_peek_clip (GskRenderNode *node);
void gsk_transform_node_get_transform (GskRenderNode *node, graphene_matrix_t *transform);
GskBlendMode gsk_render_node_get_blend_mode (GskRenderNode *node);

View File

@ -534,6 +534,10 @@ append_node (GtkTreeModelRenderNode *nodemodel,
append_node (nodemodel, gsk_opacity_node_get_child (node), priv->nodes->len - 1);
break;
case GSK_CLIP_NODE:
append_node (nodemodel, gsk_clip_node_get_child (node), priv->nodes->len - 1);
break;
case GSK_CONTAINER_NODE:
{
gint elt_index;