| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/compositor/layer_animation_delegate.h" | 12 #include "ui/compositor/layer_animation_delegate.h" |
| 13 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 13 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 14 #include "ui/compositor/test/test_layer_animation_delegate.h" | 14 #include "ui/compositor/test/test_layer_animation_delegate.h" |
| 15 #include "ui/compositor/test/test_utils.h" | 15 #include "ui/compositor/test/test_utils.h" |
| 16 #include "ui/gfx/frame_time.h" |
| 16 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 17 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
| 18 | 19 |
| 19 namespace ui { | 20 namespace ui { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Check that the transformation element progresses the delegate as expected and | 24 // Check that the transformation element progresses the delegate as expected and |
| 24 // that the element can be reused after it completes. | 25 // that the element can be reused after it completes. |
| 25 TEST(LayerAnimationElementTest, TransformElement) { | 26 TEST(LayerAnimationElementTest, TransformElement) { |
| 26 TestLayerAnimationDelegate delegate; | 27 TestLayerAnimationDelegate delegate; |
| 27 gfx::Transform start_transform, target_transform; | 28 gfx::Transform start_transform, target_transform; |
| 28 start_transform.Rotate(-30.0); | 29 start_transform.Rotate(-30.0); |
| 29 target_transform.Rotate(30.0); | 30 target_transform.Rotate(30.0); |
| 30 base::TimeTicks start_time; | 31 gfx::FrameTime start_time; |
| 31 base::TimeTicks effective_start_time; | 32 gfx::FrameTime effective_start_time; |
| 32 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 33 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 33 | 34 |
| 34 scoped_ptr<LayerAnimationElement> element( | 35 scoped_ptr<LayerAnimationElement> element( |
| 35 LayerAnimationElement::CreateTransformElement(target_transform, delta)); | 36 LayerAnimationElement::CreateTransformElement(target_transform, delta)); |
| 36 element->set_animation_group_id(1); | 37 element->set_animation_group_id(1); |
| 37 | 38 |
| 38 for (int i = 0; i < 2; ++i) { | 39 for (int i = 0; i < 2; ++i) { |
| 39 start_time = effective_start_time + delta; | 40 start_time = effective_start_time + delta; |
| 40 element->set_requested_start_time(start_time); | 41 element->set_requested_start_time(start_time); |
| 41 delegate.SetTransformFromAnimation(start_transform); | 42 delegate.SetTransformFromAnimation(start_transform); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 LayerAnimationElement::CreateTransformElement(transform, delta)); | 92 LayerAnimationElement::CreateTransformElement(transform, delta)); |
| 92 | 93 |
| 93 scoped_ptr<LayerAnimationElement> inverse_element( | 94 scoped_ptr<LayerAnimationElement> inverse_element( |
| 94 LayerAnimationElement::CreateInverseTransformElement(transform, | 95 LayerAnimationElement::CreateInverseTransformElement(transform, |
| 95 base_element.get())); | 96 base_element.get())); |
| 96 EXPECT_EQ(base_element->duration(), inverse_element->duration()); | 97 EXPECT_EQ(base_element->duration(), inverse_element->duration()); |
| 97 } | 98 } |
| 98 | 99 |
| 99 // Ensures that the GetTargetTransform() method works as intended. | 100 // Ensures that the GetTargetTransform() method works as intended. |
| 100 TEST(LayerAnimationElementTest, InverseElementTargetCalculation) { | 101 TEST(LayerAnimationElementTest, InverseElementTargetCalculation) { |
| 101 base::TimeTicks start_time; | 102 gfx::FrameTime start_time; |
| 102 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 103 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 103 start_time += delta; | 104 start_time += delta; |
| 104 | 105 |
| 105 gfx::Transform identity, transform; | 106 gfx::Transform identity, transform; |
| 106 | 107 |
| 107 transform.Scale3d(2.0, 2.0, 2.0); | 108 transform.Scale3d(2.0, 2.0, 2.0); |
| 108 | 109 |
| 109 scoped_ptr<LayerAnimationElement> base_element( | 110 scoped_ptr<LayerAnimationElement> base_element( |
| 110 LayerAnimationElement::CreateTransformElement(transform, delta)); | 111 LayerAnimationElement::CreateTransformElement(transform, delta)); |
| 111 scoped_ptr<LayerAnimationElement> inverse_element( | 112 scoped_ptr<LayerAnimationElement> inverse_element( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 129 } | 130 } |
| 130 | 131 |
| 131 // Check that the bounds element progresses the delegate as expected and | 132 // Check that the bounds element progresses the delegate as expected and |
| 132 // that the element can be reused after it completes. | 133 // that the element can be reused after it completes. |
| 133 TEST(LayerAnimationElementTest, BoundsElement) { | 134 TEST(LayerAnimationElementTest, BoundsElement) { |
| 134 TestLayerAnimationDelegate delegate; | 135 TestLayerAnimationDelegate delegate; |
| 135 gfx::Rect start, target, middle; | 136 gfx::Rect start, target, middle; |
| 136 start = target = middle = gfx::Rect(0, 0, 50, 50); | 137 start = target = middle = gfx::Rect(0, 0, 50, 50); |
| 137 start.set_x(-90); | 138 start.set_x(-90); |
| 138 target.set_x(90); | 139 target.set_x(90); |
| 139 base::TimeTicks start_time; | 140 gfx::FrameTime start_time; |
| 140 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 141 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 141 | 142 |
| 142 scoped_ptr<LayerAnimationElement> element( | 143 scoped_ptr<LayerAnimationElement> element( |
| 143 LayerAnimationElement::CreateBoundsElement(target, delta)); | 144 LayerAnimationElement::CreateBoundsElement(target, delta)); |
| 144 | 145 |
| 145 for (int i = 0; i < 2; ++i) { | 146 for (int i = 0; i < 2; ++i) { |
| 146 start_time += delta; | 147 start_time += delta; |
| 147 element->set_requested_start_time(start_time); | 148 element->set_requested_start_time(start_time); |
| 148 delegate.SetBoundsFromAnimation(start); | 149 delegate.SetBoundsFromAnimation(start); |
| 149 element->Start(&delegate, 1); | 150 element->Start(&delegate, 1); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 165 CheckApproximatelyEqual(target, target_value.bounds); | 166 CheckApproximatelyEqual(target, target_value.bounds); |
| 166 } | 167 } |
| 167 | 168 |
| 168 // Check that the opacity element progresses the delegate as expected and | 169 // Check that the opacity element progresses the delegate as expected and |
| 169 // that the element can be reused after it completes. | 170 // that the element can be reused after it completes. |
| 170 TEST(LayerAnimationElementTest, OpacityElement) { | 171 TEST(LayerAnimationElementTest, OpacityElement) { |
| 171 TestLayerAnimationDelegate delegate; | 172 TestLayerAnimationDelegate delegate; |
| 172 float start = 0.0; | 173 float start = 0.0; |
| 173 float middle = 0.5; | 174 float middle = 0.5; |
| 174 float target = 1.0; | 175 float target = 1.0; |
| 175 base::TimeTicks start_time; | 176 gfx::FrameTime start_time; |
| 176 base::TimeTicks effective_start_time; | 177 gfx::FrameTime effective_start_time; |
| 177 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 178 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 178 scoped_ptr<LayerAnimationElement> element( | 179 scoped_ptr<LayerAnimationElement> element( |
| 179 LayerAnimationElement::CreateOpacityElement(target, delta)); | 180 LayerAnimationElement::CreateOpacityElement(target, delta)); |
| 180 | 181 |
| 181 for (int i = 0; i < 2; ++i) { | 182 for (int i = 0; i < 2; ++i) { |
| 182 start_time = effective_start_time + delta; | 183 start_time = effective_start_time + delta; |
| 183 element->set_requested_start_time(start_time); | 184 element->set_requested_start_time(start_time); |
| 184 delegate.SetOpacityFromAnimation(start); | 185 delegate.SetOpacityFromAnimation(start); |
| 185 element->Start(&delegate, 1); | 186 element->Start(&delegate, 1); |
| 186 element->Progress(start_time, &delegate); | 187 element->Progress(start_time, &delegate); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 206 element->GetTargetValue(&target_value); | 207 element->GetTargetValue(&target_value); |
| 207 EXPECT_FLOAT_EQ(target, target_value.opacity); | 208 EXPECT_FLOAT_EQ(target, target_value.opacity); |
| 208 } | 209 } |
| 209 | 210 |
| 210 // Check that the visibility element progresses the delegate as expected and | 211 // Check that the visibility element progresses the delegate as expected and |
| 211 // that the element can be reused after it completes. | 212 // that the element can be reused after it completes. |
| 212 TEST(LayerAnimationElementTest, VisibilityElement) { | 213 TEST(LayerAnimationElementTest, VisibilityElement) { |
| 213 TestLayerAnimationDelegate delegate; | 214 TestLayerAnimationDelegate delegate; |
| 214 bool start = true; | 215 bool start = true; |
| 215 bool target = false; | 216 bool target = false; |
| 216 base::TimeTicks start_time; | 217 gfx::FrameTime start_time; |
| 217 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 218 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 218 scoped_ptr<LayerAnimationElement> element( | 219 scoped_ptr<LayerAnimationElement> element( |
| 219 LayerAnimationElement::CreateVisibilityElement(target, delta)); | 220 LayerAnimationElement::CreateVisibilityElement(target, delta)); |
| 220 | 221 |
| 221 for (int i = 0; i < 2; ++i) { | 222 for (int i = 0; i < 2; ++i) { |
| 222 start_time += delta; | 223 start_time += delta; |
| 223 element->set_requested_start_time(start_time); | 224 element->set_requested_start_time(start_time); |
| 224 delegate.SetVisibilityFromAnimation(start); | 225 delegate.SetVisibilityFromAnimation(start); |
| 225 element->Start(&delegate, 1); | 226 element->Start(&delegate, 1); |
| 226 element->Progress(start_time, &delegate); | 227 element->Progress(start_time, &delegate); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 241 EXPECT_FALSE(target_value.visibility); | 242 EXPECT_FALSE(target_value.visibility); |
| 242 } | 243 } |
| 243 | 244 |
| 244 // Check that the Brightness element progresses the delegate as expected and | 245 // Check that the Brightness element progresses the delegate as expected and |
| 245 // that the element can be reused after it completes. | 246 // that the element can be reused after it completes. |
| 246 TEST(LayerAnimationElementTest, BrightnessElement) { | 247 TEST(LayerAnimationElementTest, BrightnessElement) { |
| 247 TestLayerAnimationDelegate delegate; | 248 TestLayerAnimationDelegate delegate; |
| 248 float start = 0.0; | 249 float start = 0.0; |
| 249 float middle = 0.5; | 250 float middle = 0.5; |
| 250 float target = 1.0; | 251 float target = 1.0; |
| 251 base::TimeTicks start_time; | 252 gfx::FrameTime start_time; |
| 252 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 253 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 253 scoped_ptr<LayerAnimationElement> element( | 254 scoped_ptr<LayerAnimationElement> element( |
| 254 LayerAnimationElement::CreateBrightnessElement(target, delta)); | 255 LayerAnimationElement::CreateBrightnessElement(target, delta)); |
| 255 | 256 |
| 256 for (int i = 0; i < 2; ++i) { | 257 for (int i = 0; i < 2; ++i) { |
| 257 start_time += delta; | 258 start_time += delta; |
| 258 element->set_requested_start_time(start_time); | 259 element->set_requested_start_time(start_time); |
| 259 delegate.SetBrightnessFromAnimation(start); | 260 delegate.SetBrightnessFromAnimation(start); |
| 260 element->Start(&delegate, 1); | 261 element->Start(&delegate, 1); |
| 261 element->Progress(start_time, &delegate); | 262 element->Progress(start_time, &delegate); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 276 EXPECT_FLOAT_EQ(target, target_value.brightness); | 277 EXPECT_FLOAT_EQ(target, target_value.brightness); |
| 277 } | 278 } |
| 278 | 279 |
| 279 // Check that the Grayscale element progresses the delegate as expected and | 280 // Check that the Grayscale element progresses the delegate as expected and |
| 280 // that the element can be reused after it completes. | 281 // that the element can be reused after it completes. |
| 281 TEST(LayerAnimationElementTest, GrayscaleElement) { | 282 TEST(LayerAnimationElementTest, GrayscaleElement) { |
| 282 TestLayerAnimationDelegate delegate; | 283 TestLayerAnimationDelegate delegate; |
| 283 float start = 0.0; | 284 float start = 0.0; |
| 284 float middle = 0.5; | 285 float middle = 0.5; |
| 285 float target = 1.0; | 286 float target = 1.0; |
| 286 base::TimeTicks start_time; | 287 gfx::FrameTime start_time; |
| 287 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 288 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 288 scoped_ptr<LayerAnimationElement> element( | 289 scoped_ptr<LayerAnimationElement> element( |
| 289 LayerAnimationElement::CreateGrayscaleElement(target, delta)); | 290 LayerAnimationElement::CreateGrayscaleElement(target, delta)); |
| 290 | 291 |
| 291 for (int i = 0; i < 2; ++i) { | 292 for (int i = 0; i < 2; ++i) { |
| 292 start_time += delta; | 293 start_time += delta; |
| 293 element->set_requested_start_time(start_time); | 294 element->set_requested_start_time(start_time); |
| 294 delegate.SetGrayscaleFromAnimation(start); | 295 delegate.SetGrayscaleFromAnimation(start); |
| 295 element->Start(&delegate, 1); | 296 element->Start(&delegate, 1); |
| 296 element->Progress(start_time, &delegate); | 297 element->Progress(start_time, &delegate); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 313 | 314 |
| 314 // Check that the pause element progresses the delegate as expected and | 315 // Check that the pause element progresses the delegate as expected and |
| 315 // that the element can be reused after it completes. | 316 // that the element can be reused after it completes. |
| 316 TEST(LayerAnimationElementTest, PauseElement) { | 317 TEST(LayerAnimationElementTest, PauseElement) { |
| 317 LayerAnimationElement::AnimatableProperties properties; | 318 LayerAnimationElement::AnimatableProperties properties; |
| 318 properties.insert(LayerAnimationElement::TRANSFORM); | 319 properties.insert(LayerAnimationElement::TRANSFORM); |
| 319 properties.insert(LayerAnimationElement::BOUNDS); | 320 properties.insert(LayerAnimationElement::BOUNDS); |
| 320 properties.insert(LayerAnimationElement::OPACITY); | 321 properties.insert(LayerAnimationElement::OPACITY); |
| 321 properties.insert(LayerAnimationElement::BRIGHTNESS); | 322 properties.insert(LayerAnimationElement::BRIGHTNESS); |
| 322 properties.insert(LayerAnimationElement::GRAYSCALE); | 323 properties.insert(LayerAnimationElement::GRAYSCALE); |
| 323 base::TimeTicks start_time; | 324 gfx::FrameTime start_time; |
| 324 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 325 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 325 | 326 |
| 326 scoped_ptr<LayerAnimationElement> element( | 327 scoped_ptr<LayerAnimationElement> element( |
| 327 LayerAnimationElement::CreatePauseElement(properties, delta)); | 328 LayerAnimationElement::CreatePauseElement(properties, delta)); |
| 328 | 329 |
| 329 TestLayerAnimationDelegate delegate; | 330 TestLayerAnimationDelegate delegate; |
| 330 TestLayerAnimationDelegate copy = delegate; | 331 TestLayerAnimationDelegate copy = delegate; |
| 331 | 332 |
| 332 start_time += delta; | 333 start_time += delta; |
| 333 element->set_requested_start_time(start_time); | 334 element->set_requested_start_time(start_time); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 352 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), | 353 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), |
| 353 copy.GetGrayscaleForAnimation()); | 354 copy.GetGrayscaleForAnimation()); |
| 354 } | 355 } |
| 355 | 356 |
| 356 // Check that a threaded opacity element updates the delegate as expected when | 357 // Check that a threaded opacity element updates the delegate as expected when |
| 357 // aborted. | 358 // aborted. |
| 358 TEST(LayerAnimationElementTest, AbortOpacityElement) { | 359 TEST(LayerAnimationElementTest, AbortOpacityElement) { |
| 359 TestLayerAnimationDelegate delegate; | 360 TestLayerAnimationDelegate delegate; |
| 360 float start = 0.0; | 361 float start = 0.0; |
| 361 float target = 1.0; | 362 float target = 1.0; |
| 362 base::TimeTicks start_time; | 363 gfx::FrameTime start_time; |
| 363 base::TimeTicks effective_start_time; | 364 gfx::FrameTime effective_start_time; |
| 364 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 365 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 365 scoped_ptr<LayerAnimationElement> element( | 366 scoped_ptr<LayerAnimationElement> element( |
| 366 LayerAnimationElement::CreateOpacityElement(target, delta)); | 367 LayerAnimationElement::CreateOpacityElement(target, delta)); |
| 367 | 368 |
| 368 // Choose a non-linear Tween type. | 369 // Choose a non-linear Tween type. |
| 369 gfx::Tween::Type tween_type = gfx::Tween::EASE_IN; | 370 gfx::Tween::Type tween_type = gfx::Tween::EASE_IN; |
| 370 element->set_tween_type(tween_type); | 371 element->set_tween_type(tween_type); |
| 371 | 372 |
| 372 delegate.SetOpacityFromAnimation(start); | 373 delegate.SetOpacityFromAnimation(start); |
| 373 | 374 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 391 delegate.GetOpacityForAnimation()); | 392 delegate.GetOpacityForAnimation()); |
| 392 } | 393 } |
| 393 | 394 |
| 394 // Check that a threaded transform element updates the delegate as expected when | 395 // Check that a threaded transform element updates the delegate as expected when |
| 395 // aborted. | 396 // aborted. |
| 396 TEST(LayerAnimationElementTest, AbortTransformElement) { | 397 TEST(LayerAnimationElementTest, AbortTransformElement) { |
| 397 TestLayerAnimationDelegate delegate; | 398 TestLayerAnimationDelegate delegate; |
| 398 gfx::Transform start_transform, target_transform; | 399 gfx::Transform start_transform, target_transform; |
| 399 start_transform.Rotate(-30.0); | 400 start_transform.Rotate(-30.0); |
| 400 target_transform.Rotate(30.0); | 401 target_transform.Rotate(30.0); |
| 401 base::TimeTicks start_time; | 402 gfx::FrameTime start_time; |
| 402 base::TimeTicks effective_start_time; | 403 gfx::FrameTime effective_start_time; |
| 403 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 404 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 404 scoped_ptr<LayerAnimationElement> element( | 405 scoped_ptr<LayerAnimationElement> element( |
| 405 LayerAnimationElement::CreateTransformElement(target_transform, delta)); | 406 LayerAnimationElement::CreateTransformElement(target_transform, delta)); |
| 406 | 407 |
| 407 // Choose a non-linear Tween type. | 408 // Choose a non-linear Tween type. |
| 408 gfx::Tween::Type tween_type = gfx::Tween::EASE_IN; | 409 gfx::Tween::Type tween_type = gfx::Tween::EASE_IN; |
| 409 element->set_tween_type(tween_type); | 410 element->set_tween_type(tween_type); |
| 410 | 411 |
| 411 delegate.SetTransformFromAnimation(start_transform); | 412 delegate.SetTransformFromAnimation(start_transform); |
| 412 | 413 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 428 element->Abort(&delegate); | 429 element->Abort(&delegate); |
| 429 target_transform.Blend(start_transform, | 430 target_transform.Blend(start_transform, |
| 430 gfx::Tween::CalculateValue(tween_type, 0.5)); | 431 gfx::Tween::CalculateValue(tween_type, 0.5)); |
| 431 CheckApproximatelyEqual(target_transform, | 432 CheckApproximatelyEqual(target_transform, |
| 432 delegate.GetTransformForAnimation()); | 433 delegate.GetTransformForAnimation()); |
| 433 } | 434 } |
| 434 | 435 |
| 435 } // namespace | 436 } // namespace |
| 436 | 437 |
| 437 } // namespace ui | 438 } // namespace ui |
| OLD | NEW |