| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT: | 172 INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT: |
| 173 return ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT; | 173 return ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT; |
| 174 } | 174 } |
| 175 NOTREACHED(); | 175 NOTREACHED(); |
| 176 return ui::LATENCY_COMPONENT_TYPE_LAST; | 176 return ui::LATENCY_COMPONENT_TYPE_LAST; |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace | 179 } // namespace |
| 180 | 180 |
| 181 // static | 181 // static |
| 182 int64_t | 182 int64_t StructTraits<ui::mojom::LatencyComponentDataView, |
| 183 StructTraits<ui::mojom::LatencyComponent, ui::LatencyInfo::LatencyComponent>:: | 183 ui::LatencyInfo::LatencyComponent>:: |
| 184 sequence_number(const ui::LatencyInfo::LatencyComponent& component) { | 184 sequence_number(const ui::LatencyInfo::LatencyComponent& component) { |
| 185 return component.sequence_number; | 185 return component.sequence_number; |
| 186 } | 186 } |
| 187 | 187 |
| 188 // static | 188 // static |
| 189 base::TimeTicks | 189 base::TimeTicks StructTraits<ui::mojom::LatencyComponentDataView, |
| 190 StructTraits<ui::mojom::LatencyComponent, ui::LatencyInfo::LatencyComponent>:: | 190 ui::LatencyInfo::LatencyComponent>:: |
| 191 event_time(const ui::LatencyInfo::LatencyComponent& component) { | 191 event_time(const ui::LatencyInfo::LatencyComponent& component) { |
| 192 return component.event_time; | 192 return component.event_time; |
| 193 } | 193 } |
| 194 | 194 |
| 195 // static | 195 // static |
| 196 uint32_t | 196 uint32_t StructTraits<ui::mojom::LatencyComponentDataView, |
| 197 StructTraits<ui::mojom::LatencyComponent, ui::LatencyInfo::LatencyComponent>:: | 197 ui::LatencyInfo::LatencyComponent>:: |
| 198 event_count(const ui::LatencyInfo::LatencyComponent& component) { | 198 event_count(const ui::LatencyInfo::LatencyComponent& component) { |
| 199 return component.event_count; | 199 return component.event_count; |
| 200 } | 200 } |
| 201 | 201 |
| 202 // static | 202 // static |
| 203 bool StructTraits<ui::mojom::LatencyComponent, | 203 bool StructTraits<ui::mojom::LatencyComponentDataView, |
| 204 ui::LatencyInfo::LatencyComponent>:: | 204 ui::LatencyInfo::LatencyComponent>:: |
| 205 Read(ui::mojom::LatencyComponentDataView data, | 205 Read(ui::mojom::LatencyComponentDataView data, |
| 206 ui::LatencyInfo::LatencyComponent* out) { | 206 ui::LatencyInfo::LatencyComponent* out) { |
| 207 if (!data.ReadEventTime(&out->event_time)) | 207 if (!data.ReadEventTime(&out->event_time)) |
| 208 return false; | 208 return false; |
| 209 out->sequence_number = data.sequence_number(); | 209 out->sequence_number = data.sequence_number(); |
| 210 out->event_count = data.event_count(); | 210 out->event_count = data.event_count(); |
| 211 return true; | 211 return true; |
| 212 } | 212 } |
| 213 | 213 |
| 214 // static | 214 // static |
| 215 ui::mojom::LatencyComponentType | 215 ui::mojom::LatencyComponentType |
| 216 StructTraits<ui::mojom::LatencyComponentId, | 216 StructTraits<ui::mojom::LatencyComponentIdDataView, |
| 217 std::pair<ui::LatencyComponentType, int64_t>>:: | 217 std::pair<ui::LatencyComponentType, int64_t>>:: |
| 218 type(const std::pair<ui::LatencyComponentType, int64_t>& id) { | 218 type(const std::pair<ui::LatencyComponentType, int64_t>& id) { |
| 219 return UILatencyComponentTypeToMojo(id.first); | 219 return UILatencyComponentTypeToMojo(id.first); |
| 220 } | 220 } |
| 221 | 221 |
| 222 // static | 222 // static |
| 223 int64_t StructTraits<ui::mojom::LatencyComponentId, | 223 int64_t StructTraits<ui::mojom::LatencyComponentIdDataView, |
| 224 std::pair<ui::LatencyComponentType, int64_t>>:: | 224 std::pair<ui::LatencyComponentType, int64_t>>:: |
| 225 id(const std::pair<ui::LatencyComponentType, int64_t>& id) { | 225 id(const std::pair<ui::LatencyComponentType, int64_t>& id) { |
| 226 return id.second; | 226 return id.second; |
| 227 } | 227 } |
| 228 | 228 |
| 229 // static | 229 // static |
| 230 bool StructTraits<ui::mojom::LatencyComponentId, | 230 bool StructTraits<ui::mojom::LatencyComponentIdDataView, |
| 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 // static | 239 // static |
| 240 const std::string& | 240 const std::string& |
| 241 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::trace_name( | 241 StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::trace_name( |
| 242 const ui::LatencyInfo& info) { | 242 const ui::LatencyInfo& info) { |
| 243 return info.trace_name_; | 243 return info.trace_name_; |
| 244 } | 244 } |
| 245 | 245 |
| 246 const ui::LatencyInfo::LatencyMap& | 246 const ui::LatencyInfo::LatencyMap& |
| 247 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::latency_components( | 247 StructTraits<ui::mojom::LatencyInfoDataView, |
| 248 const ui::LatencyInfo& info) { | 248 ui::LatencyInfo>::latency_components(const ui::LatencyInfo& info) { |
| 249 return info.latency_components(); | 249 return info.latency_components(); |
| 250 } | 250 } |
| 251 InputCoordinateArray | 251 InputCoordinateArray |
| 252 StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::input_coordinates( | 252 StructTraits<ui::mojom::LatencyInfoDataView, |
| 253 const ui::LatencyInfo& info) { | 253 ui::LatencyInfo>::input_coordinates(const ui::LatencyInfo& info) { |
| 254 return {info.input_coordinates_size_, ui::LatencyInfo::kMaxInputCoordinates, | 254 return {info.input_coordinates_size_, ui::LatencyInfo::kMaxInputCoordinates, |
| 255 const_cast<gfx::PointF*>(info.input_coordinates_)}; | 255 const_cast<gfx::PointF*>(info.input_coordinates_)}; |
| 256 } | 256 } |
| 257 | 257 |
| 258 int64_t StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::trace_id( | 258 int64_t StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::trace_id( |
| 259 const ui::LatencyInfo& info) { | 259 const ui::LatencyInfo& info) { |
| 260 return info.trace_id(); | 260 return info.trace_id(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::coalesced( | 263 bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::coalesced( |
| 264 const ui::LatencyInfo& info) { | 264 const ui::LatencyInfo& info) { |
| 265 return info.coalesced(); | 265 return info.coalesced(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::terminated( | 268 bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::terminated( |
| 269 const ui::LatencyInfo& info) { | 269 const ui::LatencyInfo& info) { |
| 270 return info.terminated(); | 270 return info.terminated(); |
| 271 } | 271 } |
| 272 | 272 |
| 273 bool StructTraits<ui::mojom::LatencyInfo, ui::LatencyInfo>::Read( | 273 bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::Read( |
| 274 ui::mojom::LatencyInfoDataView data, | 274 ui::mojom::LatencyInfoDataView data, |
| 275 ui::LatencyInfo* out) { | 275 ui::LatencyInfo* out) { |
| 276 if (!data.ReadTraceName(&out->trace_name_)) | 276 if (!data.ReadTraceName(&out->trace_name_)) |
| 277 return false; | 277 return false; |
| 278 | 278 |
| 279 // TODO(fsamuel): Figure out how to optimize deserialization. | 279 // TODO(fsamuel): Figure out how to optimize deserialization. |
| 280 mojo::Array<ui::mojom::LatencyComponentPairPtr> components; | 280 mojo::Array<ui::mojom::LatencyComponentPairPtr> components; |
| 281 if (!data.ReadLatencyComponents(&components)) | 281 if (!data.ReadLatencyComponents(&components)) |
| 282 return false; | 282 return false; |
| 283 for (uint32_t i = 0; i < components.size(); ++i) | 283 for (uint32_t i = 0; i < components.size(); ++i) |
| 284 out->latency_components_[components[i]->key] = components[i]->value; | 284 out->latency_components_[components[i]->key] = components[i]->value; |
| 285 | 285 |
| 286 InputCoordinateArray input_coordinate_array = { | 286 InputCoordinateArray input_coordinate_array = { |
| 287 0, ui::LatencyInfo::kMaxInputCoordinates, out->input_coordinates_}; | 287 0, ui::LatencyInfo::kMaxInputCoordinates, out->input_coordinates_}; |
| 288 if (!data.ReadInputCoordinates(&input_coordinate_array)) | 288 if (!data.ReadInputCoordinates(&input_coordinate_array)) |
| 289 return false; | 289 return false; |
| 290 // 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. |
| 291 out->input_coordinates_size_ = | 291 out->input_coordinates_size_ = |
| 292 static_cast<uint32_t>(input_coordinate_array.size); | 292 static_cast<uint32_t>(input_coordinate_array.size); |
| 293 | 293 |
| 294 out->trace_id_ = data.trace_id(); | 294 out->trace_id_ = data.trace_id(); |
| 295 out->coalesced_ = data.coalesced(); | 295 out->coalesced_ = data.coalesced(); |
| 296 out->terminated_ = data.terminated(); | 296 out->terminated_ = data.terminated(); |
| 297 return true; | 297 return true; |
| 298 } | 298 } |
| 299 | 299 |
| 300 } // namespace mojo | 300 } // namespace mojo |
| OLD | NEW |