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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 always_impl_thread_(&proxy_), | 81 always_impl_thread_(&proxy_), |
82 always_main_thread_blocked_(&proxy_), | 82 always_main_thread_blocked_(&proxy_), |
83 shared_bitmap_manager_(new TestSharedBitmapManager), | 83 shared_bitmap_manager_(new TestSharedBitmapManager), |
84 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager), | 84 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager), |
85 on_can_draw_state_changed_called_(false), | 85 on_can_draw_state_changed_called_(false), |
86 did_notify_ready_to_activate_(false), | 86 did_notify_ready_to_activate_(false), |
87 did_request_commit_(false), | 87 did_request_commit_(false), |
88 did_request_redraw_(false), | 88 did_request_redraw_(false), |
89 did_request_animate_(false), | 89 did_request_animate_(false), |
90 did_request_prepare_tiles_(false), | 90 did_request_prepare_tiles_(false), |
| 91 did_complete_page_scale_animation_(false), |
91 reduce_memory_result_(true), | 92 reduce_memory_result_(true), |
92 current_limit_bytes_(0), | 93 current_limit_bytes_(0), |
93 current_priority_cutoff_value_(0) { | 94 current_priority_cutoff_value_(0) { |
94 } | 95 } |
95 | 96 |
96 LayerTreeSettings DefaultSettings() { | 97 LayerTreeSettings DefaultSettings() { |
97 LayerTreeSettings settings; | 98 LayerTreeSettings settings; |
98 settings.minimum_occlusion_tracking_size = gfx::Size(); | 99 settings.minimum_occlusion_tracking_size = gfx::Size(); |
99 settings.impl_side_painting = true; | 100 settings.impl_side_painting = true; |
100 settings.renderer_settings.texture_id_allocation_chunk_size = 1; | 101 settings.renderer_settings.texture_id_allocation_chunk_size = 1; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 145 } |
145 bool IsInsideDraw() override { return false; } | 146 bool IsInsideDraw() override { return false; } |
146 void RenewTreePriority() override {} | 147 void RenewTreePriority() override {} |
147 void PostDelayedScrollbarFadeOnImplThread(const base::Closure& start_fade, | 148 void PostDelayedScrollbarFadeOnImplThread(const base::Closure& start_fade, |
148 base::TimeDelta delay) override { | 149 base::TimeDelta delay) override { |
149 scrollbar_fade_start_ = start_fade; | 150 scrollbar_fade_start_ = start_fade; |
150 requested_scrollbar_animation_delay_ = delay; | 151 requested_scrollbar_animation_delay_ = delay; |
151 } | 152 } |
152 void DidActivateSyncTree() override {} | 153 void DidActivateSyncTree() override {} |
153 void DidPrepareTiles() override {} | 154 void DidPrepareTiles() override {} |
| 155 void DidCompletePageScaleAnimationOnImplThread() override { |
| 156 did_complete_page_scale_animation_ = true; |
| 157 } |
154 | 158 |
155 void set_reduce_memory_result(bool reduce_memory_result) { | 159 void set_reduce_memory_result(bool reduce_memory_result) { |
156 reduce_memory_result_ = reduce_memory_result; | 160 reduce_memory_result_ = reduce_memory_result; |
157 } | 161 } |
158 | 162 |
159 virtual bool CreateHostImpl(const LayerTreeSettings& settings, | 163 virtual bool CreateHostImpl(const LayerTreeSettings& settings, |
160 scoped_ptr<OutputSurface> output_surface) { | 164 scoped_ptr<OutputSurface> output_surface) { |
161 host_impl_ = LayerTreeHostImpl::Create(settings, | 165 host_impl_ = LayerTreeHostImpl::Create(settings, |
162 this, | 166 this, |
163 &proxy_, | 167 &proxy_, |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; | 391 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; |
388 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 392 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
389 scoped_ptr<LayerTreeHostImpl> host_impl_; | 393 scoped_ptr<LayerTreeHostImpl> host_impl_; |
390 FakeRenderingStatsInstrumentation stats_instrumentation_; | 394 FakeRenderingStatsInstrumentation stats_instrumentation_; |
391 bool on_can_draw_state_changed_called_; | 395 bool on_can_draw_state_changed_called_; |
392 bool did_notify_ready_to_activate_; | 396 bool did_notify_ready_to_activate_; |
393 bool did_request_commit_; | 397 bool did_request_commit_; |
394 bool did_request_redraw_; | 398 bool did_request_redraw_; |
395 bool did_request_animate_; | 399 bool did_request_animate_; |
396 bool did_request_prepare_tiles_; | 400 bool did_request_prepare_tiles_; |
| 401 bool did_complete_page_scale_animation_; |
397 bool reduce_memory_result_; | 402 bool reduce_memory_result_; |
398 base::Closure scrollbar_fade_start_; | 403 base::Closure scrollbar_fade_start_; |
399 base::TimeDelta requested_scrollbar_animation_delay_; | 404 base::TimeDelta requested_scrollbar_animation_delay_; |
400 size_t current_limit_bytes_; | 405 size_t current_limit_bytes_; |
401 int current_priority_cutoff_value_; | 406 int current_priority_cutoff_value_; |
402 }; | 407 }; |
403 | 408 |
404 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { | 409 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { |
405 bool always_draw = false; | 410 bool always_draw = false; |
406 CheckNotifyCalledIfCanDrawChanged(always_draw); | 411 CheckNotifyCalledIfCanDrawChanged(always_draw); |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 host_impl_->Animate(end_time); | 1339 host_impl_->Animate(end_time); |
1335 EXPECT_TRUE(did_request_commit_); | 1340 EXPECT_TRUE(did_request_commit_); |
1336 EXPECT_FALSE(did_request_animate_); | 1341 EXPECT_FALSE(did_request_animate_); |
1337 | 1342 |
1338 scoped_ptr<ScrollAndScaleSet> scroll_info = | 1343 scoped_ptr<ScrollAndScaleSet> scroll_info = |
1339 host_impl_->ProcessScrollDeltas(); | 1344 host_impl_->ProcessScrollDeltas(); |
1340 EXPECT_EQ(scroll_info->page_scale_delta, target_scale); | 1345 EXPECT_EQ(scroll_info->page_scale_delta, target_scale); |
1341 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); | 1346 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); |
1342 } | 1347 } |
1343 | 1348 |
| 1349 TEST_F(LayerTreeHostImplTest, PageScaleAnimationCompletedNotification) { |
| 1350 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 1351 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1352 DrawFrame(); |
| 1353 |
| 1354 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 1355 DCHECK(scroll_layer); |
| 1356 |
| 1357 base::TimeTicks start_time = |
| 1358 base::TimeTicks() + base::TimeDelta::FromSeconds(1); |
| 1359 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 1360 base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 1361 base::TimeTicks end_time = start_time + duration; |
| 1362 |
| 1363 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
| 1364 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); |
| 1365 |
| 1366 did_complete_page_scale_animation_ = false; |
| 1367 host_impl_->active_tree()->SetPendingPageScaleAnimation( |
| 1368 scoped_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation( |
| 1369 gfx::Vector2d(), false, 2.f, duration))); |
| 1370 host_impl_->ActivateSyncTree(); |
| 1371 host_impl_->Animate(start_time); |
| 1372 EXPECT_FALSE(did_complete_page_scale_animation_); |
| 1373 |
| 1374 host_impl_->Animate(halfway_through_animation); |
| 1375 EXPECT_FALSE(did_complete_page_scale_animation_); |
| 1376 |
| 1377 host_impl_->Animate(end_time); |
| 1378 EXPECT_TRUE(did_complete_page_scale_animation_); |
| 1379 } |
| 1380 |
1344 class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { | 1381 class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { |
1345 public: | 1382 public: |
1346 LayerTreeHostImplOverridePhysicalTime( | 1383 LayerTreeHostImplOverridePhysicalTime( |
1347 const LayerTreeSettings& settings, | 1384 const LayerTreeSettings& settings, |
1348 LayerTreeHostImplClient* client, | 1385 LayerTreeHostImplClient* client, |
1349 Proxy* proxy, | 1386 Proxy* proxy, |
1350 SharedBitmapManager* manager, | 1387 SharedBitmapManager* manager, |
1351 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 1388 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
1352 : LayerTreeHostImpl(settings, | 1389 : LayerTreeHostImpl(settings, |
1353 client, | 1390 client, |
(...skipping 3356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4710 | 4747 |
4711 host_impl_->SetDeviceScaleFactor(2.f); | 4748 host_impl_->SetDeviceScaleFactor(2.f); |
4712 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); | 4749 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
4713 SetupActiveTreeLayers(); | 4750 SetupActiveTreeLayers(); |
4714 TestLayerCoversFullViewport(); | 4751 TestLayerCoversFullViewport(); |
4715 TestEmptyLayer(); | 4752 TestEmptyLayer(); |
4716 TestLayerInMiddleOfViewport(); | 4753 TestLayerInMiddleOfViewport(); |
4717 TestLayerIsLargerThanViewport(); | 4754 TestLayerIsLargerThanViewport(); |
4718 } | 4755 } |
4719 | 4756 |
4720 TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCoveredOverhangBitmap) { | |
4721 viewport_size_ = gfx::Size(1000, 1000); | |
4722 | |
4723 bool always_draw = false; | |
4724 CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(always_draw)); | |
4725 | |
4726 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); | |
4727 SetupActiveTreeLayers(); | |
4728 | |
4729 // Specify an overhang bitmap to use. | |
4730 bool is_opaque = false; | |
4731 UIResourceBitmap ui_resource_bitmap(gfx::Size(2, 2), is_opaque); | |
4732 ui_resource_bitmap.SetWrapMode(UIResourceBitmap::REPEAT); | |
4733 UIResourceId ui_resource_id = 12345; | |
4734 host_impl_->CreateUIResource(ui_resource_id, ui_resource_bitmap); | |
4735 host_impl_->SetOverhangUIResource(ui_resource_id, gfx::Size(32, 32)); | |
4736 set_gutter_quad_material(DrawQuad::TEXTURE_CONTENT); | |
4737 set_gutter_texture_size(gfx::Size(32, 32)); | |
4738 | |
4739 TestLayerCoversFullViewport(); | |
4740 TestEmptyLayer(); | |
4741 TestLayerInMiddleOfViewport(); | |
4742 TestLayerIsLargerThanViewport(); | |
4743 | |
4744 // Change the resource size. | |
4745 host_impl_->SetOverhangUIResource(ui_resource_id, gfx::Size(128, 16)); | |
4746 set_gutter_texture_size(gfx::Size(128, 16)); | |
4747 | |
4748 TestLayerCoversFullViewport(); | |
4749 TestEmptyLayer(); | |
4750 TestLayerInMiddleOfViewport(); | |
4751 TestLayerIsLargerThanViewport(); | |
4752 | |
4753 // Change the device scale factor | |
4754 host_impl_->SetDeviceScaleFactor(2.f); | |
4755 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); | |
4756 | |
4757 TestLayerCoversFullViewport(); | |
4758 TestEmptyLayer(); | |
4759 TestLayerInMiddleOfViewport(); | |
4760 TestLayerIsLargerThanViewport(); | |
4761 } | |
4762 | |
4763 TEST_F(LayerTreeHostImplViewportCoveredTest, ActiveTreeGrowViewportInvalid) { | 4757 TEST_F(LayerTreeHostImplViewportCoveredTest, ActiveTreeGrowViewportInvalid) { |
4764 viewport_size_ = gfx::Size(1000, 1000); | 4758 viewport_size_ = gfx::Size(1000, 1000); |
4765 | 4759 |
4766 bool always_draw = true; | 4760 bool always_draw = true; |
4767 CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(always_draw)); | 4761 CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(always_draw)); |
4768 | 4762 |
4769 // Pending tree to force active_tree size invalid. Not used otherwise. | 4763 // Pending tree to force active_tree size invalid. Not used otherwise. |
4770 host_impl_->CreatePendingTree(); | 4764 host_impl_->CreatePendingTree(); |
4771 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); | 4765 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
4772 EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); | 4766 EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); |
(...skipping 3253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8026 // surface. | 8020 // surface. |
8027 EXPECT_EQ(0, num_lost_surfaces_); | 8021 EXPECT_EQ(0, num_lost_surfaces_); |
8028 host_impl_->DidLoseOutputSurface(); | 8022 host_impl_->DidLoseOutputSurface(); |
8029 EXPECT_EQ(1, num_lost_surfaces_); | 8023 EXPECT_EQ(1, num_lost_surfaces_); |
8030 host_impl_->DidLoseOutputSurface(); | 8024 host_impl_->DidLoseOutputSurface(); |
8031 EXPECT_LE(1, num_lost_surfaces_); | 8025 EXPECT_LE(1, num_lost_surfaces_); |
8032 } | 8026 } |
8033 | 8027 |
8034 } // namespace | 8028 } // namespace |
8035 } // namespace cc | 8029 } // namespace cc |
OLD | NEW |