OLD | NEW |
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/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" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 return true; | 86 return true; |
87 } | 87 } |
88 | 88 |
89 void ParamTraits<gfx::Point3F>::Log(const gfx::Point3F& p, std::string* l) { | 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())); | 90 l->append(base::StringPrintf("(%f, %f, %f)", p.x(), p.y(), p.z())); |
91 } | 91 } |
92 | 92 |
93 void ParamTraits<gfx::Size>::Write(base::Pickle* m, const gfx::Size& p) { | 93 void ParamTraits<gfx::Size>::Write(base::Pickle* m, const gfx::Size& p) { |
94 DCHECK_GE(p.width(), 0); | 94 DCHECK_GE(p.width(), 0); |
95 DCHECK_GE(p.height(), 0); | 95 DCHECK_GE(p.height(), 0); |
96 int values[2] = { p.width(), p.height() }; | 96 int values[2] = {p.width(), p.height()}; |
97 m->WriteBytes(&values, sizeof(int) * 2); | 97 m->WriteBytes(&values, sizeof(int) * 2); |
98 } | 98 } |
99 | 99 |
100 bool ParamTraits<gfx::Size>::Read(const base::Pickle* m, | 100 bool ParamTraits<gfx::Size>::Read(const base::Pickle* m, |
101 base::PickleIterator* iter, | 101 base::PickleIterator* iter, |
102 gfx::Size* r) { | 102 gfx::Size* r) { |
103 const char* char_values; | 103 const char* char_values; |
104 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) | 104 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) |
105 return false; | 105 return false; |
106 const int* values = reinterpret_cast<const int*>(char_values); | 106 const int* values = reinterpret_cast<const int*>(char_values); |
107 if (values[0] < 0 || values[1] < 0) | 107 if (values[0] < 0 || values[1] < 0) |
108 return false; | 108 return false; |
109 r->set_width(values[0]); | 109 r->set_width(values[0]); |
110 r->set_height(values[1]); | 110 r->set_height(values[1]); |
111 return true; | 111 return true; |
112 } | 112 } |
113 | 113 |
114 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { | 114 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { |
115 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); | 115 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); |
116 } | 116 } |
117 | 117 |
118 void ParamTraits<gfx::SizeF>::Write(base::Pickle* m, const gfx::SizeF& p) { | 118 void ParamTraits<gfx::SizeF>::Write(base::Pickle* m, const gfx::SizeF& p) { |
119 float values[2] = { p.width(), p.height() }; | 119 float values[2] = {p.width(), p.height()}; |
120 m->WriteBytes(&values, sizeof(float) * 2); | 120 m->WriteBytes(&values, sizeof(float) * 2); |
121 } | 121 } |
122 | 122 |
123 bool ParamTraits<gfx::SizeF>::Read(const base::Pickle* m, | 123 bool ParamTraits<gfx::SizeF>::Read(const base::Pickle* m, |
124 base::PickleIterator* iter, | 124 base::PickleIterator* iter, |
125 gfx::SizeF* r) { | 125 gfx::SizeF* r) { |
126 const char* char_values; | 126 const char* char_values; |
127 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) | 127 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) |
128 return false; | 128 return false; |
129 const float* values = reinterpret_cast<const float*>(char_values); | 129 const float* values = reinterpret_cast<const float*>(char_values); |
130 r->set_width(values[0]); | 130 r->set_width(values[0]); |
131 r->set_height(values[1]); | 131 r->set_height(values[1]); |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { | 135 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { |
136 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); | 136 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); |
137 } | 137 } |
138 | 138 |
139 void ParamTraits<gfx::Vector2d>::GetSize(base::PickleSizer* s, | 139 void ParamTraits<gfx::Vector2d>::GetSize(base::PickleSizer* s, |
140 const gfx::Vector2d& p) { | 140 const gfx::Vector2d& p) { |
141 s->AddBytes(sizeof(int) * 2); | 141 s->AddBytes(sizeof(int) * 2); |
142 } | 142 } |
143 | 143 |
144 void ParamTraits<gfx::Vector2d>::Write(base::Pickle* m, | 144 void ParamTraits<gfx::Vector2d>::Write(base::Pickle* m, |
145 const gfx::Vector2d& p) { | 145 const gfx::Vector2d& p) { |
146 int values[2] = { p.x(), p.y() }; | 146 int values[2] = {p.x(), p.y()}; |
147 m->WriteBytes(&values, sizeof(int) * 2); | 147 m->WriteBytes(&values, sizeof(int) * 2); |
148 } | 148 } |
149 | 149 |
150 bool ParamTraits<gfx::Vector2d>::Read(const base::Pickle* m, | 150 bool ParamTraits<gfx::Vector2d>::Read(const base::Pickle* m, |
151 base::PickleIterator* iter, | 151 base::PickleIterator* iter, |
152 gfx::Vector2d* r) { | 152 gfx::Vector2d* r) { |
153 const char* char_values; | 153 const char* char_values; |
154 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) | 154 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) |
155 return false; | 155 return false; |
156 const int* values = reinterpret_cast<const int*>(char_values); | 156 const int* values = reinterpret_cast<const int*>(char_values); |
157 r->set_x(values[0]); | 157 r->set_x(values[0]); |
158 r->set_y(values[1]); | 158 r->set_y(values[1]); |
159 return true; | 159 return true; |
160 } | 160 } |
161 | 161 |
162 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { | 162 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { |
163 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); | 163 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); |
164 } | 164 } |
165 | 165 |
166 void ParamTraits<gfx::Vector2dF>::Write(base::Pickle* m, | 166 void ParamTraits<gfx::Vector2dF>::Write(base::Pickle* m, |
167 const gfx::Vector2dF& p) { | 167 const gfx::Vector2dF& p) { |
168 float values[2] = { p.x(), p.y() }; | 168 float values[2] = {p.x(), p.y()}; |
169 m->WriteBytes(&values, sizeof(float) * 2); | 169 m->WriteBytes(&values, sizeof(float) * 2); |
170 } | 170 } |
171 | 171 |
172 bool ParamTraits<gfx::Vector2dF>::Read(const base::Pickle* m, | 172 bool ParamTraits<gfx::Vector2dF>::Read(const base::Pickle* m, |
173 base::PickleIterator* iter, | 173 base::PickleIterator* iter, |
174 gfx::Vector2dF* r) { | 174 gfx::Vector2dF* r) { |
175 const char* char_values; | 175 const char* char_values; |
176 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) | 176 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) |
177 return false; | 177 return false; |
178 const float* values = reinterpret_cast<const float*>(char_values); | 178 const float* values = reinterpret_cast<const float*>(char_values); |
179 r->set_x(values[0]); | 179 r->set_x(values[0]); |
180 r->set_y(values[1]); | 180 r->set_y(values[1]); |
181 return true; | 181 return true; |
182 } | 182 } |
183 | 183 |
184 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { | 184 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { |
185 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); | 185 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); |
186 } | 186 } |
187 | 187 |
188 void ParamTraits<gfx::Rect>::Write(base::Pickle* m, const gfx::Rect& p) { | 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() }; | 189 int values[4] = {p.x(), p.y(), p.width(), p.height()}; |
190 m->WriteBytes(&values, sizeof(int) * 4); | 190 m->WriteBytes(&values, sizeof(int) * 4); |
191 } | 191 } |
192 | 192 |
193 bool ParamTraits<gfx::Rect>::Read(const base::Pickle* m, | 193 bool ParamTraits<gfx::Rect>::Read(const base::Pickle* m, |
194 base::PickleIterator* iter, | 194 base::PickleIterator* iter, |
195 gfx::Rect* r) { | 195 gfx::Rect* r) { |
196 const char* char_values; | 196 const char* char_values; |
197 if (!iter->ReadBytes(&char_values, sizeof(int) * 4)) | 197 if (!iter->ReadBytes(&char_values, sizeof(int) * 4)) |
198 return false; | 198 return false; |
199 const int* values = reinterpret_cast<const int*>(char_values); | 199 const int* values = reinterpret_cast<const int*>(char_values); |
200 if (values[2] < 0 || values[3] < 0) | 200 if (values[2] < 0 || values[3] < 0) |
201 return false; | 201 return false; |
202 r->SetRect(values[0], values[1], values[2], values[3]); | 202 r->SetRect(values[0], values[1], values[2], values[3]); |
203 return true; | 203 return true; |
204 } | 204 } |
205 | 205 |
206 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { | 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(), | 207 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), p.width(), |
208 p.width(), p.height())); | 208 p.height())); |
209 } | 209 } |
210 | 210 |
211 void ParamTraits<gfx::RectF>::GetSize(base::PickleSizer* s, | 211 void ParamTraits<gfx::RectF>::GetSize(base::PickleSizer* s, |
212 const gfx::RectF& p) { | 212 const gfx::RectF& p) { |
213 s->AddBytes(sizeof(float) * 4); | 213 s->AddBytes(sizeof(float) * 4); |
214 } | 214 } |
215 | 215 |
216 void ParamTraits<gfx::RectF>::Write(base::Pickle* m, const gfx::RectF& p) { | 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() }; | 217 float values[4] = {p.x(), p.y(), p.width(), p.height()}; |
218 m->WriteBytes(&values, sizeof(float) * 4); | 218 m->WriteBytes(&values, sizeof(float) * 4); |
219 } | 219 } |
220 | 220 |
221 bool ParamTraits<gfx::RectF>::Read(const base::Pickle* m, | 221 bool ParamTraits<gfx::RectF>::Read(const base::Pickle* m, |
222 base::PickleIterator* iter, | 222 base::PickleIterator* iter, |
223 gfx::RectF* r) { | 223 gfx::RectF* r) { |
224 const char* char_values; | 224 const char* char_values; |
225 if (!iter->ReadBytes(&char_values, sizeof(float) * 4)) | 225 if (!iter->ReadBytes(&char_values, sizeof(float) * 4)) |
226 return false; | 226 return false; |
227 const float* values = reinterpret_cast<const float*>(char_values); | 227 const float* values = reinterpret_cast<const float*>(char_values); |
228 r->SetRect(values[0], values[1], values[2], values[3]); | 228 r->SetRect(values[0], values[1], values[2], values[3]); |
229 return true; | 229 return true; |
230 } | 230 } |
231 | 231 |
232 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { | 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(), | 233 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), p.width(), |
234 p.width(), p.height())); | 234 p.height())); |
235 } | |
236 | |
237 void ParamTraits<gfx::Range>::Write(base::Pickle* m, const gfx::Range& r) { | |
238 m->WriteUInt32(r.start()); | |
239 m->WriteUInt32(r.end()); | |
240 } | |
241 | |
242 bool ParamTraits<gfx::Range>::Read(const base::Pickle* m, | |
243 base::PickleIterator* iter, | |
244 gfx::Range* r) { | |
245 uint32_t start, end; | |
246 if (!iter->ReadUInt32(&start) || !iter->ReadUInt32(&end)) | |
247 return false; | |
248 r->set_start(start); | |
249 r->set_end(end); | |
250 return true; | |
251 } | |
252 | |
253 void ParamTraits<gfx::Range>::Log(const gfx::Range& r, std::string* l) { | |
254 l->append(base::StringPrintf("(%d, %d)", r.start(), r.end())); | |
255 } | 235 } |
256 | 236 |
257 void ParamTraits<gfx::ScrollOffset>::Write(base::Pickle* m, | 237 void ParamTraits<gfx::ScrollOffset>::Write(base::Pickle* m, |
258 const param_type& p) { | 238 const param_type& p) { |
259 m->WriteDouble(p.x()); | 239 m->WriteDouble(p.x()); |
260 m->WriteDouble(p.y()); | 240 m->WriteDouble(p.y()); |
261 } | 241 } |
262 | 242 |
263 bool ParamTraits<gfx::ScrollOffset>::Read(const base::Pickle* m, | 243 bool ParamTraits<gfx::ScrollOffset>::Read(const base::Pickle* m, |
264 base::PickleIterator* iter, | 244 base::PickleIterator* iter, |
(...skipping 10 matching lines...) Expand all Loading... |
275 } | 255 } |
276 | 256 |
277 void ParamTraits<gfx::ScrollOffset>::Log(const param_type& p, std::string* l) { | 257 void ParamTraits<gfx::ScrollOffset>::Log(const param_type& p, std::string* l) { |
278 l->append("("); | 258 l->append("("); |
279 LogParam(p.x(), l); | 259 LogParam(p.x(), l); |
280 l->append(", "); | 260 l->append(", "); |
281 LogParam(p.y(), l); | 261 LogParam(p.y(), l); |
282 l->append(")"); | 262 l->append(")"); |
283 } | 263 } |
284 | 264 |
285 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
286 void ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort>::Write( | |
287 base::Pickle* m, | |
288 const param_type p) { | |
289 MachPortMac mach_port_mac(p.get()); | |
290 ParamTraits<MachPortMac>::Write(m, mach_port_mac); | |
291 } | |
292 | |
293 bool ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort>::Read( | |
294 const base::Pickle* m, | |
295 base::PickleIterator* iter, | |
296 param_type* r) { | |
297 MachPortMac mach_port_mac; | |
298 if (!ParamTraits<MachPortMac>::Read(m, iter, &mach_port_mac)) | |
299 return false; | |
300 r->reset(mach_port_mac.get_mach_port()); | |
301 return true; | |
302 } | |
303 | |
304 void ParamTraits<gfx::ScopedRefCountedIOSurfaceMachPort>::Log( | |
305 const param_type& p, | |
306 std::string* l) { | |
307 l->append("IOSurface Mach send right: "); | |
308 LogParam(p.get(), l); | |
309 } | |
310 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | |
311 | |
312 } // namespace IPC | 265 } // namespace IPC |
313 | 266 |
314 // Generate param traits write methods. | 267 // Generate param traits write methods. |
315 #include "ipc/param_traits_write_macros.h" | 268 #include "ipc/param_traits_write_macros.h" |
316 namespace IPC { | 269 namespace IPC { |
317 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ | 270 #undef UI_GFX_IPC_GEOMETRY_GFX_PARAM_TRAITS_MACROS_H_ |
318 #include "ui/gfx/ipc/gfx_param_traits_macros.h" | 271 #include "ui/gfx/ipc/geometry/gfx_param_traits_macros.h" |
319 } // namespace IPC | 272 } // namespace IPC |
320 | 273 |
321 // Generate param traits read methods. | 274 // Generate param traits read methods. |
322 #include "ipc/param_traits_read_macros.h" | 275 #include "ipc/param_traits_read_macros.h" |
323 namespace IPC { | 276 namespace IPC { |
324 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ | 277 #undef UI_GFX_IPC_GEOMETRY_GFX_PARAM_TRAITS_MACROS_H_ |
325 #include "ui/gfx/ipc/gfx_param_traits_macros.h" | 278 #include "ui/gfx/ipc/geometry/gfx_param_traits_macros.h" |
326 } // namespace IPC | 279 } // namespace IPC |
327 | 280 |
328 // Generate param traits log methods. | 281 // Generate param traits log methods. |
329 #include "ipc/param_traits_log_macros.h" | 282 #include "ipc/param_traits_log_macros.h" |
330 namespace IPC { | 283 namespace IPC { |
331 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ | 284 #undef UI_GFX_IPC_GEOMETRY_GFX_PARAM_TRAITS_MACROS_H_ |
332 #include "ui/gfx/ipc/gfx_param_traits_macros.h" | 285 #include "ui/gfx/ipc/geometry/gfx_param_traits_macros.h" |
333 } // namespace IPC | 286 } // namespace IPC |
OLD | NEW |