| 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" |
| 16 #include "ui/gfx/range/range.h" | |
| 17 | 16 |
| 18 #if defined(OS_MACOSX) | 17 #if defined(OS_MACOSX) |
| 19 #include "ipc/mach_port_mac.h" | 18 #include "ipc/mach_port_mac.h" |
| 20 #endif | 19 #endif |
| 21 | 20 |
| 22 namespace IPC { | 21 namespace IPC { |
| 23 | 22 |
| 24 void ParamTraits<gfx::Point>::Write(base::Pickle* m, const gfx::Point& p) { | 23 void ParamTraits<gfx::Point>::Write(base::Pickle* m, const gfx::Point& p) { |
| 25 WriteParam(m, p.x()); | 24 WriteParam(m, p.x()); |
| 26 WriteParam(m, p.y()); | 25 WriteParam(m, p.y()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 return true; | 85 return true; |
| 87 } | 86 } |
| 88 | 87 |
| 89 void ParamTraits<gfx::Point3F>::Log(const gfx::Point3F& p, std::string* l) { | 88 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())); | 89 l->append(base::StringPrintf("(%f, %f, %f)", p.x(), p.y(), p.z())); |
| 91 } | 90 } |
| 92 | 91 |
| 93 void ParamTraits<gfx::Size>::Write(base::Pickle* m, const gfx::Size& p) { | 92 void ParamTraits<gfx::Size>::Write(base::Pickle* m, const gfx::Size& p) { |
| 94 DCHECK_GE(p.width(), 0); | 93 DCHECK_GE(p.width(), 0); |
| 95 DCHECK_GE(p.height(), 0); | 94 DCHECK_GE(p.height(), 0); |
| 96 int values[2] = { p.width(), p.height() }; | 95 int values[2] = {p.width(), p.height()}; |
| 97 m->WriteBytes(&values, sizeof(int) * 2); | 96 m->WriteBytes(&values, sizeof(int) * 2); |
| 98 } | 97 } |
| 99 | 98 |
| 100 bool ParamTraits<gfx::Size>::Read(const base::Pickle* m, | 99 bool ParamTraits<gfx::Size>::Read(const base::Pickle* m, |
| 101 base::PickleIterator* iter, | 100 base::PickleIterator* iter, |
| 102 gfx::Size* r) { | 101 gfx::Size* r) { |
| 103 const char* char_values; | 102 const char* char_values; |
| 104 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) | 103 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) |
| 105 return false; | 104 return false; |
| 106 const int* values = reinterpret_cast<const int*>(char_values); | 105 const int* values = reinterpret_cast<const int*>(char_values); |
| 107 if (values[0] < 0 || values[1] < 0) | 106 if (values[0] < 0 || values[1] < 0) |
| 108 return false; | 107 return false; |
| 109 r->set_width(values[0]); | 108 r->set_width(values[0]); |
| 110 r->set_height(values[1]); | 109 r->set_height(values[1]); |
| 111 return true; | 110 return true; |
| 112 } | 111 } |
| 113 | 112 |
| 114 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { | 113 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { |
| 115 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); | 114 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); |
| 116 } | 115 } |
| 117 | 116 |
| 118 void ParamTraits<gfx::SizeF>::Write(base::Pickle* m, const gfx::SizeF& p) { | 117 void ParamTraits<gfx::SizeF>::Write(base::Pickle* m, const gfx::SizeF& p) { |
| 119 float values[2] = { p.width(), p.height() }; | 118 float values[2] = {p.width(), p.height()}; |
| 120 m->WriteBytes(&values, sizeof(float) * 2); | 119 m->WriteBytes(&values, sizeof(float) * 2); |
| 121 } | 120 } |
| 122 | 121 |
| 123 bool ParamTraits<gfx::SizeF>::Read(const base::Pickle* m, | 122 bool ParamTraits<gfx::SizeF>::Read(const base::Pickle* m, |
| 124 base::PickleIterator* iter, | 123 base::PickleIterator* iter, |
| 125 gfx::SizeF* r) { | 124 gfx::SizeF* r) { |
| 126 const char* char_values; | 125 const char* char_values; |
| 127 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) | 126 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) |
| 128 return false; | 127 return false; |
| 129 const float* values = reinterpret_cast<const float*>(char_values); | 128 const float* values = reinterpret_cast<const float*>(char_values); |
| 130 r->set_width(values[0]); | 129 r->set_width(values[0]); |
| 131 r->set_height(values[1]); | 130 r->set_height(values[1]); |
| 132 return true; | 131 return true; |
| 133 } | 132 } |
| 134 | 133 |
| 135 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { | 134 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { |
| 136 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); | 135 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); |
| 137 } | 136 } |
| 138 | 137 |
| 139 void ParamTraits<gfx::Vector2d>::GetSize(base::PickleSizer* s, | 138 void ParamTraits<gfx::Vector2d>::GetSize(base::PickleSizer* s, |
| 140 const gfx::Vector2d& p) { | 139 const gfx::Vector2d& p) { |
| 141 s->AddBytes(sizeof(int) * 2); | 140 s->AddBytes(sizeof(int) * 2); |
| 142 } | 141 } |
| 143 | 142 |
| 144 void ParamTraits<gfx::Vector2d>::Write(base::Pickle* m, | 143 void ParamTraits<gfx::Vector2d>::Write(base::Pickle* m, |
| 145 const gfx::Vector2d& p) { | 144 const gfx::Vector2d& p) { |
| 146 int values[2] = { p.x(), p.y() }; | 145 int values[2] = {p.x(), p.y()}; |
| 147 m->WriteBytes(&values, sizeof(int) * 2); | 146 m->WriteBytes(&values, sizeof(int) * 2); |
| 148 } | 147 } |
| 149 | 148 |
| 150 bool ParamTraits<gfx::Vector2d>::Read(const base::Pickle* m, | 149 bool ParamTraits<gfx::Vector2d>::Read(const base::Pickle* m, |
| 151 base::PickleIterator* iter, | 150 base::PickleIterator* iter, |
| 152 gfx::Vector2d* r) { | 151 gfx::Vector2d* r) { |
| 153 const char* char_values; | 152 const char* char_values; |
| 154 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) | 153 if (!iter->ReadBytes(&char_values, sizeof(int) * 2)) |
| 155 return false; | 154 return false; |
| 156 const int* values = reinterpret_cast<const int*>(char_values); | 155 const int* values = reinterpret_cast<const int*>(char_values); |
| 157 r->set_x(values[0]); | 156 r->set_x(values[0]); |
| 158 r->set_y(values[1]); | 157 r->set_y(values[1]); |
| 159 return true; | 158 return true; |
| 160 } | 159 } |
| 161 | 160 |
| 162 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { | 161 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { |
| 163 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); | 162 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); |
| 164 } | 163 } |
| 165 | 164 |
| 166 void ParamTraits<gfx::Vector2dF>::Write(base::Pickle* m, | 165 void ParamTraits<gfx::Vector2dF>::Write(base::Pickle* m, |
| 167 const gfx::Vector2dF& p) { | 166 const gfx::Vector2dF& p) { |
| 168 float values[2] = { p.x(), p.y() }; | 167 float values[2] = {p.x(), p.y()}; |
| 169 m->WriteBytes(&values, sizeof(float) * 2); | 168 m->WriteBytes(&values, sizeof(float) * 2); |
| 170 } | 169 } |
| 171 | 170 |
| 172 bool ParamTraits<gfx::Vector2dF>::Read(const base::Pickle* m, | 171 bool ParamTraits<gfx::Vector2dF>::Read(const base::Pickle* m, |
| 173 base::PickleIterator* iter, | 172 base::PickleIterator* iter, |
| 174 gfx::Vector2dF* r) { | 173 gfx::Vector2dF* r) { |
| 175 const char* char_values; | 174 const char* char_values; |
| 176 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) | 175 if (!iter->ReadBytes(&char_values, sizeof(float) * 2)) |
| 177 return false; | 176 return false; |
| 178 const float* values = reinterpret_cast<const float*>(char_values); | 177 const float* values = reinterpret_cast<const float*>(char_values); |
| 179 r->set_x(values[0]); | 178 r->set_x(values[0]); |
| 180 r->set_y(values[1]); | 179 r->set_y(values[1]); |
| 181 return true; | 180 return true; |
| 182 } | 181 } |
| 183 | 182 |
| 184 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { | 183 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { |
| 185 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); | 184 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); |
| 186 } | 185 } |
| 187 | 186 |
| 188 void ParamTraits<gfx::Rect>::Write(base::Pickle* m, const gfx::Rect& p) { | 187 void ParamTraits<gfx::Rect>::Write(base::Pickle* m, const gfx::Rect& p) { |
| 189 int values[4] = { p.x(), p.y(), p.width(), p.height() }; | 188 int values[4] = {p.x(), p.y(), p.width(), p.height()}; |
| 190 m->WriteBytes(&values, sizeof(int) * 4); | 189 m->WriteBytes(&values, sizeof(int) * 4); |
| 191 } | 190 } |
| 192 | 191 |
| 193 bool ParamTraits<gfx::Rect>::Read(const base::Pickle* m, | 192 bool ParamTraits<gfx::Rect>::Read(const base::Pickle* m, |
| 194 base::PickleIterator* iter, | 193 base::PickleIterator* iter, |
| 195 gfx::Rect* r) { | 194 gfx::Rect* r) { |
| 196 const char* char_values; | 195 const char* char_values; |
| 197 if (!iter->ReadBytes(&char_values, sizeof(int) * 4)) | 196 if (!iter->ReadBytes(&char_values, sizeof(int) * 4)) |
| 198 return false; | 197 return false; |
| 199 const int* values = reinterpret_cast<const int*>(char_values); | 198 const int* values = reinterpret_cast<const int*>(char_values); |
| 200 if (values[2] < 0 || values[3] < 0) | 199 if (values[2] < 0 || values[3] < 0) |
| 201 return false; | 200 return false; |
| 202 r->SetRect(values[0], values[1], values[2], values[3]); | 201 r->SetRect(values[0], values[1], values[2], values[3]); |
| 203 return true; | 202 return true; |
| 204 } | 203 } |
| 205 | 204 |
| 206 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { | 205 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(), | 206 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), p.width(), |
| 208 p.width(), p.height())); | 207 p.height())); |
| 209 } | 208 } |
| 210 | 209 |
| 211 void ParamTraits<gfx::RectF>::GetSize(base::PickleSizer* s, | 210 void ParamTraits<gfx::RectF>::GetSize(base::PickleSizer* s, |
| 212 const gfx::RectF& p) { | 211 const gfx::RectF& p) { |
| 213 s->AddBytes(sizeof(float) * 4); | 212 s->AddBytes(sizeof(float) * 4); |
| 214 } | 213 } |
| 215 | 214 |
| 216 void ParamTraits<gfx::RectF>::Write(base::Pickle* m, const gfx::RectF& p) { | 215 void ParamTraits<gfx::RectF>::Write(base::Pickle* m, const gfx::RectF& p) { |
| 217 float values[4] = { p.x(), p.y(), p.width(), p.height() }; | 216 float values[4] = {p.x(), p.y(), p.width(), p.height()}; |
| 218 m->WriteBytes(&values, sizeof(float) * 4); | 217 m->WriteBytes(&values, sizeof(float) * 4); |
| 219 } | 218 } |
| 220 | 219 |
| 221 bool ParamTraits<gfx::RectF>::Read(const base::Pickle* m, | 220 bool ParamTraits<gfx::RectF>::Read(const base::Pickle* m, |
| 222 base::PickleIterator* iter, | 221 base::PickleIterator* iter, |
| 223 gfx::RectF* r) { | 222 gfx::RectF* r) { |
| 224 const char* char_values; | 223 const char* char_values; |
| 225 if (!iter->ReadBytes(&char_values, sizeof(float) * 4)) | 224 if (!iter->ReadBytes(&char_values, sizeof(float) * 4)) |
| 226 return false; | 225 return false; |
| 227 const float* values = reinterpret_cast<const float*>(char_values); | 226 const float* values = reinterpret_cast<const float*>(char_values); |
| 228 r->SetRect(values[0], values[1], values[2], values[3]); | 227 r->SetRect(values[0], values[1], values[2], values[3]); |
| 229 return true; | 228 return true; |
| 230 } | 229 } |
| 231 | 230 |
| 232 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { | 231 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(), | 232 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), p.width(), |
| 234 p.width(), p.height())); | 233 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 } | 234 } |
| 256 | 235 |
| 257 void ParamTraits<gfx::ScrollOffset>::Write(base::Pickle* m, | 236 void ParamTraits<gfx::ScrollOffset>::Write(base::Pickle* m, |
| 258 const param_type& p) { | 237 const param_type& p) { |
| 259 m->WriteDouble(p.x()); | 238 m->WriteDouble(p.x()); |
| 260 m->WriteDouble(p.y()); | 239 m->WriteDouble(p.y()); |
| 261 } | 240 } |
| 262 | 241 |
| 263 bool ParamTraits<gfx::ScrollOffset>::Read(const base::Pickle* m, | 242 bool ParamTraits<gfx::ScrollOffset>::Read(const base::Pickle* m, |
| 264 base::PickleIterator* iter, | 243 base::PickleIterator* iter, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 275 } | 254 } |
| 276 | 255 |
| 277 void ParamTraits<gfx::ScrollOffset>::Log(const param_type& p, std::string* l) { | 256 void ParamTraits<gfx::ScrollOffset>::Log(const param_type& p, std::string* l) { |
| 278 l->append("("); | 257 l->append("("); |
| 279 LogParam(p.x(), l); | 258 LogParam(p.x(), l); |
| 280 l->append(", "); | 259 l->append(", "); |
| 281 LogParam(p.y(), l); | 260 LogParam(p.y(), l); |
| 282 l->append(")"); | 261 l->append(")"); |
| 283 } | 262 } |
| 284 | 263 |
| 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 | 264 } // namespace IPC |
| 313 | |
| 314 // Generate param traits write methods. | |
| 315 #include "ipc/param_traits_write_macros.h" | |
| 316 namespace IPC { | |
| 317 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ | |
| 318 #include "ui/gfx/ipc/gfx_param_traits_macros.h" | |
| 319 } // namespace IPC | |
| 320 | |
| 321 // Generate param traits read methods. | |
| 322 #include "ipc/param_traits_read_macros.h" | |
| 323 namespace IPC { | |
| 324 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ | |
| 325 #include "ui/gfx/ipc/gfx_param_traits_macros.h" | |
| 326 } // namespace IPC | |
| 327 | |
| 328 // Generate param traits log methods. | |
| 329 #include "ipc/param_traits_log_macros.h" | |
| 330 namespace IPC { | |
| 331 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ | |
| 332 #include "ui/gfx/ipc/gfx_param_traits_macros.h" | |
| 333 } // namespace IPC | |
| OLD | NEW |