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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 LayerTreeHostImpl::FrameData* frame_data, | 435 LayerTreeHostImpl::FrameData* frame_data, |
436 DrawResult draw_result) override { | 436 DrawResult draw_result) override { |
437 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 437 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
438 | 438 |
439 gfx::RectF root_damage_rect; | 439 gfx::RectF root_damage_rect; |
440 if (!frame_data->render_passes.empty()) | 440 if (!frame_data->render_passes.empty()) |
441 root_damage_rect = frame_data->render_passes.back()->damage_rect; | 441 root_damage_rect = frame_data->render_passes.back()->damage_rect; |
442 | 442 |
443 if (!num_draws_) { | 443 if (!num_draws_) { |
444 // If this is the first frame, expect full frame damage. | 444 // If this is the first frame, expect full frame damage. |
445 EXPECT_RECT_EQ(root_damage_rect, gfx::Rect(bounds_)); | 445 EXPECT_EQ(root_damage_rect, gfx::Rect(bounds_)); |
446 } else { | 446 } else { |
447 // Check that invalid_rect_ is indeed repainted. | 447 // Check that invalid_rect_ is indeed repainted. |
448 EXPECT_TRUE(root_damage_rect.Contains(invalid_rect_)); | 448 EXPECT_TRUE(root_damage_rect.Contains(invalid_rect_)); |
449 } | 449 } |
450 | 450 |
451 return draw_result; | 451 return draw_result; |
452 } | 452 } |
453 | 453 |
454 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 454 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
455 if (!num_draws_) { | 455 if (!num_draws_) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 LayerTreeHostImpl::FrameData* frame_data, | 617 LayerTreeHostImpl::FrameData* frame_data, |
618 DrawResult draw_result) override { | 618 DrawResult draw_result) override { |
619 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 619 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
620 | 620 |
621 gfx::RectF root_damage_rect; | 621 gfx::RectF root_damage_rect; |
622 if (!frame_data->render_passes.empty()) | 622 if (!frame_data->render_passes.empty()) |
623 root_damage_rect = frame_data->render_passes.back()->damage_rect; | 623 root_damage_rect = frame_data->render_passes.back()->damage_rect; |
624 | 624 |
625 switch (num_draws_) { | 625 switch (num_draws_) { |
626 case 0: | 626 case 0: |
627 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect); | 627 EXPECT_EQ(gfx::Rect(bounds_), root_damage_rect); |
628 break; | 628 break; |
629 case 1: | 629 case 1: |
630 case 2: | 630 case 2: |
631 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root_damage_rect); | 631 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root_damage_rect); |
632 break; | 632 break; |
633 case 3: | 633 case 3: |
634 EXPECT_RECT_EQ(invalid_rect_, root_damage_rect); | 634 EXPECT_EQ(invalid_rect_, root_damage_rect); |
635 break; | 635 break; |
636 case 4: | 636 case 4: |
637 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect); | 637 EXPECT_EQ(gfx::Rect(bounds_), root_damage_rect); |
638 break; | 638 break; |
639 default: | 639 default: |
640 NOTREACHED(); | 640 NOTREACHED(); |
641 } | 641 } |
642 | 642 |
643 return draw_result; | 643 return draw_result; |
644 } | 644 } |
645 | 645 |
646 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 646 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
647 switch (num_draws_) { | 647 switch (num_draws_) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 if (!frame_data->render_passes.empty()) | 729 if (!frame_data->render_passes.empty()) |
730 root_damage_rect = frame_data->render_passes.back()->damage_rect; | 730 root_damage_rect = frame_data->render_passes.back()->damage_rect; |
731 | 731 |
732 // The first time, the whole view needs be drawn. | 732 // The first time, the whole view needs be drawn. |
733 // Afterwards, just the opacity of surface_layer1 is changed a few times, | 733 // Afterwards, just the opacity of surface_layer1 is changed a few times, |
734 // and each damage should be the bounding box of it and its child. If this | 734 // and each damage should be the bounding box of it and its child. If this |
735 // was working improperly, the damage might not include its childs bounding | 735 // was working improperly, the damage might not include its childs bounding |
736 // box. | 736 // box. |
737 switch (host_impl->active_tree()->source_frame_number()) { | 737 switch (host_impl->active_tree()->source_frame_number()) { |
738 case 0: | 738 case 0: |
739 EXPECT_RECT_EQ(gfx::Rect(root_layer_->bounds()), root_damage_rect); | 739 EXPECT_EQ(gfx::Rect(root_layer_->bounds()), root_damage_rect); |
740 break; | 740 break; |
741 case 1: | 741 case 1: |
742 case 2: | 742 case 2: |
743 case 3: | 743 case 3: |
744 EXPECT_RECT_EQ(gfx::Rect(child_layer_->bounds()), root_damage_rect); | 744 EXPECT_EQ(gfx::Rect(child_layer_->bounds()), root_damage_rect); |
745 break; | 745 break; |
746 default: | 746 default: |
747 NOTREACHED(); | 747 NOTREACHED(); |
748 } | 748 } |
749 | 749 |
750 return draw_result; | 750 return draw_result; |
751 } | 751 } |
752 | 752 |
753 void DidCommitAndDrawFrame() override { | 753 void DidCommitAndDrawFrame() override { |
754 switch (layer_tree_host()->source_frame_number()) { | 754 switch (layer_tree_host()->source_frame_number()) { |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 const LayerImplList& render_surface_layer_list = | 1262 const LayerImplList& render_surface_layer_list = |
1263 *frame_data.render_surface_layer_list; | 1263 *frame_data.render_surface_layer_list; |
1264 | 1264 |
1265 // Both layers should be drawing into the root render surface. | 1265 // Both layers should be drawing into the root render surface. |
1266 ASSERT_EQ(1u, render_surface_layer_list.size()); | 1266 ASSERT_EQ(1u, render_surface_layer_list.size()); |
1267 ASSERT_EQ(root->render_surface(), | 1267 ASSERT_EQ(root->render_surface(), |
1268 render_surface_layer_list[0]->render_surface()); | 1268 render_surface_layer_list[0]->render_surface()); |
1269 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | 1269 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
1270 | 1270 |
1271 // The root render surface is the size of the viewport. | 1271 // The root render surface is the size of the viewport. |
1272 EXPECT_RECT_EQ(gfx::Rect(0, 0, 60, 60), | 1272 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), root->render_surface()->content_rect()); |
1273 root->render_surface()->content_rect()); | |
1274 | 1273 |
1275 // The max tiling scale of the child should be scaled. | 1274 // The max tiling scale of the child should be scaled. |
1276 EXPECT_FLOAT_EQ(1.5f, child->MaximumTilingContentsScale()); | 1275 EXPECT_FLOAT_EQ(1.5f, child->MaximumTilingContentsScale()); |
1277 | 1276 |
1278 gfx::Transform scale_transform; | 1277 gfx::Transform scale_transform; |
1279 scale_transform.Scale(impl->device_scale_factor(), | 1278 scale_transform.Scale(impl->device_scale_factor(), |
1280 impl->device_scale_factor()); | 1279 impl->device_scale_factor()); |
1281 | 1280 |
1282 // The root layer is scaled by 2x. | 1281 // The root layer is scaled by 2x. |
1283 gfx::Transform root_screen_space_transform = scale_transform; | 1282 gfx::Transform root_screen_space_transform = scale_transform; |
(...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2636 LayerTreeHostTest::SetupTree(); | 2635 LayerTreeHostTest::SetupTree(); |
2637 } | 2636 } |
2638 | 2637 |
2639 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 2638 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
2640 void AfterTest() override {} | 2639 void AfterTest() override {} |
2641 | 2640 |
2642 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 2641 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
2643 num_commits_++; | 2642 num_commits_++; |
2644 if (num_commits_ == 1) { | 2643 if (num_commits_ == 1) { |
2645 LayerImpl* root_layer = host_impl->active_tree()->root_layer(); | 2644 LayerImpl* root_layer = host_impl->active_tree()->root_layer(); |
2646 EXPECT_SIZE_EQ(gfx::Size(1, 1), root_layer->bounds()); | 2645 EXPECT_EQ(gfx::Size(1, 1), root_layer->bounds()); |
2647 } else { | 2646 } else { |
2648 LayerImpl* root_layer = host_impl->active_tree()->root_layer(); | 2647 LayerImpl* root_layer = host_impl->active_tree()->root_layer(); |
2649 EXPECT_SIZE_EQ(gfx::Size(2, 2), root_layer->bounds()); | 2648 EXPECT_EQ(gfx::Size(2, 2), root_layer->bounds()); |
2650 EndTest(); | 2649 EndTest(); |
2651 } | 2650 } |
2652 } | 2651 } |
2653 | 2652 |
2654 private: | 2653 private: |
2655 SetBoundsClient client_; | 2654 SetBoundsClient client_; |
2656 int num_commits_; | 2655 int num_commits_; |
2657 }; | 2656 }; |
2658 | 2657 |
2659 SINGLE_AND_MULTI_THREAD_TEST_F( | 2658 SINGLE_AND_MULTI_THREAD_TEST_F( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2762 DrawResult draw_result) override { | 2761 DrawResult draw_result) override { |
2763 Mock::VerifyAndClearExpectations(&mock_context_); | 2762 Mock::VerifyAndClearExpectations(&mock_context_); |
2764 ResourceProvider* resource_provider = host_impl->resource_provider(); | 2763 ResourceProvider* resource_provider = host_impl->resource_provider(); |
2765 EXPECT_EQ(1u, resource_provider->num_resources()); | 2764 EXPECT_EQ(1u, resource_provider->num_resources()); |
2766 CHECK_EQ(1u, frame->render_passes.size()); | 2765 CHECK_EQ(1u, frame->render_passes.size()); |
2767 CHECK_LE(1u, frame->render_passes[0]->quad_list.size()); | 2766 CHECK_LE(1u, frame->render_passes[0]->quad_list.size()); |
2768 const DrawQuad* quad = frame->render_passes[0]->quad_list.front(); | 2767 const DrawQuad* quad = frame->render_passes[0]->quad_list.front(); |
2769 CHECK_EQ(DrawQuad::IO_SURFACE_CONTENT, quad->material); | 2768 CHECK_EQ(DrawQuad::IO_SURFACE_CONTENT, quad->material); |
2770 const IOSurfaceDrawQuad* io_surface_draw_quad = | 2769 const IOSurfaceDrawQuad* io_surface_draw_quad = |
2771 IOSurfaceDrawQuad::MaterialCast(quad); | 2770 IOSurfaceDrawQuad::MaterialCast(quad); |
2772 EXPECT_SIZE_EQ(io_surface_size_, io_surface_draw_quad->io_surface_size); | 2771 EXPECT_EQ(io_surface_size_, io_surface_draw_quad->io_surface_size); |
2773 EXPECT_NE(0u, io_surface_draw_quad->io_surface_resource_id); | 2772 EXPECT_NE(0u, io_surface_draw_quad->io_surface_resource_id); |
2774 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_RECTANGLE_ARB), | 2773 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_RECTANGLE_ARB), |
2775 resource_provider->TargetForTesting( | 2774 resource_provider->TargetForTesting( |
2776 io_surface_draw_quad->io_surface_resource_id)); | 2775 io_surface_draw_quad->io_surface_resource_id)); |
2777 | 2776 |
2778 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) | 2777 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) |
2779 .Times(1); | 2778 .Times(1); |
2780 if (delegating_renderer()) { | 2779 if (delegating_renderer()) { |
2781 // The io surface layer's resource should be sent to the parent. | 2780 // The io surface layer's resource should be sent to the parent. |
2782 EXPECT_CALL(*mock_context_, | 2781 EXPECT_CALL(*mock_context_, |
(...skipping 1929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4712 } | 4711 } |
4713 } | 4712 } |
4714 | 4713 |
4715 int commit_count_; | 4714 int commit_count_; |
4716 int commit_complete_count_; | 4715 int commit_complete_count_; |
4717 TestSwapPromiseResult swap_promise_result_[3]; | 4716 TestSwapPromiseResult swap_promise_result_[3]; |
4718 }; | 4717 }; |
4719 | 4718 |
4720 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); | 4719 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); |
4721 | 4720 |
| 4721 class LayerTreeHostTestKeepSwapPromise : public LayerTreeTest { |
| 4722 public: |
| 4723 LayerTreeHostTestKeepSwapPromise() {} |
| 4724 |
| 4725 void BeginTest() override { |
| 4726 layer_ = SolidColorLayer::Create(); |
| 4727 layer_->SetIsDrawable(true); |
| 4728 layer_->SetBounds(gfx::Size(10, 10)); |
| 4729 layer_tree_host()->SetRootLayer(layer_); |
| 4730 gfx::Size bounds(100, 100); |
| 4731 layer_tree_host()->SetViewportSize(bounds); |
| 4732 PostSetNeedsCommitToMainThread(); |
| 4733 } |
| 4734 |
| 4735 void DidCommit() override { |
| 4736 MainThreadTaskRunner()->PostTask( |
| 4737 FROM_HERE, base::Bind(&LayerTreeHostTestKeepSwapPromise::ChangeFrame, |
| 4738 base::Unretained(this))); |
| 4739 } |
| 4740 |
| 4741 void ChangeFrame() { |
| 4742 switch (layer_tree_host()->source_frame_number()) { |
| 4743 case 1: |
| 4744 layer_->SetBounds(gfx::Size(10, 11)); |
| 4745 layer_tree_host()->QueueSwapPromise( |
| 4746 make_scoped_ptr(new TestSwapPromise(&swap_promise_result_))); |
| 4747 break; |
| 4748 case 2: |
| 4749 break; |
| 4750 default: |
| 4751 NOTREACHED(); |
| 4752 break; |
| 4753 } |
| 4754 } |
| 4755 |
| 4756 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
| 4757 EXPECT_TRUE(result); |
| 4758 if (host_impl->active_tree()->source_frame_number() >= 1) { |
| 4759 // The commit changes layers so it should cause a swap. |
| 4760 base::AutoLock lock(swap_promise_result_.lock); |
| 4761 EXPECT_TRUE(swap_promise_result_.did_swap_called); |
| 4762 EXPECT_FALSE(swap_promise_result_.did_not_swap_called); |
| 4763 EXPECT_TRUE(swap_promise_result_.dtor_called); |
| 4764 EndTest(); |
| 4765 } |
| 4766 } |
| 4767 |
| 4768 void AfterTest() override {} |
| 4769 |
| 4770 private: |
| 4771 scoped_refptr<Layer> layer_; |
| 4772 TestSwapPromiseResult swap_promise_result_; |
| 4773 }; |
| 4774 |
| 4775 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise); |
| 4776 |
4722 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit | 4777 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit |
4723 : public LayerTreeHostTest { | 4778 : public LayerTreeHostTest { |
4724 protected: | 4779 protected: |
4725 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 4780 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
4726 | 4781 |
4727 void DidCommit() override { | 4782 void DidCommit() override { |
4728 layer_tree_host()->SetDeferCommits(true); | 4783 layer_tree_host()->SetDeferCommits(true); |
4729 layer_tree_host()->SetNeedsCommit(); | 4784 layer_tree_host()->SetNeedsCommit(); |
4730 } | 4785 } |
4731 | 4786 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4773 void DidDeferCommit() override { | 4828 void DidDeferCommit() override { |
4774 layer_tree_host()->DidLoseOutputSurface(); | 4829 layer_tree_host()->DidLoseOutputSurface(); |
4775 scoped_ptr<SwapPromise> swap_promise( | 4830 scoped_ptr<SwapPromise> swap_promise( |
4776 new TestSwapPromise(&swap_promise_result_)); | 4831 new TestSwapPromise(&swap_promise_result_)); |
4777 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); | 4832 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
4778 layer_tree_host()->SetDeferCommits(false); | 4833 layer_tree_host()->SetDeferCommits(false); |
4779 } | 4834 } |
4780 | 4835 |
4781 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, | 4836 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, |
4782 bool did_handle) override { | 4837 bool did_handle) override { |
| 4838 // This is needed so that the impl-thread state matches main-thread state. |
| 4839 host_impl->DidLoseOutputSurface(); |
4783 EndTest(); | 4840 EndTest(); |
4784 // This lets the test finally commit and exit. | |
4785 MainThreadTaskRunner()->PostTask( | |
4786 FROM_HERE, | |
4787 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit:: | |
4788 FindOutputSurface, | |
4789 base::Unretained(this))); | |
4790 } | |
4791 | |
4792 void FindOutputSurface() { | |
4793 layer_tree_host()->OnCreateAndInitializeOutputSurfaceAttempted(true); | |
4794 } | 4841 } |
4795 | 4842 |
4796 void AfterTest() override { | 4843 void AfterTest() override { |
4797 { | 4844 { |
4798 base::AutoLock lock(swap_promise_result_.lock); | 4845 base::AutoLock lock(swap_promise_result_.lock); |
4799 EXPECT_FALSE(swap_promise_result_.did_swap_called); | 4846 EXPECT_FALSE(swap_promise_result_.did_swap_called); |
4800 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); | 4847 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); |
4801 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); | 4848 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); |
4802 EXPECT_TRUE(swap_promise_result_.dtor_called); | 4849 EXPECT_TRUE(swap_promise_result_.dtor_called); |
4803 } | 4850 } |
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5912 | 5959 |
5913 protected: | 5960 protected: |
5914 FakeContentLayerClient client_; | 5961 FakeContentLayerClient client_; |
5915 size_t notify_ready_to_activate_count_; | 5962 size_t notify_ready_to_activate_count_; |
5916 size_t scheduled_manage_tiles_count_; | 5963 size_t scheduled_manage_tiles_count_; |
5917 }; | 5964 }; |
5918 | 5965 |
5919 MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestOneActivatePerManageTiles); | 5966 MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestOneActivatePerManageTiles); |
5920 | 5967 |
5921 } // namespace cc | 5968 } // namespace cc |
OLD | NEW |