From 1d9d9a4a8794028edab4565ed5d947d7b651f476 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sat, 21 Jun 2025 12:55:18 +0200 Subject: [PATCH] Prefer use of `gdk_memory_texture_new()` As the gdk-pixbuf dependency is expected to be dropped in GTK5. --- src/tile.c | 32 ++++++++++++++++---------------- src/tile.h | 5 ++--- src/tilecache.c | 15 +++------------ 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/tile.c b/src/tile.c index 77935c9..def7047 100644 --- a/src/tile.c +++ b/src/tile.c @@ -50,8 +50,7 @@ tile_dispose(GObject *object) #endif /*DEBUG*/ VIPS_UNREF(tile->texture); - VIPS_UNREF(tile->pixbuf); - VIPS_FREE(tile->data_copy); + VIPS_FREEF(g_bytes_unref, tile->bytes); VIPS_UNREF(tile->region); G_OBJECT_CLASS(tile_parent_class)->dispose(object); @@ -145,31 +144,32 @@ tile_get_texture(Tile *tile) * 1. We must make a copy of the pixel data from libvips, to stop * it being changed under our feet. * - * 2. Wrap a pixbuf around that copy. + * 2. Wrap a GBytes around that copy. * * 3. Tag it as a texture that may need upload to the GPU. */ if (!tile->texture) { - VIPS_FREE(tile->data_copy); - tile->data_copy = g_memdup2( + gpointer copy = g_memdup2( VIPS_REGION_ADDR(tile->region, tile->region->valid.left, tile->region->valid.top), VIPS_REGION_SIZEOF_LINE(tile->region) * tile->region->valid.height); - VIPS_UNREF(tile->pixbuf); - tile->pixbuf = gdk_pixbuf_new_from_data( - tile->data_copy, - GDK_COLORSPACE_RGB, - tile->region->im->Bands == 4, - 8, + VIPS_FREEF(g_bytes_unref, tile->bytes); + tile->bytes = g_bytes_new_take( + copy, + VIPS_REGION_SIZEOF_LINE(tile->region) * + tile->region->valid.height); + + tile->texture = gdk_memory_texture_new( tile->region->valid.width, tile->region->valid.height, - VIPS_REGION_LSKIP(tile->region), - NULL, NULL); - - tile->texture = gdk_texture_new_for_pixbuf(tile->pixbuf); + tile->region->im->Bands == 4 + ? GDK_MEMORY_R8G8B8A8 + : GDK_MEMORY_R8G8B8, + tile->bytes, + VIPS_REGION_LSKIP(tile->region)); } return tile->texture; @@ -184,5 +184,5 @@ tile_free_texture(Tile *tile) g_assert(tile->valid); VIPS_UNREF(tile->texture); - VIPS_UNREF(tile->pixbuf); + VIPS_FREEF(g_bytes_unref, tile->bytes); } diff --git a/src/tile.h b/src/tile.h index 5306dc8..4481d24 100644 --- a/src/tile.h +++ b/src/tile.h @@ -70,12 +70,11 @@ typedef struct _Tile { /* Pixels going out to the scene graph. * - * pixbuf and texture won't make a copy of the data, so we must make a + * bytes and texture won't make a copy of the data, so we must make a * copy ourselves, in case a later fetch from the same region produces * invalid data. */ - VipsPel *data_copy; - GdkPixbuf *pixbuf; + GBytes *bytes; GdkTexture *texture; } Tile; diff --git a/src/tilecache.c b/src/tilecache.c index c9b484a..ae332ca 100644 --- a/src/tilecache.c +++ b/src/tilecache.c @@ -122,12 +122,6 @@ tilecache_area_changed(Tilecache *tilecache, VipsRect *dirty, int z) g_signal_emit(tilecache, tilecache_signals[SIG_AREA_CHANGED], 0, dirty, z); } -static void -tilecache_checkerboard_destroy_notify(guchar *pixels, gpointer data) -{ - g_free(pixels); -} - /* Make a GdkTexture for the checkerboard pattern we use for compositing. */ static GdkTexture * @@ -159,13 +153,10 @@ tilecache_texture(TilecacheBackground background) data[y * TILE_SIZE * 3 + x * 3 + z] = v; } - g_autoptr(GdkPixbuf) pixbuf = gdk_pixbuf_new_from_data(data, - GDK_COLORSPACE_RGB, - FALSE, 8, - TILE_SIZE, TILE_SIZE, TILE_SIZE * 3, - tilecache_checkerboard_destroy_notify, NULL); + g_autoptr(GBytes) bytes = g_bytes_new_take(data, TILE_SIZE * TILE_SIZE * 3); - return gdk_texture_new_for_pixbuf(pixbuf); + return gdk_memory_texture_new( + TILE_SIZE, TILE_SIZE, GDK_MEMORY_R8G8B8, bytes, TILE_SIZE * 3); } static void