static cairo_surface_t * st_texture_cache_load_uri_sync_to_cairo_surface (StTextureCache *cache, StTextureCachePolicy policy, const gchar *uri, int available_width, int available_height, GError **error) { cairo_surface_t *surface; GdkPixbuf *pixbuf; char *key; int width = available_width == -1 ? -1 : available_width * cache->priv->scale; int height = available_height == -1 ? -1 : available_height * cache->priv->scale; key = g_strconcat (CACHE_PREFIX_URI_FOR_CAIRO, uri, NULL); surface = g_hash_table_lookup (cache->priv->keyed_surface_cache, key); if (surface == NULL) { pixbuf = impl_load_pixbuf_file (uri, width, height, 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_surface_cache, g_strdup (key), surface); } } else cairo_surface_reference (surface); ensure_monitor_for_uri (cache, uri); out: free (key); return surface; }
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; }