summaryrefslogtreecommitdiffstats
path: root/chrome/common/ipc_message_utils.cc
diff options
context:
space:
mode:
authormaruel@google.com <maruel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-12 15:22:13 +0000
committermaruel@google.com <maruel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-12 15:22:13 +0000
commite1981f43505c69351e5786eac1bff1913f4c96db (patch)
tree9be2552eea732795716489cba689918dc5dd74a3 /chrome/common/ipc_message_utils.cc
parent169da8f5bba74250fe73f708a1a3b666b4fb2431 (diff)
downloadchromium_src-e1981f43505c69351e5786eac1bff1913f4c96db.zip
chromium_src-e1981f43505c69351e5786eac1bff1913f4c96db.tar.gz
chromium_src-e1981f43505c69351e5786eac1bff1913f4c96db.tar.bz2
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
Diffstat (limited to 'chrome/common/ipc_message_utils.cc')
-rw-r--r--chrome/common/ipc_message_utils.cc95
1 files changed, 86 insertions, 9 deletions
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<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);
+ bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size);
+ return true;
+}
+
+void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::wstring* l) {
+ l->append(StringPrintf(L"<SkBitmap>"));
+}
+
+
void ParamTraits<GURL>::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<gfx::Point>::Log(const gfx::Point& p, std::wstring* l) {
}
-
void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) {
m->WriteInt(p.x());
m->WriteInt(p.y());
@@ -100,7 +183,8 @@ bool ParamTraits<gfx::Rect>::Read(const Message* m, void** iter, gfx::Rect* r) {
}
void ParamTraits<gfx::Rect>::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<gfx::Size>::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<WebCursor>::Write(Message* m, const WebCursor& p) {
const SkBitmap& src_bitmap = p.bitmap();
WebCursor_Data web_cursor_info;