[mutter/wip/rstrode/rhel-8.0.0: 80/117] cursor-renderer: Add API to allow inhibiting HW cursor



commit 46dccd898eec92dad67cadc2152969866e2b1a1f
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Thu Sep 13 11:28:51 2018 +0200

    cursor-renderer: Add API to allow inhibiting HW cursor
    
    There may be reasons to temporarly inhibit the HW cursor under certain
    circumstances. Allow adding such inhibitations by adding API to the
    cursor renderer to allow API users to add generic inhibitors with
    whatever logic is deemed necessary.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/357

 src/backends/meta-cursor-renderer.c               | 62 +++++++++++++++++++++++
 src/backends/meta-cursor-renderer.h               | 21 ++++++++
 src/backends/native/meta-cursor-renderer-native.c |  4 ++
 3 files changed, 87 insertions(+)
---
diff --git a/src/backends/meta-cursor-renderer.c b/src/backends/meta-cursor-renderer.c
index eb79737f1..0a456bee6 100644
--- a/src/backends/meta-cursor-renderer.c
+++ b/src/backends/meta-cursor-renderer.c
@@ -35,6 +35,9 @@
 
 #include "meta-stage-private.h"
 
+G_DEFINE_INTERFACE (MetaHwCursorInhibitor, meta_hw_cursor_inhibitor,
+                    G_TYPE_OBJECT)
+
 struct _MetaCursorRendererPrivate
 {
   float current_x;
@@ -44,6 +47,8 @@ struct _MetaCursorRendererPrivate
   MetaOverlay *stage_overlay;
   gboolean handled_by_backend;
   guint post_paint_func_id;
+
+  GList *hw_cursor_inhibitors;
 };
 typedef struct _MetaCursorRendererPrivate MetaCursorRendererPrivate;
 
@@ -55,6 +60,21 @@ static guint signals[LAST_SIGNAL];
 
 G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRenderer, meta_cursor_renderer, G_TYPE_OBJECT);
 
+static gboolean
+meta_hw_cursor_inhibitor_is_cursor_sprite_inhibited (MetaHwCursorInhibitor *inhibitor,
+                                                     MetaCursorSprite      *cursor_sprite)
+{
+  MetaHwCursorInhibitorInterface *iface =
+    META_HW_CURSOR_INHIBITOR_GET_IFACE (inhibitor);
+
+  return iface->is_cursor_sprite_inhibited (inhibitor, cursor_sprite);
+}
+
+static void
+meta_hw_cursor_inhibitor_default_init (MetaHwCursorInhibitorInterface *iface)
+{
+}
+
 void
 meta_cursor_renderer_emit_painted (MetaCursorRenderer *renderer,
                                    MetaCursorSprite   *cursor_sprite)
@@ -283,3 +303,45 @@ meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer)
 
   return priv->displayed_cursor;
 }
+
+void
+meta_cursor_renderer_add_hw_cursor_inhibitor (MetaCursorRenderer    *renderer,
+                                              MetaHwCursorInhibitor *inhibitor)
+{
+  MetaCursorRendererPrivate *priv =
+    meta_cursor_renderer_get_instance_private (renderer);
+
+  priv->hw_cursor_inhibitors = g_list_prepend (priv->hw_cursor_inhibitors,
+                                               inhibitor);
+}
+
+void
+meta_cursor_renderer_remove_hw_cursor_inhibitor (MetaCursorRenderer    *renderer,
+                                                 MetaHwCursorInhibitor *inhibitor)
+{
+  MetaCursorRendererPrivate *priv =
+    meta_cursor_renderer_get_instance_private (renderer);
+
+  priv->hw_cursor_inhibitors = g_list_remove (priv->hw_cursor_inhibitors,
+                                              inhibitor);
+}
+
+gboolean
+meta_cursor_renderer_is_hw_cursors_inhibited (MetaCursorRenderer *renderer,
+                                              MetaCursorSprite   *cursor_sprite)
+{
+  MetaCursorRendererPrivate *priv =
+    meta_cursor_renderer_get_instance_private (renderer);
+  GList *l;
+
+  for (l = priv->hw_cursor_inhibitors; l; l = l->next)
+    {
+      MetaHwCursorInhibitor *inhibitor = l->data;
+
+      if (meta_hw_cursor_inhibitor_is_cursor_sprite_inhibited (inhibitor,
+                                                               cursor_sprite))
+        return TRUE;
+    }
+
+  return FALSE;
+}
diff --git a/src/backends/meta-cursor-renderer.h b/src/backends/meta-cursor-renderer.h
index 830d16ef6..092f17f1e 100644
--- a/src/backends/meta-cursor-renderer.h
+++ b/src/backends/meta-cursor-renderer.h
@@ -30,6 +30,18 @@
 #include <meta/screen.h>
 #include "meta-cursor.h"
 
+#define META_TYPE_HW_CURSOR_INHIBITOR (meta_hw_cursor_inhibitor_get_type ())
+G_DECLARE_INTERFACE (MetaHwCursorInhibitor, meta_hw_cursor_inhibitor,
+                     META, HW_CURSOR_INHIBITOR, GObject)
+
+struct _MetaHwCursorInhibitorInterface
+{
+  GTypeInterface parent_iface;
+
+  gboolean (* is_cursor_sprite_inhibited) (MetaHwCursorInhibitor *inhibitor,
+                                           MetaCursorSprite      *cursor_sprite);
+};
+
 #define META_TYPE_CURSOR_RENDERER (meta_cursor_renderer_get_type ())
 G_DECLARE_DERIVABLE_TYPE (MetaCursorRenderer, meta_cursor_renderer,
                           META, CURSOR_RENDERER, GObject);
@@ -55,6 +67,15 @@ void meta_cursor_renderer_force_update (MetaCursorRenderer *renderer);
 
 MetaCursorSprite * meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer);
 
+void meta_cursor_renderer_add_hw_cursor_inhibitor (MetaCursorRenderer    *renderer,
+                                                   MetaHwCursorInhibitor *inhibitor);
+
+void meta_cursor_renderer_remove_hw_cursor_inhibitor (MetaCursorRenderer    *renderer,
+                                                      MetaHwCursorInhibitor *inhibitor);
+
+gboolean meta_cursor_renderer_is_hw_cursors_inhibited (MetaCursorRenderer *renderer,
+                                                       MetaCursorSprite   *cursor_sprite);
+
 ClutterRect meta_cursor_renderer_calculate_rect (MetaCursorRenderer *renderer,
                                                  MetaCursorSprite   *cursor_sprite);
 
diff --git a/src/backends/native/meta-cursor-renderer-native.c 
b/src/backends/native/meta-cursor-renderer-native.c
index 29800953b..3ff4e81fb 100644
--- a/src/backends/native/meta-cursor-renderer-native.c
+++ b/src/backends/native/meta-cursor-renderer-native.c
@@ -587,6 +587,10 @@ should_have_hw_cursor (MetaCursorRenderer *renderer,
   if (!cursor_sprite)
     return FALSE;
 
+  if (meta_cursor_renderer_is_hw_cursors_inhibited (renderer,
+                                                    cursor_sprite))
+    return FALSE;
+
   for (l = gpus; l; l = l->next)
     {
       MetaGpuKms *gpu_kms = l->data;


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