Blame SOURCES/video-memory-purge.patch

d1d875
From bf6c9bea02c9800a53e3db65966ffdc4ab506cb0 Mon Sep 17 00:00:00 2001
d1d875
From: Rui Matos <tiagomatos@gmail.com>
d1d875
Date: Thu, 9 Jun 2016 19:07:15 +0200
d1d875
Subject: [PATCH 1/4] restart: Make meta_restart() work without a message
d1d875
d1d875
In some cases there's no meaningful message to show.
d1d875
d1d875
https://bugzilla.gnome.org/show_bug.cgi?id=739178
d1d875
---
d1d875
 src/core/restart.c | 4 ++--
d1d875
 1 file changed, 2 insertions(+), 2 deletions(-)
d1d875
d1d875
diff --git a/src/core/restart.c b/src/core/restart.c
d1d875
index f01464c..1fa1c88 100644
d1d875
--- a/src/core/restart.c
d1d875
+++ b/src/core/restart.c
d1d875
@@ -103,7 +103,7 @@ restart_message_painted (gpointer data)
d1d875
 
d1d875
 /**
d1d875
  * meta_restart:
d1d875
- * @message: message to display to the user.
d1d875
+ * @message: (allow-none): message to display to the user, or %NULL
d1d875
  *
d1d875
  * Starts the process of restarting the compositor. Note that Mutter's
d1d875
  * involvement here is to make the restart visually smooth for the
d1d875
@@ -126,7 +126,7 @@ meta_restart (const char *message)
d1d875
     MUTTER_LIBEXECDIR "/mutter-restart-helper", NULL
d1d875
   };
d1d875
 
d1d875
-  if (meta_display_show_restart_message (display, message))
d1d875
+  if (message && meta_display_show_restart_message (display, message))
d1d875
     {
d1d875
       /* Wait until the stage was painted */
d1d875
       clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_POST_PAINT,
d1d875
-- 
d1d875
2.7.4
d1d875
d1d875
d1d875
From 384709b7304adedc730b605953cb8393c4708dbc Mon Sep 17 00:00:00 2001
d1d875
From: Rui Matos <tiagomatos@gmail.com>
d1d875
Date: Fri, 20 May 2016 19:22:23 +0200
d1d875
Subject: [PATCH 2/4] compositor: Handle GL context reset errors
d1d875
d1d875
Emit a signal so that interested parties can recreate their FBOs and
d1d875
queue a full scene graph redraw to ensure we don't end up showing
d1d875
graphical artifacts.
d1d875
d1d875
This relies on the GL driver supporting the ARB_robustness extension
d1d875
and cogl creating a suitable GL context. For now we only make use of
d1d875
it with the X backend since the only driver with which this is useful
d1d875
is NVIDIA.
d1d875
d1d875
https://bugzilla.gnome.org/show_bug.cgi?id=739178
d1d875
---
d1d875
 src/backends/x11/meta-backend-x11.c |  2 ++
d1d875
 src/compositor/compositor-private.h |  1 +
d1d875
 src/compositor/compositor.c         | 28 ++++++++++++++++++++++++++--
d1d875
 src/core/display.c                  |  9 +++++++++
d1d875
 4 files changed, 38 insertions(+), 2 deletions(-)
d1d875
d1d875
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
d1d875
index 586f991..4a041ff 100644
d1d875
--- a/src/backends/x11/meta-backend-x11.c
d1d875
+++ b/src/backends/x11/meta-backend-x11.c
d1d875
@@ -696,6 +696,8 @@ meta_backend_x11_class_init (MetaBackendX11Class *klass)
d1d875
 static void
d1d875
 meta_backend_x11_init (MetaBackendX11 *x11)
d1d875
 {
d1d875
+  clutter_x11_request_reset_on_video_memory_purge ();
d1d875
+
d1d875
   /* We do X11 event retrieval ourselves */
d1d875
   clutter_x11_disable_event_retrieval ();
d1d875
 }
