John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 17 | #include "Animator.h" |
| 18 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 19 | #include <inttypes.h> |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 20 | #include <set> |
| 21 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 22 | #include "AnimationContext.h" |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 23 | #include "Interpolator.h" |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 24 | #include "RenderNode.h" |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 25 | #include "RenderProperties.h" |
| 26 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | |
| 30 | /************************************************************ |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 31 | * BaseRenderNodeAnimator |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 32 | ************************************************************/ |
| 33 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 34 | BaseRenderNodeAnimator::BaseRenderNodeAnimator(float finalValue) |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 35 | : mTarget(NULL) |
| 36 | , mFinalValue(finalValue) |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 37 | , mDeltaValue(0) |
| 38 | , mFromValue(0) |
| 39 | , mInterpolator(0) |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 40 | , mStagingPlayState(NOT_STARTED) |
| 41 | , mPlayState(NOT_STARTED) |
| 42 | , mHasStartValue(false) |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 43 | , mStartTime(0) |
Alan Viverette | ad2f8e3 | 2014-05-16 13:28:33 -0700 | [diff] [blame] | 44 | , mDuration(300) |
Chris Craik | 572d9ac | 2014-09-12 17:40:20 -0700 | [diff] [blame] | 45 | , mStartDelay(0) |
| 46 | , mMayRunAsync(true) { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 47 | } |
| 48 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 49 | BaseRenderNodeAnimator::~BaseRenderNodeAnimator() { |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 50 | delete mInterpolator; |
| 51 | } |
| 52 | |
| 53 | void BaseRenderNodeAnimator::checkMutable() { |
| 54 | // Should be impossible to hit as the Java-side also has guards for this |
| 55 | LOG_ALWAYS_FATAL_IF(mStagingPlayState != NOT_STARTED, |
| 56 | "Animator has already been started!"); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 57 | } |
| 58 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 59 | void BaseRenderNodeAnimator::setInterpolator(Interpolator* interpolator) { |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 60 | checkMutable(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 61 | delete mInterpolator; |
| 62 | mInterpolator = interpolator; |
| 63 | } |
| 64 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 65 | void BaseRenderNodeAnimator::setStartValue(float value) { |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 66 | checkMutable(); |
| 67 | doSetStartValue(value); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 68 | } |
| 69 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 70 | void BaseRenderNodeAnimator::doSetStartValue(float value) { |
| 71 | mFromValue = value; |
| 72 | mDeltaValue = (mFinalValue - mFromValue); |
| 73 | mHasStartValue = true; |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Alan Viverette | ad2f8e3 | 2014-05-16 13:28:33 -0700 | [diff] [blame] | 76 | void BaseRenderNodeAnimator::setDuration(nsecs_t duration) { |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 77 | checkMutable(); |
Alan Viverette | ad2f8e3 | 2014-05-16 13:28:33 -0700 | [diff] [blame] | 78 | mDuration = duration; |
| 79 | } |
| 80 | |
| 81 | void BaseRenderNodeAnimator::setStartDelay(nsecs_t startDelay) { |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 82 | checkMutable(); |
Alan Viverette | ad2f8e3 | 2014-05-16 13:28:33 -0700 | [diff] [blame] | 83 | mStartDelay = startDelay; |
| 84 | } |
| 85 | |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 86 | void BaseRenderNodeAnimator::attach(RenderNode* target) { |
| 87 | mTarget = target; |
| 88 | onAttached(); |
| 89 | } |
| 90 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 91 | void BaseRenderNodeAnimator::pushStaging(AnimationContext& context) { |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 92 | if (!mHasStartValue) { |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 93 | doSetStartValue(getValue(mTarget)); |
Alan Viverette | ad2f8e3 | 2014-05-16 13:28:33 -0700 | [diff] [blame] | 94 | } |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 95 | if (mStagingPlayState > mPlayState) { |
| 96 | mPlayState = mStagingPlayState; |
| 97 | // Oh boy, we're starting! Man the battle stations! |
| 98 | if (mPlayState == RUNNING) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 99 | transitionToRunning(context); |
John Reck | 4d2c472 | 2014-08-29 10:40:56 -0700 | [diff] [blame] | 100 | } else if (mPlayState == FINISHED) { |
| 101 | callOnFinishedListener(context); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 102 | } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 103 | } |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 104 | } |
| 105 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 106 | void BaseRenderNodeAnimator::transitionToRunning(AnimationContext& context) { |
| 107 | nsecs_t frameTimeMs = context.frameTimeMs(); |
| 108 | LOG_ALWAYS_FATAL_IF(frameTimeMs <= 0, "%" PRId64 " isn't a real frame time!", frameTimeMs); |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 109 | if (mStartDelay < 0 || mStartDelay > 50000) { |
| 110 | ALOGW("Your start delay is strange and confusing: %" PRId64, mStartDelay); |
| 111 | } |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 112 | mStartTime = frameTimeMs + mStartDelay; |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 113 | if (mStartTime < 0) { |
| 114 | ALOGW("Ended up with a really weird start time of %" PRId64 |
| 115 | " with frame time %" PRId64 " and start delay %" PRId64, |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 116 | mStartTime, frameTimeMs, mStartDelay); |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 117 | // Set to 0 so that the animate() basically instantly finishes |
| 118 | mStartTime = 0; |
| 119 | } |
| 120 | // No interpolator was set, use the default |
| 121 | if (!mInterpolator) { |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 122 | mInterpolator = Interpolator::createDefaultInterpolator(); |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 123 | } |
| 124 | if (mDuration < 0 || mDuration > 50000) { |
| 125 | ALOGW("Your duration is strange and confusing: %" PRId64, mDuration); |
| 126 | } |
| 127 | } |
| 128 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 129 | bool BaseRenderNodeAnimator::animate(AnimationContext& context) { |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 130 | if (mPlayState < RUNNING) { |
| 131 | return false; |
| 132 | } |
John Reck | 32fb630 | 2014-07-07 09:50:32 -0700 | [diff] [blame] | 133 | if (mPlayState == FINISHED) { |
| 134 | return true; |
| 135 | } |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 136 | |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 137 | // If BaseRenderNodeAnimator is handling the delay (not typical), then |
| 138 | // because the staging properties reflect the final value, we always need |
| 139 | // to call setValue even if the animation isn't yet running or is still |
| 140 | // being delayed as we need to override the staging value |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 141 | if (mStartTime > context.frameTimeMs()) { |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 142 | setValue(mTarget, mFromValue); |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 143 | return false; |
| 144 | } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 145 | |
| 146 | float fraction = 1.0f; |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 147 | if (mPlayState == RUNNING && mDuration > 0) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 148 | fraction = (float)(context.frameTimeMs() - mStartTime) / mDuration; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 149 | } |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 150 | if (fraction >= 1.0f) { |
| 151 | fraction = 1.0f; |
| 152 | mPlayState = FINISHED; |
| 153 | } |
| 154 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 155 | fraction = mInterpolator->interpolate(fraction); |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 156 | setValue(mTarget, mFromValue + (mDeltaValue * fraction)); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 157 | |
| 158 | if (mPlayState == FINISHED) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 159 | callOnFinishedListener(context); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 160 | return true; |
| 161 | } |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 162 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 163 | return false; |
| 164 | } |
| 165 | |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 166 | void BaseRenderNodeAnimator::forceEndNow(AnimationContext& context) { |
| 167 | if (mPlayState < FINISHED) { |
| 168 | mPlayState = FINISHED; |
| 169 | callOnFinishedListener(context); |
| 170 | } |
| 171 | } |
| 172 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 173 | void BaseRenderNodeAnimator::callOnFinishedListener(AnimationContext& context) { |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 174 | if (mListener.get()) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 175 | context.callOnFinished(this, mListener.get()); |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | /************************************************************ |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 180 | * RenderPropertyAnimator |
| 181 | ************************************************************/ |
| 182 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 183 | struct RenderPropertyAnimator::PropertyAccessors { |
| 184 | RenderNode::DirtyPropertyMask dirtyMask; |
| 185 | GetFloatProperty getter; |
| 186 | SetFloatProperty setter; |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 189 | // Maps RenderProperty enum to accessors |
| 190 | const RenderPropertyAnimator::PropertyAccessors RenderPropertyAnimator::PROPERTY_ACCESSOR_LUT[] = { |
| 191 | {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationX, &RenderProperties::setTranslationX }, |
| 192 | {RenderNode::TRANSLATION_Y, &RenderProperties::getTranslationY, &RenderProperties::setTranslationY }, |
| 193 | {RenderNode::TRANSLATION_X, &RenderProperties::getTranslationZ, &RenderProperties::setTranslationZ }, |
| 194 | {RenderNode::SCALE_X, &RenderProperties::getScaleX, &RenderProperties::setScaleX }, |
| 195 | {RenderNode::SCALE_Y, &RenderProperties::getScaleY, &RenderProperties::setScaleY }, |
| 196 | {RenderNode::ROTATION, &RenderProperties::getRotation, &RenderProperties::setRotation }, |
| 197 | {RenderNode::ROTATION_X, &RenderProperties::getRotationX, &RenderProperties::setRotationX }, |
| 198 | {RenderNode::ROTATION_Y, &RenderProperties::getRotationY, &RenderProperties::setRotationY }, |
| 199 | {RenderNode::X, &RenderProperties::getX, &RenderProperties::setX }, |
| 200 | {RenderNode::Y, &RenderProperties::getY, &RenderProperties::setY }, |
| 201 | {RenderNode::Z, &RenderProperties::getZ, &RenderProperties::setZ }, |
| 202 | {RenderNode::ALPHA, &RenderProperties::getAlpha, &RenderProperties::setAlpha }, |
| 203 | }; |
| 204 | |
| 205 | RenderPropertyAnimator::RenderPropertyAnimator(RenderProperty property, float finalValue) |
| 206 | : BaseRenderNodeAnimator(finalValue) |
| 207 | , mPropertyAccess(&(PROPERTY_ACCESSOR_LUT[property])) { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 208 | } |
| 209 | |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 210 | void RenderPropertyAnimator::onAttached() { |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 211 | if (!mHasStartValue |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 212 | && mTarget->isPropertyFieldDirty(mPropertyAccess->dirtyMask)) { |
| 213 | setStartValue((mTarget->stagingProperties().*mPropertyAccess->getter)()); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 214 | } |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void RenderPropertyAnimator::onStagingPlayStateChanged() { |
| 218 | if (mStagingPlayState == RUNNING) { |
| 219 | (mTarget->mutateStagingProperties().*mPropertyAccess->setter)(finalValue()); |
John Reck | 32fb630 | 2014-07-07 09:50:32 -0700 | [diff] [blame] | 220 | } else if (mStagingPlayState == FINISHED) { |
| 221 | // We're being canceled, so make sure that whatever values the UI thread |
| 222 | // is observing for us is pushed over |
| 223 | mTarget->setPropertyFieldsDirty(dirtyMask()); |
John Reck | 8d8af3c | 2014-07-01 15:23:45 -0700 | [diff] [blame] | 224 | } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 225 | } |
| 226 | |
John Reck | 2218472 | 2014-06-20 07:19:30 -0700 | [diff] [blame] | 227 | uint32_t RenderPropertyAnimator::dirtyMask() { |
| 228 | return mPropertyAccess->dirtyMask; |
| 229 | } |
| 230 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 231 | float RenderPropertyAnimator::getValue(RenderNode* target) const { |
| 232 | return (target->properties().*mPropertyAccess->getter)(); |
| 233 | } |
| 234 | |
| 235 | void RenderPropertyAnimator::setValue(RenderNode* target, float value) { |
| 236 | (target->animatorProperties().*mPropertyAccess->setter)(value); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 237 | } |
| 238 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 239 | /************************************************************ |
| 240 | * CanvasPropertyPrimitiveAnimator |
| 241 | ************************************************************/ |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 242 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 243 | CanvasPropertyPrimitiveAnimator::CanvasPropertyPrimitiveAnimator( |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 244 | CanvasPropertyPrimitive* property, float finalValue) |
| 245 | : BaseRenderNodeAnimator(finalValue) |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 246 | , mProperty(property) { |
| 247 | } |
| 248 | |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 249 | float CanvasPropertyPrimitiveAnimator::getValue(RenderNode* target) const { |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 250 | return mProperty->value; |
| 251 | } |
| 252 | |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 253 | void CanvasPropertyPrimitiveAnimator::setValue(RenderNode* target, float value) { |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 254 | mProperty->value = value; |
| 255 | } |
| 256 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 257 | uint32_t CanvasPropertyPrimitiveAnimator::dirtyMask() { |
| 258 | return RenderNode::DISPLAY_LIST; |
| 259 | } |
| 260 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 261 | /************************************************************ |
| 262 | * CanvasPropertySkPaintAnimator |
| 263 | ************************************************************/ |
| 264 | |
| 265 | CanvasPropertyPaintAnimator::CanvasPropertyPaintAnimator( |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 266 | CanvasPropertyPaint* property, PaintField field, float finalValue) |
| 267 | : BaseRenderNodeAnimator(finalValue) |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 268 | , mProperty(property) |
| 269 | , mField(field) { |
| 270 | } |
| 271 | |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 272 | float CanvasPropertyPaintAnimator::getValue(RenderNode* target) const { |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 273 | switch (mField) { |
| 274 | case STROKE_WIDTH: |
| 275 | return mProperty->value.getStrokeWidth(); |
| 276 | case ALPHA: |
| 277 | return mProperty->value.getAlpha(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 278 | } |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 279 | LOG_ALWAYS_FATAL("Unknown field %d", (int) mField); |
| 280 | return -1; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 281 | } |
| 282 | |
John Reck | 531ee70 | 2014-05-13 10:06:08 -0700 | [diff] [blame] | 283 | static uint8_t to_uint8(float value) { |
| 284 | int c = (int) (value + .5f); |
| 285 | return static_cast<uint8_t>( c < 0 ? 0 : c > 255 ? 255 : c ); |
| 286 | } |
| 287 | |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 288 | void CanvasPropertyPaintAnimator::setValue(RenderNode* target, float value) { |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 289 | switch (mField) { |
| 290 | case STROKE_WIDTH: |
| 291 | mProperty->value.setStrokeWidth(value); |
| 292 | return; |
| 293 | case ALPHA: |
John Reck | 531ee70 | 2014-05-13 10:06:08 -0700 | [diff] [blame] | 294 | mProperty->value.setAlpha(to_uint8(value)); |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 295 | return; |
| 296 | } |
| 297 | LOG_ALWAYS_FATAL("Unknown field %d", (int) mField); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 298 | } |
| 299 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 300 | uint32_t CanvasPropertyPaintAnimator::dirtyMask() { |
| 301 | return RenderNode::DISPLAY_LIST; |
| 302 | } |
| 303 | |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 304 | RevealAnimator::RevealAnimator(int centerX, int centerY, |
John Reck | d3de42c | 2014-07-15 14:29:33 -0700 | [diff] [blame] | 305 | float startValue, float finalValue) |
| 306 | : BaseRenderNodeAnimator(finalValue) |
| 307 | , mCenterX(centerX) |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 308 | , mCenterY(centerY) { |
John Reck | d3de42c | 2014-07-15 14:29:33 -0700 | [diff] [blame] | 309 | setStartValue(startValue); |
| 310 | } |
| 311 | |
| 312 | float RevealAnimator::getValue(RenderNode* target) const { |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 313 | return target->properties().getRevealClip().getRadius(); |
John Reck | d3de42c | 2014-07-15 14:29:33 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void RevealAnimator::setValue(RenderNode* target, float value) { |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 317 | target->animatorProperties().mutableRevealClip().set(true, |
John Reck | d3de42c | 2014-07-15 14:29:33 -0700 | [diff] [blame] | 318 | mCenterX, mCenterY, value); |
| 319 | } |
| 320 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 321 | uint32_t RevealAnimator::dirtyMask() { |
| 322 | return RenderNode::GENERIC; |
| 323 | } |
| 324 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 325 | } /* namespace uirenderer */ |
| 326 | } /* namespace android */ |