Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
5 changes: 2 additions & 3 deletions src/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 3 additions & 12 deletions src/tilecache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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
Expand Down
Loading