OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output/begin_frame_args.h" | 5 #include "cc/output/begin_frame_args.h" |
6 | 6 |
7 #include "base/debug/trace_event_argument.h" | 7 #include "base/debug/trace_event_argument.h" |
8 #include "ui/gfx/frame_time.h" | 8 #include "ui/gfx/frame_time.h" |
9 | 9 |
10 namespace cc { | 10 namespace cc { |
11 | 11 |
12 const char* BeginFrameArgs::TypeToString(BeginFrameArgsType type) { | |
13 switch (type) { | |
picksi1
2014/11/20 14:04:20
should this be a const function?
mithro-old
2014/11/21 03:17:04
Static functions can't be const.
| |
14 case BeginFrameArgs::INVALID: | |
15 return "INVALID"; | |
16 case BeginFrameArgs::NORMAL: | |
17 return "NORMAL"; | |
18 case BeginFrameArgs::SYNCHRONOUS: | |
19 return "SYNCHRONOUS"; | |
20 case BeginFrameArgs::MISSED: | |
21 return "MISSED"; | |
22 } | |
23 NOTREACHED(); | |
24 return "???"; | |
picksi1
2014/11/20 14:04:20
If this return value is Logged somewhere (in the t
danakj
2014/11/20 16:03:02
The NOTREACHED implies we never get to this line.
mithro-old
2014/11/21 03:17:03
This follows the approach in cc/scheduler/schedule
mithro-old
2014/11/21 03:17:04
NOTREACHED() doesn't fail where DCHECK is not enab
| |
25 } | |
26 | |
12 BeginFrameArgs::BeginFrameArgs() | 27 BeginFrameArgs::BeginFrameArgs() |
13 : frame_time(base::TimeTicks()), | 28 : frame_time(base::TimeTicks()), |
14 deadline(base::TimeTicks()), | 29 deadline(base::TimeTicks()), |
15 interval(base::TimeDelta::FromMicroseconds(-1)), | 30 interval(base::TimeDelta::FromMicroseconds(-1)), |
16 type(BeginFrameArgs::INVALID) { | 31 type(BeginFrameArgs::INVALID) { |
17 } | 32 } |
18 | 33 |
19 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time, | 34 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time, |
20 base::TimeTicks deadline, | 35 base::TimeTicks deadline, |
21 base::TimeDelta interval, | 36 base::TimeDelta interval, |
22 BeginFrameArgs::BeginFrameArgsType type) | 37 BeginFrameArgs::BeginFrameArgsType type) |
23 : frame_time(frame_time), | 38 : frame_time(frame_time), |
24 deadline(deadline), | 39 deadline(deadline), |
25 interval(interval), | 40 interval(interval), |
26 type(type) { | 41 type(type) { |
27 } | 42 } |
28 | 43 |
29 BeginFrameArgs BeginFrameArgs::CreateTyped( | 44 BeginFrameArgs BeginFrameArgs::Create(BeginFrameArgs::CreationLocation location, |
30 base::TimeTicks frame_time, | 45 base::TimeTicks frame_time, |
31 base::TimeTicks deadline, | 46 base::TimeTicks deadline, |
32 base::TimeDelta interval, | 47 base::TimeDelta interval, |
33 BeginFrameArgs::BeginFrameArgsType type) { | 48 BeginFrameArgs::BeginFrameArgsType type) { |
34 DCHECK_NE(type, BeginFrameArgs::INVALID); | 49 DCHECK_NE(type, BeginFrameArgs::INVALID); |
50 #ifdef NDEBUG | |
35 return BeginFrameArgs(frame_time, deadline, interval, type); | 51 return BeginFrameArgs(frame_time, deadline, interval, type); |
36 } | 52 #else |
37 | 53 BeginFrameArgs args = BeginFrameArgs(frame_time, deadline, interval, type); |
38 BeginFrameArgs BeginFrameArgs::Create(base::TimeTicks frame_time, | 54 args.created_by = *location; |
39 base::TimeTicks deadline, | 55 return args; |
40 base::TimeDelta interval) { | 56 #endif |
41 return CreateTyped(frame_time, deadline, interval, BeginFrameArgs::NORMAL); | |
42 } | 57 } |
43 | 58 |
44 scoped_refptr<base::debug::ConvertableToTraceFormat> BeginFrameArgs::AsValue() | 59 scoped_refptr<base::debug::ConvertableToTraceFormat> BeginFrameArgs::AsValue() |
45 const { | 60 const { |
46 scoped_refptr<base::debug::TracedValue> state = | 61 scoped_refptr<base::debug::TracedValue> state = |
47 new base::debug::TracedValue(); | 62 new base::debug::TracedValue(); |
48 AsValueInto(state.get()); | 63 AsValueInto(state.get()); |
49 return state; | 64 return state; |
50 } | 65 } |
51 | 66 |
52 void BeginFrameArgs::AsValueInto(base::debug::TracedValue* state) const { | 67 void BeginFrameArgs::AsValueInto(base::debug::TracedValue* state) const { |
53 state->SetString("type", "BeginFrameArgs"); | 68 state->SetString("type", "BeginFrameArgs"); |
54 switch (type) { | 69 state->SetString("subtype", TypeToString(type)); |
55 case BeginFrameArgs::INVALID: | |
56 state->SetString("subtype", "INVALID"); | |
57 break; | |
58 case BeginFrameArgs::NORMAL: | |
59 state->SetString("subtype", "NORMAL"); | |
60 break; | |
61 case BeginFrameArgs::SYNCHRONOUS: | |
62 state->SetString("subtype", "SYNCHRONOUS"); | |
63 break; | |
64 case BeginFrameArgs::MISSED: | |
65 state->SetString("subtype", "MISSED"); | |
66 break; | |
67 } | |
68 state->SetDouble("frame_time_us", frame_time.ToInternalValue()); | 70 state->SetDouble("frame_time_us", frame_time.ToInternalValue()); |
69 state->SetDouble("deadline_us", deadline.ToInternalValue()); | 71 state->SetDouble("deadline_us", deadline.ToInternalValue()); |
70 state->SetDouble("interval_us", interval.InMicroseconds()); | 72 state->SetDouble("interval_us", interval.InMicroseconds()); |
71 } | 73 #ifndef NDEBUG |
72 | 74 std::string created_by_str(""); |
73 BeginFrameArgs BeginFrameArgs::CreateForSynchronousCompositor( | 75 created_by.Write(true, true, &created_by_str); |
74 base::TimeTicks now) { | 76 state->SetString("created_by", created_by_str); |
75 // For WebView/SynchronousCompositor, we always want to draw immediately, | 77 #endif |
76 // so we set the deadline to 0 and guess that the interval is 16 milliseconds. | |
77 if (now.is_null()) | |
78 now = gfx::FrameTime::Now(); | |
79 return CreateTyped( | |
80 now, base::TimeTicks(), DefaultInterval(), BeginFrameArgs::SYNCHRONOUS); | |
81 } | 78 } |
82 | 79 |
83 // This is a hard-coded deadline adjustment that assumes 60Hz, to be used in | 80 // This is a hard-coded deadline adjustment that assumes 60Hz, to be used in |
84 // cases where a good estimated draw time is not known. Using 1/3 of the vsync | 81 // cases where a good estimated draw time is not known. Using 1/3 of the vsync |
85 // as the default adjustment gives the Browser the last 1/3 of a frame to | 82 // as the default adjustment gives the Browser the last 1/3 of a frame to |
86 // produce output, the Renderer Impl thread the middle 1/3 of a frame to produce | 83 // produce output, the Renderer Impl thread the middle 1/3 of a frame to produce |
87 // ouput, and the Renderer Main thread the first 1/3 of a frame to produce | 84 // ouput, and the Renderer Main thread the first 1/3 of a frame to produce |
88 // output. | 85 // output. |
89 base::TimeDelta BeginFrameArgs::DefaultEstimatedParentDrawTime() { | 86 base::TimeDelta BeginFrameArgs::DefaultEstimatedParentDrawTime() { |
90 return base::TimeDelta::FromMicroseconds(16666 / 3); | 87 return base::TimeDelta::FromMicroseconds(16666 / 3); |
91 } | 88 } |
92 | 89 |
93 base::TimeDelta BeginFrameArgs::DefaultInterval() { | 90 base::TimeDelta BeginFrameArgs::DefaultInterval() { |
94 return base::TimeDelta::FromMicroseconds(16666); | 91 return base::TimeDelta::FromMicroseconds(16666); |
95 } | 92 } |
96 | 93 |
97 base::TimeDelta BeginFrameArgs::DefaultRetroactiveBeginFramePeriod() { | 94 base::TimeDelta BeginFrameArgs::DefaultRetroactiveBeginFramePeriod() { |
98 return base::TimeDelta::FromMicroseconds(4444); | 95 return base::TimeDelta::FromMicroseconds(4444); |
99 } | 96 } |
100 | 97 |
101 } // namespace cc | 98 } // namespace cc |
OLD | NEW |