| Index: content/common/common_param_traits.cc
|
| ===================================================================
|
| --- content/common/common_param_traits.cc (revision 79031)
|
| +++ content/common/common_param_traits.cc (working copy)
|
| @@ -9,9 +9,45 @@
|
| #include "net/base/upload_data.h"
|
| #include "net/http/http_response_headers.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
|
| +#include "third_party/skia/include/core/SkBitmap.h"
|
| #include "ui/gfx/rect.h"
|
| #include "webkit/glue/resource_loader_bridge.h"
|
|
|
| +namespace {
|
| +
|
| +struct SkBitmap_Data {
|
| + // The configuration for the bitmap (bits per pixel, etc).
|
| + SkBitmap::Config fConfig;
|
| +
|
| + // The width of the bitmap in pixels.
|
| + uint32 fWidth;
|
| +
|
| + // The height of the bitmap in pixels.
|
| + uint32 fHeight;
|
| +
|
| + void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) {
|
| + fConfig = bitmap.config();
|
| + fWidth = bitmap.width();
|
| + fHeight = bitmap.height();
|
| + }
|
| +
|
| + // Returns whether |bitmap| successfully initialized.
|
| + bool InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels,
|
| + size_t total_pixels) const {
|
| + if (total_pixels) {
|
| + bitmap->setConfig(fConfig, fWidth, fHeight, 0);
|
| + if (!bitmap->allocPixels())
|
| + return false;
|
| + if (total_pixels != bitmap->getSize())
|
| + return false;
|
| + memcpy(bitmap->getPixels(), pixels, total_pixels);
|
| + }
|
| + return true;
|
| + }
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| NPIdentifier_Param::NPIdentifier_Param()
|
| : identifier() {
|
| }
|
| @@ -761,4 +797,43 @@
|
| }
|
| }
|
|
|
| +void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) {
|
| + size_t fixed_size = sizeof(SkBitmap_Data);
|
| + SkBitmap_Data bmp_data;
|
| + bmp_data.InitSkBitmapDataForTransfer(p);
|
| + m->WriteData(reinterpret_cast<const char*>(&bmp_data),
|
| + static_cast<int>(fixed_size));
|
| + size_t pixel_size = p.getSize();
|
| + SkAutoLockPixels p_lock(p);
|
| + m->WriteData(reinterpret_cast<const char*>(p.getPixels()),
|
| + static_cast<int>(pixel_size));
|
| +}
|
| +
|
| +bool ParamTraits<SkBitmap>::Read(const Message* m, void** iter, SkBitmap* r) {
|
| + const char* fixed_data;
|
| + int fixed_data_size = 0;
|
| + if (!m->ReadData(iter, &fixed_data, &fixed_data_size) ||
|
| + (fixed_data_size <= 0)) {
|
| + NOTREACHED();
|
| + return false;
|
| + }
|
| + if (fixed_data_size != sizeof(SkBitmap_Data))
|
| + return false; // Message is malformed.
|
| +
|
| + const char* variable_data;
|
| + int variable_data_size = 0;
|
| + if (!m->ReadData(iter, &variable_data, &variable_data_size) ||
|
| + (variable_data_size < 0)) {
|
| + NOTREACHED();
|
| + return false;
|
| + }
|
| + const SkBitmap_Data* bmp_data =
|
| + reinterpret_cast<const SkBitmap_Data*>(fixed_data);
|
| + return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size);
|
| +}
|
| +
|
| +void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) {
|
| + l->append("<SkBitmap>");
|
| +}
|
| +
|
| } // namespace IPC
|
|
|