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