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"
15 bool AddRenderingScheduledComponent(ui::LatencyInfo* latency_info) {
16 if (latency_info->FindLatency(
17 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, nullptr))
19 latency_info->AddLatencyNumber(
20 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, 0);
24 bool AddForwardingScrollUpdateToMainComponent(ui::LatencyInfo* latency_info) {
25 if (latency_info->FindLatency(
26 ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT,
30 latency_info->AddLatencyNumber(
31 ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT,
33 latency_info->trace_id);
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),
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();
71 if (it->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT) {
73 (static_cast<int64>(base::PlatformThread::CurrentId()) << 32) |
74 (it->second.sequence_number & 0xffffffff);
75 DCHECK(new_sequence_number != it->second.sequence_number);
79 if (!new_sequence_number)
81 ui::LatencyInfo new_latency;
82 new_latency.AddLatencyNumber(
83 ui::INPUT_EVENT_LATENCY_BEGIN_SCROLL_UPDATE_MAIN_COMPONENT,
86 new_latency.TraceEventType("ScrollUpdate");
87 new_latency.CopyLatencyFrom(
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(