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"
8 #include "ui/gfx/frame_time.h"
12 const char* BeginFrameArgs::TypeToString(BeginFrameArgsType type
) {
14 case BeginFrameArgs::INVALID
:
16 case BeginFrameArgs::NORMAL
:
18 case BeginFrameArgs::SYNCHRONOUS
:
20 case BeginFrameArgs::MISSED
:
22 case BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX
:
23 return "BEGIN_FRAME_ARGS_TYPE_MAX";
29 BeginFrameArgs::BeginFrameArgs()
30 : frame_time(base::TimeTicks()),
31 deadline(base::TimeTicks()),
32 interval(base::TimeDelta::FromMicroseconds(-1)),
33 type(BeginFrameArgs::INVALID
) {
36 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time
,
37 base::TimeTicks deadline
,
38 base::TimeDelta interval
,
39 BeginFrameArgs::BeginFrameArgsType type
)
40 : frame_time(frame_time
),
46 BeginFrameArgs
BeginFrameArgs::Create(BeginFrameArgs::CreationLocation location
,
47 base::TimeTicks frame_time
,
48 base::TimeTicks deadline
,
49 base::TimeDelta interval
,
50 BeginFrameArgs::BeginFrameArgsType type
) {
51 DCHECK_NE(type
, BeginFrameArgs::INVALID
);
52 DCHECK_NE(type
, BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX
);
54 return BeginFrameArgs(frame_time
, deadline
, interval
, type
);
56 BeginFrameArgs args
= BeginFrameArgs(frame_time
, deadline
, interval
, type
);
57 args
.created_from
= location
;
62 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
63 BeginFrameArgs::AsValue() const {
64 scoped_refptr
<base::trace_event::TracedValue
> state
=
65 new base::trace_event::TracedValue();
66 AsValueInto(state
.get());
70 void BeginFrameArgs::AsValueInto(base::trace_event::TracedValue
* state
) const {
71 state
->SetString("type", "BeginFrameArgs");
72 state
->SetString("subtype", TypeToString(type
));
73 state
->SetDouble("frame_time_us", frame_time
.ToInternalValue());
74 state
->SetDouble("deadline_us", deadline
.ToInternalValue());
75 state
->SetDouble("interval_us", interval
.InMicroseconds());
77 state
->SetString("created_from", created_from
.ToString());
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);