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::MISSED
:
20 case BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX
:
21 return "BEGIN_FRAME_ARGS_TYPE_MAX";
27 BeginFrameArgs::BeginFrameArgs()
28 : frame_time(base::TimeTicks()),
29 deadline(base::TimeTicks()),
30 interval(base::TimeDelta::FromMicroseconds(-1)),
31 type(BeginFrameArgs::INVALID
) {
34 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time
,
35 base::TimeTicks deadline
,
36 base::TimeDelta interval
,
37 BeginFrameArgs::BeginFrameArgsType type
)
38 : frame_time(frame_time
),
44 BeginFrameArgs
BeginFrameArgs::Create(BeginFrameArgs::CreationLocation location
,
45 base::TimeTicks frame_time
,
46 base::TimeTicks deadline
,
47 base::TimeDelta interval
,
48 BeginFrameArgs::BeginFrameArgsType type
) {
49 DCHECK_NE(type
, BeginFrameArgs::INVALID
);
50 DCHECK_NE(type
, BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX
);
52 return BeginFrameArgs(frame_time
, deadline
, interval
, type
);
54 BeginFrameArgs args
= BeginFrameArgs(frame_time
, deadline
, interval
, type
);
55 args
.created_from
= location
;
60 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
61 BeginFrameArgs::AsValue() const {
62 scoped_refptr
<base::trace_event::TracedValue
> state
=
63 new base::trace_event::TracedValue();
64 AsValueInto(state
.get());
68 void BeginFrameArgs::AsValueInto(base::trace_event::TracedValue
* state
) const {
69 state
->SetString("type", "BeginFrameArgs");
70 state
->SetString("subtype", TypeToString(type
));
71 state
->SetDouble("frame_time_us", frame_time
.ToInternalValue());
72 state
->SetDouble("deadline_us", deadline
.ToInternalValue());
73 state
->SetDouble("interval_us", interval
.InMicroseconds());
75 state
->SetString("created_from", created_from
.ToString());
79 // This is a hard-coded deadline adjustment that assumes 60Hz, to be used in
80 // cases where a good estimated draw time is not known. Using 1/3 of the vsync
81 // as the default adjustment gives the Browser the last 1/3 of a frame to
82 // produce output, the Renderer Impl thread the middle 1/3 of a frame to produce
83 // ouput, and the Renderer Main thread the first 1/3 of a frame to produce
85 base::TimeDelta
BeginFrameArgs::DefaultEstimatedParentDrawTime() {
86 return base::TimeDelta::FromMicroseconds(16666 / 3);
89 base::TimeDelta
BeginFrameArgs::DefaultInterval() {
90 return base::TimeDelta::FromMicroseconds(16666);