diff options
author | David Reveman <davidr@novell.com> | 2008-06-23 23:27:01 -0400 |
---|---|---|
committer | David Reveman <davidr@novell.com> | 2008-10-30 03:36:57 -0400 |
commit | 1d401db26613ccd24d6f218f459bf824710e7b44 (patch) | |
tree | bfb51df4060613b2f3def4d9fb696e4f5b388c0d | |
parent | e4e5db738039d3ab5d5fe2132beee4c45851f07e (diff) |
Expose animated cursors to DDX for possible acceleration.
Each animated cursor is now realized as regular cursors
and IsAnimCur macro can be used to check if a cursor is
an animated cursor.
-rw-r--r-- | render/animcur.c | 98 | ||||
-rw-r--r-- | render/picturestr.h | 25 |
2 files changed, 72 insertions, 51 deletions
diff --git a/render/animcur.c b/render/animcur.c index 335feaa56..d4e2ca58e 100644 --- a/render/animcur.c +++ b/render/animcur.c @@ -44,22 +44,12 @@ #include "dixfontstr.h" #include "opaque.h" #include "picturestr.h" #include "inputstr.h" #include "xace.h" -typedef struct _AnimCurElt { - CursorPtr pCursor; /* cursor to show */ - CARD32 delay; /* in ms */ -} AnimCurElt; - -typedef struct _AnimCur { - int nelt; /* number of elements in the elts array */ - AnimCurElt *elts; /* actually allocated right after the structure */ -} AnimCurRec, *AnimCurPtr; - typedef struct _AnimScrPriv { CursorPtr pCursor; int elt; CARD32 time; CloseScreenProcPtr CloseScreen; @@ -83,23 +73,21 @@ typedef struct _AnimCurState { /* What a waste. But we need an API change to alloc it per device only. */ static AnimCurStateRec animCurState[MAX_DEVICES]; static unsigned char empty[4]; -static CursorBits animCursorBits = { +CursorBits animCursorBits = { empty, empty, 2, 1, 1, 0, 0, 1 }; static int AnimCurGeneration; static int AnimCurScreenPrivateKeyIndex; static DevPrivateKey AnimCurScreenPrivateKey = &AnimCurScreenPrivateKeyIndex; -#define IsAnimCur(c) ((c) && ((c)->bits == &animCursorBits)) -#define GetAnimCur(c) ((AnimCurPtr) ((c) + 1)) #define GetAnimCurScreen(s) ((AnimCurScreenPtr)dixLookupPrivate(&(s)->devPrivates, AnimCurScreenPrivateKey)) #define GetAnimCurScreenIfSet(s) GetAnimCurScreen(s) #define SetAnimCurScreen(s,p) dixSetPrivate(&(s)->devPrivates, AnimCurScreenPrivateKey, p) #define Wrap(as,s,elt,func) (((as)->elt = (s)->elt), (s)->elt = func) #define Unwrap(as,s,elt) ((s)->elt = (as)->elt) @@ -285,16 +273,13 @@ AnimCurRealizeCursor (DeviceIntPtr pDev, CursorPtr pCursor) { AnimCurScreenPtr as = GetAnimCurScreen(pScreen); Bool ret; Unwrap (as, pScreen, RealizeCursor); - if (IsAnimCur(pCursor)) - ret = TRUE; - else - ret = (*pScreen->RealizeCursor) (pDev, pScreen, pCursor); + ret = (*pScreen->RealizeCursor) (pDev, pScreen, pCursor); Wrap (as, pScreen, RealizeCursor, AnimCurRealizeCursor); return ret; } static Bool AnimCurUnrealizeCursor (DeviceIntPtr pDev, @@ -302,24 +287,22 @@ AnimCurUnrealizeCursor (DeviceIntPtr pDev, CursorPtr pCursor) { AnimCurScreenPtr as = GetAnimCurScreen(pScreen); Bool ret; Unwrap (as, pScreen, UnrealizeCursor); + ret = (*pScreen->UnrealizeCursor) (pDev, pScreen, pCursor); if (IsAnimCur(pCursor)) { AnimCurPtr ac = GetAnimCur(pCursor); int i; if (pScreen->myNum == 0) for (i = 0; i < ac->nelt; i++) FreeCursor (ac->elts[i].pCursor, 0); - ret = TRUE; } - else - ret = (*pScreen->UnrealizeCursor) (pDev, pScreen, pCursor); Wrap (as, pScreen, UnrealizeCursor, AnimCurUnrealizeCursor); return ret; } static void AnimCurRecolorCursor (DeviceIntPtr pDev, @@ -378,15 +361,17 @@ AnimCurInit (ScreenPtr pScreen) return TRUE; } int AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor, ClientPtr client, XID cid) { - CursorPtr pCursor; - int rc, i; - AnimCurPtr ac; + CursorPtr pCursor; + int rc, nscr, i; + AnimCurPtr ac; + ScreenPtr pscr; + DeviceIntPtr pDev; for (i = 0; i < screenInfo.numScreens; i++) if (!GetAnimCurScreenIfSet (screenInfo.screens[i])) return BadImplementation; for (i = 0; i < ncursor; i++) @@ -432,30 +417,57 @@ AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *pp for (i = 0; i < ncursor; i++) { cursors[i]->refcnt++; ac->elts[i].pCursor = cursors[i]; ac->elts[i].delay = deltas[i]; } - - *ppCursor = pCursor; - return Success; -} -void -AnimForEachCursorElt (ScreenPtr pScreen, - CursorPtr pCursor, - CursorProcPtr callBack) -{ - if (IsAnimCur (pCursor)) - { - AnimCurPtr ac = GetAnimCur (pCursor); - int i; - - for (i = 0; i < ac->nelt; i++) - (*callBack) (pScreen, ac->elts[i].pCursor); - - } - else + /* + * realize the cursor for every screen + * Do not change the refcnt, this will be changed when ChangeToCursor + * actually changes the sprite. + */ + for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { - (*callBack) (pScreen, pCursor); + pscr = screenInfo.screens[nscr]; + for (pDev = inputInfo.devices; pDev; pDev = pDev->next) + { + if (DevHasCursor(pDev)) + { + if (!( *pscr->RealizeCursor)(pDev, pscr, pCursor)) + { + /* Realize failed for device pDev on screen pscr. + * We have to assume that for all devices before, realize + * worked. We need to rollback all devices so far on the + * current screen and then all devices on previous + * screens. + */ + DeviceIntPtr pDevIt = inputInfo.devices; /*dev iterator*/ + while(pDevIt && pDevIt != pDev) + { + if (DevHasCursor(pDevIt)) + ( *pscr->UnrealizeCursor)(pDevIt, pscr, pCursor); + pDevIt = pDevIt->next; + } + while (--nscr >= 0) + { + pscr = screenInfo.screens[nscr]; + /* now unrealize all devices on previous screens */ + pDevIt = inputInfo.devices; + while (pDevIt) + { + if (DevHasCursor(pDevIt)) + ( *pscr->UnrealizeCursor)(pDevIt, pscr, pCursor); + pDevIt = pDevIt->next; + } + ( *pscr->UnrealizeCursor)(pDev, pscr, pCursor); + } + dixFreePrivates(pCursor->devPrivates); + xfree(pCursor); + return BadAlloc; + } + } + } } + *ppCursor = pCursor; + return Success; } diff --git a/render/picturestr.h b/render/picturestr.h index 71647e67f..e91a70a25 100644 --- a/render/picturestr.h +++ b/render/picturestr.h @@ -23,12 +23,13 @@ #ifndef _PICTURESTR_H_ #define _PICTURESTR_H_ #include "scrnintstr.h" #include "glyphstr.h" +#include "cursorstr.h" #include "resource.h" #include "privates.h" typedef struct _DirectFormat { CARD16 red, redMask; CARD16 green, greenMask; @@ -614,12 +615,28 @@ CARD32 PictureGradientColor (PictGradientStopPtr stop1, PictGradientStopPtr stop2, CARD32 x); void RenderExtensionInit (void); + +typedef struct _AnimCurElt { + CursorPtr pCursor; /* cursor to show */ + CARD32 delay; /* in ms */ +} AnimCurElt; + +typedef struct _AnimCur { + int nelt; /* number of elements in the elts array */ + AnimCurElt *elts; /* actually allocated right after the structure */ +} AnimCurRec, *AnimCurPtr; + +extern CursorBits animCursorBits; + +#define IsAnimCur(c) ((c) && ((c)->bits == &animCursorBits)) +#define GetAnimCur(c) ((AnimCurPtr) ((c) + 1)) + Bool AnimCurInit (ScreenPtr pScreen); int AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor, ClientPtr client, XID cid); @@ -670,15 +687,7 @@ CreateConicalGradientPicture (Picture pid, #ifdef PANORAMIX void PanoramiXRenderInit (void); void PanoramiXRenderReset (void); #endif -typedef void (*CursorProcPtr) (ScreenPtr pScreen, - CursorPtr pCursor); - -void -AnimForEachCursorElt (ScreenPtr pScreen, - CursorPtr pCursor, - CursorProcPtr callBack); - #endif /* _PICTURESTR_H_ */ |