| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layers/layer.h" | 5 #include "cc/layers/layer.h" |
| 6 | 6 |
| 7 #include "cc/animation/keyframed_animation_curve.h" | 7 #include "cc/animation/keyframed_animation_curve.h" |
| 8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
| 9 #include "cc/base/thread.h" | 9 #include "cc/base/thread.h" |
| 10 #include "cc/layers/layer_impl.h" | 10 #include "cc/layers/layer_impl.h" |
| 11 #include "cc/resources/layer_painter.h" | 11 #include "cc/resources/layer_painter.h" |
| 12 #include "cc/test/animation_test_common.h" | 12 #include "cc/test/animation_test_common.h" |
| 13 #include "cc/test/fake_impl_proxy.h" | 13 #include "cc/test/fake_impl_proxy.h" |
| 14 #include "cc/test/fake_layer_tree_host_client.h" | 14 #include "cc/test/fake_layer_tree_host_client.h" |
| 15 #include "cc/test/fake_layer_tree_host_impl.h" | 15 #include "cc/test/fake_layer_tree_host_impl.h" |
| 16 #include "cc/test/geometry_test_utils.h" | 16 #include "cc/test/geometry_test_utils.h" |
| 17 #include "cc/trees/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
| 18 #include "cc/trees/single_thread_proxy.h" | 18 #include "cc/trees/single_thread_proxy.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/gfx/transform.h" | 21 #include "ui/gfx/transform.h" |
| 22 | 22 |
| 23 using ::testing::AnyNumber; | 23 using ::testing::AnyNumber; |
| 24 using ::testing::AtLeast; | 24 using ::testing::AtLeast; |
| 25 using ::testing::Mock; | 25 using ::testing::Mock; |
| 26 using ::testing::StrictMock; | 26 using ::testing::StrictMock; |
| 27 using ::testing::_; | 27 using ::testing::_; |
| 28 | 28 |
| 29 #define EXPECT_SET_NEEDS_COMMIT(expect, codeToTest) do { \ | 29 #define EXPECT_SET_NEEDS_COMMIT(expect, code_to_test) do { \ |
| 30 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \ | 30 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \ |
| 31 codeToTest; \ | 31 code_to_test; \ |
| 32 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ | 32 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ |
| 33 } while (false) | 33 } while (false) |
| 34 | 34 |
| 35 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, codeToTest) do { \ | 35 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) do { \ |
| 36 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ | 36 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ |
| 37 codeToTest; \ | 37 code_to_test; \ |
| 38 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ | 38 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ |
| 39 } while (false) | 39 } while (false) |
| 40 | 40 |
| 41 | 41 |
| 42 namespace cc { | 42 namespace cc { |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 class MockLayerTreeHost : public LayerTreeHost { | 45 class MockLayerTreeHost : public LayerTreeHost { |
| 46 public: | 46 public: |
| 47 MockLayerTreeHost(LayerTreeHostClient* client) | 47 MockLayerTreeHost(LayerTreeHostClient* client) |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 EXPECT_FALSE(child3_->parent()); | 385 EXPECT_FALSE(child3_->parent()); |
| 386 } | 386 } |
| 387 | 387 |
| 388 TEST_F(LayerTest, SetChildren) { | 388 TEST_F(LayerTest, SetChildren) { |
| 389 scoped_refptr<Layer> old_parent = Layer::Create(); | 389 scoped_refptr<Layer> old_parent = Layer::Create(); |
| 390 scoped_refptr<Layer> new_parent = Layer::Create(); | 390 scoped_refptr<Layer> new_parent = Layer::Create(); |
| 391 | 391 |
| 392 scoped_refptr<Layer> child1 = Layer::Create(); | 392 scoped_refptr<Layer> child1 = Layer::Create(); |
| 393 scoped_refptr<Layer> child2 = Layer::Create(); | 393 scoped_refptr<Layer> child2 = Layer::Create(); |
| 394 | 394 |
| 395 std::vector<scoped_refptr<Layer> > newChildren; | 395 std::vector<scoped_refptr<Layer> > new_children; |
| 396 newChildren.push_back(child1); | 396 new_children.push_back(child1); |
| 397 newChildren.push_back(child2); | 397 new_children.push_back(child2); |
| 398 | 398 |
| 399 // Set up and verify initial test conditions: child1 has a parent, child2 has | 399 // Set up and verify initial test conditions: child1 has a parent, child2 has |
| 400 // no parent. | 400 // no parent. |
| 401 old_parent->AddChild(child1); | 401 old_parent->AddChild(child1); |
| 402 ASSERT_EQ(0U, new_parent->children().size()); | 402 ASSERT_EQ(0U, new_parent->children().size()); |
| 403 EXPECT_EQ(old_parent.get(), child1->parent()); | 403 EXPECT_EQ(old_parent.get(), child1->parent()); |
| 404 EXPECT_FALSE(child2->parent()); | 404 EXPECT_FALSE(child2->parent()); |
| 405 | 405 |
| 406 new_parent->SetLayerTreeHost(layer_tree_host_.get()); | 406 new_parent->SetLayerTreeHost(layer_tree_host_.get()); |
| 407 | 407 |
| 408 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 408 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 409 AtLeast(1), new_parent->SetChildren(newChildren)); | 409 AtLeast(1), new_parent->SetChildren(new_children)); |
| 410 | 410 |
| 411 ASSERT_EQ(2U, new_parent->children().size()); | 411 ASSERT_EQ(2U, new_parent->children().size()); |
| 412 EXPECT_EQ(new_parent.get(), child1->parent()); | 412 EXPECT_EQ(new_parent.get(), child1->parent()); |
| 413 EXPECT_EQ(new_parent.get(), child2->parent()); | 413 EXPECT_EQ(new_parent.get(), child2->parent()); |
| 414 | 414 |
| 415 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); | 415 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); |
| 416 } | 416 } |
| 417 | 417 |
| 418 TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) { | 418 TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) { |
| 419 CreateSimpleTestTree(); | 419 CreateSimpleTestTree(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 EXPECT_EQ(parent_.get(), child1_->RootLayer()); | 464 EXPECT_EQ(parent_.get(), child1_->RootLayer()); |
| 465 EXPECT_EQ(parent_.get(), child2_->RootLayer()); | 465 EXPECT_EQ(parent_.get(), child2_->RootLayer()); |
| 466 EXPECT_EQ(parent_.get(), child3_->RootLayer()); | 466 EXPECT_EQ(parent_.get(), child3_->RootLayer()); |
| 467 EXPECT_EQ(grand_child3_.get(), child4->RootLayer()); | 467 EXPECT_EQ(grand_child3_.get(), child4->RootLayer()); |
| 468 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); | 468 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); |
| 469 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); | 469 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); |
| 470 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); | 470 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); |
| 471 } | 471 } |
| 472 | 472 |
| 473 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { | 473 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { |
| 474 // The semantics for setNeedsDisplay which are tested here: | 474 // The semantics for SetNeedsDisplay which are tested here: |
| 475 // 1. sets NeedsDisplay flag appropriately. | 475 // 1. sets NeedsDisplay flag appropriately. |
| 476 // 2. indirectly calls SetNeedsCommit, exactly once for each call to | 476 // 2. indirectly calls SetNeedsCommit, exactly once for each call to |
| 477 // SetNeedsDisplay. | 477 // SetNeedsDisplay. |
| 478 | 478 |
| 479 scoped_refptr<Layer> test_layer = Layer::Create(); | 479 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 480 test_layer->SetLayerTreeHost(layer_tree_host_.get()); | 480 test_layer->SetLayerTreeHost(layer_tree_host_.get()); |
| 481 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); | 481 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
| 482 | 482 |
| 483 gfx::Size test_bounds = gfx::Size(501, 508); | 483 gfx::Size test_bounds = gfx::Size(501, 508); |
| 484 | 484 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetDebugName("Test Layer")); | 559 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetDebugName("Test Layer")); |
| 560 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetDrawCheckerboardForMissingTiles( | 560 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetDrawCheckerboardForMissingTiles( |
| 561 !test_layer->DrawCheckerboardForMissingTiles())); | 561 !test_layer->DrawCheckerboardForMissingTiles())); |
| 562 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetForceRenderSurface(true)); | 562 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetForceRenderSurface(true)); |
| 563 | 563 |
| 564 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, test_layer->SetMaskLayer( | 564 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, test_layer->SetMaskLayer( |
| 565 dummy_layer1.get())); | 565 dummy_layer1.get())); |
| 566 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, test_layer->SetReplicaLayer( | 566 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, test_layer->SetReplicaLayer( |
| 567 dummy_layer2.get())); | 567 dummy_layer2.get())); |
| 568 | 568 |
| 569 // The above tests should not have caused a change to the needsDisplay flag. | 569 // The above tests should not have caused a change to the needs_display flag. |
| 570 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 570 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 571 | 571 |
| 572 // As layers are removed from the tree, they will cause a tree sync. | 572 // As layers are removed from the tree, they will cause a tree sync. |
| 573 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber())); | 573 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber())); |
| 574 } | 574 } |
| 575 | 575 |
| 576 TEST_F(LayerTest, SetBoundsTriggersSetNeedsRedrawAfterGettingNonEmptyBounds) { | 576 TEST_F(LayerTest, SetBoundsTriggersSetNeedsRedrawAfterGettingNonEmptyBounds) { |
| 577 scoped_refptr<Layer> test_layer = Layer::Create(); | 577 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 578 test_layer->SetLayerTreeHost(layer_tree_host_.get()); | 578 test_layer->SetLayerTreeHost(layer_tree_host_.get()); |
| 579 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); | 579 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
| 580 | 580 |
| 581 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 581 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 582 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(gfx::Size(0, 10))); | 582 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(gfx::Size(0, 10))); |
| 583 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 583 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 584 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(gfx::Size(10, 10))); | 584 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(gfx::Size(10, 10))); |
| 585 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); | 585 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
| 586 | 586 |
| 587 test_layer->ResetNeedsDisplayForTesting(); | 587 test_layer->ResetNeedsDisplayForTesting(); |
| 588 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 588 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 589 | 589 |
| 590 // Calling setBounds only invalidates on the first time. | 590 // Calling SetBounds only invalidates on the first time. |
| 591 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(gfx::Size(7, 10))); | 591 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBounds(gfx::Size(7, 10))); |
| 592 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 592 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 593 } | 593 } |
| 594 | 594 |
| 595 TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { | 595 TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { |
| 596 scoped_refptr<Layer> test_layer = Layer::Create(); | 596 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 597 scoped_ptr<LayerImpl> impl_layer = | 597 scoped_ptr<LayerImpl> impl_layer = |
| 598 LayerImpl::Create(host_impl_.active_tree(), 1); | 598 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 599 | 599 |
| 600 test_layer->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); | 600 test_layer->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 layer->SetLayerTreeHost(layer_tree_host.get()); | 1002 layer->SetLayerTreeHost(layer_tree_host.get()); |
| 1003 AssertLayerTreeHostMatchesForSubtree(layer.get(), layer_tree_host.get()); | 1003 AssertLayerTreeHostMatchesForSubtree(layer.get(), layer_tree_host.get()); |
| 1004 | 1004 |
| 1005 // Case 3: with a LayerTreeHost where accelerated animation is disabled, the | 1005 // Case 3: with a LayerTreeHost where accelerated animation is disabled, the |
| 1006 // animation should be rejected. | 1006 // animation should be rejected. |
| 1007 EXPECT_FALSE(AddTestAnimation(layer.get())); | 1007 EXPECT_FALSE(AddTestAnimation(layer.get())); |
| 1008 } | 1008 } |
| 1009 | 1009 |
| 1010 } // namespace | 1010 } // namespace |
| 1011 } // namespace cc | 1011 } // namespace cc |
| OLD | NEW |