Introduce animated pointer icon for STYLE_WAIT.
Change-Id: I893f8276e09351db6187c553f349008794b95690
diff --git a/libs/input/PointerController.cpp b/libs/input/PointerController.cpp
index c9586e4..bd6af78 100644
--- a/libs/input/PointerController.cpp
+++ b/libs/input/PointerController.cpp
@@ -86,6 +86,9 @@
mLocked.pointerIconChanged = false;
mLocked.requestedPointerShape = mPolicy->getDefaultPointerIconId();
+ mLocked.animationFrameIndex = 0;
+ mLocked.lastFrameUpdatedTime = 0;
+
mLocked.buttonState = 0;
loadResources();
@@ -239,7 +242,8 @@
AutoMutex _l(mLock);
if (presentation == PRESENTATION_POINTER && mLocked.additionalMouseResources.empty()) {
- mPolicy->loadAdditionalMouseResources(&mLocked.additionalMouseResources);
+ mPolicy->loadAdditionalMouseResources(&mLocked.additionalMouseResources,
+ &mLocked.animationResources);
}
if (mLocked.presentation != presentation) {
@@ -402,7 +406,7 @@
updatePointerLocked();
}
-void PointerController::updatePointerShape(int iconId) {
+void PointerController::updatePointerShape(int32_t iconId) {
AutoMutex _l(mLock);
if (mLocked.requestedPointerShape != iconId) {
mLocked.requestedPointerShape = iconId;
@@ -462,8 +466,17 @@
void PointerController::doAnimate(nsecs_t timestamp) {
AutoMutex _l(mLock);
- bool keepAnimating = false;
mLocked.animationPending = false;
+
+ bool keepFading = doFadingAnimationLocked(timestamp);
+ bool keepBitmapFlipping = doBitmapAnimationLocked(timestamp);
+ if (keepFading || keepBitmapFlipping) {
+ startAnimationLocked();
+ }
+}
+
+bool PointerController::doFadingAnimationLocked(nsecs_t timestamp) {
+ bool keepAnimating = false;
nsecs_t frameDelay = timestamp - mLocked.animationTime;
// Animate pointer fade.
@@ -501,10 +514,32 @@
}
}
}
+ return keepAnimating;
+}
- if (keepAnimating) {
- startAnimationLocked();
+bool PointerController::doBitmapAnimationLocked(nsecs_t timestamp) {
+ std::map<int32_t, PointerAnimation>::const_iterator iter = mLocked.animationResources.find(
+ mLocked.requestedPointerShape);
+ if (iter == mLocked.animationResources.end()) {
+ return false;
}
+
+ if (timestamp - mLocked.lastFrameUpdatedTime > iter->second.durationPerFrame) {
+ mSpriteController->openTransaction();
+
+ int incr = (timestamp - mLocked.lastFrameUpdatedTime) / iter->second.durationPerFrame;
+ mLocked.animationFrameIndex += incr;
+ mLocked.lastFrameUpdatedTime += iter->second.durationPerFrame * incr;
+ while (mLocked.animationFrameIndex >= iter->second.animationFrames.size()) {
+ mLocked.animationFrameIndex -= iter->second.animationFrames.size();
+ }
+ mLocked.pointerSprite->setIcon(iter->second.animationFrames[mLocked.animationFrameIndex]);
+
+ mSpriteController->closeTransaction();
+ }
+
+ // Keep animating.
+ return true;
}
void PointerController::doInactivityTimeout() {
@@ -549,9 +584,16 @@
if (mLocked.requestedPointerShape == mPolicy->getDefaultPointerIconId()) {
mLocked.pointerSprite->setIcon(mLocked.pointerIcon);
} else {
- std::map<int, SpriteIcon>::const_iterator iter =
+ std::map<int32_t, SpriteIcon>::const_iterator iter =
mLocked.additionalMouseResources.find(mLocked.requestedPointerShape);
if (iter != mLocked.additionalMouseResources.end()) {
+ std::map<int32_t, PointerAnimation>::const_iterator anim_iter =
+ mLocked.animationResources.find(mLocked.requestedPointerShape);
+ if (anim_iter != mLocked.animationResources.end()) {
+ mLocked.animationFrameIndex = 0;
+ mLocked.lastFrameUpdatedTime = systemTime(SYSTEM_TIME_MONOTONIC);
+ startAnimationLocked();
+ }
mLocked.pointerSprite->setIcon(iter->second);
} else {
ALOGW("Can't find the resource for icon id %d", mLocked.requestedPointerShape);
diff --git a/libs/input/PointerController.h b/libs/input/PointerController.h
index 6d840db..b6c01d2 100644
--- a/libs/input/PointerController.h
+++ b/libs/input/PointerController.h
@@ -20,6 +20,7 @@
#include "SpriteController.h"
#include <map>
+#include <vector>
#include <ui/DisplayInfo.h>
#include <input/Input.h>
@@ -30,8 +31,6 @@
#include <utils/String8.h>
#include <gui/DisplayEventReceiver.h>
-#include <SkBitmap.h>
-
namespace android {
/*
@@ -43,6 +42,11 @@
SpriteIcon spotAnchor;
};
+struct PointerAnimation {
+ std::vector<SpriteIcon> animationFrames;
+ nsecs_t durationPerFrame;
+};
+
/*
* Pointer controller policy interface.
*
@@ -59,7 +63,8 @@
public:
virtual void loadPointerResources(PointerResources* outResources) = 0;
- virtual void loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources) = 0;
+ virtual void loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
+ std::map<int32_t, PointerAnimation>* outAnimationResources) = 0;
virtual int32_t getDefaultPointerIconId() = 0;
};
@@ -98,7 +103,7 @@
const uint32_t* spotIdToIndex, BitSet32 spotIdBits);
virtual void clearSpots();
- void updatePointerShape(int iconId);
+ void updatePointerShape(int32_t iconId);
void setDisplayViewport(int32_t width, int32_t height, int32_t orientation);
void setPointerIcon(const SpriteIcon& icon);
void setInactivityTimeout(InactivityTimeout inactivityTimeout);
@@ -145,6 +150,9 @@
bool animationPending;
nsecs_t animationTime;
+ size_t animationFrameIndex;
+ nsecs_t lastFrameUpdatedTime;
+
int32_t displayWidth;
int32_t displayHeight;
int32_t displayOrientation;
@@ -162,7 +170,8 @@
SpriteIcon pointerIcon;
bool pointerIconChanged;
- std::map<int, SpriteIcon> additionalMouseResources;
+ std::map<int32_t, SpriteIcon> additionalMouseResources;
+ std::map<int32_t, PointerAnimation> animationResources;
int32_t requestedPointerShape;
@@ -178,6 +187,8 @@
void handleMessage(const Message& message);
int handleEvent(int fd, int events, void* data);
void doAnimate(nsecs_t timestamp);
+ bool doFadingAnimationLocked(nsecs_t timestamp);
+ bool doBitmapAnimationLocked(nsecs_t timestamp);
void doInactivityTimeout();
void startAnimationLocked();