latency_info_mojom_traits.cc 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. #include "ui/latency/mojom/latency_info_mojom_traits.h"
  5. #include "mojo/public/cpp/base/time_mojom_traits.h"
  6. namespace mojo {
  7. namespace {
  8. ui::mojom::SourceEventType UISourceEventTypeToMojo(ui::SourceEventType type) {
  9. switch (type) {
  10. case ui::SourceEventType::UNKNOWN:
  11. return ui::mojom::SourceEventType::UNKNOWN;
  12. case ui::SourceEventType::WHEEL:
  13. return ui::mojom::SourceEventType::WHEEL;
  14. case ui::SourceEventType::MOUSE:
  15. return ui::mojom::SourceEventType::MOUSE;
  16. case ui::SourceEventType::TOUCH:
  17. return ui::mojom::SourceEventType::TOUCH;
  18. case ui::SourceEventType::INERTIAL:
  19. return ui::mojom::SourceEventType::INERTIAL;
  20. case ui::SourceEventType::KEY_PRESS:
  21. return ui::mojom::SourceEventType::KEY_PRESS;
  22. case ui::SourceEventType::TOUCHPAD:
  23. return ui::mojom::SourceEventType::TOUCHPAD;
  24. case ui::SourceEventType::SCROLLBAR:
  25. return ui::mojom::SourceEventType::SCROLLBAR;
  26. case ui::SourceEventType::OTHER:
  27. return ui::mojom::SourceEventType::OTHER;
  28. }
  29. NOTREACHED();
  30. return ui::mojom::SourceEventType::UNKNOWN;
  31. }
  32. ui::SourceEventType MojoSourceEventTypeToUI(ui::mojom::SourceEventType type) {
  33. switch (type) {
  34. case ui::mojom::SourceEventType::UNKNOWN:
  35. return ui::SourceEventType::UNKNOWN;
  36. case ui::mojom::SourceEventType::WHEEL:
  37. return ui::SourceEventType::WHEEL;
  38. case ui::mojom::SourceEventType::MOUSE:
  39. return ui::SourceEventType::MOUSE;
  40. case ui::mojom::SourceEventType::TOUCH:
  41. return ui::SourceEventType::TOUCH;
  42. case ui::mojom::SourceEventType::INERTIAL:
  43. return ui::SourceEventType::INERTIAL;
  44. case ui::mojom::SourceEventType::KEY_PRESS:
  45. return ui::SourceEventType::KEY_PRESS;
  46. case ui::mojom::SourceEventType::TOUCHPAD:
  47. return ui::SourceEventType::TOUCHPAD;
  48. case ui::mojom::SourceEventType::SCROLLBAR:
  49. return ui::SourceEventType::SCROLLBAR;
  50. case ui::mojom::SourceEventType::OTHER:
  51. return ui::SourceEventType::OTHER;
  52. }
  53. NOTREACHED();
  54. return ui::SourceEventType::UNKNOWN;
  55. }
  56. } // namespace
  57. // static
  58. const ui::LatencyInfo::LatencyMap&
  59. StructTraits<ui::mojom::LatencyInfoDataView,
  60. ui::LatencyInfo>::latency_components(const ui::LatencyInfo& info) {
  61. return info.latency_components();
  62. }
  63. // static
  64. int64_t StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::trace_id(
  65. const ui::LatencyInfo& info) {
  66. return info.trace_id();
  67. }
  68. // static
  69. ukm::SourceId
  70. StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::ukm_source_id(
  71. const ui::LatencyInfo& info) {
  72. return info.ukm_source_id();
  73. }
  74. // static
  75. bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::coalesced(
  76. const ui::LatencyInfo& info) {
  77. return info.coalesced();
  78. }
  79. // static
  80. bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::began(
  81. const ui::LatencyInfo& info) {
  82. return info.began();
  83. }
  84. // static
  85. bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::terminated(
  86. const ui::LatencyInfo& info) {
  87. return info.terminated();
  88. }
  89. // static
  90. ui::mojom::SourceEventType
  91. StructTraits<ui::mojom::LatencyInfoDataView,
  92. ui::LatencyInfo>::source_event_type(const ui::LatencyInfo& info) {
  93. return UISourceEventTypeToMojo(info.source_event_type());
  94. }
  95. // static
  96. int64_t
  97. StructTraits<ui::mojom::LatencyInfoDataView,
  98. ui::LatencyInfo>::gesture_scroll_id(const ui::LatencyInfo& info) {
  99. return info.gesture_scroll_id();
  100. }
  101. // static
  102. int64_t
  103. StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::touch_trace_id(
  104. const ui::LatencyInfo& info) {
  105. return info.touch_trace_id();
  106. }
  107. // static
  108. bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::Read(
  109. ui::mojom::LatencyInfoDataView data,
  110. ui::LatencyInfo* out) {
  111. if (!data.ReadLatencyComponents(&out->latency_components_))
  112. return false;
  113. out->trace_id_ = data.trace_id();
  114. out->ukm_source_id_ = data.ukm_source_id();
  115. out->coalesced_ = data.coalesced();
  116. out->began_ = data.began();
  117. out->terminated_ = data.terminated();
  118. out->source_event_type_ = MojoSourceEventTypeToUI(data.source_event_type());
  119. out->gesture_scroll_id_ = data.gesture_scroll_id();
  120. out->touch_trace_id_ = data.touch_trace_id();
  121. return true;
  122. }
  123. // static
  124. ui::mojom::LatencyComponentType
  125. EnumTraits<ui::mojom::LatencyComponentType, ui::LatencyComponentType>::ToMojom(
  126. ui::LatencyComponentType type) {
  127. switch (type) {
  128. case ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT:
  129. return ui::mojom::LatencyComponentType::
  130. INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT;
  131. case ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT:
  132. return ui::mojom::LatencyComponentType::
  133. INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT;
  134. case ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT:
  135. return ui::mojom::LatencyComponentType::
  136. INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT;
  137. case ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT:
  138. return ui::mojom::LatencyComponentType::
  139. INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT;
  140. case ui::INPUT_EVENT_LATENCY_UI_COMPONENT:
  141. return ui::mojom::LatencyComponentType::INPUT_EVENT_LATENCY_UI_COMPONENT;
  142. case ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT:
  143. return ui::mojom::LatencyComponentType::
  144. INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT;
  145. case ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT:
  146. return ui::mojom::LatencyComponentType::
  147. INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT;
  148. case ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT:
  149. return ui::mojom::LatencyComponentType::
  150. INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT;
  151. case ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT:
  152. return ui::mojom::LatencyComponentType::
  153. INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT;
  154. case ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT:
  155. return ui::mojom::LatencyComponentType::
  156. DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT;
  157. case ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT:
  158. return ui::mojom::LatencyComponentType::
  159. INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT;
  160. case ui::INPUT_EVENT_LATENCY_FRAME_SWAP_COMPONENT:
  161. return ui::mojom::LatencyComponentType::
  162. INPUT_EVENT_LATENCY_FRAME_SWAP_COMPONENT;
  163. }
  164. NOTREACHED();
  165. return ui::mojom::LatencyComponentType::kMaxValue;
  166. }
  167. // static
  168. bool EnumTraits<ui::mojom::LatencyComponentType, ui::LatencyComponentType>::
  169. FromMojom(ui::mojom::LatencyComponentType input,
  170. ui::LatencyComponentType* output) {
  171. switch (input) {
  172. case ui::mojom::LatencyComponentType::
  173. INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT:
  174. *output = ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT;
  175. return true;
  176. case ui::mojom::LatencyComponentType::
  177. INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT:
  178. *output = ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT;
  179. return true;
  180. case ui::mojom::LatencyComponentType::
  181. INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT:
  182. *output = ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT;
  183. return true;
  184. case ui::mojom::LatencyComponentType::
  185. INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT:
  186. *output = ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT;
  187. return true;
  188. case ui::mojom::LatencyComponentType::INPUT_EVENT_LATENCY_UI_COMPONENT:
  189. *output = ui::INPUT_EVENT_LATENCY_UI_COMPONENT;
  190. return true;
  191. case ui::mojom::LatencyComponentType::
  192. INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT:
  193. *output = ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT;
  194. return true;
  195. case ui::mojom::LatencyComponentType::
  196. INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT:
  197. *output = ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT;
  198. return true;
  199. case ui::mojom::LatencyComponentType::
  200. INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT:
  201. *output = ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT;
  202. return true;
  203. case ui::mojom::LatencyComponentType::
  204. INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT:
  205. *output = ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT;
  206. return true;
  207. case ui::mojom::LatencyComponentType::
  208. DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT:
  209. *output = ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT;
  210. return true;
  211. case ui::mojom::LatencyComponentType::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT:
  212. *output = ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT;
  213. return true;
  214. case ui::mojom::LatencyComponentType::
  215. INPUT_EVENT_LATENCY_FRAME_SWAP_COMPONENT:
  216. *output = ui::INPUT_EVENT_LATENCY_FRAME_SWAP_COMPONENT;
  217. return true;
  218. }
  219. return false;
  220. }
  221. } // namespace mojo