| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/compositor/layer_animation_element.h" | 5 #include "ui/compositor/layer_animation_element.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 ~Pause() override {} | 38 ~Pause() override {} |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 void OnStart(LayerAnimationDelegate* delegate) override {} | 41 void OnStart(LayerAnimationDelegate* delegate) override {} |
| 42 bool OnProgress(double t, LayerAnimationDelegate* delegate) override { | 42 bool OnProgress(double t, LayerAnimationDelegate* delegate) override { |
| 43 return false; | 43 return false; |
| 44 } | 44 } |
| 45 void OnGetTarget(TargetValue* target) const override {} | 45 void OnGetTarget(TargetValue* target) const override {} |
| 46 void OnAbort(LayerAnimationDelegate* delegate) override {} | 46 void OnAbort(LayerAnimationDelegate* delegate) override {} |
| 47 bool AreStartAndTargetSame() override { |
| 48 return false; |
| 49 } |
| 47 | 50 |
| 48 DISALLOW_COPY_AND_ASSIGN(Pause); | 51 DISALLOW_COPY_AND_ASSIGN(Pause); |
| 49 }; | 52 }; |
| 50 | 53 |
| 51 // InterpolatedTransformTransition --------------------------------------------- | 54 // InterpolatedTransformTransition --------------------------------------------- |
| 52 | 55 |
| 53 class InterpolatedTransformTransition : public LayerAnimationElement { | 56 class InterpolatedTransformTransition : public LayerAnimationElement { |
| 54 public: | 57 public: |
| 55 InterpolatedTransformTransition(InterpolatedTransform* interpolated_transform, | 58 InterpolatedTransformTransition(InterpolatedTransform* interpolated_transform, |
| 56 base::TimeDelta duration) | 59 base::TimeDelta duration) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 67 interpolated_transform_->Interpolate(static_cast<float>(t))); | 70 interpolated_transform_->Interpolate(static_cast<float>(t))); |
| 68 return true; | 71 return true; |
| 69 } | 72 } |
| 70 | 73 |
| 71 void OnGetTarget(TargetValue* target) const override { | 74 void OnGetTarget(TargetValue* target) const override { |
| 72 target->transform = interpolated_transform_->Interpolate(1.0f); | 75 target->transform = interpolated_transform_->Interpolate(1.0f); |
| 73 } | 76 } |
| 74 | 77 |
| 75 void OnAbort(LayerAnimationDelegate* delegate) override {} | 78 void OnAbort(LayerAnimationDelegate* delegate) override {} |
| 76 | 79 |
| 80 bool AreStartAndTargetSame() override { |
| 81 return false; |
| 82 } |
| 83 |
| 77 private: | 84 private: |
| 78 std::unique_ptr<InterpolatedTransform> interpolated_transform_; | 85 std::unique_ptr<InterpolatedTransform> interpolated_transform_; |
| 79 | 86 |
| 80 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformTransition); | 87 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformTransition); |
| 81 }; | 88 }; |
| 82 | 89 |
| 83 // BoundsTransition ------------------------------------------------------------ | 90 // BoundsTransition ------------------------------------------------------------ |
| 84 | 91 |
| 85 class BoundsTransition : public LayerAnimationElement { | 92 class BoundsTransition : public LayerAnimationElement { |
| 86 public: | 93 public: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 100 gfx::Tween::RectValueBetween(t, start_, target_)); | 107 gfx::Tween::RectValueBetween(t, start_, target_)); |
| 101 return true; | 108 return true; |
| 102 } | 109 } |
| 103 | 110 |
| 104 void OnGetTarget(TargetValue* target) const override { | 111 void OnGetTarget(TargetValue* target) const override { |
| 105 target->bounds = target_; | 112 target->bounds = target_; |
| 106 } | 113 } |
| 107 | 114 |
| 108 void OnAbort(LayerAnimationDelegate* delegate) override {} | 115 void OnAbort(LayerAnimationDelegate* delegate) override {} |
| 109 | 116 |
| 117 bool AreStartAndTargetSame() override { |
| 118 return start_ == target_; |
| 119 } |
| 120 |
| 110 private: | 121 private: |
| 111 gfx::Rect start_; | 122 gfx::Rect start_; |
| 112 const gfx::Rect target_; | 123 const gfx::Rect target_; |
| 113 | 124 |
| 114 DISALLOW_COPY_AND_ASSIGN(BoundsTransition); | 125 DISALLOW_COPY_AND_ASSIGN(BoundsTransition); |
| 115 }; | 126 }; |
| 116 | 127 |
| 117 // VisibilityTransition -------------------------------------------------------- | 128 // VisibilityTransition -------------------------------------------------------- |
| 118 | 129 |
| 119 class VisibilityTransition : public LayerAnimationElement { | 130 class VisibilityTransition : public LayerAnimationElement { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 134 delegate->SetVisibilityFromAnimation(t == 1.0 ? target_ : start_); | 145 delegate->SetVisibilityFromAnimation(t == 1.0 ? target_ : start_); |
| 135 return t == 1.0; | 146 return t == 1.0; |
| 136 } | 147 } |
| 137 | 148 |
| 138 void OnGetTarget(TargetValue* target) const override { | 149 void OnGetTarget(TargetValue* target) const override { |
| 139 target->visibility = target_; | 150 target->visibility = target_; |
| 140 } | 151 } |
| 141 | 152 |
| 142 void OnAbort(LayerAnimationDelegate* delegate) override {} | 153 void OnAbort(LayerAnimationDelegate* delegate) override {} |
| 143 | 154 |
| 155 bool AreStartAndTargetSame() override { |
| 156 return start_ == target_; |
| 157 } |
| 158 |
| 144 private: | 159 private: |
| 145 bool start_; | 160 bool start_; |
| 146 const bool target_; | 161 const bool target_; |
| 147 | 162 |
| 148 DISALLOW_COPY_AND_ASSIGN(VisibilityTransition); | 163 DISALLOW_COPY_AND_ASSIGN(VisibilityTransition); |
| 149 }; | 164 }; |
| 150 | 165 |
| 151 // BrightnessTransition -------------------------------------------------------- | 166 // BrightnessTransition -------------------------------------------------------- |
| 152 | 167 |
| 153 class BrightnessTransition : public LayerAnimationElement { | 168 class BrightnessTransition : public LayerAnimationElement { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 169 gfx::Tween::FloatValueBetween(t, start_, target_)); | 184 gfx::Tween::FloatValueBetween(t, start_, target_)); |
| 170 return true; | 185 return true; |
| 171 } | 186 } |
| 172 | 187 |
| 173 void OnGetTarget(TargetValue* target) const override { | 188 void OnGetTarget(TargetValue* target) const override { |
| 174 target->brightness = target_; | 189 target->brightness = target_; |
| 175 } | 190 } |
| 176 | 191 |
| 177 void OnAbort(LayerAnimationDelegate* delegate) override {} | 192 void OnAbort(LayerAnimationDelegate* delegate) override {} |
| 178 | 193 |
| 194 bool AreStartAndTargetSame() override { |
| 195 return start_ == target_; |
| 196 } |
| 197 |
| 179 private: | 198 private: |
| 180 float start_; | 199 float start_; |
| 181 const float target_; | 200 const float target_; |
| 182 | 201 |
| 183 DISALLOW_COPY_AND_ASSIGN(BrightnessTransition); | 202 DISALLOW_COPY_AND_ASSIGN(BrightnessTransition); |
| 184 }; | 203 }; |
| 185 | 204 |
| 186 // GrayscaleTransition --------------------------------------------------------- | 205 // GrayscaleTransition --------------------------------------------------------- |
| 187 | 206 |
| 188 class GrayscaleTransition : public LayerAnimationElement { | 207 class GrayscaleTransition : public LayerAnimationElement { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 204 gfx::Tween::FloatValueBetween(t, start_, target_)); | 223 gfx::Tween::FloatValueBetween(t, start_, target_)); |
| 205 return true; | 224 return true; |
| 206 } | 225 } |
| 207 | 226 |
| 208 void OnGetTarget(TargetValue* target) const override { | 227 void OnGetTarget(TargetValue* target) const override { |
| 209 target->grayscale = target_; | 228 target->grayscale = target_; |
| 210 } | 229 } |
| 211 | 230 |
| 212 void OnAbort(LayerAnimationDelegate* delegate) override {} | 231 void OnAbort(LayerAnimationDelegate* delegate) override {} |
| 213 | 232 |
| 233 bool AreStartAndTargetSame() override { |
| 234 return start_ == target_; |
| 235 } |
| 236 |
| 214 private: | 237 private: |
| 215 float start_; | 238 float start_; |
| 216 const float target_; | 239 const float target_; |
| 217 | 240 |
| 218 DISALLOW_COPY_AND_ASSIGN(GrayscaleTransition); | 241 DISALLOW_COPY_AND_ASSIGN(GrayscaleTransition); |
| 219 }; | 242 }; |
| 220 | 243 |
| 221 // ColorTransition ------------------------------------------------------------- | 244 // ColorTransition ------------------------------------------------------------- |
| 222 | 245 |
| 223 class ColorTransition : public LayerAnimationElement { | 246 class ColorTransition : public LayerAnimationElement { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 239 gfx::Tween::ColorValueBetween(t, start_, target_)); | 262 gfx::Tween::ColorValueBetween(t, start_, target_)); |
| 240 return true; | 263 return true; |
| 241 } | 264 } |
| 242 | 265 |
| 243 void OnGetTarget(TargetValue* target) const override { | 266 void OnGetTarget(TargetValue* target) const override { |
| 244 target->color = target_; | 267 target->color = target_; |
| 245 } | 268 } |
| 246 | 269 |
| 247 void OnAbort(LayerAnimationDelegate* delegate) override {} | 270 void OnAbort(LayerAnimationDelegate* delegate) override {} |
| 248 | 271 |
| 272 bool AreStartAndTargetSame() override { |
| 273 return start_ == target_; |
| 274 } |
| 275 |
| 249 private: | 276 private: |
| 250 SkColor start_; | 277 SkColor start_; |
| 251 const SkColor target_; | 278 const SkColor target_; |
| 252 | 279 |
| 253 DISALLOW_COPY_AND_ASSIGN(ColorTransition); | 280 DISALLOW_COPY_AND_ASSIGN(ColorTransition); |
| 254 }; | 281 }; |
| 255 | 282 |
| 256 // ThreadedLayerAnimationElement ----------------------------------------------- | 283 // ThreadedLayerAnimationElement ----------------------------------------------- |
| 257 | 284 |
| 258 class ThreadedLayerAnimationElement : public LayerAnimationElement { | 285 class ThreadedLayerAnimationElement : public LayerAnimationElement { |
| 259 public: | 286 public: |
| 260 ThreadedLayerAnimationElement(AnimatableProperties properties, | 287 ThreadedLayerAnimationElement(AnimatableProperties properties, |
| 261 base::TimeDelta duration) | 288 base::TimeDelta duration) |
| 262 : LayerAnimationElement(properties, duration) { | 289 : LayerAnimationElement(properties, duration) { |
| 263 } | 290 } |
| 264 ~ThreadedLayerAnimationElement() override {} | 291 ~ThreadedLayerAnimationElement() override {} |
| 265 | 292 |
| 266 bool IsThreaded() const override { return !duration().is_zero(); } | 293 bool IsThreaded() const override { return !duration().is_zero(); } |
| 267 | 294 |
| 268 protected: | 295 protected: |
| 269 explicit ThreadedLayerAnimationElement(const LayerAnimationElement& element) | 296 explicit ThreadedLayerAnimationElement(const LayerAnimationElement& element) |
| 270 : LayerAnimationElement(element) { | 297 : LayerAnimationElement(element) { |
| 271 } | 298 } |
| 272 | 299 |
| 273 bool OnProgress(double t, LayerAnimationDelegate* delegate) override { | 300 bool OnProgress(double t, LayerAnimationDelegate* delegate) override { |
| 274 if (t < 1.0) | 301 if (t < 1.0) |
| 275 return false; | 302 return false; |
| 276 | 303 |
| 277 if (Started() && IsThreaded()) { | 304 if (Started() && IsThreaded()) { |
| 305 LOG(ERROR) << "RemoveThreadedAnimation"; |
| 278 LayerThreadedAnimationDelegate* threaded = | 306 LayerThreadedAnimationDelegate* threaded = |
| 279 delegate->GetThreadedAnimationDelegate(); | 307 delegate->GetThreadedAnimationDelegate(); |
| 280 DCHECK(threaded); | 308 DCHECK(threaded); |
| 281 threaded->RemoveThreadedAnimation(animation_id()); | 309 threaded->RemoveThreadedAnimation(animation_id()); |
| 282 } | 310 } |
| 283 | 311 |
| 284 OnEnd(delegate); | 312 OnEnd(delegate); |
| 285 return true; | 313 return true; |
| 286 } | 314 } |
| 287 | 315 |
| 288 void OnAbort(LayerAnimationDelegate* delegate) override { | 316 void OnAbort(LayerAnimationDelegate* delegate) override { |
| 289 if (delegate && Started() && IsThreaded()) { | 317 if (delegate && Started() && IsThreaded()) { |
| 290 LayerThreadedAnimationDelegate* threaded = | 318 LayerThreadedAnimationDelegate* threaded = |
| 291 delegate->GetThreadedAnimationDelegate(); | 319 delegate->GetThreadedAnimationDelegate(); |
| 292 DCHECK(threaded); | 320 DCHECK(threaded); |
| 293 threaded->RemoveThreadedAnimation(animation_id()); | 321 threaded->RemoveThreadedAnimation(animation_id()); |
| 294 } | 322 } |
| 295 } | 323 } |
| 296 | 324 |
| 297 void RequestEffectiveStart(LayerAnimationDelegate* delegate) override { | 325 void RequestEffectiveStart(LayerAnimationDelegate* delegate) override { |
| 298 DCHECK(animation_group_id()); | 326 DCHECK(animation_group_id()); |
| 299 if (!IsThreaded()) { | 327 if (!IsThreaded()) { |
| 300 set_effective_start_time(requested_start_time()); | 328 set_effective_start_time(requested_start_time()); |
| 301 return; | 329 return; |
| 302 } | 330 } |
| 303 set_effective_start_time(base::TimeTicks()); | 331 set_effective_start_time(base::TimeTicks()); |
| 304 std::unique_ptr<cc::Animation> animation = CreateCCAnimation(); | 332 std::unique_ptr<cc::Animation> animation = CreateCCAnimation(); |
| 305 animation->set_needs_synchronized_start_time(true); | 333 animation->set_needs_synchronized_start_time(true); |
| 334 LOG(ERROR) << "AddThreadedAnimation"; |
| 306 | 335 |
| 307 LayerThreadedAnimationDelegate* threaded = | 336 LayerThreadedAnimationDelegate* threaded = |
| 308 delegate->GetThreadedAnimationDelegate(); | 337 delegate->GetThreadedAnimationDelegate(); |
| 309 DCHECK(threaded); | 338 DCHECK(threaded); |
| 310 threaded->AddThreadedAnimation(std::move(animation)); | 339 threaded->AddThreadedAnimation(std::move(animation)); |
| 311 } | 340 } |
| 312 | 341 |
| 313 virtual void OnEnd(LayerAnimationDelegate* delegate) = 0; | 342 virtual void OnEnd(LayerAnimationDelegate* delegate) = 0; |
| 314 | 343 |
| 315 virtual std::unique_ptr<cc::Animation> CreateCCAnimation() = 0; | 344 virtual std::unique_ptr<cc::Animation> CreateCCAnimation() = 0; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 342 start_, | 371 start_, |
| 343 target_)); | 372 target_)); |
| 344 } | 373 } |
| 345 } | 374 } |
| 346 | 375 |
| 347 void OnEnd(LayerAnimationDelegate* delegate) override { | 376 void OnEnd(LayerAnimationDelegate* delegate) override { |
| 348 delegate->SetOpacityFromAnimation(target_); | 377 delegate->SetOpacityFromAnimation(target_); |
| 349 } | 378 } |
| 350 | 379 |
| 351 std::unique_ptr<cc::Animation> CreateCCAnimation() override { | 380 std::unique_ptr<cc::Animation> CreateCCAnimation() override { |
| 381 LOG(ERROR) << "Create Opacity CC Animation"; |
| 352 std::unique_ptr<cc::AnimationCurve> animation_curve( | 382 std::unique_ptr<cc::AnimationCurve> animation_curve( |
| 353 new FloatAnimationCurveAdapter(tween_type(), start_, target_, | 383 new FloatAnimationCurveAdapter(tween_type(), start_, target_, |
| 354 duration())); | 384 duration())); |
| 355 std::unique_ptr<cc::Animation> animation(cc::Animation::Create( | 385 std::unique_ptr<cc::Animation> animation(cc::Animation::Create( |
| 356 std::move(animation_curve), animation_id(), animation_group_id(), | 386 std::move(animation_curve), animation_id(), animation_group_id(), |
| 357 cc::TargetProperty::OPACITY)); | 387 cc::TargetProperty::OPACITY)); |
| 358 return animation; | 388 return animation; |
| 359 } | 389 } |
| 360 | 390 |
| 361 void OnGetTarget(TargetValue* target) const override { | 391 void OnGetTarget(TargetValue* target) const override { |
| 362 target->opacity = target_; | 392 target->opacity = target_; |
| 363 } | 393 } |
| 364 | 394 |
| 395 bool AreStartAndTargetSame() override { |
| 396 return start_ == target_; |
| 397 } |
| 398 |
| 365 private: | 399 private: |
| 366 float start_; | 400 float start_; |
| 367 const float target_; | 401 const float target_; |
| 368 | 402 |
| 369 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition); | 403 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition); |
| 370 }; | 404 }; |
| 371 | 405 |
| 372 // ThreadedTransformTransition ------------------------------------------------- | 406 // ThreadedTransformTransition ------------------------------------------------- |
| 373 | 407 |
| 374 class ThreadedTransformTransition : public ThreadedLayerAnimationElement { | 408 class ThreadedTransformTransition : public ThreadedLayerAnimationElement { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 std::unique_ptr<cc::Animation> animation(cc::Animation::Create( | 440 std::unique_ptr<cc::Animation> animation(cc::Animation::Create( |
| 407 std::move(animation_curve), animation_id(), animation_group_id(), | 441 std::move(animation_curve), animation_id(), animation_group_id(), |
| 408 cc::TargetProperty::TRANSFORM)); | 442 cc::TargetProperty::TRANSFORM)); |
| 409 return animation; | 443 return animation; |
| 410 } | 444 } |
| 411 | 445 |
| 412 void OnGetTarget(TargetValue* target) const override { | 446 void OnGetTarget(TargetValue* target) const override { |
| 413 target->transform = target_; | 447 target->transform = target_; |
| 414 } | 448 } |
| 415 | 449 |
| 450 bool AreStartAndTargetSame() override { |
| 451 return start_ == target_; |
| 452 } |
| 453 |
| 416 private: | 454 private: |
| 417 gfx::Transform start_; | 455 gfx::Transform start_; |
| 418 const gfx::Transform target_; | 456 const gfx::Transform target_; |
| 419 | 457 |
| 420 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); | 458 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); |
| 421 }; | 459 }; |
| 422 | 460 |
| 423 } // namespace | 461 } // namespace |
| 424 | 462 |
| 425 // LayerAnimationElement::TargetValue ------------------------------------------ | 463 // LayerAnimationElement::TargetValue ------------------------------------------ |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 510 |
| 473 LayerAnimationElement::~LayerAnimationElement() { | 511 LayerAnimationElement::~LayerAnimationElement() { |
| 474 } | 512 } |
| 475 | 513 |
| 476 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate, | 514 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate, |
| 477 int animation_group_id) { | 515 int animation_group_id) { |
| 478 DCHECK(requested_start_time_ != base::TimeTicks()); | 516 DCHECK(requested_start_time_ != base::TimeTicks()); |
| 479 DCHECK(first_frame_); | 517 DCHECK(first_frame_); |
| 480 animation_group_id_ = animation_group_id; | 518 animation_group_id_ = animation_group_id; |
| 481 last_progressed_fraction_ = 0.0; | 519 last_progressed_fraction_ = 0.0; |
| 520 |
| 482 OnStart(delegate); | 521 OnStart(delegate); |
| 522 if (AreStartAndTargetSame()) { |
| 523 ProgressToEnd(delegate); |
| 524 return; |
| 525 } |
| 526 |
| 483 RequestEffectiveStart(delegate); | 527 RequestEffectiveStart(delegate); |
| 484 first_frame_ = false; | 528 first_frame_ = false; |
| 485 } | 529 } |
| 486 | 530 |
| 487 bool LayerAnimationElement::Progress(base::TimeTicks now, | 531 bool LayerAnimationElement::Progress(base::TimeTicks now, |
| 488 LayerAnimationDelegate* delegate) { | 532 LayerAnimationDelegate* delegate) { |
| 489 DCHECK(requested_start_time_ != base::TimeTicks()); | 533 DCHECK(requested_start_time_ != base::TimeTicks()); |
| 490 DCHECK(!first_frame_); | 534 DCHECK(!first_frame_); |
| 491 | 535 |
| 492 bool need_draw; | 536 bool need_draw; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 } | 699 } |
| 656 | 700 |
| 657 // static | 701 // static |
| 658 LayerAnimationElement* LayerAnimationElement::CreateColorElement( | 702 LayerAnimationElement* LayerAnimationElement::CreateColorElement( |
| 659 SkColor color, | 703 SkColor color, |
| 660 base::TimeDelta duration) { | 704 base::TimeDelta duration) { |
| 661 return new ColorTransition(color, duration); | 705 return new ColorTransition(color, duration); |
| 662 } | 706 } |
| 663 | 707 |
| 664 } // namespace ui | 708 } // namespace ui |
| OLD | NEW |