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

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

Issue 2040733002: Implement LatencyInfo StructTraits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make Windows happier Created 4 years, 6 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_MOUSE_COMPONENT:
66 return ui::mojom::LatencyComponentType::
67 INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT;
68 case ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_WHEEL_COMPONENT:
69 return ui::mojom::LatencyComponentType::
70 INPUT_EVENT_LATENCY_TERMINATED_MOUSE_WHEEL_COMPONENT;
71 case ui::INPUT_EVENT_LATENCY_TERMINATED_KEYBOARD_COMPONENT:
72 return ui::mojom::LatencyComponentType::
73 INPUT_EVENT_LATENCY_TERMINATED_KEYBOARD_COMPONENT;
74 case ui::INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT:
75 return ui::mojom::LatencyComponentType::
76 INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT;
77 case ui::INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT:
78 return ui::mojom::LatencyComponentType::
79 INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT;
80 case ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT:
81 return ui::mojom::LatencyComponentType::
82 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT;
83 case ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT:
84 return ui::mojom::LatencyComponentType::
85 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT;
86 case ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT:
87 return ui::mojom::LatencyComponentType::
88 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT;
89 case ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT:
90 return ui::mojom::LatencyComponentType::
91 INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT;
92 }
93 NOTREACHED();
94 return ui::mojom::LatencyComponentType::LATENCY_COMPONENT_TYPE_LAST;
95 }
96
97 ui::LatencyComponentType MojoLatencyComponentTypeToUI(
98 ui::mojom::LatencyComponentType type) {
99 switch (type) {
100 case ui::mojom::LatencyComponentType::
101 INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT:
102 return ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT;
103 case ui::mojom::LatencyComponentType::
104 LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT:
105 return ui::LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT;
106 case ui::mojom::LatencyComponentType::
107 INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT:
108 return ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT;
109 case ui::mojom::LatencyComponentType::
110 INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT:
111 return ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT;
112 case ui::mojom::LatencyComponentType::
113 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT:
114 return ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT;
115 case ui::mojom::LatencyComponentType::INPUT_EVENT_LATENCY_UI_COMPONENT:
116 return ui::INPUT_EVENT_LATENCY_UI_COMPONENT;
117 case ui::mojom::LatencyComponentType::
118 INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT:
119 return ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT;
120 case ui::mojom::LatencyComponentType::
121 INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT:
122 return ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT;
123 case ui::mojom::LatencyComponentType::
124 INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT:
125 return ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT;
126 case ui::mojom::LatencyComponentType::
127 INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT:
128 return ui::INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT;
129 case ui::mojom::LatencyComponentType::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT:
130 return ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT;
131 case ui::mojom::LatencyComponentType::
132 WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT:
133 return ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT;
134 case ui::mojom::LatencyComponentType::TAB_SHOW_COMPONENT:
135 return ui::TAB_SHOW_COMPONENT;
136 case ui::mojom::LatencyComponentType::
137 INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT:
138 return ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT;
139 case ui::mojom::LatencyComponentType::
140 INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT:
141 return ui::INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT;
142 case ui::mojom::LatencyComponentType::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT:
143 return ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT;
144 case ui::mojom::LatencyComponentType::
145 INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL:
146 return ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL;
147 case ui::mojom::LatencyComponentType::
148 INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT:
149 return ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT;
150 case ui::mojom::LatencyComponentType::
151 INPUT_EVENT_LATENCY_TERMINATED_MOUSE_WHEEL_COMPONENT:
152 return ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_WHEEL_COMPONENT;
153 case ui::mojom::LatencyComponentType::
154 INPUT_EVENT_LATENCY_TERMINATED_KEYBOARD_COMPONENT:
155 return ui::INPUT_EVENT_LATENCY_TERMINATED_KEYBOARD_COMPONENT;
156 case ui::mojom::LatencyComponentType::
157 INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT:
158 return ui::INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT;
159 case ui::mojom::LatencyComponentType::
160 INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT:
161 return ui::INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT;
162 case ui::mojom::LatencyComponentType::
163 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT:
164 return ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT;
165 case ui::mojom::LatencyComponentType::
166 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT:
167 return ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT;
168 case ui::mojom::LatencyComponentType::
169 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT:
170 return ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT;
171 case ui::mojom::LatencyComponentType::
172 INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT:
173 return ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT;
174 }
175 NOTREACHED();
176 return ui::LATENCY_COMPONENT_TYPE_LAST;
177 }
178
179 } // namespace
180
181 // static
182 size_t ArrayTraits<InputCoordinateArray>::GetSize(
183 const InputCoordinateArray& b) {
184 return b.size;
185 }
186
187 // static
188 ui::LatencyInfo::InputCoordinate* ArrayTraits<InputCoordinateArray>::GetData(
189 InputCoordinateArray& b) {
190 return b.data;
191 }
192
193 // static
194 const ui::LatencyInfo::InputCoordinate*
195 ArrayTraits<InputCoordinateArray>::GetData(const InputCoordinateArray& b) {
196 return b.data;
197 }
198
199 // static
200 ui::LatencyInfo::InputCoordinate& ArrayTraits<InputCoordinateArray>::GetAt(
201 InputCoordinateArray& b,
202 size_t i) {
203 return b.data[i];
204 }
205
206 // static
207 const ui::LatencyInfo::InputCoordinate&
208 ArrayTraits<InputCoordinateArray>::GetAt(const InputCoordinateArray& b,
209 size_t i) {
210 return b.data[i];
211 }
212
213 // static
214 void ArrayTraits<InputCoordinateArray>::Resize(InputCoordinateArray& b,
215 size_t size) {
216 // TODO(fsamuel): We should update ArrayTraits<T>::Resize to return a bool.
217 CHECK_LE(size, ui::LatencyInfo::kMaxInputCoordinates);
218 b.size = size;
219 }
220
221 // static
222 int64_t
223 StructTraits<ui::mojom::LatencyComponent, ui::LatencyInfo::LatencyComponent>::
224 sequence_number(const ui::LatencyInfo::LatencyComponent& component) {
225 return component.sequence_number;
226 }
227
228 // static
229 base::TimeTicks
230 StructTraits<ui::mojom::LatencyComponent, ui::LatencyInfo::LatencyComponent>::
231 event_time(const ui::LatencyInfo::LatencyComponent& component) {
232 return component.event_time;
233 }
234
235 // static
236 uint32_t
237 StructTraits<ui::mojom::LatencyComponent, ui::LatencyInfo::LatencyComponent>::
238 event_count(const ui::LatencyInfo::LatencyComponent& component) {
239 return component.event_count;
240 }
241
242 // static
243 bool StructTraits<ui::mojom::LatencyComponent,
244 ui::LatencyInfo::LatencyComponent>::
245 Read(ui::mojom::LatencyComponentDataView data,
246 ui::LatencyInfo::LatencyComponent* out) {
247 if (!data.ReadEventTime(&out->event_time))
248 return false;
249 out->sequence_number = data.sequence_number();
250 out->event_count = data.event_count();
251 return true;
252 }
253
254 // static
255 ui::mojom::LatencyComponentType
256 StructTraits<ui::mojom::LatencyComponentId,
257 std::pair<ui::LatencyComponentType, int64_t>>::
258 type(const std::pair<ui::LatencyComponentType, int64_t>& id) {
259 return UILatencyComponentTypeToMojo(id.first);
260 }
261
262 // static
263 int64_t StructTraits<ui::mojom::LatencyComponentId,
264 std::pair<ui::LatencyComponentType, int64_t>>::
265 id(const std::pair<ui::LatencyComponentType, int64_t>& id) {
266 return id.second;
267 }
268
269 // static
270 bool StructTraits<ui::mojom::LatencyComponentId,
271 std::pair<ui::LatencyComponentType, int64_t>>::
272 Read(ui::mojom::LatencyComponentIdDataView data,
273 std::pair<ui::LatencyComponentType, int64_t>* out) {
274 out->first = MojoLatencyComponentTypeToUI(data.type());
275 out->second = data.id();
276 return true;
277 }
278
279 void* StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::SetUpContext(
280 const ui::LatencyInfo& info) {
281 // TODO(fsamuel): It would be nice if we had IterableTraits.
282 auto components = new mojo::Array<ui::mojom::LatencyComponentPairPtr>(
283 info.latency_components().size());
284 uint32_t i = 0;
285 for (ui::LatencyInfo::LatencyMap::const_iterator
286 it = info.latency_components().begin();
287 it != info.latency_components().end(); ++it, ++i) {
288 auto latency_component_pair = ui::mojom::LatencyComponentPair::New();
289 latency_component_pair->key = it->first;
290 latency_component_pair->value = it->second;
291 (*components)[i] = std::move(latency_component_pair);
292 }
293 return components;
294 }
295
296 void StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::TearDownContext(
297 const ui::LatencyInfo& info,
298 void* context) {
299 // static_cast to ensure destructor is called.
300 delete static_cast<mojo::Array<ui::mojom::LatencyComponentPairPtr>*>(context);
301 }
302
303 // static
304 const std::string&
305 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::trace_name(
306 const ui::LatencyInfo& info) {
307 return info.trace_name_;
308 }
309
310 // static
311 mojo::Array<ui::mojom::LatencyComponentPairPtr>&
312 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::latency_components(
313 const ui::LatencyInfo& info,
314 void* context) {
315 return *static_cast<mojo::Array<ui::mojom::LatencyComponentPairPtr>*>(
316 context);
317 }
318
319 InputCoordinateArray
320 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::input_coordinates(
321 const ui::LatencyInfo& info) {
322 InputCoordinateArray input_coordinates_array = {
323 ui::LatencyInfo::kMaxInputCoordinates,
324 const_cast<ui::LatencyInfo::InputCoordinate*>(info.input_coordinates_)};
325 return input_coordinates_array;
326 }
327
328 int64_t StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::trace_id(
329 const ui::LatencyInfo& info) {
330 return info.trace_id();
331 }
332
333 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::coalesced(
334 const ui::LatencyInfo& info) {
335 return info.coalesced();
336 }
337
338 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::terminated(
339 const ui::LatencyInfo& info) {
340 return info.terminated();
341 }
342
343 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::Read(
344 ui::mojom::LatencyInfoDataView data,
345 ui::LatencyInfo* out) {
346 if (!data.ReadTraceName(&out->trace_name_))
347 return false;
348
349 mojo::Array<ui::mojom::LatencyComponentPairPtr> components;
350 if (!data.ReadLatencyComponents(&components))
351 return false;
352 for (uint32_t i = 0; i < components.size(); ++i)
353 out->latency_components_[components[i]->key] = components[i]->value;
354
355 InputCoordinateArray input_coordinate_array = {
356 ui::LatencyInfo::kMaxInputCoordinates, out->input_coordinates_};
357 if (!data.ReadInputCoordinates(&input_coordinate_array))
358 return false;
359 // TODO(fsamuel): ui::LatencyInfo::input_coordinates_size_ should be a size_t.
360 out->input_coordinates_size_ =
361 static_cast<uint32_t>(input_coordinate_array.size);
362
363 out->trace_id_ = data.trace_id();
364 out->coalesced_ = data.coalesced();
365 out->terminated_ = data.terminated();
366 return true;
367 }
368
369 } // 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