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