| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/common/ipc_message_utils.h" | 5 #include "chrome/common/ipc_message_utils.h" |
| 6 | 6 |
| 7 #include "base/gfx/rect.h" | 7 #include "base/gfx/rect.h" |
| 8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "webkit/glue/dom_operations.h" | 10 #include "webkit/glue/dom_operations.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // The number of bytes between subsequent rows of the bitmap. | 26 // The number of bytes between subsequent rows of the bitmap. |
| 27 uint32 fRowBytes; | 27 uint32 fRowBytes; |
| 28 | 28 |
| 29 void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) { | 29 void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) { |
| 30 fConfig = bitmap.config(); | 30 fConfig = bitmap.config(); |
| 31 fWidth = bitmap.width(); | 31 fWidth = bitmap.width(); |
| 32 fHeight = bitmap.height(); | 32 fHeight = bitmap.height(); |
| 33 fRowBytes = bitmap.rowBytes(); | 33 fRowBytes = bitmap.rowBytes(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels, | 36 // Returns whether |bitmap| successfully initialized. |
| 37 bool InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels, |
| 37 size_t total_pixels) const { | 38 size_t total_pixels) const { |
| 38 if (total_pixels) { | 39 if (total_pixels) { |
| 39 bitmap->setConfig(fConfig, fWidth, fHeight, fRowBytes); | 40 bitmap->setConfig(fConfig, fWidth, fHeight, fRowBytes); |
| 40 bitmap->allocPixels(); | 41 if (!bitmap->allocPixels()) |
| 42 return false; |
| 43 if (total_pixels > bitmap->getSize()) |
| 44 return false; |
| 41 memcpy(bitmap->getPixels(), pixels, total_pixels); | 45 memcpy(bitmap->getPixels(), pixels, total_pixels); |
| 42 } | 46 } |
| 47 return true; |
| 43 } | 48 } |
| 44 }; | 49 }; |
| 45 | 50 |
| 46 } // namespace | 51 } // namespace |
| 47 | 52 |
| 48 | 53 |
| 49 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { | 54 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { |
| 50 size_t fixed_size = sizeof(SkBitmap_Data); | 55 size_t fixed_size = sizeof(SkBitmap_Data); |
| 51 SkBitmap_Data bmp_data; | 56 SkBitmap_Data bmp_data; |
| 52 bmp_data.InitSkBitmapDataForTransfer(p); | 57 bmp_data.InitSkBitmapDataForTransfer(p); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 71 | 76 |
| 72 const char* variable_data; | 77 const char* variable_data; |
| 73 int variable_data_size = 0; | 78 int variable_data_size = 0; |
| 74 if (!m->ReadData(iter, &variable_data, &variable_data_size) || | 79 if (!m->ReadData(iter, &variable_data, &variable_data_size) || |
| 75 (variable_data_size < 0)) { | 80 (variable_data_size < 0)) { |
| 76 NOTREACHED(); | 81 NOTREACHED(); |
| 77 return false; | 82 return false; |
| 78 } | 83 } |
| 79 const SkBitmap_Data* bmp_data = | 84 const SkBitmap_Data* bmp_data = |
| 80 reinterpret_cast<const SkBitmap_Data*>(fixed_data); | 85 reinterpret_cast<const SkBitmap_Data*>(fixed_data); |
| 81 bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); | 86 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); |
| 82 return true; | |
| 83 } | 87 } |
| 84 | 88 |
| 85 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::wstring* l) { | 89 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::wstring* l) { |
| 86 l->append(StringPrintf(L"<SkBitmap>")); | 90 l->append(StringPrintf(L"<SkBitmap>")); |
| 87 } | 91 } |
| 88 | 92 |
| 89 | 93 |
| 90 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { | 94 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { |
| 91 m->WriteString(p.possibly_invalid_spec()); | 95 m->WriteString(p.possibly_invalid_spec()); |
| 92 // TODO(brettw) bug 684583: Add encoding for query params. | 96 // TODO(brettw) bug 684583: Add encoding for query params. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 211 } |
| 208 return result; | 212 return result; |
| 209 } | 213 } |
| 210 | 214 |
| 211 void ParamTraits<webkit_glue::WebApplicationInfo>::Log( | 215 void ParamTraits<webkit_glue::WebApplicationInfo>::Log( |
| 212 const webkit_glue::WebApplicationInfo& p, std::wstring* l) { | 216 const webkit_glue::WebApplicationInfo& p, std::wstring* l) { |
| 213 l->append(L"<WebApplicationInfo>"); | 217 l->append(L"<WebApplicationInfo>"); |
| 214 } | 218 } |
| 215 | 219 |
| 216 } // namespace IPC | 220 } // namespace IPC |
| OLD | NEW |