static void file_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other, GFileMonitorEvent event_type, gpointer user_data) { StTextureCache *cache = user_data; char *key; guint file_hash; if (event_type != G_FILE_MONITOR_EVENT_CHANGED) return; file_hash = g_file_hash (file); key = g_strdup_printf (CACHE_PREFIX_FILE "%u", file_hash); g_hash_table_remove (cache->priv->keyed_cache, key); g_free (key); key = g_strdup_printf (CACHE_PREFIX_FILE_FOR_CAIRO "%u", file_hash); g_hash_table_remove (cache->priv->keyed_cache, key); g_free (key); g_signal_emit (cache, signals[TEXTURE_FILE_CHANGED], 0, file); }
guint ide_file_hash (IdeFile *self) { g_return_val_if_fail (IDE_IS_FILE (self), 0); return g_file_hash (self->file); }
/** * st_texture_cache_load_file_async: * @cache: The texture cache instance * @file: a #GFile of the image file from which to create a pixbuf * @available_width: available width for the image, can be -1 if not limited * @available_height: available height for the image, can be -1 if not limited * @scale: scale factor of the display * * Asynchronously load an image. Initially, the returned texture will have a natural * size of zero. At some later point, either the image will be loaded successfully * and at that point size will be negotiated, or upon an error, no image will be set. * * Return value: (transfer none): A new #ClutterActor with no image loaded initially. */ ClutterActor * st_texture_cache_load_file_async (StTextureCache *cache, GFile *file, int available_width, int available_height, int scale) { ClutterActor *texture; AsyncTextureLoadData *request; StTextureCachePolicy policy; gchar *key; key = g_strdup_printf (CACHE_PREFIX_FILE "%u", g_file_hash (file)); policy = ST_TEXTURE_CACHE_POLICY_NONE; /* XXX */ texture = (ClutterActor *) create_default_texture (); if (ensure_request (cache, key, policy, &request, texture)) { /* If there's an outstanding request, we've just added ourselves to it */ g_free (key); } else { /* Else, make a new request */ request->cache = cache; /* Transfer ownership of key */ request->key = key; request->file = g_object_ref (file); request->policy = policy; request->width = available_width; request->height = available_height; request->scale = scale; load_texture_async (cache, request); } ensure_monitor_for_file (cache, file); return CLUTTER_ACTOR (texture); }
static cairo_surface_t * st_texture_cache_load_file_sync_to_cairo_surface (StTextureCache *cache, StTextureCachePolicy policy, GFile *file, int available_width, int available_height, int scale, GError **error) { cairo_surface_t *surface; GdkPixbuf *pixbuf; char *key; key = g_strdup_printf (CACHE_PREFIX_FILE_FOR_CAIRO "%u", g_file_hash (file)); surface = g_hash_table_lookup (cache->priv->keyed_cache, key); if (surface == NULL) { pixbuf = impl_load_pixbuf_file (file, available_width, available_height, scale, error); if (!pixbuf) goto out; surface = pixbuf_to_cairo_surface (pixbuf); g_object_unref (pixbuf); if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER) { cairo_surface_reference (surface); g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), surface); } } else cairo_surface_reference (surface); ensure_monitor_for_file (cache, file); out: g_free (key); return surface; }
static CoglTexture * st_texture_cache_load_file_sync_to_cogl_texture (StTextureCache *cache, StTextureCachePolicy policy, GFile *file, int available_width, int available_height, int scale, GError **error) { CoglTexture *texdata; GdkPixbuf *pixbuf; char *key; key = g_strdup_printf (CACHE_PREFIX_FILE "%u", g_file_hash (file)); texdata = g_hash_table_lookup (cache->priv->keyed_cache, key); if (texdata == NULL) { pixbuf = impl_load_pixbuf_file (file, available_width, available_height, scale, error); if (!pixbuf) goto out; texdata = pixbuf_to_cogl_texture (pixbuf); g_object_unref (pixbuf); if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER) { cogl_object_ref (texdata); g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata); } } else cogl_object_ref (texdata); ensure_monitor_for_file (cache, file); out: g_free (key); return texdata; }