Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / cc / base / latency_info_swap_promise_monitor.cc
blobdc2873988b3ef97b6bb355712e6adf13e68e4074
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
3 // found in the LICENSE file.
5 #include "cc/base/latency_info_swap_promise_monitor.h"
7 #include "base/threading/platform_thread.h"
8 #include "cc/base/latency_info_swap_promise.h"
9 #include "cc/trees/layer_tree_host.h"
10 #include "cc/trees/layer_tree_host_impl.h"
11 #include "cc/trees/layer_tree_impl.h"
13 namespace {
15 bool AddRenderingScheduledComponent(ui::LatencyInfo* latency_info) {
16 if (latency_info->FindLatency(
17 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, nullptr))
18 return false;
19 latency_info->AddLatencyNumber(
20 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, 0);
21 return true;
24 bool AddForwardingScrollUpdateToMainComponent(ui::LatencyInfo* latency_info) {
25 if (latency_info->FindLatency(
26 ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT,
28 nullptr))
29 return false;
30 latency_info->AddLatencyNumber(
31 ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT,
33 latency_info->trace_id);
34 return true;
37 } // namespace
39 namespace cc {
41 LatencyInfoSwapPromiseMonitor::LatencyInfoSwapPromiseMonitor(
42 ui::LatencyInfo* latency,
43 LayerTreeHost* layer_tree_host,
44 LayerTreeHostImpl* layer_tree_host_impl)
45 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
46 latency_(latency) {}
48 LatencyInfoSwapPromiseMonitor::~LatencyInfoSwapPromiseMonitor() {}
50 void LatencyInfoSwapPromiseMonitor::OnSetNeedsCommitOnMain() {
51 if (AddRenderingScheduledComponent(latency_)) {
52 scoped_ptr<SwapPromise> swap_promise(new LatencyInfoSwapPromise(*latency_));
53 layer_tree_host_->QueueSwapPromise(swap_promise.Pass());
57 void LatencyInfoSwapPromiseMonitor::OnSetNeedsRedrawOnImpl() {
58 if (AddRenderingScheduledComponent(latency_)) {
59 scoped_ptr<SwapPromise> swap_promise(new LatencyInfoSwapPromise(*latency_));
60 layer_tree_host_impl_->active_tree()->QueueSwapPromise(swap_promise.Pass());
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;
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,
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());
97 } // namespace cc