texture-cache: Avoid creating unnecessary ClutterImages

After loading the GdkPixbuf, StTextureCache unconditionally
creates a ClutterImage and, if it's not in the cache, add
it to the cache. That's a waste of resources when the image
is already committed to the texture cache.

Fix that by reusing the ClutterImage of the cache if it is
already there; otherwise, create a new ClutterImage as we
were previously doing.
This commit is contained in:
Georges Basile Stavracas Neto 2019-01-24 13:57:40 -02:00
parent deec0bf255
commit 1847a4f4cc
No known key found for this signature in database
GPG Key ID: 886C17EE170D1385

View File

@ -528,20 +528,30 @@ finish_texture_load (AsyncTextureLoadData *data,
if (pixbuf == NULL)
goto out;
image = pixbuf_to_clutter_image (pixbuf);
if (!image)
goto out;
if (data->policy != ST_TEXTURE_CACHE_POLICY_NONE)
{
gpointer orig_key, value;
gpointer orig_key = NULL, value = NULL;
if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
&orig_key, &value))
{
image = pixbuf_to_clutter_image (pixbuf);
if (!image)
goto out;
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (data->key),
g_object_ref (image));
}
else
{
image = g_object_ref (value);
}
}
else
{
image = pixbuf_to_clutter_image (pixbuf);
if (!image)
goto out;
}
for (iter = data->actors; iter; iter = iter->next)