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/trace_event/trace_event_argument.h" | 7 #include "base/trace_event/trace_event_argument.h" |
8 #include "cc/proto/base_conversions.h" | 8 #include "cc/proto/base_conversions.h" |
9 #include "cc/proto/begin_main_frame_and_commit_state.pb.h" | |
10 | 9 |
11 namespace cc { | 10 namespace cc { |
12 | 11 |
13 const char* BeginFrameArgs::TypeToString(BeginFrameArgsType type) { | 12 const char* BeginFrameArgs::TypeToString(BeginFrameArgsType type) { |
14 switch (type) { | 13 switch (type) { |
15 case BeginFrameArgs::INVALID: | 14 case BeginFrameArgs::INVALID: |
16 return "INVALID"; | 15 return "INVALID"; |
17 case BeginFrameArgs::NORMAL: | 16 case BeginFrameArgs::NORMAL: |
18 return "NORMAL"; | 17 return "NORMAL"; |
19 case BeginFrameArgs::MISSED: | 18 case BeginFrameArgs::MISSED: |
20 return "MISSED"; | 19 return "MISSED"; |
21 case BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX: | 20 case BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX: |
22 return "BEGIN_FRAME_ARGS_TYPE_MAX"; | 21 return "BEGIN_FRAME_ARGS_TYPE_MAX"; |
23 } | 22 } |
24 NOTREACHED(); | 23 NOTREACHED(); |
25 return "???"; | 24 return "???"; |
26 } | 25 } |
27 | 26 |
28 void BeginFrameArgs::BeginFrameArgsTypeToProtobuf( | |
29 proto::BeginFrameArgs* proto) const { | |
30 switch (type) { | |
31 case BeginFrameArgs::INVALID: | |
32 proto->set_type(proto::BeginFrameArgs::INVALID); | |
33 return; | |
34 case BeginFrameArgs::NORMAL: | |
35 proto->set_type(proto::BeginFrameArgs::NORMAL); | |
36 return; | |
37 case BeginFrameArgs::MISSED: | |
38 proto->set_type(proto::BeginFrameArgs::MISSED); | |
39 return; | |
40 case BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX: | |
41 proto->set_type(proto::BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX); | |
42 return; | |
43 } | |
44 NOTREACHED(); | |
45 } | |
46 | |
47 void BeginFrameArgs::BeginFrameArgsTypeFromProtobuf( | |
48 const proto::BeginFrameArgs& proto) { | |
49 switch (proto.type()) { | |
50 case proto::BeginFrameArgs::INVALID: | |
51 type = BeginFrameArgs::INVALID; | |
52 return; | |
53 case proto::BeginFrameArgs::NORMAL: | |
54 type = BeginFrameArgs::NORMAL; | |
55 return; | |
56 case proto::BeginFrameArgs::MISSED: | |
57 type = BeginFrameArgs::MISSED; | |
58 return; | |
59 case proto::BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX: | |
60 type = BeginFrameArgs::BEGIN_FRAME_ARGS_TYPE_MAX; | |
61 return; | |
62 } | |
63 NOTREACHED(); | |
64 } | |
65 | |
66 BeginFrameArgs::BeginFrameArgs() | 27 BeginFrameArgs::BeginFrameArgs() |
67 : frame_time(base::TimeTicks()), | 28 : frame_time(base::TimeTicks()), |
68 deadline(base::TimeTicks()), | 29 deadline(base::TimeTicks()), |
69 interval(base::TimeDelta::FromMicroseconds(-1)), | 30 interval(base::TimeDelta::FromMicroseconds(-1)), |
70 type(BeginFrameArgs::INVALID), | 31 type(BeginFrameArgs::INVALID), |
71 on_critical_path(true) { | 32 on_critical_path(true) { |
72 } | 33 } |
73 | 34 |
74 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time, | 35 BeginFrameArgs::BeginFrameArgs(base::TimeTicks frame_time, |
75 base::TimeTicks deadline, | 36 base::TimeTicks deadline, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 state->SetString("subtype", TypeToString(type)); | 72 state->SetString("subtype", TypeToString(type)); |
112 state->SetDouble("frame_time_us", frame_time.ToInternalValue()); | 73 state->SetDouble("frame_time_us", frame_time.ToInternalValue()); |
113 state->SetDouble("deadline_us", deadline.ToInternalValue()); | 74 state->SetDouble("deadline_us", deadline.ToInternalValue()); |
114 state->SetDouble("interval_us", interval.InMicroseconds()); | 75 state->SetDouble("interval_us", interval.InMicroseconds()); |
115 #ifndef NDEBUG | 76 #ifndef NDEBUG |
116 state->SetString("created_from", created_from.ToString()); | 77 state->SetString("created_from", created_from.ToString()); |
117 #endif | 78 #endif |
118 state->SetBoolean("on_critical_path", on_critical_path); | 79 state->SetBoolean("on_critical_path", on_critical_path); |
119 } | 80 } |
120 | 81 |
121 void BeginFrameArgs::ToProtobuf(proto::BeginFrameArgs* proto) const { | |
122 proto->set_frame_time(TimeTicksToProto(frame_time)); | |
123 proto->set_deadline(TimeTicksToProto(deadline)); | |
124 proto->set_interval(interval.ToInternalValue()); | |
125 BeginFrameArgsTypeToProtobuf(proto); | |
126 proto->set_on_critical_path(on_critical_path); | |
127 } | |
128 | |
129 void BeginFrameArgs::FromProtobuf(const proto::BeginFrameArgs& proto) { | |
130 frame_time = ProtoToTimeTicks(proto.frame_time()); | |
131 deadline = ProtoToTimeTicks(proto.deadline()); | |
132 interval = base::TimeDelta::FromInternalValue(proto.interval()); | |
133 BeginFrameArgsTypeFromProtobuf(proto); | |
134 on_critical_path = proto.on_critical_path(); | |
135 } | |
136 | |
137 // This is a hard-coded deadline adjustment that assumes 60Hz, to be used in | 82 // This is a hard-coded deadline adjustment that assumes 60Hz, to be used in |
138 // cases where a good estimated draw time is not known. Using 1/3 of the vsync | 83 // cases where a good estimated draw time is not known. Using 1/3 of the vsync |
139 // as the default adjustment gives the Browser the last 1/3 of a frame to | 84 // as the default adjustment gives the Browser the last 1/3 of a frame to |
140 // produce output, the Renderer Impl thread the middle 1/3 of a frame to produce | 85 // produce output, the Renderer Impl thread the middle 1/3 of a frame to produce |
141 // ouput, and the Renderer Main thread the first 1/3 of a frame to produce | 86 // ouput, and the Renderer Main thread the first 1/3 of a frame to produce |
142 // output. | 87 // output. |
143 base::TimeDelta BeginFrameArgs::DefaultEstimatedParentDrawTime() { | 88 base::TimeDelta BeginFrameArgs::DefaultEstimatedParentDrawTime() { |
144 return base::TimeDelta::FromMicroseconds(16666 / 3); | 89 return base::TimeDelta::FromMicroseconds(16666 / 3); |
145 } | 90 } |
146 | 91 |
147 base::TimeDelta BeginFrameArgs::DefaultInterval() { | 92 base::TimeDelta BeginFrameArgs::DefaultInterval() { |
148 return base::TimeDelta::FromMicroseconds(16666); | 93 return base::TimeDelta::FromMicroseconds(16666); |
149 } | 94 } |
150 | 95 |
151 } // namespace cc | 96 } // namespace cc |
OLD | NEW |