Animator.cpp revision 64bb413a664001c95c8439cf097dc3033f4ed733
1e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck/* 2e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * Copyright (C) 2014 The Android Open Source Project 3e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * 4e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * Licensed under the Apache License, Version 2.0 (the "License"); 5e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * you may not use this file except in compliance with the License. 6e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * You may obtain a copy of the License at 7e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * 8e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * http://www.apache.org/licenses/LICENSE-2.0 9e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * 10e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * Unless required by applicable law or agreed to in writing, software 11e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * distributed under the License is distributed on an "AS IS" BASIS, 12e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * See the License for the specific language governing permissions and 14e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * limitations under the License. 15e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck */ 16e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 17e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#include "Animator.h" 18e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 1968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck#include <inttypes.h> 20e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#include <set> 21e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 22119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck#include "AnimationContext.h" 232dc236b2bae13b9a0ed9b3f7320502aecd7983b3Tom Hudson#include "Interpolator.h" 2452244fff29042926e21fa897ef5ab11148e35299John Reck#include "RenderNode.h" 25e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#include "RenderProperties.h" 26e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 27e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Recknamespace android { 28e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Recknamespace uirenderer { 29e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 30e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck/************************************************************ 31ff941dcd815021bb20d6504eb486acb1e50592c3John Reck * BaseRenderNodeAnimator 32e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck ************************************************************/ 33e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 34ff941dcd815021bb20d6504eb486acb1e50592c3John ReckBaseRenderNodeAnimator::BaseRenderNodeAnimator(float finalValue) 358d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck : mTarget(NULL) 368d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck , mFinalValue(finalValue) 37ff941dcd815021bb20d6504eb486acb1e50592c3John Reck , mDeltaValue(0) 38ff941dcd815021bb20d6504eb486acb1e50592c3John Reck , mFromValue(0) 39ff941dcd815021bb20d6504eb486acb1e50592c3John Reck , mInterpolator(0) 4068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck , mStagingPlayState(NOT_STARTED) 4168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck , mPlayState(NOT_STARTED) 4268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck , mHasStartValue(false) 43e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck , mStartTime(0) 44ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette , mDuration(300) 45572d9acd598517c20c7bf2feb189357e925fa879Chris Craik , mStartDelay(0) 46572d9acd598517c20c7bf2feb189357e925fa879Chris Craik , mMayRunAsync(true) { 47e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} 48e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 49ff941dcd815021bb20d6504eb486acb1e50592c3John ReckBaseRenderNodeAnimator::~BaseRenderNodeAnimator() { 5068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck delete mInterpolator; 5168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck} 5268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck 5368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reckvoid BaseRenderNodeAnimator::checkMutable() { 5468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck // Should be impossible to hit as the Java-side also has guards for this 5568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck LOG_ALWAYS_FATAL_IF(mStagingPlayState != NOT_STARTED, 5668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck "Animator has already been started!"); 57e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} 58e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 59ff941dcd815021bb20d6504eb486acb1e50592c3John Reckvoid BaseRenderNodeAnimator::setInterpolator(Interpolator* interpolator) { 6068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck checkMutable(); 61e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck delete mInterpolator; 62e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck mInterpolator = interpolator; 63e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} 64e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 65ff941dcd815021bb20d6504eb486acb1e50592c3John Reckvoid BaseRenderNodeAnimator::setStartValue(float value) { 6668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck checkMutable(); 6768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck doSetStartValue(value); 68ff941dcd815021bb20d6504eb486acb1e50592c3John Reck} 69ff941dcd815021bb20d6504eb486acb1e50592c3John Reck 7068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reckvoid BaseRenderNodeAnimator::doSetStartValue(float value) { 7168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck mFromValue = value; 7268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck mDeltaValue = (mFinalValue - mFromValue); 7368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck mHasStartValue = true; 74ff941dcd815021bb20d6504eb486acb1e50592c3John Reck} 75ff941dcd815021bb20d6504eb486acb1e50592c3John Reck 76ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverettevoid BaseRenderNodeAnimator::setDuration(nsecs_t duration) { 7768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck checkMutable(); 78ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette mDuration = duration; 79ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette} 80ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette 81ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverettevoid BaseRenderNodeAnimator::setStartDelay(nsecs_t startDelay) { 8268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck checkMutable(); 83ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette mStartDelay = startDelay; 84ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette} 85ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette 868d8af3c1b768d590754d657a7d1242dcb462454bJohn Reckvoid BaseRenderNodeAnimator::attach(RenderNode* target) { 878d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck mTarget = target; 888d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck onAttached(); 898d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck} 908d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck 91119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reckvoid BaseRenderNodeAnimator::pushStaging(AnimationContext& context) { 9268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (!mHasStartValue) { 938d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck doSetStartValue(getValue(mTarget)); 94ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette } 9568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (mStagingPlayState > mPlayState) { 9668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck mPlayState = mStagingPlayState; 9768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck // Oh boy, we're starting! Man the battle stations! 9868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (mPlayState == RUNNING) { 99119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck transitionToRunning(context); 1004d2c47206a8e1706e5f89ef73c0e50e7321bf862John Reck } else if (mPlayState == FINISHED) { 1014d2c47206a8e1706e5f89ef73c0e50e7321bf862John Reck callOnFinishedListener(context); 10268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck } 10368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck } 10468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck} 105ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette 106119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reckvoid BaseRenderNodeAnimator::transitionToRunning(AnimationContext& context) { 107119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck nsecs_t frameTimeMs = context.frameTimeMs(); 108119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck LOG_ALWAYS_FATAL_IF(frameTimeMs <= 0, "%" PRId64 " isn't a real frame time!", frameTimeMs); 10968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (mStartDelay < 0 || mStartDelay > 50000) { 11068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck ALOGW("Your start delay is strange and confusing: %" PRId64, mStartDelay); 11168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck } 112119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck mStartTime = frameTimeMs + mStartDelay; 11368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (mStartTime < 0) { 11468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck ALOGW("Ended up with a really weird start time of %" PRId64 11568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck " with frame time %" PRId64 " and start delay %" PRId64, 116119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck mStartTime, frameTimeMs, mStartDelay); 11768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck // Set to 0 so that the animate() basically instantly finishes 11868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck mStartTime = 0; 11968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck } 12068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck // No interpolator was set, use the default 12168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (!mInterpolator) { 1228d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck mInterpolator = Interpolator::createDefaultInterpolator(); 12368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck } 12468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (mDuration < 0 || mDuration > 50000) { 12568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck ALOGW("Your duration is strange and confusing: %" PRId64, mDuration); 12668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck } 12768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck} 12868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck 129119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reckbool BaseRenderNodeAnimator::animate(AnimationContext& context) { 13068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (mPlayState < RUNNING) { 131ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette return false; 132ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette } 13332fb6307de7c3ee9399a39dc6734f1c82ffd1dcbJohn Reck if (mPlayState == FINISHED) { 13432fb6307de7c3ee9399a39dc6734f1c82ffd1dcbJohn Reck return true; 13532fb6307de7c3ee9399a39dc6734f1c82ffd1dcbJohn Reck } 136ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette 1378d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck // If BaseRenderNodeAnimator is handling the delay (not typical), then 1388d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck // because the staging properties reflect the final value, we always need 1398d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck // to call setValue even if the animation isn't yet running or is still 1408d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck // being delayed as we need to override the staging value 141119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck if (mStartTime > context.frameTimeMs()) { 1428d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck setValue(mTarget, mFromValue); 14368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck return false; 144e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck } 145e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 146e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck float fraction = 1.0f; 14768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (mPlayState == RUNNING && mDuration > 0) { 148119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck fraction = (float)(context.frameTimeMs() - mStartTime) / mDuration; 149e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck } 15068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (fraction >= 1.0f) { 15168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck fraction = 1.0f; 15268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck mPlayState = FINISHED; 15368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck } 15468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck 155e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck fraction = mInterpolator->interpolate(fraction); 1568d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck setValue(mTarget, mFromValue + (mDeltaValue * fraction)); 157e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 158e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck if (mPlayState == FINISHED) { 159119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck callOnFinishedListener(context); 160e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck return true; 161e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck } 16268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck 163e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck return false; 164e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} 165e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 166e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reckvoid BaseRenderNodeAnimator::forceEndNow(AnimationContext& context) { 167e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck if (mPlayState < FINISHED) { 168e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck mPlayState = FINISHED; 169e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck callOnFinishedListener(context); 170e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck } 171e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck} 172e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck 173119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reckvoid BaseRenderNodeAnimator::callOnFinishedListener(AnimationContext& context) { 17452244fff29042926e21fa897ef5ab11148e35299John Reck if (mListener.get()) { 175119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck context.callOnFinished(this, mListener.get()); 17652244fff29042926e21fa897ef5ab11148e35299John Reck } 17752244fff29042926e21fa897ef5ab11148e35299John Reck} 17852244fff29042926e21fa897ef5ab11148e35299John Reck 179e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck/************************************************************ 18052244fff29042926e21fa897ef5ab11148e35299John Reck * RenderPropertyAnimator 18152244fff29042926e21fa897ef5ab11148e35299John Reck ************************************************************/ 18252244fff29042926e21fa897ef5ab11148e35299John Reck 183ff941dcd815021bb20d6504eb486acb1e50592c3John Reckstruct RenderPropertyAnimator::PropertyAccessors { 184ff941dcd815021bb20d6504eb486acb1e50592c3John Reck RenderNode::DirtyPropertyMask dirtyMask; 185ff941dcd815021bb20d6504eb486acb1e50592c3John Reck GetFloatProperty getter; 186ff941dcd815021bb20d6504eb486acb1e50592c3John Reck SetFloatProperty setter; 187ff941dcd815021bb20d6504eb486acb1e50592c3John Reck}; 188ff941dcd815021bb20d6504eb486acb1e50592c3John Reck 18952244fff29042926e21fa897ef5ab11148e35299John Reck// Maps RenderProperty enum to accessors 19052244fff29042926e21fa897ef5ab11148e35299John Reckconst RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY_ACCESSOR_LUT[] = { 191ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationX, &RenderProperties::setTranslationX }, 192ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::TRANSLATION_Y, &RenderProperties::getTranslationY, &RenderProperties::setTranslationY }, 193ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationZ, &RenderProperties::setTranslationZ }, 194ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::SCALE_X, &RenderProperties::getScaleX, &RenderProperties::setScaleX }, 195ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::SCALE_Y, &RenderProperties::getScaleY, &RenderProperties::setScaleY }, 196ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::ROTATION, &RenderProperties::getRotation, &RenderProperties::setRotation }, 197ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::ROTATION_X, &RenderProperties::getRotationX, &RenderProperties::setRotationX }, 198ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::ROTATION_Y, &RenderProperties::getRotationY, &RenderProperties::setRotationY }, 199ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::X, &RenderProperties::getX, &RenderProperties::setX }, 200ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::Y, &RenderProperties::getY, &RenderProperties::setY }, 201ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::Z, &RenderProperties::getZ, &RenderProperties::setZ }, 202ff941dcd815021bb20d6504eb486acb1e50592c3John Reck {RenderNode::ALPHA, &RenderProperties::getAlpha, &RenderProperties::setAlpha }, 20352244fff29042926e21fa897ef5ab11148e35299John Reck}; 20452244fff29042926e21fa897ef5ab11148e35299John Reck 205ff941dcd815021bb20d6504eb486acb1e50592c3John ReckRenderPropertyAnimator::RenderPropertyAnimator(RenderProperty property, float finalValue) 206ff941dcd815021bb20d6504eb486acb1e50592c3John Reck : BaseRenderNodeAnimator(finalValue) 207ff941dcd815021bb20d6504eb486acb1e50592c3John Reck , mPropertyAccess(&(PROPERTY_ACCESSOR_LUT[property])) { 208ff941dcd815021bb20d6504eb486acb1e50592c3John Reck} 209ff941dcd815021bb20d6504eb486acb1e50592c3John Reck 2108d8af3c1b768d590754d657a7d1242dcb462454bJohn Reckvoid RenderPropertyAnimator::onAttached() { 21168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck if (!mHasStartValue 2128d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck && mTarget->isPropertyFieldDirty(mPropertyAccess->dirtyMask)) { 2138d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck setStartValue((mTarget->stagingProperties().*mPropertyAccess->getter)()); 2148d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck } 2158d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck} 2168d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck 2178d8af3c1b768d590754d657a7d1242dcb462454bJohn Reckvoid RenderPropertyAnimator::onStagingPlayStateChanged() { 2188d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck if (mStagingPlayState == RUNNING) { 2198d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck (mTarget->mutateStagingProperties().*mPropertyAccess->setter)(finalValue()); 22032fb6307de7c3ee9399a39dc6734f1c82ffd1dcbJohn Reck } else if (mStagingPlayState == FINISHED) { 22132fb6307de7c3ee9399a39dc6734f1c82ffd1dcbJohn Reck // We're being canceled, so make sure that whatever values the UI thread 22232fb6307de7c3ee9399a39dc6734f1c82ffd1dcbJohn Reck // is observing for us is pushed over 22332fb6307de7c3ee9399a39dc6734f1c82ffd1dcbJohn Reck mTarget->setPropertyFieldsDirty(dirtyMask()); 224ff941dcd815021bb20d6504eb486acb1e50592c3John Reck } 22552244fff29042926e21fa897ef5ab11148e35299John Reck} 22652244fff29042926e21fa897ef5ab11148e35299John Reck 2272218472d23483f09341bf655d55db21dcbabc1b6John Reckuint32_t RenderPropertyAnimator::dirtyMask() { 2282218472d23483f09341bf655d55db21dcbabc1b6John Reck return mPropertyAccess->dirtyMask; 2292218472d23483f09341bf655d55db21dcbabc1b6John Reck} 2302218472d23483f09341bf655d55db21dcbabc1b6John Reck 231ff941dcd815021bb20d6504eb486acb1e50592c3John Reckfloat RenderPropertyAnimator::getValue(RenderNode* target) const { 232ff941dcd815021bb20d6504eb486acb1e50592c3John Reck return (target->properties().*mPropertyAccess->getter)(); 23352244fff29042926e21fa897ef5ab11148e35299John Reck} 23452244fff29042926e21fa897ef5ab11148e35299John Reck 235ff941dcd815021bb20d6504eb486acb1e50592c3John Reckvoid RenderPropertyAnimator::setValue(RenderNode* target, float value) { 236ff941dcd815021bb20d6504eb486acb1e50592c3John Reck (target->animatorProperties().*mPropertyAccess->setter)(value); 23752244fff29042926e21fa897ef5ab11148e35299John Reck} 23852244fff29042926e21fa897ef5ab11148e35299John Reck 23952244fff29042926e21fa897ef5ab11148e35299John Reck/************************************************************ 24052244fff29042926e21fa897ef5ab11148e35299John Reck * CanvasPropertyPrimitiveAnimator 24152244fff29042926e21fa897ef5ab11148e35299John Reck ************************************************************/ 24252244fff29042926e21fa897ef5ab11148e35299John Reck 24352244fff29042926e21fa897ef5ab11148e35299John ReckCanvasPropertyPrimitiveAnimator::CanvasPropertyPrimitiveAnimator( 244ff941dcd815021bb20d6504eb486acb1e50592c3John Reck CanvasPropertyPrimitive* property, float finalValue) 245ff941dcd815021bb20d6504eb486acb1e50592c3John Reck : BaseRenderNodeAnimator(finalValue) 24652244fff29042926e21fa897ef5ab11148e35299John Reck , mProperty(property) { 24752244fff29042926e21fa897ef5ab11148e35299John Reck} 24852244fff29042926e21fa897ef5ab11148e35299John Reck 24964bb413a664001c95c8439cf097dc3033f4ed733Andreas Gampefloat CanvasPropertyPrimitiveAnimator::getValue(RenderNode* target) const { 25052244fff29042926e21fa897ef5ab11148e35299John Reck return mProperty->value; 25152244fff29042926e21fa897ef5ab11148e35299John Reck} 25252244fff29042926e21fa897ef5ab11148e35299John Reck 25364bb413a664001c95c8439cf097dc3033f4ed733Andreas Gampevoid CanvasPropertyPrimitiveAnimator::setValue(RenderNode* target, float value) { 25452244fff29042926e21fa897ef5ab11148e35299John Reck mProperty->value = value; 25552244fff29042926e21fa897ef5ab11148e35299John Reck} 25652244fff29042926e21fa897ef5ab11148e35299John Reck 257a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reckuint32_t CanvasPropertyPrimitiveAnimator::dirtyMask() { 258a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck return RenderNode::DISPLAY_LIST; 259a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck} 260a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck 26152244fff29042926e21fa897ef5ab11148e35299John Reck/************************************************************ 26252244fff29042926e21fa897ef5ab11148e35299John Reck * CanvasPropertySkPaintAnimator 26352244fff29042926e21fa897ef5ab11148e35299John Reck ************************************************************/ 26452244fff29042926e21fa897ef5ab11148e35299John Reck 26552244fff29042926e21fa897ef5ab11148e35299John ReckCanvasPropertyPaintAnimator::CanvasPropertyPaintAnimator( 266ff941dcd815021bb20d6504eb486acb1e50592c3John Reck CanvasPropertyPaint* property, PaintField field, float finalValue) 267ff941dcd815021bb20d6504eb486acb1e50592c3John Reck : BaseRenderNodeAnimator(finalValue) 26852244fff29042926e21fa897ef5ab11148e35299John Reck , mProperty(property) 26952244fff29042926e21fa897ef5ab11148e35299John Reck , mField(field) { 27052244fff29042926e21fa897ef5ab11148e35299John Reck} 27152244fff29042926e21fa897ef5ab11148e35299John Reck 27264bb413a664001c95c8439cf097dc3033f4ed733Andreas Gampefloat CanvasPropertyPaintAnimator::getValue(RenderNode* target) const { 27352244fff29042926e21fa897ef5ab11148e35299John Reck switch (mField) { 27452244fff29042926e21fa897ef5ab11148e35299John Reck case STROKE_WIDTH: 27552244fff29042926e21fa897ef5ab11148e35299John Reck return mProperty->value.getStrokeWidth(); 27652244fff29042926e21fa897ef5ab11148e35299John Reck case ALPHA: 27752244fff29042926e21fa897ef5ab11148e35299John Reck return mProperty->value.getAlpha(); 27852244fff29042926e21fa897ef5ab11148e35299John Reck } 27952244fff29042926e21fa897ef5ab11148e35299John Reck LOG_ALWAYS_FATAL("Unknown field %d", (int) mField); 28052244fff29042926e21fa897ef5ab11148e35299John Reck return -1; 28152244fff29042926e21fa897ef5ab11148e35299John Reck} 28252244fff29042926e21fa897ef5ab11148e35299John Reck 283531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reckstatic uint8_t to_uint8(float value) { 284531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reck int c = (int) (value + .5f); 285531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reck return static_cast<uint8_t>( c < 0 ? 0 : c > 255 ? 255 : c ); 286531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reck} 287531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reck 28864bb413a664001c95c8439cf097dc3033f4ed733Andreas Gampevoid CanvasPropertyPaintAnimator::setValue(RenderNode* target, float value) { 28952244fff29042926e21fa897ef5ab11148e35299John Reck switch (mField) { 29052244fff29042926e21fa897ef5ab11148e35299John Reck case STROKE_WIDTH: 29152244fff29042926e21fa897ef5ab11148e35299John Reck mProperty->value.setStrokeWidth(value); 29252244fff29042926e21fa897ef5ab11148e35299John Reck return; 29352244fff29042926e21fa897ef5ab11148e35299John Reck case ALPHA: 294531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reck mProperty->value.setAlpha(to_uint8(value)); 29552244fff29042926e21fa897ef5ab11148e35299John Reck return; 29652244fff29042926e21fa897ef5ab11148e35299John Reck } 29752244fff29042926e21fa897ef5ab11148e35299John Reck LOG_ALWAYS_FATAL("Unknown field %d", (int) mField); 298e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} 299e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 300a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reckuint32_t CanvasPropertyPaintAnimator::dirtyMask() { 301a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck return RenderNode::DISPLAY_LIST; 302a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck} 303a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck 304af4d04cab6d48ae0d6a5e79bd30f679af87abaadChris CraikRevealAnimator::RevealAnimator(int centerX, int centerY, 305d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck float startValue, float finalValue) 306d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck : BaseRenderNodeAnimator(finalValue) 307d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck , mCenterX(centerX) 308af4d04cab6d48ae0d6a5e79bd30f679af87abaadChris Craik , mCenterY(centerY) { 309d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck setStartValue(startValue); 310d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck} 311d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck 312d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reckfloat RevealAnimator::getValue(RenderNode* target) const { 313af4d04cab6d48ae0d6a5e79bd30f679af87abaadChris Craik return target->properties().getRevealClip().getRadius(); 314d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck} 315d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck 316d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reckvoid RevealAnimator::setValue(RenderNode* target, float value) { 317af4d04cab6d48ae0d6a5e79bd30f679af87abaadChris Craik target->animatorProperties().mutableRevealClip().set(true, 318d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck mCenterX, mCenterY, value); 319d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck} 320d3de42cae84fadfa1befd082a2cf1bf72f9ad82aJohn Reck 321a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reckuint32_t RevealAnimator::dirtyMask() { 322a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck return RenderNode::GENERIC; 323a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck} 324a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck 325e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace uirenderer */ 326e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace android */ 327