Blame SOURCES/0008-background-purge-all-background-textures-on-suspend.patch

776610
From 6bf00273a995597c22b3e98d9f4752fbb238f5ea Mon Sep 17 00:00:00 2001
776610
From: Ray Strode <rstrode@redhat.com>
776610
Date: Wed, 9 Jan 2019 16:57:05 -0500
776610
Subject: [PATCH 8/9] background: purge all background textures on suspend
776610
776610
This commit makes sure all background textures get purged
776610
on suspend, which is important for nvidia.
776610
---
776610
 src/compositor/meta-background-image.c | 28 ++++++++++++++++++++++++++
776610
 src/compositor/meta-background.c       | 19 ++++++++++++++++-
776610
 src/meta/meta-background-image.h       |  2 ++
776610
 3 files changed, 48 insertions(+), 1 deletion(-)
776610
776610
diff --git a/src/compositor/meta-background-image.c b/src/compositor/meta-background-image.c
776610
index b06066422..995e588fa 100644
776610
--- a/src/compositor/meta-background-image.c
776610
+++ b/src/compositor/meta-background-image.c
776610
@@ -252,60 +252,88 @@ meta_background_image_cache_load (MetaBackgroundImageCache *cache,
776610
   g_object_unref (task);
776610
 
776610
   return image;
776610
 }
776610
 
776610
 /**
776610
  * meta_background_image_cache_purge:
776610
  * @cache: a #MetaBackgroundImageCache
776610
  * @file: file to remove from the cache
776610
  *
776610
  * Remove an entry from the cache; this would be used if monitoring
776610
  * showed that the file changed.
776610
  */
776610
 void
776610
 meta_background_image_cache_purge (MetaBackgroundImageCache *cache,
776610
                                    GFile                    *file)
776610
 {
776610
   MetaBackgroundImage *image;
776610
 
776610
   g_return_if_fail (META_IS_BACKGROUND_IMAGE_CACHE (cache));
776610
   g_return_if_fail (file != NULL);
776610
 
776610
   image = g_hash_table_lookup (cache->images, file);
776610
   if (image == NULL)
776610
     return;
776610
 
776610
   g_hash_table_remove (cache->images, image->file);
776610
   image->in_cache = FALSE;
776610
 }
776610
 
776610
+/**
776610
+ * meta_background_image_cache_unload_all:
776610
+ * @cache: a #MetaBackgroundImageCache
776610
+ *
776610
+ * Remove all entries from the cache and unloads them; this would be used
776610
+ * if textures in video memory have been invalidated.
776610
+ */
776610
+void
776610
+meta_background_image_cache_unload_all (MetaBackgroundImageCache *cache)
776610
+{
776610
+  GHashTableIter iter;
776610
+  gpointer key, value;
776610
+
776610
+  g_return_if_fail (META_IS_BACKGROUND_IMAGE_CACHE (cache));
776610
+
776610
+  g_hash_table_iter_init (&iter, cache->images);
776610
+  while (g_hash_table_iter_next (&iter, &key, &value))
776610
+    {
776610
+      MetaBackgroundImage *image = value;
776610
+
776610
+      g_clear_pointer (&image->texture, cogl_object_unref);
776610
+      image->in_cache = FALSE;
776610
+      image->loaded = FALSE;
776610
+    }
776610
+
776610
+  g_hash_table_remove_all (cache->images);
776610
+}
776610
+
776610
 G_DEFINE_TYPE (MetaBackgroundImage, meta_background_image, G_TYPE_OBJECT);
776610
 
776610
 static void
776610
 meta_background_image_init (MetaBackgroundImage *image)
776610
 {
776610
 }
776610
 
776610
 static void
776610
 meta_background_image_finalize (GObject *object)
776610
 {
776610
   MetaBackgroundImage *image = META_BACKGROUND_IMAGE (object);
776610
 
776610
   if (image->in_cache)
776610
     g_hash_table_remove (image->cache->images, image->file);
776610
 
776610
   if (image->texture)
776610
     cogl_object_unref (image->texture);
776610
   if (image->file)
776610
     g_object_unref (image->file);
776610
 
776610
   G_OBJECT_CLASS (meta_background_image_parent_class)->finalize (object);
776610
 }
