forked from AuroraMiddleware/gtk
Merge branch 'widgetfactory-async-load' into 'master'
Revert "Use GtkLoader for image loading" See merge request GNOME/gtk!3986
This commit is contained in:
commit
20f6610c61
@ -17,11 +17,12 @@
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkloaderprivate.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "gtksnapshot.h"
|
||||
enum {
|
||||
PROP_RESOURCE = 1,
|
||||
};
|
||||
|
||||
struct _GtkLoader
|
||||
{
|
||||
@ -67,7 +68,7 @@ gtk_loader_paintable_get_intrinsic_width (GdkPaintable *paintable)
|
||||
if (self->texture)
|
||||
return gdk_paintable_get_intrinsic_width (GDK_PAINTABLE (self->texture));
|
||||
|
||||
return 16;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -78,7 +79,7 @@ gtk_loader_paintable_get_intrinsic_height (GdkPaintable *paintable)
|
||||
if (self->texture)
|
||||
return gdk_paintable_get_intrinsic_height (GDK_PAINTABLE (self->texture));
|
||||
|
||||
return 16;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double
|
||||
@ -116,12 +117,40 @@ gtk_loader_dispose (GObject *object)
|
||||
G_OBJECT_CLASS (gtk_loader_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void gtk_loader_set_resource (GtkLoader *self, const char *resource);
|
||||
|
||||
static void
|
||||
gtk_loader_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkLoader *self = (GtkLoader *)object;
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_RESOURCE:
|
||||
gtk_loader_set_resource (self, g_value_get_string (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_loader_class_init (GtkLoaderClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
gobject_class->dispose = gtk_loader_dispose;
|
||||
gobject_class->set_property = gtk_loader_set_property;
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_RESOURCE,
|
||||
g_param_spec_string ("resource", "", "",
|
||||
NULL,
|
||||
G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -135,11 +164,11 @@ load_texture_in_thread (GTask *task,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
GBytes *bytes = task_data;
|
||||
const char *resource = task_data;
|
||||
GdkTexture *texture;
|
||||
GError *error = NULL;
|
||||
|
||||
texture = gdk_texture_new_from_bytes (bytes, &error);
|
||||
texture = gdk_texture_new_from_resource (resource);
|
||||
|
||||
if (texture)
|
||||
g_task_return_pointer (task, texture, g_object_unref);
|
||||
@ -167,20 +196,20 @@ texture_finished (GObject *source,
|
||||
}
|
||||
}
|
||||
|
||||
GdkPaintable *
|
||||
gtk_loader_new (GBytes *bytes)
|
||||
static void
|
||||
gtk_loader_set_resource (GtkLoader *self,
|
||||
const char *resource)
|
||||
{
|
||||
GtkLoader *self;
|
||||
GTask *task;
|
||||
|
||||
g_return_val_if_fail (bytes != NULL, NULL);
|
||||
|
||||
self = g_object_new (GTK_TYPE_LOADER, NULL);
|
||||
|
||||
task = g_task_new (self, NULL, texture_finished, NULL);
|
||||
g_task_set_task_data (task, g_bytes_ref (bytes), (GDestroyNotify)g_bytes_unref);
|
||||
g_task_set_task_data (task, g_strdup (resource), (GDestroyNotify)g_free);
|
||||
g_task_run_in_thread (task, load_texture_in_thread);
|
||||
g_object_unref (task);
|
||||
|
||||
return GDK_PAINTABLE (self);
|
||||
}
|
||||
|
||||
GdkPaintable *
|
||||
gtk_loader_new (void)
|
||||
{
|
||||
return g_object_new (GTK_TYPE_LOADER, NULL);
|
||||
}
|
@ -28,7 +28,7 @@ G_BEGIN_DECLS
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GtkLoader, gtk_loader, GTK, LOADER, GObject)
|
||||
|
||||
GdkPaintable * gtk_loader_new (GBytes *bytes);
|
||||
GdkPaintable * gtk_loader_new (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -6,7 +6,7 @@ widgetfactory_resources = gnome.compile_resources('widgetfactory_resources',
|
||||
)
|
||||
|
||||
executable('gtk4-widget-factory',
|
||||
sources: ['widget-factory.c', widgetfactory_resources],
|
||||
sources: ['widget-factory.c', 'gtkloader.c', widgetfactory_resources],
|
||||
c_args: common_cflags,
|
||||
dependencies: [ libgtk_dep, demo_conf_h ],
|
||||
include_directories: confinc,
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "demo_conf.h"
|
||||
#include "gtkloaderprivate.h"
|
||||
|
||||
static void
|
||||
change_dark_state (GSimpleAction *action,
|
||||
@ -2054,6 +2055,7 @@ activate (GApplication *app)
|
||||
GtkEventController *controller;
|
||||
|
||||
g_type_ensure (my_text_view_get_type ());
|
||||
g_type_ensure (gtk_loader_get_type ());
|
||||
|
||||
provider = gtk_css_provider_new ();
|
||||
gtk_css_provider_load_from_resource (provider, "/org/gtk/WidgetFactory4/widget-factory.css");
|
||||
|
@ -1251,7 +1251,11 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
|
||||
<object class="GtkNotebookPage">
|
||||
<property name="child">
|
||||
<object class="GtkPicture">
|
||||
<property name="file">resource:///org/gtk/WidgetFactory4/sunset.jpg</property>
|
||||
<property name="paintable">
|
||||
<object class="GtkLoader">
|
||||
<property name="resource">/org/gtk/WidgetFactory4/sunset.jpg</property>
|
||||
</object>
|
||||
</property>
|
||||
<child>
|
||||
<object class="GtkDragSource">
|
||||
<property name="actions">copy</property>
|
||||
@ -1278,7 +1282,11 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
|
||||
<object class="GtkNotebookPage">
|
||||
<property name="child">
|
||||
<object class="GtkPicture">
|
||||
<property name="file">resource:///org/gtk/WidgetFactory4/nyc.jpg</property>
|
||||
<property name="paintable">
|
||||
<object class="GtkLoader">
|
||||
<property name="resource">/org/gtk/WidgetFactory4/nyc.jpg</property>
|
||||
</object>
|
||||
</property>
|
||||
<child>
|
||||
<object class="GtkDragSource">
|
||||
<property name="actions">copy</property>
|
||||
@ -1305,7 +1313,11 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
|
||||
<object class="GtkNotebookPage">
|
||||
<property name="child">
|
||||
<object class="GtkPicture">
|
||||
<property name="file">resource:///org/gtk/WidgetFactory4/beach.jpg</property>
|
||||
<property name="paintable">
|
||||
<object class="GtkLoader">
|
||||
<property name="resource">/org/gtk/WidgetFactory4/beach.jpg</property>
|
||||
</object>
|
||||
</property>
|
||||
<child>
|
||||
<object class="GtkDragSource">
|
||||
<property name="actions">copy</property>
|
||||
|
@ -409,6 +409,10 @@ gdk_texture_new_for_surface (cairo_surface_t *surface)
|
||||
*
|
||||
* Creates a new texture object representing the `GdkPixbuf`.
|
||||
*
|
||||
* This function is threadsafe, so that you can e.g. use GTask
|
||||
* and g_task_run_in_thread() to avoid blocking the main thread
|
||||
* while loading a big image.
|
||||
*
|
||||
* Returns: a new `GdkTexture`
|
||||
*/
|
||||
GdkTexture *
|
||||
@ -451,6 +455,10 @@ gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf)
|
||||
* If you are unsure about the validity of a resource, use
|
||||
* [ctor@Gdk.Texture.new_from_file] to load it.
|
||||
*
|
||||
* This function is threadsafe, so that you can e.g. use GTask
|
||||
* and g_task_run_in_thread() to avoid blocking the main thread
|
||||
* while loading a big image.
|
||||
*
|
||||
* Return value: A newly-created `GdkTexture`
|
||||
*/
|
||||
GdkTexture *
|
||||
@ -489,6 +497,10 @@ gdk_texture_new_from_resource (const char *resource_path)
|
||||
*
|
||||
* If %NULL is returned, then @error will be set.
|
||||
*
|
||||
* This function is threadsafe, so that you can e.g. use GTask
|
||||
* and g_task_run_in_thread() to avoid blocking the main thread
|
||||
* while loading a big image.
|
||||
*
|
||||
* Return value: A newly-created `GdkTexture`
|
||||
*/
|
||||
GdkTexture *
|
||||
@ -578,6 +590,10 @@ gdk_texture_new_from_bytes_pixbuf (GBytes *bytes,
|
||||
*
|
||||
* If %NULL is returned, then @error will be set.
|
||||
*
|
||||
* This function is threadsafe, so that you can e.g. use GTask
|
||||
* and g_task_run_in_thread() to avoid blocking the main thread
|
||||
* while loading a big image.
|
||||
*
|
||||
* Return value: A newly-created `GdkTexture`
|
||||
*
|
||||
* Since: 4.6
|
||||
@ -620,6 +636,10 @@ gdk_texture_new_from_bytes (GBytes *bytes,
|
||||
*
|
||||
* If %NULL is returned, then @error will be set.
|
||||
*
|
||||
* This function is threadsafe, so that you can e.g. use GTask
|
||||
* and g_task_run_in_thread() to avoid blocking the main thread
|
||||
* while loading a big image.
|
||||
*
|
||||
* Return value: A newly-created `GdkTexture`
|
||||
*/
|
||||
GdkTexture *
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <gdk/gdk.h>
|
||||
#include "gdkpixbufutilsprivate.h"
|
||||
#include "gtkscalerprivate.h"
|
||||
#include "gtkloaderprivate.h"
|
||||
|
||||
#include "gdk/gdktextureprivate.h"
|
||||
|
||||
@ -581,7 +580,7 @@ gdk_paintable_new_from_bytes_scaled (GBytes *bytes,
|
||||
int scale_factor)
|
||||
{
|
||||
LoaderData loader_data;
|
||||
GdkPaintable *inner;
|
||||
GdkTexture *texture;
|
||||
GdkPaintable *paintable;
|
||||
|
||||
loader_data.scale_factor = scale_factor;
|
||||
@ -589,8 +588,8 @@ gdk_paintable_new_from_bytes_scaled (GBytes *bytes,
|
||||
if (gdk_texture_can_load (bytes))
|
||||
{
|
||||
/* We know these formats can't be scaled */
|
||||
inner = GDK_PAINTABLE (gtk_loader_new (bytes));
|
||||
if (inner == NULL)
|
||||
texture = gdk_texture_new_from_bytes (bytes, NULL);
|
||||
if (texture == NULL)
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
@ -609,16 +608,16 @@ gdk_paintable_new_from_bytes_scaled (GBytes *bytes,
|
||||
if (!success)
|
||||
return NULL;
|
||||
|
||||
inner = GDK_PAINTABLE (gdk_texture_new_for_pixbuf (gdk_pixbuf_loader_get_pixbuf (loader)));
|
||||
texture = gdk_texture_new_for_pixbuf (gdk_pixbuf_loader_get_pixbuf (loader));
|
||||
g_object_unref (loader);
|
||||
}
|
||||
|
||||
if (loader_data.scale_factor != 1)
|
||||
paintable = gtk_scaler_new (inner, loader_data.scale_factor);
|
||||
paintable = gtk_scaler_new (GDK_PAINTABLE (texture), loader_data.scale_factor);
|
||||
else
|
||||
paintable = g_object_ref ((GdkPaintable *)inner);
|
||||
paintable = g_object_ref ((GdkPaintable *)texture);
|
||||
|
||||
g_object_unref (inner);
|
||||
g_object_unref (texture);
|
||||
|
||||
return paintable;
|
||||
}
|
||||
|
@ -116,7 +116,6 @@ gtk_private_sources = files([
|
||||
'gtkiconhelper.c',
|
||||
'gtkjoinedmenu.c',
|
||||
'gtkkineticscrolling.c',
|
||||
'gtkloader.c',
|
||||
'gtkmagnifier.c',
|
||||
'gtkmenusectionbox.c',
|
||||
'gtkmenutracker.c',
|
||||
|
Loading…
Reference in New Issue
Block a user