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/output/latency_info_swap_promise.h"
7 #include "base/logging.h"
8 #include "base/trace_event/trace_event.h"
11 ui::LatencyComponentType
DidNotSwapReasonToLatencyComponentType(
12 cc::SwapPromise::DidNotSwapReason reason
) {
14 case cc::SwapPromise::ACTIVATION_FAILS
:
15 case cc::SwapPromise::SWAP_FAILS
:
16 return ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT
;
17 case cc::SwapPromise::COMMIT_FAILS
:
18 return ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT
;
19 case cc::SwapPromise::COMMIT_NO_UPDATE
:
20 return ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT
;
22 NOTREACHED() << "Unhandled DidNotSwapReason.";
23 return ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT
;
29 LatencyInfoSwapPromise::LatencyInfoSwapPromise(const ui::LatencyInfo
& latency
)
33 LatencyInfoSwapPromise::~LatencyInfoSwapPromise() {
36 void LatencyInfoSwapPromise::DidSwap(CompositorFrameMetadata
* metadata
) {
37 DCHECK(!latency_
.terminated());
38 metadata
->latency_info
.push_back(latency_
);
41 void LatencyInfoSwapPromise::DidNotSwap(DidNotSwapReason reason
) {
42 latency_
.AddLatencyNumber(DidNotSwapReasonToLatencyComponentType(reason
), 0,
44 // TODO(miletus): Turn this back on once per-event LatencyInfo tracking
45 // is enabled in GPU side.
46 // DCHECK(latency_.terminated);
49 int64
LatencyInfoSwapPromise::TraceId() const {
50 return latency_
.trace_id();
53 // Trace the original LatencyInfo of a LatencyInfoSwapPromise
54 void LatencyInfoSwapPromise::OnCommit() {
55 TRACE_EVENT_WITH_FLOW1("input,benchmark",
57 TRACE_ID_DONT_MANGLE(TraceId()),
58 TRACE_EVENT_FLAG_FLOW_IN
| TRACE_EVENT_FLAG_FLOW_OUT
,
59 "step", "HandleInputEventMainCommit");