From ce6371395599eea49038c4c6a1ba5b86d55be86e Mon Sep 17 00:00:00 2001 From: Liam Harrington Date: Fri, 14 Aug 2020 04:00:11 +0000 Subject: 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 --- libs/input/TouchSpotController.cpp | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'libs/input/TouchSpotController.cpp') 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& spots) { + std::vector& 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 func = std::bind(&TouchSpotController::doAnimations, this, _1); + mContext.addAnimationCallback(mDisplayId, func); +} + } // namespace android -- cgit v1.2.3-59-g8ed1b