From 2a2b7901db452db5a21226ebd120d14a63dfce8b Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 22 Jun 2025 10:57:24 +0200 Subject: [PATCH] Prefer use of `gtk_snapshot_set_snap()` See: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/8494 --- meson.build | 7 +++++-- src/imagedisplay.c | 7 +++++++ src/tile.c | 2 +- src/tilecache.c | 13 ++++++++++--- src/vipsdisp.h | 4 ---- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/meson.build b/meson.build index b9d36d0..2d0b0d9 100644 --- a/meson.build +++ b/meson.build @@ -34,6 +34,10 @@ add_project_arguments('-DHAVE_CONFIG_H', language: 'c') # so it can find config.h add_project_arguments('-I.', language: 'c') +gtk_dep = dependency('gtk4', version: '>=4.14') +# use this to fix tile alignment, not yet merged +config_h.set('HAVE_GTK_SNAPSHOT_SET_SNAP', cc.has_header_symbol('gtk.h', 'gtk_snapshot_set_snap', dependencies: gtk_dep)) + configure_file( output: 'config.h', configuration: config_h, @@ -41,10 +45,9 @@ configure_file( # need vips_thread_execute() vips_dep = dependency('vips', version: '>=8.17') -glib_dep = dependency('glib-2.0') -gtk_dep = dependency('gtk4') m_dep = cc.find_library('m') +glib_dep = dependency('glib-2.0') if not cc.has_header_symbol('glib.h', 'g_autofree', dependencies : glib_dep) error('vipsdisp requires the GNU C "cleanup" attribute.') endif diff --git a/src/imagedisplay.c b/src/imagedisplay.c index abdba50..ad744b6 100644 --- a/src/imagedisplay.c +++ b/src/imagedisplay.c @@ -651,6 +651,13 @@ imagedisplay_snapshot(GtkWidget *widget, GtkSnapshot *snapshot) GTK_WIDGET_CLASS(imagedisplay_parent_class)->snapshot(widget, snapshot); +#ifdef HAVE_GTK_SNAPSHOT_SET_SNAP + /* Round tile bounds to the closest pixel edge on all sides to prevent + * seams. + */ + gtk_snapshot_set_snap(snapshot, GSK_RECT_SNAP_ROUND); +#endif /*HAVE_GTK_SNAPSHOT_SET_SNAP*/ + /* Clip to the widget area, or we may paint over the display control * bar. */ diff --git a/src/tile.c b/src/tile.c index def7047..bb3dddc 100644 --- a/src/tile.c +++ b/src/tile.c @@ -87,7 +87,7 @@ tile_touch(Tile *tile) } /* Make a tile on an image. left/top in this image's coordinates (not level0 - * coordfinates). + * coordinates). */ Tile * tile_new(VipsImage *level, int left, int top, int z) diff --git a/src/tilecache.c b/src/tilecache.c index ae332ca..5446410 100644 --- a/src/tilecache.c +++ b/src/tilecache.c @@ -1023,11 +1023,18 @@ tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot, graphene_rect_t bounds; - // +1 to hide tile boundaries bounds.origin.x = tile->bounds.left * scale - x + paint->origin.x; bounds.origin.y = tile->bounds.top * scale - y + paint->origin.y; - bounds.size.width = tile->bounds.width * scale + 1; - bounds.size.height = tile->bounds.height * scale + 1; + bounds.size.width = tile->bounds.width * scale; + bounds.size.height = tile->bounds.height * scale; + +#ifndef HAVE_GTK_SNAPSHOT_SET_SNAP + /* Without set snap, we have to hide tile edges by expanding the + * tile. + */ + bounds.size.width += 1; + bounds.size.height += 1; +#endif /*!HAVE_GTK_SNAPSHOT_SET_SNAP*/ gtk_snapshot_append_scaled_texture(snapshot, tile_get_texture(tile), filter, &bounds); diff --git a/src/vipsdisp.h b/src/vipsdisp.h index d6c9b88..41e5d84 100644 --- a/src/vipsdisp.h +++ b/src/vipsdisp.h @@ -28,10 +28,6 @@ */ #define MAX_TILES (2 * (4096 / TILE_SIZE) * (2048 / TILE_SIZE)) -/* We GtkInfoBar, which is going away in gtk5. - */ -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - #define FREESID(SID, OBJ) \ G_STMT_START \ { \