Blob Blame History Raw
From a01f454edf05c1204ea4be23fd79576fa7c5b5ff Mon Sep 17 00:00:00 2001
From: Rui Matos <tiagomatos@gmail.com>
Date: Tue, 21 Jun 2016 17:40:15 +0200
Subject: [PATCH] clutter/x11: Add API to request video memory purges to be
 reported

---
 clutter/x11/clutter-backend-x11.c | 28 +++++++++++++++++++++++++++-
 clutter/x11/clutter-x11.h         |  3 +++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/clutter/x11/clutter-backend-x11.c b/clutter/x11/clutter-backend-x11.c
index 14eda35..eb0d643 100644
--- a/clutter/x11/clutter-backend-x11.c
+++ b/clutter/x11/clutter-backend-x11.c
@@ -90,6 +90,7 @@ static const gchar *atom_names[] = {
 #define N_ATOM_NAMES G_N_ELEMENTS (atom_names)
 
 /* various flags corresponding to pre init setup calls */
+static gboolean _want_reset_on_video_memory_purge = FALSE;
 static gboolean _no_xevent_retrieval = FALSE;
 static gboolean clutter_enable_xinput = TRUE;
 static gboolean clutter_enable_argb = FALSE;
@@ -685,7 +686,8 @@ clutter_backend_x11_get_renderer (ClutterBackend  *backend,
 
   /* set the display object we're using */
   cogl_xlib_renderer_set_foreign_display (renderer, xdisplay);
-
+  cogl_xlib_renderer_request_reset_on_video_memory_purge (renderer,
+                                                          _want_reset_on_video_memory_purge);
   return renderer;
 }
 
@@ -1028,6 +1030,30 @@ clutter_x11_has_event_retrieval (void)
 }
 
 /**
+ * clutter_x11_request_reset_on_video_memory_purge:
+ *
+ * If the GL driver supports the NV_robustness_video_memory_purge
+ * extension, this call lets applications request that it gets
+ * initialized, thus allowing cogl_get_graphics_reset_status() to
+ * report memory purged errors if they happen. Checking for the
+ * graphics reset status is the application's responsibility.
+ *
+ * This function can only be called before calling clutter_init().
+ */
+void
+clutter_x11_request_reset_on_video_memory_purge (void)
+{
+  if (_clutter_context_is_initialized ())
+    {
+      g_warning ("%s() can only be used before calling clutter_init()",
+                 G_STRFUNC);
+      return;
+    }
+
+  _want_reset_on_video_memory_purge = TRUE;
+}
+
+/**
  * clutter_x11_get_default_screen:
  *
  * Gets the number of the default X Screen object.
diff --git a/clutter/x11/clutter-x11.h b/clutter/x11/clutter-x11.h
index 4fb2b35..817cd85 100644
--- a/clutter/x11/clutter-x11.h
+++ b/clutter/x11/clutter-x11.h
@@ -168,6 +168,9 @@ gint clutter_x11_event_get_key_group (const ClutterEvent *event);
 CLUTTER_AVAILABLE_IN_ALL
 guint clutter_x11_event_sequence_get_touch_detail (const ClutterEventSequence *sequence);
 
+CLUTTER_AVAILABLE_IN_ALL
+void clutter_x11_request_reset_on_video_memory_purge (void);
+
 G_END_DECLS
 
 #endif /* __CLUTTER_X11_H__ */
-- 
2.7.4