3b9d787ab2c0b43ac51b33081786fb5b4c8ae4ba
[platform/framework/web/crosswalk.git] / src / mojo / services / public / cpp / geometry / lib / geometry_type_converters.cc
1 // Copyright 2014 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 "mojo/services/public/cpp/geometry/geometry_type_converters.h"
6
7 namespace mojo {
8
9 // static
10 PointPtr TypeConverter<PointPtr, gfx::Point>::ConvertFrom(
11     const gfx::Point& input) {
12   PointPtr point(Point::New());
13   point->x = input.x();
14   point->y = input.y();
15   return point.Pass();
16 }
17
18 // static
19 gfx::Point TypeConverter<PointPtr, gfx::Point>::ConvertTo(
20     const PointPtr& input) {
21   if (input.is_null())
22     return gfx::Point();
23   return gfx::Point(input->x, input->y);
24 }
25
26 // static
27 PointFPtr TypeConverter<PointFPtr, gfx::PointF>::ConvertFrom(
28     const gfx::PointF& input) {
29   PointFPtr point(PointF::New());
30   point->x = input.x();
31   point->y = input.y();
32   return point.Pass();
33 }
34
35 // static
36 gfx::PointF TypeConverter<PointFPtr, gfx::PointF>::ConvertTo(
37     const PointFPtr& input) {
38   if (input.is_null())
39     return gfx::PointF();
40   return gfx::PointF(input->x, input->y);
41 }
42
43 // static
44 SizePtr TypeConverter<SizePtr, gfx::Size>::ConvertFrom(const gfx::Size& input) {
45   SizePtr size(Size::New());
46   size->width = input.width();
47   size->height = input.height();
48   return size.Pass();
49 }
50
51 // static
52 gfx::Size TypeConverter<SizePtr, gfx::Size>::ConvertTo(const SizePtr& input) {
53   if (input.is_null())
54     return gfx::Size();
55   return gfx::Size(input->width, input->height);
56 }
57
58 // static
59 RectPtr TypeConverter<RectPtr, gfx::Rect>::ConvertFrom(const gfx::Rect& input) {
60   RectPtr rect(Rect::New());
61   rect->x = input.x();
62   rect->y = input.y();
63   rect->width = input.width();
64   rect->height = input.height();
65   return rect.Pass();
66 }
67
68 // static
69 gfx::Rect TypeConverter<RectPtr, gfx::Rect>::ConvertTo(const RectPtr& input) {
70   if (input.is_null())
71     return gfx::Rect();
72   return gfx::Rect(input->x, input->y, input->width, input->height);
73 }
74
75 // static
76 TransformPtr TypeConverter<TransformPtr, gfx::Transform>::ConvertFrom(
77     const gfx::Transform& input) {
78   std::vector<float> storage(16);
79   input.matrix().asRowMajorf(&storage[0]);
80   mojo::Array<float> matrix;
81   matrix.Swap(&storage);
82   TransformPtr transform(Transform::New());
83   transform->matrix = matrix.Pass();
84   return transform.Pass();
85 }
86
87 // static
88 gfx::Transform TypeConverter<TransformPtr, gfx::Transform>::ConvertTo(
89     const TransformPtr& input) {
90   if (input.is_null())
91     return gfx::Transform();
92   gfx::Transform transform(gfx::Transform::kSkipInitialization);
93   transform.matrix().setRowMajorf(&input->matrix.storage()[0]);
94   return transform;
95 }
96
97 }  // namespace mojo