Blame SOURCES/0004-background-refresh-background-on-gl-video-memory-pur.patch

c7fac9
From b440c4c529aee18ecc36a7b8a24809bc684cfe5b Mon Sep 17 00:00:00 2001
c7fac9
From: Ray Strode <rstrode@redhat.com>
c7fac9
Date: Mon, 21 Jan 2019 15:07:15 -0500
c7fac9
Subject: [PATCH 4/4] background: refresh background on gl-video-memory-purged
c7fac9
 signal
c7fac9
c7fac9
Right now we refresh the background when resuming and when NVIDIA.
c7fac9
But mutter has a signal to tell us specifically when to refresh,
c7fac9
and the signal is only emitted for NVIDIA, so use that instead.
c7fac9
---
c7fac9
 js/ui/background.js |  9 +++++++--
c7fac9
 js/ui/layout.js     | 12 ------------
c7fac9
 src/shell-util.c    |  9 ---------
c7fac9
 3 files changed, 7 insertions(+), 23 deletions(-)
c7fac9
c7fac9
diff --git a/js/ui/background.js b/js/ui/background.js
c7fac9
index c61d946a4..ae7ef275e 100644
c7fac9
--- a/js/ui/background.js
c7fac9
+++ b/js/ui/background.js
c7fac9
@@ -512,64 +512,69 @@ var SystemBackground = new Lang.Class({
c7fac9
         let image = cache.load(file);
c7fac9
         if (image.is_loaded()) {
c7fac9
             image = null;
c7fac9
             let id = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
c7fac9
                 this.emit('loaded');
c7fac9
                 return GLib.SOURCE_REMOVE;
c7fac9
             });
c7fac9
             GLib.Source.set_name_by_id(id, '[gnome-shell] SystemBackground.loaded');
c7fac9
         } else {
c7fac9
             let id = image.connect('loaded', () => {
c7fac9
                 this.emit('loaded');
c7fac9
                 image.disconnect(id);
c7fac9
                 image = null;
c7fac9
             });
c7fac9
         }
c7fac9
     },
c7fac9
 });
c7fac9
 Signals.addSignalMethods(SystemBackground.prototype);
c7fac9
 
