[gtk/wip/otte/lottie] xxx



commit f4b6f6a1aeb9ad5eced303c026a41e987191acdb
Author: Benjamin Otte <otte redhat com>
Date:   Thu Dec 24 15:20:10 2020 +0100

    xxx

 ottie/meson.build             |  1 +
 ottie/ottiecomposition.c      | 49 ++++++++++++++++++++++++++++++--
 ottie/ottielayer.c            |  8 ++++--
 ottie/ottielayerprivate.h     |  8 ++++--
 ottie/ottienulllayer.c        | 66 +++++++++++++++++++++++++++++++++++++++++++
 ottie/ottienulllayerprivate.h | 45 +++++++++++++++++++++++++++++
 ottie/ottieparser.c           | 30 ++++++++++++++++++++
 ottie/ottieparserprivate.h    |  6 ++++
 ottie/ottieshape.c            |  9 ------
 9 files changed, 206 insertions(+), 16 deletions(-)
---
diff --git a/ottie/meson.build b/ottie/meson.build
index c4701b7dda..32325d87e6 100644
--- a/ottie/meson.build
+++ b/ottie/meson.build
@@ -12,6 +12,7 @@ ottie_private_sources = files([
   'ottiefillshape.c',
   'ottiegroupshape.c',
   'ottielayer.c',
+  'ottienulllayer.c',
   'ottieparser.c',
   'ottiepathshape.c',
   'ottiepathvalue.c',
diff --git a/ottie/ottiecomposition.c b/ottie/ottiecomposition.c
index 9fdb8da7e8..ce9b8ab53c 100644
--- a/ottie/ottiecomposition.c
+++ b/ottie/ottiecomposition.c
@@ -23,6 +23,7 @@
 
 #include "ottieparserprivate.h"
 #include "ottiecompositionlayerprivate.h"
+#include "ottienulllayerprivate.h"
 #include "ottieshapelayerprivate.h"
 
 #include <glib/gi18n-lib.h>
@@ -40,6 +41,7 @@ struct _OttieComposition
   OttieLayer parent;
 
   OttieLayerList layers;
+  GHashTable *layers_by_index;
 };
 
 struct _OttieCompositionClass
@@ -73,7 +75,23 @@ ottie_composition_render (OttieLayer  *layer,
 
   for (gsize i = 0; i < ottie_layer_list_get_size (&self->layers); i++)
     {
-      ottie_layer_render (ottie_layer_list_get (&self->layers, i), &child_render, timestamp);
+      OttieLayer *child = ottie_layer_list_get (&self->layers, i);
+
+      ottie_layer_render (child, &child_render, timestamp);
+      /* XXX: Should we clear paths here because they're not needed anymore? */
+
+      /* Use a counter here to avoid inflooping */
+      for (gsize j = 0; j < ottie_layer_list_get_size (&self->layers); j++)
+        {
+          if (child->transform)
+            ottie_shape_render (OTTIE_SHAPE (child->transform), &child_render, timestamp);
+          if (child->parent_index == OTTIE_INT_UNSET)
+            break;
+          child = g_hash_table_lookup (self->layers_by_index, GINT_TO_POINTER (child->parent_index));
+          if (child == NULL)
+            break;
+        }
+
       ottie_render_merge (render, &child_render);
     }
 
@@ -86,10 +104,21 @@ ottie_composition_dispose (GObject *object)
   OttieComposition *self = OTTIE_COMPOSITION (object);
 
   ottie_layer_list_clear (&self->layers);
+  g_hash_table_remove_all (self->layers_by_index);
 
   G_OBJECT_CLASS (ottie_composition_parent_class)->dispose (object);
 }
 
+static void
+ottie_composition_finalize (GObject *object)
+{
+  OttieComposition *self = OTTIE_COMPOSITION (object);
+
+  g_hash_table_unref (self->layers_by_index);
+
+  G_OBJECT_CLASS (ottie_composition_parent_class)->finalize (object);
+}
+
 static void
 ottie_composition_class_init (OttieCompositionClass *klass)
 {
@@ -100,12 +129,24 @@ ottie_composition_class_init (OttieCompositionClass *klass)
   layer_class->render = ottie_composition_render;
 
   gobject_class->dispose = ottie_composition_dispose;
+  gobject_class->finalize = ottie_composition_finalize;
 }
 
 static void
 ottie_composition_init (OttieComposition *self)
 {
   ottie_layer_list_init (&self->layers);
+
+  self->layers_by_index = g_hash_table_new (g_direct_hash, g_direct_equal);
+}
+
+static void
+ottie_composition_append (OttieComposition *self,
+                          OttieLayer       *layer)
+{
+  ottie_layer_list_append (&self->layers, layer);
+  if (layer->index != OTTIE_INT_UNSET)
+    g_hash_table_insert (self->layers_by_index, GINT_TO_POINTER (layer->index), layer);
 }
 
 static gboolean
@@ -141,6 +182,10 @@ ottie_composition_parse_layer (JsonReader *reader,
       layer = ottie_composition_layer_parse (reader);
       break;
 
+    case 3:
+      layer = ottie_null_layer_parse (reader);
+      break;
+
     case 4:
       layer = ottie_shape_layer_parse (reader);
       break;
@@ -154,7 +199,7 @@ ottie_composition_parse_layer (JsonReader *reader,
   }
 
   if (layer)
-    ottie_layer_list_append (&self->layers, layer);
+    ottie_composition_append (self, layer);
 
   return TRUE;
 }
diff --git a/ottie/ottielayer.c b/ottie/ottielayer.c
index f7291bea0b..36a01f2043 100644
--- a/ottie/ottielayer.c
+++ b/ottie/ottielayer.c
@@ -45,6 +45,9 @@ ottie_layer_dispose (GObject *object)
   OttieLayer *self = OTTIE_LAYER (object);
 
   g_clear_object (&self->transform);
+  g_clear_pointer (&self->layer_name, g_free);
+  g_clear_pointer (&self->name, g_free);
+  g_clear_pointer (&self->match_name, g_free);
 
   G_OBJECT_CLASS (ottie_layer_parent_class)->dispose (object);
 }
