[gtk/wip/otte/for-master: 14/16] rendernodeparser: Skip root node when it's a container



commit 2f07fc109d5d8eef210e997a4ee97392d2bf3521
Author: Benjamin Otte <otte redhat com>
Date:   Tue May 14 02:49:19 2019 +0200

    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.

 gsk/gskrendernode.c              | 28 ------------------
 gsk/gskrendernodeparser.c        | 61 +++++++++++++++++++++++++++++++++++++---
 gsk/gskrendernodeparserprivate.h |  1 -
 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
@@ -310,34 +310,6 @@ gsk_render_node_diff (GskRenderNode  *node1,
 #define GSK_RENDER_NODE_SERIALIZATION_VERSION 0
 #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
diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c
index 91ebf08e3d..574d131381 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"
 
@@ -1919,13 +1941,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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]