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

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: Fixed build for other targets 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
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 void ProtoToPoint(const proto::Point& proto, gfx::Point* point) {
30 point->SetPoint(proto.x(), proto.y());
31 }
32
33 gfx::Point ProtoToPoint(const proto::Point& proto) {
34 return gfx::Point(proto.x(), proto.y());
35 }
36
37 void PointFToProto(const gfx::PointF& point, proto::PointF* proto) {
38 proto->set_x(point.x());
39 proto->set_y(point.y());
40 }
41
42 void ProtoToPointF(const proto::PointF& proto, gfx::PointF* point) {
43 point->SetPoint(proto.x(), proto.y());
44 }
45
46 gfx::PointF ProtoToPointF(const proto::PointF& proto) {
47 return gfx::PointF(proto.x(), proto.y());
48 }
49
50 void RectToProto(const gfx::Rect& rect, proto::Rect* proto) {
51 proto->mutable_origin()->set_x(rect.x());
52 proto->mutable_origin()->set_y(rect.y());
53 proto->mutable_size()->set_width(rect.width());
54 proto->mutable_size()->set_height(rect.height());
55 }
56
57 void ProtoToRect(const proto::Rect& proto, gfx::Rect* rect) {
58 rect->SetRect(proto.origin().x(), proto.origin().y(), proto.size().width(),
59 proto.size().height());
60 }
61
62 gfx::Rect ProtoToRect(const proto::Rect& proto) {
63 return gfx::Rect(proto.origin().x(), proto.origin().y(), proto.size().width(),
64 proto.size().height());
65 }
66
67 void RectFToProto(const gfx::RectF& rect, proto::RectF* proto) {
68 proto->mutable_origin()->set_x(rect.x());
69 proto->mutable_origin()->set_y(rect.y());
70 proto->mutable_size()->set_width(rect.width());
71 proto->mutable_size()->set_height(rect.height());
72 }
73
74 void ProtoToRectF(const proto::RectF& proto, gfx::RectF* rect) {
75 rect->SetRect(proto.origin().x(), proto.origin().y(), proto.size().width(),
76 proto.size().height());
77 }
78
79 gfx::RectF ProtoToRectF(const proto::RectF& proto) {
80 return gfx::RectF(proto.origin().x(), proto.origin().y(),
81 proto.size().width(), proto.size().height());
82 }
83
84 void SizeToProto(const gfx::Size& size, proto::Size* proto) {
85 proto->set_width(size.width());
86 proto->set_height(size.height());
87 }
88
89 void ProtoToSize(const proto::Size& proto, gfx::Size* size) {
90 size->SetSize(proto.width(), proto.height());
91 }
92
93 gfx::Size ProtoToSize(const proto::Size& proto) {
94 return gfx::Size(proto.width(), proto.height());
95 }
96
97 void SizeFToProto(const gfx::SizeF& size, proto::SizeF* proto) {
98 proto->set_width(size.width());
99 proto->set_height(size.height());
100 }
101
102 void ProtoToSizeF(const proto::SizeF& proto, gfx::SizeF* size) {
103 size->SetSize(proto.width(), proto.height());
104 }
105
106 gfx::SizeF ProtoToSizeF(const proto::SizeF& proto) {
107 return gfx::SizeF(proto.width(), proto.height());
108 }
109
110 void TransformToProto(const gfx::Transform& transform,
111 proto::Transform* proto) {
112 for (int i = 0; i < 4; i++) {
113 for (int j = 0; j < 4; j++) {
114 proto->add_matrix(transform.matrix().get(i, j));
115 }
116 }
117 }
118
119 void ProtoToTransform(const proto::Transform& proto,
120 gfx::Transform* transform) {
121 DCHECK_EQ(16, proto.matrix_size());
122 for (int i = 0; i < 4; i++) {
123 for (int j = 0; j < 4; j++) {
124 transform->matrix().set(i, j, proto.matrix(i * 4 + j));
125 }
126 }
127 }
128
129 gfx::Transform ProtoToTransform(const proto::Transform& proto) {
130 gfx::Transform transform;
131 ProtoToTransform(proto, &transform);
132 return transform;
133 }
134
135 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698