Animator.cpp revision 8d8af3c1b768d590754d657a7d1242dcb462454b
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#define LOG_TAG "RT-Animator"
18e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
19e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#include "Animator.h"
20e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
2168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck#include <inttypes.h>
22e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#include <set>
23e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
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)
45ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette        , mStartDelay(0) {
46e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck}
47e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
48ff941dcd815021bb20d6504eb486acb1e50592c3John ReckBaseRenderNodeAnimator::~BaseRenderNodeAnimator() {
4968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    delete mInterpolator;
5068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck}
5168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
5268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reckvoid BaseRenderNodeAnimator::checkMutable() {
5368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    // Should be impossible to hit as the Java-side also has guards for this
5468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    LOG_ALWAYS_FATAL_IF(mStagingPlayState != NOT_STARTED,
5568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck            "Animator has already been started!");
56e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck}
57e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
58ff941dcd815021bb20d6504eb486acb1e50592c3John Reckvoid BaseRenderNodeAnimator::setInterpolator(Interpolator* interpolator) {
5968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    checkMutable();
60e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    delete mInterpolator;
61e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    mInterpolator = interpolator;
62e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck}
63e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
64ff941dcd815021bb20d6504eb486acb1e50592c3John Reckvoid BaseRenderNodeAnimator::setStartValue(float value) {
6568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    checkMutable();
6668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    doSetStartValue(value);
67ff941dcd815021bb20d6504eb486acb1e50592c3John Reck}
68ff941dcd815021bb20d6504eb486acb1e50592c3John Reck
6968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reckvoid BaseRenderNodeAnimator::doSetStartValue(float value) {
7068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    mFromValue = value;
7168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    mDeltaValue = (mFinalValue - mFromValue);
7268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    mHasStartValue = true;
73ff941dcd815021bb20d6504eb486acb1e50592c3John Reck}
74ff941dcd815021bb20d6504eb486acb1e50592c3John Reck
75ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverettevoid BaseRenderNodeAnimator::setDuration(nsecs_t duration) {
7668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    checkMutable();
77ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette    mDuration = duration;
78ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette}
79ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette
80ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverettevoid BaseRenderNodeAnimator::setStartDelay(nsecs_t startDelay) {
8168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    checkMutable();
82ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette    mStartDelay = startDelay;
83ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette}
84ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette
858d8af3c1b768d590754d657a7d1242dcb462454bJohn Reckvoid BaseRenderNodeAnimator::attach(RenderNode* target) {
868d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck    mTarget = target;
878d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck    onAttached();
888d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck}
898d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck
908d8af3c1b768d590754d657a7d1242dcb462454bJohn Reckvoid BaseRenderNodeAnimator::pushStaging(TreeInfo& info) {
9168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (!mHasStartValue) {
928d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck        doSetStartValue(getValue(mTarget));
93ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette    }
9468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (mStagingPlayState > mPlayState) {
9568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        mPlayState = mStagingPlayState;
9668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        // Oh boy, we're starting! Man the battle stations!
9768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        if (mPlayState == RUNNING) {
9868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck            transitionToRunning(info);
9968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        }
10068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    }
10168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck}
102ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette
10368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reckvoid BaseRenderNodeAnimator::transitionToRunning(TreeInfo& info) {
10468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    LOG_ALWAYS_FATAL_IF(info.frameTimeMs <= 0, "%" PRId64 " isn't a real frame time!", info.frameTimeMs);
10568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (mStartDelay < 0 || mStartDelay > 50000) {
10668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        ALOGW("Your start delay is strange and confusing: %" PRId64, mStartDelay);
10768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    }
10868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    mStartTime = info.frameTimeMs + mStartDelay;
10968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (mStartTime < 0) {
11068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        ALOGW("Ended up with a really weird start time of %" PRId64
11168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck                " with frame time %" PRId64 " and start delay %" PRId64,
11268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck                mStartTime, info.frameTimeMs, mStartDelay);
11368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        // Set to 0 so that the animate() basically instantly finishes
11468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        mStartTime = 0;
11568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    }
11668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    // No interpolator was set, use the default
11768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (!mInterpolator) {
1188d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck        mInterpolator = Interpolator::createDefaultInterpolator();
11968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    }
12068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (mDuration < 0 || mDuration > 50000) {
12168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        ALOGW("Your duration is strange and confusing: %" PRId64, mDuration);
12268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    }
12368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck}
12468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
1258d8af3c1b768d590754d657a7d1242dcb462454bJohn Reckbool BaseRenderNodeAnimator::animate(TreeInfo& info) {
12668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (mPlayState < RUNNING) {
127ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette        return false;
128ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette    }
129ad2f8e334f3ef22d3e412b0660a2e1f996f94116Alan Viverette
1308d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck    // If BaseRenderNodeAnimator is handling the delay (not typical), then
1318d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck    // because the staging properties reflect the final value, we always need
1328d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck    // to call setValue even if the animation isn't yet running or is still
1338d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck    // being delayed as we need to override the staging value
13468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (mStartTime > info.frameTimeMs) {
13568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        info.out.hasAnimations |= true;
1368d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck        setValue(mTarget, mFromValue);
13768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        return false;
138e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    }
139e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
140e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    float fraction = 1.0f;
14168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (mPlayState == RUNNING && mDuration > 0) {
14268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        fraction = (float)(info.frameTimeMs - mStartTime) / mDuration;
143e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    }
14468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (fraction >= 1.0f) {
14568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        fraction = 1.0f;
14668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        mPlayState = FINISHED;
14768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    }
14868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
149e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    fraction = mInterpolator->interpolate(fraction);
1508d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck    setValue(mTarget, mFromValue + (mDeltaValue * fraction));
151e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
152e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    if (mPlayState == FINISHED) {
15352244fff29042926e21fa897ef5ab11148e35299John Reck        callOnFinishedListener(info);
154e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck        return true;
155e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    }
15668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
15768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    info.out.hasAnimations |= true;
158e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    return false;
159e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck}
160e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
161ff941dcd815021bb20d6504eb486acb1e50592c3John Reckvoid BaseRenderNodeAnimator::callOnFinishedListener(TreeInfo& info) {
16252244fff29042926e21fa897ef5ab11148e35299John Reck    if (mListener.get()) {
16352244fff29042926e21fa897ef5ab11148e35299John Reck        if (!info.animationHook) {
16452244fff29042926e21fa897ef5ab11148e35299John Reck            mListener->onAnimationFinished(this);
16552244fff29042926e21fa897ef5ab11148e35299John Reck        } else {
16652244fff29042926e21fa897ef5ab11148e35299John Reck            info.animationHook->callOnFinished(this, mListener.get());
16752244fff29042926e21fa897ef5ab11148e35299John Reck        }
16852244fff29042926e21fa897ef5ab11148e35299John Reck    }
16952244fff29042926e21fa897ef5ab11148e35299John Reck}
17052244fff29042926e21fa897ef5ab11148e35299John Reck
171e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck/************************************************************
17252244fff29042926e21fa897ef5ab11148e35299John Reck *  RenderPropertyAnimator
17352244fff29042926e21fa897ef5ab11148e35299John Reck ************************************************************/
17452244fff29042926e21fa897ef5ab11148e35299John Reck
175ff941dcd815021bb20d6504eb486acb1e50592c3John Reckstruct RenderPropertyAnimator::PropertyAccessors {
176ff941dcd815021bb20d6504eb486acb1e50592c3John Reck   RenderNode::DirtyPropertyMask dirtyMask;
177ff941dcd815021bb20d6504eb486acb1e50592c3John Reck   GetFloatProperty getter;
178ff941dcd815021bb20d6504eb486acb1e50592c3John Reck   SetFloatProperty setter;
179ff941dcd815021bb20d6504eb486acb1e50592c3John Reck};
180ff941dcd815021bb20d6504eb486acb1e50592c3John Reck
18152244fff29042926e21fa897ef5ab11148e35299John Reck// Maps RenderProperty enum to accessors
18252244fff29042926e21fa897ef5ab11148e35299John Reckconst RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY_ACCESSOR_LUT[] = {
183ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationX, &RenderProperties::setTranslationX },
184ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::TRANSLATION_Y, &RenderProperties::getTranslationY, &RenderProperties::setTranslationY },
185ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationZ, &RenderProperties::setTranslationZ },
186ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::SCALE_X, &RenderProperties::getScaleX, &RenderProperties::setScaleX },
187ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::SCALE_Y, &RenderProperties::getScaleY, &RenderProperties::setScaleY },
188ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::ROTATION, &RenderProperties::getRotation, &RenderProperties::setRotation },
189ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::ROTATION_X, &RenderProperties::getRotationX, &RenderProperties::setRotationX },
190ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::ROTATION_Y, &RenderProperties::getRotationY, &RenderProperties::setRotationY },
191ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::X, &RenderProperties::getX, &RenderProperties::setX },
192ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::Y, &RenderProperties::getY, &RenderProperties::setY },
193ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::Z, &RenderProperties::getZ, &RenderProperties::setZ },
194ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    {RenderNode::ALPHA, &RenderProperties::getAlpha, &RenderProperties::setAlpha },
19552244fff29042926e21fa897ef5ab11148e35299John Reck};
19652244fff29042926e21fa897ef5ab11148e35299John Reck
197ff941dcd815021bb20d6504eb486acb1e50592c3John ReckRenderPropertyAnimator::RenderPropertyAnimator(RenderProperty property, float finalValue)
198ff941dcd815021bb20d6504eb486acb1e50592c3John Reck        : BaseRenderNodeAnimator(finalValue)
199ff941dcd815021bb20d6504eb486acb1e50592c3John Reck        , mPropertyAccess(&(PROPERTY_ACCESSOR_LUT[property])) {
200ff941dcd815021bb20d6504eb486acb1e50592c3John Reck}
201ff941dcd815021bb20d6504eb486acb1e50592c3John Reck
2028d8af3c1b768d590754d657a7d1242dcb462454bJohn Reckvoid RenderPropertyAnimator::onAttached() {
20368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    if (!mHasStartValue
2048d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck            && mTarget->isPropertyFieldDirty(mPropertyAccess->dirtyMask)) {
2058d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck        setStartValue((mTarget->stagingProperties().*mPropertyAccess->getter)());
2068d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck    }
2078d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck}
2088d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck
2098d8af3c1b768d590754d657a7d1242dcb462454bJohn Reckvoid RenderPropertyAnimator::onStagingPlayStateChanged() {
2108d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck    if (mStagingPlayState == RUNNING) {
2118d8af3c1b768d590754d657a7d1242dcb462454bJohn Reck        (mTarget->mutateStagingProperties().*mPropertyAccess->setter)(finalValue());
212ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    }
21352244fff29042926e21fa897ef5ab11148e35299John Reck}
21452244fff29042926e21fa897ef5ab11148e35299John Reck
2152218472d23483f09341bf655d55db21dcbabc1b6John Reckuint32_t RenderPropertyAnimator::dirtyMask() {
2162218472d23483f09341bf655d55db21dcbabc1b6John Reck    return mPropertyAccess->dirtyMask;
2172218472d23483f09341bf655d55db21dcbabc1b6John Reck}
2182218472d23483f09341bf655d55db21dcbabc1b6John Reck
219ff941dcd815021bb20d6504eb486acb1e50592c3John Reckfloat RenderPropertyAnimator::getValue(RenderNode* target) const {
220ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    return (target->properties().*mPropertyAccess->getter)();
22152244fff29042926e21fa897ef5ab11148e35299John Reck}
22252244fff29042926e21fa897ef5ab11148e35299John Reck
223ff941dcd815021bb20d6504eb486acb1e50592c3John Reckvoid RenderPropertyAnimator::setValue(RenderNode* target, float value) {
224ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    (target->animatorProperties().*mPropertyAccess->setter)(value);
22552244fff29042926e21fa897ef5ab11148e35299John Reck}
22652244fff29042926e21fa897ef5ab11148e35299John Reck
22752244fff29042926e21fa897ef5ab11148e35299John Reck/************************************************************
22852244fff29042926e21fa897ef5ab11148e35299John Reck *  CanvasPropertyPrimitiveAnimator
22952244fff29042926e21fa897ef5ab11148e35299John Reck ************************************************************/
23052244fff29042926e21fa897ef5ab11148e35299John Reck
23152244fff29042926e21fa897ef5ab11148e35299John ReckCanvasPropertyPrimitiveAnimator::CanvasPropertyPrimitiveAnimator(
232ff941dcd815021bb20d6504eb486acb1e50592c3John Reck                CanvasPropertyPrimitive* property, float finalValue)
233ff941dcd815021bb20d6504eb486acb1e50592c3John Reck        : BaseRenderNodeAnimator(finalValue)
23452244fff29042926e21fa897ef5ab11148e35299John Reck        , mProperty(property) {
23552244fff29042926e21fa897ef5ab11148e35299John Reck}
23652244fff29042926e21fa897ef5ab11148e35299John Reck
237ff941dcd815021bb20d6504eb486acb1e50592c3John Reckfloat CanvasPropertyPrimitiveAnimator::getValue(RenderNode* target) const {
23852244fff29042926e21fa897ef5ab11148e35299John Reck    return mProperty->value;
23952244fff29042926e21fa897ef5ab11148e35299John Reck}
24052244fff29042926e21fa897ef5ab11148e35299John Reck
241ff941dcd815021bb20d6504eb486acb1e50592c3John Reckvoid CanvasPropertyPrimitiveAnimator::setValue(RenderNode* target, float value) {
24252244fff29042926e21fa897ef5ab11148e35299John Reck    mProperty->value = value;
24352244fff29042926e21fa897ef5ab11148e35299John Reck}
24452244fff29042926e21fa897ef5ab11148e35299John Reck
24552244fff29042926e21fa897ef5ab11148e35299John Reck/************************************************************
24652244fff29042926e21fa897ef5ab11148e35299John Reck *  CanvasPropertySkPaintAnimator
24752244fff29042926e21fa897ef5ab11148e35299John Reck ************************************************************/
24852244fff29042926e21fa897ef5ab11148e35299John Reck
24952244fff29042926e21fa897ef5ab11148e35299John ReckCanvasPropertyPaintAnimator::CanvasPropertyPaintAnimator(
250ff941dcd815021bb20d6504eb486acb1e50592c3John Reck                CanvasPropertyPaint* property, PaintField field, float finalValue)
251ff941dcd815021bb20d6504eb486acb1e50592c3John Reck        : BaseRenderNodeAnimator(finalValue)
25252244fff29042926e21fa897ef5ab11148e35299John Reck        , mProperty(property)
25352244fff29042926e21fa897ef5ab11148e35299John Reck        , mField(field) {
25452244fff29042926e21fa897ef5ab11148e35299John Reck}
25552244fff29042926e21fa897ef5ab11148e35299John Reck
256ff941dcd815021bb20d6504eb486acb1e50592c3John Reckfloat CanvasPropertyPaintAnimator::getValue(RenderNode* target) const {
25752244fff29042926e21fa897ef5ab11148e35299John Reck    switch (mField) {
25852244fff29042926e21fa897ef5ab11148e35299John Reck    case STROKE_WIDTH:
25952244fff29042926e21fa897ef5ab11148e35299John Reck        return mProperty->value.getStrokeWidth();
26052244fff29042926e21fa897ef5ab11148e35299John Reck    case ALPHA:
26152244fff29042926e21fa897ef5ab11148e35299John Reck        return mProperty->value.getAlpha();
26252244fff29042926e21fa897ef5ab11148e35299John Reck    }
26352244fff29042926e21fa897ef5ab11148e35299John Reck    LOG_ALWAYS_FATAL("Unknown field %d", (int) mField);
26452244fff29042926e21fa897ef5ab11148e35299John Reck    return -1;
26552244fff29042926e21fa897ef5ab11148e35299John Reck}
26652244fff29042926e21fa897ef5ab11148e35299John Reck
267531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reckstatic uint8_t to_uint8(float value) {
268531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reck    int c = (int) (value + .5f);
269531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reck    return static_cast<uint8_t>( c < 0 ? 0 : c > 255 ? 255 : c );
270531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reck}
271531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reck
272ff941dcd815021bb20d6504eb486acb1e50592c3John Reckvoid CanvasPropertyPaintAnimator::setValue(RenderNode* target, float value) {
27352244fff29042926e21fa897ef5ab11148e35299John Reck    switch (mField) {
27452244fff29042926e21fa897ef5ab11148e35299John Reck    case STROKE_WIDTH:
27552244fff29042926e21fa897ef5ab11148e35299John Reck        mProperty->value.setStrokeWidth(value);
27652244fff29042926e21fa897ef5ab11148e35299John Reck        return;
27752244fff29042926e21fa897ef5ab11148e35299John Reck    case ALPHA:
278531ee701ddca2d1604fcce8e5d6d8837a3f651acJohn Reck        mProperty->value.setAlpha(to_uint8(value));
27952244fff29042926e21fa897ef5ab11148e35299John Reck        return;
28052244fff29042926e21fa897ef5ab11148e35299John Reck    }
28152244fff29042926e21fa897ef5ab11148e35299John Reck    LOG_ALWAYS_FATAL("Unknown field %d", (int) mField);
282e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck}
283e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
284e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace uirenderer */
285e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace android */
286