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 <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "cc/animation/scrollbar_animation_controller.h" | 16 #include "cc/animation/scrollbar_animation_controller.h" |
17 #include "cc/animation/timing_function.h" | 17 #include "cc/animation/timing_function.h" |
| 18 #include "cc/base/latency_info_swap_promise.h" |
18 #include "cc/base/latency_info_swap_promise_monitor.h" | 19 #include "cc/base/latency_info_swap_promise_monitor.h" |
19 #include "cc/base/math_util.h" | 20 #include "cc/base/math_util.h" |
20 #include "cc/base/util.h" | 21 #include "cc/base/util.h" |
21 #include "cc/debug/benchmark_instrumentation.h" | 22 #include "cc/debug/benchmark_instrumentation.h" |
22 #include "cc/debug/debug_rect_history.h" | 23 #include "cc/debug/debug_rect_history.h" |
23 #include "cc/debug/devtools_instrumentation.h" | 24 #include "cc/debug/devtools_instrumentation.h" |
24 #include "cc/debug/frame_rate_counter.h" | 25 #include "cc/debug/frame_rate_counter.h" |
25 #include "cc/debug/paint_time_counter.h" | 26 #include "cc/debug/paint_time_counter.h" |
26 #include "cc/debug/rendering_stats_instrumentation.h" | 27 #include "cc/debug/rendering_stats_instrumentation.h" |
27 #include "cc/debug/traced_value.h" | 28 #include "cc/debug/traced_value.h" |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 return layer_impl != NULL; | 494 return layer_impl != NULL; |
494 } | 495 } |
495 | 496 |
496 scoped_ptr<SwapPromiseMonitor> | 497 scoped_ptr<SwapPromiseMonitor> |
497 LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor( | 498 LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor( |
498 ui::LatencyInfo* latency) { | 499 ui::LatencyInfo* latency) { |
499 return scoped_ptr<SwapPromiseMonitor>( | 500 return scoped_ptr<SwapPromiseMonitor>( |
500 new LatencyInfoSwapPromiseMonitor(latency, NULL, this)); | 501 new LatencyInfoSwapPromiseMonitor(latency, NULL, this)); |
501 } | 502 } |
502 | 503 |
| 504 void LayerTreeHostImpl::QueueSwapPromiseForMainThreadScrollUpdate( |
| 505 scoped_ptr<LatencyInfoSwapPromise> swap_promise) { |
| 506 if (swap_promises_for_main_thread_scroll_update_.size() > |
| 507 kMaxQueuedSwapPromiseNumber) { |
| 508 BreakSwapPromisesForMainThreadScrollUpdate( |
| 509 SwapPromise::SWAP_PROMISE_LIST_OVERFLOW); |
| 510 } |
| 511 swap_promises_for_main_thread_scroll_update_.push_back(swap_promise.Pass()); |
| 512 } |
| 513 |
| 514 void LayerTreeHostImpl::BreakSwapPromisesForMainThreadScrollUpdate( |
| 515 SwapPromise::DidNotSwapReason reason) { |
| 516 for (size_t i = 0; i < swap_promises_for_main_thread_scroll_update_.size(); |
| 517 i++) |
| 518 swap_promises_for_main_thread_scroll_update_[i]->DidNotSwap(reason); |
| 519 swap_promises_for_main_thread_scroll_update_.clear(); |
| 520 } |
| 521 |
503 void LayerTreeHostImpl::TrackDamageForAllSurfaces( | 522 void LayerTreeHostImpl::TrackDamageForAllSurfaces( |
504 LayerImpl* root_draw_layer, | 523 LayerImpl* root_draw_layer, |
505 const LayerImplList& render_surface_layer_list) { | 524 const LayerImplList& render_surface_layer_list) { |
506 // For now, we use damage tracking to compute a global scissor. To do this, we | 525 // For now, we use damage tracking to compute a global scissor. To do this, we |
507 // must compute all damage tracking before drawing anything, so that we know | 526 // must compute all damage tracking before drawing anything, so that we know |
508 // the root damage rect. The root damage rect is then used to scissor each | 527 // the root damage rect. The root damage rect is then used to scissor each |
509 // surface. | 528 // surface. |
510 | 529 |
511 for (int surface_index = render_surface_layer_list.size() - 1; | 530 for (int surface_index = render_surface_layer_list.size() - 1; |
512 surface_index >= 0; | 531 surface_index >= 0; |
(...skipping 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2461 // which the layer moved. | 2480 // which the layer moved. |
2462 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); | 2481 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); |
2463 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); | 2482 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); |
2464 | 2483 |
2465 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) | 2484 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) |
2466 break; | 2485 break; |
2467 } | 2486 } |
2468 | 2487 |
2469 bool did_scroll_content = did_scroll_x || did_scroll_y; | 2488 bool did_scroll_content = did_scroll_x || did_scroll_y; |
2470 if (did_scroll_content) { | 2489 if (did_scroll_content) { |
| 2490 // If we are scrolling with an active scroll handler, forward latency |
| 2491 // tracking information to the main thread so the delay introduced by the |
| 2492 // handler is accounted for. |
| 2493 if (scroll_affects_scroll_handler()) |
| 2494 NotifySwapPromiseMonitorsOfForwardingToMainThread(); |
2471 client_->SetNeedsCommitOnImplThread(); | 2495 client_->SetNeedsCommitOnImplThread(); |
2472 SetNeedsRedraw(); | 2496 SetNeedsRedraw(); |
2473 client_->RenewTreePriority(); | 2497 client_->RenewTreePriority(); |
2474 } | 2498 } |
2475 | 2499 |
2476 // Scrolling along an axis resets accumulated root overscroll for that axis. | 2500 // Scrolling along an axis resets accumulated root overscroll for that axis. |
2477 if (did_scroll_x) | 2501 if (did_scroll_x) |
2478 accumulated_root_overscroll_.set_x(0); | 2502 accumulated_root_overscroll_.set_x(0); |
2479 if (did_scroll_y) | 2503 if (did_scroll_y) |
2480 accumulated_root_overscroll_.set_y(0); | 2504 accumulated_root_overscroll_.set_y(0); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2762 for (size_t i = 0; i < layer_impl->children().size(); ++i) | 2786 for (size_t i = 0; i < layer_impl->children().size(); ++i) |
2763 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); | 2787 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); |
2764 } | 2788 } |
2765 | 2789 |
2766 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { | 2790 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { |
2767 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); | 2791 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); |
2768 | 2792 |
2769 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); | 2793 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); |
2770 scroll_info->page_scale_delta = active_tree_->page_scale_delta(); | 2794 scroll_info->page_scale_delta = active_tree_->page_scale_delta(); |
2771 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta); | 2795 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta); |
| 2796 scroll_info->swap_promises.swap(swap_promises_for_main_thread_scroll_update_); |
2772 | 2797 |
2773 return scroll_info.Pass(); | 2798 return scroll_info.Pass(); |
2774 } | 2799 } |
2775 | 2800 |
2776 void LayerTreeHostImpl::SetFullRootLayerDamage() { | 2801 void LayerTreeHostImpl::SetFullRootLayerDamage() { |
2777 SetViewportDamage(gfx::Rect(DrawViewportSize())); | 2802 SetViewportDamage(gfx::Rect(DrawViewportSize())); |
2778 } | 2803 } |
2779 | 2804 |
2780 void LayerTreeHostImpl::RunOnDemandRasterTask(Task* on_demand_raster_task) { | 2805 void LayerTreeHostImpl::RunOnDemandRasterTask(Task* on_demand_raster_task) { |
2781 DCHECK(on_demand_task_graph_runner_); | 2806 DCHECK(on_demand_task_graph_runner_); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3138 void LayerTreeHostImpl::RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor) { | 3163 void LayerTreeHostImpl::RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor) { |
3139 swap_promise_monitor_.erase(monitor); | 3164 swap_promise_monitor_.erase(monitor); |
3140 } | 3165 } |
3141 | 3166 |
3142 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { | 3167 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { |
3143 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3168 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
3144 for (; it != swap_promise_monitor_.end(); it++) | 3169 for (; it != swap_promise_monitor_.end(); it++) |
3145 (*it)->OnSetNeedsRedrawOnImpl(); | 3170 (*it)->OnSetNeedsRedrawOnImpl(); |
3146 } | 3171 } |
3147 | 3172 |
| 3173 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfForwardingToMainThread() { |
| 3174 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
| 3175 for (; it != swap_promise_monitor_.end(); it++) |
| 3176 (*it)->OnForwardScrollUpdateToMainThreadOnImpl(); |
| 3177 } |
| 3178 |
3148 void LayerTreeHostImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) { | 3179 void LayerTreeHostImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) { |
3149 DCHECK(std::find(picture_layers_.begin(), picture_layers_.end(), layer) == | 3180 DCHECK(std::find(picture_layers_.begin(), picture_layers_.end(), layer) == |
3150 picture_layers_.end()); | 3181 picture_layers_.end()); |
3151 picture_layers_.push_back(layer); | 3182 picture_layers_.push_back(layer); |
3152 } | 3183 } |
3153 | 3184 |
3154 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3185 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3155 std::vector<PictureLayerImpl*>::iterator it = | 3186 std::vector<PictureLayerImpl*>::iterator it = |
3156 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3187 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3157 DCHECK(it != picture_layers_.end()); | 3188 DCHECK(it != picture_layers_.end()); |
3158 picture_layers_.erase(it); | 3189 picture_layers_.erase(it); |
3159 } | 3190 } |
3160 | 3191 |
3161 } // namespace cc | 3192 } // namespace cc |
OLD | NEW |