OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "cc/animation/animation_curve.h" | 9 #include "cc/animation/animation_curve.h" |
10 #include "cc/animation/layer_animation_controller.h" | 10 #include "cc/animation/layer_animation_controller.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); | 129 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); |
130 } | 130 } |
131 | 131 |
132 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 132 void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
133 bool has_unfinished_animation) override { | 133 bool has_unfinished_animation) override { |
134 EXPECT_FALSE(has_unfinished_animation); | 134 EXPECT_FALSE(has_unfinished_animation); |
135 update_animation_state_was_called_ = true; | 135 update_animation_state_was_called_ = true; |
136 } | 136 } |
137 | 137 |
138 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 138 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
139 Animation::TargetProperty target_property, | 139 TargetProperty::Type target_property, |
140 int group) override { | 140 int group) override { |
141 EXPECT_LT(base::TimeTicks(), monotonic_time); | 141 EXPECT_LT(base::TimeTicks(), monotonic_time); |
142 | 142 |
143 LayerAnimationController* controller = | 143 LayerAnimationController* controller = |
144 layer_tree_host()->root_layer()->layer_animation_controller(); | 144 layer_tree_host()->root_layer()->layer_animation_controller(); |
145 Animation* animation = controller->GetAnimation(Animation::OPACITY); | 145 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); |
146 if (animation) | 146 if (animation) |
147 controller->RemoveAnimation(animation->id()); | 147 controller->RemoveAnimation(animation->id()); |
148 | 148 |
149 EndTest(); | 149 EndTest(); |
150 } | 150 } |
151 | 151 |
152 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } | 152 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } |
153 | 153 |
154 private: | 154 private: |
155 bool update_animation_state_was_called_; | 155 bool update_animation_state_was_called_; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 if (!started_animating_ && have_animations) { | 213 if (!started_animating_ && have_animations) { |
214 started_animating_ = true; | 214 started_animating_ = true; |
215 return; | 215 return; |
216 } | 216 } |
217 | 217 |
218 if (started_animating_ && !have_animations) | 218 if (started_animating_ && !have_animations) |
219 EndTest(); | 219 EndTest(); |
220 } | 220 } |
221 | 221 |
222 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 222 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
223 Animation::TargetProperty target_property, | 223 TargetProperty::Type target_property, |
224 int group) override { | 224 int group) override { |
225 // Animations on the impl-side controller only get deleted during a commit, | 225 // Animations on the impl-side controller only get deleted during a commit, |
226 // so we need to schedule a commit. | 226 // so we need to schedule a commit. |
227 layer_tree_host()->SetNeedsCommit(); | 227 layer_tree_host()->SetNeedsCommit(); |
228 } | 228 } |
229 | 229 |
230 void AfterTest() override {} | 230 void AfterTest() override {} |
231 | 231 |
232 private: | 232 private: |
233 bool started_animating_; | 233 bool started_animating_; |
(...skipping 17 matching lines...) Expand all Loading... |
251 | 251 |
252 void AnimateLayers(LayerTreeHostImpl* host_impl, | 252 void AnimateLayers(LayerTreeHostImpl* host_impl, |
253 base::TimeTicks monotonic_time) override { | 253 base::TimeTicks monotonic_time) override { |
254 // TODO(ajuma): This test only checks the active tree. Add checks for | 254 // TODO(ajuma): This test only checks the active tree. Add checks for |
255 // pending tree too. | 255 // pending tree too. |
256 if (!host_impl->active_tree()->root_layer()) | 256 if (!host_impl->active_tree()->root_layer()) |
257 return; | 257 return; |
258 LayerAnimationController* controller_impl = | 258 LayerAnimationController* controller_impl = |
259 host_impl->active_tree()->root_layer()->children()[0]-> | 259 host_impl->active_tree()->root_layer()->children()[0]-> |
260 layer_animation_controller(); | 260 layer_animation_controller(); |
261 Animation* animation = controller_impl->GetAnimation(Animation::OPACITY); | 261 Animation* animation = |
| 262 controller_impl->GetAnimation(TargetProperty::OPACITY); |
262 if (!animation) | 263 if (!animation) |
263 return; | 264 return; |
264 | 265 |
265 const FloatAnimationCurve* curve = | 266 const FloatAnimationCurve* curve = |
266 animation->curve()->ToFloatAnimationCurve(); | 267 animation->curve()->ToFloatAnimationCurve(); |
267 float start_opacity = curve->GetValue(base::TimeDelta()); | 268 float start_opacity = curve->GetValue(base::TimeDelta()); |
268 float end_opacity = curve->GetValue(curve->Duration()); | 269 float end_opacity = curve->GetValue(curve->Duration()); |
269 float linearly_interpolated_opacity = | 270 float linearly_interpolated_opacity = |
270 0.25f * end_opacity + 0.75f * start_opacity; | 271 0.25f * end_opacity + 0.75f * start_opacity; |
271 base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f); | 272 base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f); |
(...skipping 24 matching lines...) Expand all Loading... |
296 picture_ = FakePictureLayer::Create(layer_settings(), &client_); | 297 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
297 picture_->SetBounds(gfx::Size(4, 4)); | 298 picture_->SetBounds(gfx::Size(4, 4)); |
298 client_.set_bounds(picture_->bounds()); | 299 client_.set_bounds(picture_->bounds()); |
299 picture_->set_layer_animation_delegate(this); | 300 picture_->set_layer_animation_delegate(this); |
300 layer_tree_host()->root_layer()->AddChild(picture_); | 301 layer_tree_host()->root_layer()->AddChild(picture_); |
301 } | 302 } |
302 | 303 |
303 void BeginTest() override { PostAddAnimationToMainThread(picture_.get()); } | 304 void BeginTest() override { PostAddAnimationToMainThread(picture_.get()); } |
304 | 305 |
305 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 306 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
306 Animation::TargetProperty target_property, | 307 TargetProperty::Type target_property, |
307 int group) override { | 308 int group) override { |
308 LayerAnimationController* controller = | 309 LayerAnimationController* controller = |
309 layer_tree_host()->root_layer()->children()[0]-> | 310 layer_tree_host()->root_layer()->children()[0]-> |
310 layer_animation_controller(); | 311 layer_animation_controller(); |
311 Animation* animation = controller->GetAnimation(Animation::OPACITY); | 312 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); |
312 main_start_time_ = animation->start_time(); | 313 main_start_time_ = animation->start_time(); |
313 controller->RemoveAnimation(animation->id()); | 314 controller->RemoveAnimation(animation->id()); |
314 EndTest(); | 315 EndTest(); |
315 } | 316 } |
316 | 317 |
317 void UpdateAnimationState(LayerTreeHostImpl* impl_host, | 318 void UpdateAnimationState(LayerTreeHostImpl* impl_host, |
318 bool has_unfinished_animation) override { | 319 bool has_unfinished_animation) override { |
319 LayerAnimationController* controller = | 320 LayerAnimationController* controller = |
320 impl_host->active_tree()->root_layer()->children()[0]-> | 321 impl_host->active_tree()->root_layer()->children()[0]-> |
321 layer_animation_controller(); | 322 layer_animation_controller(); |
322 Animation* animation = controller->GetAnimation(Animation::OPACITY); | 323 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); |
323 if (!animation) | 324 if (!animation) |
324 return; | 325 return; |
325 | 326 |
326 impl_start_time_ = animation->start_time(); | 327 impl_start_time_ = animation->start_time(); |
327 } | 328 } |
328 | 329 |
329 void AfterTest() override { | 330 void AfterTest() override { |
330 EXPECT_EQ(impl_start_time_, main_start_time_); | 331 EXPECT_EQ(impl_start_time_, main_start_time_); |
331 EXPECT_LT(base::TimeTicks(), impl_start_time_); | 332 EXPECT_LT(base::TimeTicks(), impl_start_time_); |
332 } | 333 } |
(...skipping 10 matching lines...) Expand all Loading... |
343 | 344 |
344 // Ensures that notify animation finished is called. | 345 // Ensures that notify animation finished is called. |
345 class LayerTreeHostAnimationTestAnimationFinishedEvents | 346 class LayerTreeHostAnimationTestAnimationFinishedEvents |
346 : public LayerTreeHostAnimationTest { | 347 : public LayerTreeHostAnimationTest { |
347 public: | 348 public: |
348 void BeginTest() override { | 349 void BeginTest() override { |
349 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); | 350 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); |
350 } | 351 } |
351 | 352 |
352 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 353 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
353 Animation::TargetProperty target_property, | 354 TargetProperty::Type target_property, |
354 int group) override { | 355 int group) override { |
355 LayerAnimationController* controller = | 356 LayerAnimationController* controller = |
356 layer_tree_host()->root_layer()->layer_animation_controller(); | 357 layer_tree_host()->root_layer()->layer_animation_controller(); |
357 Animation* animation = controller->GetAnimation(Animation::OPACITY); | 358 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); |
358 if (animation) | 359 if (animation) |
359 controller->RemoveAnimation(animation->id()); | 360 controller->RemoveAnimation(animation->id()); |
360 EndTest(); | 361 EndTest(); |
361 } | 362 } |
362 | 363 |
363 void AfterTest() override {} | 364 void AfterTest() override {} |
364 }; | 365 }; |
365 | 366 |
366 SINGLE_AND_MULTI_THREAD_TEST_F( | 367 SINGLE_AND_MULTI_THREAD_TEST_F( |
367 LayerTreeHostAnimationTestAnimationFinishedEvents); | 368 LayerTreeHostAnimationTestAnimationFinishedEvents); |
(...skipping 15 matching lines...) Expand all Loading... |
383 } | 384 } |
384 | 385 |
385 void BeginTest() override { | 386 void BeginTest() override { |
386 PostAddAnimationToMainThread(update_check_layer_.get()); | 387 PostAddAnimationToMainThread(update_check_layer_.get()); |
387 } | 388 } |
388 | 389 |
389 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 390 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
390 LayerAnimationController* controller_impl = | 391 LayerAnimationController* controller_impl = |
391 host_impl->active_tree()->root_layer()->layer_animation_controller(); | 392 host_impl->active_tree()->root_layer()->layer_animation_controller(); |
392 Animation* animation_impl = | 393 Animation* animation_impl = |
393 controller_impl->GetAnimation(Animation::OPACITY); | 394 controller_impl->GetAnimation(TargetProperty::OPACITY); |
394 controller_impl->RemoveAnimation(animation_impl->id()); | 395 controller_impl->RemoveAnimation(animation_impl->id()); |
395 EndTest(); | 396 EndTest(); |
396 } | 397 } |
397 | 398 |
398 void AfterTest() override { | 399 void AfterTest() override { |
399 // Update() should have been called once, proving that the layer was not | 400 // Update() should have been called once, proving that the layer was not |
400 // skipped. | 401 // skipped. |
401 EXPECT_EQ(1, update_check_layer_->update_count()); | 402 EXPECT_EQ(1, update_check_layer_->update_count()); |
402 | 403 |
403 // clear update_check_layer_ so LayerTreeHost dies. | 404 // clear update_check_layer_ so LayerTreeHost dies. |
(...skipping 16 matching lines...) Expand all Loading... |
420 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 421 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
421 | 422 |
422 void DidCommit() override { | 423 void DidCommit() override { |
423 if (layer_tree_host()->source_frame_number() == 1) { | 424 if (layer_tree_host()->source_frame_number() == 1) { |
424 scoped_refptr<Layer> layer = Layer::Create(layer_settings()); | 425 scoped_refptr<Layer> layer = Layer::Create(layer_settings()); |
425 layer->set_layer_animation_delegate(this); | 426 layer->set_layer_animation_delegate(this); |
426 | 427 |
427 // Any valid AnimationCurve will do here. | 428 // Any valid AnimationCurve will do here. |
428 scoped_ptr<AnimationCurve> curve(new FakeFloatAnimationCurve()); | 429 scoped_ptr<AnimationCurve> curve(new FakeFloatAnimationCurve()); |
429 scoped_ptr<Animation> animation( | 430 scoped_ptr<Animation> animation( |
430 Animation::Create(std::move(curve), 1, 1, Animation::OPACITY)); | 431 Animation::Create(std::move(curve), 1, 1, TargetProperty::OPACITY)); |
431 layer->layer_animation_controller()->AddAnimation(std::move(animation)); | 432 layer->layer_animation_controller()->AddAnimation(std::move(animation)); |
432 | 433 |
433 // We add the animation *before* attaching the layer to the tree. | 434 // We add the animation *before* attaching the layer to the tree. |
434 layer_tree_host()->root_layer()->AddChild(layer); | 435 layer_tree_host()->root_layer()->AddChild(layer); |
435 } | 436 } |
436 } | 437 } |
437 | 438 |
438 void AnimateLayers(LayerTreeHostImpl* impl_host, | 439 void AnimateLayers(LayerTreeHostImpl* impl_host, |
439 base::TimeTicks monotonic_time) override { | 440 base::TimeTicks monotonic_time) override { |
440 EndTest(); | 441 EndTest(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 AddOpacityTransitionToLayer(picture_.get(), 0.1, 0.2f, 0.8f, false); | 610 AddOpacityTransitionToLayer(picture_.get(), 0.1, 0.2f, 0.8f, false); |
610 break; | 611 break; |
611 case 2: | 612 case 2: |
612 // This second animation will not be drawn so it should not start. | 613 // This second animation will not be drawn so it should not start. |
613 AddAnimatedTransformToLayer(picture_.get(), 0.1, 5, 5); | 614 AddAnimatedTransformToLayer(picture_.get(), 0.1, 5, 5); |
614 break; | 615 break; |
615 } | 616 } |
616 } | 617 } |
617 | 618 |
618 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 619 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
619 Animation::TargetProperty target_property, | 620 TargetProperty::Type target_property, |
620 int group) override { | 621 int group) override { |
621 if (TestEnded()) | 622 if (TestEnded()) |
622 return; | 623 return; |
623 started_times_++; | 624 started_times_++; |
624 } | 625 } |
625 | 626 |
626 void AfterTest() override { | 627 void AfterTest() override { |
627 // Make sure we tried to draw the second animation but failed. | 628 // Make sure we tried to draw the second animation but failed. |
628 EXPECT_LT(0, prevented_draw_); | 629 EXPECT_LT(0, prevented_draw_); |
629 // The first animation should be started, but the second should not because | 630 // The first animation should be started, but the second should not because |
(...skipping 30 matching lines...) Expand all Loading... |
660 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 661 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
661 | 662 |
662 void DidCommit() override { | 663 void DidCommit() override { |
663 switch (layer_tree_host()->source_frame_number()) { | 664 switch (layer_tree_host()->source_frame_number()) { |
664 case 1: { | 665 case 1: { |
665 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 666 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
666 ScrollOffsetAnimationCurve::Create( | 667 ScrollOffsetAnimationCurve::Create( |
667 gfx::ScrollOffset(500.f, 550.f), | 668 gfx::ScrollOffset(500.f, 550.f), |
668 EaseInOutTimingFunction::Create())); | 669 EaseInOutTimingFunction::Create())); |
669 scoped_ptr<Animation> animation(Animation::Create( | 670 scoped_ptr<Animation> animation(Animation::Create( |
670 std::move(curve), 1, 0, Animation::SCROLL_OFFSET)); | 671 std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
671 animation->set_needs_synchronized_start_time(true); | 672 animation->set_needs_synchronized_start_time(true); |
672 bool animation_added = | 673 bool animation_added = |
673 scroll_layer_->AddAnimation(std::move(animation)); | 674 scroll_layer_->AddAnimation(std::move(animation)); |
674 bool impl_scrolling_supported = | 675 bool impl_scrolling_supported = |
675 layer_tree_host()->proxy()->SupportsImplScrolling(); | 676 layer_tree_host()->proxy()->SupportsImplScrolling(); |
676 EXPECT_EQ(impl_scrolling_supported, animation_added); | 677 EXPECT_EQ(impl_scrolling_supported, animation_added); |
677 if (!impl_scrolling_supported) | 678 if (!impl_scrolling_supported) |
678 EndTest(); | 679 EndTest(); |
679 break; | 680 break; |
680 } | 681 } |
(...skipping 30 matching lines...) Expand all Loading... |
711 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); | 712 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
712 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); | 713 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
713 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); | 714 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); |
714 client_.set_bounds(scroll_layer_->bounds()); | 715 client_.set_bounds(scroll_layer_->bounds()); |
715 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); | 716 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); |
716 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 717 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
717 | 718 |
718 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 719 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
719 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), | 720 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), |
720 EaseInOutTimingFunction::Create())); | 721 EaseInOutTimingFunction::Create())); |
721 scoped_ptr<Animation> animation( | 722 scoped_ptr<Animation> animation(Animation::Create( |
722 Animation::Create(std::move(curve), 1, 0, Animation::SCROLL_OFFSET)); | 723 std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
723 animation->set_needs_synchronized_start_time(true); | 724 animation->set_needs_synchronized_start_time(true); |
724 scroll_layer_->AddAnimation(std::move(animation)); | 725 scroll_layer_->AddAnimation(std::move(animation)); |
725 } | 726 } |
726 | 727 |
727 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 728 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
728 | 729 |
729 void BeginMainFrame(const BeginFrameArgs& args) override { | 730 void BeginMainFrame(const BeginFrameArgs& args) override { |
730 switch (layer_tree_host()->source_frame_number()) { | 731 switch (layer_tree_host()->source_frame_number()) { |
731 case 0: | 732 case 0: |
732 break; | 733 break; |
733 case 1: { | 734 case 1: { |
734 Animation* animation = | 735 Animation* animation = |
735 scroll_layer_->layer_animation_controller()->GetAnimation( | 736 scroll_layer_->layer_animation_controller()->GetAnimation( |
736 Animation::SCROLL_OFFSET); | 737 TargetProperty::SCROLL_OFFSET); |
737 scroll_layer_->layer_animation_controller()->RemoveAnimation( | 738 scroll_layer_->layer_animation_controller()->RemoveAnimation( |
738 animation->id()); | 739 animation->id()); |
739 scroll_layer_->SetScrollOffset(final_postion_); | 740 scroll_layer_->SetScrollOffset(final_postion_); |
740 break; | 741 break; |
741 } | 742 } |
742 default: | 743 default: |
743 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); | 744 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
744 } | 745 } |
745 } | 746 } |
746 | 747 |
747 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { | 748 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
748 host_impl->BlockNotifyReadyToActivateForTesting(true); | 749 host_impl->BlockNotifyReadyToActivateForTesting(true); |
749 } | 750 } |
750 | 751 |
751 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, | 752 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, |
752 const BeginFrameArgs& args) override { | 753 const BeginFrameArgs& args) override { |
753 if (!host_impl->pending_tree()) | 754 if (!host_impl->pending_tree()) |
754 return; | 755 return; |
755 | 756 |
756 if (!host_impl->active_tree()->root_layer()) { | 757 if (!host_impl->active_tree()->root_layer()) { |
757 host_impl->BlockNotifyReadyToActivateForTesting(false); | 758 host_impl->BlockNotifyReadyToActivateForTesting(false); |
758 return; | 759 return; |
759 } | 760 } |
760 | 761 |
761 LayerImpl* scroll_layer_impl = | 762 LayerImpl* scroll_layer_impl = |
762 host_impl->active_tree()->root_layer()->children()[0].get(); | 763 host_impl->active_tree()->root_layer()->children()[0].get(); |
763 Animation* animation = | 764 Animation* animation = |
764 scroll_layer_impl->layer_animation_controller()->GetAnimation( | 765 scroll_layer_impl->layer_animation_controller()->GetAnimation( |
765 Animation::SCROLL_OFFSET); | 766 TargetProperty::SCROLL_OFFSET); |
766 | 767 |
767 if (!animation || animation->run_state() != Animation::RUNNING) { | 768 if (!animation || animation->run_state() != Animation::RUNNING) { |
768 host_impl->BlockNotifyReadyToActivateForTesting(false); | 769 host_impl->BlockNotifyReadyToActivateForTesting(false); |
769 return; | 770 return; |
770 } | 771 } |
771 | 772 |
772 // Block activation until the running animation has a chance to produce a | 773 // Block activation until the running animation has a chance to produce a |
773 // scroll delta. | 774 // scroll delta. |
774 gfx::Vector2dF scroll_delta = scroll_layer_impl->ScrollDelta(); | 775 gfx::Vector2dF scroll_delta = scroll_layer_impl->ScrollDelta(); |
775 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) | 776 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 if (frame_count_with_pending_tree_ == 2) { | 858 if (frame_count_with_pending_tree_ == 2) { |
858 host_impl->BlockNotifyReadyToActivateForTesting(false); | 859 host_impl->BlockNotifyReadyToActivateForTesting(false); |
859 } | 860 } |
860 } | 861 } |
861 | 862 |
862 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 863 void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
863 bool has_unfinished_animation) override { | 864 bool has_unfinished_animation) override { |
864 LayerAnimationController* root_controller_impl = | 865 LayerAnimationController* root_controller_impl = |
865 host_impl->active_tree()->root_layer()->layer_animation_controller(); | 866 host_impl->active_tree()->root_layer()->layer_animation_controller(); |
866 Animation* root_animation = | 867 Animation* root_animation = |
867 root_controller_impl->GetAnimation(Animation::OPACITY); | 868 root_controller_impl->GetAnimation(TargetProperty::OPACITY); |
868 if (!root_animation || root_animation->run_state() != Animation::RUNNING) | 869 if (!root_animation || root_animation->run_state() != Animation::RUNNING) |
869 return; | 870 return; |
870 | 871 |
871 LayerAnimationController* child_controller_impl = | 872 LayerAnimationController* child_controller_impl = |
872 host_impl->active_tree()->root_layer()->children() | 873 host_impl->active_tree()->root_layer()->children() |
873 [0]->layer_animation_controller(); | 874 [0]->layer_animation_controller(); |
874 Animation* child_animation = | 875 Animation* child_animation = |
875 child_controller_impl->GetAnimation(Animation::OPACITY); | 876 child_controller_impl->GetAnimation(TargetProperty::OPACITY); |
876 EXPECT_EQ(Animation::RUNNING, child_animation->run_state()); | 877 EXPECT_EQ(Animation::RUNNING, child_animation->run_state()); |
877 EXPECT_EQ(root_animation->start_time(), child_animation->start_time()); | 878 EXPECT_EQ(root_animation->start_time(), child_animation->start_time()); |
878 root_controller_impl->AbortAnimations(Animation::OPACITY); | 879 root_controller_impl->AbortAnimations(TargetProperty::OPACITY); |
879 root_controller_impl->AbortAnimations(Animation::TRANSFORM); | 880 root_controller_impl->AbortAnimations(TargetProperty::TRANSFORM); |
880 child_controller_impl->AbortAnimations(Animation::OPACITY); | 881 child_controller_impl->AbortAnimations(TargetProperty::OPACITY); |
881 EndTest(); | 882 EndTest(); |
882 } | 883 } |
883 | 884 |
884 void AfterTest() override {} | 885 void AfterTest() override {} |
885 | 886 |
886 private: | 887 private: |
887 int frame_count_with_pending_tree_; | 888 int frame_count_with_pending_tree_; |
888 }; | 889 }; |
889 | 890 |
890 // This test blocks activation which is not supported for single thread mode. | 891 // This test blocks activation which is not supported for single thread mode. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 | 926 |
926 // After checking this on the sync tree, we will activate, which will cause | 927 // After checking this on the sync tree, we will activate, which will cause |
927 // PrepareTiles to happen again (which races with the test exiting). | 928 // PrepareTiles to happen again (which races with the test exiting). |
928 if (TestEnded()) | 929 if (TestEnded()) |
929 return; | 930 return; |
930 | 931 |
931 LayerImpl* root = host_impl->sync_tree()->root_layer(); | 932 LayerImpl* root = host_impl->sync_tree()->root_layer(); |
932 LayerImpl* child = root->children()[0].get(); | 933 LayerImpl* child = root->children()[0].get(); |
933 LayerAnimationController* controller_impl = | 934 LayerAnimationController* controller_impl = |
934 child->layer_animation_controller(); | 935 child->layer_animation_controller(); |
935 Animation* animation = controller_impl->GetAnimation(Animation::TRANSFORM); | 936 Animation* animation = |
| 937 controller_impl->GetAnimation(TargetProperty::TRANSFORM); |
936 | 938 |
937 // The animation should be starting for the first frame. | 939 // The animation should be starting for the first frame. |
938 EXPECT_EQ(Animation::STARTING, animation->run_state()); | 940 EXPECT_EQ(Animation::STARTING, animation->run_state()); |
939 | 941 |
940 // And the transform should be propogated to the sync tree layer, at its | 942 // And the transform should be propogated to the sync tree layer, at its |
941 // starting state which is 6,7. | 943 // starting state which is 6,7. |
942 gfx::Transform expected_transform; | 944 gfx::Transform expected_transform; |
943 expected_transform.Translate(6.0, 7.0); | 945 expected_transform.Translate(6.0, 7.0); |
944 EXPECT_EQ(expected_transform, child->DrawTransform()); | 946 EXPECT_EQ(expected_transform, child->DrawTransform()); |
945 // And the sync tree layer should know it is animating. | 947 // And the sync tree layer should know it is animating. |
946 EXPECT_TRUE(child->screen_space_transform_is_animating()); | 948 EXPECT_TRUE(child->screen_space_transform_is_animating()); |
947 | 949 |
948 controller_impl->AbortAnimations(Animation::TRANSFORM); | 950 controller_impl->AbortAnimations(TargetProperty::TRANSFORM); |
949 EndTest(); | 951 EndTest(); |
950 } | 952 } |
951 | 953 |
952 void AfterTest() override {} | 954 void AfterTest() override {} |
953 | 955 |
954 FakeContentLayerClient client_; | 956 FakeContentLayerClient client_; |
955 scoped_refptr<Layer> layer_; | 957 scoped_refptr<Layer> layer_; |
956 }; | 958 }; |
957 | 959 |
958 SINGLE_AND_MULTI_THREAD_TEST_F( | 960 SINGLE_AND_MULTI_THREAD_TEST_F( |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 // start times. | 1041 // start times. |
1040 if (host_impl->active_tree()->source_frame_number() < 2) | 1042 if (host_impl->active_tree()->source_frame_number() < 2) |
1041 return; | 1043 return; |
1042 AnimationRegistrar::AnimationControllerMap controllers_copy = | 1044 AnimationRegistrar::AnimationControllerMap controllers_copy = |
1043 host_impl->animation_registrar() | 1045 host_impl->animation_registrar() |
1044 ->active_animation_controllers_for_testing(); | 1046 ->active_animation_controllers_for_testing(); |
1045 EXPECT_EQ(2u, controllers_copy.size()); | 1047 EXPECT_EQ(2u, controllers_copy.size()); |
1046 for (auto& it : controllers_copy) { | 1048 for (auto& it : controllers_copy) { |
1047 int id = it.first; | 1049 int id = it.first; |
1048 if (id == host_impl->RootLayer()->id()) { | 1050 if (id == host_impl->RootLayer()->id()) { |
1049 Animation* anim = it.second->GetAnimation(Animation::TRANSFORM); | 1051 Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); |
1050 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1052 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
1051 } else if (id == host_impl->RootLayer()->children()[0]->id()) { | 1053 } else if (id == host_impl->RootLayer()->children()[0]->id()) { |
1052 Animation* anim = it.second->GetAnimation(Animation::OPACITY); | 1054 Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); |
1053 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1055 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
1054 } | 1056 } |
1055 EndTest(); | 1057 EndTest(); |
1056 } | 1058 } |
1057 } | 1059 } |
1058 | 1060 |
1059 void AfterTest() override {} | 1061 void AfterTest() override {} |
1060 | 1062 |
1061 private: | 1063 private: |
1062 scoped_refptr<Layer> layer_; | 1064 scoped_refptr<Layer> layer_; |
(...skipping 16 matching lines...) Expand all Loading... |
1079 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1081 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1080 | 1082 |
1081 void DidCommit() override { | 1083 void DidCommit() override { |
1082 switch (layer_tree_host()->source_frame_number()) { | 1084 switch (layer_tree_host()->source_frame_number()) { |
1083 case 1: | 1085 case 1: |
1084 AddAnimatedTransformToLayer(layer_.get(), 1.0, 5, 5); | 1086 AddAnimatedTransformToLayer(layer_.get(), 1.0, 5, 5); |
1085 break; | 1087 break; |
1086 case 2: | 1088 case 2: |
1087 LayerAnimationController* controller = | 1089 LayerAnimationController* controller = |
1088 layer_->layer_animation_controller(); | 1090 layer_->layer_animation_controller(); |
1089 Animation* animation = controller->GetAnimation(Animation::TRANSFORM); | 1091 Animation* animation = |
| 1092 controller->GetAnimation(TargetProperty::TRANSFORM); |
1090 layer_->RemoveAnimation(animation->id()); | 1093 layer_->RemoveAnimation(animation->id()); |
1091 gfx::Transform transform; | 1094 gfx::Transform transform; |
1092 transform.Translate(10.f, 10.f); | 1095 transform.Translate(10.f, 10.f); |
1093 layer_->SetTransform(transform); | 1096 layer_->SetTransform(transform); |
1094 | 1097 |
1095 // Do something that causes property trees to get rebuilt. This is | 1098 // Do something that causes property trees to get rebuilt. This is |
1096 // intended to simulate the conditions that caused the bug whose fix | 1099 // intended to simulate the conditions that caused the bug whose fix |
1097 // this is testing (the test will pass without it but won't test what | 1100 // this is testing (the test will pass without it but won't test what |
1098 // we want it to). We were updating the wrong transform node at the end | 1101 // we want it to). We were updating the wrong transform node at the end |
1099 // of an animation (we were assuming the layer with the finished | 1102 // of an animation (we were assuming the layer with the finished |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1158 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1156 | 1159 |
1157 void DidCommit() override { | 1160 void DidCommit() override { |
1158 switch (layer_tree_host()->source_frame_number()) { | 1161 switch (layer_tree_host()->source_frame_number()) { |
1159 case 1: | 1162 case 1: |
1160 AddAnimatedTransformToLayer(layer_.get(), 1.0, 5, 5); | 1163 AddAnimatedTransformToLayer(layer_.get(), 1.0, 5, 5); |
1161 break; | 1164 break; |
1162 case 2: | 1165 case 2: |
1163 LayerAnimationController* controller = | 1166 LayerAnimationController* controller = |
1164 layer_->layer_animation_controller(); | 1167 layer_->layer_animation_controller(); |
1165 Animation* animation = controller->GetAnimation(Animation::TRANSFORM); | 1168 Animation* animation = |
| 1169 controller->GetAnimation(TargetProperty::TRANSFORM); |
1166 layer_->RemoveAnimation(animation->id()); | 1170 layer_->RemoveAnimation(animation->id()); |
1167 break; | 1171 break; |
1168 } | 1172 } |
1169 } | 1173 } |
1170 | 1174 |
1171 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1175 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
1172 LayerImpl* root = host_impl->sync_tree()->root_layer(); | 1176 LayerImpl* root = host_impl->sync_tree()->root_layer(); |
1173 LayerImpl* child = root->children()[0].get(); | 1177 LayerImpl* child = root->children()[0].get(); |
1174 switch (host_impl->sync_tree()->source_frame_number()) { | 1178 switch (host_impl->sync_tree()->source_frame_number()) { |
1175 case 0: | 1179 case 0: |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 client_.set_bounds(picture_->bounds()); | 1307 client_.set_bounds(picture_->bounds()); |
1304 picture_->set_layer_animation_delegate(this); | 1308 picture_->set_layer_animation_delegate(this); |
1305 layer_tree_host()->root_layer()->AddChild(picture_); | 1309 layer_tree_host()->root_layer()->AddChild(picture_); |
1306 } | 1310 } |
1307 | 1311 |
1308 void BeginTest() override { | 1312 void BeginTest() override { |
1309 PostAddLongAnimationToMainThread(picture_.get()); | 1313 PostAddLongAnimationToMainThread(picture_.get()); |
1310 } | 1314 } |
1311 | 1315 |
1312 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 1316 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
1313 Animation::TargetProperty target_property, | 1317 TargetProperty::Type target_property, |
1314 int group) override { | 1318 int group) override { |
1315 called_animation_started_ = true; | 1319 called_animation_started_ = true; |
1316 layer_tree_host()->AnimateLayers(base::TimeTicks::FromInternalValue( | 1320 layer_tree_host()->AnimateLayers(base::TimeTicks::FromInternalValue( |
1317 std::numeric_limits<int64_t>::max())); | 1321 std::numeric_limits<int64_t>::max())); |
1318 PostSetNeedsCommitToMainThread(); | 1322 PostSetNeedsCommitToMainThread(); |
1319 } | 1323 } |
1320 | 1324 |
1321 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 1325 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
1322 Animation::TargetProperty target_property, | 1326 TargetProperty::Type target_property, |
1323 int group) override { | 1327 int group) override { |
1324 called_animation_finished_ = true; | 1328 called_animation_finished_ = true; |
1325 EndTest(); | 1329 EndTest(); |
1326 } | 1330 } |
1327 | 1331 |
1328 void AfterTest() override { | 1332 void AfterTest() override { |
1329 EXPECT_TRUE(called_animation_started_); | 1333 EXPECT_TRUE(called_animation_started_); |
1330 EXPECT_TRUE(called_animation_finished_); | 1334 EXPECT_TRUE(called_animation_finished_); |
1331 } | 1335 } |
1332 | 1336 |
1333 private: | 1337 private: |
1334 bool called_animation_started_; | 1338 bool called_animation_started_; |
1335 bool called_animation_finished_; | 1339 bool called_animation_finished_; |
1336 FakeContentLayerClient client_; | 1340 FakeContentLayerClient client_; |
1337 scoped_refptr<FakePictureLayer> picture_; | 1341 scoped_refptr<FakePictureLayer> picture_; |
1338 }; | 1342 }; |
1339 | 1343 |
1340 SINGLE_AND_MULTI_THREAD_TEST_F( | 1344 SINGLE_AND_MULTI_THREAD_TEST_F( |
1341 LayerTreeHostAnimationTestNotifyAnimationFinished); | 1345 LayerTreeHostAnimationTestNotifyAnimationFinished); |
1342 | 1346 |
1343 } // namespace | 1347 } // namespace |
1344 } // namespace cc | 1348 } // namespace cc |
OLD | NEW |