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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/texture_layer.h" | 7 #include "cc/texture_layer.h" |
8 | 8 |
9 #include "cc/layer_tree_host.h" | 9 #include "cc/layer_tree_host.h" |
10 #include "cc/single_thread_proxy.h" | 10 #include "cc/single_thread_proxy.h" |
11 #include "cc/texture_layer_impl.h" | 11 #include "cc/texture_layer_impl.h" |
12 #include "cc/test/fake_layer_tree_host_client.h" | 12 #include "cc/test/fake_layer_tree_host_client.h" |
13 #include "cc/thread.h" | |
14 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 using namespace cc; | 16 using namespace cc; |
18 using ::testing::Mock; | 17 using ::testing::Mock; |
19 using ::testing::_; | 18 using ::testing::_; |
20 using ::testing::AtLeast; | 19 using ::testing::AtLeast; |
21 using ::testing::AnyNumber; | 20 using ::testing::AnyNumber; |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 class MockLayerImplTreeHost : public LayerTreeHost { | 24 class MockLayerImplTreeHost : public LayerTreeHost { |
26 public: | 25 public: |
27 MockLayerImplTreeHost() | 26 MockLayerImplTreeHost() |
28 : LayerTreeHost(&m_fakeClient, LayerTreeSettings()) | 27 : LayerTreeHost(&m_fakeClient, LayerTreeSettings()) |
29 { | 28 { |
30 initialize(scoped_ptr<Thread>(NULL)); | 29 initialize(); |
31 } | 30 } |
32 | 31 |
33 MOCK_METHOD0(acquireLayerTextures, void()); | 32 MOCK_METHOD0(acquireLayerTextures, void()); |
34 MOCK_METHOD0(setNeedsCommit, void()); | 33 MOCK_METHOD0(setNeedsCommit, void()); |
35 | 34 |
36 private: | 35 private: |
37 FakeLayerImplTreeHostClient m_fakeClient; | 36 FakeLayerImplTreeHostClient m_fakeClient; |
38 }; | 37 }; |
39 | 38 |
40 | 39 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 90 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
92 } | 91 } |
93 | 92 |
94 TEST_F(TextureLayerTest, syncImplWhenDrawing) | 93 TEST_F(TextureLayerTest, syncImplWhenDrawing) |
95 { | 94 { |
96 gfx::RectF dirtyRect(0, 0, 1, 1); | 95 gfx::RectF dirtyRect(0, 0, 1, 1); |
97 | 96 |
98 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); | 97 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); |
99 ASSERT_TRUE(testLayer); | 98 ASSERT_TRUE(testLayer); |
100 scoped_ptr<TextureLayerImpl> implLayer; | 99 scoped_ptr<TextureLayerImpl> implLayer; |
101 implLayer = TextureLayerImpl::create(1); | 100 { |
| 101 DebugScopedSetImplThread setImplThread; |
| 102 implLayer = TextureLayerImpl::create(1); |
| 103 } |
102 ASSERT_TRUE(implLayer); | 104 ASSERT_TRUE(implLayer); |
103 | 105 |
104 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); | 106 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); |
105 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); | 107 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); |
106 m_layerTreeHost->setRootLayer(testLayer); | 108 m_layerTreeHost->setRootLayer(testLayer); |
107 testLayer->setTextureId(1); | 109 testLayer->setTextureId(1); |
108 testLayer->setIsDrawable(true); | 110 testLayer->setIsDrawable(true); |
109 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 111 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
110 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); | 112 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); |
111 | 113 |
(...skipping 23 matching lines...) Expand all Loading... |
135 testLayer->pushPropertiesTo(implLayer.get()); // fake commit | 137 testLayer->pushPropertiesTo(implLayer.get()); // fake commit |
136 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 138 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
137 | 139 |
138 // Second draw with layer in non-drawable state: no texture | 140 // Second draw with layer in non-drawable state: no texture |
139 // acquisition. | 141 // acquisition. |
140 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); | 142 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
141 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(0); | 143 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(0); |
142 testLayer->willModifyTexture(); | 144 testLayer->willModifyTexture(); |
143 testLayer->setNeedsDisplayRect(dirtyRect); | 145 testLayer->setNeedsDisplayRect(dirtyRect); |
144 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 146 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 147 |
| 148 { |
| 149 DebugScopedSetImplThread setImplThread; |
| 150 delete implLayer.release(); |
| 151 } |
145 } | 152 } |
146 | 153 |
147 TEST_F(TextureLayerTest, syncImplWhenRemovingFromTree) | 154 TEST_F(TextureLayerTest, syncImplWhenRemovingFromTree) |
148 { | 155 { |
149 scoped_refptr<Layer> rootLayer = Layer::create(); | 156 scoped_refptr<Layer> rootLayer = Layer::create(); |
150 ASSERT_TRUE(rootLayer); | 157 ASSERT_TRUE(rootLayer); |
151 scoped_refptr<Layer> childLayer = Layer::create(); | 158 scoped_refptr<Layer> childLayer = Layer::create(); |
152 ASSERT_TRUE(childLayer); | 159 ASSERT_TRUE(childLayer); |
153 rootLayer->addChild(childLayer); | 160 rootLayer->addChild(childLayer); |
154 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); | 161 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); |
(...skipping 21 matching lines...) Expand all Loading... |
176 testLayer->setTextureId(1); | 183 testLayer->setTextureId(1); |
177 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 184 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
178 | 185 |
179 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); | 186 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); |
180 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); | 187 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
181 testLayer->removeFromParent(); | 188 testLayer->removeFromParent(); |
182 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 189 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
183 } | 190 } |
184 | 191 |
185 } // anonymous namespace | 192 } // anonymous namespace |
OLD | NEW |