| 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 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 paint_time_counter_(PaintTimeCounter::Create()), | 188 paint_time_counter_(PaintTimeCounter::Create()), |
| 189 memory_history_(MemoryHistory::Create()), | 189 memory_history_(MemoryHistory::Create()), |
| 190 debug_rect_history_(DebugRectHistory::Create()), | 190 debug_rect_history_(DebugRectHistory::Create()), |
| 191 max_memory_needed_bytes_(0), | 191 max_memory_needed_bytes_(0), |
| 192 last_sent_memory_visible_bytes_(0), | 192 last_sent_memory_visible_bytes_(0), |
| 193 last_sent_memory_visible_and_nearby_bytes_(0), | 193 last_sent_memory_visible_and_nearby_bytes_(0), |
| 194 last_sent_memory_use_bytes_(0), | 194 last_sent_memory_use_bytes_(0), |
| 195 zero_budget_(false), | 195 zero_budget_(false), |
| 196 device_scale_factor_(1.f), | 196 device_scale_factor_(1.f), |
| 197 overdraw_bottom_height_(0.f), | 197 overdraw_bottom_height_(0.f), |
| 198 device_viewport_valid_for_tile_management_(true), |
| 198 external_stencil_test_enabled_(false), | 199 external_stencil_test_enabled_(false), |
| 199 animation_registrar_(AnimationRegistrar::Create()), | 200 animation_registrar_(AnimationRegistrar::Create()), |
| 200 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 201 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
| 201 need_to_update_visible_tiles_before_draw_(false) { | 202 need_to_update_visible_tiles_before_draw_(false) { |
| 202 DCHECK(proxy_->IsImplThread()); | 203 DCHECK(proxy_->IsImplThread()); |
| 203 DidVisibilityChange(this, visible_); | 204 DidVisibilityChange(this, visible_); |
| 204 | 205 |
| 205 SetDebugState(settings.initial_debug_state); | 206 SetDebugState(settings.initial_debug_state); |
| 206 | 207 |
| 207 if (settings.calculate_top_controls_position) { | 208 if (settings.calculate_top_controls_position) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // draw_and_swap_full_viewport_every_frame check. Tracked in crbug.com/264967. | 285 // draw_and_swap_full_viewport_every_frame check. Tracked in crbug.com/264967. |
| 285 if (!active_tree_->root_layer()) { | 286 if (!active_tree_->root_layer()) { |
| 286 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw no root layer", | 287 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw no root layer", |
| 287 TRACE_EVENT_SCOPE_THREAD); | 288 TRACE_EVENT_SCOPE_THREAD); |
| 288 return false; | 289 return false; |
| 289 } | 290 } |
| 290 | 291 |
| 291 if (output_surface_->capabilities().draw_and_swap_full_viewport_every_frame) | 292 if (output_surface_->capabilities().draw_and_swap_full_viewport_every_frame) |
| 292 return true; | 293 return true; |
| 293 | 294 |
| 294 if (device_viewport_size_.IsEmpty()) { | 295 if (DeviceViewport().IsEmpty()) { |
| 295 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw empty viewport", | 296 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw empty viewport", |
| 296 TRACE_EVENT_SCOPE_THREAD); | 297 TRACE_EVENT_SCOPE_THREAD); |
| 297 return false; | 298 return false; |
| 298 } | 299 } |
| 299 if (active_tree_->ViewportSizeInvalid()) { | 300 if (active_tree_->ViewportSizeInvalid()) { |
| 300 TRACE_EVENT_INSTANT0( | 301 TRACE_EVENT_INSTANT0( |
| 301 "cc", "LayerTreeHostImpl::CanDraw viewport size recently changed", | 302 "cc", "LayerTreeHostImpl::CanDraw viewport size recently changed", |
| 302 TRACE_EVENT_SCOPE_THREAD); | 303 TRACE_EVENT_SCOPE_THREAD); |
| 303 return false; | 304 return false; |
| 304 } | 305 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 319 AnimateLayers(monotonic_time, wall_clock_time); | 320 AnimateLayers(monotonic_time, wall_clock_time); |
| 320 AnimateScrollbars(monotonic_time); | 321 AnimateScrollbars(monotonic_time); |
| 321 AnimateTopControls(monotonic_time); | 322 AnimateTopControls(monotonic_time); |
| 322 } | 323 } |
| 323 | 324 |
| 324 void LayerTreeHostImpl::ManageTiles() { | 325 void LayerTreeHostImpl::ManageTiles() { |
| 325 if (!tile_manager_) | 326 if (!tile_manager_) |
| 326 return; | 327 return; |
| 327 if (!manage_tiles_needed_) | 328 if (!manage_tiles_needed_) |
| 328 return; | 329 return; |
| 330 if (!device_viewport_valid_for_tile_management_) |
| 331 return; |
| 332 |
| 329 manage_tiles_needed_ = false; | 333 manage_tiles_needed_ = false; |
| 330 tile_manager_->ManageTiles(); | 334 tile_manager_->ManageTiles(); |
| 331 | 335 |
| 332 size_t memory_required_bytes; | 336 size_t memory_required_bytes; |
| 333 size_t memory_nice_to_have_bytes; | 337 size_t memory_nice_to_have_bytes; |
| 334 size_t memory_allocated_bytes; | 338 size_t memory_allocated_bytes; |
| 335 size_t memory_used_bytes; | 339 size_t memory_used_bytes; |
| 336 tile_manager_->GetMemoryStats(&memory_required_bytes, | 340 tile_manager_->GetMemoryStats(&memory_required_bytes, |
| 337 &memory_nice_to_have_bytes, | 341 &memory_nice_to_have_bytes, |
| 338 &memory_allocated_bytes, | 342 &memory_allocated_bytes, |
| 339 &memory_used_bytes); | 343 &memory_used_bytes); |
| 340 SendManagedMemoryStats(memory_required_bytes, | 344 SendManagedMemoryStats(memory_required_bytes, |
| 341 memory_nice_to_have_bytes, | 345 memory_nice_to_have_bytes, |
| 342 memory_used_bytes); | 346 memory_used_bytes); |
| 343 } | 347 } |
| 344 | 348 |
| 345 void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset, | 349 void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset, |
| 346 bool anchor_point, | 350 bool anchor_point, |
| 347 float page_scale, | 351 float page_scale, |
| 348 base::TimeTicks start_time, | 352 base::TimeTicks start_time, |
| 349 base::TimeDelta duration) { | 353 base::TimeDelta duration) { |
| 350 if (!RootScrollLayer()) | 354 if (!RootScrollLayer()) |
| 351 return; | 355 return; |
| 352 | 356 |
| 353 gfx::Vector2dF scroll_total = | 357 gfx::Vector2dF scroll_total = |
| 354 RootScrollLayer()->scroll_offset() + RootScrollLayer()->ScrollDelta(); | 358 RootScrollLayer()->scroll_offset() + RootScrollLayer()->ScrollDelta(); |
| 355 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); | 359 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); |
| 356 gfx::SizeF viewport_size = VisibleViewportSize(); | 360 gfx::SizeF viewport_size = UnscaledScrollableViewportSize(); |
| 357 | 361 |
| 358 double start_time_seconds = (start_time - base::TimeTicks()).InSecondsF(); | 362 double start_time_seconds = (start_time - base::TimeTicks()).InSecondsF(); |
| 359 | 363 |
| 360 // Easing constants experimentally determined. | 364 // Easing constants experimentally determined. |
| 361 scoped_ptr<TimingFunction> timing_function = | 365 scoped_ptr<TimingFunction> timing_function = |
| 362 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); | 366 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); |
| 363 | 367 |
| 364 page_scale_animation_ = | 368 page_scale_animation_ = |
| 365 PageScaleAnimation::Create(scroll_total, | 369 PageScaleAnimation::Create(scroll_total, |
| 366 active_tree_->total_page_scale_factor(), | 370 active_tree_->total_page_scale_factor(), |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 old_policy.priority_cutoff_when_visible) { | 1157 old_policy.priority_cutoff_when_visible) { |
| 1154 needs_commit = false; | 1158 needs_commit = false; |
| 1155 } | 1159 } |
| 1156 | 1160 |
| 1157 if (needs_commit) | 1161 if (needs_commit) |
| 1158 client_->SetNeedsCommitOnImplThread(); | 1162 client_->SetNeedsCommitOnImplThread(); |
| 1159 } | 1163 } |
| 1160 | 1164 |
| 1161 void LayerTreeHostImpl::SetExternalDrawConstraints( | 1165 void LayerTreeHostImpl::SetExternalDrawConstraints( |
| 1162 const gfx::Transform& transform, | 1166 const gfx::Transform& transform, |
| 1163 gfx::Rect viewport) { | 1167 gfx::Rect viewport, |
| 1168 gfx::Rect clip, |
| 1169 bool valid_for_tile_management) { |
| 1164 external_transform_ = transform; | 1170 external_transform_ = transform; |
| 1165 external_viewport_ = viewport; | 1171 external_viewport_ = viewport; |
| 1172 external_clip_ = clip; |
| 1173 device_viewport_valid_for_tile_management_ = valid_for_tile_management; |
| 1166 } | 1174 } |
| 1167 | 1175 |
| 1168 void LayerTreeHostImpl::SetExternalStencilTest(bool enabled) { | 1176 void LayerTreeHostImpl::SetExternalStencilTest(bool enabled) { |
| 1169 external_stencil_test_enabled_ = enabled; | 1177 external_stencil_test_enabled_ = enabled; |
| 1170 } | 1178 } |
| 1171 | 1179 |
| 1172 void LayerTreeHostImpl::SetNeedsRedrawRect(gfx::Rect damage_rect) { | 1180 void LayerTreeHostImpl::SetNeedsRedrawRect(gfx::Rect damage_rect) { |
| 1173 client_->SetNeedsRedrawRectOnImplThread(damage_rect); | 1181 client_->SetNeedsRedrawRectOnImplThread(damage_rect); |
| 1174 } | 1182 } |
| 1175 | 1183 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 | 1364 |
| 1357 void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) { | 1365 void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) { |
| 1358 if (output_surface_) | 1366 if (output_surface_) |
| 1359 output_surface_->SetNeedsBeginFrame(enable); | 1367 output_surface_->SetNeedsBeginFrame(enable); |
| 1360 } | 1368 } |
| 1361 | 1369 |
| 1362 float LayerTreeHostImpl::DeviceScaleFactor() const { | 1370 float LayerTreeHostImpl::DeviceScaleFactor() const { |
| 1363 return device_scale_factor_; | 1371 return device_scale_factor_; |
| 1364 } | 1372 } |
| 1365 | 1373 |
| 1366 gfx::SizeF LayerTreeHostImpl::VisibleViewportSize() const { | 1374 gfx::SizeF LayerTreeHostImpl::UnscaledScrollableViewportSize() const { |
| 1367 // The container layer bounds should be used if non-overlay scrollbars may | 1375 // The container layer bounds should be used if non-overlay scrollbars may |
| 1368 // exist since it adjusts for them. | 1376 // exist since it adjusts for them. |
| 1369 LayerImpl* container_layer = active_tree_->RootContainerLayer(); | 1377 LayerImpl* container_layer = active_tree_->RootContainerLayer(); |
| 1370 if (!Settings().solid_color_scrollbars && container_layer) { | 1378 if (!Settings().solid_color_scrollbars && container_layer) { |
| 1371 DCHECK(!top_controls_manager_); | 1379 DCHECK(!top_controls_manager_); |
| 1372 DCHECK_EQ(0, overdraw_bottom_height_); | 1380 DCHECK_EQ(0, overdraw_bottom_height_); |
| 1373 return container_layer->bounds(); | 1381 return container_layer->bounds(); |
| 1374 } | 1382 } |
| 1375 | 1383 |
| 1376 gfx::SizeF dip_size = | 1384 gfx::SizeF dip_size = |
| 1377 gfx::ScaleSize(device_viewport_size(), 1.f / device_scale_factor()); | 1385 gfx::ScaleSize(device_viewport_size_, 1.f / device_scale_factor()); |
| 1378 | 1386 |
| 1379 float top_offset = | 1387 float top_offset = |
| 1380 top_controls_manager_ ? top_controls_manager_->content_top_offset() : 0.f; | 1388 top_controls_manager_ ? top_controls_manager_->content_top_offset() : 0.f; |
| 1381 return gfx::SizeF(dip_size.width(), | 1389 return gfx::SizeF(dip_size.width(), |
| 1382 dip_size.height() - top_offset - overdraw_bottom_height_); | 1390 dip_size.height() - top_offset - overdraw_bottom_height_); |
| 1383 } | 1391 } |
| 1384 | 1392 |
| 1385 const LayerTreeSettings& LayerTreeHostImpl::Settings() const { | 1393 const LayerTreeSettings& LayerTreeHostImpl::Settings() const { |
| 1386 return settings(); | 1394 return settings(); |
| 1387 } | 1395 } |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1804 SetFullRootLayerDamage(); | 1812 SetFullRootLayerDamage(); |
| 1805 } | 1813 } |
| 1806 | 1814 |
| 1807 gfx::Rect LayerTreeHostImpl::DeviceViewport() const { | 1815 gfx::Rect LayerTreeHostImpl::DeviceViewport() const { |
| 1808 if (external_viewport_.IsEmpty()) | 1816 if (external_viewport_.IsEmpty()) |
| 1809 return gfx::Rect(device_viewport_size_); | 1817 return gfx::Rect(device_viewport_size_); |
| 1810 | 1818 |
| 1811 return external_viewport_; | 1819 return external_viewport_; |
| 1812 } | 1820 } |
| 1813 | 1821 |
| 1822 gfx::Rect LayerTreeHostImpl::DeviceClip() const { |
| 1823 if (external_clip_.IsEmpty()) |
| 1824 return DeviceViewport(); |
| 1825 |
| 1826 return external_clip_; |
| 1827 } |
| 1828 |
| 1814 const gfx::Transform& LayerTreeHostImpl::DeviceTransform() const { | 1829 const gfx::Transform& LayerTreeHostImpl::DeviceTransform() const { |
| 1815 return external_transform_; | 1830 return external_transform_; |
| 1816 } | 1831 } |
| 1817 | 1832 |
| 1818 void LayerTreeHostImpl::UpdateMaxScrollOffset() { | 1833 void LayerTreeHostImpl::UpdateMaxScrollOffset() { |
| 1819 active_tree_->UpdateMaxScrollOffset(); | 1834 active_tree_->UpdateMaxScrollOffset(); |
| 1820 } | 1835 } |
| 1821 | 1836 |
| 1822 void LayerTreeHostImpl::DidChangeTopControlsPosition() { | 1837 void LayerTreeHostImpl::DidChangeTopControlsPosition() { |
| 1823 client_->SetNeedsRedrawOnImplThread(); | 1838 client_->SetNeedsRedrawOnImplThread(); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2257 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); | 2272 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); |
| 2258 | 2273 |
| 2259 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); | 2274 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); |
| 2260 scroll_info->page_scale_delta = active_tree_->page_scale_delta(); | 2275 scroll_info->page_scale_delta = active_tree_->page_scale_delta(); |
| 2261 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta); | 2276 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta); |
| 2262 | 2277 |
| 2263 return scroll_info.Pass(); | 2278 return scroll_info.Pass(); |
| 2264 } | 2279 } |
| 2265 | 2280 |
| 2266 void LayerTreeHostImpl::SetFullRootLayerDamage() { | 2281 void LayerTreeHostImpl::SetFullRootLayerDamage() { |
| 2267 SetViewportDamage(gfx::Rect(device_viewport_size_)); | 2282 SetViewportDamage(gfx::Rect(DeviceViewport().size())); |
| 2268 } | 2283 } |
| 2269 | 2284 |
| 2270 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) { | 2285 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) { |
| 2271 if (!page_scale_animation_ || !RootScrollLayer()) | 2286 if (!page_scale_animation_ || !RootScrollLayer()) |
| 2272 return; | 2287 return; |
| 2273 | 2288 |
| 2274 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); | 2289 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); |
| 2275 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() + | 2290 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() + |
| 2276 RootScrollLayer()->ScrollDelta(); | 2291 RootScrollLayer()->ScrollDelta(); |
| 2277 | 2292 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2577 | 2592 |
| 2578 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource( | 2593 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource( |
| 2579 UIResourceId uid) const { | 2594 UIResourceId uid) const { |
| 2580 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid); | 2595 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid); |
| 2581 if (iter != ui_resource_map_.end()) | 2596 if (iter != ui_resource_map_.end()) |
| 2582 return iter->second; | 2597 return iter->second; |
| 2583 return 0; | 2598 return 0; |
| 2584 } | 2599 } |
| 2585 | 2600 |
| 2586 } // namespace cc | 2601 } // namespace cc |
| OLD | NEW |