kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone
Blob Blame History Raw
From c78a614b0d45a4bc8101a93c7138c9fb6102d13c Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Wed, 9 Jan 2019 16:57:05 -0500
Subject: [PATCH 8/9] background: purge all background textures on suspend

This commit makes sure all background textures get purged
on suspend, which is important for nvidia.
---
 src/compositor/meta-background-image.c | 28 ++++++++++++++++++++++++++
 src/compositor/meta-background.c       | 17 +++++++++++++++-
 src/meta/meta-background-image.h       |  2 ++
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/compositor/meta-background-image.c b/src/compositor/meta-background-image.c
index 14d3baf57..98909cb53 100644
--- a/src/compositor/meta-background-image.c
+++ b/src/compositor/meta-background-image.c
@@ -283,6 +283,34 @@ meta_background_image_cache_purge (MetaBackgroundImageCache *cache,
   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);
 
 static void
diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c
index c033395fe..abdfcc7df 100644
--- a/src/compositor/meta-background.c
+++ b/src/compositor/meta-background.c
@@ -303,6 +303,18 @@ meta_background_finalize (GObject *object)
   G_OBJECT_CLASS (meta_background_parent_class)->finalize (object);
 }
 
+static void
+free_textures (MetaBackground *self)
+{
+  free_color_texture (self);
+  free_wallpaper_texture (self);
+
+  set_file (self, &self->file1, &self->background_image1, NULL);
+  set_file (self, &self->file2, &self->background_image2, NULL);
+
+  mark_changed (self);
+}
+
 static void
 meta_background_constructed (GObject *object)
 {
@@ -312,7 +324,7 @@ meta_background_constructed (GObject *object)
   G_OBJECT_CLASS (meta_background_parent_class)->constructed (object);
 
   g_signal_connect_object (self->display, "gl-video-memory-purged",
-                           G_CALLBACK (mark_changed), object, G_CONNECT_SWAPPED);
+                           G_CALLBACK (free_textures), object, G_CONNECT_SWAPPED);
 
   g_signal_connect_object (monitor_manager, "monitors-changed",
                            G_CALLBACK (on_monitors_changed), self,
@@ -950,8 +962,11 @@ meta_background_set_blend (MetaBackground          *self,
 void
 meta_background_refresh_all (void)
 {
+  MetaBackgroundImageCache *cache = meta_background_image_cache_get_default ();
   GSList *l;
 
+  meta_background_image_cache_unload_all (cache);
+
   for (l = all_backgrounds; l; l = l->next)
     mark_changed (l->data);
 }
diff --git a/src/meta/meta-background-image.h b/src/meta/meta-background-image.h
index 137a6ff8e..87e40d251 100644
--- a/src/meta/meta-background-image.h
+++ b/src/meta/meta-background-image.h
@@ -66,4 +66,6 @@ META_EXPORT
 void                 meta_background_image_cache_purge (MetaBackgroundImageCache *cache,
                                                         GFile                    *file);
 
+void                 meta_background_image_cache_unload_all (MetaBackgroundImageCache *cache);
+
 #endif /* __META_BACKGROUND_IMAGE_H__ */
-- 
2.21.0