diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index 99fd76c258..146ecfab26 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -2056,6 +2056,67 @@ hide_widget (GtkWidget *widget) gtk_widget_set_visible (widget, FALSE); } +static void +load_texture_thread (GTask *task, + gpointer source_object, + gpointer task_data, + GCancellable *cancellable) +{ + const char *resource_path = (const char *) task_data; + GBytes *bytes; + GdkTexture *texture; + GError *error = NULL; + + bytes = g_resources_lookup_data (resource_path, 0, &error); + if (!bytes) + { + g_task_return_error (task, error); + return; + } + + texture = gdk_texture_new_from_bytes (bytes, &error); + g_bytes_unref (bytes); + + if (!texture) + { + g_task_return_error (task, error); + return; + } + + g_task_return_pointer (task, texture, g_object_unref); +} + +static void +load_texture_done (GObject *source, + GAsyncResult *result, + gpointer data) +{ + GtkWidget *picture = GTK_WIDGET (source); + GdkTexture *texture; + GError *error = NULL; + + texture = g_task_propagate_pointer (G_TASK (result), &error); + if (!texture) + { + g_warning ("%s", error->message); + g_error_free (error); + return; + } + + gtk_picture_set_paintable (GTK_PICTURE (picture), GDK_PAINTABLE (texture)); + g_object_unref (texture); +} + +static void +load_texture_in_thread (GtkWidget *picture, + const char *resource_path) +{ + GTask *task = g_task_new (picture, NULL, load_texture_done, NULL); + g_task_set_task_data (task, (gpointer)resource_path, NULL); + g_task_run_in_thread (task, load_texture_thread); + g_object_unref (task); +} + static void activate (GApplication *app) { @@ -2155,6 +2216,13 @@ activate (GApplication *app) window = (GtkWindow *)gtk_builder_get_object (builder, "window"); + load_texture_in_thread ((GtkWidget *)gtk_builder_get_object (builder, "notebook_sunset"), + "/org/gtk/WidgetFactory4/sunset.jpg"); + load_texture_in_thread ((GtkWidget *)gtk_builder_get_object (builder, "notebook_nyc"), + "/org/gtk/WidgetFactory4/nyc.jpg"); + load_texture_in_thread ((GtkWidget *)gtk_builder_get_object (builder, "notebook_beach"), + "/org/gtk/WidgetFactory4/beach.jpg"); + if (g_strcmp0 (PROFILE, "devel") == 0) gtk_widget_add_css_class (GTK_WIDGET (window), "devel"); diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui index db55c43cc4..9c3b5d7e84 100644 --- a/demos/widget-factory/widget-factory.ui +++ b/demos/widget-factory/widget-factory.ui @@ -1263,8 +1263,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus. - - resource:///org/gtk/WidgetFactory4/sunset.jpg + cover @@ -1290,8 +1289,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus. - - resource:///org/gtk/WidgetFactory4/nyc.jpg + @@ -1316,8 +1314,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus. - - resource:///org/gtk/WidgetFactory4/beach.jpg + diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c index 3c4bf10634..bac18dc9fe 100644 --- a/gdk/gdktexture.c +++ b/gdk/gdktexture.c @@ -463,7 +463,7 @@ gdk_texture_new_from_resource (const char *resource_path) * Creates a new texture by loading an image from a file. * * The file format is detected automatically. The supported formats - * are PNG and JPEG, though more formats might be available. + * are PNG, JPEG and TIFF, though more formats might be available. * * If %NULL is returned, then @error will be set. * @@ -556,7 +556,7 @@ gdk_texture_new_from_bytes_pixbuf (GBytes *bytes, * Creates a new texture by loading an image from memory, * * The file format is detected automatically. The supported formats - * are PNG and JPEG, though more formats might be available. + * are PNG, JPEG and TIFF, though more formats might be available. * * If %NULL is returned, then @error will be set. * @@ -602,7 +602,7 @@ gdk_texture_new_from_bytes (GBytes *bytes, * Creates a new texture by loading an image from a file. * * The file format is detected automatically. The supported formats - * are PNG and JPEG, though more formats might be available. + * are PNG, JPEG and TIFF, though more formats might be available. * * If %NULL is returned, then @error will be set. *