Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: cc/proto/gfx_conversions.cc

Issue 1394353002: Add Protobuf support in cc for gfx objects (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move deps to public_deps Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/proto/gfx_conversions.h ('k') | cc/proto/gfx_conversions_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/pointf.pb.h"
9 #include "cc/proto/rect.pb.h"
10 #include "cc/proto/rectf.pb.h"
11 #include "cc/proto/size.pb.h"
12 #include "cc/proto/sizef.pb.h"
13 #include "cc/proto/transform.pb.h"
14 #include "ui/gfx/geometry/point.h"
15 #include "ui/gfx/geometry/point_f.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/geometry/rect_f.h"
18 #include "ui/gfx/geometry/size.h"
19 #include "ui/gfx/geometry/size_f.h"
20 #include "ui/gfx/transform.h"
21
22 namespace cc {
23
24 void PointToProto(const gfx::Point& point, proto::Point* proto) {
25 proto->set_x(point.x());
26 proto->set_y(point.y());
27 }
28
29 gfx::Point ProtoToPoint(const proto::Point& proto) {
30 return gfx::Point(proto.x(), proto.y());
31 }
32
33 void PointFToProto(const gfx::PointF& point, proto::PointF* proto) {
34 proto->set_x(point.x());
35 proto->set_y(point.y());
36 }
37
38 gfx::PointF ProtoToPointF(const proto::PointF& proto) {
39 return gfx::PointF(proto.x(), proto.y());
40 }
41
42 void RectToProto(const gfx::Rect& rect, proto::Rect* proto) {
43 proto->mutable_origin()->set_x(rect.x());
44 proto->mutable_origin()->set_y(rect.y());
45 proto->mutable_size()->set_width(rect.width());
46 proto->mutable_size()->set_height(rect.height());
47 }
48
49 gfx::Rect ProtoToRect(const proto::Rect& proto) {
50 return gfx::Rect(proto.origin().x(), proto.origin().y(), proto.size().width(),
51 proto.size().height());
52 }
53
54 void RectFToProto(const gfx::RectF& rect, proto::RectF* proto) {
55 proto->mutable_origin()->set_x(rect.x());
56 proto->mutable_origin()->set_y(rect.y());
57 proto->mutable_size()->set_width(rect.width());
58 proto->mutable_size()->set_height(rect.height());
59 }
60
61 gfx::RectF ProtoToRectF(const proto::RectF& proto) {
62 return gfx::RectF(proto.origin().x(), proto.origin().y(),
63 proto.size().width(), proto.size().height());
64 }
65
66 void SizeToProto(const gfx::Size& size, proto::Size* proto) {
67 proto->set_width(size.width());
68 proto->set_height(size.height());
69 }
70
71 gfx::Size ProtoToSize(const proto::Size& proto) {
72 return gfx::Size(proto.width(), proto.height());
73 }
74
75 void SizeFToProto(const gfx::SizeF& size, proto::SizeF* proto) {
76 proto->set_width(size.width());
77 proto->set_height(size.height());
78 }
79
80 gfx::SizeF ProtoToSizeF(const proto::SizeF& proto) {
81 return gfx::SizeF(proto.width(), proto.height());
82 }
83
84 void TransformToProto(const gfx::Transform& transform,
85 proto::Transform* proto) {
86 for (int i = 0; i < 4; i++) {
87 for (int j = 0; j < 4; j++) {
88 proto->add_matrix(transform.matrix().get(i, j));
89 }
90 }
91 }
92
93 gfx::Transform ProtoToTransform(const proto::Transform& proto) {
94 gfx::Transform transform;
95 DCHECK_EQ(16, proto.matrix_size());
96 for (int i = 0; i < 4; i++) {
97 for (int j = 0; j < 4; j++) {
98 transform.matrix().set(i, j, proto.matrix(i * 4 + j));
99 }
100 }
101 return transform;
102 }
103
104 } // namespace cc
OLDNEW
« no previous file with comments | « cc/proto/gfx_conversions.h ('k') | cc/proto/gfx_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698