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 7namespace mojo { 8 9// static 10PointPtr TypeConverter<PointPtr, gfx::Point>::Convert(const gfx::Point& input) { 11 PointPtr point(Point::New()); 12 point->x = input.x(); 13 point->y = input.y(); 14 return point.Pass(); 15} 16 17// static 18gfx::Point TypeConverter<gfx::Point, PointPtr>::Convert(const PointPtr& input) { 19 if (input.is_null()) 20 return gfx::Point(); 21 return gfx::Point(input->x, input->y); 22} 23 24// static 25PointFPtr TypeConverter<PointFPtr, gfx::PointF>::Convert( 26 const gfx::PointF& input) { 27 PointFPtr point(PointF::New()); 28 point->x = input.x(); 29 point->y = input.y(); 30 return point.Pass(); 31} 32 33// static 34gfx::PointF TypeConverter<gfx::PointF, PointFPtr>::Convert( 35 const PointFPtr& input) { 36 if (input.is_null()) 37 return gfx::PointF(); 38 return gfx::PointF(input->x, input->y); 39} 40 41// static 42SizePtr TypeConverter<SizePtr, gfx::Size>::Convert(const gfx::Size& input) { 43 SizePtr size(Size::New()); 44 size->width = input.width(); 45 size->height = input.height(); 46 return size.Pass(); 47} 48 49// static 50gfx::Size TypeConverter<gfx::Size, SizePtr>::Convert(const SizePtr& input) { 51 if (input.is_null()) 52 return gfx::Size(); 53 return gfx::Size(input->width, input->height); 54} 55 56// static 57RectPtr TypeConverter<RectPtr, gfx::Rect>::Convert(const gfx::Rect& input) { 58 RectPtr rect(Rect::New()); 59 rect->x = input.x(); 60 rect->y = input.y(); 61 rect->width = input.width(); 62 rect->height = input.height(); 63 return rect.Pass(); 64} 65 66// static 67gfx::Rect TypeConverter<gfx::Rect, RectPtr>::Convert(const RectPtr& input) { 68 if (input.is_null()) 69 return gfx::Rect(); 70 return gfx::Rect(input->x, input->y, input->width, input->height); 71} 72 73// static 74RectFPtr TypeConverter<RectFPtr, gfx::RectF>::Convert(const gfx::RectF& input) { 75 RectFPtr rect(RectF::New()); 76 rect->x = input.x(); 77 rect->y = input.y(); 78 rect->width = input.width(); 79 rect->height = input.height(); 80 return rect.Pass(); 81} 82 83// static 84gfx::RectF TypeConverter<gfx::RectF, RectFPtr>::Convert(const RectFPtr& input) { 85 if (input.is_null()) 86 return gfx::RectF(); 87 return gfx::RectF(input->x, input->y, input->width, input->height); 88} 89 90// static 91TransformPtr TypeConverter<TransformPtr, gfx::Transform>::Convert( 92 const gfx::Transform& input) { 93 std::vector<float> storage(16); 94 input.matrix().asRowMajorf(&storage[0]); 95 mojo::Array<float> matrix; 96 matrix.Swap(&storage); 97 TransformPtr transform(Transform::New()); 98 transform->matrix = matrix.Pass(); 99 return transform.Pass(); 100} 101 102// static 103gfx::Transform TypeConverter<gfx::Transform, TransformPtr>::Convert( 104 const TransformPtr& input) { 105 if (input.is_null()) 106 return gfx::Transform(); 107 gfx::Transform transform(gfx::Transform::kSkipInitialization); 108 transform.matrix().setRowMajorf(&input->matrix.storage()[0]); 109 return transform; 110} 111 112} // namespace mojo 113