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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { | 75 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { |
76 public: | 76 public: |
77 LayerTreeHostTestReadyToActivateEmpty() | 77 LayerTreeHostTestReadyToActivateEmpty() |
78 : did_notify_ready_to_activate_(false), | 78 : did_notify_ready_to_activate_(false), |
79 all_tiles_required_for_activation_are_ready_to_draw_(false), | 79 all_tiles_required_for_activation_are_ready_to_draw_(false), |
80 required_for_activation_count_(0) {} | 80 required_for_activation_count_(0) {} |
81 | 81 |
82 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 82 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
83 | 83 |
84 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | 84 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
85 const std::vector<PictureLayerImpl*>& layers = impl->GetPictureLayers(); | 85 const std::vector<PictureLayerImpl*>& layers = |
| 86 impl->sync_tree()->picture_layers(); |
86 required_for_activation_count_ = 0; | 87 required_for_activation_count_ = 0; |
87 for (const auto& layer : layers) { | 88 for (const auto& layer : layers) { |
88 FakePictureLayerImpl* fake_layer = | 89 FakePictureLayerImpl* fake_layer = |
89 static_cast<FakePictureLayerImpl*>(layer); | 90 static_cast<FakePictureLayerImpl*>(layer); |
90 required_for_activation_count_ += | 91 required_for_activation_count_ += |
91 fake_layer->CountTilesRequiredForActivation(); | 92 fake_layer->CountTilesRequiredForActivation(); |
92 } | 93 } |
93 } | 94 } |
94 | 95 |
95 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override { | 96 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 void AfterTest() override { | 133 void AfterTest() override { |
133 EXPECT_TRUE(did_notify_ready_to_activate_); | 134 EXPECT_TRUE(did_notify_ready_to_activate_); |
134 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_); | 135 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_); |
135 EXPECT_LE(size_t(1), required_for_activation_count_); | 136 EXPECT_LE(size_t(1), required_for_activation_count_); |
136 } | 137 } |
137 | 138 |
138 private: | 139 private: |
139 FakeContentLayerClient client_; | 140 FakeContentLayerClient client_; |
140 }; | 141 }; |
141 | 142 |
142 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty); | 143 // Multi-thread only because in single thread the commit goes directly to the |
| 144 // active tree, so notify ready to activate is skipped. |
| 145 MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty); |
143 | 146 |
144 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when | 147 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when |
145 // no raster tasks get scheduled. | 148 // no raster tasks get scheduled. |
146 class LayerTreeHostTestReadyToDrawEmpty : public LayerTreeHostTest { | 149 class LayerTreeHostTestReadyToDrawEmpty : public LayerTreeHostTest { |
147 public: | 150 public: |
148 LayerTreeHostTestReadyToDrawEmpty() | 151 LayerTreeHostTestReadyToDrawEmpty() |
149 : did_notify_ready_to_draw_(false), | 152 : did_notify_ready_to_draw_(false), |
150 all_tiles_required_for_draw_are_ready_to_draw_(false), | 153 all_tiles_required_for_draw_are_ready_to_draw_(false), |
151 required_for_draw_count_(0) {} | 154 required_for_draw_count_(0) {} |
152 | 155 |
153 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 156 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
154 | 157 |
155 void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override { | 158 void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override { |
156 did_notify_ready_to_draw_ = true; | 159 did_notify_ready_to_draw_ = true; |
157 const std::vector<PictureLayerImpl*>& layers = impl->GetPictureLayers(); | 160 const std::vector<PictureLayerImpl*>& layers = |
| 161 impl->active_tree()->picture_layers(); |
158 all_tiles_required_for_draw_are_ready_to_draw_ = | 162 all_tiles_required_for_draw_are_ready_to_draw_ = |
159 impl->tile_manager()->IsReadyToDraw(); | 163 impl->tile_manager()->IsReadyToDraw(); |
160 for (const auto& layer : layers) { | 164 for (const auto& layer : layers) { |
161 FakePictureLayerImpl* fake_layer = | 165 FakePictureLayerImpl* fake_layer = |
162 static_cast<FakePictureLayerImpl*>(layer); | 166 static_cast<FakePictureLayerImpl*>(layer); |
163 required_for_draw_count_ += fake_layer->CountTilesRequiredForDraw(); | 167 required_for_draw_count_ += fake_layer->CountTilesRequiredForDraw(); |
164 } | 168 } |
165 | 169 |
166 EndTest(); | 170 EndTest(); |
167 } | 171 } |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 layer_tree_host()->SetDeviceScaleFactor(4.f); | 575 layer_tree_host()->SetDeviceScaleFactor(4.f); |
572 break; | 576 break; |
573 default: | 577 default: |
574 // No extra commits. | 578 // No extra commits. |
575 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); | 579 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); |
576 } | 580 } |
577 } | 581 } |
578 | 582 |
579 void AfterTest() override { | 583 void AfterTest() override { |
580 EXPECT_EQ(gfx::Size(40, 40).ToString(), | 584 EXPECT_EQ(gfx::Size(40, 40).ToString(), |
581 scrollbar_->content_bounds().ToString()); | 585 scrollbar_->internal_content_bounds().ToString()); |
582 } | 586 } |
583 | 587 |
584 private: | 588 private: |
585 FakeContentLayerClient client_; | 589 FakeContentLayerClient client_; |
586 scoped_refptr<Layer> root_layer_; | 590 scoped_refptr<Layer> root_layer_; |
587 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_; | 591 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_; |
588 }; | 592 }; |
589 | 593 |
590 SINGLE_AND_MULTI_THREAD_TEST_F( | 594 SINGLE_AND_MULTI_THREAD_TEST_F( |
591 LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate); | 595 LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate); |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1786 | 1790 |
1787 class EvictionTestLayerImpl : public LayerImpl { | 1791 class EvictionTestLayerImpl : public LayerImpl { |
1788 public: | 1792 public: |
1789 static scoped_ptr<EvictionTestLayerImpl> Create(LayerTreeImpl* tree_impl, | 1793 static scoped_ptr<EvictionTestLayerImpl> Create(LayerTreeImpl* tree_impl, |
1790 int id) { | 1794 int id) { |
1791 return make_scoped_ptr(new EvictionTestLayerImpl(tree_impl, id)); | 1795 return make_scoped_ptr(new EvictionTestLayerImpl(tree_impl, id)); |
1792 } | 1796 } |
1793 ~EvictionTestLayerImpl() override {} | 1797 ~EvictionTestLayerImpl() override {} |
1794 | 1798 |
1795 void AppendQuads(RenderPass* render_pass, | 1799 void AppendQuads(RenderPass* render_pass, |
1796 const Occlusion& occlusion_in_content_space, | |
1797 AppendQuadsData* append_quads_data) override { | 1800 AppendQuadsData* append_quads_data) override { |
1798 ASSERT_TRUE(has_texture_); | 1801 ASSERT_TRUE(has_texture_); |
1799 ASSERT_NE(0u, layer_tree_impl()->resource_provider()->num_resources()); | 1802 ASSERT_NE(0u, layer_tree_impl()->resource_provider()->num_resources()); |
1800 } | 1803 } |
1801 | 1804 |
1802 void SetHasTexture(bool has_texture) { has_texture_ = has_texture; } | 1805 void SetHasTexture(bool has_texture) { has_texture_ = has_texture; } |
1803 | 1806 |
1804 private: | 1807 private: |
1805 EvictionTestLayerImpl(LayerTreeImpl* tree_impl, int id) | 1808 EvictionTestLayerImpl(LayerTreeImpl* tree_impl, int id) |
1806 : LayerImpl(tree_impl, id), has_texture_(false) {} | 1809 : LayerImpl(tree_impl, id), has_texture_(false) {} |
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2933 } | 2936 } |
2934 } | 2937 } |
2935 | 2938 |
2936 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) { | 2939 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) { |
2937 EXPECT_FALSE(did_initialize_gl_); | 2940 EXPECT_FALSE(did_initialize_gl_); |
2938 // SetAndInitializeContext3D calls SetNeedsCommit. | 2941 // SetAndInitializeContext3D calls SetNeedsCommit. |
2939 FakeOutputSurface* fake_output_surface = | 2942 FakeOutputSurface* fake_output_surface = |
2940 static_cast<FakeOutputSurface*>(host_impl->output_surface()); | 2943 static_cast<FakeOutputSurface*>(host_impl->output_surface()); |
2941 scoped_refptr<TestContextProvider> context_provider = | 2944 scoped_refptr<TestContextProvider> context_provider = |
2942 TestContextProvider::Create(); // Not bound to thread. | 2945 TestContextProvider::Create(); // Not bound to thread. |
2943 EXPECT_TRUE( | 2946 scoped_refptr<TestContextProvider> worker_context_provider = |
2944 fake_output_surface->InitializeAndSetContext3d(context_provider)); | 2947 TestContextProvider::Create(); // Not bound to thread. |
| 2948 EXPECT_TRUE(fake_output_surface->InitializeAndSetContext3d( |
| 2949 context_provider, worker_context_provider)); |
2945 did_initialize_gl_ = true; | 2950 did_initialize_gl_ = true; |
2946 } | 2951 } |
2947 | 2952 |
2948 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) { | 2953 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) { |
2949 EXPECT_TRUE(did_initialize_gl_); | 2954 EXPECT_TRUE(did_initialize_gl_); |
2950 EXPECT_FALSE(did_release_gl_); | 2955 EXPECT_FALSE(did_release_gl_); |
2951 // ReleaseGL calls SetNeedsCommit. | 2956 // ReleaseGL calls SetNeedsCommit. |
2952 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL(); | 2957 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL(); |
2953 did_release_gl_ = true; | 2958 did_release_gl_ = true; |
2954 } | 2959 } |
(...skipping 2210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5165 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); | 5170 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); |
5166 // Veto will take effect when layers are updated. | 5171 // Veto will take effect when layers are updated. |
5167 // The results will be verified after commit is completed below. | 5172 // The results will be verified after commit is completed below. |
5168 // Since we are manually marking picture pile as unsuitable, | 5173 // Since we are manually marking picture pile as unsuitable, |
5169 // make sure that the layer gets a chance to update. | 5174 // make sure that the layer gets a chance to update. |
5170 layer->SetNeedsDisplay(); | 5175 layer->SetNeedsDisplay(); |
5171 PostSetNeedsCommitToMainThread(); | 5176 PostSetNeedsCommitToMainThread(); |
5172 } | 5177 } |
5173 | 5178 |
5174 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 5179 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
5175 EXPECT_TRUE(host_impl->pending_tree()->use_gpu_rasterization()); | 5180 EXPECT_TRUE(host_impl->sync_tree()->use_gpu_rasterization()); |
5176 EXPECT_TRUE(host_impl->use_gpu_rasterization()); | 5181 EXPECT_TRUE(host_impl->use_gpu_rasterization()); |
5177 } | 5182 } |
5178 | 5183 |
5179 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 5184 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
5180 EXPECT_TRUE(host_impl->active_tree()->use_gpu_rasterization()); | 5185 EXPECT_TRUE(host_impl->active_tree()->use_gpu_rasterization()); |
5181 EXPECT_TRUE(host_impl->use_gpu_rasterization()); | 5186 EXPECT_TRUE(host_impl->use_gpu_rasterization()); |
5182 EndTest(); | 5187 EndTest(); |
5183 } | 5188 } |
5184 | 5189 |
5185 void AfterTest() override {} | 5190 void AfterTest() override {} |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5790 EndTest(); | 5795 EndTest(); |
5791 return draw_result; | 5796 return draw_result; |
5792 } | 5797 } |
5793 void AfterTest() override {} | 5798 void AfterTest() override {} |
5794 | 5799 |
5795 FakeContentLayerClient client_; | 5800 FakeContentLayerClient client_; |
5796 }; | 5801 }; |
5797 | 5802 |
5798 MULTI_THREAD_IMPL_TEST_F(RasterizeWithGpuRasterizationCreatesResources); | 5803 MULTI_THREAD_IMPL_TEST_F(RasterizeWithGpuRasterizationCreatesResources); |
5799 | 5804 |
5800 class GpuRasterizationRasterizesVisibleOnly : public LayerTreeHostTest { | 5805 class SynchronousGpuRasterizationRasterizesVisibleOnly |
| 5806 : public LayerTreeHostTest { |
5801 protected: | 5807 protected: |
5802 GpuRasterizationRasterizesVisibleOnly() : viewport_size_(1024, 2048) {} | 5808 SynchronousGpuRasterizationRasterizesVisibleOnly() |
| 5809 : viewport_size_(1024, 2048) {} |
5803 | 5810 |
5804 void InitializeSettings(LayerTreeSettings* settings) override { | 5811 void InitializeSettings(LayerTreeSettings* settings) override { |
5805 settings->impl_side_painting = true; | 5812 settings->impl_side_painting = true; |
5806 settings->gpu_rasterization_enabled = true; | 5813 settings->gpu_rasterization_enabled = true; |
5807 settings->gpu_rasterization_forced = true; | 5814 settings->gpu_rasterization_forced = true; |
| 5815 settings->threaded_gpu_rasterization_enabled = false; |
5808 } | 5816 } |
5809 | 5817 |
5810 void SetupTree() override { | 5818 void SetupTree() override { |
5811 client_.set_fill_with_nonsolid_color(true); | 5819 client_.set_fill_with_nonsolid_color(true); |
5812 | 5820 |
5813 scoped_ptr<FakePicturePile> pile( | 5821 scoped_ptr<FakePicturePile> pile( |
5814 new FakePicturePile(ImplSidePaintingSettings().minimum_contents_scale, | 5822 new FakePicturePile(ImplSidePaintingSettings().minimum_contents_scale, |
5815 ImplSidePaintingSettings().default_tile_grid_size)); | 5823 ImplSidePaintingSettings().default_tile_grid_size)); |
5816 scoped_refptr<FakePictureLayer> root = | 5824 scoped_refptr<FakePictureLayer> root = |
5817 FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass()); | 5825 FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5849 return draw_result; | 5857 return draw_result; |
5850 } | 5858 } |
5851 | 5859 |
5852 void AfterTest() override {} | 5860 void AfterTest() override {} |
5853 | 5861 |
5854 private: | 5862 private: |
5855 FakeContentLayerClient client_; | 5863 FakeContentLayerClient client_; |
5856 gfx::Size viewport_size_; | 5864 gfx::Size viewport_size_; |
5857 }; | 5865 }; |
5858 | 5866 |
5859 MULTI_THREAD_IMPL_TEST_F(GpuRasterizationRasterizesVisibleOnly); | 5867 MULTI_THREAD_IMPL_TEST_F(SynchronousGpuRasterizationRasterizesVisibleOnly); |
| 5868 |
| 5869 class ThreadedGpuRasterizationRasterizesBorderTiles : public LayerTreeHostTest { |
| 5870 protected: |
| 5871 ThreadedGpuRasterizationRasterizesBorderTiles() |
| 5872 : viewport_size_(1024, 2048) {} |
| 5873 |
| 5874 void InitializeSettings(LayerTreeSettings* settings) override { |
| 5875 settings->impl_side_painting = true; |
| 5876 settings->gpu_rasterization_enabled = true; |
| 5877 settings->gpu_rasterization_forced = true; |
| 5878 settings->threaded_gpu_rasterization_enabled = true; |
| 5879 } |
| 5880 |
| 5881 void SetupTree() override { |
| 5882 client_.set_fill_with_nonsolid_color(true); |
| 5883 |
| 5884 scoped_ptr<FakePicturePile> pile( |
| 5885 new FakePicturePile(ImplSidePaintingSettings().minimum_contents_scale, |
| 5886 ImplSidePaintingSettings().default_tile_grid_size)); |
| 5887 scoped_refptr<FakePictureLayer> root = |
| 5888 FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass()); |
| 5889 root->SetBounds(gfx::Size(10000, 10000)); |
| 5890 root->SetContentsOpaque(true); |
| 5891 |
| 5892 layer_tree_host()->SetRootLayer(root); |
| 5893 LayerTreeHostTest::SetupTree(); |
| 5894 layer_tree_host()->SetViewportSize(viewport_size_); |
| 5895 } |
| 5896 |
| 5897 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 5898 |
| 5899 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 5900 LayerTreeHostImpl::FrameData* frame_data, |
| 5901 DrawResult draw_result) override { |
| 5902 EXPECT_EQ(10u, host_impl->resource_provider()->num_resources()); |
| 5903 EndTest(); |
| 5904 return draw_result; |
| 5905 } |
| 5906 |
| 5907 void AfterTest() override {} |
| 5908 |
| 5909 private: |
| 5910 FakeContentLayerClient client_; |
| 5911 gfx::Size viewport_size_; |
| 5912 }; |
| 5913 |
| 5914 MULTI_THREAD_IMPL_TEST_F(ThreadedGpuRasterizationRasterizesBorderTiles); |
5860 | 5915 |
5861 class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles | 5916 class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles |
5862 : public LayerTreeHostTest { | 5917 : public LayerTreeHostTest { |
5863 protected: | 5918 protected: |
5864 LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles() | 5919 LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles() |
5865 : playback_allowed_event_(true, true) {} | 5920 : playback_allowed_event_(true, true) {} |
5866 | 5921 |
5867 void InitializeSettings(LayerTreeSettings* settings) override { | 5922 void InitializeSettings(LayerTreeSettings* settings) override { |
5868 settings->impl_side_painting = true; | 5923 settings->impl_side_painting = true; |
5869 } | 5924 } |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6235 | 6290 |
6236 void AfterTest() override { EXPECT_TRUE(did_commit_); } | 6291 void AfterTest() override { EXPECT_TRUE(did_commit_); } |
6237 | 6292 |
6238 private: | 6293 private: |
6239 bool did_commit_; | 6294 bool did_commit_; |
6240 }; | 6295 }; |
6241 | 6296 |
6242 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); | 6297 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); |
6243 | 6298 |
6244 } // namespace cc | 6299 } // namespace cc |
OLD | NEW |