diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2020-08-24 11:28:48 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-08-24 11:28:48 +0000 |
commit | 42e412b5111f99e6e4813aa9ab7450ec215ca09b (patch) | |
tree | 08eec6c6c1d0725ed35b7db71a1d15f9ea18db6c /libs/input/TouchSpotController.cpp | |
parent | be053b7e197809408865a2a4989df05d3012385b (diff) | |
parent | 5267d9227289a074aa4c4a972586d182ce4c76a5 (diff) |
Merge "Switch to callback animation" am: 51060f3f7a am: 5267d92272
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1399752
Change-Id: I3e4d82a9a2f9e9f4f1232a2de21a55cc19a2168a
Diffstat (limited to 'libs/input/TouchSpotController.cpp')
-rw-r--r-- | libs/input/TouchSpotController.cpp | 36 |
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 |