[PATCH v2 3/4] render: set anim cursor state for pointer enabled devices only
Peter Hutterer
peter.hutterer at who-t.net
Tue May 11 17:00:32 PDT 2010
On Fri, May 07, 2010 at 06:24:18PM +0300, Tiago Vignatti wrote:
> The structure containing the state of animated cursor was amended within
> SpriteInfoRec, removing all previously privates logic to keep such state.
>
> API change: It was removed MAXDEVICES dependency \o/
>
> Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
> ---
> include/inputstr.h | 7 ++++++
> render/animcur.c | 59 +++++++++++++++-------------------------------------
> 2 files changed, 24 insertions(+), 42 deletions(-)
>
> diff --git a/include/inputstr.h b/include/inputstr.h
> index 6da3f38..e87411f 100644
> --- a/include/inputstr.h
> +++ b/include/inputstr.h
> @@ -477,6 +477,13 @@ typedef struct _SpriteInfoRec {
> DeviceIntPtr paired; /* The paired device. Keyboard if
> spriteOwner is TRUE, otherwise the
> pointer that owns the sprite. */
> +
> + /* keep states for animated cursor */
> + CursorPtr pCursor;
> + ScreenPtr pScreen;
> + int elt;
> + CARD32 time;
> +
> } SpriteInfoRec, *SpriteInfoPtr;
Personally, I'd prefer this to be grouped in a substruct or just be a
AnimCurStateRec. It's rather confusing to read things like
dev->spriteInfo->time, dev->spriteInfo->anim.time seems to be clearer here.
> /* device types */
> diff --git a/render/animcur.c b/render/animcur.c
> index eb74b1a..8e2b498 100644
> --- a/render/animcur.c
> +++ b/render/animcur.c
> @@ -70,24 +70,12 @@ typedef struct _AnimScrPriv {
> RecolorCursorProcPtr RecolorCursor;
> } AnimCurScreenRec, *AnimCurScreenPtr;
>
> -typedef struct _AnimCurState {
> - CursorPtr pCursor;
> - ScreenPtr pScreen;
> - int elt;
> - CARD32 time;
> -} AnimCurStateRec, *AnimCurStatePtr;
> -
> -/* What a waste. But we need an API change to alloc it per device only. */
> -static AnimCurStateRec animCurState[MAXDEVICES];
> -
> static unsigned char empty[4];
>
> static CursorBits animCursorBits = {
> empty, empty, 2, 1, 1, 0, 0, 1
> };
>
> -static int AnimCurGeneration;
> -
> static int AnimCurScreenPrivateKeyIndex;
> static DevPrivateKey AnimCurScreenPrivateKey = &AnimCurScreenPrivateKeyIndex;
>
> @@ -99,7 +87,6 @@ static DevPrivateKey AnimCurScreenPrivateKey = &AnimCurScreenPrivateKeyIndex;
> #define Wrap(as,s,elt,func) (((as)->elt = (s)->elt), (s)->elt = func)
> #define Unwrap(as,s,elt) ((s)->elt = (as)->elt)
>
> -
> static Bool
> AnimCurCloseScreen (int index, ScreenPtr pScreen)
> {
> @@ -167,14 +154,14 @@ AnimCurScreenBlockHandler (int screenNum,
>
> for (dev = inputInfo.devices; dev; dev = dev->next)
> {
> - if (IsPointerDevice(dev) && pScreen == animCurState[dev->id].pScreen)
> + if (IsPointerDevice(dev) && pScreen == dev->spriteInfo->pScreen)
> {
> if (!now) now = GetTimeInMillis ();
>
> - if ((INT32) (now - animCurState[dev->id].time) >= 0)
> + if ((INT32) (now - dev->spriteInfo->time) >= 0)
> {
> - AnimCurPtr ac = GetAnimCur(animCurState[dev->id].pCursor);
> - int elt = (animCurState[dev->id].elt + 1) % ac->nelt;
> + AnimCurPtr ac = GetAnimCur(dev->spriteInfo->pCursor);
> + int elt = (dev->spriteInfo->elt + 1) % ac->nelt;
> DisplayCursorProcPtr DisplayCursor;
>
> /*
> @@ -190,12 +177,12 @@ AnimCurScreenBlockHandler (int screenNum,
> as->DisplayCursor = pScreen->DisplayCursor;
> pScreen->DisplayCursor = DisplayCursor;
>
> - animCurState[dev->id].elt = elt;
> - animCurState[dev->id].time = now + ac->elts[elt].delay;
> + dev->spriteInfo->elt = elt;
> + dev->spriteInfo->time = now + ac->elts[elt].delay;
> }
>
> - if (soonest > animCurState[dev->id].time)
> - soonest = animCurState[dev->id].time;
> + if (soonest > dev->spriteInfo->time)
> + soonest = dev->spriteInfo->time;
> }
> }
>
> @@ -218,7 +205,7 @@ AnimCurDisplayCursor (DeviceIntPtr pDev,
> Unwrap (as, pScreen, DisplayCursor);
> if (IsAnimCur(pCursor))
> {
> - if (pCursor != animCurState[pDev->id].pCursor)
> + if (pCursor != pDev->spriteInfo->pCursor)
> {
> AnimCurPtr ac = GetAnimCur(pCursor);
>
> @@ -226,10 +213,10 @@ AnimCurDisplayCursor (DeviceIntPtr pDev,
> (pDev, pScreen, ac->elts[0].pCursor);
> if (ret)
> {
> - animCurState[pDev->id].elt = 0;
> - animCurState[pDev->id].time = GetTimeInMillis () + ac->elts[0].delay;
> - animCurState[pDev->id].pCursor = pCursor;
> - animCurState[pDev->id].pScreen = pScreen;
> + pDev->spriteInfo->elt = 0;
> + pDev->spriteInfo->time = GetTimeInMillis () + ac->elts[0].delay;
> + pDev->spriteInfo->pCursor = pCursor;
> + pDev->spriteInfo->pScreen = pScreen;
> }
> }
> else
> @@ -237,8 +224,6 @@ AnimCurDisplayCursor (DeviceIntPtr pDev,
> }
> else
> {
> - animCurState[pDev->id].pCursor = 0;
> - animCurState[pDev->id].pScreen = 0;
> ret = (*pScreen->DisplayCursor) (pDev, pScreen, pCursor);
> }
might want to remove the { } here as well.
> Wrap (as, pScreen, DisplayCursor, AnimCurDisplayCursor);
> @@ -256,8 +241,9 @@ AnimCurSetCursorPosition (DeviceIntPtr pDev,
> Bool ret;
>
> Unwrap (as, pScreen, SetCursorPosition);
> - if (animCurState[pDev->id].pCursor)
> - animCurState[pDev->id].pScreen = pScreen;
> + if (pDev->spriteInfo->pCursor)
> + pDev->spriteInfo->pScreen = pScreen;
> +
> ret = (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent);
> Wrap (as, pScreen, SetCursorPosition, AnimCurSetCursorPosition);
> return ret;
> @@ -322,7 +308,7 @@ AnimCurRecolorCursor (DeviceIntPtr pDev,
> for (i = 0; i < ac->nelt; i++)
> (*pScreen->RecolorCursor) (pDev, pScreen, ac->elts[i].pCursor,
> displayed &&
> - animCurState[pDev->id].elt == i);
> + pDev->spriteInfo->elt == i);
> }
> else
> (*pScreen->RecolorCursor) (pDev, pScreen, pCursor, displayed);
> @@ -334,17 +320,6 @@ AnimCurInit (ScreenPtr pScreen)
> {
> AnimCurScreenPtr as;
>
> - if (AnimCurGeneration != serverGeneration)
> - {
> - int i;
> - AnimCurGeneration = serverGeneration;
> - for (i = 0; i < MAXDEVICES; i++) {
> - animCurState[i].pCursor = 0;
> - animCurState[i].pScreen = 0;
> - animCurState[i].elt = 0;
> - animCurState[i].time = 0;
> - }
> - }
> as = (AnimCurScreenPtr) xalloc (sizeof (AnimCurScreenRec));
> if (!as)
> return FALSE;
> --
> 1.6.0.4
Other than that
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
Cheers,
Peter
More information about the xorg-devel
mailing list