From cb89b3a9e7eb937607c8a761ad739f8a605cee91 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Fri, 18 Aug 2023 11:07:35 +0300 Subject: [PATCH] paintable: Implement gdk_paintable_default_get_current_image () Signed-off-by: Sergey Bugaev --- gdk/gdkpaintable.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gdk/gdkpaintable.c b/gdk/gdkpaintable.c index 94f3dc7a5d..071b99e61d 100644 --- a/gdk/gdkpaintable.c +++ b/gdk/gdkpaintable.c @@ -25,10 +25,12 @@ #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 -- 2.30.2