diff --git a/gsk/gskrenderer.c b/gsk/gskrenderer.c index 8738067628..b766a73c06 100644 --- a/gsk/gskrenderer.c +++ b/gsk/gskrenderer.c @@ -676,6 +676,11 @@ gsk_renderer_render (GskRenderer *renderer, g_clear_pointer (&priv->root_node, gsk_render_node_unref); } +static const GskRenderNodeClass GSK_CONTAINER_NODE_CLASS = { + GSK_CONTAINER_NODE, + "GskContainerNode" +}; + /** * gsk_renderer_create_render_node: * @renderer: a #GskRenderer @@ -691,7 +696,7 @@ gsk_renderer_create_render_node (GskRenderer *renderer) { g_return_val_if_fail (GSK_IS_RENDERER (renderer), NULL); - return gsk_render_node_new (GSK_CONTAINER_NODE); + return gsk_render_node_new (&GSK_CONTAINER_NODE_CLASS); } /*< private > diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c index 0d088403b0..6ac783624a 100644 --- a/gsk/gskrendernode.c +++ b/gsk/gskrendernode.c @@ -86,20 +86,21 @@ gsk_render_node_finalize (GskRenderNode *self) /*< private > * gsk_render_node_new: - * @type: type of the new node + * @node_class: class structure for this node * * Returns: (transfer full): the newly created #GskRenderNode */ GskRenderNode * -gsk_render_node_new (GskRenderNodeType type) +gsk_render_node_new (const GskRenderNodeClass *node_class) { GskRenderNode *self; - g_return_val_if_fail (type != GSK_NOT_A_RENDER_NODE, NULL); + g_return_val_if_fail (node_class != NULL, NULL); + g_return_val_if_fail (node_class->node_type != GSK_NOT_A_RENDER_NODE, NULL); self = g_slice_new0 (GskRenderNode); - self->type = type; + self->node_class = node_class; self->ref_count = 1; @@ -173,7 +174,7 @@ gsk_render_node_get_node_type (GskRenderNode *node) { g_return_val_if_fail (GSK_IS_RENDER_NODE (node), GSK_NOT_A_RENDER_NODE); - return node->type; + return node->node_class->node_type; } /** @@ -393,8 +394,7 @@ GskRenderNode * gsk_render_node_append_child (GskRenderNode *node, GskRenderNode *child) { - g_return_val_if_fail (GSK_IS_RENDER_NODE (node), NULL); - g_return_val_if_fail (node->type == GSK_CONTAINER_NODE, NULL); + g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CONTAINER_NODE), NULL); g_return_val_if_fail (GSK_IS_RENDER_NODE (child), node); g_return_val_if_fail (node->is_mutable, node); @@ -494,9 +494,8 @@ void gsk_render_node_set_bounds (GskRenderNode *node, const graphene_rect_t *bounds) { - g_return_if_fail (GSK_IS_RENDER_NODE (node)); + g_return_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CONTAINER_NODE)); g_return_if_fail (node->is_mutable); - g_return_if_fail (node->type == GSK_CONTAINER_NODE); if (bounds == NULL) graphene_rect_init_from_rect (&node->bounds, graphene_rect_zero ()); diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c index be1214d8b8..5b1cbf56cb 100644 --- a/gsk/gskrendernodeimpl.c +++ b/gsk/gskrendernodeimpl.c @@ -24,11 +24,15 @@ /*** GSK_TEXTURE_NODE ***/ +static const GskRenderNodeClass GSK_TEXTURE_NODE_CLASS = { + GSK_TEXTURE_NODE, + "GskTextureNode" +}; + GskTexture * gsk_texture_node_get_texture (GskRenderNode *node) { - g_return_val_if_fail (GSK_IS_RENDER_NODE (node), 0); - g_return_val_if_fail (node->type == GSK_TEXTURE_NODE, 0); + g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_TEXTURE_NODE), 0); return node->texture; } @@ -54,7 +58,7 @@ gsk_texture_node_new (GskTexture *texture, g_return_val_if_fail (GSK_IS_TEXTURE (texture), NULL); g_return_val_if_fail (bounds != NULL, NULL); - node = gsk_render_node_new (GSK_TEXTURE_NODE); + node = gsk_render_node_new (&GSK_TEXTURE_NODE_CLASS); node->texture = gsk_texture_ref (texture); graphene_rect_init_from_rect (&node->bounds, bounds); @@ -64,6 +68,11 @@ gsk_texture_node_new (GskTexture *texture, /*** GSK_CAIRO_NODE ***/ +static const GskRenderNodeClass GSK_CAIRO_NODE_CLASS = { + GSK_CAIRO_NODE, + "GskCairoNode" +}; + /*< private > * gsk_cairo_node_get_surface: * @node: a #GskRenderNode @@ -75,8 +84,7 @@ gsk_texture_node_new (GskTexture *texture, cairo_surface_t * gsk_cairo_node_get_surface (GskRenderNode *node) { - g_return_val_if_fail (GSK_IS_RENDER_NODE (node), NULL); - g_return_val_if_fail (node->type == GSK_CAIRO_NODE, NULL); + g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CAIRO_NODE), NULL); return node->surface; } @@ -100,7 +108,7 @@ gsk_cairo_node_new (const graphene_rect_t *bounds) g_return_val_if_fail (bounds != NULL, NULL); - node = gsk_render_node_new (GSK_CAIRO_NODE); + node = gsk_render_node_new (&GSK_CAIRO_NODE_CLASS); graphene_rect_init_from_rect (&node->bounds, bounds); @@ -129,8 +137,7 @@ gsk_cairo_node_get_draw_context (GskRenderNode *node, int width, height; cairo_t *res; - g_return_val_if_fail (GSK_IS_RENDER_NODE (node), NULL); - g_return_val_if_fail (node->type == GSK_CAIRO_NODE, NULL); + g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CAIRO_NODE), NULL); g_return_val_if_fail (node->is_mutable, NULL); g_return_val_if_fail (renderer == NULL || GSK_IS_RENDERER (renderer), NULL); diff --git a/gsk/gskrendernodeprivate.h b/gsk/gskrendernodeprivate.h index f67913add3..3908f94880 100644 --- a/gsk/gskrendernodeprivate.h +++ b/gsk/gskrendernodeprivate.h @@ -6,9 +6,13 @@ G_BEGIN_DECLS +typedef struct _GskRenderNodeClass GskRenderNodeClass; + +#define GSK_IS_RENDER_NODE_TYPE(node,type) (GSK_IS_RENDER_NODE (node) && (node)->node_class->node_type == (type)) + struct _GskRenderNode { - GskRenderNodeType type; + const GskRenderNodeClass *node_class; volatile int ref_count; @@ -59,7 +63,13 @@ struct _GskRenderNode gboolean needs_world_matrix_update : 1; }; -GskRenderNode *gsk_render_node_new (GskRenderNodeType type); +struct _GskRenderNodeClass +{ + GskRenderNodeType node_type; + const char *type_name; +}; + +GskRenderNode *gsk_render_node_new (const GskRenderNodeClass *node_class); void gsk_render_node_make_immutable (GskRenderNode *node);