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 BeginFrameArgs::BeginFrameArgs() | 12 BeginFrameArgs::BeginFrameArgs() |
13 : frame_time(base::TimeTicks()), | 13 : frame_time(base::TimeTicks()), |
14 deadline(base::TimeTicks()), | 14 deadline(base::TimeTicks()), |
15 interval(base::TimeDelta::FromMicroseconds(-1)) { | 15 interval(base::TimeDelta::FromMicroseconds(-1)), |
| 16 type(BeginFrameArgs::INVALID) { |
16 } | 17 } |
17 | 18 |
18 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time, | 19 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time, |
19 base::TimeTicks deadline, | 20 base::TimeTicks deadline, |
20 base::TimeDelta interval) | 21 base::TimeDelta interval, |
21 : frame_time(frame_time), | 22 BeginFrameArgs::BeginFrameArgsType type) |
22 deadline(deadline), | 23 : frame_time(frame_time), |
23 interval(interval) | 24 deadline(deadline), |
24 {} | 25 interval(interval), |
| 26 type(type) { |
| 27 } |
| 28 |
| 29 BeginFrameArgs BeginFrameArgs::CreateTyped( |
| 30 base::TimeTicks frame_time, |
| 31 base::TimeTicks deadline, |
| 32 base::TimeDelta interval, |
| 33 BeginFrameArgs::BeginFrameArgsType type) { |
| 34 DCHECK_NE(type, BeginFrameArgs::INVALID); |
| 35 return BeginFrameArgs(frame_time, deadline, interval, type); |
| 36 } |
25 | 37 |
26 BeginFrameArgs BeginFrameArgs::Create(base::TimeTicks frame_time, | 38 BeginFrameArgs BeginFrameArgs::Create(base::TimeTicks frame_time, |
27 base::TimeTicks deadline, | 39 base::TimeTicks deadline, |
28 base::TimeDelta interval) { | 40 base::TimeDelta interval) { |
29 return BeginFrameArgs(frame_time, deadline, interval); | 41 return CreateTyped(frame_time, deadline, interval, BeginFrameArgs::NORMAL); |
30 } | 42 } |
31 | 43 |
32 scoped_refptr<base::debug::ConvertableToTraceFormat> BeginFrameArgs::AsValue() | 44 scoped_refptr<base::debug::ConvertableToTraceFormat> BeginFrameArgs::AsValue() |
33 const { | 45 const { |
34 scoped_refptr<base::debug::TracedValue> state = | 46 scoped_refptr<base::debug::TracedValue> state = |
35 new base::debug::TracedValue(); | 47 new base::debug::TracedValue(); |
36 AsValueInto(state.get()); | 48 AsValueInto(state.get()); |
37 return state; | 49 return state; |
38 } | 50 } |
39 | 51 |
40 void BeginFrameArgs::AsValueInto(base::debug::TracedValue* state) const { | 52 void BeginFrameArgs::AsValueInto(base::debug::TracedValue* state) const { |
41 state->SetString("type", "BeginFrameArgs"); | 53 state->SetString("type", "BeginFrameArgs"); |
| 54 switch (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 } |
42 state->SetDouble("frame_time_us", frame_time.ToInternalValue()); | 68 state->SetDouble("frame_time_us", frame_time.ToInternalValue()); |
43 state->SetDouble("deadline_us", deadline.ToInternalValue()); | 69 state->SetDouble("deadline_us", deadline.ToInternalValue()); |
44 state->SetDouble("interval_us", interval.InMicroseconds()); | 70 state->SetDouble("interval_us", interval.InMicroseconds()); |
45 } | 71 } |
46 | 72 |
47 BeginFrameArgs BeginFrameArgs::CreateForSynchronousCompositor( | 73 BeginFrameArgs BeginFrameArgs::CreateForSynchronousCompositor( |
48 base::TimeTicks now) { | 74 base::TimeTicks now) { |
49 // For WebView/SynchronousCompositor, we always want to draw immediately, | 75 // 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. | 76 // so we set the deadline to 0 and guess that the interval is 16 milliseconds. |
51 if (now.is_null()) | 77 if (now.is_null()) |
52 now = gfx::FrameTime::Now(); | 78 now = gfx::FrameTime::Now(); |
53 return BeginFrameArgs(now, base::TimeTicks(), DefaultInterval()); | 79 return CreateTyped( |
| 80 now, base::TimeTicks(), DefaultInterval(), BeginFrameArgs::SYNCHRONOUS); |
54 } | 81 } |
55 | 82 |
56 // This is a hard-coded deadline adjustment that assumes 60Hz, to be used in | 83 // 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 | 84 // 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 | 85 // 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 | 86 // 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 | 87 // ouput, and the Renderer Main thread the first 1/3 of a frame to produce |
61 // output. | 88 // output. |
62 base::TimeDelta BeginFrameArgs::DefaultEstimatedParentDrawTime() { | 89 base::TimeDelta BeginFrameArgs::DefaultEstimatedParentDrawTime() { |
63 return base::TimeDelta::FromMicroseconds(16666 / 3); | 90 return base::TimeDelta::FromMicroseconds(16666 / 3); |
64 } | 91 } |
65 | 92 |
66 base::TimeDelta BeginFrameArgs::DefaultInterval() { | 93 base::TimeDelta BeginFrameArgs::DefaultInterval() { |
67 return base::TimeDelta::FromMicroseconds(16666); | 94 return base::TimeDelta::FromMicroseconds(16666); |
68 } | 95 } |
69 | 96 |
70 base::TimeDelta BeginFrameArgs::DefaultRetroactiveBeginFramePeriod() { | 97 base::TimeDelta BeginFrameArgs::DefaultRetroactiveBeginFramePeriod() { |
71 return base::TimeDelta::FromMicroseconds(4444); | 98 return base::TimeDelta::FromMicroseconds(4444); |
72 } | 99 } |
73 | 100 |
74 } // namespace cc | 101 } // namespace cc |
OLD | NEW |