[gnome-shell] st: Port to GTask
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] st: Port to GTask
- Date: Thu, 15 Oct 2015 21:11:13 +0000 (UTC)
commit f2731d4d6a9ca1338dbc38c8f33fdde0113f9b50
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Sep 25 20:25:41 2015 +0200
st: Port to GTask
GSimpleAsyncResult has been deprecated for a while.
src/st/st-texture-cache.c | 55 ++++++++++++++++++--------------------------
1 files changed, 23 insertions(+), 32 deletions(-)
---
diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c
index 5cc48e3..d4a4ee9 100644
--- a/src/st/st-texture-cache.c
+++ b/src/st/st-texture-cache.c
@@ -430,38 +430,30 @@ impl_load_pixbuf_file (GFile *file,
}
static void
-load_pixbuf_thread (GSimpleAsyncResult *result,
- GObject *object,
+load_pixbuf_thread (GTask *result,
+ gpointer source,
+ gpointer task_data,
GCancellable *cancellable)
{
GdkPixbuf *pixbuf;
- AsyncTextureLoadData *data;
+ AsyncTextureLoadData *data = task_data;
GError *error = NULL;
- data = g_async_result_get_user_data (G_ASYNC_RESULT (result));
g_assert (data != NULL);
g_assert (data->file != NULL);
pixbuf = impl_load_pixbuf_file (data->file, data->width, data->height, data->scale, &error);
if (error != NULL)
- {
- g_simple_async_result_set_from_error (result, error);
- return;
- }
-
- if (pixbuf)
- g_simple_async_result_set_op_res_gpointer (result, g_object_ref (pixbuf),
- g_object_unref);
+ g_task_return_error (result, error);
+ else if (pixbuf)
+ g_task_return_pointer (result, g_object_ref (pixbuf), g_object_unref);
}
static GdkPixbuf *
load_pixbuf_async_finish (StTextureCache *cache, GAsyncResult *result, GError **error)
{
- GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
- if (g_simple_async_result_propagate_error (simple, error))
- return NULL;
- return g_simple_async_result_get_op_res_gpointer (simple);
+ return g_task_propagate_pointer (G_TASK (result), error);
}
static CoglTexture *
@@ -582,10 +574,9 @@ load_texture_async (StTextureCache *cache,
{
if (data->file)
{
- GSimpleAsyncResult *result;
- result = g_simple_async_result_new (G_OBJECT (cache), on_pixbuf_loaded, data, load_texture_async);
- g_simple_async_result_run_in_thread (result, load_pixbuf_thread, G_PRIORITY_DEFAULT, NULL);
- g_object_unref (result);
+ GTask *task = g_task_new (cache, NULL, on_pixbuf_loaded, data);
+ g_task_run_in_thread (task, load_pixbuf_thread);
+ g_object_unref (task);
}
else if (data->icon_info)
{
@@ -1024,13 +1015,13 @@ on_sliced_image_loaded (GObject *source_object,
{
GObject *cache = source_object;
AsyncImageData *data = (AsyncImageData *)user_data;
- GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
+ GTask *task = G_TASK (res);
GList *list;
- if (g_simple_async_result_propagate_error (simple, NULL))
+ if (g_task_had_error (task))
return;
- for (list = g_simple_async_result_get_op_res_gpointer (simple); list; list = g_list_next (list))
+ for (list = g_task_propagate_pointer (task, NULL); list; list = list->next)
{
ClutterActor *actor = load_from_pixbuf (GDK_PIXBUF (list->data));
clutter_actor_hide (actor);
@@ -1065,8 +1056,9 @@ on_loader_size_prepared (GdkPixbufLoader *loader,
}
static void
-load_sliced_image (GSimpleAsyncResult *result,
- GObject *object,
+load_sliced_image (GTask *result,
+ gpointer object,
+ gpointer task_data,
GCancellable *cancellable)
{
AsyncImageData *data;
@@ -1079,7 +1071,7 @@ load_sliced_image (GSimpleAsyncResult *result,
g_assert (!cancellable);
- data = g_object_get_data (G_OBJECT (result), "load_sliced_image");
+ data = task_data;
g_assert (data);
loader = gdk_pixbuf_loader_new ();
@@ -1114,7 +1106,7 @@ load_sliced_image (GSimpleAsyncResult *result,
* though the subpixbufs will hold a reference. */
g_object_unref (loader);
g_free (buffer);
- g_simple_async_result_set_op_res_gpointer (result, res, free_glist_unref_gobjects);
+ g_task_return_pointer (result, res, free_glist_unref_gobjects);
}
/**
@@ -1144,7 +1136,7 @@ st_texture_cache_load_sliced_image (StTextureCache *cache,
gpointer user_data)
{
AsyncImageData *data;
- GSimpleAsyncResult *result;
+ GTask *result;
ClutterActor *actor = clutter_actor_new ();
data = g_new0 (AsyncImageData, 1);
@@ -1157,10 +1149,9 @@ st_texture_cache_load_sliced_image (StTextureCache *cache,
data->load_callback_data = user_data;
g_object_ref (G_OBJECT (actor));
- result = g_simple_async_result_new (G_OBJECT (cache), on_sliced_image_loaded, data,
st_texture_cache_load_sliced_image);
-
- g_object_set_data_full (G_OBJECT (result), "load_sliced_image", data, on_data_destroy);
- g_simple_async_result_run_in_thread (result, load_sliced_image, G_PRIORITY_DEFAULT, NULL);
+ result = g_task_new (cache, NULL, on_sliced_image_loaded, data);
+ g_task_set_task_data (result, data, on_data_destroy);
+ g_task_run_in_thread (result, load_sliced_image);
g_object_unref (result);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]