Revert "Revert "Revert "VectorDrawable native rendering - Step 5 of MANY"""
This reverts commit 0d20a275a5baf8579c8b9111cf2ce6615874a6b6.
Change-Id: I97c782f1164a5d39ab74dc098cca71d9e1b30cd8
diff --git a/libs/hwui/Animator.cpp b/libs/hwui/Animator.cpp
index 372bcb3..7bd2b24 100644
--- a/libs/hwui/Animator.cpp
+++ b/libs/hwui/Animator.cpp
@@ -42,8 +42,7 @@
, mStartTime(0)
, mDuration(300)
, mStartDelay(0)
- , mMayRunAsync(true)
- , mPlayTime(0) {
+ , mMayRunAsync(true) {
}
BaseRenderNodeAnimator::~BaseRenderNodeAnimator() {
@@ -86,113 +85,20 @@
onAttached();
}
-void BaseRenderNodeAnimator::start() {
- mStagingPlayState = PlayState::Running;
- mStagingRequests.push_back(Request::Start);
- onStagingPlayStateChanged();
-}
-
-void BaseRenderNodeAnimator::cancel() {
- mStagingPlayState = PlayState::Finished;
- mStagingRequests.push_back(Request::Cancel);
- onStagingPlayStateChanged();
-}
-
-void BaseRenderNodeAnimator::reset() {
- mStagingPlayState = PlayState::Finished;
- mStagingRequests.push_back(Request::Reset);
- onStagingPlayStateChanged();
-}
-
-void BaseRenderNodeAnimator::reverse() {
- mStagingPlayState = PlayState::Reversing;
- mStagingRequests.push_back(Request::Reverse);
- onStagingPlayStateChanged();
-}
-
-void BaseRenderNodeAnimator::end() {
- mStagingPlayState = PlayState::Finished;
- mStagingRequests.push_back(Request::End);
- onStagingPlayStateChanged();
-}
-
-void BaseRenderNodeAnimator::resolveStagingRequest(Request request) {
- switch (request) {
- case Request::Start:
- mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) ?
- mPlayTime : 0;
- mPlayState = PlayState::Running;
- break;
- case Request::Reverse:
- mPlayTime = (mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) ?
- mPlayTime : mDuration;
- mPlayState = PlayState::Reversing;
- break;
- case Request::Reset:
- mPlayTime = 0;
- mPlayState = PlayState::Finished;
- break;
- case Request::Cancel:
- mPlayState = PlayState::Finished;
- break;
- case Request::End:
- mPlayTime = mPlayState == PlayState::Reversing ? 0 : mDuration;
- mPlayState = PlayState::Finished;
- break;
- default:
- LOG_ALWAYS_FATAL("Invalid staging request: %d", static_cast<int>(request));
- };
-}
-
void BaseRenderNodeAnimator::pushStaging(AnimationContext& context) {
if (!mHasStartValue) {
doSetStartValue(getValue(mTarget));
}
-
- if (!mStagingRequests.empty()) {
- // Keep track of the play state and play time before they are changed when
- // staging requests are resolved.
- nsecs_t currentPlayTime = mPlayTime;
- PlayState prevFramePlayState = mPlayState;
-
- // Resolve staging requests one by one.
- for (Request request : mStagingRequests) {
- resolveStagingRequest(request);
+ if (mStagingPlayState > mPlayState) {
+ if (mStagingPlayState == PlayState::Restarted) {
+ mStagingPlayState = PlayState::Running;
}
- mStagingRequests.clear();
-
- if (mStagingPlayState == PlayState::Finished) {
- // Set the staging play time and end the animation
- updatePlayTime(mPlayTime);
+ mPlayState = mStagingPlayState;
+ // Oh boy, we're starting! Man the battle stations!
+ if (mPlayState == PlayState::Running) {
+ transitionToRunning(context);
+ } else if (mPlayState == PlayState::Finished) {
callOnFinishedListener(context);
- } else if (mStagingPlayState == PlayState::Running
- || mStagingPlayState == PlayState::Reversing) {
- bool changed = currentPlayTime != mPlayTime || prevFramePlayState != mStagingPlayState;
- if (prevFramePlayState != mStagingPlayState) {
- transitionToRunning(context);
- }
- if (changed) {
- // Now we need to seek to the stagingPlayTime (i.e. the animation progress that was
- // requested from UI thread). It is achieved by modifying mStartTime, such that
- // current time - mStartTime = stagingPlayTime (or mDuration -stagingPlayTime in the
- // case of reversing)
- nsecs_t currentFrameTime = context.frameTimeMs();
- if (mPlayState == PlayState::Reversing) {
- // Reverse is not supported for animations with a start delay, so here we
- // assume no start delay.
- mStartTime = currentFrameTime - (mDuration - mPlayTime);
- } else {
- // Animation should play forward
- if (mPlayTime == 0) {
- // If the request is to start from the beginning, include start delay.
- mStartTime = currentFrameTime + mStartDelay;
- } else {
- // If the request is to seek to a non-zero play time, then we skip start
- // delay.
- mStartTime = currentFrameTime - mPlayTime;
- }
- }
- }
}
}
}
@@ -230,37 +136,37 @@
// This should be set before setValue() so animators can query this time when setValue
// is called.
- nsecs_t currentPlayTime = context.frameTimeMs() - mStartTime;
- bool finished = updatePlayTime(currentPlayTime);
- if (finished && mPlayState != PlayState::Finished) {
- mPlayState = PlayState::Finished;
- callOnFinishedListener(context);
- }
- return finished;
-}
+ nsecs_t currentFrameTime = context.frameTimeMs();
+ onPlayTimeChanged(currentFrameTime - mStartTime);
-bool BaseRenderNodeAnimator::updatePlayTime(nsecs_t playTime) {
- mPlayTime = mPlayState == PlayState::Reversing ? mDuration - playTime : playTime;
- onPlayTimeChanged(mPlayTime);
// If BaseRenderNodeAnimator is handling the delay (not typical), then
// because the staging properties reflect the final value, we always need
// to call setValue even if the animation isn't yet running or is still
// being delayed as we need to override the staging value
- if (playTime < 0) {
+ if (mStartTime > context.frameTimeMs()) {
setValue(mTarget, mFromValue);
return false;
}
float fraction = 1.0f;
- if ((mPlayState == PlayState::Running || mPlayState == PlayState::Reversing) && mDuration > 0) {
- fraction = mPlayTime / (float) mDuration;
+
+ if (mPlayState == PlayState::Running && mDuration > 0) {
+ fraction = (float)(currentFrameTime - mStartTime) / mDuration;
}
- fraction = MathUtils::clamp(fraction, 0.0f, 1.0f);
+ if (fraction >= 1.0f) {
+ fraction = 1.0f;
+ mPlayState = PlayState::Finished;
+ }
fraction = mInterpolator->interpolate(fraction);
setValue(mTarget, mFromValue + (mDeltaValue * fraction));
- return playTime >= mDuration;
+ if (mPlayState == PlayState::Finished) {
+ callOnFinishedListener(context);
+ return true;
+ }
+
+ return false;
}
void BaseRenderNodeAnimator::forceEndNow(AnimationContext& context) {