Chromium Code Reviews| 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 #include <climits> | |
| 8 | 9 |
| 9 #include "cc/animation/animation_curve.h" | 10 #include "cc/animation/animation_curve.h" |
| 10 #include "cc/animation/animation_host.h" | 11 #include "cc/animation/animation_host.h" |
| 11 #include "cc/animation/animation_id_provider.h" | 12 #include "cc/animation/animation_id_provider.h" |
| 12 #include "cc/animation/animation_player.h" | 13 #include "cc/animation/animation_player.h" |
| 13 #include "cc/animation/animation_timeline.h" | 14 #include "cc/animation/animation_timeline.h" |
| 14 #include "cc/animation/element_animations.h" | 15 #include "cc/animation/element_animations.h" |
| 15 #include "cc/animation/scroll_offset_animation_curve.h" | 16 #include "cc/animation/scroll_offset_animation_curve.h" |
| 16 #include "cc/animation/scroll_offset_animations.h" | 17 #include "cc/animation/scroll_offset_animations.h" |
| 17 #include "cc/animation/timing_function.h" | 18 #include "cc/animation/timing_function.h" |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1396 layer_->SetBounds(gfx::Size(4, 4)); | 1397 layer_->SetBounds(gfx::Size(4, 4)); |
| 1397 client_.set_bounds(layer_->bounds()); | 1398 client_.set_bounds(layer_->bounds()); |
| 1398 layer_tree_host()->root_layer()->AddChild(layer_); | 1399 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1399 | 1400 |
| 1400 AttachPlayersToTimeline(); | 1401 AttachPlayersToTimeline(); |
| 1401 | 1402 |
| 1402 player_->AttachElement(layer_tree_host()->root_layer()->element_id()); | 1403 player_->AttachElement(layer_tree_host()->root_layer()->element_id()); |
| 1403 player_child_->AttachElement(layer_->element_id()); | 1404 player_child_->AttachElement(layer_->element_id()); |
| 1404 } | 1405 } |
| 1405 | 1406 |
| 1406 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1407 void BeginTest() override { |
| 1408 animation_stopped_ = false; | |
| 1409 last_frame_number_ = INT_MAX; | |
| 1410 PostSetNeedsCommitToMainThread(); | |
| 1411 } | |
| 1407 | 1412 |
| 1408 void DidCommit() override { | 1413 void DidCommit() override { |
| 1409 switch (layer_tree_host()->SourceFrameNumber()) { | 1414 switch (layer_tree_host()->SourceFrameNumber()) { |
| 1410 case 1: | 1415 case 1: |
| 1411 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); | 1416 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); |
| 1412 break; | 1417 break; |
| 1413 case 2: | 1418 case 2: |
| 1414 Animation* animation = | 1419 Animation* animation = |
| 1415 player_child_->GetAnimation(TargetProperty::TRANSFORM); | 1420 player_child_->GetAnimation(TargetProperty::TRANSFORM); |
| 1416 player_child_->RemoveAnimation(animation->id()); | 1421 player_child_->RemoveAnimation(animation->id()); |
| 1417 gfx::Transform transform; | 1422 gfx::Transform transform; |
| 1418 transform.Translate(10.f, 10.f); | 1423 transform.Translate(10.f, 10.f); |
| 1419 layer_->SetTransform(transform); | 1424 layer_->SetTransform(transform); |
| 1420 | 1425 |
| 1421 // Do something that causes property trees to get rebuilt. This is | 1426 // Do something that causes property trees to get rebuilt. This is |
| 1422 // intended to simulate the conditions that caused the bug whose fix | 1427 // intended to simulate the conditions that caused the bug whose fix |
| 1423 // this is testing (the test will pass without it but won't test what | 1428 // this is testing (the test will pass without it but won't test what |
| 1424 // we want it to). We were updating the wrong transform node at the end | 1429 // we want it to). We were updating the wrong transform node at the end |
| 1425 // of an animation (we were assuming the layer with the finished | 1430 // of an animation (we were assuming the layer with the finished |
| 1426 // animation still had its own transform node). But nodes can only get | 1431 // animation still had its own transform node). But nodes can only get |
| 1427 // added/deleted when something triggers a rebuild. Adding a layer | 1432 // added/deleted when something triggers a rebuild. Adding a layer |
| 1428 // triggers a rebuild, and since the layer that had an animation before | 1433 // triggers a rebuild, and since the layer that had an animation before |
| 1429 // no longer has one, it doesn't get a transform node in the rebuild. | 1434 // no longer has one, it doesn't get a transform node in the rebuild. |
| 1430 layer_->AddChild(Layer::Create()); | 1435 layer_->AddChild(Layer::Create()); |
| 1431 break; | 1436 break; |
| 1432 } | 1437 } |
| 1433 } | 1438 } |
| 1434 | 1439 |
| 1435 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 1440 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 1441 GetImplTimelineAndPlayerByID(*host_impl); | |
| 1436 LayerImpl* child = host_impl->active_tree()->LayerById(layer_->id()); | 1442 LayerImpl* child = host_impl->active_tree()->LayerById(layer_->id()); |
| 1437 switch (host_impl->active_tree()->source_frame_number()) { | 1443 switch (host_impl->active_tree()->source_frame_number()) { |
| 1438 case 0: | 1444 case 0: |
| 1439 // No animation yet. | 1445 // No animation yet. |
| 1440 break; | 1446 break; |
| 1441 case 1: | 1447 case 1: |
| 1442 // Animation is started. | 1448 // Animation is started. |
| 1443 EXPECT_TRUE(child->screen_space_transform_is_animating()); | 1449 EXPECT_TRUE(child->screen_space_transform_is_animating()); |
| 1444 break; | 1450 break; |
| 1445 case 2: { | 1451 case 2: { |
| 1446 // The animation is removed, the transform that was set afterward is | 1452 // The animation is stopped, the transform that was set afterward is |
| 1447 // applied. | 1453 // applied. |
| 1448 gfx::Transform expected_transform; | 1454 gfx::Transform expected_transform; |
| 1449 expected_transform.Translate(10.f, 10.f); | 1455 expected_transform.Translate(10.f, 10.f); |
| 1450 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | 1456 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 1451 child->DrawTransform()); | 1457 child->DrawTransform()); |
| 1452 EXPECT_FALSE(child->screen_space_transform_is_animating()); | 1458 EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 1453 EndTest(); | 1459 animation_stopped_ = true; |
| 1460 PostSetNeedsCommitToMainThread(); | |
| 1454 break; | 1461 break; |
| 1455 } | 1462 } |
| 1456 default: | |
| 1457 NOTREACHED(); | |
| 1458 } | 1463 } |
| 1459 } | 1464 } |
| 1460 | 1465 |
| 1466 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | |
| 1467 if (host_impl->sync_tree()->source_frame_number() >= last_frame_number_) { | |
| 1468 // Check that eventurally the animation is removed. | |
|
ajuma
2017/04/11 23:32:02
'eventually'
| |
| 1469 EXPECT_FALSE(player_child_impl_->has_any_animation()); | |
| 1470 EndTest(); | |
| 1471 } | |
| 1472 } | |
| 1473 | |
| 1474 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | |
| 1475 bool has_unfinished_animation) override { | |
| 1476 // Non impl only animations are removed during commit. After the animation | |
| 1477 // is fully stopped on compositor thread, make sure another commit happens. | |
| 1478 if (animation_stopped_ && !has_unfinished_animation) { | |
| 1479 last_frame_number_ = | |
| 1480 std::min(last_frame_number_, | |
| 1481 host_impl->active_tree()->source_frame_number() + 1); | |
| 1482 PostSetNeedsCommitToMainThread(); | |
| 1483 } | |
| 1484 } | |
| 1485 | |
| 1461 void AfterTest() override {} | 1486 void AfterTest() override {} |
| 1462 | 1487 |
| 1463 private: | 1488 private: |
| 1464 scoped_refptr<Layer> layer_; | 1489 scoped_refptr<Layer> layer_; |
| 1465 FakeContentLayerClient client_; | 1490 FakeContentLayerClient client_; |
| 1491 | |
| 1492 int last_frame_number_; | |
| 1493 bool animation_stopped_; | |
| 1466 }; | 1494 }; |
| 1467 | 1495 |
| 1468 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestRemoveAnimation); | 1496 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestRemoveAnimation); |
| 1469 | 1497 |
| 1470 class LayerTreeHostAnimationTestIsAnimating | 1498 class LayerTreeHostAnimationTestIsAnimating |
| 1471 : public LayerTreeHostAnimationTest { | 1499 : public LayerTreeHostAnimationTest { |
| 1472 public: | 1500 public: |
| 1473 void SetupTree() override { | 1501 void SetupTree() override { |
| 1474 LayerTreeHostAnimationTest::SetupTree(); | 1502 LayerTreeHostAnimationTest::SetupTree(); |
| 1475 layer_ = FakePictureLayer::Create(&client_); | 1503 layer_ = FakePictureLayer::Create(&client_); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1861 private: | 1889 private: |
| 1862 scoped_refptr<Layer> layer_; | 1890 scoped_refptr<Layer> layer_; |
| 1863 FakeContentLayerClient client_; | 1891 FakeContentLayerClient client_; |
| 1864 }; | 1892 }; |
| 1865 | 1893 |
| 1866 MULTI_THREAD_TEST_F( | 1894 MULTI_THREAD_TEST_F( |
| 1867 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); | 1895 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); |
| 1868 | 1896 |
| 1869 } // namespace | 1897 } // namespace |
| 1870 } // namespace cc | 1898 } // namespace cc |
| OLD | NEW |