| 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/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 "third_party/skia/include/core/SkBitmap.h" | |
| 13 #include "ui/gfx/geometry/point3_f.h" | 12 #include "ui/gfx/geometry/point3_f.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 15 #include "ui/gfx/geometry/rect_f.h" | 14 #include "ui/gfx/geometry/rect_f.h" |
| 16 #include "ui/gfx/geometry/scroll_offset.h" | 15 #include "ui/gfx/geometry/scroll_offset.h" |
| 17 #include "ui/gfx/range/range.h" | 16 #include "ui/gfx/range/range.h" |
| 18 | 17 |
| 19 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
| 20 #include "ipc/mach_port_mac.h" | 19 #include "ipc/mach_port_mac.h" |
| 21 #endif | 20 #endif |
| 22 | 21 |
| 23 namespace { | |
| 24 | |
| 25 struct SkBitmap_Data { | |
| 26 // The color type for the bitmap (bits per pixel, etc). | |
| 27 SkColorType fColorType; | |
| 28 | |
| 29 // The alpha type for the bitmap (opaque, premul, unpremul). | |
| 30 SkAlphaType fAlphaType; | |
| 31 | |
| 32 // The width of the bitmap in pixels. | |
| 33 uint32_t fWidth; | |
| 34 | |
| 35 // The height of the bitmap in pixels. | |
| 36 uint32_t fHeight; | |
| 37 | |
| 38 void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) { | |
| 39 const SkImageInfo& info = bitmap.info(); | |
| 40 fColorType = info.colorType(); | |
| 41 fAlphaType = info.alphaType(); | |
| 42 fWidth = info.width(); | |
| 43 fHeight = info.height(); | |
| 44 } | |
| 45 | |
| 46 // Returns whether |bitmap| successfully initialized. | |
| 47 bool InitSkBitmapFromData(SkBitmap* bitmap, | |
| 48 const char* pixels, | |
| 49 size_t pixels_size) const { | |
| 50 if (!bitmap->tryAllocPixels( | |
| 51 SkImageInfo::Make(fWidth, fHeight, fColorType, fAlphaType))) | |
| 52 return false; | |
| 53 if (pixels_size != bitmap->getSize()) | |
| 54 return false; | |
| 55 memcpy(bitmap->getPixels(), pixels, pixels_size); | |
| 56 return true; | |
| 57 } | |
| 58 }; | |
| 59 | |
| 60 } // namespace | |
| 61 | |
| 62 namespace IPC { | 22 namespace IPC { |
| 63 | 23 |
| 64 void ParamTraits<gfx::Point>::Write(base::Pickle* m, const gfx::Point& p) { | 24 void ParamTraits<gfx::Point>::Write(base::Pickle* m, const gfx::Point& p) { |
| 65 WriteParam(m, p.x()); | 25 WriteParam(m, p.x()); |
| 66 WriteParam(m, p.y()); | 26 WriteParam(m, p.y()); |
| 67 } | 27 } |
| 68 | 28 |
| 69 bool ParamTraits<gfx::Point>::Read(const base::Pickle* m, | 29 bool ParamTraits<gfx::Point>::Read(const base::Pickle* m, |
| 70 base::PickleIterator* iter, | 30 base::PickleIterator* iter, |
| 71 gfx::Point* r) { | 31 gfx::Point* r) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 const float* values = reinterpret_cast<const float*>(char_values); | 227 const float* values = reinterpret_cast<const float*>(char_values); |
| 268 r->SetRect(values[0], values[1], values[2], values[3]); | 228 r->SetRect(values[0], values[1], values[2], values[3]); |
| 269 return true; | 229 return true; |
| 270 } | 230 } |
| 271 | 231 |
| 272 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) { |
| 273 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(), |
| 274 p.width(), p.height())); | 234 p.width(), p.height())); |
| 275 } | 235 } |
| 276 | 236 |
| 277 void ParamTraits<SkBitmap>::Write(base::Pickle* m, const SkBitmap& p) { | |
| 278 size_t fixed_size = sizeof(SkBitmap_Data); | |
| 279 SkBitmap_Data bmp_data; | |
| 280 bmp_data.InitSkBitmapDataForTransfer(p); | |
| 281 m->WriteData(reinterpret_cast<const char*>(&bmp_data), | |
| 282 static_cast<int>(fixed_size)); | |
| 283 size_t pixel_size = p.getSize(); | |
| 284 SkAutoLockPixels p_lock(p); | |
| 285 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), | |
| 286 static_cast<int>(pixel_size)); | |
| 287 } | |
| 288 | |
| 289 bool ParamTraits<SkBitmap>::Read(const base::Pickle* m, | |
| 290 base::PickleIterator* iter, | |
| 291 SkBitmap* r) { | |
| 292 const char* fixed_data; | |
| 293 int fixed_data_size = 0; | |
| 294 if (!iter->ReadData(&fixed_data, &fixed_data_size) || | |
| 295 (fixed_data_size <= 0)) { | |
| 296 NOTREACHED(); | |
| 297 return false; | |
| 298 } | |
| 299 if (fixed_data_size != sizeof(SkBitmap_Data)) | |
| 300 return false; // Message is malformed. | |
| 301 | |
| 302 const char* variable_data; | |
| 303 int variable_data_size = 0; | |
| 304 if (!iter->ReadData(&variable_data, &variable_data_size) || | |
| 305 (variable_data_size < 0)) { | |
| 306 NOTREACHED(); | |
| 307 return false; | |
| 308 } | |
| 309 const SkBitmap_Data* bmp_data = | |
| 310 reinterpret_cast<const SkBitmap_Data*>(fixed_data); | |
| 311 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); | |
| 312 } | |
| 313 | |
| 314 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { | |
| 315 l->append("<SkBitmap>"); | |
| 316 } | |
| 317 | |
| 318 void ParamTraits<gfx::Range>::Write(base::Pickle* m, const gfx::Range& r) { | 237 void ParamTraits<gfx::Range>::Write(base::Pickle* m, const gfx::Range& r) { |
| 319 m->WriteUInt32(r.start()); | 238 m->WriteUInt32(r.start()); |
| 320 m->WriteUInt32(r.end()); | 239 m->WriteUInt32(r.end()); |
| 321 } | 240 } |
| 322 | 241 |
| 323 bool ParamTraits<gfx::Range>::Read(const base::Pickle* m, | 242 bool ParamTraits<gfx::Range>::Read(const base::Pickle* m, |
| 324 base::PickleIterator* iter, | 243 base::PickleIterator* iter, |
| 325 gfx::Range* r) { | 244 gfx::Range* r) { |
| 326 uint32_t start, end; | 245 uint32_t start, end; |
| 327 if (!iter->ReadUInt32(&start) || !iter->ReadUInt32(&end)) | 246 if (!iter->ReadUInt32(&start) || !iter->ReadUInt32(&end)) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ | 324 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ |
| 406 #include "ui/gfx/ipc/gfx_param_traits_macros.h" | 325 #include "ui/gfx/ipc/gfx_param_traits_macros.h" |
| 407 } // namespace IPC | 326 } // namespace IPC |
| 408 | 327 |
| 409 // Generate param traits log methods. | 328 // Generate param traits log methods. |
| 410 #include "ipc/param_traits_log_macros.h" | 329 #include "ipc/param_traits_log_macros.h" |
| 411 namespace IPC { | 330 namespace IPC { |
| 412 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ | 331 #undef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ |
| 413 #include "ui/gfx/ipc/gfx_param_traits_macros.h" | 332 #include "ui/gfx/ipc/gfx_param_traits_macros.h" |
| 414 } // namespace IPC | 333 } // namespace IPC |
| OLD | NEW |