[gtk/wip/otte/paintable: 2/15] cssimage: Implement dynamic values



commit 801304e670d2bf1a6c0ffc25d48584ca04058178
Author: Benjamin Otte <otte redhat com>
Date:   Tue Feb 13 07:04:21 2018 +0100

    cssimage: Implement dynamic values
    
    No image actually implements it yet, but this is the plumbing.

 gtk/gtkcssimage.c        | 40 ++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssimageprivate.h |  8 ++++++++
 gtk/gtkcssimagevalue.c   | 35 +++++++++++++++++++++++++++++++++--
 3 files changed, 81 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c
index 7ce0f0a7e2..d592c1be6e 100644
--- a/gtk/gtkcssimage.c
+++ b/gtk/gtkcssimage.c
@@ -135,6 +135,19 @@ gtk_css_image_real_snapshot (GtkCssImage *image,
   cairo_destroy (cr);
 }
 
+static gboolean
+gtk_css_image_real_is_dynamic (GtkCssImage *image)
+{
+  return FALSE;
+}
+
+static GtkCssImage *
+gtk_css_image_real_get_dynamic_image (GtkCssImage *image,
+                                      gint64       monotonic_time)
+{
+  return g_object_ref (image);
+}
+
 static void
 _gtk_css_image_class_init (GtkCssImageClass *klass)
 {
@@ -146,6 +159,8 @@ _gtk_css_image_class_init (GtkCssImageClass *klass)
   klass->transition = gtk_css_image_real_transition;
   klass->draw = gtk_css_image_real_draw;
   klass->snapshot = gtk_css_image_real_snapshot;
+  klass->is_dynamic = gtk_css_image_real_is_dynamic;
+  klass->get_dynamic_image = gtk_css_image_real_get_dynamic_image;
 }
 
 static void
@@ -294,6 +309,31 @@ gtk_css_image_snapshot (GtkCssImage *image,
   klass->snapshot (image, snapshot, width, height);
 }
 
+gboolean
+gtk_css_image_is_dynamic (GtkCssImage *image)
+{
+  GtkCssImageClass *klass;
+
+  g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), FALSE);
+
+  klass = GTK_CSS_IMAGE_GET_CLASS (image);
+
+  return klass->is_dynamic (image);
+}
+
+GtkCssImage *
+gtk_css_image_get_dynamic_image (GtkCssImage *image,
+                                 gint64       monotonic_time)
+{
+  GtkCssImageClass *klass;
+
+  g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
+
+  klass = GTK_CSS_IMAGE_GET_CLASS (image);
+
+  return klass->get_dynamic_image (image, monotonic_time);
+}
+
 void
 _gtk_css_image_print (GtkCssImage *image,
                       GString     *string)
diff --git a/gtk/gtkcssimageprivate.h b/gtk/gtkcssimageprivate.h
index 9fc962df28..00502b8705 100644
--- a/gtk/gtkcssimageprivate.h
+++ b/gtk/gtkcssimageprivate.h
@@ -79,6 +79,11 @@ struct _GtkCssImageClass
                                                     GtkSnapshot                *snapshot,
                                                     double                      width,
                                                     double                      height);
+  /* does this image change based on timestamp? (optional) */
+  gboolean     (* is_dynamic)                      (GtkCssImage                *image);
+  /* get image for given timestamp or @image when not dynamic (optional) */
+  GtkCssImage *(* get_dynamic_image)               (GtkCssImage                *image,
+                                                    gint64                      monotonic_time);
   /* parse CSS, return TRUE on success */
   gboolean     (* parse)                           (GtkCssImage                *image,
                                                     GtkCssParser               *parser);
@@ -116,6 +121,9 @@ void           gtk_css_image_snapshot              (GtkCssImage                *
                                                     GtkSnapshot                *snapshot,
                                                     double                      width,
                                                     double                      height);
+gboolean       gtk_css_image_is_dynamic            (GtkCssImage                *image);
+GtkCssImage *  gtk_css_image_get_dynamic_image     (GtkCssImage                *image,
+                                                    gint64                      monotonic_time);
 void           _gtk_css_image_print                (GtkCssImage                *image,
                                                     GString                    *string);
 
diff --git a/gtk/gtkcssimagevalue.c b/gtk/gtkcssimagevalue.c
index 1b674a332b..c5923e96d6 100644
--- a/gtk/gtkcssimagevalue.c
+++ b/gtk/gtkcssimagevalue.c
@@ -81,6 +81,37 @@ gtk_css_value_image_transition (GtkCssValue *start,
   return _gtk_css_image_value_new (transition);
 }
 
+static gboolean
+gtk_css_value_image_is_dynamic (GtkCssValue *value)
+{
+  GtkCssImage *image = _gtk_css_image_value_get_image (value);
+
+  if (image == NULL)
+    return FALSE;
+
+  return gtk_css_image_is_dynamic (image);
+}
+
+static GtkCssValue *
+gtk_css_value_image_get_dynamic_value (GtkCssValue *value,
+                                       gint64       monotonic_time)
+{
+  GtkCssImage *image, *dynamic;
+  
+  image = _gtk_css_image_value_get_image (value);
+  if (image == NULL)
+    return gtk_css_value_ref (value);
+
+  dynamic = gtk_css_image_get_dynamic_image (image, monotonic_time);
+  if (dynamic == image)
+    {
+      g_object_unref (dynamic);
+      return gtk_css_value_ref (value);
+    }
+
+  return _gtk_css_image_value_new (dynamic);
+}
+
 static void
 gtk_css_value_image_print (const GtkCssValue *value,
                            GString           *string)
@@ -96,8 +127,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
   gtk_css_value_image_compute,
   gtk_css_value_image_equal,
   gtk_css_value_image_transition,
-  NULL,
-  NULL,
+  gtk_css_value_image_is_dynamic,
+  gtk_css_value_image_get_dynamic_value,
   gtk_css_value_image_print
 };
 


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