summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2019-05-14 02:49:19 +0200
committerBenjamin Otte <otte@redhat.com>2019-05-21 06:43:59 +0200
commit20d1bc2cccabe2225ae3eaf2248a9a1464ac513a (patch)
treeebc95c02f85135141786db0085a58a65844552ca
parented0ecf0ff0968a1b09448929656c086e5837a28c (diff)
downloadgtk+-20d1bc2cccabe2225ae3eaf2248a9a1464ac513a.tar.gz
rendernodeparser: Skip root node when it's a container
When printing, behave the same way as when parsing: Magically skip a container node if there is one - just like the parser magically creates a container node to hold all the nodes it parses.
-rw-r--r--gsk/gskrendernode.c28
-rw-r--r--gsk/gskrendernodeparser.c61
-rw-r--r--gsk/gskrendernodeparserprivate.h1
3 files changed, 57 insertions, 33 deletions
diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c
index 1b1dd2d78f..2e4753a2e0 100644
--- a/gsk/gskrendernode.c
+++ b/gsk/gskrendernode.c
@@ -311,34 +311,6 @@ gsk_render_node_diff (GskRenderNode *node1,
#define GSK_RENDER_NODE_SERIALIZATION_ID "GskRenderNode"
/**
- * gsk_render_node_serialize:
- * @node: a #GskRenderNode
- *
- * Serializes the @node for later deserialization via
- * gsk_render_node_deserialize(). No guarantees are made about the format
- * used other than that the same version of GTK+ will be able to deserialize
- * the result of a call to gsk_render_node_serialize() and
- * gsk_render_node_deserialize() will correctly reject files it cannot open
- * that were created with previous versions of GTK+.
- *
- * The intended use of this functions is testing, benchmarking and debugging.
- * The format is not meant as a permanent storage format.
- *
- * Returns: a #GBytes representing the node.
- **/
-GBytes *
-gsk_render_node_serialize (GskRenderNode *node)
-{
- GBytes *result;
- char *str;
-
- str = gsk_render_node_serialize_to_string (node);
- result = g_bytes_new_take (str, strlen (str));
-
- return result;
-}
-
-/**
* gsk_render_node_write_to_file:
* @node: a #GskRenderNode
* @filename: the file to save it to.
diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c
index caf601d401..b9603b235e 100644
--- a/gsk/gskrendernodeparser.c
+++ b/gsk/gskrendernodeparser.c
@@ -1,3 +1,25 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ * Timm Bäder
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ * Timm Bäder <mail@baedert.org>
+ */
+
+#include "config.h"
#include "gskrendernodeparserprivate.h"
@@ -1945,13 +1967,44 @@ render_node_print (Printer *p,
}
}
-char *
-gsk_render_node_serialize_to_string (GskRenderNode *root)
+/**
+ * gsk_render_node_serialize:
+ * @node: a #GskRenderNode
+ *
+ * Serializes the @node for later deserialization via
+ * gsk_render_node_deserialize(). No guarantees are made about the format
+ * used other than that the same version of GTK+ will be able to deserialize
+ * the result of a call to gsk_render_node_serialize() and
+ * gsk_render_node_deserialize() will correctly reject files it cannot open
+ * that were created with previous versions of GTK+.
+ *
+ * The intended use of this functions is testing, benchmarking and debugging.
+ * The format is not meant as a permanent storage format.
+ *
+ * Returns: a #GBytes representing the node.
+ **/
+GBytes *
+gsk_render_node_serialize (GskRenderNode *node)
{
Printer p;
printer_init (&p);
- render_node_print (&p, root);
- return g_string_free (p.str, FALSE);
+ if (gsk_render_node_get_node_type (node) == GSK_CONTAINER_NODE)
+ {
+ guint i;
+
+ for (i = 0; i < gsk_container_node_get_n_children (node); i ++)
+ {
+ GskRenderNode *child = gsk_container_node_get_child (node, i);
+
+ render_node_print (&p, child);
+ }
+ }
+ else
+ {
+ render_node_print (&p, node);
+ }
+
+ return g_string_free_to_bytes (p.str);
}
diff --git a/gsk/gskrendernodeparserprivate.h b/gsk/gskrendernodeparserprivate.h
index a506244429..7994488772 100644
--- a/gsk/gskrendernodeparserprivate.h
+++ b/gsk/gskrendernodeparserprivate.h
@@ -7,6 +7,5 @@
GskRenderNode * gsk_render_node_deserialize_from_bytes (GBytes *bytes,
GskParseErrorFunc error_func,
gpointer user_data);
-char * gsk_render_node_serialize_to_string (GskRenderNode *root);
#endif