OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "ui/events/mojo/latency_info_struct_traits.h" | 5 #include "ui/events/mojo/latency_info_struct_traits.h" |
6 | 6 |
7 #include "ipc/ipc_message_utils.h" | 7 #include "ipc/ipc_message_utils.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 | 10 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // static | 229 // static |
230 bool StructTraits<ui::mojom::LatencyComponentId, | 230 bool StructTraits<ui::mojom::LatencyComponentId, |
231 std::pair<ui::LatencyComponentType, int64_t>>:: | 231 std::pair<ui::LatencyComponentType, int64_t>>:: |
232 Read(ui::mojom::LatencyComponentIdDataView data, | 232 Read(ui::mojom::LatencyComponentIdDataView data, |
233 std::pair<ui::LatencyComponentType, int64_t>* out) { | 233 std::pair<ui::LatencyComponentType, int64_t>* out) { |
234 out->first = MojoLatencyComponentTypeToUI(data.type()); | 234 out->first = MojoLatencyComponentTypeToUI(data.type()); |
235 out->second = data.id(); | 235 out->second = data.id(); |
236 return true; | 236 return true; |
237 } | 237 } |
238 | 238 |
239 void* StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::SetUpContext( | |
240 const ui::LatencyInfo& info) { | |
241 // TODO(fsamuel): It would be nice if we had IterableTraits. | |
242 auto components = new mojo::Array<ui::mojom::LatencyComponentPairPtr>( | |
243 info.latency_components().size()); | |
244 uint32_t i = 0; | |
245 for (ui::LatencyInfo::LatencyMap::const_iterator | |
246 it = info.latency_components().begin(); | |
247 it != info.latency_components().end(); ++it, ++i) { | |
248 auto latency_component_pair = ui::mojom::LatencyComponentPair::New(); | |
249 latency_component_pair->key = it->first; | |
250 latency_component_pair->value = it->second; | |
251 (*components)[i] = std::move(latency_component_pair); | |
252 } | |
253 return components; | |
254 } | |
255 | |
256 void StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::TearDownContext( | |
257 const ui::LatencyInfo& info, | |
258 void* context) { | |
259 // static_cast to ensure destructor is called. | |
260 delete static_cast<mojo::Array<ui::mojom::LatencyComponentPairPtr>*>(context); | |
261 } | |
262 | |
263 // static | 239 // static |
264 const std::string& | 240 const std::string& |
265 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::trace_name( | 241 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::trace_name( |
266 const ui::LatencyInfo& info) { | 242 const ui::LatencyInfo& info) { |
267 return info.trace_name_; | 243 return info.trace_name_; |
268 } | 244 } |
269 | 245 |
270 // static | 246 const ui::LatencyInfo::LatencyMap& |
271 mojo::Array<ui::mojom::LatencyComponentPairPtr>& | |
272 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::latency_components( | 247 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::latency_components( |
273 const ui::LatencyInfo& info, | 248 const ui::LatencyInfo& info) { |
274 void* context) { | 249 return info.latency_components(); |
275 return *static_cast<mojo::Array<ui::mojom::LatencyComponentPairPtr>*>( | |
276 context); | |
277 } | 250 } |
278 | |
279 InputCoordinateArray | 251 InputCoordinateArray |
280 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::input_coordinates( | 252 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::input_coordinates( |
281 const ui::LatencyInfo& info) { | 253 const ui::LatencyInfo& info) { |
282 return {info.input_coordinates_size_, ui::LatencyInfo::kMaxInputCoordinates, | 254 return {info.input_coordinates_size_, ui::LatencyInfo::kMaxInputCoordinates, |
283 const_cast<gfx::PointF*>(info.input_coordinates_)}; | 255 const_cast<gfx::PointF*>(info.input_coordinates_)}; |
284 } | 256 } |
285 | 257 |
286 int64_t StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::trace_id( | 258 int64_t StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::trace_id( |
287 const ui::LatencyInfo& info) { | 259 const ui::LatencyInfo& info) { |
288 return info.trace_id(); | 260 return info.trace_id(); |
289 } | 261 } |
290 | 262 |
291 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::coalesced( | 263 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::coalesced( |
292 const ui::LatencyInfo& info) { | 264 const ui::LatencyInfo& info) { |
293 return info.coalesced(); | 265 return info.coalesced(); |
294 } | 266 } |
295 | 267 |
296 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::terminated( | 268 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::terminated( |
297 const ui::LatencyInfo& info) { | 269 const ui::LatencyInfo& info) { |
298 return info.terminated(); | 270 return info.terminated(); |
299 } | 271 } |
300 | 272 |
301 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::Read( | 273 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::Read( |
302 ui::mojom::LatencyInfoDataView data, | 274 ui::mojom::LatencyInfoDataView data, |
303 ui::LatencyInfo* out) { | 275 ui::LatencyInfo* out) { |
304 if (!data.ReadTraceName(&out->trace_name_)) | 276 if (!data.ReadTraceName(&out->trace_name_)) |
305 return false; | 277 return false; |
306 | 278 |
| 279 // TODO(fsamuel): Figure out how to optimize deserialization. |
307 mojo::Array<ui::mojom::LatencyComponentPairPtr> components; | 280 mojo::Array<ui::mojom::LatencyComponentPairPtr> components; |
308 if (!data.ReadLatencyComponents(&components)) | 281 if (!data.ReadLatencyComponents(&components)) |
309 return false; | 282 return false; |
310 for (uint32_t i = 0; i < components.size(); ++i) | 283 for (uint32_t i = 0; i < components.size(); ++i) |
311 out->latency_components_[components[i]->key] = components[i]->value; | 284 out->latency_components_[components[i]->key] = components[i]->value; |
312 | 285 |
313 InputCoordinateArray input_coordinate_array = { | 286 InputCoordinateArray input_coordinate_array = { |
314 0, ui::LatencyInfo::kMaxInputCoordinates, out->input_coordinates_}; | 287 0, ui::LatencyInfo::kMaxInputCoordinates, out->input_coordinates_}; |
315 if (!data.ReadInputCoordinates(&input_coordinate_array)) | 288 if (!data.ReadInputCoordinates(&input_coordinate_array)) |
316 return false; | 289 return false; |
317 // TODO(fsamuel): ui::LatencyInfo::input_coordinates_size_ should be a size_t. | 290 // TODO(fsamuel): ui::LatencyInfo::input_coordinates_size_ should be a size_t. |
318 out->input_coordinates_size_ = | 291 out->input_coordinates_size_ = |
319 static_cast<uint32_t>(input_coordinate_array.size); | 292 static_cast<uint32_t>(input_coordinate_array.size); |
320 | 293 |
321 out->trace_id_ = data.trace_id(); | 294 out->trace_id_ = data.trace_id(); |
322 out->coalesced_ = data.coalesced(); | 295 out->coalesced_ = data.coalesced(); |
323 out->terminated_ = data.terminated(); | 296 out->terminated_ = data.terminated(); |
324 return true; | 297 return true; |
325 } | 298 } |
326 | 299 |
327 } // namespace mojo | 300 } // namespace mojo |
OLD | NEW |