d1d875
diff --git a/src/compositor/compositor-private.h b/src/compositor/compositor-private.h
d1d875
index e9b7463..9d99f6f 100644
d1d875
--- a/src/compositor/compositor-private.h
d1d875
+++ b/src/compositor/compositor-private.h
d1d875
@@ -35,6 +35,7 @@ struct _MetaCompositor
d1d875
 
d1d875
   CoglOnscreen          *onscreen;
d1d875
   CoglFrameClosure      *frame_closure;
d1d875
+  CoglContext           *context;
d1d875
 
d1d875
   /* Used for unredirecting fullscreen windows */
d1d875
   guint                  disable_unredirect_count;
d1d875
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
d1d875
index 11b7c2c..75272ef 100644
d1d875
--- a/src/compositor/compositor.c
d1d875
+++ b/src/compositor/compositor.c
d1d875
@@ -1152,8 +1152,7 @@ frame_callback (CoglOnscreen  *onscreen,
d1d875
            * is fairly fast, so calling it twice and subtracting to get a
d1d875
            * nearly-zero number is acceptable, if a litle ugly.
d1d875
            */
d1d875
-          CoglContext *context = cogl_framebuffer_get_context (COGL_FRAMEBUFFER (onscreen));
d1d875
-          gint64 current_cogl_time = cogl_get_clock_time (context);
d1d875
+          gint64 current_cogl_time = cogl_get_clock_time (compositor->context);
d1d875
           gint64 current_monotonic_time = g_get_monotonic_time ();
d1d875
 
d1d875
           presentation_time =
d1d875
@@ -1183,6 +1182,7 @@ meta_pre_paint_func (gpointer data)
d1d875
                                                                     frame_callback,
d1d875
                                                                     compositor,
d1d875
                                                                     NULL);
d1d875
+      compositor->context = cogl_framebuffer_get_context (COGL_FRAMEBUFFER (compositor->onscreen));
d1d875
     }
d1d875
 
d1d875
   if (compositor->windows == NULL)
d1d875
@@ -1236,6 +1236,7 @@ static gboolean
d1d875
 meta_post_paint_func (gpointer data)
d1d875
 {
d1d875
   MetaCompositor *compositor = data;
d1d875
+  CoglGraphicsResetStatus status;
d1d875
 
d1d875
   if (compositor->frame_has_updated_xsurfaces)
d1d875
     {
d1d875
@@ -1245,6 +1246,29 @@ meta_post_paint_func (gpointer data)
d1d875
       compositor->frame_has_updated_xsurfaces = FALSE;
d1d875
     }
d1d875
 
d1d875
+  status = cogl_get_graphics_reset_status (compositor->context);
d1d875
+  switch (status)
d1d875
+    {
d1d875
+    case COGL_GRAPHICS_RESET_STATUS_NO_ERROR:
d1d875
+      break;
d1d875
+
d1d875
+    case COGL_GRAPHICS_RESET_STATUS_PURGED_CONTEXT_RESET:
d1d875
+      g_signal_emit_by_name (compositor->display, "gl-video-memory-purged");
d1d875
+      clutter_actor_queue_redraw (CLUTTER_ACTOR (compositor->stage));
d1d875
+      break;
d1d875
+
d1d875
+    default:
d1d875
+      /* The ARB_robustness spec says that, on error, the application
d1d875
+         should destroy the old context and create a new one. Since we
d1d875
+         don't have the necessary plumbing to do this we'll simply
d1d875
+         restart the process. Obviously we can't do this when we are
d1d875
+         a wayland compositor but in that case we shouldn't get here
d1d875
+         since we don't enable robustness in that case. */
d1d875
+      g_assert (!meta_is_wayland_compositor ());
d1d875
+      meta_restart (NULL);
d1d875
+      break;
d1d875
+    }
d1d875
+
d1d875
   return TRUE;
d1d875
 }
d1d875
 
d1d875
diff --git a/src/core/display.c b/src/core/display.c
d1d875
index 29242fa..8b9dd04 100644
d1d875
--- a/src/core/display.c
d1d875
+++ b/src/core/display.c
d1d875
@@ -122,6 +122,7 @@ enum
d1d875
   GRAB_OP_END,
