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

Side by Side Diff: ui/gfx/ipc/gfx_param_traits.cc

Issue 1924613002: Move ui/gfx/geometry ParamTraits to ui/gfx/ipc/geometry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forward declare Range in gfx_param_traits Created 4 years, 7 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 | « ui/gfx/ipc/gfx_param_traits.h ('k') | ui/ozone/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/ipc/gfx_param_traits.h" 5 #include "ui/gfx/ipc/gfx_param_traits.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "ui/gfx/geometry/point3_f.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/rect_f.h"
15 #include "ui/gfx/geometry/scroll_offset.h"
16 #include "ui/gfx/range/range.h" 12 #include "ui/gfx/range/range.h"
17 13
18 #if defined(OS_MACOSX) 14 #if defined(OS_MACOSX)
19 #include "ipc/mach_port_mac.h" 15 #include "ipc/mach_port_mac.h"
20 #endif 16 #endif
21 17
22 namespace IPC { 18 namespace IPC {
23 19
24 void ParamTraits<gfx::Point>::Write(base::Pickle* m, const gfx::Point& p) {
25 WriteParam(m, p.x());
26 WriteParam(m, p.y());
27 }
28
29 bool ParamTraits<gfx::Point>::Read(const base::Pickle* m,
30 base::PickleIterator* iter,
31 gfx::Point* r) {
32 int x, y;
33 if (!ReadParam(m, iter, &x) || !ReadParam(m, iter, &y))
34 return false;
35 r->set_x(x);
36 r->set_y(y);
37 return true;
38 }
39
40 void ParamTraits<gfx::Point>::Log(const gfx::Point& p, std::string* l) {
41 l->append(base::StringPrintf("(%d, %d)", p.x(), p.y()));
42 }
43
44 void ParamTraits<gfx::PointF>::GetSize(base::PickleSizer* s,
45 const gfx::PointF& p) {
46 GetParamSize(s, p.x());
47 GetParamSize(s, p.y());
48 }
49
50 void ParamTraits<gfx::PointF>::Write(base::Pickle* m, const gfx::PointF& p) {
51 WriteParam(m, p.x());
52 WriteParam(m, p.y());
53 }
54
55 bool ParamTraits<gfx::PointF>::Read(const base::Pickle* m,
56 base::PickleIterator* iter,
57 gfx::PointF* r) {
58 float x, y;
59 if (!ReadParam(m, iter, &x) || !ReadParam(m, iter, &y))
60 return false;
61 r->set_x(x);
62 r->set_y(y);
63 return true;
64 }
65
66 void ParamTraits<gfx::PointF>::Log(const gfx::PointF& p, std::string* l) {
67 l->append(base::StringPrintf("(%f, %f)", p.x(), p.y()));
68 }
69
70 void ParamTraits<gfx::Point3F>::Write(base::Pickle* m, const gfx::Point3F& p) {
71 WriteParam(m, p.x());
72 WriteParam(m, p.y());
73 WriteParam(m, p.z());
74 }
75
76 bool ParamTraits<gfx::Point3F>::Read(const base::Pickle* m,
77 base::PickleIterator* iter,
78 gfx::Point3F* r) {
79 float x, y, z;
80 if (!ReadParam(m, iter, &x) || !ReadParam(m, iter, &y) ||
81 !ReadParam(m, iter, &z))
82 return false;
83 r->set_x(x);
84 r->set_y(y);
85 r->set_z(z);
86 return true;
87 }
88
89 void ParamTraits<gfx::Point3F>::Log(const gfx::Point3F& p, std::string* l) {
90 l->append(base::StringPrintf("(%f, %f, %f)", p.x(), p.y(), p.z()));
91 }
92
93 void ParamTraits<gfx::Size>::Write(base::Pickle* m, const gfx::Size& p) {
94 DCHECK_GE(p.width(), 0);
95 DCHECK_GE(p.height(), 0);
96 int values[2] = { p.width(), p.height() };
97 m->WriteBytes(&values, sizeof(int) * 2);
98 }
99
100 bool ParamTraits<gfx::Size>::Read(const base::Pickle* m,
101 base::PickleIterator* iter,
102 gfx::Size* r) {
103 const char* char_values;
104 if (!iter->ReadBytes(&char_values, sizeof(int) * 2))
105 return false;
106 const int* values = reinterpret_cast<const int*>(char_values);
107 if (values[0] < 0 || values[1] < 0)
108 return false;
109 r->set_width(values[0]);
110 r->set_height(values[1]);
111 return true;
112 }
113
114 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) {
115 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height()));
116 }
117
118 void ParamTraits<gfx::SizeF>::Write(base::Pickle* m, const gfx::SizeF& p) {
119 float values[2] = { p.width(), p.height() };
120 m->WriteBytes(&values, sizeof(float) * 2);
121 }
122
123 bool ParamTraits<gfx::SizeF>::Read(const base::Pickle* m,
124 base::PickleIterator* iter,
125 gfx::SizeF* r) {
126 const char* char_values;
127 if (!iter->ReadBytes(&char_values, sizeof(float) * 2))
128 return false;
129 const float* values = reinterpret_cast<const float*>(char_values);
130 r->set_width(values[0]);
131 r->set_height(values[1]);
132 return true;
133 }
134
135 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) {
136 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height()));
137 }
138
139 void ParamTraits<gfx::Vector2d>::GetSize(base::PickleSizer* s,
140 const gfx::Vector2d& p) {
141 s->AddBytes(sizeof(int) * 2);
142 }
143
144 void ParamTraits<gfx::Vector2d>::Write(base::Pickle* m,
145 const gfx::Vector2d& p) {
146 int values[2] = { p.x(), p.y() };
147 m->WriteBytes(&values, sizeof(int) * 2);
148 }
149
150 bool ParamTraits<gfx::Vector2d>::Read(const base::Pickle* m,
151 base::PickleIterator* iter,
152 gfx::Vector2d* r) {
153 const char* char_values;
154 if (!iter->ReadBytes(&char_values, sizeof(int) * 2))
155 return false;
156 const int* values = reinterpret_cast<const int*>(char_values);
157 r->set_x(values[0]);
158 r->set_y(values[1]);
159 return true;
160 }
161
162 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) {
163 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y()));
164 }
165
166 void ParamTraits<gfx::Vector2dF>::Write(base::Pickle* m,
167 const gfx::Vector2dF& p) {
168 float values[2] = { p.x(), p.y() };
169 m->WriteBytes(&values, sizeof(float) * 2);
170 }
171
172 bool ParamTraits<gfx::Vector2dF>::Read(const base::Pickle* m,
173 base::PickleIterator* iter,
174 gfx::Vector2dF* r) {
175 const char* char_values;
176 if (!iter->ReadBytes(&char_values, sizeof(float) * 2))
177 return false;
178 const float* values = reinterpret_cast<const float*>(char_values);
179 r->set_x(values[0]);
180 r->set_y(values[1]);
181 return true;
182 }
183
184 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) {
185 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y()));
186 }
187
188 void ParamTraits<gfx::Rect>::Write(base::Pickle* m, const gfx::Rect& p) {
189 int values[4] = { p.x(), p.y(), p.width(), p.height() };
190 m->WriteBytes(&values, sizeof(int) * 4);
191 }
192
193 bool ParamTraits<gfx::Rect>::Read(const base::Pickle* m,
194 base::PickleIterator* iter,
195 gfx::Rect* r) {
196 const char* char_values;
197 if (!iter->ReadBytes(&char_values, sizeof(int) * 4))
198 return false;
199 const int* values = reinterpret_cast<const int*>(char_values);
200 if (values[2] < 0 || values[3] < 0)
201 return false;
202 r->SetRect(values[0], values[1], values[2], values[3]);
203 return true;
204 }
205
206 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) {
207 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(),
208 p.width(), p.height()));
209 }
210
211 void ParamTraits<gfx::RectF>::GetSize(base::PickleSizer* s,
212 const gfx::RectF& p) {
213 s->AddBytes(sizeof(float) * 4);
214 }
215
216 void ParamTraits<gfx::RectF>::Write(base::Pickle* m, const gfx::RectF& p) {
217 float values[4] = { p.x(), p.y(), p.width(), p.height() };
218 m->WriteBytes(&values, sizeof(float) * 4);
219 }
220
221 bool ParamTraits<gfx::RectF>::Read(const base::Pickle* m,
222 base::PickleIterator* iter,
223 gfx::RectF* r) {
224 const char* char_values;
225 if (!iter->ReadBytes(&char_values, sizeof(float) * 4))
226 return false;
227 const float* values = reinterpret_cast<const float*>(char_values);
228 r->SetRect(values[0], values[1], values[2], values[3]);
229 return true;
230 }
231
232 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) {
233 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(),
234 p.width(), p.height()));
235 }
236
237 void ParamTraits<gfx::Range>::Write(base::Pickle* m, const gfx::Range& r) { 20 void ParamTraits<gfx::Range>::Write(base::Pickle* m, const gfx::Range& r) {
238 m->WriteUInt32(r.start()); 21 m->WriteUInt32(r.start());
239 m->WriteUInt32(r.end()); 22 m->WriteUInt32(r.end());
240 } 23 }
241 24
242 bool ParamTraits<gfx::Range>::Read(const base::Pickle* m, 25 bool ParamTraits<gfx::Range>::Read(const base::Pickle* m,
243 base::PickleIterator* iter, 26 base::PickleIterator* iter,
244 gfx::Range* r) { 27 gfx::Range* r) {
245 uint32_t start, end; 28 uint32_t start, end;
246 if (!iter->ReadUInt32(&start) || !iter->ReadUInt32(&end)) 29 if (!iter->ReadUInt32(&start) || !iter->ReadUInt32(&end))
247 return false; 30 return false;
248 r->set_start(start); 31 r->set_start(start);
249 r->set_end(end); 32 r->set_end(end);
250 return true; 33 return true;
251 } 34 }
252 35
253 void ParamTraits<gfx::Range>::Log(const gfx::Range& r, std::string* l) { 36 void ParamTraits<gfx::Range>::Log(const gfx::Range& r, std::string* l) {
254 l->append(base::StringPrintf("(%d, %d)", r.start(), r.end())); 37 l->append(base::StringPrintf("(%d, %d)", r.start(), r.end()));
255 } 38 }
256 39
257 void ParamTraits<gfx::ScrollOffset>::Write(base::Pickle* m,
258 const param_type& p) {
259 m->WriteDouble(p.x());
260 m->WriteDouble(p.y());
261 }
262
263 bool ParamTraits<gfx::ScrollOffset>::Read(const base::Pickle* m,
264 base::PickleIterator* iter,
265 param_type* r) {
266 double x = 0.f;
267 double y = 0.f;
268 if (!iter->ReadDouble(&x))
269 return false;
270 if (!iter->ReadDouble(&y))
271 return false;
272 r->set_x(x);
273 r->set_y(y);
274 return true;
275 }
276
277 void ParamTraits<gfx::ScrollOffset>::Log(const param_type& p, std::string* l) {
278 l->append("(");
279 LogParam(p.x(), l);
280 l->append(", ");
281 LogParam(p.y(), l);
282 l->append(")");
283 }
284
285 #if defined(OS_MACOSX) && !defined(OS_IOS) 40 #if defined(OS_MACOSX) && !defined(OS_IOS)
286 void ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort>::Write( 41 void ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort>::Write(
287 base::Pickle* m, 42 base::Pickle* m,
288 const param_type p) { 43 const param_type p) {
289 MachPortMac mach_port_mac(p.get()); 44 MachPortMac mach_port_mac(p.get());
290 ParamTraits<MachPortMac>::Write(m, mach_port_mac); 45 ParamTraits<MachPortMac>::Write(m, mach_port_mac);
291 } 46 }
292 47
293 bool ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort>::Read( 48 bool ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort>::Read(
294 const base::Pickle* m, 49 const base::Pickle* m,
(...skipping 29 matching lines...) Expand all
324 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ 79 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_
325 #include "ui/gfx/ipc/gfx_param_traits_macros.h" 80 #include "ui/gfx/ipc/gfx_param_traits_macros.h"
326 } // namespace IPC 81 } // namespace IPC
327 82
328 // Generate param traits log methods. 83 // Generate param traits log methods.
329 #include "ipc/param_traits_log_macros.h" 84 #include "ipc/param_traits_log_macros.h"
330 namespace IPC { 85 namespace IPC {
331 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ 86 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_
332 #include "ui/gfx/ipc/gfx_param_traits_macros.h" 87 #include "ui/gfx/ipc/gfx_param_traits_macros.h"
333 } // namespace IPC 88 } // namespace IPC
OLDNEW
« no previous file with comments | « ui/gfx/ipc/gfx_param_traits.h ('k') | ui/ozone/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698