[PATCH 3/3] render: set anim cursor state for pointer enable devices only
Peter Hutterer
peter.hutterer at who-t.net
Tue May 4 22:36:43 PDT 2010
On Tue, May 04, 2010 at 08:07:05PM +0300, Tiago Vignatti wrote:
> remove MAXDEVICES dependency \o/
>
> Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
> ---
> dix/devices.c | 3 ++
> render/animcur.c | 91 +++++++++++++++++++++++++++++++++-----------------
> render/picturestr.h | 3 ++
> 3 files changed, 66 insertions(+), 31 deletions(-)
>
> diff --git a/dix/devices.c b/dix/devices.c
> index 1386491..16a8d92 100644
> --- a/dix/devices.c
> +++ b/dix/devices.c
> @@ -342,6 +342,9 @@ EnableDevice(DeviceIntPtr dev, BOOL sendevent)
>
> RecalculateMasterButtons(dev);
>
> + /* allocate animated cursor is a device is capable */
> + AnimCursorAlloc(dev);
> +
InitializeSprite() should be the better place for this, because I guess most
keyboards won't need a cursor allocated.
> return TRUE;
> }
>
> diff --git a/render/animcur.c b/render/animcur.c
> index eb74b1a..ede1dbb 100644
> --- a/render/animcur.c
> +++ b/render/animcur.c
> @@ -77,8 +77,6 @@ typedef struct _AnimCurState {
> 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];
>
> @@ -99,6 +97,22 @@ 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 int AnimCurStatePrivateKeyIndex;
> +static DevPrivateKey AnimCurStatePrivateKey = &AnimCurStatePrivateKeyIndex;
> +
> +static inline AnimCurStatePtr
> +GetAnimCurState (DeviceIntPtr d)
> +{
> + return ((AnimCurStatePtr) dixLookupPrivate(&(d)->devPrivates,
> + AnimCurStatePrivateKey));
> +}
> +
> +static inline void
> +SetAnimCurState (DeviceIntPtr d, AnimCurStatePtr c)
> +{
> + dixSetPrivate(&(d)->devPrivates, AnimCurStatePrivateKey, c);
> +}
> +
as Keith said, this could be added to the spriteInfo struct instead of the
devPrivates.
Cheers,
Peter
> static Bool
> AnimCurCloseScreen (int index, ScreenPtr pScreen)
> @@ -167,14 +181,14 @@ AnimCurScreenBlockHandler (int screenNum,
>
> for (dev = inputInfo.devices; dev; dev = dev->next)
> {
> - if (IsPointerDevice(dev) && pScreen == animCurState[dev->id].pScreen)
> + if (IsPointerDevice(dev) && pScreen == GetAnimCurState(dev)->pScreen)
> {
> if (!now) now = GetTimeInMillis ();
>
> - if ((INT32) (now - animCurState[dev->id].time) >= 0)
> + if ((INT32) (now - GetAnimCurState(dev)->time) >= 0)
> {
> - AnimCurPtr ac = GetAnimCur(animCurState[dev->id].pCursor);
> - int elt = (animCurState[dev->id].elt + 1) % ac->nelt;
> + AnimCurPtr ac = GetAnimCur(GetAnimCurState(dev)->pCursor);
> + int elt = (GetAnimCurState(dev)->elt + 1) % ac->nelt;
> DisplayCursorProcPtr DisplayCursor;
>
> /*
> @@ -190,12 +204,14 @@ AnimCurScreenBlockHandler (int screenNum,
> as->DisplayCursor = pScreen->DisplayCursor;
> pScreen->DisplayCursor = DisplayCursor;
>
> - animCurState[dev->id].elt = elt;
> - animCurState[dev->id].time = now + ac->elts[elt].delay;
> + AnimCurStatePtr animCurState = GetAnimCurState(dev);
> + animCurState->elt = elt;
> + animCurState->time = now + ac->elts[elt].delay;
> + SetAnimCurState(dev, animCurState);
> }
>
> - if (soonest > animCurState[dev->id].time)
> - soonest = animCurState[dev->id].time;
> + if (soonest > GetAnimCurState(dev)->time)
> + soonest = GetAnimCurState(dev)->time;
> }
> }
>
> @@ -218,7 +234,7 @@ AnimCurDisplayCursor (DeviceIntPtr pDev,
> Unwrap (as, pScreen, DisplayCursor);
> if (IsAnimCur(pCursor))
> {
> - if (pCursor != animCurState[pDev->id].pCursor)
> + if (pCursor != GetAnimCurState(pDev)->pCursor)
> {
> AnimCurPtr ac = GetAnimCur(pCursor);
>
> @@ -226,10 +242,12 @@ 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;
> + AnimCurStatePtr animCurState = GetAnimCurState(pDev);
> + animCurState->elt = 0;
> + animCurState->time = GetTimeInMillis () + ac->elts[0].delay;
> + animCurState->pCursor = pCursor;
> + animCurState->pScreen = pScreen;
> + SetAnimCurState(pDev, animCurState);
> }
> }
> else
> @@ -237,8 +255,6 @@ AnimCurDisplayCursor (DeviceIntPtr pDev,
> }
> else
> {
> - animCurState[pDev->id].pCursor = 0;
> - animCurState[pDev->id].pScreen = 0;
> ret = (*pScreen->DisplayCursor) (pDev, pScreen, pCursor);
> }
> Wrap (as, pScreen, DisplayCursor, AnimCurDisplayCursor);
> @@ -256,8 +272,11 @@ AnimCurSetCursorPosition (DeviceIntPtr pDev,
> Bool ret;
>
> Unwrap (as, pScreen, SetCursorPosition);
> - if (animCurState[pDev->id].pCursor)
> - animCurState[pDev->id].pScreen = pScreen;
> + if ((AnimCurGeneration == serverGeneration) && GetAnimCurState(pDev)->pCursor) {
> + AnimCurStatePtr animCurState = GetAnimCurState(pDev);
> + animCurState->pScreen = pScreen;
> + SetAnimCurState(pDev, animCurState);
> + }
> ret = (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent);
> Wrap (as, pScreen, SetCursorPosition, AnimCurSetCursorPosition);
> return ret;
> @@ -322,29 +341,39 @@ AnimCurRecolorCursor (DeviceIntPtr pDev,
> for (i = 0; i < ac->nelt; i++)
> (*pScreen->RecolorCursor) (pDev, pScreen, ac->elts[i].pCursor,
> displayed &&
> - animCurState[pDev->id].elt == i);
> + GetAnimCurState(pDev)->elt == i);
> }
> else
> (*pScreen->RecolorCursor) (pDev, pScreen, pCursor, displayed);
> Wrap (as, pScreen, RecolorCursor, AnimCurRecolorCursor);
> }
>
> +void
> +AnimCursorAlloc(DeviceIntPtr dev)
> +{
> +
> + if (IsPointerDevice(dev)) {
> + AnimCurStatePtr animCurState;
> +
> + animCurState = xalloc (sizeof(AnimCurStateRec));
> + if (!animCurState)
> + FatalError("Unable to allocate animated cursors\n");
> +
> + animCurState->pCursor = 0;
> + animCurState->pScreen = 0;
> + animCurState->elt = 0;
> + animCurState->time = 0;
> + SetAnimCurState(dev, animCurState);
> + }
> +
> + AnimCurGeneration = serverGeneration;
> +}
> +
> Bool
> 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;
> diff --git a/render/picturestr.h b/render/picturestr.h
> index 6a8d76d..b45f603 100644
> --- a/render/picturestr.h
> +++ b/render/picturestr.h
> @@ -623,6 +623,9 @@ extern _X_EXPORT void RenderExtensionInit (void);
> Bool
> AnimCurInit (ScreenPtr pScreen);
>
> +Bool
> +AnimCurAlloc (DeviceIntPtr dev);
> +
> int
> AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor, ClientPtr client, XID cid);
>
> --
> 1.6.0.4
>
More information about the xorg-devel
mailing list