Blame SOURCES/0001-background-Reload-when-GPU-memory-is-invalidated.patch

e82d74
From 5a486f5b6bf5f838db5dc2bfc5819a0cba5d2d19 Mon Sep 17 00:00:00 2001
e82d74
From: Daniel van Vugt <daniel.van.vugt@canonical.com>
e82d74
Date: Thu, 23 May 2019 18:15:28 +0800
e82d74
Subject: [PATCH] background: Reload when GPU memory is invalidated
e82d74
e82d74
Fixes corrupt background wallpaper when resuming from suspend on the
e82d74
Nvidia driver.
e82d74
e82d74
https://gitlab.gnome.org/GNOME/gnome-shell/issues/1084
e82d74
e82d74
(cherry picked from commit a5265365dd268e15a461a58000a10b122d0bccba)
e82d74
e82d74
https://gitlab.gnome.org/GNOME/mutter/merge_requests/777
e82d74
---
e82d74
 src/compositor/meta-background.c | 46 +++++++++++++++++++++++++-------
e82d74
 1 file changed, 36 insertions(+), 10 deletions(-)
e82d74
e82d74
diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c
e82d74
index c033395fe..387ce5dd3 100644
e82d74
--- a/src/compositor/meta-background.c
e82d74
+++ b/src/compositor/meta-background.c
e82d74
@@ -252,12 +252,11 @@ static void
e82d74
 set_file (MetaBackground       *self,
e82d74
           GFile               **filep,
e82d74
           MetaBackgroundImage **imagep,
e82d74
-          GFile                *file)
e82d74
+          GFile                *file,
e82d74
+          gboolean              force_reload)
e82d74
 {
e82d74
-  if (!file_equal0 (*filep, file))
e82d74
+  if (force_reload || !file_equal0 (*filep, file))
e82d74
     {
e82d74
-      g_clear_object (filep);
e82d74
-
e82d74
       if (*imagep)
e82d74
         {
e82d74
           g_signal_handlers_disconnect_by_func (*imagep,
e82d74
@@ -267,11 +266,12 @@ set_file (MetaBackground       *self,
e82d74
           *imagep = NULL;
e82d74
         }
e82d74
 
e82d74
+      g_set_object (filep, file);
e82d74
+
e82d74
       if (file)
e82d74
         {
e82d74
           MetaBackgroundImageCache *cache = meta_background_image_cache_get_default ();
e82d74
 
e82d74
-          *filep = g_object_ref (file);
e82d74
           *imagep = meta_background_image_cache_load (cache, file);
e82d74
           g_signal_connect (*imagep, "loaded",
e82d74
                             G_CALLBACK (on_background_loaded), self);
e82d74
@@ -279,6 +279,32 @@ set_file (MetaBackground       *self,
e82d74
     }
e82d74
 }
e82d74
 
e82d74
+static void
e82d74
+on_gl_video_memory_purged (MetaBackground *self)
e82d74
+{
e82d74
+  MetaBackgroundImageCache *cache = meta_background_image_cache_get_default ();
e82d74
+
e82d74
+  /* The GPU memory that just got invalidated is the texture inside
e82d74
+   * self->background_image1,2 and/or its mipmaps. However, to save memory the
e82d74
+   * original pixbuf isn't kept in RAM so we can't do a simple re-upload. The
e82d74
+   * only copy of the image was the one in texture memory that got invalidated.
e82d74
+   * So we need to do a full reload from disk.
e82d74
+   */
e82d74
+  if (self->file1)
e82d74
+    {
e82d74
+      meta_background_image_cache_purge (cache, self->file1);
e82d74
+      set_file (self, &self->file1, &self->background_image1, self->file1, TRUE);
e82d74
+    }
e82d74
+
e82d74
+  if (self->file2)
e82d74
+    {
e82d74
+      meta_background_image_cache_purge (cache, self->file2);
e82d74
+      set_file (self, &self->file2, &self->background_image2, self->file2, TRUE);
e82d74
+    }
e82d74
+
e82d74
+  mark_changed (self);
e82d74
+}
e82d74
+
e82d74
 static void
e82d74
 meta_background_dispose (GObject *object)
e82d74
 {
e82d74
@@ -287,8 +313,8 @@ meta_background_dispose (GObject *object)
e82d74
   free_color_texture (self);
e82d74
   free_wallpaper_texture (self);
e82d74
 
e82d74
-  set_file (self, &self->file1, &self->background_image1, NULL);
e82d74
-  set_file (self, &self->file2, &self->background_image2, NULL);
e82d74
+  set_file (self, &self->file1, &self->background_image1, NULL, FALSE);
e82d74
+  set_file (self, &self->file2, &self->background_image2, NULL, FALSE);
e82d74
 
e82d74
   set_display (self, NULL);
e82d74
 
e82d74
@@ -312,7 +338,7 @@ meta_background_constructed (GObject *object)
e82d74
   G_OBJECT_CLASS (meta_background_parent_class)->constructed (object);
e82d74
 
e82d74
   g_signal_connect_object (self->display, "gl-video-memory-purged",
e82d74
-                           G_CALLBACK (mark_changed), object, G_CONNECT_SWAPPED);
e82d74
+                           G_CALLBACK (on_gl_video_memory_purged), object, G_CONNECT_SWAPPED);
e82d74
 
e82d74
   g_signal_connect_object (monitor_manager, "monitors-changed",
e82d74
                            G_CALLBACK (on_monitors_changed), self,
e82d74
@@ -937,8 +963,8 @@ meta_background_set_blend (MetaBackground          *self,
e82d74
   g_return_if_fail (META_IS_BACKGROUND (self));
e82d74
   g_return_if_fail (blend_factor >= 0.0 && blend_factor <= 1.0);
e82d74
 
e82d74
-  set_file (self, &self->file1, &self->background_image1, file1);
e82d74
-  set_file (self, &self->file2, &self->background_image2, file2);
e82d74
+  set_file (self, &self->file1, &self->background_image1, file1, FALSE);
e82d74
+  set_file (self, &self->file2, &self->background_image2, file2, FALSE);
e82d74
 
e82d74
   self->blend_factor = blend_factor;
e82d74
   self->style = style;
e82d74
-- 
e82d74
2.26.2
e82d74