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/begin_frame_args.h"
7 #include "base/trace_event/trace_event_argument.h"
11 const char* BeginFrameArgs::TypeToString(BeginFrameArgsType type
) {
13 case BeginFrameArgs::INVALID
:
15 case BeginFrameArgs::NORMAL
:
17 case BeginFrameArgs::MISSED
:
19 case BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX
:
20 return "BEGIN_FRAME_ARGS_TYPE_MAX";
26 BeginFrameArgs::BeginFrameArgs()
27 : frame_time(base::TimeTicks()),
28 deadline(base::TimeTicks()),
29 interval(base::TimeDelta::FromMicroseconds(-1)),
30 type(BeginFrameArgs::INVALID
),
31 on_critical_path(true) {
34 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time
,
35 base::TimeTicks deadline
,
36 base::TimeDelta interval
,
37 BeginFrameArgs::BeginFrameArgsType type
)
38 : frame_time(frame_time
),
42 on_critical_path(true) {
45 BeginFrameArgs
BeginFrameArgs::Create(BeginFrameArgs::CreationLocation location
,
46 base::TimeTicks frame_time
,
47 base::TimeTicks deadline
,
48 base::TimeDelta interval
,
49 BeginFrameArgs::BeginFrameArgsType type
) {
50 DCHECK_NE(type
, BeginFrameArgs::INVALID
);
51 DCHECK_NE(type
, BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX
);
53 return BeginFrameArgs(frame_time
, deadline
, interval
, type
);
55 BeginFrameArgs args
= BeginFrameArgs(frame_time
, deadline
, interval
, type
);
56 args
.created_from
= location
;
61 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
62 BeginFrameArgs::AsValue() const {
63 scoped_refptr
<base::trace_event::TracedValue
> state
=
64 new base::trace_event::TracedValue();
65 AsValueInto(state
.get());
69 void BeginFrameArgs::AsValueInto(base::trace_event::TracedValue
* state
) const {
70 state
->SetString("type", "BeginFrameArgs");
71 state
->SetString("subtype", TypeToString(type
));
72 state
->SetDouble("frame_time_us", frame_time
.ToInternalValue());
73 state
->SetDouble("deadline_us", deadline
.ToInternalValue());
74 state
->SetDouble("interval_us", interval
.InMicroseconds());
76 state
->SetString("created_from", created_from
.ToString());
78 state
->SetBoolean("on_critical_path", on_critical_path
);
81 // This is a hard-coded deadline adjustment that assumes 60Hz, to be used in
82 // cases where a good estimated draw time is not known. Using 1/3 of the vsync
83 // as the default adjustment gives the Browser the last 1/3 of a frame to
84 // produce output, the Renderer Impl thread the middle 1/3 of a frame to produce
85 // ouput, and the Renderer Main thread the first 1/3 of a frame to produce
87 base::TimeDelta
BeginFrameArgs::DefaultEstimatedParentDrawTime() {
88 return base::TimeDelta::FromMicroseconds(16666 / 3);
91 base::TimeDelta
BeginFrameArgs::DefaultInterval() {
92 return base::TimeDelta::FromMicroseconds(16666);