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/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" |
| 11 #include "cc/layer_tree_impl.h" | |
| 8 #include "cc/single_thread_proxy.h" | 12 #include "cc/single_thread_proxy.h" |
| 9 #include "cc/test/fake_impl_proxy.h" | 13 #include "cc/test/fake_impl_proxy.h" |
| 10 #include "cc/test/fake_layer_tree_host_client.h" | 14 #include "cc/test/fake_layer_tree_host_client.h" |
| 11 #include "cc/test/fake_layer_tree_host_impl.h" | 15 #include "cc/test/fake_layer_tree_host_impl.h" |
| 16 #include "cc/test/layer_tree_test_common.h" | |
| 12 #include "cc/texture_layer_impl.h" | 17 #include "cc/texture_layer_impl.h" |
| 13 #include "cc/thread.h" | 18 #include "cc/thread.h" |
| 19 | |
|
danakj
2013/01/07 18:24:28
no newline here
alexst (slow to review)
2013/01/07 18:38:04
Done.
| |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 22 |
| 17 using ::testing::Mock; | 23 using ::testing::Mock; |
| 18 using ::testing::_; | 24 using ::testing::_; |
| 19 using ::testing::AtLeast; | 25 using ::testing::AtLeast; |
| 20 using ::testing::AnyNumber; | 26 using ::testing::AnyNumber; |
| 21 | 27 |
| 22 namespace cc { | 28 namespace cc { |
| 23 namespace { | 29 namespace { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 99 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 94 } | 100 } |
| 95 | 101 |
| 96 TEST_F(TextureLayerTest, syncImplWhenDrawing) | 102 TEST_F(TextureLayerTest, syncImplWhenDrawing) |
| 97 { | 103 { |
| 98 gfx::RectF dirtyRect(0, 0, 1, 1); | 104 gfx::RectF dirtyRect(0, 0, 1, 1); |
| 99 | 105 |
| 100 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); | 106 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); |
| 101 ASSERT_TRUE(testLayer); | 107 ASSERT_TRUE(testLayer); |
| 102 scoped_ptr<TextureLayerImpl> implLayer; | 108 scoped_ptr<TextureLayerImpl> implLayer; |
| 103 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1); | 109 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1, false); |
| 104 ASSERT_TRUE(implLayer); | 110 ASSERT_TRUE(implLayer); |
| 105 | 111 |
| 106 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); | 112 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); |
| 107 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); | 113 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); |
| 108 m_layerTreeHost->setRootLayer(testLayer); | 114 m_layerTreeHost->setRootLayer(testLayer); |
| 109 testLayer->setTextureId(1); | 115 testLayer->setTextureId(1); |
| 110 testLayer->setIsDrawable(true); | 116 testLayer->setIsDrawable(true); |
| 111 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 117 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 112 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); | 118 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); |
| 113 | 119 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); | 183 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
| 178 testLayer->setTextureId(1); | 184 testLayer->setTextureId(1); |
| 179 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 185 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 180 | 186 |
| 181 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); | 187 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); |
| 182 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); | 188 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
| 183 testLayer->removeFromParent(); | 189 testLayer->removeFromParent(); |
| 184 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | 190 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 185 } | 191 } |
| 186 | 192 |
| 193 class MockMailboxCallback { | |
| 194 public: | |
| 195 MOCK_METHOD2(Release, void(const std::string& mailbox, unsigned syncPoint)); | |
| 196 }; | |
| 197 | |
| 198 struct CommonMailboxObjects { | |
| 199 CommonMailboxObjects() | |
| 200 : m_mailbox1(64, '1') | |
| 201 , m_mailbox2(64, '2') | |
| 202 { | |
| 203 m_releaseMailbox1 = base::Bind(&MockMailboxCallback::Release, | |
| 204 base::Unretained(&m_mockCallback), | |
| 205 m_mailbox1); | |
| 206 m_releaseMailbox2 = base::Bind(&MockMailboxCallback::Release, | |
| 207 base::Unretained(&m_mockCallback), | |
| 208 m_mailbox2); | |
| 209 } | |
| 210 | |
| 211 std::string m_mailbox1; | |
| 212 std::string m_mailbox2; | |
| 213 MockMailboxCallback m_mockCallback; | |
| 214 TextureLayer::MailboxCallback m_releaseMailbox1; | |
| 215 TextureLayer::MailboxCallback m_releaseMailbox2; | |
| 216 }; | |
| 217 | |
| 218 class TextureLayerWithMailboxTest : public TextureLayerTest { | |
| 219 protected: | |
| 220 virtual void TearDown() | |
| 221 { | |
| 222 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); | |
| 223 EXPECT_CALL(m_testData.m_mockCallback, | |
| 224 Release(m_testData.m_mailbox1, _)).Times(1); | |
| 225 TextureLayerTest::TearDown(); | |
| 226 } | |
| 227 | |
| 228 CommonMailboxObjects m_testData; | |
| 229 }; | |
| 230 | |
| 231 TEST_F(TextureLayerWithMailboxTest, replaceMailboxOnMainThreadBeforeCommit) | |
| 232 { | |
| 233 scoped_refptr<TextureLayer> testLayer = TextureLayer::createForMailbox(); | |
| 234 ASSERT_TRUE(testLayer); | |
| 235 | |
| 236 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); | |
| 237 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); | |
| 238 m_layerTreeHost->setRootLayer(testLayer); | |
| 239 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | |
| 240 | |
| 241 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); | |
| 242 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); | |
| 243 testLayer->setTextureMailbox(m_testData.m_mailbox1, | |
| 244 m_testData.m_releaseMailbox1); | |
| 245 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | |
| 246 | |
| 247 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); | |
| 248 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); | |
| 249 EXPECT_CALL(m_testData.m_mockCallback, | |
| 250 Release(m_testData.m_mailbox1, _)).Times(1); | |
| 251 testLayer->setTextureMailbox(m_testData.m_mailbox2, | |
| 252 m_testData.m_releaseMailbox2); | |
| 253 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | |
| 254 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); | |
| 255 | |
| 256 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); | |
| 257 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); | |
| 258 EXPECT_CALL(m_testData.m_mockCallback, | |
| 259 Release(m_testData.m_mailbox2, _)).Times(1); | |
| 260 testLayer->setTextureMailbox(std::string(), | |
| 261 TextureLayer::MailboxCallback()); | |
| 262 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); | |
| 263 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); | |
| 264 | |
| 265 // Test destructor. | |
| 266 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); | |
| 267 testLayer->setTextureMailbox(m_testData.m_mailbox1, | |
| 268 m_testData.m_releaseMailbox1); | |
| 269 } | |
| 270 | |
| 271 class TextureLayerImplWithMailboxThreadedCallback : public ThreadedTest { | |
| 272 public: | |
| 273 TextureLayerImplWithMailboxThreadedCallback() | |
| 274 : m_resetMailbox(false) | |
| 275 { | |
| 276 } | |
| 277 | |
| 278 // Make sure callback is received on main and doesn't block the impl thread. | |
| 279 void releaseCallback(unsigned syncPoint) { | |
| 280 EXPECT_EQ(true, proxy()->isMainThread()); | |
| 281 endTest(); | |
| 282 } | |
| 283 | |
| 284 virtual void beginTest() OVERRIDE | |
| 285 { | |
| 286 m_layer = TextureLayer::createForMailbox(); | |
| 287 m_layer->setIsDrawable(true); | |
| 288 m_layerTreeHost->setRootLayer(m_layer); | |
| 289 m_layer->setTextureMailbox( | |
| 290 std::string(64, '1'), | |
| 291 base::Bind( | |
| 292 &TextureLayerImplWithMailboxThreadedCallback::releaseCallback, | |
| 293 base::Unretained(this))); | |
| 294 postSetNeedsCommitToMainThread(); | |
| 295 } | |
| 296 | |
| 297 virtual void didCommit() OVERRIDE | |
| 298 { | |
| 299 if (m_resetMailbox) | |
| 300 return; | |
| 301 | |
| 302 m_layer->setTextureMailbox(std::string(), | |
| 303 TextureLayer::MailboxCallback()); | |
| 304 m_resetMailbox = true; | |
| 305 } | |
| 306 | |
| 307 virtual void afterTest() OVERRIDE | |
| 308 { | |
| 309 } | |
| 310 | |
| 311 private: | |
| 312 bool m_resetMailbox; | |
| 313 scoped_refptr<TextureLayer> m_layer; | |
| 314 }; | |
| 315 | |
| 316 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback); | |
| 317 | |
| 318 class TextureLayerImplWithMailboxTest : public TextureLayerTest { | |
| 319 protected: | |
| 320 virtual void SetUp() | |
| 321 { | |
| 322 TextureLayerTest::SetUp(); | |
| 323 m_layerTreeHost.reset(new MockLayerImplTreeHost); | |
| 324 EXPECT_TRUE(m_hostImpl.initializeRenderer(createFakeOutputSurface())); | |
| 325 } | |
| 326 | |
| 327 CommonMailboxObjects m_testData; | |
| 328 }; | |
| 329 | |
| 330 TEST_F(TextureLayerImplWithMailboxTest, testImplLayerCallbacks) | |
| 331 { | |
| 332 scoped_ptr<TextureLayerImpl> implLayer; | |
| 333 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1, true); | |
| 334 ASSERT_TRUE(implLayer); | |
| 335 | |
| 336 // Test setting identical mailbox. | |
| 337 EXPECT_CALL(m_testData.m_mockCallback, Release(_, _)).Times(0); | |
| 338 implLayer->setTextureMailbox(m_testData.m_mailbox1, | |
| 339 m_testData.m_releaseMailbox1); | |
| 340 implLayer->setTextureMailbox(m_testData.m_mailbox1, | |
| 341 m_testData.m_releaseMailbox1); | |
| 342 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); | |
| 343 | |
| 344 // Test multiple commits without a draw. | |
| 345 EXPECT_CALL(m_testData.m_mockCallback, | |
| 346 Release(m_testData.m_mailbox1, _)).Times(1); | |
| 347 implLayer->setTextureMailbox(m_testData.m_mailbox2, | |
| 348 m_testData.m_releaseMailbox2); | |
| 349 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); | |
| 350 | |
| 351 // Test resetting the mailbox. | |
| 352 EXPECT_CALL(m_testData.m_mockCallback, | |
| 353 Release(m_testData.m_mailbox2, _)).Times(1); | |
| 354 implLayer->setTextureMailbox(std::string(), | |
| 355 TextureLayer::MailboxCallback()); | |
| 356 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback); | |
| 357 | |
| 358 // Test destructor. | |
| 359 EXPECT_CALL(m_testData.m_mockCallback, | |
| 360 Release(m_testData.m_mailbox1, _)).Times(1); | |
| 361 implLayer->setTextureMailbox(m_testData.m_mailbox1, | |
| 362 m_testData.m_releaseMailbox1); | |
| 363 } | |
| 364 | |
| 365 TEST_F(TextureLayerImplWithMailboxTest, testDestructorCallbackOnCreatedResource) | |
| 366 { | |
| 367 scoped_ptr<TextureLayerImpl> implLayer; | |
| 368 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1, true); | |
| 369 ASSERT_TRUE(implLayer); | |
| 370 | |
| 371 EXPECT_CALL(m_testData.m_mockCallback, | |
| 372 Release(m_testData.m_mailbox1, _)).Times(1); | |
| 373 implLayer->setTextureMailbox(m_testData.m_mailbox1, | |
| 374 m_testData.m_releaseMailbox1); | |
| 375 implLayer->willDraw(m_hostImpl.activeTree()->resource_provider()); | |
|
danakj
2013/01/07 18:24:28
if you didDraw() after this, would the test still
alexst (slow to review)
2013/01/07 18:38:04
Yes, should work, added the call.
On 2013/01/07 1
| |
| 376 implLayer->setTextureMailbox(std::string(), | |
| 377 TextureLayer::MailboxCallback()); | |
| 378 } | |
| 379 | |
| 380 TEST_F(TextureLayerImplWithMailboxTest, testCallbackOnInUseResource) | |
| 381 { | |
| 382 EXPECT_CALL(m_testData.m_mockCallback, | |
| 383 Release(m_testData.m_mailbox1, _)).Times(1); | |
| 384 ResourceProvider *provider = m_hostImpl.activeTree()->resource_provider(); | |
| 385 ResourceProvider::ResourceId id = | |
| 386 provider->createResourceFromTextureMailbox( | |
| 387 m_testData.m_mailbox1, | |
| 388 m_testData.m_releaseMailbox1); | |
| 389 | |
| 390 // Transfer some resources to the parent. | |
| 391 ResourceProvider::ResourceIdArray resourceIdsToTransfer; | |
| 392 resourceIdsToTransfer.push_back(id); | |
| 393 TransferableResourceList list; | |
| 394 provider->prepareSendToParent(resourceIdsToTransfer, &list); | |
| 395 EXPECT_TRUE(provider->inUseByConsumer(id)); | |
| 396 provider->deleteResource(id); | |
|
danakj
2013/01/07 18:24:28
can you check expectations after this delete that
alexst (slow to review)
2013/01/07 18:38:04
Done.
| |
| 397 provider->receiveFromParent(list); | |
| 398 } | |
| 399 | |
| 187 } // namespace | 400 } // namespace |
| 188 } // namespace cc | 401 } // namespace cc |
| OLD | NEW |