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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_manage_tiles_(false), |
90 did_upload_visible_tile_(false), | |
91 reduce_memory_result_(true), | 90 reduce_memory_result_(true), |
92 current_limit_bytes_(0), | 91 current_limit_bytes_(0), |
93 current_priority_cutoff_value_(0) { | 92 current_priority_cutoff_value_(0) { |
94 } | 93 } |
95 | 94 |
96 LayerTreeSettings DefaultSettings() { | 95 LayerTreeSettings DefaultSettings() { |
97 LayerTreeSettings settings; | 96 LayerTreeSettings settings; |
98 settings.minimum_occlusion_tracking_size = gfx::Size(); | 97 settings.minimum_occlusion_tracking_size = gfx::Size(); |
99 settings.impl_side_painting = true; | 98 settings.impl_side_painting = true; |
100 settings.texture_id_allocation_chunk_size = 1; | 99 settings.texture_id_allocation_chunk_size = 1; |
101 settings.report_overscroll_only_for_scrollable_axes = true; | 100 settings.report_overscroll_only_for_scrollable_axes = true; |
102 settings.use_pinch_virtual_viewport = true; | 101 settings.use_pinch_virtual_viewport = true; |
103 return settings; | 102 return settings; |
104 } | 103 } |
105 | 104 |
106 virtual void SetUp() override { | 105 void SetUp() override { |
107 CreateHostImpl(DefaultSettings(), CreateOutputSurface()); | 106 CreateHostImpl(DefaultSettings(), CreateOutputSurface()); |
108 } | 107 } |
109 | 108 |
110 virtual void TearDown() override {} | 109 void TearDown() override {} |
111 | 110 |
112 void UpdateRendererCapabilitiesOnImplThread() override {} | 111 void UpdateRendererCapabilitiesOnImplThread() override {} |
113 void DidLoseOutputSurfaceOnImplThread() override {} | 112 void DidLoseOutputSurfaceOnImplThread() override {} |
114 void CommitVSyncParameters(base::TimeTicks timebase, | 113 void CommitVSyncParameters(base::TimeTicks timebase, |
115 base::TimeDelta interval) override {} | 114 base::TimeDelta interval) override {} |
116 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override {} | 115 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override {} |
117 void SetMaxSwapsPendingOnImplThread(int max) override {} | 116 void SetMaxSwapsPendingOnImplThread(int max) override {} |
118 void DidSwapBuffersOnImplThread() override {} | 117 void DidSwapBuffersOnImplThread() override {} |
119 void DidSwapBuffersCompleteOnImplThread() override {} | 118 void DidSwapBuffersCompleteOnImplThread() override {} |
120 void OnCanDrawStateChanged(bool can_draw) override { | 119 void OnCanDrawStateChanged(bool can_draw) override { |
121 on_can_draw_state_changed_called_ = true; | 120 on_can_draw_state_changed_called_ = true; |
122 } | 121 } |
123 void NotifyReadyToActivate() override { | 122 void NotifyReadyToActivate() override { |
124 did_notify_ready_to_activate_ = true; | 123 did_notify_ready_to_activate_ = true; |
125 host_impl_->ActivateSyncTree(); | 124 host_impl_->ActivateSyncTree(); |
126 } | 125 } |
127 void NotifyReadyToDraw() override {} | 126 void NotifyReadyToDraw() override {} |
128 void SetNeedsRedrawOnImplThread() override { did_request_redraw_ = true; } | 127 void SetNeedsRedrawOnImplThread() override { did_request_redraw_ = true; } |
129 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) override { | 128 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) override { |
130 did_request_redraw_ = true; | 129 did_request_redraw_ = true; |
131 } | 130 } |
132 void SetNeedsAnimateOnImplThread() override { did_request_animate_ = true; } | 131 void SetNeedsAnimateOnImplThread() override { did_request_animate_ = true; } |
133 void SetNeedsManageTilesOnImplThread() override { | 132 void SetNeedsManageTilesOnImplThread() override { |
134 did_request_manage_tiles_ = true; | 133 did_request_manage_tiles_ = true; |
135 } | 134 } |
136 void DidInitializeVisibleTileOnImplThread() override { | |
137 did_upload_visible_tile_ = true; | |
138 } | |
139 void SetNeedsCommitOnImplThread() override { did_request_commit_ = true; } | 135 void SetNeedsCommitOnImplThread() override { did_request_commit_ = true; } |
140 void PostAnimationEventsToMainThreadOnImplThread( | 136 void PostAnimationEventsToMainThreadOnImplThread( |
141 scoped_ptr<AnimationEventsVector> events) override {} | 137 scoped_ptr<AnimationEventsVector> events) override {} |
142 bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, | 138 bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, |
143 int priority_cutoff) override { | 139 int priority_cutoff) override { |
144 current_limit_bytes_ = limit_bytes; | 140 current_limit_bytes_ = limit_bytes; |
145 current_priority_cutoff_value_ = priority_cutoff; | 141 current_priority_cutoff_value_ = priority_cutoff; |
146 return reduce_memory_result_; | 142 return reduce_memory_result_; |
147 } | 143 } |
148 bool IsInsideDraw() override { return false; } | 144 bool IsInsideDraw() override { return false; } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; | 383 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; |
388 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 384 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
389 scoped_ptr<LayerTreeHostImpl> host_impl_; | 385 scoped_ptr<LayerTreeHostImpl> host_impl_; |
390 FakeRenderingStatsInstrumentation stats_instrumentation_; | 386 FakeRenderingStatsInstrumentation stats_instrumentation_; |
391 bool on_can_draw_state_changed_called_; | 387 bool on_can_draw_state_changed_called_; |
392 bool did_notify_ready_to_activate_; | 388 bool did_notify_ready_to_activate_; |
393 bool did_request_commit_; | 389 bool did_request_commit_; |
394 bool did_request_redraw_; | 390 bool did_request_redraw_; |
395 bool did_request_animate_; | 391 bool did_request_animate_; |
396 bool did_request_manage_tiles_; | 392 bool did_request_manage_tiles_; |
397 bool did_upload_visible_tile_; | |
398 bool reduce_memory_result_; | 393 bool reduce_memory_result_; |
399 base::Closure scrollbar_fade_start_; | 394 base::Closure scrollbar_fade_start_; |
400 base::TimeDelta requested_scrollbar_animation_delay_; | 395 base::TimeDelta requested_scrollbar_animation_delay_; |
401 size_t current_limit_bytes_; | 396 size_t current_limit_bytes_; |
402 int current_priority_cutoff_value_; | 397 int current_priority_cutoff_value_; |
403 }; | 398 }; |
404 | 399 |
405 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { | 400 TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { |
406 bool always_draw = false; | 401 bool always_draw = false; |
407 CheckNotifyCalledIfCanDrawChanged(always_draw); | 402 CheckNotifyCalledIfCanDrawChanged(always_draw); |
(...skipping 5809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6217 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); | 6212 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
6218 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 6213 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
6219 host_impl_->DidDrawAllLayers(frame); | 6214 host_impl_->DidDrawAllLayers(frame); |
6220 | 6215 |
6221 EXPECT_EQ(1u, frame.will_draw_layers.size()); | 6216 EXPECT_EQ(1u, frame.will_draw_layers.size()); |
6222 EXPECT_EQ(host_impl_->active_tree()->root_layer(), frame.will_draw_layers[0]); | 6217 EXPECT_EQ(host_impl_->active_tree()->root_layer(), frame.will_draw_layers[0]); |
6223 } | 6218 } |
6224 | 6219 |
6225 class LayerTreeHostImplTestDeferredInitialize : public LayerTreeHostImplTest { | 6220 class LayerTreeHostImplTestDeferredInitialize : public LayerTreeHostImplTest { |
6226 protected: | 6221 protected: |
6227 virtual void SetUp() override { | 6222 void SetUp() override { |
6228 LayerTreeHostImplTest::SetUp(); | 6223 LayerTreeHostImplTest::SetUp(); |
6229 | 6224 |
6230 set_reduce_memory_result(false); | 6225 set_reduce_memory_result(false); |
6231 | 6226 |
6232 bool delegated_rendering = false; | 6227 bool delegated_rendering = false; |
6233 scoped_ptr<FakeOutputSurface> output_surface( | 6228 scoped_ptr<FakeOutputSurface> output_surface( |
6234 FakeOutputSurface::CreateDeferredGL( | 6229 FakeOutputSurface::CreateDeferredGL( |
6235 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()), | 6230 scoped_ptr<SoftwareOutputDevice>(new CountingSoftwareDevice()), |
6236 delegated_rendering)); | 6231 delegated_rendering)); |
6237 output_surface_ = output_surface.get(); | 6232 output_surface_ = output_surface.get(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6406 | 6401 |
6407 host_impl_->ResetRequiresHighResToDraw(); | 6402 host_impl_->ResetRequiresHighResToDraw(); |
6408 | 6403 |
6409 EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); | 6404 EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
6410 host_impl_->SetUseGpuRasterization(true); | 6405 host_impl_->SetUseGpuRasterization(true); |
6411 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); | 6406 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
6412 } | 6407 } |
6413 | 6408 |
6414 class LayerTreeHostImplTestManageTiles : public LayerTreeHostImplTest { | 6409 class LayerTreeHostImplTestManageTiles : public LayerTreeHostImplTest { |
6415 public: | 6410 public: |
6416 virtual void SetUp() override { | 6411 void SetUp() override { |
6417 LayerTreeSettings settings; | 6412 LayerTreeSettings settings; |
6418 settings.impl_side_painting = true; | 6413 settings.impl_side_painting = true; |
6419 | 6414 |
6420 fake_host_impl_ = new FakeLayerTreeHostImpl( | 6415 fake_host_impl_ = new FakeLayerTreeHostImpl( |
6421 settings, &proxy_, shared_bitmap_manager_.get()); | 6416 settings, &proxy_, shared_bitmap_manager_.get()); |
6422 host_impl_.reset(fake_host_impl_); | 6417 host_impl_.reset(fake_host_impl_); |
6423 host_impl_->InitializeRenderer(CreateOutputSurface()); | 6418 host_impl_->InitializeRenderer(CreateOutputSurface()); |
6424 host_impl_->SetViewportSize(gfx::Size(10, 10)); | 6419 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
6425 } | 6420 } |
6426 | 6421 |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7064 host_impl_->ScrollEnd(); | 7059 host_impl_->ScrollEnd(); |
7065 | 7060 |
7066 EXPECT_EQ(0, set_needs_commit_count); | 7061 EXPECT_EQ(0, set_needs_commit_count); |
7067 EXPECT_EQ(2, set_needs_redraw_count); | 7062 EXPECT_EQ(2, set_needs_redraw_count); |
7068 EXPECT_EQ(1, forward_to_main_count); | 7063 EXPECT_EQ(1, forward_to_main_count); |
7069 } | 7064 } |
7070 } | 7065 } |
7071 | 7066 |
7072 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { | 7067 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { |
7073 public: | 7068 public: |
7074 virtual void SetUp() override { | 7069 void SetUp() override { |
7075 LayerTreeSettings settings = DefaultSettings(); | 7070 LayerTreeSettings settings = DefaultSettings(); |
7076 settings.calculate_top_controls_position = true; | 7071 settings.calculate_top_controls_position = true; |
7077 settings.top_controls_height = top_controls_height_; | 7072 settings.top_controls_height = top_controls_height_; |
7078 CreateHostImpl(settings, CreateOutputSurface()); | 7073 CreateHostImpl(settings, CreateOutputSurface()); |
7079 } | 7074 } |
7080 | 7075 |
7081 protected: | 7076 protected: |
7082 static const int top_controls_height_; | 7077 static const int top_controls_height_; |
7083 }; | 7078 }; |
7084 | 7079 |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7452 | 7447 |
7453 host_impl_->ScrollEnd(); | 7448 host_impl_->ScrollEnd(); |
7454 | 7449 |
7455 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->TotalScrollOffset()); | 7450 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->TotalScrollOffset()); |
7456 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->TotalScrollOffset()); | 7451 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->TotalScrollOffset()); |
7457 } | 7452 } |
7458 } | 7453 } |
7459 | 7454 |
7460 class LayerTreeHostImplWithImplicitLimitsTest : public LayerTreeHostImplTest { | 7455 class LayerTreeHostImplWithImplicitLimitsTest : public LayerTreeHostImplTest { |
7461 public: | 7456 public: |
7462 virtual void SetUp() override { | 7457 void SetUp() override { |
7463 LayerTreeSettings settings = DefaultSettings(); | 7458 LayerTreeSettings settings = DefaultSettings(); |
7464 settings.max_memory_for_prepaint_percentage = 50; | 7459 settings.max_memory_for_prepaint_percentage = 50; |
7465 CreateHostImpl(settings, CreateOutputSurface()); | 7460 CreateHostImpl(settings, CreateOutputSurface()); |
7466 } | 7461 } |
7467 }; | 7462 }; |
7468 | 7463 |
7469 TEST_F(LayerTreeHostImplWithImplicitLimitsTest, ImplicitMemoryLimits) { | 7464 TEST_F(LayerTreeHostImplWithImplicitLimitsTest, ImplicitMemoryLimits) { |
7470 // Set up a memory policy and percentages which could cause | 7465 // Set up a memory policy and percentages which could cause |
7471 // 32-bit integer overflows. | 7466 // 32-bit integer overflows. |
7472 ManagedMemoryPolicy mem_policy(300 * 1024 * 1024); // 300MB | 7467 ManagedMemoryPolicy mem_policy(300 * 1024 * 1024); // 300MB |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7679 // surface. | 7674 // surface. |
7680 EXPECT_EQ(0, num_lost_surfaces_); | 7675 EXPECT_EQ(0, num_lost_surfaces_); |
7681 host_impl_->DidLoseOutputSurface(); | 7676 host_impl_->DidLoseOutputSurface(); |
7682 EXPECT_EQ(1, num_lost_surfaces_); | 7677 EXPECT_EQ(1, num_lost_surfaces_); |
7683 host_impl_->DidLoseOutputSurface(); | 7678 host_impl_->DidLoseOutputSurface(); |
7684 EXPECT_LE(1, num_lost_surfaces_); | 7679 EXPECT_LE(1, num_lost_surfaces_); |
7685 } | 7680 } |
7686 | 7681 |
7687 } // namespace | 7682 } // namespace |
7688 } // namespace cc | 7683 } // namespace cc |
OLD | NEW |