st/texture-cache: Remove load_sliced_image()
It was only used by the `Animation`/`AnimatedIcon` classes, which have now been removed since `Spinner` is now an independent implementation. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3612>
This commit is contained in:
parent
f24a624335
commit
9beacca329
@ -1043,31 +1043,6 @@ st_texture_cache_load_gicon (StTextureCache *cache,
|
||||
return actor;
|
||||
}
|
||||
|
||||
static ClutterActor *
|
||||
load_from_pixbuf (GdkPixbuf *pixbuf,
|
||||
int paint_scale,
|
||||
float resource_scale)
|
||||
{
|
||||
g_autoptr(ClutterContent) image = NULL;
|
||||
ClutterActor *actor;
|
||||
ClutterContext *context;
|
||||
ClutterBackend *backend;
|
||||
CoglContext *cogl_context;
|
||||
|
||||
actor = g_object_new (CLUTTER_TYPE_ACTOR,
|
||||
"request-mode", CLUTTER_REQUEST_CONTENT_SIZE,
|
||||
NULL);
|
||||
|
||||
context = clutter_actor_get_context (actor);
|
||||
backend = clutter_context_get_backend (context);
|
||||
cogl_context = clutter_backend_get_cogl_context (backend);
|
||||
image = pixbuf_to_st_content_image (pixbuf, cogl_context, -1, -1,
|
||||
paint_scale, resource_scale);
|
||||
clutter_actor_set_content (actor, image);
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
static void
|
||||
hash_table_remove_with_scales (GHashTable *hash,
|
||||
GList *scales,
|
||||
@ -1150,224 +1125,6 @@ ensure_monitor_for_file (StTextureCache *cache,
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GFile *gfile;
|
||||
gint grid_width, grid_height;
|
||||
gint paint_scale;
|
||||
gfloat resource_scale;
|
||||
ClutterActor *actor;
|
||||
GCancellable *cancellable;
|
||||
GFunc load_callback;
|
||||
gpointer load_callback_data;
|
||||
} AsyncImageData;
|
||||
|
||||
static void
|
||||
on_data_destroy (gpointer data)
|
||||
{
|
||||
AsyncImageData *d = (AsyncImageData *)data;
|
||||
g_object_unref (d->gfile);
|
||||
g_object_unref (d->actor);
|
||||
g_object_unref (d->cancellable);
|
||||
g_free (d);
|
||||
}
|
||||
|
||||
static void
|
||||
on_sliced_image_actor_destroyed (ClutterActor *actor,
|
||||
gpointer data)
|
||||
{
|
||||
GTask *task = data;
|
||||
GCancellable *cancellable = g_task_get_cancellable (task);
|
||||
|
||||
g_cancellable_cancel (cancellable);
|
||||
}
|
||||
|
||||
static void
|
||||
on_sliced_image_loaded (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GObject *cache = source_object;
|
||||
AsyncImageData *data = (AsyncImageData *)user_data;
|
||||
GTask *task = G_TASK (res);
|
||||
GList *list, *pixbufs;
|
||||
|
||||
if (g_task_had_error (task) || g_cancellable_is_cancelled (data->cancellable))
|
||||
return;
|
||||
|
||||
clutter_actor_set_layout_manager (data->actor,
|
||||
g_object_new (CLUTTER_TYPE_BIN_LAYOUT, NULL));
|
||||
/* stop propagation of child expand flags */
|
||||
clutter_actor_set_x_expand (data->actor, FALSE);
|
||||
clutter_actor_set_y_expand (data->actor, FALSE);
|
||||
|
||||
pixbufs = g_task_propagate_pointer (task, NULL);
|
||||
|
||||
for (list = pixbufs; list; list = list->next)
|
||||
{
|
||||
ClutterActor *actor = load_from_pixbuf (GDK_PIXBUF (list->data),
|
||||
data->paint_scale,
|
||||
data->resource_scale);
|
||||
clutter_actor_set_x_expand (actor, TRUE);
|
||||
clutter_actor_set_y_expand (actor, TRUE);
|
||||
clutter_actor_set_x_align (actor, CLUTTER_ACTOR_ALIGN_FILL);
|
||||
clutter_actor_set_y_align (actor, CLUTTER_ACTOR_ALIGN_FILL);
|
||||
clutter_actor_hide (actor);
|
||||
clutter_actor_add_child (data->actor, actor);
|
||||
}
|
||||
|
||||
g_list_free_full (pixbufs, g_object_unref);
|
||||
|
||||
g_signal_handlers_disconnect_by_func (data->actor,
|
||||
on_sliced_image_actor_destroyed,
|
||||
task);
|
||||
|
||||
if (data->load_callback != NULL)
|
||||
data->load_callback (cache, data->load_callback_data);
|
||||
}
|
||||
|
||||
static void
|
||||
free_glist_unref_gobjects (gpointer p)
|
||||
{
|
||||
g_list_free_full (p, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
on_loader_size_prepared (GdkPixbufLoader *loader,
|
||||
gint width,
|
||||
gint height,
|
||||
gpointer user_data)
|
||||
{
|
||||
AsyncImageData *data = user_data;
|
||||
int scale = ceilf (data->paint_scale * data->resource_scale);
|
||||
|
||||
gdk_pixbuf_loader_set_size (loader, width * scale, height * scale);
|
||||
}
|
||||
|
||||
static void
|
||||
load_sliced_image (GTask *result,
|
||||
gpointer object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
AsyncImageData *data;
|
||||
GList *res = NULL;
|
||||
GdkPixbuf *pix;
|
||||
gint width, height, y, x;
|
||||
gint scale_factor;
|
||||
GdkPixbufLoader *loader = NULL;
|
||||
GError *error = NULL;
|
||||
gchar *buffer = NULL;
|
||||
gsize length;
|
||||
|
||||
g_assert (cancellable);
|
||||
|
||||
data = task_data;
|
||||
g_assert (data);
|
||||
|
||||
if (!g_file_load_contents (data->gfile, cancellable, &buffer, &length, NULL, &error))
|
||||
{
|
||||
g_warning ("Failed to open sliced image: %s", error->message);
|
||||
goto out;
|
||||
}
|
||||
|
||||
loader = gdk_pixbuf_loader_new ();
|
||||
g_signal_connect (loader, "size-prepared", G_CALLBACK (on_loader_size_prepared), data);
|
||||
|
||||
if (!gdk_pixbuf_loader_write (loader, (const guchar *) buffer, length, &error))
|
||||
{
|
||||
g_warning ("Failed to load image: %s", error->message);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!gdk_pixbuf_loader_close (loader, NULL))
|
||||
goto out;
|
||||
|
||||
pix = gdk_pixbuf_loader_get_pixbuf (loader);
|
||||
width = gdk_pixbuf_get_width (pix);
|
||||
height = gdk_pixbuf_get_height (pix);
|
||||
scale_factor = ceilf (data->paint_scale * data->resource_scale);
|
||||
for (y = 0; y < height; y += data->grid_height * scale_factor)
|
||||
{
|
||||
for (x = 0; x < width; x += data->grid_width * scale_factor)
|
||||
{
|
||||
GdkPixbuf *pixbuf = gdk_pixbuf_new_subpixbuf (pix, x, y,
|
||||
data->grid_width * scale_factor,
|
||||
data->grid_height * scale_factor);
|
||||
g_assert (pixbuf != NULL);
|
||||
res = g_list_append (res, pixbuf);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
/* We don't need the original pixbuf anymore, which is owned by the loader,
|
||||
* though the subpixbufs will hold a reference. */
|
||||
g_clear_object (&loader);
|
||||
g_free (buffer);
|
||||
g_clear_pointer (&error, g_error_free);
|
||||
g_task_return_pointer (result, res, free_glist_unref_gobjects);
|
||||
}
|
||||
|
||||
/**
|
||||
* st_texture_cache_load_sliced_image:
|
||||
* @cache: A #StTextureCache
|
||||
* @file: A #GFile
|
||||
* @grid_width: Width in pixels
|
||||
* @grid_height: Height in pixels
|
||||
* @paint_scale: Scale factor of the display
|
||||
* @load_callback: (scope async) (nullable): Function called when the image is loaded, or %NULL
|
||||
* @user_data: Data to pass to the load callback
|
||||
*
|
||||
* This function reads a single image file which contains multiple images internally.
|
||||
* The image file will be divided using @grid_width and @grid_height;
|
||||
* note that the dimensions of the image loaded from @path
|
||||
* should be a multiple of the specified grid dimensions.
|
||||
*
|
||||
* Returns: (transfer none): A new #ClutterActor
|
||||
*/
|
||||
ClutterActor *
|
||||
st_texture_cache_load_sliced_image (StTextureCache *cache,
|
||||
GFile *file,
|
||||
gint grid_width,
|
||||
gint grid_height,
|
||||
gint paint_scale,
|
||||
gfloat resource_scale,
|
||||
GFunc load_callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
AsyncImageData *data;
|
||||
GTask *result;
|
||||
ClutterActor *actor = clutter_actor_new ();
|
||||
GCancellable *cancellable = g_cancellable_new ();
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
g_assert (paint_scale > 0);
|
||||
g_assert (resource_scale > 0);
|
||||
|
||||
data = g_new0 (AsyncImageData, 1);
|
||||
data->grid_width = grid_width;
|
||||
data->grid_height = grid_height;
|
||||
data->paint_scale = paint_scale;
|
||||
data->resource_scale = resource_scale;
|
||||
data->gfile = g_object_ref (file);
|
||||
data->actor = actor;
|
||||
data->cancellable = cancellable;
|
||||
data->load_callback = load_callback;
|
||||
data->load_callback_data = user_data;
|
||||
g_object_ref (G_OBJECT (actor));
|
||||
|
||||
result = g_task_new (cache, cancellable, on_sliced_image_loaded, data);
|
||||
|
||||
g_signal_connect (actor, "destroy",
|
||||
G_CALLBACK (on_sliced_image_actor_destroyed), result);
|
||||
|
||||
g_task_set_task_data (result, data, on_data_destroy);
|
||||
g_task_run_in_thread (result, load_sliced_image);
|
||||
|
||||
g_object_unref (result);
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* st_texture_cache_load_file_async:
|
||||
* @cache: A #StTextureCache
|
||||
|
@ -44,16 +44,6 @@ typedef enum {
|
||||
|
||||
StTextureCache* st_texture_cache_get_default (void);
|
||||
|
||||
ClutterActor *
|
||||
st_texture_cache_load_sliced_image (StTextureCache *cache,
|
||||
GFile *file,
|
||||
gint grid_width,
|
||||
gint grid_height,
|
||||
gint paint_scale,
|
||||
gfloat resource_scale,
|
||||
GFunc load_callback,
|
||||
gpointer user_data);
|
||||
|
||||
ClutterActor *st_texture_cache_load_gicon (StTextureCache *cache,
|
||||
StThemeNode *theme_node,
|
||||
GIcon *icon,
|
||||
|
Loading…
x
Reference in New Issue
Block a user