d1d875
   SHOW_RESTART_MESSAGE,
d1d875
   RESTART,
d1d875
+  GL_VIDEO_MEMORY_PURGED,
d1d875
   LAST_SIGNAL
d1d875
 };
d1d875
 
d1d875
@@ -329,6 +330,14 @@ meta_display_class_init (MetaDisplayClass *klass)
d1d875
                   NULL, NULL,
d1d875
                   G_TYPE_BOOLEAN, 0);
d1d875
 
d1d875
+  display_signals[GL_VIDEO_MEMORY_PURGED] =
d1d875
+    g_signal_new ("gl-video-memory-purged",
d1d875
+                  G_TYPE_FROM_CLASS (klass),
d1d875
+                  G_SIGNAL_RUN_LAST,
d1d875
+                  0,
d1d875
+                  NULL, NULL, NULL,
d1d875
+                  G_TYPE_NONE, 0);
d1d875
+
d1d875
   g_object_class_install_property (object_class,
d1d875
                                    PROP_FOCUS_WINDOW,
d1d875
                                    g_param_spec_object ("focus-window",
d1d875
-- 
d1d875
2.7.4
d1d875
d1d875
d1d875
From 2cbaf5d5a5ee256b2623b6d52d4fa9e891a1abd0 Mon Sep 17 00:00:00 2001
d1d875
From: Rui Matos <tiagomatos@gmail.com>
d1d875
Date: Sun, 29 May 2016 19:58:25 +0200
d1d875
Subject: [PATCH 3/4] MetaBackground: invalidate contents on loss of graphics
d1d875
 context
d1d875
d1d875
We use FBOs so we need to cause them to be recreated if we get a GL
d1d875
context lost error.
d1d875
d1d875
https://bugzilla.gnome.org/show_bug.cgi?id=739178
d1d875
---
d1d875
 src/compositor/meta-background.c | 13 +++++++++++++
d1d875
 1 file changed, 13 insertions(+)
d1d875
d1d875
diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c
d1d875
index de0407b..8195814 100644
d1d875
--- a/src/compositor/meta-background.c
d1d875
+++ b/src/compositor/meta-background.c
d1d875
@@ -300,6 +300,18 @@ meta_background_finalize (GObject *object)
d1d875
 }
d1d875
 
d1d875
 static void
d1d875
+meta_background_constructed (GObject *object)
d1d875
+{
d1d875
+  MetaBackground        *self = META_BACKGROUND (object);
d1d875
+  MetaBackgroundPrivate *priv = self->priv;
d1d875
+
d1d875
+  G_OBJECT_CLASS (meta_background_parent_class)->constructed (object);
d1d875
+
d1d875
+  g_signal_connect_object (meta_screen_get_display (priv->screen), "gl-video-memory-purged",
d1d875
+                           G_CALLBACK (mark_changed), object, G_CONNECT_SWAPPED);
d1d875
+}
d1d875
+
d1d875
+static void
d1d875
 meta_background_class_init (MetaBackgroundClass *klass)
d1d875
 {
d1d875
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
d1d875
@@ -309,6 +321,7 @@ meta_background_class_init (MetaBackgroundClass *klass)
d1d875
 
d1d875
   object_class->dispose = meta_background_dispose;
d1d875
   object_class->finalize = meta_background_finalize;
d1d875
+  object_class->constructed = meta_background_constructed;
d1d875
   object_class->set_property = meta_background_set_property;
d1d875
   object_class->get_property = meta_background_get_property;
d1d875
 
d1d875
-- 
d1d875
2.7.4
d1d875
d1d875
d1d875
From bf0837c9b0b2f25344d92c4f7bbcd83e089c2f38 Mon Sep 17 00:00:00 2001
d1d875
From: Rui Matos <tiagomatos@gmail.com>
d1d875
Date: Sun, 29 May 2016 20:00:45 +0200
d1d875
Subject: [PATCH 4/4] MetaSurfaceActorX11: invalidate the stex on loss of
d1d875
 graphics context
d1d875
d1d875
MetaShapedTexture uses FBOs when mipmapping so we need to cause them
d1d875
to be recreated if we get a GL context lost error.
d1d875
d1d875
https://bugzilla.gnome.org/show_bug.cgi?id=739178
d1d875
---
d1d875
 src/compositor/meta-surface-actor-x11.c | 23 ++++++++++++++++++++++-
d1d875
 1 file changed, 22 insertions(+), 1 deletion(-)
d1d875
d1d875
diff --git a/src/compositor/meta-surface-actor-x11.c b/src/compositor/meta-surface-actor-x11.c
d1d875
index c837b5e..f10ec86 100644
d1d875
--- a/src/compositor/meta-surface-actor-x11.c
d1d875
+++ b/src/compositor/meta-surface-actor-x11.c
d1d875
@@ -44,6 +44,7 @@ struct _MetaSurfaceActorX11Private
d1d875
   MetaDisplay *display;
d1d875
 
d1d875
   CoglTexture *texture;
d1d875
+  CoglTexture *texture_right;
d1d875
   Pixmap pixmap;
d1d875
   Damage damage;
d1d875
 
d1d875
@@ -106,6 +107,7 @@ detach_pixmap (MetaSurfaceActorX11 *self)
d1d875
   meta_error_trap_pop (display);
d1d875
 
d1d875
   g_clear_pointer (&priv->texture, cogl_object_unref);
d1d875
+  g_clear_pointer (&priv->texture_right, cogl_object_unref);
d1d875
 }
d1d875
 
d1d875
 static void
d1d875
@@ -145,7 +147,7 @@ set_pixmap (MetaSurfaceActorX11 *self,
d1d875
   meta_shaped_texture_set_textures (stex, COGL_TEXTURE (texture), COGL_TEXTURE (texture_right));
d1d875
 
d1d875
   if (priv->stereo)
d1d875
-    cogl_object_unref (texture_right);
d1d875
+    priv->texture_right = COGL_TEXTURE (texture_right);
d1d875
 }
d1d875
 
d1d875
 static void
d1d875
@@ -408,6 +410,22 @@ window_decorated_notify (MetaWindow *window,
d1d875
   create_damage (self);
d1d875
 }
d1d875
 
d1d875
+static void
d1d875
+reset_texture (MetaSurfaceActorX11 *self)
d1d875
+{
d1d875
+  MetaSurfaceActorX11Private *priv = meta_surface_actor_x11_get_instance_private (self);
d1d875
+  MetaShapedTexture *stex = meta_surface_actor_get_texture (META_SURFACE_ACTOR (self));
d1d875
+
d1d875
+  if (!priv->texture)
d1d875
+    return;
d1d875
+
d1d875
+  /* Setting the texture to NULL will cause all the FBO's cached by the
d1d875
+   * shaped texture's MetaTextureTower to be discarded and recreated.
d1d875
+   */
d1d875
+  meta_shaped_texture_set_textures (stex, NULL, NULL);
d1d875
+  meta_shaped_texture_set_textures (stex, priv->texture, priv->texture_right);
d1d875
+}
d1d875
+
d1d875
 MetaSurfaceActor *
d1d875
 meta_surface_actor_x11_new (MetaWindow *window)
d1d875
 {
d1d875
@@ -421,6 +439,9 @@ meta_surface_actor_x11_new (MetaWindow *window)
d1d875
   priv->window = window;
d1d875
   priv->display = display;
d1d875
 
d1d875
+  g_signal_connect_object (priv->display, "gl-video-memory-purged",
d1d875
+                           G_CALLBACK (reset_texture), self, G_CONNECT_SWAPPED);
d1d875
+
d1d875
   xwindow = meta_window_x11_get_toplevel_xwindow (window);
d1d875
   priv->stereo = meta_compositor_window_is_stereo (display->screen, xwindow);
d1d875
   meta_compositor_select_stereo_notify (display->screen, xwindow);
d1d875
-- 
d1d875
2.7.4
d1d875