mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-13 20:30:11 +00:00
png: Move texture data download further down
We only download the data when we actually need it for writing into the PNG stream. This allows modifying the download parameters (in particular color state in the next commit) while writing out their settings, so the code for selecting the right colorstate liives in only one place. We have to be careful though, because the download now happens after the setjmp(), so we need to make sure the error path handles both cases without leaking: Where the download has happened and where it hasn't.
This commit is contained in:
parent
03daf42fb5
commit
6c33afc13c
@ -451,15 +451,11 @@ gdk_save_png (GdkTexture *texture)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gdk_texture_downloader_init (&downloader, texture);
|
bytes = NULL;
|
||||||
gdk_texture_downloader_set_format (&downloader, format);
|
|
||||||
bytes = gdk_texture_downloader_download_bytes (&downloader, &stride);
|
|
||||||
gdk_texture_downloader_finish (&downloader);
|
|
||||||
data = g_bytes_get_data (bytes, NULL);
|
|
||||||
|
|
||||||
if (sigsetjmp (png_jmpbuf (png), 1))
|
if (sigsetjmp (png_jmpbuf (png), 1))
|
||||||
{
|
{
|
||||||
g_bytes_unref (bytes);
|
g_clear_pointer (&bytes, g_bytes_unref);
|
||||||
g_free (io.data);
|
g_free (io.data);
|
||||||
png_destroy_read_struct (&png, &info, NULL);
|
png_destroy_read_struct (&png, &info, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -479,6 +475,12 @@ gdk_save_png (GdkTexture *texture)
|
|||||||
png_set_swap (png);
|
png_set_swap (png);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
gdk_texture_downloader_init (&downloader, texture);
|
||||||
|
gdk_texture_downloader_set_format (&downloader, format);
|
||||||
|
bytes = gdk_texture_downloader_download_bytes (&downloader, &stride);
|
||||||
|
gdk_texture_downloader_finish (&downloader);
|
||||||
|
data = g_bytes_get_data (bytes, NULL);
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
png_write_row (png, data + y * stride);
|
png_write_row (png, data + y * stride);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user