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/texture_layer.h" | 5 #include "cc/texture_layer.h" |
6 | 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/callback.h" |
7 #include "cc/layer_tree_host.h" | 10 #include "cc/layer_tree_host.h" |
8 #include "cc/single_thread_proxy.h" | 11 #include "cc/single_thread_proxy.h" |
9 #include "cc/test/fake_impl_proxy.h" | 12 #include "cc/test/fake_impl_proxy.h" |
10 #include "cc/test/fake_layer_tree_host_client.h" | 13 #include "cc/test/fake_layer_tree_host_client.h" |
11 #include "cc/test/fake_layer_tree_host_impl.h" | 14 #include "cc/test/fake_layer_tree_host_impl.h" |
| 15 #include "cc/test/layer_tree_test_common.h" |
12 #include "cc/texture_layer_impl.h" | 16 #include "cc/texture_layer_impl.h" |
13 #include "cc/thread.h" | 17 #include "cc/thread.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
16 | 20 |
17 using ::testing::Mock; | 21 using ::testing::Mock; |
18 using ::testing::_; | 22 using ::testing::_; |
19 using ::testing::AtLeast; | 23 using ::testing::AtLeast; |
20 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
21 | 25 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 97 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
94 } | 98 } |
95 | 99 |
96 TEST_F(TextureLayerTest, syncImplWhenDrawing) | 100 TEST_F(TextureLayerTest, syncImplWhenDrawing) |
97 { | 101 { |
98 gfx::RectF dirtyRect(0, 0, 1, 1); | 102 gfx::RectF dirtyRect(0, 0, 1, 1); |
99 | 103 |
100 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); | 104 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); |
101 ASSERT_TRUE(testLayer); | 105 ASSERT_TRUE(testLayer); |
102 scoped_ptr<TextureLayerImpl> implLayer; | 106 scoped_ptr<TextureLayerImpl> implLayer; |
103 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1); | 107 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1, false); |
104 ASSERT_TRUE(implLayer); | 108 ASSERT_TRUE(implLayer); |
105 | 109 |
106 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); | 110 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); |
107 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); | 111 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); |
108 m_layerTreeHost->setRootLayer(testLayer); | 112 m_layerTreeHost->setRootLayer(testLayer); |
109 testLayer->setTextureId(1); | 113 testLayer->setTextureId(1); |
110 testLayer->setIsDrawable(true); | 114 testLayer->setIsDrawable(true); |
111 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 115 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
112 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); | 116 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); |
113 | 117 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); | 181 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
178 testLayer->setTextureId(1); | 182 testLayer->setTextureId(1); |
179 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 183 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
180 | 184 |
181 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); | 185 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); |
182 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); | 186 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
183 testLayer->removeFromParent(); | 187 testLayer->removeFromParent(); |
184 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 188 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
185 } | 189 } |
186 | 190 |
| 191 class MockMailboxCallback { |
| 192 public: |
| 193 MOCK_METHOD2(Release, void(const std::string& mailbox, unsigned syncPoint)); |
| 194 }; |
| 195 |
| 196 struct CommonMailboxObjects { |
| 197 CommonMailboxObjects() |
| 198 : m_mailbox1(64, '1') |
| 199 , m_mailbox2(64, '2') |
| 200 { |
| 201 m_releaseMailbox1 = base::Bind(&MockMailboxCallback::Release, |
| 202 base::Unretained(&m_mockCallback), |
| 203 m_mailbox1); |
| 204 m_releaseMailbox2 = base::Bind(&MockMailboxCallback::Release, |
| 205 base::Unretained(&m_mockCallback), |
| 206 m_mailbox2); |
| 207 } |
| 208 |
| 209 std::string m_mailbox1; |
| 210 std::string m_mailbox2; |
| 211 MockMailboxCallback m_mockCallback; |
| 212 TextureLayer::MailboxCallback m_releaseMailbox1; |
| 213 TextureLayer::MailboxCallback m_releaseMailbox2; |
| 214 }; |
| 215 |
| 216 TEST_F(TextureLayerTest, testImplLayerCallbacks) |
| 217 { |
| 218 CommonMailboxObjects m_testData; |
| 219 { |
| 220 scoped_ptr<TextureLayerImpl> implLayer; |
| 221 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1, true); |
| 222 ASSERT_TRUE(implLayer); |
| 223 |
| 224 // Test setting identical mailbox. |
| 225 EXPECT_CALL(m_testData.m_mockCallback, Release(_, _)).Times(0); |
| 226 implLayer->setTextureMailbox(m_testData.m_mailbox1, |
| 227 m_testData.m_releaseMailbox1); |
| 228 implLayer->setTextureMailbox(m_testData.m_mailbox1, |
| 229 m_testData.m_releaseMailbox1); |
| 230 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); |
| 231 |
| 232 // Test multiple commits without a draw. |
| 233 EXPECT_CALL(m_testData.m_mockCallback, |
| 234 Release(m_testData.m_mailbox1, _)).Times(1); |
| 235 implLayer->setTextureMailbox(m_testData.m_mailbox2, |
| 236 m_testData.m_releaseMailbox2); |
| 237 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); |
| 238 |
| 239 // Test resetting the mailbox. |
| 240 EXPECT_CALL(m_testData.m_mockCallback, |
| 241 Release(m_testData.m_mailbox2, _)).Times(1); |
| 242 implLayer->setTextureMailbox(std::string(), |
| 243 TextureLayer::MailboxCallback()); |
| 244 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); |
| 245 |
| 246 // Test destructor. |
| 247 EXPECT_CALL(m_testData.m_mockCallback, |
| 248 Release(m_testData.m_mailbox1, _)).Times(1); |
| 249 implLayer->setTextureMailbox(m_testData.m_mailbox1, |
| 250 m_testData.m_releaseMailbox1); |
| 251 } |
| 252 } |
| 253 |
| 254 class TextureLayerWithMailboxTest : public TextureLayerTest { |
| 255 protected: |
| 256 virtual void TearDown() |
| 257 { |
| 258 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); |
| 259 EXPECT_CALL(m_testData.m_mockCallback, |
| 260 Release(m_testData.m_mailbox1, _)).Times(1); |
| 261 TextureLayerTest::TearDown(); |
| 262 } |
| 263 |
| 264 CommonMailboxObjects m_testData; |
| 265 }; |
| 266 |
| 267 TEST_F(TextureLayerWithMailboxTest, replaceMailboxOnMainThreadBeforeCommit) |
| 268 { |
| 269 scoped_refptr<TextureLayer> testLayer = TextureLayer::createForMailbox(); |
| 270 ASSERT_TRUE(testLayer); |
| 271 |
| 272 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 273 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); |
| 274 m_layerTreeHost->setRootLayer(testLayer); |
| 275 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 276 |
| 277 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 278 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
| 279 testLayer->setTextureMailbox(m_testData.m_mailbox1, |
| 280 m_testData.m_releaseMailbox1); |
| 281 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 282 |
| 283 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 284 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
| 285 EXPECT_CALL(m_testData.m_mockCallback, |
| 286 Release(m_testData.m_mailbox1, _)).Times(1); |
| 287 testLayer->setTextureMailbox(m_testData.m_mailbox2, |
| 288 m_testData.m_releaseMailbox2); |
| 289 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 290 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); |
| 291 |
| 292 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 293 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
| 294 EXPECT_CALL(m_testData.m_mockCallback, |
| 295 Release(m_testData.m_mailbox2, _)).Times(1); |
| 296 testLayer->setTextureMailbox(std::string(), |
| 297 TextureLayer::MailboxCallback()); |
| 298 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 299 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); |
| 300 |
| 301 // Test destructor. |
| 302 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
| 303 testLayer->setTextureMailbox(m_testData.m_mailbox1, |
| 304 m_testData.m_releaseMailbox1); |
| 305 } |
| 306 |
| 307 class TextureLayerImplWithMailbox : public ThreadedTest { |
| 308 public: |
| 309 TextureLayerImplWithMailbox() |
| 310 : m_resetMailbox(false) |
| 311 { |
| 312 } |
| 313 |
| 314 // Make sure callback is received on main and doesn't block the impl thread. |
| 315 void releaseCallback(unsigned syncPoint) { |
| 316 EXPECT_EQ(true, proxy()->isMainThread()); |
| 317 endTest(); |
| 318 } |
| 319 |
| 320 virtual void beginTest() OVERRIDE |
| 321 { |
| 322 m_layer = TextureLayer::createForMailbox(); |
| 323 m_layer->setIsDrawable(true); |
| 324 m_layerTreeHost->setRootLayer(m_layer); |
| 325 m_layer->setTextureMailbox( |
| 326 std::string(64, '1'), |
| 327 base::Bind(&TextureLayerImplWithMailbox::releaseCallback, |
| 328 base::Unretained(this))); |
| 329 postSetNeedsCommitToMainThread(); |
| 330 } |
| 331 |
| 332 virtual void didCommit() OVERRIDE |
| 333 { |
| 334 if (m_resetMailbox) |
| 335 return; |
| 336 |
| 337 m_layer->setTextureMailbox(std::string(), |
| 338 TextureLayer::MailboxCallback()); |
| 339 m_resetMailbox = true; |
| 340 } |
| 341 |
| 342 virtual void afterTest() OVERRIDE |
| 343 { |
| 344 } |
| 345 |
| 346 private: |
| 347 bool m_resetMailbox; |
| 348 scoped_refptr<TextureLayer> m_layer; |
| 349 }; |
| 350 |
| 351 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailbox); |
| 352 |
187 } // namespace | 353 } // namespace |
188 } // namespace cc | 354 } // namespace cc |
OLD | NEW |