kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone

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

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