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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "cc/base/thread.h" | 10 #include "cc/base/thread.h" |
| 11 #include "cc/layers/texture_layer_client.h" | |
| 11 #include "cc/layers/texture_layer_impl.h" | 12 #include "cc/layers/texture_layer_impl.h" |
| 12 #include "cc/test/fake_impl_proxy.h" | 13 #include "cc/test/fake_impl_proxy.h" |
| 13 #include "cc/test/fake_layer_tree_host_client.h" | 14 #include "cc/test/fake_layer_tree_host_client.h" |
| 14 #include "cc/test/fake_layer_tree_host_impl.h" | 15 #include "cc/test/fake_layer_tree_host_impl.h" |
| 15 #include "cc/test/layer_tree_test.h" | 16 #include "cc/test/layer_tree_test.h" |
| 16 #include "cc/trees/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
| 17 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 18 #include "cc/trees/single_thread_proxy.h" | 19 #include "cc/trees/single_thread_proxy.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 provider->PrepareSendToParent(resource_ids_to_transfer, &list); | 468 provider->PrepareSendToParent(resource_ids_to_transfer, &list); |
| 468 EXPECT_TRUE(provider->InUseByConsumer(id)); | 469 EXPECT_TRUE(provider->InUseByConsumer(id)); |
| 469 EXPECT_CALL(test_data_.mock_callback_, Release(_, _)).Times(0); | 470 EXPECT_CALL(test_data_.mock_callback_, Release(_, _)).Times(0); |
| 470 provider->DeleteResource(id); | 471 provider->DeleteResource(id); |
| 471 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 472 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 472 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name1_, _)) | 473 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name1_, _)) |
| 473 .Times(1); | 474 .Times(1); |
| 474 provider->ReceiveFromParent(list); | 475 provider->ReceiveFromParent(list); |
| 475 } | 476 } |
| 476 | 477 |
| 478 // Check that ClearClient correctly clears the state so that the impl side | |
| 479 // doesn't try to use a texture that could have been destroyed. | |
| 480 class TextureLayerClientTest : | |
| 481 public LayerTreeTest, | |
| 482 public TextureLayerClient { | |
| 483 public: | |
| 484 TextureLayerClientTest() | |
| 485 : context_(NULL), | |
| 486 texture_(0), | |
| 487 commit_count_(0), | |
| 488 expected_used_textures_on_draw_(0), | |
| 489 expected_used_textures_on_commit_(0) {} | |
| 490 | |
| 491 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { | |
| 492 scoped_ptr<TestWebGraphicsContext3D> context( | |
| 493 TestWebGraphicsContext3D::Create()); | |
| 494 context_ = context.get(); | |
| 495 texture_ = context->createTexture(); | |
| 496 return FakeOutputSurface::Create3d( | |
| 497 context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); | |
| 498 } | |
| 499 | |
| 500 virtual unsigned PrepareTexture(ResourceUpdateQueue* queue) { | |
| 501 return texture_; | |
| 502 } | |
| 503 | |
| 504 virtual WebKit::WebGraphicsContext3D* Context3d() { | |
| 505 return context_; | |
| 506 } | |
| 507 | |
| 508 virtual void SetupTree() OVERRIDE { | |
| 509 scoped_refptr<Layer> root = Layer::Create(); | |
| 510 root->SetBounds(gfx::Size(10, 10)); | |
| 511 root->SetAnchorPoint(gfx::PointF()); | |
| 512 root->SetIsDrawable(true); | |
| 513 | |
| 514 texture_layer_ = TextureLayer::Create(this); | |
| 515 texture_layer_->SetBounds(gfx::Size(10, 10)); | |
| 516 texture_layer_->SetAnchorPoint(gfx::PointF()); | |
| 517 texture_layer_->SetIsDrawable(true); | |
| 518 root->AddChild(texture_layer_); | |
| 519 | |
| 520 layer_tree_host()->SetRootLayer(root); | |
| 521 LayerTreeTest::SetupTree(); | |
| 522 { | |
| 523 base::AutoLock lock(lock_); | |
| 524 expected_used_textures_on_commit_ = 1; | |
| 525 } | |
| 526 } | |
| 527 | |
| 528 virtual void BeginTest() OVERRIDE { | |
| 529 PostSetNeedsCommitToMainThread(); | |
| 530 } | |
| 531 | |
| 532 virtual void DidCommitAndDrawFrame() OVERRIDE { | |
| 533 ++commit_count_; | |
| 534 switch (commit_count_) { | |
| 535 case 1: | |
| 536 texture_layer_->ClearClient(); | |
|
danakj
2013/03/28 03:57:07
This should also damage the layer so that it will
piman
2013/03/28 21:16:19
Done.
| |
| 537 { | |
| 538 base::AutoLock lock(lock_); | |
| 539 expected_used_textures_on_commit_ = 0; | |
| 540 } | |
| 541 texture_ = 0; | |
| 542 break; | |
| 543 case 2: | |
| 544 EndTest(); | |
| 545 break; | |
| 546 default: | |
| 547 NOTREACHED(); | |
| 548 break; | |
| 549 } | |
| 550 } | |
| 551 | |
| 552 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | |
| 553 base::AutoLock lock(lock_); | |
| 554 expected_used_textures_on_draw_ = expected_used_textures_on_commit_; | |
| 555 } | |
| 556 | |
| 557 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | |
| 558 LayerTreeHostImpl::FrameData* frame_data, | |
| 559 bool result) OVERRIDE { | |
| 560 context_->ResetUsedTextures(); | |
| 561 return true; | |
| 562 } | |
| 563 | |
| 564 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | |
| 565 bool result) OVERRIDE { | |
|
danakj
2013/03/28 04:13:55
Alternatively, or additionally, EXPECT_TRUE(result
piman
2013/03/28 21:16:19
Done.
| |
| 566 EXPECT_EQ(expected_used_textures_on_draw_, context_->NumUsedTextures()); | |
| 567 } | |
| 568 | |
| 569 virtual void AfterTest() OVERRIDE {} | |
| 570 | |
| 571 private: | |
| 572 scoped_refptr<TextureLayer> texture_layer_; | |
| 573 TestWebGraphicsContext3D* context_; | |
| 574 unsigned texture_; | |
| 575 int commit_count_; | |
| 576 | |
| 577 // Used only on thread. | |
| 578 unsigned expected_used_textures_on_draw_; | |
| 579 | |
| 580 // Used on either thread, protected by lock_. | |
| 581 base::Lock lock_; | |
| 582 unsigned expected_used_textures_on_commit_; | |
| 583 }; | |
| 584 | |
| 585 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerClientTest); | |
| 586 | |
| 477 } // namespace | 587 } // namespace |
| 478 } // namespace cc | 588 } // namespace cc |
| OLD | NEW |