776610
 
776610
 static void
776610
 meta_background_image_class_init (MetaBackgroundImageClass *klass)
776610
 {
776610
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
776610
 
776610
   object_class->finalize = meta_background_image_finalize;
776610
 
776610
diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c
776610
index 61dd12095..3d23f1fdc 100644
776610
--- a/src/compositor/meta-background.c
776610
+++ b/src/compositor/meta-background.c
776610
@@ -290,70 +290,84 @@ set_file (MetaBackground       *self,
776610
                             G_CALLBACK (on_background_loaded), self);
776610
         }
776610
     }
776610
 }
776610
 
776610
 static void
776610
 meta_background_dispose (GObject *object)
776610
 {
776610
   MetaBackground        *self = META_BACKGROUND (object);
776610
   MetaBackgroundPrivate *priv = self->priv;
776610
 
776610
   free_color_texture (self);
776610
   free_wallpaper_texture (self);
776610
 
776610
   set_file (self, &priv->file1, &priv->background_image1, NULL);
776610
   set_file (self, &priv->file2, &priv->background_image2, NULL);
776610
 
776610
   set_screen (self, NULL);
776610
 
776610
   G_OBJECT_CLASS (meta_background_parent_class)->dispose (object);
776610
 }
776610
 
776610
 static void
776610
 meta_background_finalize (GObject *object)
776610
 {
776610
   all_backgrounds = g_slist_remove (all_backgrounds, object);
776610
 
776610
   G_OBJECT_CLASS (meta_background_parent_class)->finalize (object);
776610
 }
776610
 
776610
+static void
776610
+free_textures (MetaBackground *self)
776610
+{
776610
+  MetaBackgroundPrivate *priv = self->priv;
776610
+
776610
+  free_color_texture (self);
776610
+  free_wallpaper_texture (self);
776610
+
776610
+  set_file (self, &priv->file1, &priv->background_image1, NULL);
776610
+  set_file (self, &priv->file2, &priv->background_image2, NULL);
776610
+
776610
+  mark_changed (self);
776610
+}
776610
+
776610
 static void
776610
 meta_background_constructed (GObject *object)
776610
 {
776610
   MetaBackground        *self = META_BACKGROUND (object);
776610
   MetaBackgroundPrivate *priv = self->priv;
776610
 
776610
   G_OBJECT_CLASS (meta_background_parent_class)->constructed (object);
776610
 
776610
   g_signal_connect_object (meta_screen_get_display (priv->screen), "gl-video-memory-purged",
776610
-                           G_CALLBACK (mark_changed), object, G_CONNECT_SWAPPED);
776610
+                           G_CALLBACK (free_textures), object, G_CONNECT_SWAPPED);
776610
 }
776610
 
776610
 static void
776610
 meta_background_class_init (MetaBackgroundClass *klass)
