background: purge all background textures on suspend

This commit makes sure all background textures get purged
on suspend, which is important for nvidia.
This commit is contained in:
Ray Strode 2019-01-09 16:57:05 -05:00
parent 2fc0652886
commit 395d463c08
3 changed files with 48 additions and 1 deletions

View File

@ -279,6 +279,34 @@ meta_background_image_cache_purge (MetaBackgroundImageCache *cache,
image->in_cache = FALSE; image->in_cache = FALSE;
} }
/**
* meta_background_image_cache_unload_all:
* @cache: a #MetaBackgroundImageCache
*
* Remove all entries from the cache and unloads them; this would be used
* if textures in video memory have been invalidated.
*/
void
meta_background_image_cache_unload_all (MetaBackgroundImageCache *cache)
{
GHashTableIter iter;
gpointer key, value;
g_return_if_fail (META_IS_BACKGROUND_IMAGE_CACHE (cache));
g_hash_table_iter_init (&iter, cache->images);
while (g_hash_table_iter_next (&iter, &key, &value))
{
MetaBackgroundImage *image = value;
g_clear_pointer (&image->texture, cogl_object_unref);
image->in_cache = FALSE;
image->loaded = FALSE;
}
g_hash_table_remove_all (cache->images);
}
G_DEFINE_TYPE (MetaBackgroundImage, meta_background_image, G_TYPE_OBJECT); G_DEFINE_TYPE (MetaBackgroundImage, meta_background_image, G_TYPE_OBJECT);
static void static void

View File

@ -317,6 +317,20 @@ meta_background_finalize (GObject *object)
G_OBJECT_CLASS (meta_background_parent_class)->finalize (object); G_OBJECT_CLASS (meta_background_parent_class)->finalize (object);
} }
static void
free_textures (MetaBackground *self)
{
MetaBackgroundPrivate *priv = self->priv;
free_color_texture (self);
free_wallpaper_texture (self);
set_file (self, &priv->file1, &priv->background_image1, NULL);
set_file (self, &priv->file2, &priv->background_image2, NULL);
mark_changed (self);
}
static void static void
meta_background_constructed (GObject *object) meta_background_constructed (GObject *object)
{ {
@ -326,7 +340,7 @@ meta_background_constructed (GObject *object)
G_OBJECT_CLASS (meta_background_parent_class)->constructed (object); G_OBJECT_CLASS (meta_background_parent_class)->constructed (object);
g_signal_connect_object (meta_screen_get_display (priv->screen), "gl-video-memory-purged", g_signal_connect_object (meta_screen_get_display (priv->screen), "gl-video-memory-purged",
G_CALLBACK (mark_changed), object, G_CONNECT_SWAPPED); G_CALLBACK (free_textures), object, G_CONNECT_SWAPPED);
} }
static void static void
@ -960,8 +974,11 @@ meta_background_set_blend (MetaBackground *self,
void void
meta_background_refresh_all (void) meta_background_refresh_all (void)
{ {
MetaBackgroundImageCache *cache = meta_background_image_cache_get_default ();
GSList *l; GSList *l;
meta_background_image_cache_unload_all (cache);
for (l = all_backgrounds; l; l = l->next) for (l = all_backgrounds; l; l = l->next)
mark_changed (l->data); mark_changed (l->data);
} }

View File

@ -73,4 +73,6 @@ MetaBackgroundImage *meta_background_image_cache_load (MetaBackgroundImageCache
void meta_background_image_cache_purge (MetaBackgroundImageCache *cache, void meta_background_image_cache_purge (MetaBackgroundImageCache *cache,
GFile *file); GFile *file);
void meta_background_image_cache_unload_all (MetaBackgroundImageCache *cache);
#endif /* __META_BACKGROUND_IMAGE_H__ */ #endif /* __META_BACKGROUND_IMAGE_H__ */