[gnome-shell/gbsneto/more-clutter-content: 3/5] magnifier: Use a ClutterContent to render mouse sprite



commit a7bb8ee6398b9b55a80e7fa541f4950603149178
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Jan 29 11:46:33 2019 -0200

    magnifier: Use a ClutterContent to render mouse sprite
    
    The Magnifier class uses a small subtree of actors to track the
    current cursor's position and sprite. Specifically, it uses the
    deprecated ClutterTexture to paint the cursor sprites.
    
    Add a new, very simple ClutterContent implementation to track the
    cursor sprite, and replace the ClutterTexture by a ClutterActor.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/371

 js/ui/magnifier.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 src/shell-util.c   | 18 ---------------
 src/shell-util.h   |  3 ---
 3 files changed, 64 insertions(+), 25 deletions(-)
---
diff --git a/js/ui/magnifier.js b/js/ui/magnifier.js
index 6931c7d4f..661146a1a 100644
--- a/js/ui/magnifier.js
+++ b/js/ui/magnifier.js
@@ -5,6 +5,7 @@ const Clutter = imports.gi.Clutter;
 const GDesktopEnums = imports.gi.GDesktopEnums;
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
 const Shell = imports.gi.Shell;
 const St = imports.gi.St;
 const Mainloop = imports.mainloop;
@@ -52,6 +53,51 @@ const CROSS_HAIRS_CLIP_KEY      = 'cross-hairs-clip';
 
 let magDBusService = null;
 
+var MouseSpriteContent = GObject.registerClass({
+    Implements: [ Clutter.Content ],
+}, class MouseSpriteContent extends GObject.Object {
+    _init() {
+        super._init();
+        this._texture = null;
+    }
+
+    vfunc_get_preferred_size(content) {
+        if (!this._texture)
+            return [0, 0];
+
+        return [this._texture.get_width(), this._texture.get_height()];
+    }
+
+    vfunc_paint_content(content, actor, node) {
+        if (!this._texture)
+            return;
+
+        let color = new Cogl.Color();
+        color.init_from_4ub(0, 0, 0, 0);
+
+        let textureNode = new Clutter.TextureNode(this._texture,
+                                                  color,
+                                                  Clutter.ScalingFilter.NEAREST,
+                                                  Clutter.ScalingFilter.NEAREST);
+        textureNode.set_name('MouseSpriteContent');
+        node.add_child(textureNode);
+
+        textureNode.add_rectangle(actor.get_content_box());
+    }
+
+    get texture() {
+        return this._texture;
+    }
+
+    set texture(coglTexture) {
+        if (this._texture == coglTexture)
+            return;
+
+        this._texture = coglTexture;
+        this.invalidate();
+    }
+});
+
 var Magnifier = class Magnifier {
     constructor() {
         // Magnifier is a manager of ZoomRegions.
@@ -59,8 +105,12 @@ var Magnifier = class Magnifier {
 
         // Create small clutter tree for the magnified mouse.
         let cursorTracker = Meta.CursorTracker.get_for_display(global.display);
-        this._mouseSprite = new Clutter.Texture();
-        Shell.util_cursor_tracker_to_clutter(cursorTracker, this._mouseSprite);
+        this._cursorTracker = cursorTracker;
+
+        this._mouseSprite = new Clutter.Actor({ request_mode: Clutter.RequestMode.CONTENT_SIZE });
+        this._mouseSprite.content = new MouseSpriteContent();
+        this._updateSpriteTexture();
+
         this._cursorRoot = new Clutter.Actor();
         this._cursorRoot.add_actor(this._mouseSprite);
 
@@ -76,7 +126,6 @@ var Magnifier = class Magnifier {
         aZoomRegion.scrollContentsTo(this.xMouse, this.yMouse);
 
         cursorTracker.connect('cursor-changed', this._updateMouseSprite.bind(this));
-        this._cursorTracker = cursorTracker;
 
         // Export to dbus.
         magDBusService = new MagnifierDBus.ShellMagnifier();
@@ -436,11 +485,22 @@ var Magnifier = class Magnifier {
     //// Private methods ////
 
     _updateMouseSprite() {
-        Shell.util_cursor_tracker_to_clutter(this._cursorTracker, this._mouseSprite);
+        this._updateSpriteTexture();
         let [xHot, yHot] = this._cursorTracker.get_hot();
         this._mouseSprite.set_anchor_point(xHot, yHot);
     }
 
+    _updateSpriteTexture() {
+        let sprite = this._cursorTracker.get_sprite();
+
+        if (sprite) {
+            this._mouseSprite.content.texture = sprite;
+            this._mouseSprite.show();
+        } else {
+            this._mouseSprite.hide();
+        }
+    }
+
     _settingsInit(zoomRegion) {
         this._appSettings = new Gio.Settings({ schema_id: APPLICATIONS_SCHEMA });
         this._settings = new Gio.Settings({ schema_id: MAGNIFIER_SCHEMA });
diff --git a/src/shell-util.c b/src/shell-util.c
index f0a8483d7..dfc13cd21 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -367,24 +367,6 @@ shell_util_create_pixbuf_from_data (const guchar      *data,
                                    (GdkPixbufDestroyNotify) g_free, NULL);
 }
 
-void
-shell_util_cursor_tracker_to_clutter (MetaCursorTracker *tracker,
-                                      ClutterTexture    *texture)
-{
-  CoglTexture *sprite;
-
-  sprite = meta_cursor_tracker_get_sprite (tracker);
-  if (sprite)
-    {
-      clutter_actor_show (CLUTTER_ACTOR (texture));
-      clutter_texture_set_cogl_texture (texture, sprite);
-    }
-  else
-    {
-      clutter_actor_hide (CLUTTER_ACTOR (texture));
-    }
-}
-
 typedef const gchar *(*ShellGLGetString) (GLenum);
 
 static const gchar *
diff --git a/src/shell-util.h b/src/shell-util.h
index bbd38a8be..914f438d2 100644
--- a/src/shell-util.h
+++ b/src/shell-util.h
@@ -44,9 +44,6 @@ GdkPixbuf *shell_util_create_pixbuf_from_data (const guchar      *data,
                                                int                height,
                                                int                rowstride);
 
-void    shell_util_cursor_tracker_to_clutter (MetaCursorTracker *tracker,
-                                              ClutterTexture    *texture);
-
 gboolean shell_util_need_background_refresh (void);
 
 ClutterContent * shell_util_get_content_for_window_actor (MetaWindowActor *window_actor,


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