Index: cc/proto/gfx_conversions.cc |
diff --git a/cc/proto/gfx_conversions.cc b/cc/proto/gfx_conversions.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a9f996fff8d759f7803c14afd98106ea6fae30df |
--- /dev/null |
+++ b/cc/proto/gfx_conversions.cc |
@@ -0,0 +1,135 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "cc/proto/gfx_conversions.h" |
+ |
+#include "cc/proto/point.pb.h" |
+#include "cc/proto/pointf.pb.h" |
+#include "cc/proto/rect.pb.h" |
+#include "cc/proto/rectf.pb.h" |
+#include "cc/proto/size.pb.h" |
+#include "cc/proto/sizef.pb.h" |
+#include "cc/proto/transform.pb.h" |
+#include "ui/gfx/geometry/point.h" |
+#include "ui/gfx/geometry/point_f.h" |
+#include "ui/gfx/geometry/rect.h" |
+#include "ui/gfx/geometry/rect_f.h" |
+#include "ui/gfx/geometry/size.h" |
+#include "ui/gfx/geometry/size_f.h" |
+#include "ui/gfx/transform.h" |
+ |
+namespace cc { |
+ |
+void PointToProto(const gfx::Point& point, proto::Point* proto) { |
+ proto->set_x(point.x()); |
+ proto->set_y(point.y()); |
+} |
+ |
+void ProtoToPoint(const proto::Point& proto, gfx::Point* point) { |
+ point->SetPoint(proto.x(), proto.y()); |
+} |
+ |
+gfx::Point ProtoToPoint(const proto::Point& proto) { |
+ return gfx::Point(proto.x(), proto.y()); |
+} |
+ |
+void PointFToProto(const gfx::PointF& point, proto::PointF* proto) { |
+ proto->set_x(point.x()); |
+ proto->set_y(point.y()); |
+} |
+ |
+void ProtoToPointF(const proto::PointF& proto, gfx::PointF* point) { |
+ point->SetPoint(proto.x(), proto.y()); |
+} |
+ |
+gfx::PointF ProtoToPointF(const proto::PointF& proto) { |
+ return gfx::PointF(proto.x(), proto.y()); |
+} |
+ |
+void RectToProto(const gfx::Rect& rect, proto::Rect* proto) { |
+ proto->mutable_origin()->set_x(rect.x()); |
+ proto->mutable_origin()->set_y(rect.y()); |
+ proto->mutable_size()->set_width(rect.width()); |
+ proto->mutable_size()->set_height(rect.height()); |
+} |
+ |
+void ProtoToRect(const proto::Rect& proto, gfx::Rect* rect) { |
+ rect->SetRect(proto.origin().x(), proto.origin().y(), proto.size().width(), |
+ proto.size().height()); |
+} |
+ |
+gfx::Rect ProtoToRect(const proto::Rect& proto) { |
+ return gfx::Rect(proto.origin().x(), proto.origin().y(), proto.size().width(), |
+ proto.size().height()); |
+} |
+ |
+void RectFToProto(const gfx::RectF& rect, proto::RectF* proto) { |
+ proto->mutable_origin()->set_x(rect.x()); |
+ proto->mutable_origin()->set_y(rect.y()); |
+ proto->mutable_size()->set_width(rect.width()); |
+ proto->mutable_size()->set_height(rect.height()); |
+} |
+ |
+void ProtoToRectF(const proto::RectF& proto, gfx::RectF* rect) { |
+ rect->SetRect(proto.origin().x(), proto.origin().y(), proto.size().width(), |
+ proto.size().height()); |
+} |
+ |
+gfx::RectF ProtoToRectF(const proto::RectF& proto) { |
+ return gfx::RectF(proto.origin().x(), proto.origin().y(), |
+ proto.size().width(), proto.size().height()); |
+} |
+ |
+void SizeToProto(const gfx::Size& size, proto::Size* proto) { |
+ proto->set_width(size.width()); |
+ proto->set_height(size.height()); |
+} |
+ |
+void ProtoToSize(const proto::Size& proto, gfx::Size* size) { |
+ size->SetSize(proto.width(), proto.height()); |
+} |
+ |
+gfx::Size ProtoToSize(const proto::Size& proto) { |
+ return gfx::Size(proto.width(), proto.height()); |
+} |
+ |
+void SizeFToProto(const gfx::SizeF& size, proto::SizeF* proto) { |
+ proto->set_width(size.width()); |
+ proto->set_height(size.height()); |
+} |
+ |
+void ProtoToSizeF(const proto::SizeF& proto, gfx::SizeF* size) { |
+ size->SetSize(proto.width(), proto.height()); |
+} |
+ |
+gfx::SizeF ProtoToSizeF(const proto::SizeF& proto) { |
+ return gfx::SizeF(proto.width(), proto.height()); |
+} |
+ |
+void TransformToProto(const gfx::Transform& transform, |
+ proto::Transform* proto) { |
+ for (int i = 0; i < 4; i++) { |
+ for (int j = 0; j < 4; j++) { |
+ proto->add_matrix(transform.matrix().get(i, j)); |
+ } |
+ } |
+} |
+ |
+void ProtoToTransform(const proto::Transform& proto, |
+ gfx::Transform* transform) { |
+ DCHECK_EQ(16, proto.matrix_size()); |
+ for (int i = 0; i < 4; i++) { |
+ for (int j = 0; j < 4; j++) { |
+ transform->matrix().set(i, j, proto.matrix(i * 4 + j)); |
+ } |
+ } |
+} |
+ |
+gfx::Transform ProtoToTransform(const proto::Transform& proto) { |
+ gfx::Transform transform; |
+ ProtoToTransform(proto, &transform); |
+ return transform; |
+} |
+ |
+} // namespace cc |