| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 base::ThreadTaskRunnerHandle::Get()), | 86 base::ThreadTaskRunnerHandle::Get()), |
| 87 always_impl_thread_(&proxy_), | 87 always_impl_thread_(&proxy_), |
| 88 always_main_thread_blocked_(&proxy_), | 88 always_main_thread_blocked_(&proxy_), |
| 89 on_can_draw_state_changed_called_(false), | 89 on_can_draw_state_changed_called_(false), |
| 90 did_notify_ready_to_activate_(false), | 90 did_notify_ready_to_activate_(false), |
| 91 did_request_commit_(false), | 91 did_request_commit_(false), |
| 92 did_request_redraw_(false), | 92 did_request_redraw_(false), |
| 93 did_request_animate_(false), | 93 did_request_animate_(false), |
| 94 did_request_prepare_tiles_(false), | 94 did_request_prepare_tiles_(false), |
| 95 did_complete_page_scale_animation_(false), | 95 did_complete_page_scale_animation_(false), |
| 96 reduce_memory_result_(true), | 96 reduce_memory_result_(true) { |
| 97 current_limit_bytes_(0), | |
| 98 current_priority_cutoff_value_(0) { | |
| 99 media::InitializeMediaLibrary(); | 97 media::InitializeMediaLibrary(); |
| 100 } | 98 } |
| 101 | 99 |
| 102 LayerTreeSettings DefaultSettings() { | 100 LayerTreeSettings DefaultSettings() { |
| 103 LayerTreeSettings settings; | 101 LayerTreeSettings settings; |
| 104 settings.minimum_occlusion_tracking_size = gfx::Size(); | 102 settings.minimum_occlusion_tracking_size = gfx::Size(); |
| 105 settings.renderer_settings.texture_id_allocation_chunk_size = 1; | 103 settings.renderer_settings.texture_id_allocation_chunk_size = 1; |
| 106 settings.report_overscroll_only_for_scrollable_axes = true; | 104 settings.report_overscroll_only_for_scrollable_axes = true; |
| 107 settings.gpu_rasterization_enabled = true; | 105 settings.gpu_rasterization_enabled = true; |
| 108 return settings; | 106 return settings; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 135 did_request_redraw_ = true; | 133 did_request_redraw_ = true; |
| 136 } | 134 } |
| 137 void SetNeedsAnimateOnImplThread() override { did_request_animate_ = true; } | 135 void SetNeedsAnimateOnImplThread() override { did_request_animate_ = true; } |
| 138 void SetNeedsPrepareTilesOnImplThread() override { | 136 void SetNeedsPrepareTilesOnImplThread() override { |
| 139 did_request_prepare_tiles_ = true; | 137 did_request_prepare_tiles_ = true; |
| 140 } | 138 } |
| 141 void SetNeedsCommitOnImplThread() override { did_request_commit_ = true; } | 139 void SetNeedsCommitOnImplThread() override { did_request_commit_ = true; } |
| 142 void SetVideoNeedsBeginFrames(bool needs_begin_frames) override {} | 140 void SetVideoNeedsBeginFrames(bool needs_begin_frames) override {} |
| 143 void PostAnimationEventsToMainThreadOnImplThread( | 141 void PostAnimationEventsToMainThreadOnImplThread( |
| 144 scoped_ptr<AnimationEventsVector> events) override {} | 142 scoped_ptr<AnimationEventsVector> events) override {} |
| 145 bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, | |
| 146 int priority_cutoff) override { | |
| 147 current_limit_bytes_ = limit_bytes; | |
| 148 current_priority_cutoff_value_ = priority_cutoff; | |
| 149 return reduce_memory_result_; | |
| 150 } | |
| 151 bool IsInsideDraw() override { return false; } | 143 bool IsInsideDraw() override { return false; } |
| 152 void RenewTreePriority() override {} | 144 void RenewTreePriority() override {} |
| 153 void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, | 145 void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, |
| 154 base::TimeDelta delay) override { | 146 base::TimeDelta delay) override { |
| 155 animation_task_ = task; | 147 animation_task_ = task; |
| 156 requested_animation_delay_ = delay; | 148 requested_animation_delay_ = delay; |
| 157 } | 149 } |
| 158 void DidActivateSyncTree() override {} | 150 void DidActivateSyncTree() override {} |
| 159 void DidPrepareTiles() override {} | 151 void DidPrepareTiles() override {} |
| 160 void DidCompletePageScaleAnimationOnImplThread() override { | 152 void DidCompletePageScaleAnimationOnImplThread() override { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } else { | 353 } else { |
| 362 EXPECT_FALSE(host_impl_->CanDraw()); | 354 EXPECT_FALSE(host_impl_->CanDraw()); |
| 363 } | 355 } |
| 364 EXPECT_TRUE(on_can_draw_state_changed_called_); | 356 EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 365 on_can_draw_state_changed_called_ = false; | 357 on_can_draw_state_changed_called_ = false; |
| 366 | 358 |
| 367 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 359 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 368 EXPECT_TRUE(host_impl_->CanDraw()); | 360 EXPECT_TRUE(host_impl_->CanDraw()); |
| 369 EXPECT_TRUE(on_can_draw_state_changed_called_); | 361 EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 370 on_can_draw_state_changed_called_ = false; | 362 on_can_draw_state_changed_called_ = false; |
| 371 | |
| 372 // Toggle contents textures purged without causing any evictions, | |
| 373 // and make sure that it does not change can_draw. | |
| 374 set_reduce_memory_result(false); | |
| 375 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | |
| 376 host_impl_->memory_allocation_limit_bytes() - 1)); | |
| 377 EXPECT_TRUE(host_impl_->CanDraw()); | |
| 378 EXPECT_FALSE(on_can_draw_state_changed_called_); | |
| 379 on_can_draw_state_changed_called_ = false; | |
| 380 | |
| 381 // Toggle contents textures purged to make sure it toggles can_draw. | |
| 382 set_reduce_memory_result(true); | |
| 383 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | |
| 384 host_impl_->memory_allocation_limit_bytes() - 1)); | |
| 385 if (always_draw) { | |
| 386 EXPECT_TRUE(host_impl_->CanDraw()); | |
| 387 } else { | |
| 388 EXPECT_FALSE(host_impl_->CanDraw()); | |
| 389 } | |
| 390 EXPECT_TRUE(on_can_draw_state_changed_called_); | |
| 391 on_can_draw_state_changed_called_ = false; | |
| 392 | |
| 393 host_impl_->active_tree()->ResetContentsTexturesPurged(); | |
| 394 EXPECT_TRUE(host_impl_->CanDraw()); | |
| 395 EXPECT_TRUE(on_can_draw_state_changed_called_); | |
| 396 on_can_draw_state_changed_called_ = false; | |
| 397 } | 363 } |
| 398 | 364 |
| 399 void SetupMouseMoveAtWithDeviceScale(float device_scale_factor); | 365 void SetupMouseMoveAtWithDeviceScale(float device_scale_factor); |
| 400 | 366 |
| 401 protected: | 367 protected: |
| 402 virtual scoped_ptr<OutputSurface> CreateOutputSurface() { | 368 virtual scoped_ptr<OutputSurface> CreateOutputSurface() { |
| 403 return FakeOutputSurface::Create3d(); | 369 return FakeOutputSurface::Create3d(); |
| 404 } | 370 } |
| 405 | 371 |
| 406 void DrawOneFrame() { | 372 void DrawOneFrame() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 421 bool on_can_draw_state_changed_called_; | 387 bool on_can_draw_state_changed_called_; |
| 422 bool did_notify_ready_to_activate_; | 388 bool did_notify_ready_to_activate_; |
| 423 bool did_request_commit_; | 389 bool did_request_commit_; |
| 424 bool did_request_redraw_; | 390 bool did_request_redraw_; |
| 425 bool did_request_animate_; | 391 bool did_request_animate_; |
| 426 bool did_request_prepare_tiles_; | 392 bool did_request_prepare_tiles_; |
| 427 bool did_complete_page_scale_animation_; | 393 bool did_complete_page_scale_animation_; |
| 428 bool reduce_memory_result_; | 394 bool reduce_memory_result_; |
| 429 base::Closure animation_task_; | 395 base::Closure animation_task_; |
| 430 base::TimeDelta requested_animation_delay_; | 396 base::TimeDelta requested_animation_delay_; |
| 431 size_t current_limit_bytes_; | |
| 432 int current_priority_cutoff_value_; | |
| 433 }; | 397 }; |
| 434 | 398 |
| 435 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { | 399 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { |
| 436 bool always_draw = false; | 400 bool always_draw = false; |
| 437 CheckNotifyCalledIfCanDrawChanged(always_draw); | 401 CheckNotifyCalledIfCanDrawChanged(always_draw); |
| 438 } | 402 } |
| 439 | 403 |
| 440 TEST_F(LayerTreeHostImplTest, CanDrawIncompleteFrames) { | 404 TEST_F(LayerTreeHostImplTest, CanDrawIncompleteFrames) { |
| 441 CreateHostImpl(DefaultSettings(), | 405 CreateHostImpl(DefaultSettings(), |
| 442 FakeOutputSurface::CreateAlwaysDrawAndSwap3d()); | 406 FakeOutputSurface::CreateAlwaysDrawAndSwap3d()); |
| (...skipping 5243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5686 | 5650 |
| 5687 // Verify no quads are drawn when transparent background is set. | 5651 // Verify no quads are drawn when transparent background is set. |
| 5688 host_impl_->active_tree()->set_has_transparent_background(true); | 5652 host_impl_->active_tree()->set_has_transparent_background(true); |
| 5689 host_impl_->SetFullRootLayerDamage(); | 5653 host_impl_->SetFullRootLayerDamage(); |
| 5690 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); | 5654 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
| 5691 host_impl_->DrawLayers(&frame); | 5655 host_impl_->DrawLayers(&frame); |
| 5692 host_impl_->DidDrawAllLayers(frame); | 5656 host_impl_->DidDrawAllLayers(frame); |
| 5693 Mock::VerifyAndClearExpectations(&mock_context); | 5657 Mock::VerifyAndClearExpectations(&mock_context); |
| 5694 } | 5658 } |
| 5695 | 5659 |
| 5696 TEST_F(LayerTreeHostImplTest, ReleaseContentsTextureShouldTriggerCommit) { | |
| 5697 set_reduce_memory_result(false); | |
| 5698 | |
| 5699 // If changing the memory limit wouldn't result in changing what was | |
| 5700 // committed, then no commit should be requested. | |
| 5701 set_reduce_memory_result(false); | |
| 5702 host_impl_->set_max_memory_needed_bytes( | |
| 5703 host_impl_->memory_allocation_limit_bytes() - 1); | |
| 5704 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | |
| 5705 host_impl_->memory_allocation_limit_bytes() - 1)); | |
| 5706 EXPECT_FALSE(did_request_commit_); | |
| 5707 did_request_commit_ = false; | |
| 5708 | |
| 5709 // If changing the memory limit would result in changing what was | |
| 5710 // committed, then a commit should be requested, even though nothing was | |
| 5711 // evicted. | |
| 5712 set_reduce_memory_result(false); | |
| 5713 host_impl_->set_max_memory_needed_bytes( | |
| 5714 host_impl_->memory_allocation_limit_bytes()); | |
| 5715 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | |
| 5716 host_impl_->memory_allocation_limit_bytes() - 1)); | |
| 5717 EXPECT_TRUE(did_request_commit_); | |
| 5718 did_request_commit_ = false; | |
| 5719 | |
| 5720 // Especially if changing the memory limit caused evictions, we need | |
| 5721 // to re-commit. | |
| 5722 set_reduce_memory_result(true); | |
| 5723 host_impl_->set_max_memory_needed_bytes(1); | |
| 5724 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | |
| 5725 host_impl_->memory_allocation_limit_bytes() - 1)); | |
| 5726 EXPECT_TRUE(did_request_commit_); | |
| 5727 did_request_commit_ = false; | |
| 5728 | |
| 5729 // But if we set it to the same value that it was before, we shouldn't | |
| 5730 // re-commit. | |
| 5731 host_impl_->SetMemoryPolicy(ManagedMemoryPolicy( | |
| 5732 host_impl_->memory_allocation_limit_bytes())); | |
| 5733 EXPECT_FALSE(did_request_commit_); | |
| 5734 } | |
| 5735 | |
| 5736 class LayerTreeHostImplTestWithDelegatingRenderer | 5660 class LayerTreeHostImplTestWithDelegatingRenderer |
| 5737 : public LayerTreeHostImplTest { | 5661 : public LayerTreeHostImplTest { |
| 5738 protected: | 5662 protected: |
| 5739 scoped_ptr<OutputSurface> CreateOutputSurface() override { | 5663 scoped_ptr<OutputSurface> CreateOutputSurface() override { |
| 5740 return FakeOutputSurface::CreateDelegating3d(); | 5664 return FakeOutputSurface::CreateDelegating3d(); |
| 5741 } | 5665 } |
| 5742 | 5666 |
| 5743 void DrawFrameAndTestDamage(const gfx::RectF& expected_damage) { | 5667 void DrawFrameAndTestDamage(const gfx::RectF& expected_damage) { |
| 5744 bool expect_to_draw = !expected_damage.IsEmpty(); | 5668 bool expect_to_draw = !expected_damage.IsEmpty(); |
| 5745 | 5669 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6038 host_impl_ = LayerTreeHostImpl::Create( | 5962 host_impl_ = LayerTreeHostImpl::Create( |
| 6039 settings, this, &proxy_, &stats_instrumentation_, &shared_bitmap_manager_, | 5963 settings, this, &proxy_, &stats_instrumentation_, &shared_bitmap_manager_, |
| 6040 &gpu_memory_buffer_manager_, &task_graph_runner_, 0); | 5964 &gpu_memory_buffer_manager_, &task_graph_runner_, 0); |
| 6041 | 5965 |
| 6042 scoped_ptr<OutputSurface> output_surface( | 5966 scoped_ptr<OutputSurface> output_surface( |
| 6043 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); | 5967 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); |
| 6044 host_impl_->InitializeRenderer(output_surface.Pass()); | 5968 host_impl_->InitializeRenderer(output_surface.Pass()); |
| 6045 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); | 5969 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); |
| 6046 } | 5970 } |
| 6047 | 5971 |
| 6048 TEST_F(LayerTreeHostImplTest, MemoryPolicy) { | |
| 6049 ManagedMemoryPolicy policy1( | |
| 6050 456, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 1000); | |
| 6051 int everything_cutoff_value = ManagedMemoryPolicy::PriorityCutoffToValue( | |
| 6052 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING); | |
| 6053 int allow_nice_to_have_cutoff_value = | |
| 6054 ManagedMemoryPolicy::PriorityCutoffToValue( | |
| 6055 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE); | |
| 6056 int nothing_cutoff_value = ManagedMemoryPolicy::PriorityCutoffToValue( | |
| 6057 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); | |
| 6058 | |
| 6059 // GPU rasterization should be disabled by default on the tree(s) | |
| 6060 EXPECT_FALSE(host_impl_->active_tree()->use_gpu_rasterization()); | |
| 6061 EXPECT_TRUE(host_impl_->pending_tree() == NULL); | |
| 6062 | |
| 6063 host_impl_->SetVisible(true); | |
| 6064 host_impl_->SetMemoryPolicy(policy1); | |
| 6065 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); | |
| 6066 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); | |
| 6067 | |
| 6068 host_impl_->SetVisible(false); | |
| 6069 EXPECT_EQ(0u, current_limit_bytes_); | |
| 6070 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); | |
| 6071 | |
| 6072 host_impl_->SetVisible(true); | |
| 6073 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); | |
| 6074 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); | |
| 6075 | |
| 6076 // Now enable GPU rasterization and test if we get nice to have cutoff, | |
| 6077 // when visible. | |
| 6078 LayerTreeSettings settings; | |
| 6079 settings.gpu_rasterization_enabled = true; | |
| 6080 CreateHostImpl(settings, CreateOutputSurface()); | |
| 6081 host_impl_->SetContentIsSuitableForGpuRasterization(true); | |
| 6082 host_impl_->SetHasGpuRasterizationTrigger(true); | |
| 6083 host_impl_->SetVisible(true); | |
| 6084 host_impl_->SetMemoryPolicy(policy1); | |
| 6085 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); | |
| 6086 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_); | |
| 6087 | |
| 6088 host_impl_->SetVisible(false); | |
| 6089 EXPECT_EQ(0u, current_limit_bytes_); | |
| 6090 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); | |
| 6091 } | |
| 6092 | |
| 6093 TEST_F(LayerTreeHostImplTest, RequireHighResWhenVisible) { | 5972 TEST_F(LayerTreeHostImplTest, RequireHighResWhenVisible) { |
| 6094 ASSERT_TRUE(host_impl_->active_tree()); | 5973 ASSERT_TRUE(host_impl_->active_tree()); |
| 6095 | 5974 |
| 6096 // RequiresHighResToDraw is set when new output surface is used. | 5975 // RequiresHighResToDraw is set when new output surface is used. |
| 6097 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); | 5976 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
| 6098 | 5977 |
| 6099 host_impl_->ResetRequiresHighResToDraw(); | 5978 host_impl_->ResetRequiresHighResToDraw(); |
| 6100 | 5979 |
| 6101 host_impl_->SetVisible(false); | 5980 host_impl_->SetVisible(false); |
| 6102 EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); | 5981 EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
| (...skipping 1867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7970 // Hold an unowned pointer to the output surface to use for mock expectations. | 7849 // Hold an unowned pointer to the output surface to use for mock expectations. |
| 7971 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); | 7850 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); |
| 7972 | 7851 |
| 7973 CreateHostImpl(DefaultSettings(), output_surface.Pass()); | 7852 CreateHostImpl(DefaultSettings(), output_surface.Pass()); |
| 7974 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); | 7853 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); |
| 7975 host_impl_->BeginCommit(); | 7854 host_impl_->BeginCommit(); |
| 7976 } | 7855 } |
| 7977 | 7856 |
| 7978 } // namespace | 7857 } // namespace |
| 7979 } // namespace cc | 7858 } // namespace cc |
| OLD | NEW |