OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 4451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4462 } | 4462 } |
4463 | 4463 |
4464 private: | 4464 private: |
4465 int num_will_begin_frames_; | 4465 int num_will_begin_frames_; |
4466 int num_impl_commits_; | 4466 int num_impl_commits_; |
4467 }; | 4467 }; |
4468 | 4468 |
4469 // Commits can only be aborted when using the thread proxy. | 4469 // Commits can only be aborted when using the thread proxy. |
4470 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); | 4470 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); |
4471 | 4471 |
| 4472 class TestWebGraphicsContext3DWithTextureCounts |
| 4473 : public TestWebGraphicsContext3D { |
| 4474 public: |
| 4475 static scoped_ptr<TestWebGraphicsContext3DWithTextureCounts> Create() { |
| 4476 return make_scoped_ptr(new TestWebGraphicsContext3DWithTextureCounts()); |
| 4477 } |
| 4478 |
| 4479 virtual ~TestWebGraphicsContext3DWithTextureCounts() {} |
| 4480 |
| 4481 virtual WebKit::WebGLId createTexture() OVERRIDE { |
| 4482 ++num_create_texture_calls_; |
| 4483 return TestWebGraphicsContext3D::createTexture(); |
| 4484 } |
| 4485 |
| 4486 virtual void deleteTexture(WebKit::WebGLId texture_id) OVERRIDE { |
| 4487 ++num_delete_texture_calls_; |
| 4488 TestWebGraphicsContext3D::deleteTexture(texture_id); |
| 4489 } |
| 4490 |
| 4491 int num_create_texture_calls_; |
| 4492 int num_delete_texture_calls_; |
| 4493 |
| 4494 private: |
| 4495 TestWebGraphicsContext3DWithTextureCounts() |
| 4496 : TestWebGraphicsContext3D(), |
| 4497 num_create_texture_calls_(0), |
| 4498 num_delete_texture_calls_(0) {} |
| 4499 }; |
| 4500 |
| 4501 // UI resources should be evicted when visibility is set to false and recreated |
| 4502 // when visibility is set to true. |
| 4503 class LayerTreeHostEvictUIResourceTest : public LayerTreeHostTest { |
| 4504 public: |
| 4505 LayerTreeHostEvictUIResourceTest() |
| 4506 : LayerTreeHostTest(), num_commits_(0), context3d_(NULL) {} |
| 4507 |
| 4508 virtual scoped_ptr<TestWebGraphicsContext3DWithTextureCounts> |
| 4509 CreateContext3d() { |
| 4510 return TestWebGraphicsContext3DWithTextureCounts::Create(); |
| 4511 } |
| 4512 |
| 4513 virtual scoped_ptr<OutputSurface> CreateOutputSurface( |
| 4514 bool fallback) OVERRIDE { |
| 4515 scoped_ptr<TestWebGraphicsContext3DWithTextureCounts> context3d = |
| 4516 CreateContext3d(); |
| 4517 context3d_ = context3d.get(); |
| 4518 return FakeOutputSurface::Create3d( |
| 4519 context3d.PassAs<TestWebGraphicsContext3D>()).PassAs<OutputSurface>(); |
| 4520 } |
| 4521 |
| 4522 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 4523 |
| 4524 virtual void SetupTree() OVERRIDE { |
| 4525 root_ = Layer::Create(); |
| 4526 bool paint_scrollbar = true; |
| 4527 bool has_thumb = false; |
| 4528 scrollbar_layer_ = FakePaintedScrollbarLayer::Create( |
| 4529 paint_scrollbar, has_thumb, root_->id()); |
| 4530 |
| 4531 root_->AddChild(scrollbar_layer_); |
| 4532 layer_tree_host()->SetRootLayer(root_); |
| 4533 LayerTreeHostTest::SetupTree(); |
| 4534 } |
| 4535 |
| 4536 virtual void DidCommit() OVERRIDE { |
| 4537 int frame = num_commits_; |
| 4538 scoped_ptr<base::AutoReset<bool> > ignore; |
| 4539 switch (frame) { |
| 4540 case 1: |
| 4541 PostSetNeedsCommitToMainThread(); |
| 4542 break; |
| 4543 case 2: |
| 4544 PostSetVisibleToMainThread(false); |
| 4545 PostSetNeedsRedrawToMainThread(); |
| 4546 PostSetVisibleToMainThread(true); |
| 4547 PostSetNeedsCommitToMainThread(); |
| 4548 break; |
| 4549 case 3: |
| 4550 PostSetNeedsCommitToMainThread(); |
| 4551 break; |
| 4552 case 4: |
| 4553 EndTest(); |
| 4554 break; |
| 4555 } |
| 4556 } |
| 4557 |
| 4558 virtual void PerformTest(LayerTreeHostImpl* impl) { |
| 4559 int frame = num_commits_; |
| 4560 switch (frame) { |
| 4561 case 1: |
| 4562 // Expect one texture has been created. None has been deleted. |
| 4563 EXPECT_EQ(context3d_->num_create_texture_calls_, 1); |
| 4564 EXPECT_EQ(context3d_->num_delete_texture_calls_, 0); |
| 4565 break; |
| 4566 case 2: |
| 4567 // Expect two textures has been created. One has been deleted. |
| 4568 EXPECT_EQ(context3d_->num_create_texture_calls_, 2); |
| 4569 EXPECT_EQ(context3d_->num_delete_texture_calls_, 1); |
| 4570 break; |
| 4571 case 3: |
| 4572 // Visibility has been changed once. So resource was evicted in LTHI |
| 4573 // and recreated in LTH. Expect four textures has been created. Three |
| 4574 // has been deleted. |
| 4575 EXPECT_EQ(context3d_->num_create_texture_calls_, 4); |
| 4576 EXPECT_EQ(context3d_->num_delete_texture_calls_, 3); |
| 4577 break; |
| 4578 default: |
| 4579 break; |
| 4580 } |
| 4581 } |
| 4582 |
| 4583 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 4584 ++num_commits_; |
| 4585 if (!layer_tree_host()->settings().impl_side_painting) |
| 4586 PerformTest(impl); |
| 4587 } |
| 4588 |
| 4589 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 4590 if (layer_tree_host()->settings().impl_side_painting) |
| 4591 PerformTest(impl); |
| 4592 } |
| 4593 |
| 4594 virtual void AfterTest() OVERRIDE {} |
| 4595 |
| 4596 protected: |
| 4597 scoped_refptr<Layer> root_; |
| 4598 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; |
| 4599 int num_commits_; |
| 4600 TestWebGraphicsContext3DWithTextureCounts* context3d_; |
| 4601 }; |
| 4602 |
| 4603 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostEvictUIResourceTest); |
| 4604 |
4472 } // namespace | 4605 } // namespace |
4473 | 4606 |
4474 } // namespace cc | 4607 } // namespace cc |
OLD | NEW |