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_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/run_loop.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
18 #include "cc/animation/animation_host.h" | 19 #include "cc/animation/animation_host.h" |
19 #include "cc/animation/animation_id_provider.h" | 20 #include "cc/animation/animation_id_provider.h" |
20 #include "cc/animation/transform_operations.h" | 21 #include "cc/animation/transform_operations.h" |
21 #include "cc/base/math_util.h" | 22 #include "cc/base/math_util.h" |
22 #include "cc/input/browser_controls_offset_manager.h" | 23 #include "cc/input/browser_controls_offset_manager.h" |
23 #include "cc/input/main_thread_scrolling_reason.h" | 24 #include "cc/input/main_thread_scrolling_reason.h" |
24 #include "cc/input/page_scale_animation.h" | 25 #include "cc/input/page_scale_animation.h" |
25 #include "cc/input/scrollbar_animation_controller_thinning.h" | 26 #include "cc/input/scrollbar_animation_controller_thinning.h" |
26 #include "cc/layers/append_quads_data.h" | 27 #include "cc/layers/append_quads_data.h" |
(...skipping 19 matching lines...) Expand all Loading... |
46 #include "cc/resources/ui_resource_bitmap.h" | 47 #include "cc/resources/ui_resource_bitmap.h" |
47 #include "cc/resources/ui_resource_manager.h" | 48 #include "cc/resources/ui_resource_manager.h" |
48 #include "cc/test/animation_test_common.h" | 49 #include "cc/test/animation_test_common.h" |
49 #include "cc/test/begin_frame_args_test.h" | 50 #include "cc/test/begin_frame_args_test.h" |
50 #include "cc/test/fake_compositor_frame_sink.h" | 51 #include "cc/test/fake_compositor_frame_sink.h" |
51 #include "cc/test/fake_layer_tree_host_impl.h" | 52 #include "cc/test/fake_layer_tree_host_impl.h" |
52 #include "cc/test/fake_mask_layer_impl.h" | 53 #include "cc/test/fake_mask_layer_impl.h" |
53 #include "cc/test/fake_output_surface.h" | 54 #include "cc/test/fake_output_surface.h" |
54 #include "cc/test/fake_picture_layer_impl.h" | 55 #include "cc/test/fake_picture_layer_impl.h" |
55 #include "cc/test/fake_raster_source.h" | 56 #include "cc/test/fake_raster_source.h" |
| 57 #include "cc/test/fake_recording_source.h" |
56 #include "cc/test/fake_video_frame_provider.h" | 58 #include "cc/test/fake_video_frame_provider.h" |
57 #include "cc/test/geometry_test_utils.h" | 59 #include "cc/test/geometry_test_utils.h" |
58 #include "cc/test/layer_test_common.h" | 60 #include "cc/test/layer_test_common.h" |
59 #include "cc/test/layer_tree_test.h" | 61 #include "cc/test/layer_tree_test.h" |
| 62 #include "cc/test/skia_common.h" |
60 #include "cc/test/test_compositor_frame_sink.h" | 63 #include "cc/test/test_compositor_frame_sink.h" |
61 #include "cc/test/test_task_graph_runner.h" | 64 #include "cc/test/test_task_graph_runner.h" |
62 #include "cc/test/test_web_graphics_context_3d.h" | 65 #include "cc/test/test_web_graphics_context_3d.h" |
63 #include "cc/trees/effect_node.h" | 66 #include "cc/trees/effect_node.h" |
64 #include "cc/trees/layer_tree_host_common.h" | 67 #include "cc/trees/layer_tree_host_common.h" |
65 #include "cc/trees/layer_tree_impl.h" | 68 #include "cc/trees/layer_tree_impl.h" |
66 #include "cc/trees/mutator_host.h" | 69 #include "cc/trees/mutator_host.h" |
67 #include "cc/trees/single_thread_proxy.h" | 70 #include "cc/trees/single_thread_proxy.h" |
68 #include "cc/trees/transform_node.h" | 71 #include "cc/trees/transform_node.h" |
69 #include "media/base/media.h" | 72 #include "media/base/media.h" |
(...skipping 26 matching lines...) Expand all Loading... |
96 LayerTreeHostImplTest() | 99 LayerTreeHostImplTest() |
97 : task_runner_provider_(base::ThreadTaskRunnerHandle::Get()), | 100 : task_runner_provider_(base::ThreadTaskRunnerHandle::Get()), |
98 always_main_thread_blocked_(&task_runner_provider_), | 101 always_main_thread_blocked_(&task_runner_provider_), |
99 on_can_draw_state_changed_called_(false), | 102 on_can_draw_state_changed_called_(false), |
100 did_notify_ready_to_activate_(false), | 103 did_notify_ready_to_activate_(false), |
101 did_request_commit_(false), | 104 did_request_commit_(false), |
102 did_request_redraw_(false), | 105 did_request_redraw_(false), |
103 did_request_next_frame_(false), | 106 did_request_next_frame_(false), |
104 did_request_prepare_tiles_(false), | 107 did_request_prepare_tiles_(false), |
105 did_complete_page_scale_animation_(false), | 108 did_complete_page_scale_animation_(false), |
106 reduce_memory_result_(true) { | 109 reduce_memory_result_(true), |
| 110 did_request_impl_side_invalidation_(false) { |
107 media::InitializeMediaLibrary(); | 111 media::InitializeMediaLibrary(); |
108 } | 112 } |
109 | 113 |
110 LayerTreeSettings DefaultSettings() { | 114 LayerTreeSettings DefaultSettings() { |
111 LayerTreeSettings settings; | 115 LayerTreeSettings settings; |
112 settings.minimum_occlusion_tracking_size = gfx::Size(); | 116 settings.minimum_occlusion_tracking_size = gfx::Size(); |
113 settings.renderer_settings.texture_id_allocation_chunk_size = 1; | 117 settings.renderer_settings.texture_id_allocation_chunk_size = 1; |
114 settings.verify_clip_tree_calculations = true; | 118 settings.verify_clip_tree_calculations = true; |
115 settings.renderer_settings.buffer_to_texture_target_map = | 119 settings.renderer_settings.buffer_to_texture_target_map = |
116 DefaultBufferToTextureTargetMapForTesting(); | 120 DefaultBufferToTextureTargetMapForTesting(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 void OnDrawForCompositorFrameSink(bool resourceless_software_draw) override { | 168 void OnDrawForCompositorFrameSink(bool resourceless_software_draw) override { |
165 std::unique_ptr<LayerTreeHostImpl::FrameData> frame( | 169 std::unique_ptr<LayerTreeHostImpl::FrameData> frame( |
166 new LayerTreeHostImpl::FrameData); | 170 new LayerTreeHostImpl::FrameData); |
167 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(frame.get())); | 171 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(frame.get())); |
168 last_on_draw_render_passes_.clear(); | 172 last_on_draw_render_passes_.clear(); |
169 RenderPass::CopyAll(frame->render_passes, &last_on_draw_render_passes_); | 173 RenderPass::CopyAll(frame->render_passes, &last_on_draw_render_passes_); |
170 host_impl_->DrawLayers(frame.get()); | 174 host_impl_->DrawLayers(frame.get()); |
171 host_impl_->DidDrawAllLayers(*frame); | 175 host_impl_->DidDrawAllLayers(*frame); |
172 last_on_draw_frame_ = std::move(frame); | 176 last_on_draw_frame_ = std::move(frame); |
173 } | 177 } |
| 178 void NeedsImplSideInvalidation() override { |
| 179 did_request_impl_side_invalidation_ = true; |
| 180 } |
174 | 181 |
175 void set_reduce_memory_result(bool reduce_memory_result) { | 182 void set_reduce_memory_result(bool reduce_memory_result) { |
176 reduce_memory_result_ = reduce_memory_result; | 183 reduce_memory_result_ = reduce_memory_result; |
177 } | 184 } |
178 | 185 |
179 virtual bool CreateHostImpl( | 186 virtual bool CreateHostImpl( |
180 const LayerTreeSettings& settings, | 187 const LayerTreeSettings& settings, |
181 std::unique_ptr<CompositorFrameSink> compositor_frame_sink) { | 188 std::unique_ptr<CompositorFrameSink> compositor_frame_sink) { |
182 return CreateHostImplWithTaskRunnerProvider( | 189 return CreateHostImplWithTaskRunnerProvider( |
183 settings, std::move(compositor_frame_sink), &task_runner_provider_); | 190 settings, std::move(compositor_frame_sink), &task_runner_provider_); |
184 } | 191 } |
185 | 192 |
186 AnimationHost* GetImplAnimationHost() const { | 193 AnimationHost* GetImplAnimationHost() const { |
187 return static_cast<AnimationHost*>(host_impl_->mutator_host()); | 194 return static_cast<AnimationHost*>(host_impl_->mutator_host()); |
188 } | 195 } |
189 | 196 |
190 virtual bool CreateHostImplWithTaskRunnerProvider( | 197 virtual bool CreateHostImplWithTaskRunnerProvider( |
191 const LayerTreeSettings& settings, | 198 const LayerTreeSettings& settings, |
192 std::unique_ptr<CompositorFrameSink> compositor_frame_sink, | 199 std::unique_ptr<CompositorFrameSink> compositor_frame_sink, |
193 TaskRunnerProvider* task_runner_provider) { | 200 TaskRunnerProvider* task_runner_provider) { |
194 if (host_impl_) | 201 if (host_impl_) |
195 host_impl_->ReleaseCompositorFrameSink(); | 202 host_impl_->ReleaseCompositorFrameSink(); |
| 203 host_impl_.reset(); |
| 204 InitializeImageWorker(settings); |
196 host_impl_ = LayerTreeHostImpl::Create( | 205 host_impl_ = LayerTreeHostImpl::Create( |
197 settings, this, task_runner_provider, &stats_instrumentation_, | 206 settings, this, task_runner_provider, &stats_instrumentation_, |
198 &task_graph_runner_, | 207 &task_graph_runner_, |
199 AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0, nullptr); | 208 AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0, |
| 209 image_worker_ ? image_worker_->task_runner() : nullptr); |
200 compositor_frame_sink_ = std::move(compositor_frame_sink); | 210 compositor_frame_sink_ = std::move(compositor_frame_sink); |
201 host_impl_->SetVisible(true); | 211 host_impl_->SetVisible(true); |
202 bool init = host_impl_->InitializeRenderer(compositor_frame_sink_.get()); | 212 bool init = host_impl_->InitializeRenderer(compositor_frame_sink_.get()); |
203 host_impl_->SetViewportSize(gfx::Size(10, 10)); | 213 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
204 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); | 214 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
205 // Set the BeginFrameArgs so that methods which use it are able to. | 215 // Set the BeginFrameArgs so that methods which use it are able to. |
206 host_impl_->WillBeginImplFrame(CreateBeginFrameArgsForTesting( | 216 host_impl_->WillBeginImplFrame(CreateBeginFrameArgsForTesting( |
207 BEGINFRAME_FROM_HERE, 0, 1, | 217 BEGINFRAME_FROM_HERE, 0, 1, |
208 base::TimeTicks() + base::TimeDelta::FromMilliseconds(1))); | 218 base::TimeTicks() + base::TimeDelta::FromMilliseconds(1))); |
209 host_impl_->DidFinishImplFrame(); | 219 host_impl_->DidFinishImplFrame(); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 497 |
488 void BeginImplFrameAndAnimate(BeginFrameArgs begin_frame_args, | 498 void BeginImplFrameAndAnimate(BeginFrameArgs begin_frame_args, |
489 base::TimeTicks frame_time) { | 499 base::TimeTicks frame_time) { |
490 begin_frame_args.frame_time = frame_time; | 500 begin_frame_args.frame_time = frame_time; |
491 host_impl_->WillBeginImplFrame(begin_frame_args); | 501 host_impl_->WillBeginImplFrame(begin_frame_args); |
492 host_impl_->Animate(); | 502 host_impl_->Animate(); |
493 host_impl_->UpdateAnimationState(true); | 503 host_impl_->UpdateAnimationState(true); |
494 host_impl_->DidFinishImplFrame(); | 504 host_impl_->DidFinishImplFrame(); |
495 } | 505 } |
496 | 506 |
| 507 void InitializeImageWorker(const LayerTreeSettings& settings) { |
| 508 if (settings.enable_checker_imaging) { |
| 509 image_worker_ = base::MakeUnique<base::Thread>("ImageWorker"); |
| 510 ASSERT_TRUE(image_worker_->Start()); |
| 511 } else { |
| 512 image_worker_.reset(); |
| 513 } |
| 514 } |
| 515 |
497 FakeImplTaskRunnerProvider task_runner_provider_; | 516 FakeImplTaskRunnerProvider task_runner_provider_; |
498 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; | 517 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; |
499 | 518 |
500 TestTaskGraphRunner task_graph_runner_; | 519 TestTaskGraphRunner task_graph_runner_; |
501 std::unique_ptr<CompositorFrameSink> compositor_frame_sink_; | 520 std::unique_ptr<CompositorFrameSink> compositor_frame_sink_; |
502 std::unique_ptr<LayerTreeHostImpl> host_impl_; | 521 std::unique_ptr<LayerTreeHostImpl> host_impl_; |
503 FakeRenderingStatsInstrumentation stats_instrumentation_; | 522 FakeRenderingStatsInstrumentation stats_instrumentation_; |
504 bool on_can_draw_state_changed_called_; | 523 bool on_can_draw_state_changed_called_; |
505 bool did_notify_ready_to_activate_; | 524 bool did_notify_ready_to_activate_; |
506 bool did_request_commit_; | 525 bool did_request_commit_; |
507 bool did_request_redraw_; | 526 bool did_request_redraw_; |
508 bool did_request_next_frame_; | 527 bool did_request_next_frame_; |
509 bool did_request_prepare_tiles_; | 528 bool did_request_prepare_tiles_; |
510 bool did_complete_page_scale_animation_; | 529 bool did_complete_page_scale_animation_; |
511 bool reduce_memory_result_; | 530 bool reduce_memory_result_; |
| 531 bool did_request_impl_side_invalidation_; |
512 base::Closure animation_task_; | 532 base::Closure animation_task_; |
513 base::TimeDelta requested_animation_delay_; | 533 base::TimeDelta requested_animation_delay_; |
514 std::unique_ptr<LayerTreeHostImpl::FrameData> last_on_draw_frame_; | 534 std::unique_ptr<LayerTreeHostImpl::FrameData> last_on_draw_frame_; |
515 RenderPassList last_on_draw_render_passes_; | 535 RenderPassList last_on_draw_render_passes_; |
516 scoped_refptr<AnimationTimeline> timeline_; | 536 scoped_refptr<AnimationTimeline> timeline_; |
| 537 std::unique_ptr<base::Thread> image_worker_; |
517 }; | 538 }; |
518 | 539 |
519 // A test fixture for new animation timelines tests. | 540 // A test fixture for new animation timelines tests. |
520 class LayerTreeHostImplTimelinesTest : public LayerTreeHostImplTest { | 541 class LayerTreeHostImplTimelinesTest : public LayerTreeHostImplTest { |
521 public: | 542 public: |
522 void SetUp() override { | 543 void SetUp() override { |
523 CreateHostImpl(DefaultSettings(), CreateCompositorFrameSink()); | 544 CreateHostImpl(DefaultSettings(), CreateCompositorFrameSink()); |
524 } | 545 } |
525 }; | 546 }; |
526 | 547 |
(...skipping 11205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11732 TEST_F(LayerTreeHostImplTest, | 11753 TEST_F(LayerTreeHostImplTest, |
11733 LayerTreeHostImplTestScrollbarStatesInMainThreadScorlling) { | 11754 LayerTreeHostImplTestScrollbarStatesInMainThreadScorlling) { |
11734 SetupMouseMoveAtTestScrollbarStates(true); | 11755 SetupMouseMoveAtTestScrollbarStates(true); |
11735 } | 11756 } |
11736 | 11757 |
11737 TEST_F(LayerTreeHostImplTest, | 11758 TEST_F(LayerTreeHostImplTest, |
11738 LayerTreeHostImplTestScrollbarStatesInNotMainThreadScorlling) { | 11759 LayerTreeHostImplTestScrollbarStatesInNotMainThreadScorlling) { |
11739 SetupMouseMoveAtTestScrollbarStates(false); | 11760 SetupMouseMoveAtTestScrollbarStates(false); |
11740 } | 11761 } |
11741 | 11762 |
| 11763 TEST_F(LayerTreeHostImplTest, CheckerImagingTileInvalidation) { |
| 11764 LayerTreeSettings settings = DefaultSettings(); |
| 11765 settings.enable_checker_imaging = true; |
| 11766 settings.default_tile_size = gfx::Size(256, 256); |
| 11767 settings.max_untiled_layer_size = gfx::Size(256, 256); |
| 11768 CreateHostImpl(settings, CreateCompositorFrameSink()); |
| 11769 gfx::Size layer_size = gfx::Size(750, 750); |
| 11770 |
| 11771 std::unique_ptr<FakeRecordingSource> recording_source = |
| 11772 FakeRecordingSource::CreateFilledRecordingSource(layer_size); |
| 11773 recording_source->SetGenerateDiscardableImagesMetadata(true); |
| 11774 sk_sp<SkImage> checkerable_image = |
| 11775 CreateDiscardableImage(gfx::Size(500, 500)); |
| 11776 recording_source->add_draw_image(checkerable_image, gfx::Point(0, 0)); |
| 11777 |
| 11778 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
| 11779 PaintFlags non_solid_flags; |
| 11780 non_solid_flags.setColor(non_solid_color); |
| 11781 recording_source->add_draw_rect_with_flags(gfx::Rect(510, 0, 200, 600), |
| 11782 non_solid_flags); |
| 11783 recording_source->add_draw_rect_with_flags(gfx::Rect(0, 510, 200, 400), |
| 11784 non_solid_flags); |
| 11785 recording_source->Rerecord(); |
| 11786 scoped_refptr<FakeRasterSource> raster_source = |
| 11787 FakeRasterSource::CreateFromRecordingSource(recording_source.get(), |
| 11788 false); |
| 11789 |
| 11790 // Create the pending tree. |
| 11791 host_impl_->BeginCommit(); |
| 11792 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
| 11793 host_impl_->SetViewportSize(layer_size); |
| 11794 pending_tree->SetRootLayerForTesting( |
| 11795 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, 1, |
| 11796 raster_source)); |
| 11797 FakePictureLayerImpl* root = |
| 11798 static_cast<FakePictureLayerImpl*>(*pending_tree->begin()); |
| 11799 root->SetBounds(layer_size); |
| 11800 root->SetDrawsContent(true); |
| 11801 pending_tree->BuildPropertyTreesForTesting(); |
| 11802 |
| 11803 // CompleteCommit which should perform a PrepareTiles, adding tilings for the |
| 11804 // root layer, each one having a raster task. |
| 11805 host_impl_->CommitComplete(); |
| 11806 EXPECT_EQ(root->num_tilings(), 1U); |
| 11807 const PictureLayerTiling* tiling = root->tilings()->tiling_at(0); |
| 11808 EXPECT_EQ(tiling->AllTilesForTesting().size(), 9U); |
| 11809 for (auto* tile : tiling->AllTilesForTesting()) |
| 11810 EXPECT_TRUE(tile->HasRasterTask()); |
| 11811 |
| 11812 // Activate the pending tree and ensure that all tiles are rasterized. |
| 11813 while (!did_notify_ready_to_activate_) |
| 11814 base::RunLoop().RunUntilIdle(); |
| 11815 for (auto* tile : tiling->AllTilesForTesting()) |
| 11816 EXPECT_FALSE(tile->HasRasterTask()); |
| 11817 |
| 11818 // PrepareTiles should have scheduled a decode with the ImageDecodeService, |
| 11819 // ensure that it requests an impl-side invalidation. |
| 11820 while (!did_request_impl_side_invalidation_) |
| 11821 base::RunLoop().RunUntilIdle(); |
| 11822 |
| 11823 // Invalidate content on impl-side and ensure that the correct tiles are |
| 11824 // invalidated on the pending tree. |
| 11825 host_impl_->InvalidateContentOnImplSide(); |
| 11826 pending_tree = host_impl_->pending_tree(); |
| 11827 root = static_cast<FakePictureLayerImpl*>(*pending_tree->begin()); |
| 11828 for (auto* tile : root->tilings()->tiling_at(0)->AllTilesForTesting()) { |
| 11829 if (tile->tiling_i_index() < 2 && tile->tiling_j_index() < 2) |
| 11830 EXPECT_TRUE(tile->HasRasterTask()); |
| 11831 else |
| 11832 EXPECT_FALSE(tile->HasRasterTask()); |
| 11833 } |
| 11834 Region expected_invalidation( |
| 11835 raster_source->GetRectForImage(checkerable_image->uniqueID())); |
| 11836 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); |
| 11837 } |
| 11838 |
11742 } // namespace | 11839 } // namespace |
11743 } // namespace cc | 11840 } // namespace cc |
OLD | NEW |