gsk: Add gsk_render_node_serialize/deserialize()

This does a conversion to/from GBytes and is intended for writing tests.

It's really crude but it works.
And that probably means Alex will (ab)use it for broadway.
This commit is contained in:
Benjamin Otte 2016-12-21 05:43:14 +01:00
parent 3a38bc9bf7
commit c88d279416
4 changed files with 989 additions and 0 deletions

View File

@ -285,4 +285,54 @@ gsk_render_node_draw (GskRenderNode *node,
cairo_restore (cr); cairo_restore (cr);
} }
#define GSK_RENDER_NODE_SERIALIZATION_VERSION 0
#define GSK_RENDER_NODE_SERIALIZATION_ID "GskRenderNode"
GBytes *
gsk_render_node_serialize (GskRenderNode *node)
{
GVariant *node_variant, *variant;
GBytes *result;
node_variant = gsk_render_node_serialize_node (node);
variant = g_variant_new ("(suuv)",
GSK_RENDER_NODE_SERIALIZATION_ID,
(guint32) GSK_RENDER_NODE_SERIALIZATION_VERSION,
(guint32) gsk_render_node_get_node_type (node),
node_variant);
result = g_variant_get_data_as_bytes (variant);
g_variant_unref (variant);
return result;
}
GskRenderNode *
gsk_render_node_deserialize (GBytes *bytes)
{
char *id_string;
guint32 version, node_type;
GVariant *variant, *node_variant;
GskRenderNode *node = NULL;
variant = g_variant_new_from_bytes (G_VARIANT_TYPE ("(suuv)"), bytes, FALSE);
g_variant_get (variant, "(suuv)", &id_string, &version, &node_type, &node_variant);
if (!g_str_equal (id_string, GSK_RENDER_NODE_SERIALIZATION_ID))
goto out;
if (version != GSK_RENDER_NODE_SERIALIZATION_VERSION)
goto out;
node = gsk_render_node_deserialize_node (node_type, node_variant);
out:
g_free (id_string);
g_variant_unref (node_variant);
g_variant_unref (variant);
return node;
}

View File

@ -170,6 +170,12 @@ const char * gsk_render_node_get_name (GskRenderNode *
GDK_AVAILABLE_IN_3_90 GDK_AVAILABLE_IN_3_90
void gsk_render_node_draw (GskRenderNode *node, void gsk_render_node_draw (GskRenderNode *node,
cairo_t *cr); cairo_t *cr);
GDK_AVAILABLE_IN_3_90
GBytes * gsk_render_node_serialize (GskRenderNode *node);
GDK_AVAILABLE_IN_3_90
GskRenderNode * gsk_render_node_deserialize (GBytes *bytes);
G_END_DECLS G_END_DECLS
#endif /* __GSK_RENDER_NODE_H__ */ #endif /* __GSK_RENDER_NODE_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -34,18 +34,24 @@ struct _GskRenderNodeClass
void (* finalize) (GskRenderNode *node); void (* finalize) (GskRenderNode *node);
void (* draw) (GskRenderNode *node, void (* draw) (GskRenderNode *node,
cairo_t *cr); cairo_t *cr);
GVariant * (* serialize) (GskRenderNode *node);
GskRenderNode * (* deserialize) (GVariant *variant);
}; };
GskRenderNode *gsk_render_node_new (const GskRenderNodeClass *node_class, gsize extra_size); GskRenderNode *gsk_render_node_new (const GskRenderNodeClass *node_class, gsize extra_size);
void gsk_render_node_get_bounds (GskRenderNode *node, void gsk_render_node_get_bounds (GskRenderNode *node,
graphene_rect_t *frame); graphene_rect_t *frame);
GVariant * gsk_render_node_serialize_node (GskRenderNode *node);
GskRenderNode * gsk_render_node_deserialize_node (GskRenderNodeType type, GVariant *variant);
double gsk_opacity_node_get_opacity (GskRenderNode *node); double gsk_opacity_node_get_opacity (GskRenderNode *node);
const GskRoundedRect * gsk_border_node_peek_outline (GskRenderNode *node); const GskRoundedRect * gsk_border_node_peek_outline (GskRenderNode *node);
float gsk_border_node_get_width (GskRenderNode *node, guint i); float gsk_border_node_get_width (GskRenderNode *node, guint i);
const GdkRGBA * gsk_border_node_peek_color (GskRenderNode *node, guint i); const GdkRGBA * gsk_border_node_peek_color (GskRenderNode *node, guint i);
GskRenderNode *gsk_cairo_node_new_for_surface (const graphene_rect_t *bounds, cairo_surface_t *surface);
cairo_surface_t *gsk_cairo_node_get_surface (GskRenderNode *node); cairo_surface_t *gsk_cairo_node_get_surface (GskRenderNode *node);
GskTexture *gsk_texture_node_get_texture (GskRenderNode *node); GskTexture *gsk_texture_node_get_texture (GskRenderNode *node);