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

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