Blame SOURCES/0004-animcur-Run-the-timer-from-the-device-not-the-screen.patch

637c9d
From 2a798845c62f54c921d6fad7fa7fab596dc7e11b Mon Sep 17 00:00:00 2001
637c9d
From: Adam Jackson <ajax@redhat.com>
637c9d
Date: Thu, 26 Oct 2017 15:24:39 -0400
637c9d
Subject: [PATCH xserver 4/6] animcur: Run the timer from the device, not the
637c9d
 screen
637c9d
637c9d
This is very slightly more efficient since the callback now doesn't need
637c9d
to walk every input device, instead we know exactly which device's
637c9d
cursor is being updated. AnimCurTimerNotify() gets outdented nicely as a
637c9d
result. A more important side effect is that we can stop using the
637c9d
TimerAbsolute mode and just pass in the relative delay.
637c9d
637c9d
In AnimCurSetCursorPosition, we no longer need to rearm the timer with
637c9d
the new screen; it is enough to update the device's state. In
637c9d
AnimCurDisplayCursor we need to notice when we're switching from
637c9d
animated cursor to regular and cancel the existing timer.
637c9d
637c9d
Reviewed-by: Robert Morell <rmorell@nvidia.com>
637c9d
Tested-by: Robert Morell <rmorell@nvidia.com>
637c9d
Signed-off-by: Adam Jackson <ajax@redhat.com>
637c9d
(cherry picked from commit 094a63d56fbfb9e23210cc9ac538fb198af37cee)
637c9d
---
637c9d
 render/animcur.c | 85 +++++++++++++++++++-------------------------------------
637c9d
 1 file changed, 28 insertions(+), 57 deletions(-)
637c9d
637c9d
diff --git a/render/animcur.c b/render/animcur.c
637c9d
index 26a6026ae..9393b4018 100644
637c9d
--- a/render/animcur.c
637c9d
+++ b/render/animcur.c
637c9d
@@ -55,6 +55,7 @@ typedef struct _AnimCurElt {
637c9d
 typedef struct _AnimCur {
637c9d
     int nelt;                   /* number of elements in the elts array */
637c9d
     AnimCurElt *elts;           /* actually allocated right after the structure */
637c9d
+    OsTimerPtr timer;
637c9d
 } AnimCurRec, *AnimCurPtr;
637c9d
637c9d
 typedef struct _AnimScrPriv {
637c9d
@@ -65,8 +66,6 @@ typedef struct _AnimScrPriv {
637c9d
     RealizeCursorProcPtr RealizeCursor;
637c9d
     UnrealizeCursorProcPtr UnrealizeCursor;
637c9d
     RecolorCursorProcPtr RecolorCursor;
637c9d
-    OsTimerPtr timer;
637c9d
-    Bool timer_set;
637c9d
 } AnimCurScreenRec, *AnimCurScreenPtr;
637c9d
637c9d
 static unsigned char empty[4];
637c9d
@@ -130,49 +129,27 @@ AnimCurCursorLimits(DeviceIntPtr pDev,
637c9d
 static CARD32
637c9d
 AnimCurTimerNotify(OsTimerPtr timer, CARD32 now, void *arg)
637c9d
 {
637c9d
-    ScreenPtr pScreen = arg;
637c9d
+    DeviceIntPtr dev = arg;
637c9d
+    ScreenPtr pScreen = dev->spriteInfo->anim.pScreen;
637c9d
     AnimCurScreenPtr as = GetAnimCurScreen(pScreen);
637c9d
-    DeviceIntPtr dev;
637c9d
-    Bool activeDevice = FALSE;
637c9d
-    CARD32 soonest = ~0;       /* earliest time to wakeup again */
637c9d
637c9d
-    for (dev = inputInfo.devices; dev; dev = dev->next) {
637c9d
-        if (IsPointerDevice(dev) && pScreen == dev->spriteInfo->anim.pScreen) {
637c9d
-            if (!activeDevice)
637c9d
-                activeDevice = TRUE;
637c9d
+    AnimCurPtr ac = GetAnimCur(dev->spriteInfo->anim.pCursor);
637c9d
+    int elt = (dev->spriteInfo->anim.elt + 1) % ac->nelt;
637c9d
+    DisplayCursorProcPtr DisplayCursor = pScreen->DisplayCursor;
637c9d
637c9d
-            if ((INT32) (now - dev->spriteInfo->anim.time) >= 0) {
637c9d
-                AnimCurPtr ac = GetAnimCur(dev->spriteInfo->anim.pCursor);
637c9d
-                int elt = (dev->spriteInfo->anim.elt + 1) % ac->nelt;
637c9d
-                DisplayCursorProcPtr DisplayCursor;
637c9d
+    /*
637c9d
+     * Not a simple Unwrap/Wrap as this isn't called along the DisplayCursor
637c9d
+     * wrapper chain.
637c9d
+     */
637c9d
+    pScreen->DisplayCursor = as->DisplayCursor;
637c9d
+    (void) (*pScreen->DisplayCursor) (dev, pScreen, ac->elts[elt].pCursor);
637c9d
+    as->DisplayCursor = pScreen->DisplayCursor;
637c9d
+    pScreen->DisplayCursor = DisplayCursor;
637c9d
637c9d
-                /*
637c9d
-                 * Not a simple Unwrap/Wrap as this
637c9d
-                 * isn't called along the DisplayCursor
637c9d
-                 * wrapper chain.
637c9d
-                 */
637c9d
-                DisplayCursor = pScreen->DisplayCursor;
637c9d
-                pScreen->DisplayCursor = as->DisplayCursor;
637c9d
-                (void) (*pScreen->DisplayCursor) (dev,
637c9d
-                                                  pScreen,
637c9d
-                                                  ac->elts[elt].pCursor);
637c9d
-                as->DisplayCursor = pScreen->DisplayCursor;
637c9d
-                pScreen->DisplayCursor = DisplayCursor;
637c9d
+    dev->spriteInfo->anim.elt = elt;
637c9d
+    dev->spriteInfo->anim.time = now + ac->elts[elt].delay;
637c9d
637c9d
-                dev->spriteInfo->anim.elt = elt;
637c9d
-                dev->spriteInfo->anim.time = now + ac->elts[elt].delay;
637c9d
-            }
637c9d
-
637c9d
-            if (soonest > dev->spriteInfo->anim.time)
637c9d
-                soonest = dev->spriteInfo->anim.time;
637c9d
-        }
637c9d
-    }
637c9d
-
637c9d
-    if (activeDevice)
637c9d
-        return soonest - now;
637c9d
-
637c9d
-    as->timer_set = FALSE;
637c9d
-    return 0;
637c9d
+    return ac->elts[elt].delay;
637c9d
 }
637c9d
637c9d
 static Bool
637c9d
@@ -198,17 +175,19 @@ AnimCurDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
637c9d
                 pDev->spriteInfo->anim.pCursor = pCursor;
637c9d
                 pDev->spriteInfo->anim.pScreen = pScreen;
637c9d
637c9d
-                if (!as->timer_set) {
637c9d
-                    TimerSet(as->timer, TimerAbsolute, pDev->spriteInfo->anim.time,
637c9d
-                             AnimCurTimerNotify, pScreen);
637c9d
-                    as->timer_set = TRUE;
637c9d
-                }
637c9d
+                ac->timer = TimerSet(ac->timer, 0, ac->elts[0].delay,
637c9d
+                                     AnimCurTimerNotify, pDev);
637c9d
             }
637c9d
         }
637c9d
         else
637c9d
             ret = TRUE;
637c9d
     }
