st-texture-cache: Save cairo surfaces to a different map
The default keyed_surface is meant to handle CoglTextures thus we can't
add cairo surfaces to it, as the DestroyNotify function won't handle them.
Then the quicker way is to just add another Hash table for handling
such types of textures, with proper destroy function.
(cherry picked from commit 1f03599d1c
)
This commit is contained in:
parent
2c617e5a3a
commit
4b2e0247af
@ -37,6 +37,7 @@ struct _StTextureCachePrivate
|
||||
|
||||
/* Things that were loaded with a cache policy != NONE */
|
||||
GHashTable *keyed_cache; /* char * -> CoglTexture* */
|
||||
GHashTable *keyed_surface_cache; /* char * -> cairo_surface_t* */
|
||||
|
||||
/* Presently this is used to de-duplicate requests for GIcons and async URIs. */
|
||||
GHashTable *outstanding_requests; /* char * -> AsyncTextureLoadData * */
|
||||
@ -145,6 +146,10 @@ st_texture_cache_init (StTextureCache *self)
|
||||
|
||||
self->priv->keyed_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, cogl_object_unref);
|
||||
self->priv->keyed_surface_cache = g_hash_table_new_full (g_str_hash,
|
||||
g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify) cairo_surface_destroy);
|
||||
self->priv->outstanding_requests = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, NULL);
|
||||
self->priv->file_monitors = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
|
||||
@ -166,6 +171,7 @@ st_texture_cache_dispose (GObject *object)
|
||||
}
|
||||
|
||||
g_clear_pointer (&self->priv->keyed_cache, g_hash_table_destroy);
|
||||
g_clear_pointer (&self->priv->keyed_surface_cache, g_hash_table_destroy);
|
||||
g_clear_pointer (&self->priv->outstanding_requests, g_hash_table_destroy);
|
||||
g_clear_pointer (&self->priv->file_monitors, g_hash_table_destroy);
|
||||
|
||||
@ -988,7 +994,7 @@ file_changed_cb (GFileMonitor *monitor,
|
||||
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_hash_table_remove (cache->priv->keyed_surface_cache, key);
|
||||
g_free (key);
|
||||
|
||||
g_signal_emit (cache, signals[TEXTURE_FILE_CHANGED], 0, file);
|
||||
@ -1309,7 +1315,7 @@ st_texture_cache_load_file_sync_to_cairo_surface (StTextureCache *cache,
|
||||
|
||||
key = g_strdup_printf (CACHE_PREFIX_FILE_FOR_CAIRO "%u", g_file_hash (file));
|
||||
|
||||
surface = g_hash_table_lookup (cache->priv->keyed_cache, key);
|
||||
surface = g_hash_table_lookup (cache->priv->keyed_surface_cache, key);
|
||||
|
||||
if (surface == NULL)
|
||||
{
|
||||
@ -1323,7 +1329,8 @@ st_texture_cache_load_file_sync_to_cairo_surface (StTextureCache *cache,
|
||||
if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER)
|
||||
{
|
||||
cairo_surface_reference (surface);
|
||||
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), surface);
|
||||
g_hash_table_insert (cache->priv->keyed_surface_cache,
|
||||
g_strdup (key), surface);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user