| 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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // construct a DebugScopedSetImplThread object. There is no need to do | 98 // construct a DebugScopedSetImplThread object. There is no need to do |
| 99 // this in multi-threaded mode since the real thread id's will be | 99 // this in multi-threaded mode since the real thread id's will be |
| 100 // correct. In fact, setting fake thread id's interferes with the real | 100 // correct. In fact, setting fake thread id's interferes with the real |
| 101 // thread id's and causes breakage. | 101 // thread id's and causes breakage. |
| 102 scoped_ptr<DebugScopedSetImplThread> set_impl_thread; | 102 scoped_ptr<DebugScopedSetImplThread> set_impl_thread; |
| 103 if (!layer_tree_host_impl_->proxy()->HasImplThread()) { | 103 if (!layer_tree_host_impl_->proxy()->HasImplThread()) { |
| 104 set_impl_thread.reset( | 104 set_impl_thread.reset( |
| 105 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); | 105 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // TODO(enne): This should probably happen post-animate. | 108 if (layer_tree_host_impl_->settings().impl_side_painting) { |
| 109 if (layer_tree_host_impl_->pending_tree()) { | 109 layer_tree_host_impl_->BeginFrame( |
| 110 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); | 110 BeginFrameArgs::CreateExpiredForTesting()); |
| 111 } else { |
| 112 if (layer_tree_host_impl_->pending_tree()) { |
| 113 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); |
| 111 | 114 |
| 112 if (layer_tree_host_impl_->pending_tree()) { | 115 if (layer_tree_host_impl_->pending_tree()) { |
| 113 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); | 116 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); |
| 114 layer_tree_host_impl_->ManageTiles(); | 117 layer_tree_host_impl_->ManageTiles(); |
| 118 } |
| 115 } | 119 } |
| 120 |
| 121 layer_tree_host_impl_->Animate( |
| 122 layer_tree_host_impl_->CurrentFrameTimeTicks(), |
| 123 layer_tree_host_impl_->CurrentFrameTime()); |
| 124 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); |
| 125 bool start_ready_animations = true; |
| 126 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
| 127 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
| 116 } | 128 } |
| 117 | |
| 118 layer_tree_host_impl_->Animate( | |
| 119 layer_tree_host_impl_->CurrentFrameTimeTicks(), | |
| 120 layer_tree_host_impl_->CurrentFrameTime()); | |
| 121 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); | |
| 122 bool start_ready_animations = true; | |
| 123 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | |
| 124 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | |
| 125 } | 129 } |
| 126 | 130 |
| 127 void SetActive(bool active) { | 131 void SetActive(bool active) { |
| 128 if (active != time_source_->Active()) | 132 if (active != time_source_->Active()) |
| 129 time_source_->SetActive(active); | 133 time_source_->SetActive(active); |
| 130 } | 134 } |
| 131 | 135 |
| 132 private: | 136 private: |
| 133 LayerTreeHostImplTimeSourceAdapter( | 137 LayerTreeHostImplTimeSourceAdapter( |
| 134 LayerTreeHostImpl* layer_tree_host_impl, | 138 LayerTreeHostImpl* layer_tree_host_impl, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 TRACE_EVENT_INSTANT0( | 293 TRACE_EVENT_INSTANT0( |
| 290 "cc", "LayerTreeHostImpl::CanDraw contents textures purged", | 294 "cc", "LayerTreeHostImpl::CanDraw contents textures purged", |
| 291 TRACE_EVENT_SCOPE_THREAD); | 295 TRACE_EVENT_SCOPE_THREAD); |
| 292 return false; | 296 return false; |
| 293 } | 297 } |
| 294 return true; | 298 return true; |
| 295 } | 299 } |
| 296 | 300 |
| 297 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time, | 301 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time, |
| 298 base::Time wall_clock_time) { | 302 base::Time wall_clock_time) { |
| 303 TRACE_EVENT0("cc", __FUNCTION__); |
| 299 if (input_handler_client_) | 304 if (input_handler_client_) |
| 300 input_handler_client_->Animate(monotonic_time); | 305 input_handler_client_->Animate(monotonic_time); |
| 301 AnimatePageScale(monotonic_time); | 306 AnimatePageScale(monotonic_time); |
| 302 AnimateLayers(monotonic_time, wall_clock_time); | 307 AnimateLayers(monotonic_time, wall_clock_time); |
| 303 AnimateScrollbars(monotonic_time); | 308 AnimateScrollbars(monotonic_time); |
| 304 AnimateTopControls(monotonic_time); | 309 AnimateTopControls(monotonic_time); |
| 305 } | 310 } |
| 306 | 311 |
| 307 void LayerTreeHostImpl::ManageTiles() { | 312 void LayerTreeHostImpl::ManageTiles() { |
| 308 if (!tile_manager_) | 313 if (!tile_manager_) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 321 SendManagedMemoryStats(memory_required_bytes, | 326 SendManagedMemoryStats(memory_required_bytes, |
| 322 memory_nice_to_have_bytes, | 327 memory_nice_to_have_bytes, |
| 323 memory_used_bytes); | 328 memory_used_bytes); |
| 324 } | 329 } |
| 325 | 330 |
| 326 void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset, | 331 void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset, |
| 327 bool anchor_point, | 332 bool anchor_point, |
| 328 float page_scale, | 333 float page_scale, |
| 329 base::TimeTicks start_time, | 334 base::TimeTicks start_time, |
| 330 base::TimeDelta duration) { | 335 base::TimeDelta duration) { |
| 336 TRACE_EVENT0("cc", __FUNCTION__); |
| 331 if (!RootScrollLayer()) | 337 if (!RootScrollLayer()) |
| 332 return; | 338 return; |
| 333 | 339 |
| 334 gfx::Vector2dF scroll_total = | 340 gfx::Vector2dF scroll_total = |
| 335 RootScrollLayer()->scroll_offset() + RootScrollLayer()->ScrollDelta(); | 341 RootScrollLayer()->scroll_offset() + RootScrollLayer()->ScrollDelta(); |
| 336 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); | 342 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); |
| 337 gfx::SizeF viewport_size = VisibleViewportSize(); | 343 gfx::SizeF viewport_size = VisibleViewportSize(); |
| 338 | 344 |
| 339 double start_time_seconds = (start_time - base::TimeTicks()).InSecondsF(); | 345 double start_time_seconds = (start_time - base::TimeTicks()).InSecondsF(); |
| 340 | 346 |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 if (input_handler_client_) | 769 if (input_handler_client_) |
| 764 input_handler_client_->MainThreadHasStoppedFlinging(); | 770 input_handler_client_->MainThreadHasStoppedFlinging(); |
| 765 } | 771 } |
| 766 | 772 |
| 767 void LayerTreeHostImpl::UpdateBackgroundAnimateTicking( | 773 void LayerTreeHostImpl::UpdateBackgroundAnimateTicking( |
| 768 bool should_background_tick) { | 774 bool should_background_tick) { |
| 769 DCHECK(proxy_->IsImplThread()); | 775 DCHECK(proxy_->IsImplThread()); |
| 770 | 776 |
| 771 bool enabled = should_background_tick && | 777 bool enabled = should_background_tick && |
| 772 !animation_registrar_->active_animation_controllers().empty(); | 778 !animation_registrar_->active_animation_controllers().empty(); |
| 773 | 779 if (animation_registrar_->active_animation_controllers().empty()) { |
| 780 TRACE_EVENT0("cc", "animation_registrar_->active_animation_controllers().emp
ty() == true"); |
| 781 } |
| 774 // Lazily create the time_source adapter so that we can vary the interval for | 782 // Lazily create the time_source adapter so that we can vary the interval for |
| 775 // testing. | 783 // testing. |
| 776 if (!time_source_client_adapter_) { | 784 if (!time_source_client_adapter_) { |
| 777 time_source_client_adapter_ = LayerTreeHostImplTimeSourceAdapter::Create( | 785 time_source_client_adapter_ = LayerTreeHostImplTimeSourceAdapter::Create( |
| 778 this, | 786 this, |
| 779 DelayBasedTimeSource::Create( | 787 DelayBasedTimeSource::Create( |
| 780 LowFrequencyAnimationInterval(), | 788 LowFrequencyAnimationInterval(), |
| 781 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() | 789 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() |
| 782 : proxy_->MainThreadTaskRunner())); | 790 : proxy_->MainThreadTaskRunner())); |
| 783 } | 791 } |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 TreeSynchronizer::PushProperties(pending_tree_->root_layer(), | 1389 TreeSynchronizer::PushProperties(pending_tree_->root_layer(), |
| 1382 active_tree_->root_layer()); | 1390 active_tree_->root_layer()); |
| 1383 DCHECK(!recycle_tree_); | 1391 DCHECK(!recycle_tree_); |
| 1384 | 1392 |
| 1385 pending_tree_->PushPropertiesTo(active_tree_.get()); | 1393 pending_tree_->PushPropertiesTo(active_tree_.get()); |
| 1386 | 1394 |
| 1387 // Now that we've synced everything from the pending tree to the active | 1395 // Now that we've synced everything from the pending tree to the active |
| 1388 // tree, rename the pending tree the recycle tree so we can reuse it on the | 1396 // tree, rename the pending tree the recycle tree so we can reuse it on the |
| 1389 // next sync. | 1397 // next sync. |
| 1390 pending_tree_.swap(recycle_tree_); | 1398 pending_tree_.swap(recycle_tree_); |
| 1399 client_->DidActivatePendingTree(); |
| 1391 recycle_tree_->ClearRenderSurfaces(); | 1400 recycle_tree_->ClearRenderSurfaces(); |
| 1392 | 1401 |
| 1393 active_tree_->SetRootLayerScrollOffsetDelegate( | 1402 active_tree_->SetRootLayerScrollOffsetDelegate( |
| 1394 root_layer_scroll_offset_delegate_); | 1403 root_layer_scroll_offset_delegate_); |
| 1395 active_tree_->DidBecomeActive(); | 1404 active_tree_->DidBecomeActive(); |
| 1396 | 1405 |
| 1397 // Reduce wasted memory now that unlinked resources are guaranteed not | 1406 // Reduce wasted memory now that unlinked resources are guaranteed not |
| 1398 // to be used. | 1407 // to be used. |
| 1399 client_->ReduceWastedContentsTextureMemoryOnImplThread(); | 1408 client_->ReduceWastedContentsTextureMemoryOnImplThread(); |
| 1400 | 1409 |
| 1401 client_->OnCanDrawStateChanged(CanDraw()); | 1410 client_->OnCanDrawStateChanged(CanDraw()); |
| 1402 client_->OnHasPendingTreeStateChanged(pending_tree_); | 1411 client_->OnHasPendingTreeStateChanged(pending_tree_); |
| 1403 client_->SetNeedsRedrawOnImplThread(); | 1412 client_->SetNeedsRedrawOnImplThread(); |
| 1404 client_->RenewTreePriority(); | 1413 client_->RenewTreePriority(); |
| 1405 | 1414 |
| 1406 if (debug_state_.continuous_painting) { | 1415 if (debug_state_.continuous_painting) { |
| 1407 const RenderingStats& stats = | 1416 const RenderingStats& stats = |
| 1408 rendering_stats_instrumentation_->GetRenderingStats(); | 1417 rendering_stats_instrumentation_->GetRenderingStats(); |
| 1409 paint_time_counter_->SavePaintTime( | 1418 paint_time_counter_->SavePaintTime( |
| 1410 stats.total_paint_time + stats.total_record_time + | 1419 stats.total_paint_time + stats.total_record_time + |
| 1411 stats.total_rasterize_time_for_now_bins_on_pending_tree); | 1420 stats.total_rasterize_time_for_now_bins_on_pending_tree); |
| 1412 } | 1421 } |
| 1413 | 1422 |
| 1414 client_->DidActivatePendingTree(); | |
| 1415 } | 1423 } |
| 1416 | 1424 |
| 1417 void LayerTreeHostImpl::SetVisible(bool visible) { | 1425 void LayerTreeHostImpl::SetVisible(bool visible) { |
| 1418 DCHECK(proxy_->IsImplThread()); | 1426 DCHECK(proxy_->IsImplThread()); |
| 1419 | 1427 |
| 1420 if (visible_ == visible) | 1428 if (visible_ == visible) |
| 1421 return; | 1429 return; |
| 1422 visible_ = visible; | 1430 visible_ = visible; |
| 1423 DidVisibilityChange(this, visible_); | 1431 DidVisibilityChange(this, visible_); |
| 1424 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); | 1432 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2269 | 2277 |
| 2270 void LayerTreeHostImpl::ResetCurrentFrameTimeForNextFrame() { | 2278 void LayerTreeHostImpl::ResetCurrentFrameTimeForNextFrame() { |
| 2271 current_frame_timeticks_ = base::TimeTicks(); | 2279 current_frame_timeticks_ = base::TimeTicks(); |
| 2272 current_frame_time_ = base::Time(); | 2280 current_frame_time_ = base::Time(); |
| 2273 } | 2281 } |
| 2274 | 2282 |
| 2275 void LayerTreeHostImpl::UpdateCurrentFrameTime(base::TimeTicks* ticks, | 2283 void LayerTreeHostImpl::UpdateCurrentFrameTime(base::TimeTicks* ticks, |
| 2276 base::Time* now) const { | 2284 base::Time* now) const { |
| 2277 if (ticks->is_null()) { | 2285 if (ticks->is_null()) { |
| 2278 DCHECK(now->is_null()); | 2286 DCHECK(now->is_null()); |
| 2287 TRACE_EVENT0("cc", "UpdateCurrentFrameTime"); |
| 2279 *ticks = CurrentPhysicalTimeTicks(); | 2288 *ticks = CurrentPhysicalTimeTicks(); |
| 2280 *now = base::Time::Now(); | 2289 *now = base::Time::Now(); |
| 2281 } | 2290 } |
| 2282 } | 2291 } |
| 2283 | 2292 |
| 2284 base::TimeTicks LayerTreeHostImpl::CurrentFrameTimeTicks() { | 2293 base::TimeTicks LayerTreeHostImpl::CurrentFrameTimeTicks() { |
| 2285 UpdateCurrentFrameTime(¤t_frame_timeticks_, ¤t_frame_time_); | 2294 UpdateCurrentFrameTime(¤t_frame_timeticks_, ¤t_frame_time_); |
| 2286 return current_frame_timeticks_; | 2295 return current_frame_timeticks_; |
| 2287 } | 2296 } |
| 2288 | 2297 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2344 } | 2353 } |
| 2345 | 2354 |
| 2346 void LayerTreeHostImpl::SetDebugState(const LayerTreeDebugState& debug_state) { | 2355 void LayerTreeHostImpl::SetDebugState(const LayerTreeDebugState& debug_state) { |
| 2347 if (debug_state_.continuous_painting != debug_state.continuous_painting) | 2356 if (debug_state_.continuous_painting != debug_state.continuous_painting) |
| 2348 paint_time_counter_->ClearHistory(); | 2357 paint_time_counter_->ClearHistory(); |
| 2349 | 2358 |
| 2350 debug_state_ = debug_state; | 2359 debug_state_ = debug_state; |
| 2351 } | 2360 } |
| 2352 | 2361 |
| 2353 } // namespace cc | 2362 } // namespace cc |
| OLD | NEW |