637c9d
     else {
637c9d
+        CursorPtr old = pDev->spriteInfo->anim.pCursor;
637c9d
+
637c9d
+        if (old && IsAnimCur(old))
637c9d
+            TimerCancel(GetAnimCur(old)->timer);
637c9d
+
637c9d
         pDev->spriteInfo->anim.pCursor = 0;
637c9d
         pDev->spriteInfo->anim.pScreen = 0;
637c9d
         ret = (*pScreen->DisplayCursor) (pDev, pScreen, pCursor);
637c9d
@@ -227,12 +206,6 @@ AnimCurSetCursorPosition(DeviceIntPtr pDev,
637c9d
     Unwrap(as, pScreen, SetCursorPosition);
637c9d
     if (pDev->spriteInfo->anim.pCursor) {
637c9d
         pDev->spriteInfo->anim.pScreen = pScreen;
637c9d
-
637c9d
-        if (!as->timer_set) {
637c9d
-            TimerSet(as->timer, TimerAbsolute, pDev->spriteInfo->anim.time,
637c9d
-                     AnimCurTimerNotify, pScreen);
637c9d
-            as->timer_set = TRUE;
637c9d
-        }
637c9d
     }
637c9d
     ret = (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent);
637c9d
     Wrap(as, pScreen, SetCursorPosition, AnimCurSetCursorPosition);
637c9d
@@ -307,11 +280,6 @@ AnimCurInit(ScreenPtr pScreen)
637c9d
         return FALSE;
637c9d
637c9d
     as = GetAnimCurScreen(pScreen);
637c9d
-    as->timer = TimerSet(NULL, TimerAbsolute, 0, AnimCurTimerNotify, pScreen);
637c9d
-    if (!as->timer) {
637c9d
-        return FALSE;
637c9d
-    }
637c9d
-    as->timer_set = FALSE;
637c9d
637c9d
     Wrap(as, pScreen, CloseScreen, AnimCurCloseScreen);
637c9d
637c9d
@@ -359,10 +327,14 @@ AnimCursorCreate(CursorPtr *cursors, CARD32 *deltas, int ncursor,
637c9d
637c9d
     pCursor->id = cid;
637c9d
637c9d
+    ac = GetAnimCur(pCursor);
637c9d
+    ac->timer = TimerSet(NULL, 0, 0, AnimCurTimerNotify, NULL);
637c9d
+
637c9d
     /* security creation/labeling check */
637c9d
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR, pCursor,
637c9d
                   RT_NONE, NULL, DixCreateAccess);
637c9d
     if (rc != Success) {
637c9d
+        TimerFree(ac->timer);
637c9d
         dixFiniPrivates(pCursor, PRIVATE_CURSOR);
637c9d
         free(pCursor);
637c9d
         return rc;
637c9d
@@ -372,7 +344,6 @@ AnimCursorCreate(CursorPtr *cursors, CARD32 *deltas, int ncursor,
637c9d
      * Fill in the AnimCurRec
637c9d
      */
637c9d
     animCursorBits.refcnt++;
637c9d
-    ac = GetAnimCur(pCursor);
637c9d
     ac->nelt = ncursor;
637c9d
     ac->elts = (AnimCurElt *) (ac + 1);
637c9d
637c9d
--
637c9d
2.14.3