@@ -65,6 +68,8 @@ ottie_layer_init (OttieLayer *self)
 {
   self->stretch = 1;
   self->blend_mode = GSK_BLEND_MODE_DEFAULT;
+  self->parent_index = OTTIE_INT_UNSET;
+  self->index = OTTIE_INT_UNSET;
 }
 
 void
@@ -80,8 +85,5 @@ ottie_layer_render (OttieLayer  *self,
                     double       timestamp)
 {
   OTTIE_LAYER_GET_CLASS (self)->render (self, render, timestamp);
-
-  if (self->transform)
-    ottie_shape_render (OTTIE_SHAPE (self->transform), render, timestamp);
 }
 
diff --git a/ottie/ottielayerprivate.h b/ottie/ottielayerprivate.h
index c1d4b42368..4ca68f8ab4 100644
--- a/ottie/ottielayerprivate.h
+++ b/ottie/ottielayerprivate.h
@@ -45,9 +45,11 @@ struct _OttieLayer
   OttieTransform *transform;
   gboolean auto_orient;
   GskBlendMode blend_mode;
-  double index;
+  int index;
+  int parent_index;
   char *layer_name;
   char *name;
+  char *match_name;
   double start_frame;
   double end_frame;
   double start_time;
@@ -77,10 +79,12 @@ void                    ottie_layer_render                   (OttieLayer
     { "ao", ottie_parser_option_boolean, G_STRUCT_OFFSET (OttieLayer, auto_orient) }, \
     { "bm", ottie_parser_option_blend_mode, G_STRUCT_OFFSET (OttieLayer, blend_mode) }, \
     { "nm", ottie_parser_option_string, G_STRUCT_OFFSET (OttieLayer, name) }, \
+    { "mn", ottie_parser_option_string, G_STRUCT_OFFSET (OttieLayer, match_name) }, \
     { "ln", ottie_parser_option_string, G_STRUCT_OFFSET (OttieLayer, layer_name) }, \
     { "ks", ottie_parser_option_transform, G_STRUCT_OFFSET (OttieLayer, transform) }, \
     { "ip", ottie_parser_option_double, G_STRUCT_OFFSET (OttieLayer, start_frame) }, \
-    { "ind", ottie_parser_option_double, G_STRUCT_OFFSET (OttieLayer, index) }, \
+    { "ind", ottie_parser_option_int, G_STRUCT_OFFSET (OttieLayer, index) }, \
+    { "parent", ottie_parser_option_int, G_STRUCT_OFFSET (OttieLayer, parent_index) }, \
     { "op", ottie_parser_option_double, G_STRUCT_OFFSET (OttieLayer, end_frame) }, \
     { "st", ottie_parser_option_double, G_STRUCT_OFFSET (OttieLayer, start_time) }, \
     { "sr", ottie_parser_option_double, G_STRUCT_OFFSET (OttieLayer, stretch) }, \
diff --git a/ottie/ottienulllayer.c b/ottie/ottienulllayer.c
new file mode 100644
index 0000000000..b4ae745fc2
--- /dev/null
+++ b/ottie/ottienulllayer.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright © 2020 Benjamin Otte
+ *
+ * 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>
+ */
+
+#include "config.h"
+
+#include "ottienulllayerprivate.h"
+
+#include <glib/gi18n-lib.h>
+
+struct _OttieNullLayer
+{
+  OttieLayer parent;
+};
+
+struct _OttieNullLayerClass
+{
+  OttieLayerClass parent_class;
+};
+
+G_DEFINE_TYPE (OttieNullLayer, ottie_null_layer, OTTIE_TYPE_LAYER)
+
+static void
+ottie_null_layer_class_init (OttieNullLayerClass *klass)
+{
+}
+
+static void
+ottie_null_layer_init (OttieNullLayer *self)
+{
+}
+
+OttieLayer *
+ottie_null_layer_parse (JsonReader *reader)
+{
+  OttieParserOption options[] = {
+    OTTIE_PARSE_OPTIONS_LAYER
+  };
+  OttieNullLayer *self;
+
+  self = g_object_new (OTTIE_TYPE_NULL_LAYER, NULL);
+
+  if (!ottie_parser_parse_object (reader, "null layer", options, G_N_ELEMENTS (options), self))
+    {
+      g_object_unref (self);
+      return NULL;
+    }
+
+  return OTTIE_LAYER (self);
+}
+
diff --git a/ottie/ottienulllayerprivate.h b/ottie/ottienulllayerprivate.h
new file mode 100644
index 0000000000..40347a2741
--- /dev/null
+++ b/ottie/ottienulllayerprivate.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2020 Benjamin Otte
+ *
+ * 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>
+ */
+
+#ifndef __OTTIE_NULL_LAYER_PRIVATE_H__
+#define __OTTIE_NULL_LAYER_PRIVATE_H__
+
+#include "ottielayerprivate.h"
+
+#include <json-glib/json-glib.h>
+
+G_BEGIN_DECLS
+
+#define OTTIE_TYPE_NULL_LAYER         (ottie_null_layer_get_type ())
+#define OTTIE_NULL_LAYER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), OTTIE_TYPE_NULL_LAYER, 
OttieNullLayer))
+#define OTTIE_NULL_LAYER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), OTTIE_TYPE_NULL_LAYER, 
OttieNullLayerClass))
+#define OTTIE_IS_NULL_LAYER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), OTTIE_TYPE_NULL_LAYER))
+#define OTTIE_IS_NULL_LAYER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), OTTIE_TYPE_NULL_LAYER))
+#define OTTIE_NULL_LAYER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OTTIE_TYPE_NULL_LAYER, 
OttieNullLayerClass))
+
+typedef struct _OttieNullLayer OttieNullLayer;
+typedef struct _OttieNullLayerClass OttieNullLayerClass;
+
+GType                   ottie_null_layer_get_type               (void) G_GNUC_CONST;
+
+OttieLayer *            ottie_null_layer_parse                  (JsonReader             *reader);
+
+G_END_DECLS
+
+#endif /* __OTTIE_NULL_LAYER_PRIVATE_H__ */
diff --git a/ottie/ottieparser.c b/ottie/ottieparser.c
index 66842c6a78..cec236a3a1 100644
--- a/ottie/ottieparser.c
+++ b/ottie/ottieparser.c
@@ -251,6 +251,36 @@ ottie_parser_option_double (JsonReader *reader,
   return TRUE;
 }
 
