Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Unified Diff: content/common/common_param_traits.cc

Issue 6705012: Move the rest of the content browser->renderer messages to content. Also move drag related messa... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/common_param_traits.h ('k') | content/common/content_message_generator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « content/common/common_param_traits.h ('k') | content/common/content_message_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698