776610
 {
776610
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
776610
   GParamSpec *param_spec;
776610
 
776610
   g_type_class_add_private (klass, sizeof (MetaBackgroundPrivate));
776610
 
776610
   object_class->dispose = meta_background_dispose;
776610
   object_class->finalize = meta_background_finalize;
776610
   object_class->constructed = meta_background_constructed;
776610
   object_class->set_property = meta_background_set_property;
776610
   object_class->get_property = meta_background_get_property;
776610
 
776610
   signals[CHANGED] =
776610
     g_signal_new ("changed",
776610
                   G_TYPE_FROM_CLASS (object_class),
776610
                   G_SIGNAL_RUN_LAST,
776610
                   0,
776610
                   NULL, NULL, NULL,
776610
                   G_TYPE_NONE, 0);
776610
 
776610
   param_spec = g_param_spec_object ("meta-screen",
776610
                                     "MetaScreen",
776610
                                     "MetaScreen",
776610
                                     META_TYPE_SCREEN,
776610
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
776610
 
776610
@@ -933,35 +947,38 @@ meta_background_set_file (MetaBackground            *self,
776610
   meta_background_set_blend (self, file, NULL, 0.0, style);
776610
 }
776610
 
776610
 void
776610
 meta_background_set_blend (MetaBackground          *self,
776610
                            GFile                   *file1,
776610
                            GFile                   *file2,
776610
                            double                   blend_factor,
776610
                            GDesktopBackgroundStyle  style)
776610
 {
776610
   MetaBackgroundPrivate *priv;
776610
 
776610
   g_return_if_fail (META_IS_BACKGROUND (self));
776610
   g_return_if_fail (blend_factor >= 0.0 && blend_factor <= 1.0);
776610
 
776610
   priv = self->priv;
776610
 
776610
   set_file (self, &priv->file1, &priv->background_image1, file1);
776610
   set_file (self, &priv->file2, &priv->background_image2, file2);
776610
 
776610
   priv->blend_factor = blend_factor;
776610
   priv->style = style;
776610
 
776610
   free_wallpaper_texture (self);
776610
   mark_changed (self);
776610
 }
776610
 
776610
 void
776610
 meta_background_refresh_all (void)
776610
 {
776610
+  MetaBackgroundImageCache *cache = meta_background_image_cache_get_default ();
776610
   GSList *l;
776610
 
776610
+  meta_background_image_cache_unload_all (cache);
776610
+
776610
   for (l = all_backgrounds; l; l = l->next)
776610
     mark_changed (l->data);
776610
 }
776610
diff --git a/src/meta/meta-background-image.h b/src/meta/meta-background-image.h
776610
index fa67b42cf..5ecfb9753 100644
776610
--- a/src/meta/meta-background-image.h
776610
+++ b/src/meta/meta-background-image.h
776610
@@ -46,31 +46,33 @@ GType meta_background_image_get_type (void);
776610
 gboolean     meta_background_image_is_loaded   (MetaBackgroundImage *image);
776610
 gboolean     meta_background_image_get_success (MetaBackgroundImage *image);
776610
 CoglTexture *meta_background_image_get_texture (MetaBackgroundImage *image);
776610
 
776610
 #define META_TYPE_BACKGROUND_IMAGE_CACHE            (meta_background_image_cache_get_type ())
776610
 #define META_BACKGROUND_IMAGE_CACHE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_BACKGROUND_IMAGE_CACHE, MetaBackgroundImageCache))
776610
 #define META_BACKGROUND_IMAGE_CACHE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  META_TYPE_BACKGROUND_IMAGE_CACHE, MetaBackgroundImageCacheClass))
776610
 #define META_IS_BACKGROUND_IMAGE_CACHE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_BACKGROUND_IMAGE_CACHE))
776610
 #define META_IS_BACKGROUND_IMAGE_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  META_TYPE_BACKGROUND_IMAGE_CACHE))
776610
 #define META_BACKGROUND_IMAGE_CACHE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  META_TYPE_BACKGROUND_IMAGE_CACHE, MetaBackgroundImageCacheClass))
776610
 
776610
 /**
776610
  * MetaBackgroundImageCache:
776610
  *
776610
  * #MetaBackgroundImageCache caches loading of textures for backgrounds; there's actually
776610
  * nothing background specific about it, other than it is tuned to work well for
776610
  * large images as typically are used for backgrounds.
776610
  */
776610
 typedef struct _MetaBackgroundImageCache      MetaBackgroundImageCache;
776610
 typedef struct _MetaBackgroundImageCacheClass MetaBackgroundImageCacheClass;
776610
 
776610
 MetaBackgroundImageCache *meta_background_image_cache_get_default (void);
776610
 
776610
 GType meta_background_image_cache_get_type (void);
776610
 
776610
 MetaBackgroundImage *meta_background_image_cache_load  (MetaBackgroundImageCache *cache,
776610
                                                         GFile                    *file);
776610
 void                 meta_background_image_cache_purge (MetaBackgroundImageCache *cache,
776610
                                                         GFile                    *file);
776610
 
776610
+void                 meta_background_image_cache_unload_all (MetaBackgroundImageCache *cache);
776610
+
776610
 #endif /* __META_BACKGROUND_IMAGE_H__ */
776610
-- 
776610
2.18.1
776610