1 // Copyright 2019 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 "device/vr/android/arcore/type_converters.h"
6 
7 #include "ui/gfx/transform_util.h"
8 
9 namespace mojo {
10 
11 device::mojom::XRPlaneOrientation
Convert(ArPlaneType plane_type)12 TypeConverter<device::mojom::XRPlaneOrientation, ArPlaneType>::Convert(
13     ArPlaneType plane_type) {
14   switch (plane_type) {
15     case ArPlaneType::AR_PLANE_HORIZONTAL_DOWNWARD_FACING:
16     case ArPlaneType::AR_PLANE_HORIZONTAL_UPWARD_FACING:
17       return device::mojom::XRPlaneOrientation::HORIZONTAL;
18     case ArPlaneType::AR_PLANE_VERTICAL:
19       return device::mojom::XRPlaneOrientation::VERTICAL;
20   }
21 }
22 
Convert(const device::mojom::VRPosePtr & pose)23 gfx::Transform TypeConverter<gfx::Transform, device::mojom::VRPosePtr>::Convert(
24     const device::mojom::VRPosePtr& pose) {
25   gfx::DecomposedTransform decomposed;
26   if (pose->orientation) {
27     decomposed.quaternion = *pose->orientation;
28   }
29 
30   if (pose->position) {
31     decomposed.translate[0] = pose->position->x();
32     decomposed.translate[1] = pose->position->y();
33     decomposed.translate[2] = pose->position->z();
34   }
35 
36   return gfx::ComposeTransform(decomposed);
37 }
38 
Convert(const device::mojom::Pose & pose)39 gfx::Transform TypeConverter<gfx::Transform, device::mojom::Pose>::Convert(
40     const device::mojom::Pose& pose) {
41   gfx::DecomposedTransform decomposed;
42   decomposed.quaternion = pose.orientation;
43 
44   decomposed.translate[0] = pose.position.x();
45   decomposed.translate[1] = pose.position.y();
46   decomposed.translate[2] = pose.position.z();
47 
48   return gfx::ComposeTransform(decomposed);
49 }
50 
51 }  // namespace mojo
52