c7fac9
 var BackgroundSource = new Lang.Class({
c7fac9
     Name: 'BackgroundSource',
c7fac9
 
c7fac9
     _init(layoutManager, settingsSchema) {
c7fac9
         // Allow override the background image setting for performance testing
c7fac9
         this._layoutManager = layoutManager;
c7fac9
         this._overrideImage = GLib.getenv('SHELL_BACKGROUND_IMAGE');
c7fac9
         this._settings = new Gio.Settings({ schema_id: settingsSchema });
c7fac9
         this._backgrounds = [];
c7fac9
 
c7fac9
         this._monitorsChangedId = global.screen.connect('monitors-changed',
c7fac9
-                                                        this._onMonitorsChanged.bind(this));
c7fac9
+                                                        this._refresh.bind(this));
c7fac9
+
c7fac9
+        global.display.connect('gl-video-memory-purged', () => {
c7fac9
+                                   Meta.Background.refresh_all();
c7fac9
+                                   this._refresh();
c7fac9
+                               });
c7fac9
     },
c7fac9
 
c7fac9
-    _onMonitorsChanged() {
c7fac9
+    _refresh() {
c7fac9
         for (let monitorIndex in this._backgrounds) {
c7fac9
             let background = this._backgrounds[monitorIndex];
c7fac9
 
c7fac9
             if (monitorIndex < this._layoutManager.monitors.length) {
c7fac9
                 background.updateResolution();
c7fac9
             } else {
c7fac9
                 background.disconnect(background._changedId);
c7fac9
                 background.destroy();
c7fac9
                 delete this._backgrounds[monitorIndex];
c7fac9
             }
c7fac9
         }
c7fac9
     },
c7fac9
 
c7fac9
     getBackground(monitorIndex) {
c7fac9
         let file = null;
c7fac9
         let style;
c7fac9
 
c7fac9
         // We don't watch changes to settings here,
c7fac9
         // instead we rely on Background to watch those
c7fac9
         // and emit 'changed' at the right time
c7fac9
 
c7fac9
         if (this._overrideImage != null) {
c7fac9
             file = Gio.File.new_for_path(this._overrideImage);
c7fac9
             style = GDesktopEnums.BackgroundStyle.ZOOM; // Hardcode
c7fac9
         } else {
c7fac9
             style = this._settings.get_enum(BACKGROUND_STYLE_KEY);
c7fac9
             if (style != GDesktopEnums.BackgroundStyle.NONE) {
c7fac9
                 let uri = this._settings.get_string(PICTURE_URI_KEY);
c7fac9
                 file = Gio.File.new_for_commandline_arg(uri);
c7fac9
             }
c7fac9
diff --git a/js/ui/layout.js b/js/ui/layout.js
c7fac9
index 6f810395d..2cd1e5bd3 100644
c7fac9
--- a/js/ui/layout.js
c7fac9
+++ b/js/ui/layout.js
c7fac9
@@ -251,72 +251,60 @@ var LayoutManager = new Lang.Class({
c7fac9
         this.addChrome(this.keyboardBox);
c7fac9
         this._keyboardHeightNotifyId = 0;
c7fac9
 
c7fac9
         // A dummy actor that tracks the mouse or text cursor, based on the
c7fac9
         // position and size set in setDummyCursorGeometry.
c7fac9
         this.dummyCursor = new St.Widget({ width: 0, height: 0, visible: false });
c7fac9
         this.uiGroup.add_actor(this.dummyCursor);
c7fac9
 
c7fac9
         global.stage.remove_actor(global.top_window_group);
c7fac9
         this.uiGroup.add_actor(global.top_window_group);
c7fac9
 
c7fac9
         let feedbackGroup = Meta.get_feedback_group_for_screen(global.screen);
c7fac9
         global.stage.remove_actor(feedbackGroup);
c7fac9
         this.uiGroup.add_actor(feedbackGroup);
c7fac9
 
c7fac9
         this._backgroundGroup = new Meta.BackgroundGroup();
c7fac9
         global.window_group.add_child(this._backgroundGroup);
c7fac9
         this._backgroundGroup.lower_bottom();
c7fac9
         this._bgManagers = [];
c7fac9
 
c7fac9
         // Need to update struts on new workspaces when they are added
c7fac9
         global.screen.connect('notify::n-workspaces',
c7fac9
                               this._queueUpdateRegions.bind(this));
c7fac9
         global.screen.connect('restacked',
c7fac9
                               this._windowsRestacked.bind(this));
c7fac9
         global.screen.connect('monitors-changed',
c7fac9
                               this._monitorsChanged.bind(this));
c7fac9
         global.screen.connect('in-fullscreen-changed',
c7fac9
                               this._updateFullscreen.bind(this));
c7fac9
         this._monitorsChanged();
c7fac9
-
c7fac9
-        // NVIDIA drivers don't preserve FBO contents across
c7fac9
-        // suspend/resume, see
c7fac9
-        // https://bugzilla.gnome.org/show_bug.cgi?id=739178
c7fac9
-        if (Shell.util_need_background_refresh()) {
c7fac9
-            LoginManager.getLoginManager().connect('prepare-for-sleep',
c7fac9
-                (lm, suspending) => {
c7fac9
-                    if (suspending)
c7fac9
-                        return;
c7fac9
-                    Meta.Background.refresh_all();
c7fac9
-                });
c7fac9
-        }
c7fac9
     },
c7fac9
 
c7fac9
     // This is called by Main after everything else is constructed
c7fac9
     init() {
c7fac9
         Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
c7fac9
 
c7fac9
         this._loadBackground();
c7fac9
     },
c7fac9
 
c7fac9
     showOverview() {
c7fac9
         this.overviewGroup.show();
c7fac9
 
c7fac9
         this._inOverview = true;
c7fac9
         this._updateVisibility();
c7fac9
     },
c7fac9
 
c7fac9
     hideOverview() {
c7fac9
         this.overviewGroup.hide();
c7fac9
 
c7fac9
         this._inOverview = false;
c7fac9
         this._updateVisibility();
c7fac9
     },
c7fac9
 
c7fac9
     _sessionUpdated() {
c7fac9
         this._updateVisibility();
c7fac9
         this._queueUpdateRegions();
c7fac9
     },
c7fac9
 
c7fac9
     _updateMonitors() {
c7fac9
         let screen = global.screen;
c7fac9
diff --git a/src/shell-util.c b/src/shell-util.c
c7fac9
index c43bf4cc5..c63c6efb7 100644
c7fac9
--- a/src/shell-util.c
c7fac9
+++ b/src/shell-util.c
c7fac9
@@ -369,69 +369,60 @@ shell_util_cursor_tracker_to_clutter (MetaCursorTracker *tracker,
c7fac9
   sprite = meta_cursor_tracker_get_sprite (tracker);
c7fac9
   if (sprite)
c7fac9
     {
c7fac9
       clutter_actor_show (CLUTTER_ACTOR (texture));
c7fac9
       clutter_texture_set_cogl_texture (texture, sprite);
c7fac9
     }
c7fac9
   else
c7fac9
     {
c7fac9
       clutter_actor_hide (CLUTTER_ACTOR (texture));
c7fac9
     }
c7fac9
 }
c7fac9
 
c7fac9
 typedef const gchar *(*ShellGLGetString) (GLenum);
c7fac9
 
c7fac9
 static const gchar *
c7fac9
 get_gl_vendor (void)
c7fac9
 {
c7fac9
   static const gchar *vendor = NULL;
c7fac9
 
c7fac9
   if (!vendor)
c7fac9
     {
c7fac9
       ShellGLGetString gl_get_string;
c7fac9
       gl_get_string = (ShellGLGetString) cogl_get_proc_address ("glGetString");
c7fac9
       if (gl_get_string)
c7fac9
         vendor = gl_get_string (GL_VENDOR);
c7fac9
     }
c7fac9
 
c7fac9
   return vendor;
c7fac9
 }
c7fac9
 
c7fac9
-gboolean
c7fac9
-shell_util_need_background_refresh (void)
c7fac9
-{
c7fac9
-  if (g_strcmp0 (get_gl_vendor (), "NVIDIA Corporation") == 0)
c7fac9
-    return TRUE;
c7fac9
-
c7fac9
-  return FALSE;
c7fac9
-}
c7fac9
-
c7fac9
 static gboolean
c7fac9
 canvas_draw_cb (ClutterContent *content,
c7fac9
                 cairo_t        *cr,
c7fac9
                 gint            width,
c7fac9
                 gint            height,
c7fac9
                 gpointer        user_data)
c7fac9
 {
c7fac9
   cairo_surface_t *surface = user_data;
c7fac9
 
c7fac9
   cairo_set_source_surface (cr, surface, 0, 0);
c7fac9
   cairo_paint (cr);
c7fac9
 
c7fac9
   return FALSE;
c7fac9
 }
c7fac9
 
c7fac9
 /**
c7fac9
  * shell_util_get_content_for_window_actor:
c7fac9
  * @window_actor: a #MetaWindowActor
c7fac9
  * @window_rect: a #MetaRectangle
c7fac9
  *
c7fac9
  * Returns: (transfer full): a new #ClutterContent
c7fac9
  */
c7fac9
 ClutterContent *
c7fac9
 shell_util_get_content_for_window_actor (MetaWindowActor *window_actor,
c7fac9
                                          MetaRectangle   *window_rect)
c7fac9
 {
c7fac9
   ClutterActor *texture;
c7fac9
   ClutterContent *content;
c7fac9
   cairo_surface_t *surface;
c7fac9
   cairo_rectangle_int_t clip;
c7fac9
-- 
c7fac9
2.18.1
c7fac9