| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 base::MessageLoopProxy::current()), | 79 base::MessageLoopProxy::current()), |
| 80 always_impl_thread_(&proxy_), | 80 always_impl_thread_(&proxy_), |
| 81 always_main_thread_blocked_(&proxy_), | 81 always_main_thread_blocked_(&proxy_), |
| 82 shared_bitmap_manager_(new TestSharedBitmapManager), | 82 shared_bitmap_manager_(new TestSharedBitmapManager), |
| 83 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager), | 83 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager), |
| 84 on_can_draw_state_changed_called_(false), | 84 on_can_draw_state_changed_called_(false), |
| 85 did_notify_ready_to_activate_(false), | 85 did_notify_ready_to_activate_(false), |
| 86 did_request_commit_(false), | 86 did_request_commit_(false), |
| 87 did_request_redraw_(false), | 87 did_request_redraw_(false), |
| 88 did_request_animate_(false), | 88 did_request_animate_(false), |
| 89 did_request_manage_tiles_(false), | 89 did_request_prepare_tiles_(false), |
| 90 reduce_memory_result_(true), | 90 reduce_memory_result_(true), |
| 91 current_limit_bytes_(0), | 91 current_limit_bytes_(0), |
| 92 current_priority_cutoff_value_(0) { | 92 current_priority_cutoff_value_(0) { |
| 93 } | 93 } |
| 94 | 94 |
| 95 LayerTreeSettings DefaultSettings() { | 95 LayerTreeSettings DefaultSettings() { |
| 96 LayerTreeSettings settings; | 96 LayerTreeSettings settings; |
| 97 settings.minimum_occlusion_tracking_size = gfx::Size(); | 97 settings.minimum_occlusion_tracking_size = gfx::Size(); |
| 98 settings.impl_side_painting = true; | 98 settings.impl_side_painting = true; |
| 99 settings.renderer_settings.texture_id_allocation_chunk_size = 1; | 99 settings.renderer_settings.texture_id_allocation_chunk_size = 1; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 122 void NotifyReadyToActivate() override { | 122 void NotifyReadyToActivate() override { |
| 123 did_notify_ready_to_activate_ = true; | 123 did_notify_ready_to_activate_ = true; |
| 124 host_impl_->ActivateSyncTree(); | 124 host_impl_->ActivateSyncTree(); |
| 125 } | 125 } |
| 126 void NotifyReadyToDraw() override {} | 126 void NotifyReadyToDraw() override {} |
| 127 void SetNeedsRedrawOnImplThread() override { did_request_redraw_ = true; } | 127 void SetNeedsRedrawOnImplThread() override { did_request_redraw_ = true; } |
| 128 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) override { | 128 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) override { |
| 129 did_request_redraw_ = true; | 129 did_request_redraw_ = true; |
| 130 } | 130 } |
| 131 void SetNeedsAnimateOnImplThread() override { did_request_animate_ = true; } | 131 void SetNeedsAnimateOnImplThread() override { did_request_animate_ = true; } |
| 132 void SetNeedsManageTilesOnImplThread() override { | 132 void SetNeedsPrepareTilesOnImplThread() override { |
| 133 did_request_manage_tiles_ = true; | 133 did_request_prepare_tiles_ = true; |
| 134 } | 134 } |
| 135 void SetNeedsCommitOnImplThread() override { did_request_commit_ = true; } | 135 void SetNeedsCommitOnImplThread() override { did_request_commit_ = true; } |
| 136 void PostAnimationEventsToMainThreadOnImplThread( | 136 void PostAnimationEventsToMainThreadOnImplThread( |
| 137 scoped_ptr<AnimationEventsVector> events) override {} | 137 scoped_ptr<AnimationEventsVector> events) override {} |
| 138 bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, | 138 bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, |
| 139 int priority_cutoff) override { | 139 int priority_cutoff) override { |
| 140 current_limit_bytes_ = limit_bytes; | 140 current_limit_bytes_ = limit_bytes; |
| 141 current_priority_cutoff_value_ = priority_cutoff; | 141 current_priority_cutoff_value_ = priority_cutoff; |
| 142 return reduce_memory_result_; | 142 return reduce_memory_result_; |
| 143 } | 143 } |
| 144 bool IsInsideDraw() override { return false; } | 144 bool IsInsideDraw() override { return false; } |
| 145 void RenewTreePriority() override {} | 145 void RenewTreePriority() override {} |
| 146 void PostDelayedScrollbarFadeOnImplThread(const base::Closure& start_fade, | 146 void PostDelayedScrollbarFadeOnImplThread(const base::Closure& start_fade, |
| 147 base::TimeDelta delay) override { | 147 base::TimeDelta delay) override { |
| 148 scrollbar_fade_start_ = start_fade; | 148 scrollbar_fade_start_ = start_fade; |
| 149 requested_scrollbar_animation_delay_ = delay; | 149 requested_scrollbar_animation_delay_ = delay; |
| 150 } | 150 } |
| 151 void DidActivateSyncTree() override {} | 151 void DidActivateSyncTree() override {} |
| 152 void DidManageTiles() override {} | 152 void DidPrepareTiles() override {} |
| 153 | 153 |
| 154 void set_reduce_memory_result(bool reduce_memory_result) { | 154 void set_reduce_memory_result(bool reduce_memory_result) { |
| 155 reduce_memory_result_ = reduce_memory_result; | 155 reduce_memory_result_ = reduce_memory_result; |
| 156 } | 156 } |
| 157 | 157 |
| 158 virtual bool CreateHostImpl(const LayerTreeSettings& settings, | 158 virtual bool CreateHostImpl(const LayerTreeSettings& settings, |
| 159 scoped_ptr<OutputSurface> output_surface) { | 159 scoped_ptr<OutputSurface> output_surface) { |
| 160 host_impl_ = LayerTreeHostImpl::Create(settings, | 160 host_impl_ = LayerTreeHostImpl::Create(settings, |
| 161 this, | 161 this, |
| 162 &proxy_, | 162 &proxy_, |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 383 |
| 384 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; | 384 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; |
| 385 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 385 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
| 386 scoped_ptr<LayerTreeHostImpl> host_impl_; | 386 scoped_ptr<LayerTreeHostImpl> host_impl_; |
| 387 FakeRenderingStatsInstrumentation stats_instrumentation_; | 387 FakeRenderingStatsInstrumentation stats_instrumentation_; |
| 388 bool on_can_draw_state_changed_called_; | 388 bool on_can_draw_state_changed_called_; |
| 389 bool did_notify_ready_to_activate_; | 389 bool did_notify_ready_to_activate_; |
| 390 bool did_request_commit_; | 390 bool did_request_commit_; |
| 391 bool did_request_redraw_; | 391 bool did_request_redraw_; |
| 392 bool did_request_animate_; | 392 bool did_request_animate_; |
| 393 bool did_request_manage_tiles_; | 393 bool did_request_prepare_tiles_; |
| 394 bool reduce_memory_result_; | 394 bool reduce_memory_result_; |
| 395 base::Closure scrollbar_fade_start_; | 395 base::Closure scrollbar_fade_start_; |
| 396 base::TimeDelta requested_scrollbar_animation_delay_; | 396 base::TimeDelta requested_scrollbar_animation_delay_; |
| 397 size_t current_limit_bytes_; | 397 size_t current_limit_bytes_; |
| 398 int current_priority_cutoff_value_; | 398 int current_priority_cutoff_value_; |
| 399 }; | 399 }; |
| 400 | 400 |
| 401 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { | 401 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { |
| 402 bool always_draw = false; | 402 bool always_draw = false; |
| 403 CheckNotifyCalledIfCanDrawChanged(always_draw); | 403 CheckNotifyCalledIfCanDrawChanged(always_draw); |
| (...skipping 6091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6495 host_impl_->SetUseGpuRasterization(false); | 6495 host_impl_->SetUseGpuRasterization(false); |
| 6496 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); | 6496 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
| 6497 | 6497 |
| 6498 host_impl_->ResetRequiresHighResToDraw(); | 6498 host_impl_->ResetRequiresHighResToDraw(); |
| 6499 | 6499 |
| 6500 EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); | 6500 EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
| 6501 host_impl_->SetUseGpuRasterization(true); | 6501 host_impl_->SetUseGpuRasterization(true); |
| 6502 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); | 6502 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
| 6503 } | 6503 } |
| 6504 | 6504 |
| 6505 class LayerTreeHostImplTestManageTiles : public LayerTreeHostImplTest { | 6505 class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest { |
| 6506 public: | 6506 public: |
| 6507 void SetUp() override { | 6507 void SetUp() override { |
| 6508 LayerTreeSettings settings; | 6508 LayerTreeSettings settings; |
| 6509 settings.impl_side_painting = true; | 6509 settings.impl_side_painting = true; |
| 6510 | 6510 |
| 6511 fake_host_impl_ = new FakeLayerTreeHostImpl( | 6511 fake_host_impl_ = new FakeLayerTreeHostImpl( |
| 6512 settings, &proxy_, shared_bitmap_manager_.get()); | 6512 settings, &proxy_, shared_bitmap_manager_.get()); |
| 6513 host_impl_.reset(fake_host_impl_); | 6513 host_impl_.reset(fake_host_impl_); |
| 6514 host_impl_->InitializeRenderer(CreateOutputSurface()); | 6514 host_impl_->InitializeRenderer(CreateOutputSurface()); |
| 6515 host_impl_->SetViewportSize(gfx::Size(10, 10)); | 6515 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
| 6516 } | 6516 } |
| 6517 | 6517 |
| 6518 FakeLayerTreeHostImpl* fake_host_impl_; | 6518 FakeLayerTreeHostImpl* fake_host_impl_; |
| 6519 }; | 6519 }; |
| 6520 | 6520 |
| 6521 TEST_F(LayerTreeHostImplTestManageTiles, ManageTilesWhenInvisible) { | 6521 TEST_F(LayerTreeHostImplTestPrepareTiles, PrepareTilesWhenInvisible) { |
| 6522 fake_host_impl_->DidModifyTilePriorities(); | 6522 fake_host_impl_->DidModifyTilePriorities(); |
| 6523 EXPECT_TRUE(fake_host_impl_->manage_tiles_needed()); | 6523 EXPECT_TRUE(fake_host_impl_->prepare_tiles_needed()); |
| 6524 fake_host_impl_->SetVisible(false); | 6524 fake_host_impl_->SetVisible(false); |
| 6525 EXPECT_FALSE(fake_host_impl_->manage_tiles_needed()); | 6525 EXPECT_FALSE(fake_host_impl_->prepare_tiles_needed()); |
| 6526 } | 6526 } |
| 6527 | 6527 |
| 6528 TEST_F(LayerTreeHostImplTest, UIResourceManagement) { | 6528 TEST_F(LayerTreeHostImplTest, UIResourceManagement) { |
| 6529 scoped_ptr<TestWebGraphicsContext3D> context = | 6529 scoped_ptr<TestWebGraphicsContext3D> context = |
| 6530 TestWebGraphicsContext3D::Create(); | 6530 TestWebGraphicsContext3D::Create(); |
| 6531 TestWebGraphicsContext3D* context3d = context.get(); | 6531 TestWebGraphicsContext3D* context3d = context.get(); |
| 6532 scoped_ptr<FakeOutputSurface> output_surface = FakeOutputSurface::Create3d(); | 6532 scoped_ptr<FakeOutputSurface> output_surface = FakeOutputSurface::Create3d(); |
| 6533 CreateHostImpl(DefaultSettings(), output_surface.Pass()); | 6533 CreateHostImpl(DefaultSettings(), output_surface.Pass()); |
| 6534 | 6534 |
| 6535 EXPECT_EQ(0u, context3d->NumTextures()); | 6535 EXPECT_EQ(0u, context3d->NumTextures()); |
| (...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7928 // surface. | 7928 // surface. |
| 7929 EXPECT_EQ(0, num_lost_surfaces_); | 7929 EXPECT_EQ(0, num_lost_surfaces_); |
| 7930 host_impl_->DidLoseOutputSurface(); | 7930 host_impl_->DidLoseOutputSurface(); |
| 7931 EXPECT_EQ(1, num_lost_surfaces_); | 7931 EXPECT_EQ(1, num_lost_surfaces_); |
| 7932 host_impl_->DidLoseOutputSurface(); | 7932 host_impl_->DidLoseOutputSurface(); |
| 7933 EXPECT_LE(1, num_lost_surfaces_); | 7933 EXPECT_LE(1, num_lost_surfaces_); |
| 7934 } | 7934 } |
| 7935 | 7935 |
| 7936 } // namespace | 7936 } // namespace |
| 7937 } // namespace cc | 7937 } // namespace cc |
| OLD | NEW |