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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/layer.h" | 7 #include "cc/layer.h" |
8 | 8 |
9 #include "cc/keyframed_animation_curve.h" | 9 #include "cc/keyframed_animation_curve.h" |
10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
11 #include "cc/layer_painter.h" | 11 #include "cc/layer_painter.h" |
12 #include "cc/layer_tree_host.h" | 12 #include "cc/layer_tree_host.h" |
13 #include "cc/settings.h" | 13 #include "cc/settings.h" |
14 #include "cc/single_thread_proxy.h" | 14 #include "cc/single_thread_proxy.h" |
15 #include "cc/thread.h" | |
16 #include "cc/test/fake_layer_tree_host_client.h" | 15 #include "cc/test/fake_layer_tree_host_client.h" |
17 #include "cc/test/geometry_test_utils.h" | 16 #include "cc/test/geometry_test_utils.h" |
18 #include "cc/test/test_common.h" | 17 #include "cc/test/test_common.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 #include <public/WebTransformationMatrix.h> | 20 #include <public/WebTransformationMatrix.h> |
22 | 21 |
23 using namespace cc; | 22 using namespace cc; |
24 using namespace WebKitTests; | 23 using namespace WebKitTests; |
25 using WebKit::WebTransformationMatrix; | 24 using WebKit::WebTransformationMatrix; |
26 using ::testing::Mock; | 25 using ::testing::Mock; |
27 using ::testing::_; | 26 using ::testing::_; |
28 using ::testing::AtLeast; | 27 using ::testing::AtLeast; |
29 using ::testing::AnyNumber; | 28 using ::testing::AnyNumber; |
30 | 29 |
31 #define EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(numTimesExpectedSetNeedsCom
mit, codeToTest) do { \ | 30 #define EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(numTimesExpectedSetNeedsCom
mit, codeToTest) do { \ |
32 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times((numTimesExpectedS
etNeedsCommit)); \ | 31 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times((numTimesExpectedS
etNeedsCommit)); \ |
33 codeToTest;
\ | 32 codeToTest;
\ |
34 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
\ | 33 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
\ |
35 } while (0) | 34 } while (0) |
36 | 35 |
37 namespace { | 36 namespace { |
38 | 37 |
39 class MockLayerImplTreeHost : public LayerTreeHost { | 38 class MockLayerImplTreeHost : public LayerTreeHost { |
40 public: | 39 public: |
41 MockLayerImplTreeHost() | 40 MockLayerImplTreeHost() |
42 : LayerTreeHost(&m_fakeClient, LayerTreeSettings()) | 41 : LayerTreeHost(&m_fakeClient, LayerTreeSettings()) |
43 { | 42 { |
44 initialize(scoped_ptr<Thread>(NULL)); | 43 initialize(); |
45 } | 44 } |
46 | 45 |
47 MOCK_METHOD0(setNeedsCommit, void()); | 46 MOCK_METHOD0(setNeedsCommit, void()); |
48 | 47 |
49 private: | 48 private: |
50 FakeLayerImplTreeHostClient m_fakeClient; | 49 FakeLayerImplTreeHostClient m_fakeClient; |
51 }; | 50 }; |
52 | 51 |
53 class MockLayerPainter : public LayerPainter { | 52 class MockLayerPainter : public LayerPainter { |
54 public: | 53 public: |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 // The above tests should not have caused a change to the needsDisplay flag. | 521 // The above tests should not have caused a change to the needsDisplay flag. |
523 EXPECT_FALSE(testLayer->needsDisplay()); | 522 EXPECT_FALSE(testLayer->needsDisplay()); |
524 | 523 |
525 // Test properties that should call setNeedsDisplay and setNeedsCommit | 524 // Test properties that should call setNeedsDisplay and setNeedsCommit |
526 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setBounds(gfx::Si
ze(5, 10))); | 525 EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setBounds(gfx::Si
ze(5, 10))); |
527 EXPECT_TRUE(testLayer->needsDisplay()); | 526 EXPECT_TRUE(testLayer->needsDisplay()); |
528 } | 527 } |
529 | 528 |
530 TEST_F(LayerTest, verifyPushPropertiesAccumulatesUpdateRect) | 529 TEST_F(LayerTest, verifyPushPropertiesAccumulatesUpdateRect) |
531 { | 530 { |
| 531 DebugScopedSetImplThread setImplThread; |
| 532 |
532 scoped_refptr<Layer> testLayer = Layer::create(); | 533 scoped_refptr<Layer> testLayer = Layer::create(); |
533 scoped_ptr<LayerImpl> implLayer = LayerImpl::create(1); | 534 scoped_ptr<LayerImpl> implLayer = LayerImpl::create(1); |
534 | 535 |
535 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5))); | 536 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5))); |
536 testLayer->pushPropertiesTo(implLayer.get()); | 537 testLayer->pushPropertiesTo(implLayer.get()); |
537 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5)), implLayer-
>updateRect()); | 538 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5)), implLayer-
>updateRect()); |
538 | 539 |
539 // The LayerImpl's updateRect should be accumulated here, since we did not d
o anything to clear it. | 540 // The LayerImpl's updateRect should be accumulated here, since we did not d
o anything to clear it. |
540 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5,
5))); | 541 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5,
5))); |
541 testLayer->pushPropertiesTo(implLayer.get()); | 542 testLayer->pushPropertiesTo(implLayer.get()); |
542 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(15, 15)), implLaye
r->updateRect()); | 543 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(15, 15)), implLaye
r->updateRect()); |
543 | 544 |
544 // If we do clear the LayerImpl side, then the next updateRect should be fre
sh without accumulation. | 545 // If we do clear the LayerImpl side, then the next updateRect should be fre
sh without accumulation. |
545 implLayer->resetAllChangeTrackingForSubtree(); | 546 implLayer->resetAllChangeTrackingForSubtree(); |
546 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5,
5))); | 547 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5,
5))); |
547 testLayer->pushPropertiesTo(implLayer.get()); | 548 testLayer->pushPropertiesTo(implLayer.get()); |
548 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)), impl
Layer->updateRect()); | 549 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)), impl
Layer->updateRect()); |
549 } | 550 } |
550 | 551 |
551 class FakeLayerImplTreeHost : public LayerTreeHost { | 552 class FakeLayerImplTreeHost : public LayerTreeHost { |
552 public: | 553 public: |
553 static scoped_ptr<FakeLayerImplTreeHost> create() | 554 static scoped_ptr<FakeLayerImplTreeHost> create() |
554 { | 555 { |
555 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost); | 556 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost); |
556 // The initialize call will fail, since our client doesn't provide a val
id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i
gnore the return value. | 557 // The initialize call will fail, since our client doesn't provide a val
id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i
gnore the return value. |
557 host->initialize(scoped_ptr<Thread>(NULL)); | 558 host->initialize(); |
558 return host.Pass(); | 559 return host.Pass(); |
559 } | 560 } |
560 | 561 |
561 private: | 562 private: |
562 FakeLayerImplTreeHost() | 563 FakeLayerImplTreeHost() |
563 : LayerTreeHost(&m_client, LayerTreeSettings()) | 564 : LayerTreeHost(&m_client, LayerTreeSettings()) |
564 { | 565 { |
565 } | 566 } |
566 | 567 |
567 FakeLayerImplTreeHostClient m_client; | 568 FakeLayerImplTreeHostClient m_client; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 scoped_refptr<MockLayer> layer(new MockLayer); | 793 scoped_refptr<MockLayer> layer(new MockLayer); |
793 EXPECT_FALSE(layer->needsDisplay()); | 794 EXPECT_FALSE(layer->needsDisplay()); |
794 layer->setBounds(gfx::Size(0, 10)); | 795 layer->setBounds(gfx::Size(0, 10)); |
795 EXPECT_FALSE(layer->needsDisplay()); | 796 EXPECT_FALSE(layer->needsDisplay()); |
796 layer->setBounds(gfx::Size(10, 10)); | 797 layer->setBounds(gfx::Size(10, 10)); |
797 EXPECT_TRUE(layer->needsDisplay()); | 798 EXPECT_TRUE(layer->needsDisplay()); |
798 } | 799 } |
799 | 800 |
800 | 801 |
801 } // namespace | 802 } // namespace |
OLD | NEW |