[metacity] display: always have a valid compositor



commit b245f1a02ddffc8e956165a477ab0d62e3f84c4d
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Jan 8 18:52:19 2017 +0200

    display: always have a valid compositor

 src/compositor/compositor.c |   44 ++++++++++++++++++++++++++++--------------
 src/core/display.c          |   26 ++++++++++++------------
 src/include/compositor.h    |   31 ++++++++++++++++++-----------
 3 files changed, 61 insertions(+), 40 deletions(-)
---
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index a63f30e..bbb9bb1 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -1,31 +1,45 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
 /*
  * Copyright (C) 2008 Iain Holmes
+ * Copyright (C) 2017 Alberts Muktupāvels
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <config.h>
+#include "config.h"
+
+#include "compositor-none.h"
 #include "compositor-private.h"
 #include "compositor-xrender.h"
 
 MetaCompositor *
-meta_compositor_new (MetaDisplay *display)
+meta_compositor_new (MetaCompositorType  type,
+                     MetaDisplay        *display)
 {
-  /* At some point we would have a way to select between backends */
-  return meta_compositor_xrender_new (display);
+  switch (type)
+    {
+      case META_COMPOSITOR_TYPE_NONE:
+        return meta_compositor_none_new (display);
+
+      case META_COMPOSITOR_TYPE_XRENDER:
+        return meta_compositor_xrender_new (display);
+
+      default:
+        g_assert_not_reached ();
+        break;
+    }
+
+  return NULL;
 }
 
 void
diff --git a/src/core/display.c b/src/core/display.c
index dd6bcd7..bc981d9 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -244,14 +244,13 @@ sn_error_trap_pop (SnDisplay *sn_display,
 #endif
 
 static void
-enable_compositor (MetaDisplay *display,
-                   gboolean     composite_windows)
+enable_compositor (MetaCompositorType  type,
+                   MetaDisplay        *display,
+                   gboolean            composite_windows)
 {
-  if (!display->compositor)
-      display->compositor = meta_compositor_new (display);
+  g_assert (display->compositor == NULL);
 
-  if (!display->compositor)
-    return;
+  display->compositor = meta_compositor_new (type, display);
 
   meta_compositor_manage_screen (display->compositor, display->screen);
 
@@ -262,8 +261,7 @@ enable_compositor (MetaDisplay *display,
 static void
 disable_compositor (MetaDisplay *display)
 {
-  if (!display->compositor)
-    return;
+  g_return_if_fail (display->compositor != NULL);
 
   meta_compositor_unmanage_screen (display->compositor, display->screen);
 
@@ -663,7 +661,9 @@ meta_display_open (void)
      faster with the call to meta_screen_manage_all_windows further down
      the code */
   if (meta_prefs_get_compositing_manager ())
-    enable_compositor (the_display, FALSE);
+    enable_compositor (META_COMPOSITOR_TYPE_XRENDER, the_display, FALSE);
+  else
+    enable_compositor (META_COMPOSITOR_TYPE_NONE, the_display, FALSE);
 
   meta_display_grab (the_display);
 
@@ -5062,12 +5062,12 @@ prefs_changed_callback (MetaPreference pref,
     }
   else if (pref == META_PREF_COMPOSITING_MANAGER)
     {
-      gboolean cm = meta_prefs_get_compositing_manager ();
+      disable_compositor (display);
 
-      if (cm)
-        enable_compositor (display, TRUE);
+      if (meta_prefs_get_compositing_manager ())
+        enable_compositor (META_COMPOSITOR_TYPE_XRENDER, display, TRUE);
       else
-        disable_compositor (display);
+        enable_compositor (META_COMPOSITOR_TYPE_NONE, display, TRUE);
     }
   else if (pref == META_PREF_ATTACH_MODAL_DIALOGS)
     {
diff --git a/src/include/compositor.h b/src/include/compositor.h
index ad4411b..1d1938a 100644
--- a/src/include/compositor.h
+++ b/src/include/compositor.h
@@ -1,20 +1,19 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
 /*
  * Copyright (C) 2008 Iain Holmes
+ * Copyright (C) 2017 Alberts Muktupāvels
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifndef META_COMPOSITOR_H
@@ -26,7 +25,15 @@
 #include "types.h"
 #include "boxes.h"
 
-MetaCompositor *meta_compositor_new (MetaDisplay *display);
+typedef enum
+{
+  META_COMPOSITOR_TYPE_NONE,
+  META_COMPOSITOR_TYPE_XRENDER
+} MetaCompositorType;
+
+MetaCompositor  *meta_compositor_new                (MetaCompositorType  type,
+                                                     MetaDisplay        *display);
+
 void meta_compositor_destroy (MetaCompositor *compositor);
 
 void meta_compositor_manage_screen (MetaCompositor *compositor,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]