| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "cc/test/fake_layer_tree_host_client.h" | 39 #include "cc/test/fake_layer_tree_host_client.h" |
| 40 #include "cc/test/fake_output_surface.h" | 40 #include "cc/test/fake_output_surface.h" |
| 41 #include "cc/test/fake_painted_scrollbar_layer.h" | 41 #include "cc/test/fake_painted_scrollbar_layer.h" |
| 42 #include "cc/test/fake_picture_layer.h" | 42 #include "cc/test/fake_picture_layer.h" |
| 43 #include "cc/test/fake_picture_layer_impl.h" | 43 #include "cc/test/fake_picture_layer_impl.h" |
| 44 #include "cc/test/fake_proxy.h" | 44 #include "cc/test/fake_proxy.h" |
| 45 #include "cc/test/fake_recording_source.h" | 45 #include "cc/test/fake_recording_source.h" |
| 46 #include "cc/test/fake_scoped_ui_resource.h" | 46 #include "cc/test/fake_scoped_ui_resource.h" |
| 47 #include "cc/test/fake_video_frame_provider.h" | 47 #include "cc/test/fake_video_frame_provider.h" |
| 48 #include "cc/test/geometry_test_utils.h" | 48 #include "cc/test/geometry_test_utils.h" |
| 49 #include "cc/test/layer_test_common.h" |
| 49 #include "cc/test/layer_tree_test.h" | 50 #include "cc/test/layer_tree_test.h" |
| 50 #include "cc/test/push_properties_counting_layer.h" | 51 #include "cc/test/push_properties_counting_layer.h" |
| 51 #include "cc/test/push_properties_counting_layer_impl.h" | 52 #include "cc/test/push_properties_counting_layer_impl.h" |
| 52 #include "cc/test/render_pass_test_utils.h" | 53 #include "cc/test/render_pass_test_utils.h" |
| 53 #include "cc/test/skia_common.h" | 54 #include "cc/test/skia_common.h" |
| 54 #include "cc/test/test_compositor_frame_sink.h" | 55 #include "cc/test/test_compositor_frame_sink.h" |
| 55 #include "cc/test/test_web_graphics_context_3d.h" | 56 #include "cc/test/test_web_graphics_context_3d.h" |
| 56 #include "cc/trees/clip_node.h" | 57 #include "cc/trees/clip_node.h" |
| 57 #include "cc/trees/effect_node.h" | 58 #include "cc/trees/effect_node.h" |
| 58 #include "cc/trees/frame_rate_counter.h" | 59 #include "cc/trees/frame_rate_counter.h" |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 } | 1037 } |
| 1037 } | 1038 } |
| 1038 | 1039 |
| 1039 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl, | 1040 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl, |
| 1040 LayerTreeHostImpl::FrameData* frame_data, | 1041 LayerTreeHostImpl::FrameData* frame_data, |
| 1041 DrawResult draw_result) override { | 1042 DrawResult draw_result) override { |
| 1042 LayerImpl* root_impl = impl->active_tree()->LayerById(root_->id()); | 1043 LayerImpl* root_impl = impl->active_tree()->LayerById(root_->id()); |
| 1043 LayerImpl* child_impl = impl->active_tree()->LayerById(child_->id()); | 1044 LayerImpl* child_impl = impl->active_tree()->LayerById(child_->id()); |
| 1044 switch (impl->active_tree()->source_frame_number()) { | 1045 switch (impl->active_tree()->source_frame_number()) { |
| 1045 case 0: | 1046 case 0: |
| 1046 EXPECT_TRUE(root_impl->GetRenderSurface()->AncestorPropertyChanged()); | 1047 EXPECT_TRUE(GetRenderSurface(root_impl)->AncestorPropertyChanged()); |
| 1047 EXPECT_TRUE(child_impl->GetRenderSurface()->AncestorPropertyChanged()); | 1048 EXPECT_TRUE(GetRenderSurface(child_impl)->AncestorPropertyChanged()); |
| 1048 PostSetNeedsCommitToMainThread(); | 1049 PostSetNeedsCommitToMainThread(); |
| 1049 break; | 1050 break; |
| 1050 case 1: | 1051 case 1: |
| 1051 EXPECT_FALSE(root_impl->GetRenderSurface()->AncestorPropertyChanged()); | 1052 EXPECT_FALSE(GetRenderSurface(root_impl)->AncestorPropertyChanged()); |
| 1052 EXPECT_FALSE(child_impl->GetRenderSurface()->AncestorPropertyChanged()); | 1053 EXPECT_FALSE(GetRenderSurface(child_impl)->AncestorPropertyChanged()); |
| 1053 PostSetNeedsCommitToMainThread(); | 1054 PostSetNeedsCommitToMainThread(); |
| 1054 break; | 1055 break; |
| 1055 case 2: | 1056 case 2: |
| 1056 EXPECT_TRUE(root_impl->GetRenderSurface()->AncestorPropertyChanged()); | 1057 EXPECT_TRUE(GetRenderSurface(root_impl)->AncestorPropertyChanged()); |
| 1057 EXPECT_TRUE(child_impl->GetRenderSurface()->AncestorPropertyChanged()); | 1058 EXPECT_TRUE(GetRenderSurface(child_impl)->AncestorPropertyChanged()); |
| 1058 PostSetNeedsCommitToMainThread(); | 1059 PostSetNeedsCommitToMainThread(); |
| 1059 break; | 1060 break; |
| 1060 case 3: | 1061 case 3: |
| 1061 EXPECT_FALSE(root_impl->GetRenderSurface()->AncestorPropertyChanged()); | 1062 EXPECT_FALSE(GetRenderSurface(root_impl)->AncestorPropertyChanged()); |
| 1062 EXPECT_TRUE(child_impl->GetRenderSurface()->AncestorPropertyChanged()); | 1063 EXPECT_TRUE(GetRenderSurface(child_impl)->AncestorPropertyChanged()); |
| 1063 EndTest(); | 1064 EndTest(); |
| 1064 PostSetNeedsCommitToMainThread(); | 1065 PostSetNeedsCommitToMainThread(); |
| 1065 break; | 1066 break; |
| 1066 case 4: | 1067 case 4: |
| 1067 EXPECT_FALSE(root_impl->GetRenderSurface()->AncestorPropertyChanged()); | 1068 EXPECT_FALSE(GetRenderSurface(root_impl)->AncestorPropertyChanged()); |
| 1068 EXPECT_FALSE(child_impl->GetRenderSurface()->AncestorPropertyChanged()); | 1069 EXPECT_FALSE(GetRenderSurface(child_impl)->AncestorPropertyChanged()); |
| 1069 EndTest(); | 1070 EndTest(); |
| 1070 break; | 1071 break; |
| 1071 } | 1072 } |
| 1072 | 1073 |
| 1073 return draw_result; | 1074 return draw_result; |
| 1074 } | 1075 } |
| 1075 | 1076 |
| 1076 void AfterTest() override {} | 1077 void AfterTest() override {} |
| 1077 | 1078 |
| 1078 private: | 1079 private: |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 layer_tree_host()->root_layer()->RemoveAllChildren(); | 1485 layer_tree_host()->root_layer()->RemoveAllChildren(); |
| 1485 layer_tree_host()->root_layer()->SetMaskLayer(mask_layer.get()); | 1486 layer_tree_host()->root_layer()->SetMaskLayer(mask_layer.get()); |
| 1486 break; | 1487 break; |
| 1487 } | 1488 } |
| 1488 } | 1489 } |
| 1489 | 1490 |
| 1490 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | 1491 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| 1491 switch (index_) { | 1492 switch (index_) { |
| 1492 case 0: | 1493 case 0: |
| 1493 index_++; | 1494 index_++; |
| 1494 EXPECT_FALSE(impl->sync_tree() | 1495 EXPECT_FALSE( |
| 1495 ->root_layer_for_testing() | 1496 GetRenderSurface(impl->sync_tree()->root_layer_for_testing()) |
| 1496 ->GetRenderSurface() | 1497 ->MaskLayer()); |
| 1497 ->MaskLayer()); | |
| 1498 break; | 1498 break; |
| 1499 case 1: | 1499 case 1: |
| 1500 EXPECT_TRUE(impl->sync_tree() | 1500 EXPECT_TRUE( |
| 1501 ->root_layer_for_testing() | 1501 GetRenderSurface(impl->sync_tree()->root_layer_for_testing()) |
| 1502 ->GetRenderSurface() | 1502 ->MaskLayer()); |
| 1503 ->MaskLayer()); | |
| 1504 EndTest(); | 1503 EndTest(); |
| 1505 break; | 1504 break; |
| 1506 } | 1505 } |
| 1507 } | 1506 } |
| 1508 | 1507 |
| 1509 void AfterTest() override {} | 1508 void AfterTest() override {} |
| 1510 | 1509 |
| 1511 scoped_refptr<Layer> mask_layer; | 1510 scoped_refptr<Layer> mask_layer; |
| 1512 int index_; | 1511 int index_; |
| 1513 }; | 1512 }; |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2584 // Compute all the layer transforms for the frame. | 2583 // Compute all the layer transforms for the frame. |
| 2585 LayerTreeHostImpl::FrameData frame_data; | 2584 LayerTreeHostImpl::FrameData frame_data; |
| 2586 impl->PrepareToDraw(&frame_data); | 2585 impl->PrepareToDraw(&frame_data); |
| 2587 impl->DidDrawAllLayers(frame_data); | 2586 impl->DidDrawAllLayers(frame_data); |
| 2588 | 2587 |
| 2589 const RenderSurfaceList& render_surface_list = | 2588 const RenderSurfaceList& render_surface_list = |
| 2590 *frame_data.render_surface_list; | 2589 *frame_data.render_surface_list; |
| 2591 | 2590 |
| 2592 // Both layers should be drawing into the root render surface. | 2591 // Both layers should be drawing into the root render surface. |
| 2593 ASSERT_EQ(1u, render_surface_list.size()); | 2592 ASSERT_EQ(1u, render_surface_list.size()); |
| 2594 ASSERT_EQ(root->GetRenderSurface(), render_surface_list[0]); | 2593 ASSERT_EQ(GetRenderSurface(root), render_surface_list[0]); |
| 2595 ASSERT_EQ(2, root->GetRenderSurface()->num_contributors()); | 2594 ASSERT_EQ(2, GetRenderSurface(root)->num_contributors()); |
| 2596 | 2595 |
| 2597 // The root render surface is the size of the viewport. | 2596 // The root render surface is the size of the viewport. |
| 2598 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), | 2597 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), GetRenderSurface(root)->content_rect()); |
| 2599 root->GetRenderSurface()->content_rect()); | |
| 2600 | 2598 |
| 2601 // The max tiling scale of the child should be scaled. | 2599 // The max tiling scale of the child should be scaled. |
| 2602 EXPECT_FLOAT_EQ(1.5f, child->MaximumTilingContentsScale()); | 2600 EXPECT_FLOAT_EQ(1.5f, child->MaximumTilingContentsScale()); |
| 2603 | 2601 |
| 2604 gfx::Transform scale_transform; | 2602 gfx::Transform scale_transform; |
| 2605 scale_transform.Scale(impl->active_tree()->device_scale_factor(), | 2603 scale_transform.Scale(impl->active_tree()->device_scale_factor(), |
| 2606 impl->active_tree()->device_scale_factor()); | 2604 impl->active_tree()->device_scale_factor()); |
| 2607 | 2605 |
| 2608 // The root layer is scaled by 2x. | 2606 // The root layer is scaled by 2x. |
| 2609 gfx::Transform root_screen_space_transform = scale_transform; | 2607 gfx::Transform root_screen_space_transform = scale_transform; |
| (...skipping 3062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5672 grand_child_->SetForceRenderSurfaceForTesting(true); | 5670 grand_child_->SetForceRenderSurfaceForTesting(true); |
| 5673 | 5671 |
| 5674 LayerTreeHostTest::SetupTree(); | 5672 LayerTreeHostTest::SetupTree(); |
| 5675 } | 5673 } |
| 5676 | 5674 |
| 5677 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 5675 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 5678 if (host_impl->sync_tree()->source_frame_number() >= 1) { | 5676 if (host_impl->sync_tree()->source_frame_number() >= 1) { |
| 5679 LayerImpl* grand_child_impl = | 5677 LayerImpl* grand_child_impl = |
| 5680 host_impl->sync_tree()->LayerById(grand_child_->id()); | 5678 host_impl->sync_tree()->LayerById(grand_child_->id()); |
| 5681 EXPECT_EQ(grand_child_impl->effect_tree_index(), | 5679 EXPECT_EQ(grand_child_impl->effect_tree_index(), |
| 5682 grand_child_impl->GetRenderSurface()->EffectTreeIndex()); | 5680 GetRenderSurface(grand_child_impl)->EffectTreeIndex()); |
| 5683 } | 5681 } |
| 5684 } | 5682 } |
| 5685 | 5683 |
| 5686 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 5684 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 5687 LayerImpl* grand_child_impl = | 5685 LayerImpl* grand_child_impl = |
| 5688 host_impl->active_tree()->LayerById(grand_child_->id()); | 5686 host_impl->active_tree()->LayerById(grand_child_->id()); |
| 5689 switch (host_impl->active_tree()->source_frame_number()) { | 5687 switch (host_impl->active_tree()->source_frame_number()) { |
| 5690 case 0: | 5688 case 0: |
| 5691 PostSetNeedsCommitToMainThread(); | 5689 PostSetNeedsCommitToMainThread(); |
| 5692 break; | 5690 break; |
| 5693 case 1: | 5691 case 1: |
| 5694 case 2: | 5692 case 2: |
| 5695 EXPECT_EQ(grand_child_impl->effect_tree_index(), | 5693 EXPECT_EQ(grand_child_impl->effect_tree_index(), |
| 5696 grand_child_impl->GetRenderSurface()->EffectTreeIndex()); | 5694 GetRenderSurface(grand_child_impl)->EffectTreeIndex()); |
| 5697 PostSetNeedsCommitToMainThread(); | 5695 PostSetNeedsCommitToMainThread(); |
| 5698 break; | 5696 break; |
| 5699 case 3: | 5697 case 3: |
| 5700 EXPECT_EQ(grand_child_impl->effect_tree_index(), | 5698 EXPECT_EQ(grand_child_impl->effect_tree_index(), |
| 5701 grand_child_impl->GetRenderSurface()->EffectTreeIndex()); | 5699 GetRenderSurface(grand_child_impl)->EffectTreeIndex()); |
| 5702 EndTest(); | 5700 EndTest(); |
| 5703 } | 5701 } |
| 5704 } | 5702 } |
| 5705 | 5703 |
| 5706 void DidCommit() override { | 5704 void DidCommit() override { |
| 5707 switch (layer_tree_host()->SourceFrameNumber()) { | 5705 switch (layer_tree_host()->SourceFrameNumber()) { |
| 5708 case 2: | 5706 case 2: |
| 5709 // Setting an empty viewport causes draws to get skipped, so the active | 5707 // Setting an empty viewport causes draws to get skipped, so the active |
| 5710 // tree won't update draw properties. | 5708 // tree won't update draw properties. |
| 5711 layer_tree_host()->SetViewportSize(gfx::Size()); | 5709 layer_tree_host()->SetViewportSize(gfx::Size()); |
| (...skipping 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7647 void AfterTest() override {} | 7645 void AfterTest() override {} |
| 7648 | 7646 |
| 7649 private: | 7647 private: |
| 7650 bool received_ack_ = false; | 7648 bool received_ack_ = false; |
| 7651 }; | 7649 }; |
| 7652 | 7650 |
| 7653 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDiscardAckAfterRelease); | 7651 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDiscardAckAfterRelease); |
| 7654 | 7652 |
| 7655 } // namespace | 7653 } // namespace |
| 7656 } // namespace cc | 7654 } // namespace cc |
| OLD | NEW |