[gtk+/wip/matthiasc/shadertoy: 1/3] Export more snapshot api



commit a1ac33f9a1fa16ed7cc1c8132366a69d5713e07f
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Sep 24 14:45:07 2017 -0400

    Export more snapshot api
    
    We currently don't export enough api to do custom snapshots
    outside libgtk. To demonstrate this in gtk4-demo, export
    the necessary api here.

 gtk/gtksnapshot.c        |   65 ++++++++++++++++++++++++++++++++++++----------
 gtk/gtksnapshot.h        |    7 +++++
 gtk/gtksnapshotprivate.h |    3 ++
 gtk/gtkwidget.h          |    4 +++
 gtk/gtkwidgetprivate.h   |    3 --
 5 files changed, 65 insertions(+), 17 deletions(-)
---
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index d846d7b..1fc517e 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -125,13 +125,13 @@ gtk_snapshot_state_clear (GtkSnapshotState *state)
   g_clear_pointer (&state->name, g_free);
 }
 
-void
-gtk_snapshot_init (GtkSnapshot          *snapshot,
-                   GskRenderer          *renderer,
-                   gboolean              record_names,
-                   const cairo_region_t *clip,
-                   const char           *name,
-                   ...)
+static void
+gtk_snapshot_init_va (GtkSnapshot          *snapshot,
+                      GskRenderer          *renderer,
+                      gboolean              record_names,
+                      const cairo_region_t *clip,
+                      const char           *name,
+                      va_list               args)
 {
   char *str;
 
@@ -142,13 +142,7 @@ gtk_snapshot_init (GtkSnapshot          *snapshot,
   snapshot->nodes = g_ptr_array_new_with_free_func ((GDestroyNotify)gsk_render_node_unref);
 
   if (name && record_names)
-    {
-      va_list args;
-
-      va_start (args, name);
-      str = g_strdup_vprintf (name, args);
-      va_end (args);
-    }
+    str = g_strdup_vprintf (name, args);
   else
     str = NULL;
 
@@ -159,6 +153,38 @@ gtk_snapshot_init (GtkSnapshot          *snapshot,
                            gtk_snapshot_collect_default);
 }
 
+void
+gtk_snapshot_init (GtkSnapshot          *snapshot,
+                   GskRenderer          *renderer,
+                   gboolean              record_names,
+                   const cairo_region_t *clip,
+                   const char           *name,
+                   ...)
+{
+  va_list args;
+
+  va_start (args, name);
+  gtk_snapshot_init_va (snapshot, renderer, record_names, clip, name, args);
+  va_end (args);
+}
+
+GtkSnapshot *
+gtk_snapshot_new (GtkSnapshot *parent,
+                  const char  *name,
+                  ...)
+{
+  GtkSnapshot *snapshot;
+  va_list args;
+
+  snapshot = g_new (GtkSnapshot, 1);
+
+  va_start (args, name);
+  gtk_snapshot_init_va (snapshot, parent->renderer, parent->record_names, NULL, name, args);
+  va_end (args);
+
+  return snapshot;
+}
+
 /**
  * gtk_snapshot_push:
  * @snapshot: a #GtkSnapshot
@@ -1021,6 +1047,17 @@ gtk_snapshot_finish (GtkSnapshot *snapshot)
   return result;
 }
 
+GskRenderNode *
+gtk_snapshot_free (GtkSnapshot *snapshot)
+{
+  GskRenderNode *node;
+
+  node = gtk_snapshot_finish (snapshot);
+  g_free (snapshot);
+
+  return node;
+}
+
 /**
  * gtk_snapshot_pop:
  * @snapshot: a #GtkSnapshot
diff --git a/gtk/gtksnapshot.h b/gtk/gtksnapshot.h
index b5e21ae..c10b84c 100644
--- a/gtk/gtksnapshot.h
+++ b/gtk/gtksnapshot.h
@@ -36,6 +36,13 @@
 
 G_BEGIN_DECLS
 
+GDK_AVAILABLE_IN_3_92
+GtkSnapshot *   gtk_snapshot_new                        (GtkSnapshot           *parent,
+                                                         const char            *name,
+                                                         ...) G_GNUC_PRINTF (2, 3);
+GDK_AVAILABLE_IN_3_92
+GskRenderNode * gtk_snapshot_free                       (GtkSnapshot           *snapshot);
+
 GDK_AVAILABLE_IN_3_90
 void            gtk_snapshot_push                       (GtkSnapshot            *snapshot,
                                                          gboolean                keep_coordinates,
diff --git a/gtk/gtksnapshotprivate.h b/gtk/gtksnapshotprivate.h
index 1319df7..0682a8d 100644
--- a/gtk/gtksnapshotprivate.h
+++ b/gtk/gtksnapshotprivate.h
@@ -87,14 +87,17 @@ struct _GtkSnapshot {
   GPtrArray             *nodes;
 };
 
+GDK_AVAILABLE_IN_ALL
 void            gtk_snapshot_init               (GtkSnapshot             *state,
                                                  GskRenderer             *renderer,
                                                  gboolean                 record_names,
                                                  const cairo_region_t    *clip,
                                                  const char              *name,
                                                  ...) G_GNUC_PRINTF (5, 6);
+GDK_AVAILABLE_IN_ALL
 GskRenderNode * gtk_snapshot_finish             (GtkSnapshot             *state);
 
+GDK_AVAILABLE_IN_ALL
 GskRenderer *   gtk_snapshot_get_renderer       (const GtkSnapshot       *snapshot);
 
 G_END_DECLS
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index ff2aa77..65bcb31 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -518,6 +518,10 @@ void          gtk_widget_unrealize           (GtkWidget           *widget);
 GDK_AVAILABLE_IN_ALL
 void       gtk_widget_draw                (GtkWidget           *widget,
                                            cairo_t             *cr);
+GDK_AVAILABLE_IN_3_92
+void       gtk_widget_snapshot            (GtkWidget           *widget,
+                                           GtkSnapshot         *snapshot);
+
 /* Queuing draws */
 GDK_AVAILABLE_IN_ALL
 void      gtk_widget_queue_draw          (GtkWidget           *widget);
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 6e0b746..0b7595e 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -282,9 +282,6 @@ void              gtk_widget_render                        (GtkWidget
                                                             GdkWindow            *window,
                                                             const cairo_region_t *region);
 
-
-void              gtk_widget_snapshot                      (GtkWidget            *widget,
-                                                            GtkSnapshot          *snapshot);
 void              gtk_widget_adjust_size_request           (GtkWidget      *widget,
                                                             GtkOrientation  orientation,
                                                             gint           *minimum_size,


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