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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
17 #include "ui/compositor/layer_animation_delegate.h" | 18 #include "ui/compositor/layer_animation_delegate.h" |
18 #include "ui/compositor/layer_animation_element.h" | 19 #include "ui/compositor/layer_animation_element.h" |
19 #include "ui/compositor/layer_animation_sequence.h" | 20 #include "ui/compositor/layer_animation_sequence.h" |
20 #include "ui/compositor/layer_animator_collection.h" | 21 #include "ui/compositor/layer_animator_collection.h" |
21 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 22 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
22 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
(...skipping 14 matching lines...) Expand all Loading... |
37 // space and the order if A R G B. | 38 // space and the order if A R G B. |
38 std::string ColorToString(SkColor color) { | 39 std::string ColorToString(SkColor color) { |
39 return base::StringPrintf("%d %d %d %d", SkColorGetA(color), | 40 return base::StringPrintf("%d %d %d %d", SkColorGetA(color), |
40 SkColorGetR(color), SkColorGetG(color), | 41 SkColorGetR(color), SkColorGetG(color), |
41 SkColorGetB(color)); | 42 SkColorGetB(color)); |
42 } | 43 } |
43 | 44 |
44 // Creates vector with two LayerAnimationSequences, based on |first| and | 45 // Creates vector with two LayerAnimationSequences, based on |first| and |
45 // |second| layer animation elements. | 46 // |second| layer animation elements. |
46 std::vector<LayerAnimationSequence*> CreateMultiSequence( | 47 std::vector<LayerAnimationSequence*> CreateMultiSequence( |
47 LayerAnimationElement* first, | 48 std::unique_ptr<LayerAnimationElement> first, |
48 LayerAnimationElement* second) { | 49 std::unique_ptr<LayerAnimationElement> second) { |
49 LayerAnimationSequence* first_sequence = new LayerAnimationSequence(); | 50 LayerAnimationSequence* first_sequence = new LayerAnimationSequence(); |
50 first_sequence->AddElement(first); | 51 first_sequence->AddElement(std::move(first)); |
51 LayerAnimationSequence* second_sequence = new LayerAnimationSequence(); | 52 LayerAnimationSequence* second_sequence = new LayerAnimationSequence(); |
52 second_sequence->AddElement(second); | 53 second_sequence->AddElement(std::move(second)); |
53 | 54 |
54 std::vector<ui::LayerAnimationSequence*> animations; | 55 std::vector<ui::LayerAnimationSequence*> animations; |
55 animations.push_back(first_sequence); | 56 animations.push_back(first_sequence); |
56 animations.push_back(second_sequence); | 57 animations.push_back(second_sequence); |
57 return animations; | 58 return animations; |
58 } | 59 } |
59 | 60 |
60 // Creates a default animator with timers disabled for test. |delegate| and | 61 // Creates a default animator with timers disabled for test. |delegate| and |
61 // |observer| are attached if non-null. | 62 // |observer| are attached if non-null. |
62 LayerAnimator* CreateDefaultTestAnimator(LayerAnimationDelegate* delegate, | 63 LayerAnimator* CreateDefaultTestAnimator(LayerAnimationDelegate* delegate, |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 private: | 236 private: |
236 LayerAnimatorDestructionObserver* destruction_observer_; | 237 LayerAnimatorDestructionObserver* destruction_observer_; |
237 | 238 |
238 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator); | 239 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator); |
239 }; | 240 }; |
240 | 241 |
241 // The test layer animation sequence updates a live instances count when it is | 242 // The test layer animation sequence updates a live instances count when it is |
242 // created and destroyed. | 243 // created and destroyed. |
243 class TestLayerAnimationSequence : public LayerAnimationSequence { | 244 class TestLayerAnimationSequence : public LayerAnimationSequence { |
244 public: | 245 public: |
245 TestLayerAnimationSequence(LayerAnimationElement* element, | 246 TestLayerAnimationSequence(std::unique_ptr<LayerAnimationElement> element, |
246 int* num_live_instances) | 247 int* num_live_instances) |
247 : LayerAnimationSequence(element), | 248 : LayerAnimationSequence(std::move(element)), |
248 num_live_instances_(num_live_instances) { | 249 num_live_instances_(num_live_instances) { |
249 (*num_live_instances_)++; | 250 (*num_live_instances_)++; |
250 } | 251 } |
251 | 252 |
252 ~TestLayerAnimationSequence() override { (*num_live_instances_)--; } | 253 ~TestLayerAnimationSequence() override { (*num_live_instances_)--; } |
253 | 254 |
254 private: | 255 private: |
255 int* num_live_instances_; | 256 int* num_live_instances_; |
256 | 257 |
257 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); | 258 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); |
(...skipping 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 TestLayerAnimationDelegate delegate; | 2100 TestLayerAnimationDelegate delegate; |
2100 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate)); | 2101 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate)); |
2101 | 2102 |
2102 double start_opacity(0.0); | 2103 double start_opacity(0.0); |
2103 double target_opacity(1.0); | 2104 double target_opacity(1.0); |
2104 | 2105 |
2105 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 2106 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
2106 | 2107 |
2107 delegate.SetOpacityFromAnimation(start_opacity); | 2108 delegate.SetOpacityFromAnimation(start_opacity); |
2108 | 2109 |
2109 std::unique_ptr<LayerAnimationSequence> sequence(new LayerAnimationSequence( | 2110 std::unique_ptr<LayerAnimationSequence> sequence = |
2110 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); | 2111 base::MakeUnique<LayerAnimationSequence>( |
| 2112 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)); |
2111 | 2113 |
2112 animator->StartAnimation(sequence.release()); | 2114 animator->StartAnimation(sequence.release()); |
2113 | 2115 |
2114 animator->SetOpacity(0.5); | 2116 animator->SetOpacity(0.5); |
2115 | 2117 |
2116 EXPECT_FALSE(animator->is_animating()); | 2118 EXPECT_FALSE(animator->is_animating()); |
2117 EXPECT_EQ(0.5, animator->GetTargetOpacity()); | 2119 EXPECT_EQ(0.5, animator->GetTargetOpacity()); |
2118 } | 2120 } |
2119 | 2121 |
2120 // Tests that the preemption mode IMMEDIATELY_SET_NEW_TARGET, doesn't cause the | 2122 // Tests that the preemption mode IMMEDIATELY_SET_NEW_TARGET, doesn't cause the |
(...skipping 12 matching lines...) Expand all Loading... |
2133 { | 2135 { |
2134 // start an implicit bounds animation. | 2136 // start an implicit bounds animation. |
2135 ScopedLayerAnimationSettings settings(animator.get()); | 2137 ScopedLayerAnimationSettings settings(animator.get()); |
2136 animator->SetBounds(middle_bounds); | 2138 animator->SetBounds(middle_bounds); |
2137 } | 2139 } |
2138 | 2140 |
2139 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 2141 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
2140 | 2142 |
2141 int num_live_instances = 0; | 2143 int num_live_instances = 0; |
2142 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 2144 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
2143 std::unique_ptr<TestLayerAnimationSequence> sequence( | 2145 std::unique_ptr<TestLayerAnimationSequence> sequence = |
2144 new TestLayerAnimationSequence( | 2146 base::MakeUnique<TestLayerAnimationSequence>( |
2145 LayerAnimationElement::CreateBoundsElement(target_bounds, delta), | 2147 LayerAnimationElement::CreateBoundsElement(target_bounds, delta), |
2146 &num_live_instances)); | 2148 &num_live_instances); |
2147 | 2149 |
2148 EXPECT_EQ(1, num_live_instances); | 2150 EXPECT_EQ(1, num_live_instances); |
2149 | 2151 |
2150 // This should interrupt the running sequence causing us to immediately set | 2152 // This should interrupt the running sequence causing us to immediately set |
2151 // the target value. The sequence should alse be destructed. | 2153 // the target value. The sequence should alse be destructed. |
2152 animator->StartAnimation(sequence.release()); | 2154 animator->StartAnimation(sequence.release()); |
2153 | 2155 |
2154 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 2156 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
2155 EXPECT_EQ(0, num_live_instances); | 2157 EXPECT_EQ(0, num_live_instances); |
2156 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 2158 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2949 EXPECT_EQ(observer.last_ended_sequence(), nullptr); | 2951 EXPECT_EQ(observer.last_ended_sequence(), nullptr); |
2950 EXPECT_EQ(observer.last_detached_sequence(), first_sequence); | 2952 EXPECT_EQ(observer.last_detached_sequence(), first_sequence); |
2951 | 2953 |
2952 EXPECT_TRUE(observer.AbortedEpochIsBeforeDetachedEpoch()); | 2954 EXPECT_TRUE(observer.AbortedEpochIsBeforeDetachedEpoch()); |
2953 EXPECT_TRUE(observer.AbortedEpochIsBeforeStartedEpoch()); | 2955 EXPECT_TRUE(observer.AbortedEpochIsBeforeStartedEpoch()); |
2954 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch()); | 2956 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch()); |
2955 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch()); | 2957 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch()); |
2956 } | 2958 } |
2957 | 2959 |
2958 } // namespace ui | 2960 } // namespace ui |
OLD | NEW |