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

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

Issue 1966983003: Generate param traits size methods for IPC files in content/ (and traits it depends on). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix owners 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/geometry/gfx_param_traits.h ('k') | ui/gfx/ipc/gfx_param_traits.h » ('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/geometry/gfx_param_traits.h" 5 #include "ui/gfx/ipc/geometry/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" 12 #include "ui/gfx/geometry/point3_f.h"
13 #include "ui/gfx/geometry/rect.h" 13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/rect_f.h" 14 #include "ui/gfx/geometry/rect_f.h"
15 #include "ui/gfx/geometry/scroll_offset.h" 15 #include "ui/gfx/geometry/scroll_offset.h"
16 16
17 #if defined(OS_MACOSX) 17 #if defined(OS_MACOSX)
18 #include "ipc/mach_port_mac.h" 18 #include "ipc/mach_port_mac.h"
19 #endif 19 #endif
20 20
21 namespace IPC { 21 namespace IPC {
22 22
23 void ParamTraits<gfx::Point>::GetSize(base::PickleSizer* s,
24 const gfx::Point& p) {
25 GetParamSize(s, p.x());
26 GetParamSize(s, p.y());
27 }
28
23 void ParamTraits<gfx::Point>::Write(base::Pickle* m, const gfx::Point& p) { 29 void ParamTraits<gfx::Point>::Write(base::Pickle* m, const gfx::Point& p) {
24 WriteParam(m, p.x()); 30 WriteParam(m, p.x());
25 WriteParam(m, p.y()); 31 WriteParam(m, p.y());
26 } 32 }
27 33
28 bool ParamTraits<gfx::Point>::Read(const base::Pickle* m, 34 bool ParamTraits<gfx::Point>::Read(const base::Pickle* m,
29 base::PickleIterator* iter, 35 base::PickleIterator* iter,
30 gfx::Point* r) { 36 gfx::Point* r) {
31 int x, y; 37 int x, y;
32 if (!ReadParam(m, iter, &x) || !ReadParam(m, iter, &y)) 38 if (!ReadParam(m, iter, &x) || !ReadParam(m, iter, &y))
(...skipping 26 matching lines...) Expand all
59 return false; 65 return false;
60 r->set_x(x); 66 r->set_x(x);
61 r->set_y(y); 67 r->set_y(y);
62 return true; 68 return true;
63 } 69 }
64 70
65 void ParamTraits<gfx::PointF>::Log(const gfx::PointF& p, std::string* l) { 71 void ParamTraits<gfx::PointF>::Log(const gfx::PointF& p, std::string* l) {
66 l->append(base::StringPrintf("(%f, %f)", p.x(), p.y())); 72 l->append(base::StringPrintf("(%f, %f)", p.x(), p.y()));
67 } 73 }
68 74
75 void ParamTraits<gfx::Point3F>::GetSize(base::PickleSizer* s,
76 const gfx::Point3F& p) {
77 GetParamSize(s, p.x());
78 GetParamSize(s, p.y());
79 GetParamSize(s, p.z());
80 }
81
69 void ParamTraits<gfx::Point3F>::Write(base::Pickle* m, const gfx::Point3F& p) { 82 void ParamTraits<gfx::Point3F>::Write(base::Pickle* m, const gfx::Point3F& p) {
70 WriteParam(m, p.x()); 83 WriteParam(m, p.x());
71 WriteParam(m, p.y()); 84 WriteParam(m, p.y());
72 WriteParam(m, p.z()); 85 WriteParam(m, p.z());
73 } 86 }
74 87
75 bool ParamTraits<gfx::Point3F>::Read(const base::Pickle* m, 88 bool ParamTraits<gfx::Point3F>::Read(const base::Pickle* m,
76 base::PickleIterator* iter, 89 base::PickleIterator* iter,
77 gfx::Point3F* r) { 90 gfx::Point3F* r) {
78 float x, y, z; 91 float x, y, z;
79 if (!ReadParam(m, iter, &x) || !ReadParam(m, iter, &y) || 92 if (!ReadParam(m, iter, &x) || !ReadParam(m, iter, &y) ||
80 !ReadParam(m, iter, &z)) 93 !ReadParam(m, iter, &z))
81 return false; 94 return false;
82 r->set_x(x); 95 r->set_x(x);
83 r->set_y(y); 96 r->set_y(y);
84 r->set_z(z); 97 r->set_z(z);
85 return true; 98 return true;
86 } 99 }
87 100
88 void ParamTraits<gfx::Point3F>::Log(const gfx::Point3F& p, std::string* l) { 101 void ParamTraits<gfx::Point3F>::Log(const gfx::Point3F& p, std::string* l) {
89 l->append(base::StringPrintf("(%f, %f, %f)", p.x(), p.y(), p.z())); 102 l->append(base::StringPrintf("(%f, %f, %f)", p.x(), p.y(), p.z()));
90 } 103 }
91 104
105 void ParamTraits<gfx::Size>::GetSize(base::PickleSizer* s,
106 const gfx::Size& p) {
107 s->AddBytes(sizeof(int) * 2);
108 }
109
92 void ParamTraits<gfx::Size>::Write(base::Pickle* m, const gfx::Size& p) { 110 void ParamTraits<gfx::Size>::Write(base::Pickle* m, const gfx::Size& p) {
93 DCHECK_GE(p.width(), 0); 111 DCHECK_GE(p.width(), 0);
94 DCHECK_GE(p.height(), 0); 112 DCHECK_GE(p.height(), 0);
95 int values[2] = {p.width(), p.height()}; 113 int values[2] = {p.width(), p.height()};
96 m->WriteBytes(&values, sizeof(int) * 2); 114 m->WriteBytes(&values, sizeof(int) * 2);
97 } 115 }
98 116
99 bool ParamTraits<gfx::Size>::Read(const base::Pickle* m, 117 bool ParamTraits<gfx::Size>::Read(const base::Pickle* m,
100 base::PickleIterator* iter, 118 base::PickleIterator* iter,
101 gfx::Size* r) { 119 gfx::Size* r) {
102 const char* char_values; 120 const char* char_values;
103 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) 121 if (!iter->ReadBytes(&char_values, sizeof(int) * 2))
104 return false; 122 return false;
105 const int* values = reinterpret_cast<const int*>(char_values); 123 const int* values = reinterpret_cast<const int*>(char_values);
106 if (values[0] < 0 || values[1] < 0) 124 if (values[0] < 0 || values[1] < 0)
107 return false; 125 return false;
108 r->set_width(values[0]); 126 r->set_width(values[0]);
109 r->set_height(values[1]); 127 r->set_height(values[1]);
110 return true; 128 return true;
111 } 129 }
112 130
113 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { 131 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) {
114 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); 132 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height()));
115 } 133 }
116 134
135 void ParamTraits<gfx::SizeF>::GetSize(base::PickleSizer* s,
136 const gfx::SizeF& p) {
137 s->AddBytes(sizeof(float) * 2);
138 }
139
117 void ParamTraits<gfx::SizeF>::Write(base::Pickle* m, const gfx::SizeF& p) { 140 void ParamTraits<gfx::SizeF>::Write(base::Pickle* m, const gfx::SizeF& p) {
118 float values[2] = {p.width(), p.height()}; 141 float values[2] = {p.width(), p.height()};
119 m->WriteBytes(&values, sizeof(float) * 2); 142 m->WriteBytes(&values, sizeof(float) * 2);
120 } 143 }
121 144
122 bool ParamTraits<gfx::SizeF>::Read(const base::Pickle* m, 145 bool ParamTraits<gfx::SizeF>::Read(const base::Pickle* m,
123 base::PickleIterator* iter, 146 base::PickleIterator* iter,
124 gfx::SizeF* r) { 147 gfx::SizeF* r) {
125 const char* char_values; 148 const char* char_values;
126 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) 149 if (!iter->ReadBytes(&char_values, sizeof(float) * 2))
(...skipping 28 matching lines...) Expand all
155 const int* values = reinterpret_cast<const int*>(char_values); 178 const int* values = reinterpret_cast<const int*>(char_values);
156 r->set_x(values[0]); 179 r->set_x(values[0]);
157 r->set_y(values[1]); 180 r->set_y(values[1]);
158 return true; 181 return true;
159 } 182 }
160 183
161 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { 184 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) {
162 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); 185 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y()));
163 } 186 }
164 187
188 void ParamTraits<gfx::Vector2dF>::GetSize(base::PickleSizer* s,
189 const gfx::Vector2dF& p) {
190 s->AddBytes(sizeof(float) * 2);
191 }
192
165 void ParamTraits<gfx::Vector2dF>::Write(base::Pickle* m, 193 void ParamTraits<gfx::Vector2dF>::Write(base::Pickle* m,
166 const gfx::Vector2dF& p) { 194 const gfx::Vector2dF& p) {
167 float values[2] = {p.x(), p.y()}; 195 float values[2] = {p.x(), p.y()};
168 m->WriteBytes(&values, sizeof(float) * 2); 196 m->WriteBytes(&values, sizeof(float) * 2);
169 } 197 }
170 198
171 bool ParamTraits<gfx::Vector2dF>::Read(const base::Pickle* m, 199 bool ParamTraits<gfx::Vector2dF>::Read(const base::Pickle* m,
172 base::PickleIterator* iter, 200 base::PickleIterator* iter,
173 gfx::Vector2dF* r) { 201 gfx::Vector2dF* r) {
174 const char* char_values; 202 const char* char_values;
175 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) 203 if (!iter->ReadBytes(&char_values, sizeof(float) * 2))
176 return false; 204 return false;
177 const float* values = reinterpret_cast<const float*>(char_values); 205 const float* values = reinterpret_cast<const float*>(char_values);
178 r->set_x(values[0]); 206 r->set_x(values[0]);
179 r->set_y(values[1]); 207 r->set_y(values[1]);
180 return true; 208 return true;
181 } 209 }
182 210
183 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { 211 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) {
184 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); 212 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y()));
185 } 213 }
186 214
215 void ParamTraits<gfx::Rect>::GetSize(base::PickleSizer* s,
216 const gfx::Rect& p) {
217 s->AddBytes(sizeof(int) * 4);
218 }
219
187 void ParamTraits<gfx::Rect>::Write(base::Pickle* m, const gfx::Rect& p) { 220 void ParamTraits<gfx::Rect>::Write(base::Pickle* m, const gfx::Rect& p) {
188 int values[4] = {p.x(), p.y(), p.width(), p.height()}; 221 int values[4] = {p.x(), p.y(), p.width(), p.height()};
189 m->WriteBytes(&values, sizeof(int) * 4); 222 m->WriteBytes(&values, sizeof(int) * 4);
190 } 223 }
191 224
192 bool ParamTraits<gfx::Rect>::Read(const base::Pickle* m, 225 bool ParamTraits<gfx::Rect>::Read(const base::Pickle* m,
193 base::PickleIterator* iter, 226 base::PickleIterator* iter,
194 gfx::Rect* r) { 227 gfx::Rect* r) {
195 const char* char_values; 228 const char* char_values;
196 if (!iter->ReadBytes(&char_values, sizeof(int) * 4)) 229 if (!iter->ReadBytes(&char_values, sizeof(int) * 4))
(...skipping 29 matching lines...) Expand all
226 const float* values = reinterpret_cast<const float*>(char_values); 259 const float* values = reinterpret_cast<const float*>(char_values);
227 r->SetRect(values[0], values[1], values[2], values[3]); 260 r->SetRect(values[0], values[1], values[2], values[3]);
228 return true; 261 return true;
229 } 262 }
230 263
231 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { 264 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) {
232 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), p.width(), 265 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), p.width(),
233 p.height())); 266 p.height()));
234 } 267 }
235 268
269 void ParamTraits<gfx::ScrollOffset>::GetSize(base::PickleSizer* s,
270 const gfx::ScrollOffset& p) {
271 GetParamSize(s, p.x());
272 GetParamSize(s, p.y());
273 }
274
236 void ParamTraits<gfx::ScrollOffset>::Write(base::Pickle* m, 275 void ParamTraits<gfx::ScrollOffset>::Write(base::Pickle* m,
237 const param_type& p) { 276 const param_type& p) {
238 m->WriteDouble(p.x()); 277 m->WriteDouble(p.x());
239 m->WriteDouble(p.y()); 278 m->WriteDouble(p.y());
240 } 279 }
241 280
242 bool ParamTraits<gfx::ScrollOffset>::Read(const base::Pickle* m, 281 bool ParamTraits<gfx::ScrollOffset>::Read(const base::Pickle* m,
243 base::PickleIterator* iter, 282 base::PickleIterator* iter,
244 param_type* r) { 283 param_type* r) {
245 double x = 0.f; 284 double x = 0.f;
246 double y = 0.f; 285 double y = 0.f;
247 if (!iter->ReadDouble(&x)) 286 if (!iter->ReadDouble(&x))
248 return false; 287 return false;
249 if (!iter->ReadDouble(&y)) 288 if (!iter->ReadDouble(&y))
250 return false; 289 return false;
251 r->set_x(x); 290 r->set_x(x);
252 r->set_y(y); 291 r->set_y(y);
253 return true; 292 return true;
254 } 293 }
255 294
256 void ParamTraits<gfx::ScrollOffset>::Log(const param_type& p, std::string* l) { 295 void ParamTraits<gfx::ScrollOffset>::Log(const param_type& p, std::string* l) {
257 l->append("("); 296 l->append("(");
258 LogParam(p.x(), l); 297 LogParam(p.x(), l);
259 l->append(", "); 298 l->append(", ");
260 LogParam(p.y(), l); 299 LogParam(p.y(), l);
261 l->append(")"); 300 l->append(")");
262 } 301 }
263 302
264 } // namespace IPC 303 } // namespace IPC
OLDNEW
« no previous file with comments | « ui/gfx/ipc/geometry/gfx_param_traits.h ('k') | ui/gfx/ipc/gfx_param_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698