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/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 | 44 |
| 45 gpu::Mailbox MailboxFromChar(char value) { | 45 gpu::Mailbox MailboxFromChar(char value) { |
| 46 gpu::Mailbox mailbox; | 46 gpu::Mailbox mailbox; |
| 47 memset(mailbox.name, value, sizeof(mailbox.name)); | 47 memset(mailbox.name, value, sizeof(mailbox.name)); |
| 48 return mailbox; | 48 return mailbox; |
| 49 } | 49 } |
| 50 | 50 |
| 51 class MockLayerTreeHost : public LayerTreeHost { | 51 class MockLayerTreeHost : public LayerTreeHost { |
| 52 public: | 52 public: |
| 53 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) | 53 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) |
| 54 : LayerTreeHost(client, NULL, LayerTreeSettings()) { | 54 : LayerTreeHost(client, nullptr, LayerTreeSettings()) { |
| 55 InitializeSingleThreaded(client, base::MessageLoopProxy::current()); | 55 InitializeSingleThreaded(client, base::MessageLoopProxy::current()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 MOCK_METHOD0(SetNeedsCommit, void()); | 58 MOCK_METHOD0(SetNeedsCommit, void()); |
| 59 MOCK_METHOD0(SetNeedsUpdateLayers, void()); | 59 MOCK_METHOD0(SetNeedsUpdateLayers, void()); |
| 60 MOCK_METHOD0(StartRateLimiter, void()); | 60 MOCK_METHOD0(StartRateLimiter, void()); |
| 61 MOCK_METHOD0(StopRateLimiter, void()); | 61 MOCK_METHOD0(StopRateLimiter, void()); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class FakeTextureLayerClient : public TextureLayerClient { | 64 class FakeTextureLayerClient : public TextureLayerClient { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); | 177 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); |
| 178 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 178 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 179 layer_tree_host_->SetViewportSize(gfx::Size(10, 10)); | 179 layer_tree_host_->SetViewportSize(gfx::Size(10, 10)); |
| 180 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 180 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 181 } | 181 } |
| 182 | 182 |
| 183 virtual void TearDown() { | 183 virtual void TearDown() { |
| 184 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 184 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 185 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 185 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 186 | 186 |
| 187 layer_tree_host_->SetRootLayer(NULL); | 187 layer_tree_host_->SetRootLayer(nullptr); |
| 188 layer_tree_host_ = nullptr; | 188 layer_tree_host_ = nullptr; |
| 189 } | 189 } |
| 190 | 190 |
| 191 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 191 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
| 192 FakeImplProxy proxy_; | 192 FakeImplProxy proxy_; |
| 193 FakeLayerTreeHostClient fake_client_; | 193 FakeLayerTreeHostClient fake_client_; |
| 194 TestSharedBitmapManager shared_bitmap_manager_; | 194 TestSharedBitmapManager shared_bitmap_manager_; |
| 195 FakeLayerTreeHostImpl host_impl_; | 195 FakeLayerTreeHostImpl host_impl_; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { | 198 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
| 199 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 199 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(nullpt r); |
|
reveman
2014/10/09 15:08:01
This needs re-formatting.
| |
| 200 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); | 200 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); |
| 201 | 201 |
| 202 // Test properties that should call SetNeedsCommit. All properties need to | 202 // Test properties that should call SetNeedsCommit. All properties need to |
| 203 // be set to new values in order for SetNeedsCommit to be called. | 203 // be set to new values in order for SetNeedsCommit to be called. |
| 204 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); | 204 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); |
| 205 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( | 205 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( |
| 206 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); | 206 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); |
| 207 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( | 207 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( |
| 208 0.5f, 0.5f, 0.5f, 0.5f)); | 208 0.5f, 0.5f, 0.5f, 0.5f)); |
| 209 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); | 209 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); |
| 210 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true)); | 210 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true)); |
| 211 } | 211 } |
| 212 | 212 |
| 213 TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) { | 213 TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) { |
| 214 const gfx::Size layer_bounds(100, 100); | 214 const gfx::Size layer_bounds(100, 100); |
| 215 const gfx::Rect layer_rect(layer_bounds); | 215 const gfx::Rect layer_rect(layer_bounds); |
| 216 const Region layer_region(layer_rect); | 216 const Region layer_region(layer_rect); |
| 217 | 217 |
| 218 scoped_refptr<TextureLayer> layer = TextureLayer::CreateForMailbox(NULL); | 218 scoped_refptr<TextureLayer> layer = TextureLayer::CreateForMailbox(nullptr); |
| 219 layer->SetBounds(layer_bounds); | 219 layer->SetBounds(layer_bounds); |
| 220 layer->draw_properties().visible_content_rect = layer_rect; | 220 layer->draw_properties().visible_content_rect = layer_rect; |
| 221 layer->SetBlendBackgroundColor(true); | 221 layer->SetBlendBackgroundColor(true); |
| 222 | 222 |
| 223 // Verify initial conditions. | 223 // Verify initial conditions. |
| 224 EXPECT_FALSE(layer->contents_opaque()); | 224 EXPECT_FALSE(layer->contents_opaque()); |
| 225 EXPECT_EQ(0u, layer->background_color()); | 225 EXPECT_EQ(0u, layer->background_color()); |
| 226 EXPECT_EQ(Region().ToString(), | 226 EXPECT_EQ(Region().ToString(), |
| 227 layer->VisibleContentOpaqueRegion().ToString()); | 227 layer->VisibleContentOpaqueRegion().ToString()); |
| 228 | 228 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 layer_tree_host_->SetRootLayer(test_layer); | 276 layer_tree_host_->SetRootLayer(test_layer); |
| 277 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); | 277 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); |
| 278 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 278 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 279 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()); | 279 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()); |
| 280 test_layer->SetNeedsDisplay(); | 280 test_layer->SetNeedsDisplay(); |
| 281 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 281 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 282 | 282 |
| 283 // Stop rate limiter when we're removed from the tree. | 283 // Stop rate limiter when we're removed from the tree. |
| 284 EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); | 284 EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); |
| 285 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | 285 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); |
| 286 layer_tree_host_->SetRootLayer(NULL); | 286 layer_tree_host_->SetRootLayer(nullptr); |
| 287 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 287 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 class TestMailboxHolder : public TextureLayer::TextureMailboxHolder { | 290 class TestMailboxHolder : public TextureLayer::TextureMailboxHolder { |
| 291 public: | 291 public: |
| 292 using TextureLayer::TextureMailboxHolder::Create; | 292 using TextureLayer::TextureMailboxHolder::Create; |
| 293 | 293 |
| 294 protected: | 294 protected: |
| 295 virtual ~TestMailboxHolder() {} | 295 virtual ~TestMailboxHolder() {} |
| 296 }; | 296 }; |
| 297 | 297 |
| 298 class TextureLayerWithMailboxTest : public TextureLayerTest { | 298 class TextureLayerWithMailboxTest : public TextureLayerTest { |
| 299 protected: | 299 protected: |
| 300 virtual void TearDown() { | 300 virtual void TearDown() { |
| 301 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 301 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 302 EXPECT_CALL(test_data_.mock_callback_, | 302 EXPECT_CALL(test_data_.mock_callback_, |
| 303 Release(test_data_.mailbox_name1_, | 303 Release(test_data_.mailbox_name1_, |
| 304 test_data_.sync_point1_, | 304 test_data_.sync_point1_, |
| 305 false)).Times(1); | 305 false)).Times(1); |
| 306 TextureLayerTest::TearDown(); | 306 TextureLayerTest::TearDown(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 CommonMailboxObjects test_data_; | 309 CommonMailboxObjects test_data_; |
| 310 }; | 310 }; |
| 311 | 311 |
| 312 TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { | 312 TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { |
| 313 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 313 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(nullpt r); |
|
reveman
2014/10/09 15:08:00
this too
| |
| 314 ASSERT_TRUE(test_layer.get()); | 314 ASSERT_TRUE(test_layer.get()); |
| 315 | 315 |
| 316 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 316 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 317 layer_tree_host_->SetRootLayer(test_layer); | 317 layer_tree_host_->SetRootLayer(test_layer); |
| 318 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 318 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 319 | 319 |
| 320 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 320 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 321 test_layer->SetTextureMailbox( | 321 test_layer->SetTextureMailbox( |
| 322 test_data_.mailbox1_, | 322 test_data_.mailbox1_, |
| 323 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | 323 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 364 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 365 | 365 |
| 366 // Test destructor. | 366 // Test destructor. |
| 367 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 367 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 368 test_layer->SetTextureMailbox( | 368 test_layer->SetTextureMailbox( |
| 369 test_data_.mailbox1_, | 369 test_data_.mailbox1_, |
| 370 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | 370 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); |
| 371 } | 371 } |
| 372 | 372 |
| 373 TEST_F(TextureLayerTest, SetTextureMailboxWithoutReleaseCallback) { | 373 TEST_F(TextureLayerTest, SetTextureMailboxWithoutReleaseCallback) { |
| 374 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 374 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(nullpt r); |
|
reveman
2014/10/09 15:08:00
and this
| |
| 375 ASSERT_TRUE(test_layer.get()); | 375 ASSERT_TRUE(test_layer.get()); |
| 376 | 376 |
| 377 // These use the same gpu::Mailbox, but different sync points. | 377 // These use the same gpu::Mailbox, but different sync points. |
| 378 TextureMailbox mailbox1(MailboxFromChar('a'), GL_TEXTURE_2D, 1); | 378 TextureMailbox mailbox1(MailboxFromChar('a'), GL_TEXTURE_2D, 1); |
| 379 TextureMailbox mailbox2(MailboxFromChar('a'), GL_TEXTURE_2D, 2); | 379 TextureMailbox mailbox2(MailboxFromChar('a'), GL_TEXTURE_2D, 2); |
| 380 | 380 |
| 381 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 381 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 382 layer_tree_host_->SetRootLayer(test_layer); | 382 layer_tree_host_->SetRootLayer(test_layer); |
| 383 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 383 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 384 | 384 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 } | 445 } |
| 446 | 446 |
| 447 scoped_ptr<TestMailboxHolder::MainThreadReference> | 447 scoped_ptr<TestMailboxHolder::MainThreadReference> |
| 448 main_ref_; | 448 main_ref_; |
| 449 base::Thread main_thread_; | 449 base::Thread main_thread_; |
| 450 scoped_ptr<BlockingTaskRunner> main_thread_task_runner_; | 450 scoped_ptr<BlockingTaskRunner> main_thread_task_runner_; |
| 451 CommonMailboxObjects test_data_; | 451 CommonMailboxObjects test_data_; |
| 452 }; | 452 }; |
| 453 | 453 |
| 454 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) { | 454 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) { |
| 455 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 455 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(nullpt r); |
|
reveman
2014/10/09 15:08:01
ditto
| |
| 456 ASSERT_TRUE(test_layer.get()); | 456 ASSERT_TRUE(test_layer.get()); |
| 457 | 457 |
| 458 main_thread_.message_loop()->PostTask( | 458 main_thread_.message_loop()->PostTask( |
| 459 FROM_HERE, | 459 FROM_HERE, |
| 460 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 460 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 461 base::Unretained(this))); | 461 base::Unretained(this))); |
| 462 | 462 |
| 463 Wait(main_thread_); | 463 Wait(main_thread_); |
| 464 | 464 |
| 465 // The texture layer is attached to compositor1, and passes a reference to its | 465 // The texture layer is attached to compositor1, and passes a reference to its |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 | 500 |
| 501 main_thread_.message_loop()->PostTask( | 501 main_thread_.message_loop()->PostTask( |
| 502 FROM_HERE, | 502 FROM_HERE, |
| 503 base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, | 503 base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 504 base::Unretained(this))); | 504 base::Unretained(this))); |
| 505 Wait(main_thread_); | 505 Wait(main_thread_); |
| 506 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 506 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 507 } | 507 } |
| 508 | 508 |
| 509 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) { | 509 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) { |
| 510 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 510 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(nullpt r); |
|
reveman
2014/10/09 15:08:01
format
| |
| 511 ASSERT_TRUE(test_layer.get()); | 511 ASSERT_TRUE(test_layer.get()); |
| 512 | 512 |
| 513 main_thread_.message_loop()->PostTask( | 513 main_thread_.message_loop()->PostTask( |
| 514 FROM_HERE, | 514 FROM_HERE, |
| 515 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 515 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 516 base::Unretained(this))); | 516 base::Unretained(this))); |
| 517 | 517 |
| 518 Wait(main_thread_); | 518 Wait(main_thread_); |
| 519 | 519 |
| 520 // The texture layer is attached to compositor1, and passes a reference to its | 520 // The texture layer is attached to compositor1, and passes a reference to its |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 // released back to the embedder with the last sync point from the impl tree. | 556 // released back to the embedder with the last sync point from the impl tree. |
| 557 EXPECT_CALL(test_data_.mock_callback_, | 557 EXPECT_CALL(test_data_.mock_callback_, |
| 558 Release(test_data_.mailbox_name1_, 200, true)).Times(1); | 558 Release(test_data_.mailbox_name1_, 200, true)).Times(1); |
| 559 | 559 |
| 560 compositor2->Run(200, true, main_thread_task_runner_.get()); | 560 compositor2->Run(200, true, main_thread_task_runner_.get()); |
| 561 Wait(main_thread_); | 561 Wait(main_thread_); |
| 562 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 562 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 563 } | 563 } |
| 564 | 564 |
| 565 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) { | 565 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) { |
| 566 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 566 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(nullpt r); |
|
reveman
2014/10/09 15:08:00
format
| |
| 567 ASSERT_TRUE(test_layer.get()); | 567 ASSERT_TRUE(test_layer.get()); |
| 568 | 568 |
| 569 main_thread_.message_loop()->PostTask( | 569 main_thread_.message_loop()->PostTask( |
| 570 FROM_HERE, | 570 FROM_HERE, |
| 571 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 571 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 572 base::Unretained(this))); | 572 base::Unretained(this))); |
| 573 | 573 |
| 574 Wait(main_thread_); | 574 Wait(main_thread_); |
| 575 | 575 |
| 576 // The texture layer is attached to compositor1, and passes a reference to its | 576 // The texture layer is attached to compositor1, and passes a reference to its |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 // released back to the embedder with the last sync point from the impl tree. | 612 // released back to the embedder with the last sync point from the impl tree. |
| 613 EXPECT_CALL(test_data_.mock_callback_, | 613 EXPECT_CALL(test_data_.mock_callback_, |
| 614 Release(test_data_.mailbox_name1_, 100, true)).Times(1); | 614 Release(test_data_.mailbox_name1_, 100, true)).Times(1); |
| 615 | 615 |
| 616 compositor1->Run(100, true, main_thread_task_runner_.get()); | 616 compositor1->Run(100, true, main_thread_task_runner_.get()); |
| 617 Wait(main_thread_); | 617 Wait(main_thread_); |
| 618 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 618 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 619 } | 619 } |
| 620 | 620 |
| 621 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { | 621 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { |
| 622 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 622 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(nullpt r); |
|
reveman
2014/10/09 15:08:01
format
| |
| 623 ASSERT_TRUE(test_layer.get()); | 623 ASSERT_TRUE(test_layer.get()); |
| 624 | 624 |
| 625 main_thread_.message_loop()->PostTask( | 625 main_thread_.message_loop()->PostTask( |
| 626 FROM_HERE, | 626 FROM_HERE, |
| 627 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 627 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 628 base::Unretained(this))); | 628 base::Unretained(this))); |
| 629 | 629 |
| 630 Wait(main_thread_); | 630 Wait(main_thread_); |
| 631 | 631 |
| 632 // The texture layer is attached to compositor1, and passes a reference to its | 632 // The texture layer is attached to compositor1, and passes a reference to its |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 callback.Pass()); | 721 callback.Pass()); |
| 722 } | 722 } |
| 723 | 723 |
| 724 virtual void BeginTest() override { | 724 virtual void BeginTest() override { |
| 725 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 725 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 726 | 726 |
| 727 gfx::Size bounds(100, 100); | 727 gfx::Size bounds(100, 100); |
| 728 root_ = Layer::Create(); | 728 root_ = Layer::Create(); |
| 729 root_->SetBounds(bounds); | 729 root_->SetBounds(bounds); |
| 730 | 730 |
| 731 layer_ = TextureLayer::CreateForMailbox(NULL); | 731 layer_ = TextureLayer::CreateForMailbox(nullptr); |
| 732 layer_->SetIsDrawable(true); | 732 layer_->SetIsDrawable(true); |
| 733 layer_->SetBounds(bounds); | 733 layer_->SetBounds(bounds); |
| 734 | 734 |
| 735 root_->AddChild(layer_); | 735 root_->AddChild(layer_); |
| 736 layer_tree_host()->SetRootLayer(root_); | 736 layer_tree_host()->SetRootLayer(root_); |
| 737 layer_tree_host()->SetViewportSize(bounds); | 737 layer_tree_host()->SetViewportSize(bounds); |
| 738 SetMailbox('1'); | 738 SetMailbox('1'); |
| 739 EXPECT_EQ(0, callback_count_); | 739 EXPECT_EQ(0, callback_count_); |
| 740 | 740 |
| 741 // Case #1: change mailbox before the commit. The old mailbox should be | 741 // Case #1: change mailbox before the commit. The old mailbox should be |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 layer_->SetTextureMailbox( | 844 layer_->SetTextureMailbox( |
| 845 TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), | 845 TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), |
| 846 callback.Pass()); | 846 callback.Pass()); |
| 847 } | 847 } |
| 848 | 848 |
| 849 virtual void BeginTest() override { | 849 virtual void BeginTest() override { |
| 850 gfx::Size bounds(100, 100); | 850 gfx::Size bounds(100, 100); |
| 851 root_ = Layer::Create(); | 851 root_ = Layer::Create(); |
| 852 root_->SetBounds(bounds); | 852 root_->SetBounds(bounds); |
| 853 | 853 |
| 854 layer_ = TextureLayer::CreateForMailbox(NULL); | 854 layer_ = TextureLayer::CreateForMailbox(nullptr); |
| 855 layer_->SetIsDrawable(true); | 855 layer_->SetIsDrawable(true); |
| 856 layer_->SetBounds(bounds); | 856 layer_->SetBounds(bounds); |
| 857 | 857 |
| 858 root_->AddChild(layer_); | 858 root_->AddChild(layer_); |
| 859 layer_tree_host()->SetRootLayer(root_); | 859 layer_tree_host()->SetRootLayer(root_); |
| 860 layer_tree_host()->SetViewportSize(bounds); | 860 layer_tree_host()->SetViewportSize(bounds); |
| 861 SetMailbox('1'); | 861 SetMailbox('1'); |
| 862 | 862 |
| 863 PostSetNeedsCommitToMainThread(); | 863 PostSetNeedsCommitToMainThread(); |
| 864 } | 864 } |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 private: | 1409 private: |
| 1410 bool mailbox_released_; | 1410 bool mailbox_released_; |
| 1411 }; | 1411 }; |
| 1412 | 1412 |
| 1413 class TextureLayerReleaseResourcesAfterCommit | 1413 class TextureLayerReleaseResourcesAfterCommit |
| 1414 : public TextureLayerReleaseResourcesBase { | 1414 : public TextureLayerReleaseResourcesBase { |
| 1415 public: | 1415 public: |
| 1416 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1416 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 1417 LayerTreeImpl* tree = NULL; | 1417 LayerTreeImpl* tree = nullptr; |
| 1418 if (host_impl->settings().impl_side_painting) | 1418 if (host_impl->settings().impl_side_painting) |
| 1419 tree = host_impl->pending_tree(); | 1419 tree = host_impl->pending_tree(); |
| 1420 else | 1420 else |
| 1421 tree = host_impl->active_tree(); | 1421 tree = host_impl->active_tree(); |
| 1422 tree->root_layer()->children()[0]->ReleaseResources(); | 1422 tree->root_layer()->children()[0]->ReleaseResources(); |
| 1423 } | 1423 } |
| 1424 }; | 1424 }; |
| 1425 | 1425 |
| 1426 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit); | 1426 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerReleaseResourcesAfterCommit); |
| 1427 | 1427 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1453 layer_->SetTextureMailbox( | 1453 layer_->SetTextureMailbox( |
| 1454 TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), | 1454 TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), |
| 1455 callback.Pass()); | 1455 callback.Pass()); |
| 1456 } | 1456 } |
| 1457 | 1457 |
| 1458 virtual void SetupTree() override { | 1458 virtual void SetupTree() override { |
| 1459 gfx::Size bounds(100, 100); | 1459 gfx::Size bounds(100, 100); |
| 1460 root_ = Layer::Create(); | 1460 root_ = Layer::Create(); |
| 1461 root_->SetBounds(bounds); | 1461 root_->SetBounds(bounds); |
| 1462 | 1462 |
| 1463 layer_ = TextureLayer::CreateForMailbox(NULL); | 1463 layer_ = TextureLayer::CreateForMailbox(nullptr); |
| 1464 layer_->SetIsDrawable(true); | 1464 layer_->SetIsDrawable(true); |
| 1465 layer_->SetBounds(bounds); | 1465 layer_->SetBounds(bounds); |
| 1466 | 1466 |
| 1467 root_->AddChild(layer_); | 1467 root_->AddChild(layer_); |
| 1468 layer_tree_host()->SetRootLayer(root_); | 1468 layer_tree_host()->SetRootLayer(root_); |
| 1469 layer_tree_host()->SetViewportSize(bounds); | 1469 layer_tree_host()->SetViewportSize(bounds); |
| 1470 } | 1470 } |
| 1471 | 1471 |
| 1472 virtual void BeginTest() override { | 1472 virtual void BeginTest() override { |
| 1473 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 1473 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 1474 | 1474 |
| 1475 callback_count_ = 0; | 1475 callback_count_ = 0; |
| 1476 | 1476 |
| 1477 // Set the mailbox on the main thread. | 1477 // Set the mailbox on the main thread. |
| 1478 SetMailbox('1'); | 1478 SetMailbox('1'); |
| 1479 EXPECT_EQ(0, callback_count_); | 1479 EXPECT_EQ(0, callback_count_); |
| 1480 | 1480 |
| 1481 PostSetNeedsCommitToMainThread(); | 1481 PostSetNeedsCommitToMainThread(); |
| 1482 } | 1482 } |
| 1483 | 1483 |
| 1484 virtual void DidCommitAndDrawFrame() override { | 1484 virtual void DidCommitAndDrawFrame() override { |
| 1485 switch (layer_tree_host()->source_frame_number()) { | 1485 switch (layer_tree_host()->source_frame_number()) { |
| 1486 case 1: | 1486 case 1: |
| 1487 // Delete the TextureLayer on the main thread while the mailbox is in | 1487 // Delete the TextureLayer on the main thread while the mailbox is in |
| 1488 // the impl tree. | 1488 // the impl tree. |
| 1489 layer_->RemoveFromParent(); | 1489 layer_->RemoveFromParent(); |
| 1490 layer_ = NULL; | 1490 layer_ = nullptr; |
| 1491 break; | 1491 break; |
| 1492 } | 1492 } |
| 1493 } | 1493 } |
| 1494 | 1494 |
| 1495 virtual void AfterTest() override { | 1495 virtual void AfterTest() override { |
| 1496 EXPECT_EQ(1, callback_count_); | 1496 EXPECT_EQ(1, callback_count_); |
| 1497 } | 1497 } |
| 1498 | 1498 |
| 1499 private: | 1499 private: |
| 1500 base::ThreadChecker main_thread_; | 1500 base::ThreadChecker main_thread_; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1524 layer_->SetTextureMailbox( | 1524 layer_->SetTextureMailbox( |
| 1525 TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), | 1525 TextureMailbox(MailboxFromChar(mailbox_char), GL_TEXTURE_2D, 0), |
| 1526 callback.Pass()); | 1526 callback.Pass()); |
| 1527 } | 1527 } |
| 1528 | 1528 |
| 1529 virtual void SetupTree() override { | 1529 virtual void SetupTree() override { |
| 1530 gfx::Size bounds(100, 100); | 1530 gfx::Size bounds(100, 100); |
| 1531 root_ = Layer::Create(); | 1531 root_ = Layer::Create(); |
| 1532 root_->SetBounds(bounds); | 1532 root_->SetBounds(bounds); |
| 1533 | 1533 |
| 1534 layer_ = TextureLayer::CreateForMailbox(NULL); | 1534 layer_ = TextureLayer::CreateForMailbox(nullptr); |
| 1535 layer_->SetIsDrawable(true); | 1535 layer_->SetIsDrawable(true); |
| 1536 layer_->SetBounds(bounds); | 1536 layer_->SetBounds(bounds); |
| 1537 | 1537 |
| 1538 root_->AddChild(layer_); | 1538 root_->AddChild(layer_); |
| 1539 layer_tree_host()->SetRootLayer(root_); | 1539 layer_tree_host()->SetRootLayer(root_); |
| 1540 layer_tree_host()->SetViewportSize(bounds); | 1540 layer_tree_host()->SetViewportSize(bounds); |
| 1541 } | 1541 } |
| 1542 | 1542 |
| 1543 virtual void BeginTest() override { | 1543 virtual void BeginTest() override { |
| 1544 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 1544 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
| 1545 | 1545 |
| 1546 callback_count_ = 0; | 1546 callback_count_ = 0; |
| 1547 | 1547 |
| 1548 // Set the mailbox on the main thread. | 1548 // Set the mailbox on the main thread. |
| 1549 SetMailbox('1'); | 1549 SetMailbox('1'); |
| 1550 EXPECT_EQ(0, callback_count_); | 1550 EXPECT_EQ(0, callback_count_); |
| 1551 | 1551 |
| 1552 PostSetNeedsCommitToMainThread(); | 1552 PostSetNeedsCommitToMainThread(); |
| 1553 } | 1553 } |
| 1554 | 1554 |
| 1555 virtual void DidCommitAndDrawFrame() override { | 1555 virtual void DidCommitAndDrawFrame() override { |
| 1556 switch (layer_tree_host()->source_frame_number()) { | 1556 switch (layer_tree_host()->source_frame_number()) { |
| 1557 case 1: | 1557 case 1: |
| 1558 // Remove the TextureLayer on the main thread while the mailbox is in | 1558 // Remove the TextureLayer on the main thread while the mailbox is in |
| 1559 // the impl tree, but don't delete the TextureLayer until after the impl | 1559 // the impl tree, but don't delete the TextureLayer until after the impl |
| 1560 // tree side is deleted. | 1560 // tree side is deleted. |
| 1561 layer_->RemoveFromParent(); | 1561 layer_->RemoveFromParent(); |
| 1562 break; | 1562 break; |
| 1563 case 2: | 1563 case 2: |
| 1564 layer_ = NULL; | 1564 layer_ = nullptr; |
| 1565 break; | 1565 break; |
| 1566 } | 1566 } |
| 1567 } | 1567 } |
| 1568 | 1568 |
| 1569 virtual void AfterTest() override { | 1569 virtual void AfterTest() override { |
| 1570 EXPECT_EQ(1, callback_count_); | 1570 EXPECT_EQ(1, callback_count_); |
| 1571 } | 1571 } |
| 1572 | 1572 |
| 1573 private: | 1573 private: |
| 1574 base::ThreadChecker main_thread_; | 1574 base::ThreadChecker main_thread_; |
| 1575 int callback_count_; | 1575 int callback_count_; |
| 1576 scoped_refptr<Layer> root_; | 1576 scoped_refptr<Layer> root_; |
| 1577 scoped_refptr<TextureLayer> layer_; | 1577 scoped_refptr<TextureLayer> layer_; |
| 1578 }; | 1578 }; |
| 1579 | 1579 |
| 1580 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1580 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1581 TextureLayerWithMailboxImplThreadDeleted); | 1581 TextureLayerWithMailboxImplThreadDeleted); |
| 1582 | 1582 |
| 1583 } // namespace | 1583 } // namespace |
| 1584 } // namespace cc | 1584 } // namespace cc |
| OLD | NEW |