Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: ui/events/mojo/latency_info_struct_traits.cc

Issue 2783973002: Moving LatencyInfo into a separate component. (Closed)
Patch Set: Rebase again Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/mojo/latency_info_struct_traits.h ('k') | ui/events/mojo/struct_traits_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 "ui/events/mojo/latency_info_struct_traits.h"
6
7 #include "ipc/ipc_message_utils.h"
8
9 namespace mojo {
10
11 namespace {
12
13 ui::mojom::LatencyComponentType UILatencyComponentTypeToMojo(
14 ui::LatencyComponentType type) {
15 switch (type) {
16 case ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT:
17 return ui::mojom::LatencyComponentType::
18 INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT;
19 case ui::LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT:
20 return ui::mojom::LatencyComponentType::
21 LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT;
22 case ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT:
23 return ui::mojom::LatencyComponentType::
24 INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT;
25 case ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT:
26 return ui::mojom::LatencyComponentType::
27 INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT;
28 case ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT:
29 return ui::mojom::LatencyComponentType::
30 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT;
31 case ui::INPUT_EVENT_LATENCY_UI_COMPONENT:
32 return ui::mojom::LatencyComponentType::INPUT_EVENT_LATENCY_UI_COMPONENT;
33 case ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT:
34 return ui::mojom::LatencyComponentType::
35 INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT;
36 case ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT:
37 return ui::mojom::LatencyComponentType::
38 INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT;
39 case ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT:
40 return ui::mojom::LatencyComponentType::
41 INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT;
42 case ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT:
43 return ui::mojom::LatencyComponentType::
44 INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT;
45 case ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT:
46 return ui::mojom::LatencyComponentType::
47 INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT;
48 case ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT:
49 return ui::mojom::LatencyComponentType::
50 WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT;
51 case ui::TAB_SHOW_COMPONENT:
52 return ui::mojom::LatencyComponentType::TAB_SHOW_COMPONENT;
53 case ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT:
54 return ui::mojom::LatencyComponentType::
55 INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT;
56 case ui::INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT:
57 return ui::mojom::LatencyComponentType::
58 INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT;
59 case ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT:
60 return ui::mojom::LatencyComponentType::
61 INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT;
62 case ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL:
63 return ui::mojom::LatencyComponentType::
64 INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL;
65 case ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT:
66 return ui::mojom::LatencyComponentType::
67 INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT;
68 case ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT:
69 return ui::mojom::LatencyComponentType::
70 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT;
71 case ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT:
72 return ui::mojom::LatencyComponentType::
73 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT;
74 case ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT:
75 return ui::mojom::LatencyComponentType::
76 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT;
77 case ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT:
78 return ui::mojom::LatencyComponentType::
79 INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT;
80 }
81 NOTREACHED();
82 return ui::mojom::LatencyComponentType::LATENCY_COMPONENT_TYPE_LAST;
83 }
84
85 ui::LatencyComponentType MojoLatencyComponentTypeToUI(
86 ui::mojom::LatencyComponentType type) {
87 switch (type) {
88 case ui::mojom::LatencyComponentType::
89 INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT:
90 return ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT;
91 case ui::mojom::LatencyComponentType::
92 LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT:
93 return ui::LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT;
94 case ui::mojom::LatencyComponentType::
95 INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT:
96 return ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT;
97 case ui::mojom::LatencyComponentType::
98 INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT:
99 return ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT;
100 case ui::mojom::LatencyComponentType::
101 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT:
102 return ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT;
103 case ui::mojom::LatencyComponentType::INPUT_EVENT_LATENCY_UI_COMPONENT:
104 return ui::INPUT_EVENT_LATENCY_UI_COMPONENT;
105 case ui::mojom::LatencyComponentType::
106 INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT:
107 return ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT;
108 case ui::mojom::LatencyComponentType::
109 INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT:
110 return ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT;
111 case ui::mojom::LatencyComponentType::
112 INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT:
113 return ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT;
114 case ui::mojom::LatencyComponentType::
115 INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT:
116 return ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT;
117 case ui::mojom::LatencyComponentType::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT:
118 return ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT;
119 case ui::mojom::LatencyComponentType::
120 WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT:
121 return ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT;
122 case ui::mojom::LatencyComponentType::TAB_SHOW_COMPONENT:
123 return ui::TAB_SHOW_COMPONENT;
124 case ui::mojom::LatencyComponentType::
125 INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT:
126 return ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT;
127 case ui::mojom::LatencyComponentType::
128 INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT:
129 return ui::INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT;
130 case ui::mojom::LatencyComponentType::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT:
131 return ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT;
132 case ui::mojom::LatencyComponentType::
133 INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL:
134 return ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL;
135 case ui::mojom::LatencyComponentType::
136 INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT:
137 return ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT;
138 case ui::mojom::LatencyComponentType::
139 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT:
140 return ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT;
141 case ui::mojom::LatencyComponentType::
142 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT:
143 return ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT;
144 case ui::mojom::LatencyComponentType::
145 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT:
146 return ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT;
147 case ui::mojom::LatencyComponentType::
148 INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT:
149 return ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT;
150 }
151 NOTREACHED();
152 return ui::LATENCY_COMPONENT_TYPE_LAST;
153 }
154
155 } // namespace
156
157 // static
158 int64_t StructTraits<ui::mojom::LatencyComponentDataView,
159 ui::LatencyInfo::LatencyComponent>::
160 sequence_number(const ui::LatencyInfo::LatencyComponent& component) {
161 return component.sequence_number;
162 }
163
164 // static
165 base::TimeTicks StructTraits<ui::mojom::LatencyComponentDataView,
166 ui::LatencyInfo::LatencyComponent>::
167 event_time(const ui::LatencyInfo::LatencyComponent& component) {
168 return component.event_time;
169 }
170
171 // static
172 uint32_t StructTraits<ui::mojom::LatencyComponentDataView,
173 ui::LatencyInfo::LatencyComponent>::
174 event_count(const ui::LatencyInfo::LatencyComponent& component) {
175 return component.event_count;
176 }
177
178 // static
179 base::TimeTicks StructTraits<ui::mojom::LatencyComponentDataView,
180 ui::LatencyInfo::LatencyComponent>::
181 first_event_time(const ui::LatencyInfo::LatencyComponent& component) {
182 return component.first_event_time;
183 }
184
185 // static
186 base::TimeTicks StructTraits<ui::mojom::LatencyComponentDataView,
187 ui::LatencyInfo::LatencyComponent>::
188 last_event_time(const ui::LatencyInfo::LatencyComponent& component) {
189 return component.last_event_time;
190 }
191
192 // static
193 bool StructTraits<ui::mojom::LatencyComponentDataView,
194 ui::LatencyInfo::LatencyComponent>::
195 Read(ui::mojom::LatencyComponentDataView data,
196 ui::LatencyInfo::LatencyComponent* out) {
197 if (!data.ReadEventTime(&out->event_time))
198 return false;
199 if (!data.ReadFirstEventTime(&out->first_event_time))
200 return false;
201 if (!data.ReadLastEventTime(&out->last_event_time))
202 return false;
203 out->sequence_number = data.sequence_number();
204 out->event_count = data.event_count();
205 return true;
206 }
207
208 // static
209 ui::mojom::LatencyComponentType
210 StructTraits<ui::mojom::LatencyComponentIdDataView,
211 std::pair<ui::LatencyComponentType, int64_t>>::
212 type(const std::pair<ui::LatencyComponentType, int64_t>& id) {
213 return UILatencyComponentTypeToMojo(id.first);
214 }
215
216 // static
217 int64_t StructTraits<ui::mojom::LatencyComponentIdDataView,
218 std::pair<ui::LatencyComponentType, int64_t>>::
219 id(const std::pair<ui::LatencyComponentType, int64_t>& id) {
220 return id.second;
221 }
222
223 // static
224 bool StructTraits<ui::mojom::LatencyComponentIdDataView,
225 std::pair<ui::LatencyComponentType, int64_t>>::
226 Read(ui::mojom::LatencyComponentIdDataView data,
227 std::pair<ui::LatencyComponentType, int64_t>* out) {
228 out->first = MojoLatencyComponentTypeToUI(data.type());
229 out->second = data.id();
230 return true;
231 }
232
233 // static
234 const std::string&
235 StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::trace_name(
236 const ui::LatencyInfo& info) {
237 return info.trace_name_;
238 }
239
240 const ui::LatencyInfo::LatencyMap&
241 StructTraits<ui::mojom::LatencyInfoDataView,
242 ui::LatencyInfo>::latency_components(const ui::LatencyInfo& info) {
243 return info.latency_components();
244 }
245 InputCoordinateArray
246 StructTraits<ui::mojom::LatencyInfoDataView,
247 ui::LatencyInfo>::input_coordinates(const ui::LatencyInfo& info) {
248 return {info.input_coordinates_size_, ui::LatencyInfo::kMaxInputCoordinates,
249 const_cast<gfx::PointF*>(info.input_coordinates_)};
250 }
251
252 int64_t StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::trace_id(
253 const ui::LatencyInfo& info) {
254 return info.trace_id();
255 }
256
257 bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::coalesced(
258 const ui::LatencyInfo& info) {
259 return info.coalesced();
260 }
261
262 bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::terminated(
263 const ui::LatencyInfo& info) {
264 return info.terminated();
265 }
266
267 bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::Read(
268 ui::mojom::LatencyInfoDataView data,
269 ui::LatencyInfo* out) {
270 if (!data.ReadTraceName(&out->trace_name_))
271 return false;
272
273 mojo::ArrayDataView<ui::mojom::LatencyComponentPairDataView> components;
274 data.GetLatencyComponentsDataView(&components);
275 for (uint32_t i = 0; i < components.size(); ++i) {
276 ui::mojom::LatencyComponentPairDataView component_pair;
277 components.GetDataView(i, &component_pair);
278 ui::LatencyInfo::LatencyMap::key_type key;
279 if (!component_pair.ReadKey(&key))
280 return false;
281 auto& value = out->latency_components_[key];
282 if (!component_pair.ReadValue(&value))
283 return false;
284 }
285
286 InputCoordinateArray input_coordinate_array = {
287 0, ui::LatencyInfo::kMaxInputCoordinates, out->input_coordinates_};
288 if (!data.ReadInputCoordinates(&input_coordinate_array))
289 return false;
290 // TODO(fsamuel): ui::LatencyInfo::input_coordinates_size_ should be a size_t.
291 out->input_coordinates_size_ =
292 static_cast<uint32_t>(input_coordinate_array.size);
293
294 out->trace_id_ = data.trace_id();
295 out->coalesced_ = data.coalesced();
296 out->terminated_ = data.terminated();
297 return true;
298 }
299
300 } // namespace mojo
OLDNEW
« no previous file with comments | « ui/events/mojo/latency_info_struct_traits.h ('k') | ui/events/mojo/struct_traits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698