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.
4
5 #include "cc/output/begin_frame_args.h"
6
7 #include "base/debug/trace_event_argument.h"
8 #include "ui/gfx/frame_time.h"
9
10 namespace cc {
11
BeginFrameArgs()12 BeginFrameArgs::BeginFrameArgs()
13 : frame_time(base::TimeTicks()),
14 deadline(base::TimeTicks()),
15 interval(base::TimeDelta::FromMicroseconds(-1)) {
16 }
17
BeginFrameArgs(base::TimeTicks frame_time,base::TimeTicks deadline,base::TimeDelta interval)18 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time,
19 base::TimeTicks deadline,
20 base::TimeDelta interval)
21 : frame_time(frame_time),
22 deadline(deadline),
23 interval(interval)
24 {}
25
Create(base::TimeTicks frame_time,base::TimeTicks deadline,base::TimeDelta interval)26 BeginFrameArgs BeginFrameArgs::Create(base::TimeTicks frame_time,
27 base::TimeTicks deadline,
28 base::TimeDelta interval) {
29 return BeginFrameArgs(frame_time, deadline, interval);
30 }
31
AsValue() const32 scoped_refptr<base::debug::ConvertableToTraceFormat> BeginFrameArgs::AsValue()
33 const {
34 scoped_refptr<base::debug::TracedValue> state =
35 new base::debug::TracedValue();
36 AsValueInto(state.get());
37 return state;
38 }
39
AsValueInto(base::debug::TracedValue * state) const40 void BeginFrameArgs::AsValueInto(base::debug::TracedValue* state) const {
41 state->SetString("type", "BeginFrameArgs");
42 state->SetDouble("frame_time_us", frame_time.ToInternalValue());
43 state->SetDouble("deadline_us", deadline.ToInternalValue());
44 state->SetDouble("interval_us", interval.InMicroseconds());
45 }
46
CreateForSynchronousCompositor(base::TimeTicks now)47 BeginFrameArgs BeginFrameArgs::CreateForSynchronousCompositor(
48 base::TimeTicks now) {
49 // For WebView/SynchronousCompositor, we always want to draw immediately,
50 // so we set the deadline to 0 and guess that the interval is 16 milliseconds.
51 if (now.is_null())
52 now = gfx::FrameTime::Now();
53 return BeginFrameArgs(now, base::TimeTicks(), DefaultInterval());
54 }
55
56 // This is a hard-coded deadline adjustment that assumes 60Hz, to be used in
57 // cases where a good estimated draw time is not known. Using 1/3 of the vsync
58 // as the default adjustment gives the Browser the last 1/3 of a frame to
59 // produce output, the Renderer Impl thread the middle 1/3 of a frame to produce
60 // ouput, and the Renderer Main thread the first 1/3 of a frame to produce
61 // output.
DefaultEstimatedParentDrawTime()62 base::TimeDelta BeginFrameArgs::DefaultEstimatedParentDrawTime() {
63 return base::TimeDelta::FromMicroseconds(16666 / 3);
64 }
65
DefaultInterval()66 base::TimeDelta BeginFrameArgs::DefaultInterval() {
67 return base::TimeDelta::FromMicroseconds(16666);
68 }
69
DefaultRetroactiveBeginFramePeriod()70 base::TimeDelta BeginFrameArgs::DefaultRetroactiveBeginFramePeriod() {
71 return base::TimeDelta::FromMicroseconds(4444);
72 }
73
74 } // namespace cc
75