paintable: Implement gdk_paintable_default_get_current_image ()
authorSergey Bugaev <bugaevc@gmail.com>
Fri, 18 Aug 2023 08:07:35 +0000 (11:07 +0300)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 24 Aug 2023 14:24:50 +0000 (10:24 -0400)
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
gdk/gdkpaintable.c

index 94f3dc7a5d1aff0ceb0c4beef7ccc77515755956..071b99e61dfeacb7e44d2feee13ca45d9222b6da 100644 (file)
 #include "gdkprivate.h"
 
 /* HACK: So we don't need to include any (not-yet-created) GSK or GTK headers */
+GdkSnapshot *   gtk_snapshot_new                        (void);
 void            gtk_snapshot_push_debug                 (GdkSnapshot            *snapshot,
                                                          const char             *message,
                                                          ...) G_GNUC_PRINTF (2, 3);
 void            gtk_snapshot_pop                        (GdkSnapshot            *snapshot);
+GdkPaintable *  gtk_snapshot_free_to_paintable          (GdkSnapshot            *snapshot);
 
 /**
  * GdkPaintable:
@@ -102,9 +104,21 @@ gdk_paintable_default_snapshot (GdkPaintable *paintable,
 static GdkPaintable *
 gdk_paintable_default_get_current_image (GdkPaintable *paintable)
 {
-  g_warning ("FIXME: implement by snapshotting at default size and returning a GskRendererNodePaintable");
+  int width, height;
+  GdkSnapshot *snapshot;
+
+  /* No need to check whether the paintable is static, as
+   * gdk_paintable_get_current_image () takes care of that already.  */
+
+  width = gdk_paintable_get_intrinsic_width (paintable);
+  height = gdk_paintable_get_intrinsic_height (paintable);
+
+  if (width <= 0 || height <= 0)
+    return gdk_paintable_new_empty (width, height);
 
-  return paintable;
+  snapshot = gtk_snapshot_new ();
+  gdk_paintable_snapshot (paintable, snapshot, width, height);
+  return gtk_snapshot_free_to_paintable (snapshot);
 }
 
 static GdkPaintableFlags