[gtk/image-loading: 28/36] !fixup contentdeserializer using splice
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/image-loading: 28/36] !fixup contentdeserializer using splice
- Date: Tue, 14 Sep 2021 05:40:47 +0000 (UTC)
commit b303322cd42d57a5a1aeddae7e81a0b8eb255452
Author: Benjamin Otte <otte redhat com>
Date: Tue Sep 14 03:14:51 2021 +0200
!fixup contentdeserializer using splice
gdk/gdkcontentdeserializer.c | 89 +++++++++++++++-----------------------------
1 file changed, 29 insertions(+), 60 deletions(-)
---
diff --git a/gdk/gdkcontentdeserializer.c b/gdk/gdkcontentdeserializer.c
index 6731b47e24..8757f0971f 100644
--- a/gdk/gdkcontentdeserializer.c
+++ b/gdk/gdkcontentdeserializer.c
@@ -659,84 +659,53 @@ pixbuf_deserializer (GdkContentDeserializer *deserializer)
static void
texture_deserializer_finish (GObject *source,
- GAsyncResult *res,
- gpointer data)
+ GAsyncResult *result,
+ gpointer deserializer)
{
- GdkContentDeserializer *deserializer = GDK_CONTENT_DESERIALIZER (source);
- GdkTexture *texture;
- GValue *value;
+ GOutputStream *stream = G_OUTPUT_STREAM (source);
+ GBytes *bytes;
GError *error = NULL;
+ GdkTexture *texture = NULL;
+ gssize written;
- texture = g_task_propagate_pointer (G_TASK (res), &error);
- if (texture == NULL)
+ written = g_output_stream_splice_finish (stream, result, &error);
+ if (written < 0)
{
gdk_content_deserializer_return_error (deserializer, error);
return;
}
- value = gdk_content_deserializer_get_value (deserializer);
- g_value_take_object (value, texture);
- gdk_content_deserializer_return_success (deserializer);
-}
-
-static GBytes *
-read_all_data (GInputStream *source,
- GError **error)
-{
- GOutputStream *output;
- gssize size;
- GBytes *bytes;
+ bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (stream));
- output = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
- size = g_output_stream_splice (output, source, 0, NULL, error);
- if (size == -1)
+ texture = gdk_texture_new_from_bytes (bytes, &error);
+ g_bytes_unref (bytes);
+ if(texture == NULL)
{
- g_object_unref (output);
- return NULL;
+ gdk_content_deserializer_return_error (deserializer, error);
+ return;
}
- g_output_stream_close (output, NULL, NULL);
- bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (output));
- g_object_unref (output);
-
- return bytes;
+ g_value_take_object (gdk_content_deserializer_get_value (deserializer),
+ texture);
+ gdk_content_deserializer_return_success (deserializer);
}
static void
-deserialize_texture_in_thread (GTask *task,
- gpointer source_object,
- gpointer task_data,
- GCancellable *cancellable)
+texture_deserializer (GdkContentDeserializer *deserializer)
{
- GdkContentDeserializer *deserializer = source_object;
- GBytes *bytes;
- GError *error = NULL;
- GdkTexture *texture = NULL;
-
- bytes = read_all_data (gdk_content_deserializer_get_input_stream (deserializer), &error);
- if (bytes)
- {
- texture = gdk_texture_new_from_bytes (bytes, &error);
- g_bytes_unref (bytes);
- }
+ GOutputStream *output;
- if (texture)
- g_task_return_pointer (task, texture, g_object_unref);
- else
- g_task_return_error (task, error);
-}
+ output = g_memory_output_stream_new_resizable ();
-static void
-texture_deserializer (GdkContentDeserializer *deserializer)
-{
- GTask *task;
-
- task = g_task_new (deserializer,
- gdk_content_deserializer_get_cancellable (deserializer),
- texture_deserializer_finish,
- NULL);
- g_task_run_in_thread (task, deserialize_texture_in_thread);
- g_object_unref (task);
+ g_output_stream_splice_async (output,
+ gdk_content_deserializer_get_input_stream (deserializer),
+ G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE
+ | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+ gdk_content_deserializer_get_priority (deserializer),
+ gdk_content_deserializer_get_cancellable (deserializer),
+ texture_deserializer_finish,
+ deserializer);
+ g_object_unref (output);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]