summaryrefslogtreecommitdiff
path: root/libs/input/TouchSpotController.cpp
diff options
context:
space:
mode:
authorLiam Harrington <wharrington@google.com>2020-08-14 04:00:11 +0000
committerLiam Harrington <wharrington@google.com>2020-08-19 23:02:09 +0000
commitce6371395599eea49038c4c6a1ba5b86d55be86e (patch)
tree2a2b714b1c501e84d8513b15e6305cba6ab4d7ea /libs/input/TouchSpotController.cpp
parentf623c1e2c2a7f2ff71f0360f74c93d4ef799ab39 (diff)
Switch to callback animation
Modified current animation logic to use callbacks from the controllers to further clean and modularize code. Test: Pixel 3XL device, atest PointerController_test, compile Change-Id: I1073bd78687cca491663c0349751dab4b30aa8e2
Diffstat (limited to 'libs/input/TouchSpotController.cpp')
-rw-r--r--libs/input/TouchSpotController.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/libs/input/TouchSpotController.cpp b/libs/input/TouchSpotController.cpp
index c7430ceead41..f7c685ff8ba6 100644
--- a/libs/input/TouchSpotController.cpp
+++ b/libs/input/TouchSpotController.cpp
@@ -142,7 +142,8 @@ TouchSpotController::Spot* TouchSpotController::getSpot(uint32_t id,
}
TouchSpotController::Spot* TouchSpotController::createAndAddSpotLocked(uint32_t id,
- std::vector<Spot*>& spots) {
+ std::vector<Spot*>& spots)
+ REQUIRES(mLock) {
// Remove spots until we have fewer than MAX_SPOTS remaining.
while (spots.size() >= MAX_SPOTS) {
Spot* spot = removeFirstFadingSpotLocked(spots);
@@ -186,14 +187,13 @@ void TouchSpotController::releaseSpotLocked(Spot* spot) REQUIRES(mLock) {
if (mLocked.recycledSprites.size() < MAX_RECYCLED_SPRITES) {
mLocked.recycledSprites.push_back(spot->sprite);
}
-
delete spot;
}
void TouchSpotController::fadeOutAndReleaseSpotLocked(Spot* spot) REQUIRES(mLock) {
if (spot->id != Spot::INVALID_ID) {
spot->id = Spot::INVALID_ID;
- mContext.startAnimation();
+ startAnimationLocked();
}
}
@@ -209,8 +209,24 @@ void TouchSpotController::reloadSpotResources() {
mContext.getPolicy()->loadPointerResources(&mResources, mDisplayId);
}
-bool TouchSpotController::doFadingAnimation(nsecs_t timestamp, bool keepAnimating) {
+bool TouchSpotController::doAnimations(nsecs_t timestamp) {
std::scoped_lock lock(mLock);
+ bool keepAnimating = doFadingAnimationLocked(timestamp);
+ if (!keepAnimating) {
+ /*
+ * We know that this callback will be removed before another
+ * is added. mLock in PointerAnimator will not be released
+ * until after this is removed, and adding another callback
+ * requires that lock. Thus it's safe to set mLocked.animating
+ * here.
+ */
+ mLocked.animating = false;
+ }
+ return keepAnimating;
+}
+
+bool TouchSpotController::doFadingAnimationLocked(nsecs_t timestamp) REQUIRES(mLock) {
+ bool keepAnimating = false;
nsecs_t animationTime = mContext.getAnimationTime();
nsecs_t frameDelay = timestamp - animationTime;
size_t numSpots = mLocked.displaySpots.size();
@@ -233,4 +249,16 @@ bool TouchSpotController::doFadingAnimation(nsecs_t timestamp, bool keepAnimatin
return keepAnimating;
}
+void TouchSpotController::startAnimationLocked() REQUIRES(mLock) {
+ using namespace std::placeholders;
+
+ if (mLocked.animating) {
+ return;
+ }
+ mLocked.animating = true;
+
+ std::function<bool(nsecs_t)> func = std::bind(&TouchSpotController::doAnimations, this, _1);
+ mContext.addAnimationCallback(mDisplayId, func);
+}
+
} // namespace android