From 5e089c43453e34432f6c9e47b2d064129f391a56 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 23 Dec 2016 05:58:07 +0100 Subject: [PATCH] gsk: Add gsk_render_node_write_to_file() For when you're in a debugger and need to have a closer look at this node... --- docs/reference/gsk/gsk4-sections.txt | 3 +++ gsk/gskrendernode.c | 36 ++++++++++++++++++++++++++++ gsk/gskrendernode.h | 4 ++++ 3 files changed, 43 insertions(+) diff --git a/docs/reference/gsk/gsk4-sections.txt b/docs/reference/gsk/gsk4-sections.txt index eebc74d57d..1a2c526000 100644 --- a/docs/reference/gsk/gsk4-sections.txt +++ b/docs/reference/gsk/gsk4-sections.txt @@ -30,6 +30,9 @@ gsk_render_node_unref GskRenderNodeType gsk_render_node_get_node_type gsk_render_node_draw +gsk_render_node_serialize +gsk_render_node_deserialize +gsk_render_node_write_to_file GskScalingFilter gsk_render_node_set_scaling_filters gsk_render_node_set_name diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c index d6a14b3b1d..8ce7da7f95 100644 --- a/gsk/gskrendernode.c +++ b/gsk/gskrendernode.c @@ -317,6 +317,42 @@ gsk_render_node_serialize (GskRenderNode *node) return result; } +/** + * gsk_render_node_write_to_file: + * @node: a #GskRenderNode + * @filename: the file to save it to. + * @error: Return location for a potential error + * + * This function is equivalent to calling gsk_render_node_serialize() + * followed by g_file_set_contents(). See those two functions for details + * on the arguments. + * + * It is mostly intended for use inside a debugger to quickly dump a render + * node to a file for later inspection. + * + * Returns: %TRUE if saving was successful + **/ +gboolean +gsk_render_node_write_to_file (GskRenderNode *node, + const char *filename, + GError **error) +{ + GBytes *bytes; + gboolean result; + + g_return_val_if_fail (GSK_IS_RENDER_NODE (node), FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + bytes = gsk_render_node_serialize (node); + result = g_file_set_contents (filename, + g_bytes_get_data (bytes, NULL), + g_bytes_get_size (bytes), + error); + + return result; +} + GskRenderNode * gsk_render_node_deserialize (GBytes *bytes) { diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h index 650ac9bcfb..f36cafc29b 100644 --- a/gsk/gskrendernode.h +++ b/gsk/gskrendernode.h @@ -177,6 +177,10 @@ void gsk_render_node_draw (GskRenderNode * GDK_AVAILABLE_IN_3_90 GBytes * gsk_render_node_serialize (GskRenderNode *node); GDK_AVAILABLE_IN_3_90 +gboolean gsk_render_node_write_to_file (GskRenderNode *node, + const char *filename, + GError **error); +GDK_AVAILABLE_IN_3_90 GskRenderNode * gsk_render_node_deserialize (GBytes *bytes); G_END_DECLS