| 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_animator.h" | 5 #include "ui/compositor/layer_animator.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 2514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 | 2525 |
| 2526 Layer layer; | 2526 Layer layer; |
| 2527 root_1.Add(&layer); | 2527 root_1.Add(&layer); |
| 2528 LayerAnimator* animator = layer.GetAnimator(); | 2528 LayerAnimator* animator = layer.GetAnimator(); |
| 2529 double target_opacity = 1.0; | 2529 double target_opacity = 1.0; |
| 2530 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); | 2530 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); |
| 2531 animator->ScheduleAnimation(new LayerAnimationSequence( | 2531 animator->ScheduleAnimation(new LayerAnimationSequence( |
| 2532 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta))); | 2532 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta))); |
| 2533 EXPECT_TRUE(compositor_1->layer_animator_collection()->HasActiveAnimators()); | 2533 EXPECT_TRUE(compositor_1->layer_animator_collection()->HasActiveAnimators()); |
| 2534 EXPECT_FALSE(compositor_2->layer_animator_collection()->HasActiveAnimators()); | 2534 EXPECT_FALSE(compositor_2->layer_animator_collection()->HasActiveAnimators()); |
| 2535 EXPECT_TRUE(layer.cc_layer_for_testing()->HasActiveAnimation()); |
| 2535 | 2536 |
| 2536 root_2.Add(&layer); | 2537 root_2.Add(&layer); |
| 2537 EXPECT_FALSE(compositor_1->layer_animator_collection()->HasActiveAnimators()); | 2538 EXPECT_FALSE(compositor_1->layer_animator_collection()->HasActiveAnimators()); |
| 2538 EXPECT_TRUE(compositor_2->layer_animator_collection()->HasActiveAnimators()); | 2539 EXPECT_TRUE(compositor_2->layer_animator_collection()->HasActiveAnimators()); |
| 2540 EXPECT_TRUE(layer.cc_layer_for_testing()->HasActiveAnimation()); |
| 2541 |
| 2539 host_2.reset(); | 2542 host_2.reset(); |
| 2540 host_1.reset(); | 2543 host_1.reset(); |
| 2541 TerminateContextFactoryForTests(); | 2544 TerminateContextFactoryForTests(); |
| 2542 } | 2545 } |
| 2543 | 2546 |
| 2547 TEST(LayerAnimatorTest, ThreadedAnimationSurvivesIfLayerRemovedAdded) { |
| 2548 bool enable_pixel_output = false; |
| 2549 ui::ContextFactory* context_factory = |
| 2550 InitializeContextFactoryForTests(enable_pixel_output); |
| 2551 const gfx::Rect bounds(10, 10, 100, 100); |
| 2552 scoped_ptr<TestCompositorHost> host( |
| 2553 TestCompositorHost::Create(bounds, context_factory)); |
| 2554 host->Show(); |
| 2555 |
| 2556 Compositor* compositor = host->GetCompositor(); |
| 2557 |
| 2558 Layer root; |
| 2559 compositor->SetRootLayer(&root); |
| 2560 |
| 2561 Layer layer; |
| 2562 root.Add(&layer); |
| 2563 |
| 2564 LayerAnimator* animator = layer.GetAnimator(); |
| 2565 double target_opacity = 1.0; |
| 2566 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); |
| 2567 animator->ScheduleAnimation(new LayerAnimationSequence( |
| 2568 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta))); |
| 2569 |
| 2570 EXPECT_TRUE(layer.cc_layer_for_testing()->HasActiveAnimation()); |
| 2571 root.Remove(&layer); |
| 2572 root.Add(&layer); |
| 2573 EXPECT_TRUE(layer.cc_layer_for_testing()->HasActiveAnimation()); |
| 2574 |
| 2575 host.reset(); |
| 2576 TerminateContextFactoryForTests(); |
| 2577 } |
| 2578 |
| 2544 class LayerOwnerAnimationObserver : public LayerAnimationObserver { | 2579 class LayerOwnerAnimationObserver : public LayerAnimationObserver { |
| 2545 public: | 2580 public: |
| 2546 LayerOwnerAnimationObserver(LayerAnimator* animator) | 2581 LayerOwnerAnimationObserver(LayerAnimator* animator) |
| 2547 : animator_layer_(new Layer(LAYER_TEXTURED)) { | 2582 : animator_layer_(new Layer(LAYER_TEXTURED)) { |
| 2548 animator_layer_->SetAnimator(animator); | 2583 animator_layer_->SetAnimator(animator); |
| 2549 } | 2584 } |
| 2550 | 2585 |
| 2551 ~LayerOwnerAnimationObserver() override {} | 2586 ~LayerOwnerAnimationObserver() override {} |
| 2552 | 2587 |
| 2553 void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override { | 2588 void OnLayerAnimationEnded(LayerAnimationSequence* sequence) override { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2798 EXPECT_EQ(observer.last_ended_sequence(), nullptr); | 2833 EXPECT_EQ(observer.last_ended_sequence(), nullptr); |
| 2799 EXPECT_EQ(observer.last_detached_sequence(), first_sequence); | 2834 EXPECT_EQ(observer.last_detached_sequence(), first_sequence); |
| 2800 | 2835 |
| 2801 EXPECT_TRUE(observer.AbortedEpochIsBeforeDetachedEpoch()); | 2836 EXPECT_TRUE(observer.AbortedEpochIsBeforeDetachedEpoch()); |
| 2802 EXPECT_TRUE(observer.AbortedEpochIsBeforeStartedEpoch()); | 2837 EXPECT_TRUE(observer.AbortedEpochIsBeforeStartedEpoch()); |
| 2803 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch()); | 2838 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch()); |
| 2804 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch()); | 2839 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch()); |
| 2805 } | 2840 } |
| 2806 | 2841 |
| 2807 } // namespace ui | 2842 } // namespace ui |
| OLD | NEW |