| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 "cc/proto/gfx_conversions.h" | |
| 6 | |
| 7 #include "cc/proto/point.pb.h" | |
| 8 #include "cc/proto/point3f.pb.h" | |
| 9 #include "cc/proto/pointf.pb.h" | |
| 10 #include "cc/proto/rect.pb.h" | |
| 11 #include "cc/proto/rectf.pb.h" | |
| 12 #include "cc/proto/scroll_offset.pb.h" | |
| 13 #include "cc/proto/size.pb.h" | |
| 14 #include "cc/proto/sizef.pb.h" | |
| 15 #include "cc/proto/transform.pb.h" | |
| 16 #include "cc/proto/vector2d.pb.h" | |
| 17 #include "cc/proto/vector2df.pb.h" | |
| 18 #include "ui/gfx/geometry/point.h" | |
| 19 #include "ui/gfx/geometry/point3_f.h" | |
| 20 #include "ui/gfx/geometry/point_f.h" | |
| 21 #include "ui/gfx/geometry/rect.h" | |
| 22 #include "ui/gfx/geometry/rect_f.h" | |
| 23 #include "ui/gfx/geometry/scroll_offset.h" | |
| 24 #include "ui/gfx/geometry/size.h" | |
| 25 #include "ui/gfx/geometry/size_f.h" | |
| 26 #include "ui/gfx/geometry/vector2d.h" | |
| 27 #include "ui/gfx/transform.h" | |
| 28 | |
| 29 namespace cc { | |
| 30 | |
| 31 void PointToProto(const gfx::Point& point, proto::Point* proto) { | |
| 32 proto->set_x(point.x()); | |
| 33 proto->set_y(point.y()); | |
| 34 } | |
| 35 | |
| 36 gfx::Point ProtoToPoint(const proto::Point& proto) { | |
| 37 return gfx::Point(proto.x(), proto.y()); | |
| 38 } | |
| 39 | |
| 40 void PointFToProto(const gfx::PointF& point, proto::PointF* proto) { | |
| 41 proto->set_x(point.x()); | |
| 42 proto->set_y(point.y()); | |
| 43 } | |
| 44 | |
| 45 gfx::PointF ProtoToPointF(const proto::PointF& proto) { | |
| 46 return gfx::PointF(proto.x(), proto.y()); | |
| 47 } | |
| 48 | |
| 49 void Point3FToProto(const gfx::Point3F& point, proto::Point3F* proto) { | |
| 50 proto->set_x(point.x()); | |
| 51 proto->set_y(point.y()); | |
| 52 proto->set_z(point.z()); | |
| 53 } | |
| 54 | |
| 55 gfx::Point3F ProtoToPoint3F(const proto::Point3F& proto) { | |
| 56 return gfx::Point3F(proto.x(), proto.y(), proto.z()); | |
| 57 } | |
| 58 | |
| 59 void RectToProto(const gfx::Rect& rect, proto::Rect* proto) { | |
| 60 proto->mutable_origin()->set_x(rect.x()); | |
| 61 proto->mutable_origin()->set_y(rect.y()); | |
| 62 proto->mutable_size()->set_width(rect.width()); | |
| 63 proto->mutable_size()->set_height(rect.height()); | |
| 64 } | |
| 65 | |
| 66 gfx::Rect ProtoToRect(const proto::Rect& proto) { | |
| 67 return gfx::Rect(proto.origin().x(), proto.origin().y(), proto.size().width(), | |
| 68 proto.size().height()); | |
| 69 } | |
| 70 | |
| 71 void RectFToProto(const gfx::RectF& rect, proto::RectF* proto) { | |
| 72 proto->mutable_origin()->set_x(rect.x()); | |
| 73 proto->mutable_origin()->set_y(rect.y()); | |
| 74 proto->mutable_size()->set_width(rect.width()); | |
| 75 proto->mutable_size()->set_height(rect.height()); | |
| 76 } | |
| 77 | |
| 78 gfx::RectF ProtoToRectF(const proto::RectF& proto) { | |
| 79 return gfx::RectF(proto.origin().x(), proto.origin().y(), | |
| 80 proto.size().width(), proto.size().height()); | |
| 81 } | |
| 82 | |
| 83 void SizeToProto(const gfx::Size& size, proto::Size* proto) { | |
| 84 proto->set_width(size.width()); | |
| 85 proto->set_height(size.height()); | |
| 86 } | |
| 87 | |
| 88 gfx::Size ProtoToSize(const proto::Size& proto) { | |
| 89 return gfx::Size(proto.width(), proto.height()); | |
| 90 } | |
| 91 | |
| 92 void SizeFToProto(const gfx::SizeF& size, proto::SizeF* proto) { | |
| 93 proto->set_width(size.width()); | |
| 94 proto->set_height(size.height()); | |
| 95 } | |
| 96 | |
| 97 gfx::SizeF ProtoToSizeF(const proto::SizeF& proto) { | |
| 98 return gfx::SizeF(proto.width(), proto.height()); | |
| 99 } | |
| 100 | |
| 101 void TransformToProto(const gfx::Transform& transform, | |
| 102 proto::Transform* proto) { | |
| 103 if (transform.IsIdentity()) | |
| 104 return; | |
| 105 | |
| 106 for (int i = 0; i < 4; i++) { | |
| 107 for (int j = 0; j < 4; j++) { | |
| 108 proto->add_matrix(transform.matrix().get(i, j)); | |
| 109 } | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 gfx::Transform ProtoToTransform(const proto::Transform& proto) { | |
| 114 if (proto.matrix_size() == 0) | |
| 115 return gfx::Transform(); | |
| 116 | |
| 117 gfx::Transform transform(gfx::Transform::kSkipInitialization); | |
| 118 DCHECK_EQ(16, proto.matrix_size()); | |
| 119 for (int i = 0; i < 4; i++) { | |
| 120 for (int j = 0; j < 4; j++) { | |
| 121 transform.matrix().set(i, j, proto.matrix(i * 4 + j)); | |
| 122 } | |
| 123 } | |
| 124 return transform; | |
| 125 } | |
| 126 | |
| 127 void Vector2dFToProto(const gfx::Vector2dF& vector, proto::Vector2dF* proto) { | |
| 128 proto->set_x(vector.x()); | |
| 129 proto->set_y(vector.y()); | |
| 130 } | |
| 131 | |
| 132 gfx::Vector2dF ProtoToVector2dF(const proto::Vector2dF& proto) { | |
| 133 return gfx::Vector2dF(proto.x(), proto.y()); | |
| 134 } | |
| 135 | |
| 136 void ScrollOffsetToProto(const gfx::ScrollOffset& scroll_offset, | |
| 137 proto::ScrollOffset* proto) { | |
| 138 proto->set_x(scroll_offset.x()); | |
| 139 proto->set_y(scroll_offset.y()); | |
| 140 } | |
| 141 | |
| 142 gfx::ScrollOffset ProtoToScrollOffset(const proto::ScrollOffset& proto) { | |
| 143 return gfx::ScrollOffset(proto.x(), proto.y()); | |
| 144 } | |
| 145 | |
| 146 void Vector2dToProto(const gfx::Vector2d& vector, proto::Vector2d* proto) { | |
| 147 proto->set_x(vector.x()); | |
| 148 proto->set_y(vector.y()); | |
| 149 } | |
| 150 | |
| 151 gfx::Vector2d ProtoToVector2d(const proto::Vector2d& proto) { | |
| 152 return gfx::Vector2d(proto.x(), proto.y()); | |
| 153 } | |
| 154 | |
| 155 } // namespace cc | |
| OLD | NEW |