From e1981f43505c69351e5786eac1bff1913f4c96db Mon Sep 17 00:00:00 2001 From: "maruel@google.com" Date: Tue, 12 Aug 2008 15:22:13 +0000 Subject: Cleanup a few files, reduce the number of includes. Applied glint. No code change, just moving around. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@713 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/common/ipc_message_utils.cc | 95 ++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 9 deletions(-) (limited to 'chrome/common/ipc_message_utils.cc') diff --git a/chrome/common/ipc_message_utils.cc b/chrome/common/ipc_message_utils.cc index ad5050c..ee6a554 100644 --- a/chrome/common/ipc_message_utils.cc +++ b/chrome/common/ipc_message_utils.cc @@ -31,11 +31,95 @@ #include "base/gfx/rect.h" #include "googleurl/src/gurl.h" +#include "SkBitmap.h" #include "webkit/glue/dom_operations.h" #include "webkit/glue/webcursor.h" namespace IPC { +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; + + // The number of bytes between subsequent rows of the bitmap. + uint32 fRowBytes; + + void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) { + fConfig = bitmap.config(); + fWidth = bitmap.width(); + fHeight = bitmap.height(); + fRowBytes = bitmap.rowBytes(); + } + + void InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels, + size_t total_pixels) const { + if (total_pixels) { + bitmap->setConfig(fConfig, fWidth, fHeight, fRowBytes); + bitmap->allocPixels(); + memcpy(bitmap->getPixels(), pixels, total_pixels); + } + } +}; + +struct WebCursor_Data { + WebCursor::Type cursor_type; + int hotspot_x; + int hotspot_y; + SkBitmap_Data bitmap_info; +}; + +} // namespace + + +void ParamTraits::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(&bmp_data), + static_cast(fixed_size)); + size_t pixel_size = p.getSize(); + SkAutoLockPixels p_lock(p); + m->WriteData(reinterpret_cast(p.getPixels()), + static_cast(pixel_size)); +} + +bool ParamTraits::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(fixed_data); + bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); + return true; +} + +void ParamTraits::Log(const SkBitmap& p, std::wstring* l) { + l->append(StringPrintf(L"")); +} + + void ParamTraits::Write(Message* m, const GURL& p) { m->WriteString(p.possibly_invalid_spec()); // TODO(brettw) bug 684583: Add encoding for query params. @@ -77,7 +161,6 @@ void ParamTraits::Log(const gfx::Point& p, std::wstring* l) { } - void ParamTraits::Write(Message* m, const gfx::Rect& p) { m->WriteInt(p.x()); m->WriteInt(p.y()); @@ -100,7 +183,8 @@ bool ParamTraits::Read(const Message* m, void** iter, gfx::Rect* r) { } void ParamTraits::Log(const gfx::Rect& p, std::wstring* l) { - l->append(StringPrintf(L"(%d, %d, %d, %d)", p.x(), p.y(), p.width(), p.height())); + l->append(StringPrintf(L"(%d, %d, %d, %d)", p.x(), p.y(), + p.width(), p.height())); } @@ -124,13 +208,6 @@ void ParamTraits::Log(const gfx::Size& p, std::wstring* l) { } -struct WebCursor_Data { - WebCursor::Type cursor_type; - int hotspot_x; - int hotspot_y; - SkBitmap_Data bitmap_info; -}; - void ParamTraits::Write(Message* m, const WebCursor& p) { const SkBitmap& src_bitmap = p.bitmap(); WebCursor_Data web_cursor_info; -- cgit v1.1