kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone
Blob Blame History Raw
From 6bf00273a995597c22b3e98d9f4752fbb238f5ea 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       | 19 ++++++++++++++++-
 src/meta/meta-background-image.h       |  2 ++
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/src/compositor/meta-background-image.c b/src/compositor/meta-background-image.c
index b06066422..995e588fa 100644
--- a/src/compositor/meta-background-image.c
+++ b/src/compositor/meta-background-image.c
@@ -252,60 +252,88 @@ meta_background_image_cache_load (MetaBackgroundImageCache *cache,
   g_object_unref (task);
 
   return image;
 }
 
 /**
  * meta_background_image_cache_purge:
  * @cache: a #MetaBackgroundImageCache
  * @file: file to remove from the cache
  *
  * Remove an entry from the cache; this would be used if monitoring
  * showed that the file changed.
  */
 void
 meta_background_image_cache_purge (MetaBackgroundImageCache *cache,
                                    GFile                    *file)
 {
   MetaBackgroundImage *image;
 
   g_return_if_fail (META_IS_BACKGROUND_IMAGE_CACHE (cache));
   g_return_if_fail (file != NULL);
 
   image = g_hash_table_lookup (cache->images, file);
   if (image == NULL)
     return;
 
   g_hash_table_remove (cache->images, image->file);
   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
 meta_background_image_init (MetaBackgroundImage *image)
 {
 }
 
 static void
 meta_background_image_finalize (GObject *object)
 {
   MetaBackgroundImage *image = META_BACKGROUND_IMAGE (object);
 
   if (image->in_cache)
     g_hash_table_remove (image->cache->images, image->file);
 
   if (image->texture)
     cogl_object_unref (image->texture);
   if (image->file)
     g_object_unref (image->file);
 
   G_OBJECT_CLASS (meta_background_image_parent_class)->finalize (object);
 }
 
 static void
 meta_background_image_class_init (MetaBackgroundImageClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class->finalize = meta_background_image_finalize;
 
diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c
index 61dd12095..3d23f1fdc 100644
--- a/src/compositor/meta-background.c
+++ b/src/compositor/meta-background.c
@@ -290,70 +290,84 @@ set_file (MetaBackground       *self,
                             G_CALLBACK (on_background_loaded), self);
         }
     }
 }
 
 static void
 meta_background_dispose (GObject *object)
 {
   MetaBackground        *self = META_BACKGROUND (object);
   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);
 
   set_screen (self, NULL);
 
   G_OBJECT_CLASS (meta_background_parent_class)->dispose (object);
 }
 
 static void
 meta_background_finalize (GObject *object)
 {
   all_backgrounds = g_slist_remove (all_backgrounds, 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
 meta_background_constructed (GObject *object)
 {
   MetaBackground        *self = META_BACKGROUND (object);
   MetaBackgroundPrivate *priv = self->priv;
 
   G_OBJECT_CLASS (meta_background_parent_class)->constructed (object);
 
   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
 meta_background_class_init (MetaBackgroundClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GParamSpec *param_spec;
 
   g_type_class_add_private (klass, sizeof (MetaBackgroundPrivate));
 
   object_class->dispose = meta_background_dispose;
   object_class->finalize = meta_background_finalize;
   object_class->constructed = meta_background_constructed;
   object_class->set_property = meta_background_set_property;
   object_class->get_property = meta_background_get_property;
 
   signals[CHANGED] =
     g_signal_new ("changed",
                   G_TYPE_FROM_CLASS (object_class),
                   G_SIGNAL_RUN_LAST,
                   0,
                   NULL, NULL, NULL,
                   G_TYPE_NONE, 0);
 
   param_spec = g_param_spec_object ("meta-screen",
                                     "MetaScreen",
                                     "MetaScreen",
                                     META_TYPE_SCREEN,
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 
@@ -933,35 +947,38 @@ meta_background_set_file (MetaBackground            *self,
   meta_background_set_blend (self, file, NULL, 0.0, style);
 }
 
 void
 meta_background_set_blend (MetaBackground          *self,
                            GFile                   *file1,
                            GFile                   *file2,
                            double                   blend_factor,
                            GDesktopBackgroundStyle  style)
 {
   MetaBackgroundPrivate *priv;
 
   g_return_if_fail (META_IS_BACKGROUND (self));
   g_return_if_fail (blend_factor >= 0.0 && blend_factor <= 1.0);
 
   priv = self->priv;
 
   set_file (self, &priv->file1, &priv->background_image1, file1);
   set_file (self, &priv->file2, &priv->background_image2, file2);
 
   priv->blend_factor = blend_factor;
   priv->style = style;
 
   free_wallpaper_texture (self);
   mark_changed (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 fa67b42cf..5ecfb9753 100644
--- a/src/meta/meta-background-image.h
+++ b/src/meta/meta-background-image.h
@@ -46,31 +46,33 @@ GType meta_background_image_get_type (void);
 gboolean     meta_background_image_is_loaded   (MetaBackgroundImage *image);
 gboolean     meta_background_image_get_success (MetaBackgroundImage *image);
 CoglTexture *meta_background_image_get_texture (MetaBackgroundImage *image);
 
 #define META_TYPE_BACKGROUND_IMAGE_CACHE            (meta_background_image_cache_get_type ())
 #define META_BACKGROUND_IMAGE_CACHE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_BACKGROUND_IMAGE_CACHE, MetaBackgroundImageCache))
 #define META_BACKGROUND_IMAGE_CACHE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  META_TYPE_BACKGROUND_IMAGE_CACHE, MetaBackgroundImageCacheClass))
 #define META_IS_BACKGROUND_IMAGE_CACHE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_BACKGROUND_IMAGE_CACHE))
 #define META_IS_BACKGROUND_IMAGE_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  META_TYPE_BACKGROUND_IMAGE_CACHE))
 #define META_BACKGROUND_IMAGE_CACHE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  META_TYPE_BACKGROUND_IMAGE_CACHE, MetaBackgroundImageCacheClass))
 
 /**
  * MetaBackgroundImageCache:
  *
  * #MetaBackgroundImageCache caches loading of textures for backgrounds; there's actually
  * nothing background specific about it, other than it is tuned to work well for
  * large images as typically are used for backgrounds.
  */
 typedef struct _MetaBackgroundImageCache      MetaBackgroundImageCache;
 typedef struct _MetaBackgroundImageCacheClass MetaBackgroundImageCacheClass;
 
 MetaBackgroundImageCache *meta_background_image_cache_get_default (void);
 
 GType meta_background_image_cache_get_type (void);
 
 MetaBackgroundImage *meta_background_image_cache_load  (MetaBackgroundImageCache *cache,
                                                         GFile                    *file);
 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.18.1