+gboolean
+ottie_parser_option_int (JsonReader *reader,
+                         gsize       offset,
+                         gpointer    data)
+{
+  gint64 i;
+
+  i = json_reader_get_int_value (reader);
+  if (json_reader_get_error (reader))
+    {
+      ottie_parser_emit_error (reader, json_reader_get_error (reader));
+      return FALSE;
+    }
+  
+  if (i > G_MAXINT || i < G_MININT)
+    {
+      ottie_parser_error_value (reader, "Integer value %"G_GINT64_FORMAT" out of range", i);
+      return FALSE;
+    }
+  if (i == OTTIE_INT_UNSET)
+    {
+      ottie_parser_error_unsupported (reader, "The Integer value %d is a magic internal value of Ottie, file 
a bug", OTTIE_INT_UNSET);
+      return FALSE;
+    }
+
+  *(int *) ((guint8 *) data + offset) = i;
+
+  return TRUE;
+}
+
 gboolean
 ottie_parser_option_string (JsonReader *reader,
                             gsize       offset,
diff --git a/ottie/ottieparserprivate.h b/ottie/ottieparserprivate.h
index bfd754d873..d13ee861c5 100644
--- a/ottie/ottieparserprivate.h
+++ b/ottie/ottieparserprivate.h
@@ -24,6 +24,9 @@
 
 G_BEGIN_DECLS
 
+/* for integers where we want to track that nobody has assigned a value to them */
+#define OTTIE_INT_UNSET G_MININT
+
 typedef struct _OttieParserOption OttieParserOption;
 
 typedef gboolean (* OttieParseFunc) (JsonReader *reader, gsize offset, gpointer data);
@@ -70,6 +73,9 @@ gboolean                ottie_parser_option_skip               (JsonReader
 gboolean                ottie_parser_option_boolean            (JsonReader              *reader,
                                                                 gsize                    offset,
                                                                 gpointer                 data);
+gboolean                ottie_parser_option_int                (JsonReader              *reader,
+                                                                gsize                    offset,
+                                                                gpointer                 data);
 gboolean                ottie_parser_option_double             (JsonReader              *reader,
                                                                 gsize                    offset,
                                                                 gpointer                 data);
diff --git a/ottie/ottieshape.c b/ottie/ottieshape.c
index b5f71f7d92..71f6378bfd 100644
--- a/ottie/ottieshape.c
+++ b/ottie/ottieshape.c
@@ -36,20 +36,11 @@ ottie_shape_dispose (GObject *object)
   G_OBJECT_CLASS (ottie_shape_parent_class)->dispose (object);
 }
 
-static void
-ottie_shape_finalize (GObject *object)
-{
-  //OttieShape *self = OTTIE_SHAPE (object);
-
-  G_OBJECT_CLASS (ottie_shape_parent_class)->finalize (object);
-}
-
 static void
 ottie_shape_class_init (OttieShapeClass *class)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
 
-  gobject_class->finalize = ottie_shape_finalize;
   gobject_class->dispose = ottie_shape_dispose;
 }
 


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