| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/base/latency_info_swap_promise_monitor.h" | 5 #include "cc/base/latency_info_swap_promise_monitor.h" |
| 6 | 6 |
| 7 #include "base/threading/platform_thread.h" |
| 7 #include "cc/base/latency_info_swap_promise.h" | 8 #include "cc/base/latency_info_swap_promise.h" |
| 8 #include "cc/trees/layer_tree_host.h" | 9 #include "cc/trees/layer_tree_host.h" |
| 9 #include "cc/trees/layer_tree_host_impl.h" | 10 #include "cc/trees/layer_tree_host_impl.h" |
| 10 #include "cc/trees/layer_tree_impl.h" | 11 #include "cc/trees/layer_tree_impl.h" |
| 11 | 12 |
| 13 namespace { |
| 14 |
| 15 bool AddRenderingScheduledComponent(ui::LatencyInfo* latency_info) { |
| 16 if (latency_info->FindLatency( |
| 17 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, NULL)) |
| 18 return false; |
| 19 latency_info->AddLatencyNumber( |
| 20 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, 0); |
| 21 return true; |
| 22 } |
| 23 |
| 24 bool AddForwardingScrollUpdateToMainComponent(ui::LatencyInfo* latency_info) { |
| 25 if (latency_info->FindLatency( |
| 26 ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT, |
| 27 0, |
| 28 NULL)) |
| 29 return false; |
| 30 latency_info->AddLatencyNumber( |
| 31 ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT, |
| 32 0, |
| 33 latency_info->trace_id); |
| 34 return true; |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
| 12 namespace cc { | 39 namespace cc { |
| 13 | 40 |
| 14 LatencyInfoSwapPromiseMonitor::LatencyInfoSwapPromiseMonitor( | 41 LatencyInfoSwapPromiseMonitor::LatencyInfoSwapPromiseMonitor( |
| 15 ui::LatencyInfo* latency, | 42 ui::LatencyInfo* latency, |
| 16 LayerTreeHost* layer_tree_host, | 43 LayerTreeHost* layer_tree_host, |
| 17 LayerTreeHostImpl* layer_tree_host_impl) | 44 LayerTreeHostImpl* layer_tree_host_impl) |
| 18 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), | 45 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), |
| 19 latency_(latency) {} | 46 latency_(latency) {} |
| 20 | 47 |
| 21 LatencyInfoSwapPromiseMonitor::~LatencyInfoSwapPromiseMonitor() {} | 48 LatencyInfoSwapPromiseMonitor::~LatencyInfoSwapPromiseMonitor() {} |
| 22 | 49 |
| 23 void LatencyInfoSwapPromiseMonitor::OnSetNeedsCommitOnMain() { | 50 void LatencyInfoSwapPromiseMonitor::OnSetNeedsCommitOnMain() { |
| 24 if (!latency_->FindLatency( | 51 if (AddRenderingScheduledComponent(latency_)) { |
| 25 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, 0)) { | |
| 26 latency_->AddLatencyNumber( | |
| 27 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, 0); | |
| 28 scoped_ptr<SwapPromise> swap_promise(new LatencyInfoSwapPromise(*latency_)); | 52 scoped_ptr<SwapPromise> swap_promise(new LatencyInfoSwapPromise(*latency_)); |
| 29 layer_tree_host_->QueueSwapPromise(swap_promise.Pass()); | 53 layer_tree_host_->QueueSwapPromise(swap_promise.Pass()); |
| 30 } | 54 } |
| 31 } | 55 } |
| 32 | 56 |
| 33 void LatencyInfoSwapPromiseMonitor::OnSetNeedsRedrawOnImpl() { | 57 void LatencyInfoSwapPromiseMonitor::OnSetNeedsRedrawOnImpl() { |
| 34 if (!latency_->FindLatency( | 58 if (AddRenderingScheduledComponent(latency_)) { |
| 35 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, 0)) { | |
| 36 latency_->AddLatencyNumber( | |
| 37 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, 0); | |
| 38 scoped_ptr<SwapPromise> swap_promise(new LatencyInfoSwapPromise(*latency_)); | 59 scoped_ptr<SwapPromise> swap_promise(new LatencyInfoSwapPromise(*latency_)); |
| 39 layer_tree_host_impl_->active_tree()->QueueSwapPromise(swap_promise.Pass()); | 60 layer_tree_host_impl_->active_tree()->QueueSwapPromise(swap_promise.Pass()); |
| 40 } | 61 } |
| 41 } | 62 } |
| 42 | 63 |
| 64 void LatencyInfoSwapPromiseMonitor::OnForwardScrollUpdateToMainThreadOnImpl() { |
| 65 if (AddForwardingScrollUpdateToMainComponent(latency_)) { |
| 66 int64 new_sequence_number = 0; |
| 67 for (ui::LatencyInfo::LatencyMap::const_iterator it = |
| 68 latency_->latency_components.begin(); |
| 69 it != latency_->latency_components.end(); |
| 70 ++it) { |
| 71 if (it->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT) { |
| 72 new_sequence_number = |
| 73 (static_cast<int64>(base::PlatformThread::CurrentId()) << 32) | |
| 74 (it->second.sequence_number & 0xffffffff); |
| 75 DCHECK(new_sequence_number != it->second.sequence_number); |
| 76 break; |
| 77 } |
| 78 } |
| 79 if (!new_sequence_number) |
| 80 return; |
| 81 ui::LatencyInfo new_latency; |
| 82 new_latency.AddLatencyNumber( |
| 83 ui::INPUT_EVENT_LATENCY_BEGIN_SCROLL_UPDATE_MAIN_COMPONENT, |
| 84 0, |
| 85 new_sequence_number); |
| 86 new_latency.TraceEventType("ScrollUpdate"); |
| 87 new_latency.CopyLatencyFrom( |
| 88 *latency_, |
| 89 ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT); |
| 90 scoped_ptr<SwapPromise> swap_promise( |
| 91 new LatencyInfoSwapPromise(new_latency)); |
| 92 layer_tree_host_impl_->QueueSwapPromiseForMainThreadScrollUpdate( |
| 93 swap_promise.Pass()); |
| 94 } |
| 95 } |
| 96 |
| 43 } // namespace cc | 97 } // namespace cc |
| OLD | NEW |