| 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_sequence.h" | 5 #include "ui/compositor/layer_animation_sequence.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "cc/animation/animation_events.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/compositor/layer_animation_delegate.h" | 12 #include "ui/compositor/layer_animation_delegate.h" |
| 14 #include "ui/compositor/layer_animation_element.h" | 13 #include "ui/compositor/layer_animation_element.h" |
| 15 #include "ui/compositor/test/test_layer_animation_delegate.h" | 14 #include "ui/compositor/test/test_layer_animation_delegate.h" |
| 16 #include "ui/compositor/test/test_layer_animation_observer.h" | 15 #include "ui/compositor/test/test_layer_animation_observer.h" |
| 17 #include "ui/compositor/test/test_utils.h" | 16 #include "ui/compositor/test/test_utils.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
| 20 | 19 |
| 21 namespace ui { | 20 namespace ui { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 for (int i = 0; i < 2; ++i) { | 85 for (int i = 0; i < 2; ++i) { |
| 87 int starting_group_id = 1; | 86 int starting_group_id = 1; |
| 88 sequence.set_animation_group_id(starting_group_id); | 87 sequence.set_animation_group_id(starting_group_id); |
| 89 start_time = effective_start + delta; | 88 start_time = effective_start + delta; |
| 90 sequence.set_start_time(start_time); | 89 sequence.set_start_time(start_time); |
| 91 delegate.SetOpacityFromAnimation(start); | 90 delegate.SetOpacityFromAnimation(start); |
| 92 sequence.Start(&delegate); | 91 sequence.Start(&delegate); |
| 93 sequence.Progress(start_time, &delegate); | 92 sequence.Progress(start_time, &delegate); |
| 94 EXPECT_FLOAT_EQ(start, sequence.last_progressed_fraction()); | 93 EXPECT_FLOAT_EQ(start, sequence.last_progressed_fraction()); |
| 95 effective_start = start_time + delta; | 94 effective_start = start_time + delta; |
| 96 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( | 95 sequence.OnThreadedAnimationStarted(effective_start, |
| 97 cc::AnimationEvent::STARTED, 0, sequence.animation_group_id(), | 96 cc::TargetProperty::OPACITY, |
| 98 cc::TargetProperty::OPACITY, effective_start)); | 97 sequence.animation_group_id()); |
| 99 sequence.Progress(effective_start + delta/2, &delegate); | 98 sequence.Progress(effective_start + delta/2, &delegate); |
| 100 EXPECT_FLOAT_EQ(middle, sequence.last_progressed_fraction()); | 99 EXPECT_FLOAT_EQ(middle, sequence.last_progressed_fraction()); |
| 101 EXPECT_TRUE(sequence.IsFinished(effective_start + delta)); | 100 EXPECT_TRUE(sequence.IsFinished(effective_start + delta)); |
| 102 sequence.Progress(effective_start + delta, &delegate); | 101 sequence.Progress(effective_start + delta, &delegate); |
| 103 EXPECT_FLOAT_EQ(target, sequence.last_progressed_fraction()); | 102 EXPECT_FLOAT_EQ(target, sequence.last_progressed_fraction()); |
| 104 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); | 103 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); |
| 105 } | 104 } |
| 106 | 105 |
| 107 EXPECT_EQ(static_cast<LayerAnimationElement::AnimatableProperties>( | 106 EXPECT_EQ(static_cast<LayerAnimationElement::AnimatableProperties>( |
| 108 LayerAnimationElement::OPACITY), | 107 LayerAnimationElement::OPACITY), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 start_time = opacity_effective_start + 4 * delta; | 139 start_time = opacity_effective_start + 4 * delta; |
| 141 sequence.set_start_time(start_time); | 140 sequence.set_start_time(start_time); |
| 142 delegate.SetOpacityFromAnimation(start_opacity); | 141 delegate.SetOpacityFromAnimation(start_opacity); |
| 143 delegate.SetTransformFromAnimation(start_transform); | 142 delegate.SetTransformFromAnimation(start_transform); |
| 144 | 143 |
| 145 sequence.Start(&delegate); | 144 sequence.Start(&delegate); |
| 146 sequence.Progress(start_time, &delegate); | 145 sequence.Progress(start_time, &delegate); |
| 147 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); | 146 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); |
| 148 opacity_effective_start = start_time + delta; | 147 opacity_effective_start = start_time + delta; |
| 149 EXPECT_EQ(starting_group_id, sequence.animation_group_id()); | 148 EXPECT_EQ(starting_group_id, sequence.animation_group_id()); |
| 150 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( | 149 sequence.OnThreadedAnimationStarted(opacity_effective_start, |
| 151 cc::AnimationEvent::STARTED, 0, sequence.animation_group_id(), | 150 cc::TargetProperty::OPACITY, |
| 152 cc::TargetProperty::OPACITY, opacity_effective_start)); | 151 sequence.animation_group_id()); |
| 153 sequence.Progress(opacity_effective_start + delta/2, &delegate); | 152 sequence.Progress(opacity_effective_start + delta/2, &delegate); |
| 154 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); | 153 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); |
| 155 sequence.Progress(opacity_effective_start + delta, &delegate); | 154 sequence.Progress(opacity_effective_start + delta, &delegate); |
| 156 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation()); | 155 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation()); |
| 157 | 156 |
| 158 // Now at the start of the pause. | 157 // Now at the start of the pause. |
| 159 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); | 158 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); |
| 160 TestLayerAnimationDelegate copy = delegate; | 159 TestLayerAnimationDelegate copy = delegate; |
| 161 | 160 |
| 162 // In the middle of the pause -- nothing should have changed. | 161 // In the middle of the pause -- nothing should have changed. |
| 163 sequence.Progress(opacity_effective_start + delta + delta/2, | 162 sequence.Progress(opacity_effective_start + delta + delta/2, |
| 164 &delegate); | 163 &delegate); |
| 165 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), | 164 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), |
| 166 copy.GetBoundsForAnimation()); | 165 copy.GetBoundsForAnimation()); |
| 167 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), | 166 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), |
| 168 copy.GetTransformForAnimation()); | 167 copy.GetTransformForAnimation()); |
| 169 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), | 168 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), |
| 170 copy.GetOpacityForAnimation()); | 169 copy.GetOpacityForAnimation()); |
| 171 | 170 |
| 172 sequence.Progress(opacity_effective_start + 2 * delta, &delegate); | 171 sequence.Progress(opacity_effective_start + 2 * delta, &delegate); |
| 173 CheckApproximatelyEqual(start_transform, | 172 CheckApproximatelyEqual(start_transform, |
| 174 delegate.GetTransformForAnimation()); | 173 delegate.GetTransformForAnimation()); |
| 175 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); | 174 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); |
| 176 transform_effective_start = opacity_effective_start + 3 * delta; | 175 transform_effective_start = opacity_effective_start + 3 * delta; |
| 177 EXPECT_NE(starting_group_id, sequence.animation_group_id()); | 176 EXPECT_NE(starting_group_id, sequence.animation_group_id()); |
| 178 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( | 177 sequence.OnThreadedAnimationStarted(transform_effective_start, |
| 179 cc::AnimationEvent::STARTED, 0, sequence.animation_group_id(), | 178 cc::TargetProperty::TRANSFORM, |
| 180 cc::TargetProperty::TRANSFORM, transform_effective_start)); | 179 sequence.animation_group_id()); |
| 181 sequence.Progress(transform_effective_start + delta/2, &delegate); | 180 sequence.Progress(transform_effective_start + delta/2, &delegate); |
| 182 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); | 181 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); |
| 183 EXPECT_TRUE(sequence.IsFinished(transform_effective_start + delta)); | 182 EXPECT_TRUE(sequence.IsFinished(transform_effective_start + delta)); |
| 184 sequence.Progress(transform_effective_start + delta, &delegate); | 183 sequence.Progress(transform_effective_start + delta, &delegate); |
| 185 CheckApproximatelyEqual(target_transform, | 184 CheckApproximatelyEqual(target_transform, |
| 186 delegate.GetTransformForAnimation()); | 185 delegate.GetTransformForAnimation()); |
| 187 } | 186 } |
| 188 | 187 |
| 189 EXPECT_EQ( | 188 EXPECT_EQ( |
| 190 static_cast<LayerAnimationElement::AnimatableProperties>( | 189 static_cast<LayerAnimationElement::AnimatableProperties>( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 EXPECT_TRUE(!observer.last_ended_sequence()); | 264 EXPECT_TRUE(!observer.last_ended_sequence()); |
| 266 sequence.Progress(start_time + delta, &delegate); | 265 sequence.Progress(start_time + delta, &delegate); |
| 267 EXPECT_EQ(observer.last_ended_sequence(), &sequence); | 266 EXPECT_EQ(observer.last_ended_sequence(), &sequence); |
| 268 sequence.RemoveObserver(&observer); | 267 sequence.RemoveObserver(&observer); |
| 269 } | 268 } |
| 270 } | 269 } |
| 271 | 270 |
| 272 } // namespace | 271 } // namespace |
| 273 | 272 |
| 274 } // namespace ui | 273 } // namespace ui |
| OLD | NEW |