Chromium Code Reviews| 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 bitmap->allocPixels(); |
|
cpu_(ooo_6.6-7.5)
2009/04/23 16:58:23
can you check for the return value fo allocPixels(
| |
| 42 if (total_pixels > bitmap->getSize()) | |
| 43 return false; | |
| 41 memcpy(bitmap->getPixels(), pixels, total_pixels); | 44 memcpy(bitmap->getPixels(), pixels, total_pixels); |
| 42 } | 45 } |
| 46 return true; | |
| 43 } | 47 } |
| 44 }; | 48 }; |
| 45 | 49 |
| 46 } // namespace | 50 } // namespace |
| 47 | 51 |
| 48 | 52 |
| 49 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { | 53 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { |
| 50 size_t fixed_size = sizeof(SkBitmap_Data); | 54 size_t fixed_size = sizeof(SkBitmap_Data); |
| 51 SkBitmap_Data bmp_data; | 55 SkBitmap_Data bmp_data; |
| 52 bmp_data.InitSkBitmapDataForTransfer(p); | 56 bmp_data.InitSkBitmapDataForTransfer(p); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 71 | 75 |
| 72 const char* variable_data; | 76 const char* variable_data; |
| 73 int variable_data_size = 0; | 77 int variable_data_size = 0; |
| 74 if (!m->ReadData(iter, &variable_data, &variable_data_size) || | 78 if (!m->ReadData(iter, &variable_data, &variable_data_size) || |
| 75 (variable_data_size < 0)) { | 79 (variable_data_size < 0)) { |
| 76 NOTREACHED(); | 80 NOTREACHED(); |
| 77 return false; | 81 return false; |
| 78 } | 82 } |
| 79 const SkBitmap_Data* bmp_data = | 83 const SkBitmap_Data* bmp_data = |
| 80 reinterpret_cast<const SkBitmap_Data*>(fixed_data); | 84 reinterpret_cast<const SkBitmap_Data*>(fixed_data); |
| 81 bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); | 85 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); |
| 82 return true; | |
| 83 } | 86 } |
| 84 | 87 |
| 85 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::wstring* l) { | 88 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::wstring* l) { |
| 86 l->append(StringPrintf(L"<SkBitmap>")); | 89 l->append(StringPrintf(L"<SkBitmap>")); |
| 87 } | 90 } |
| 88 | 91 |
| 89 | 92 |
| 90 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { | 93 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { |
| 91 m->WriteString(p.possibly_invalid_spec()); | 94 m->WriteString(p.possibly_invalid_spec()); |
| 92 // TODO(brettw) bug 684583: Add encoding for query params. | 95 // TODO(brettw) bug 684583: Add encoding for query params. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 } | 210 } |
| 208 return result; | 211 return result; |
| 209 } | 212 } |
| 210 | 213 |
| 211 void ParamTraits<webkit_glue::WebApplicationInfo>::Log( | 214 void ParamTraits<webkit_glue::WebApplicationInfo>::Log( |
| 212 const webkit_glue::WebApplicationInfo& p, std::wstring* l) { | 215 const webkit_glue::WebApplicationInfo& p, std::wstring* l) { |
| 213 l->append(L"<WebApplicationInfo>"); | 216 l->append(L"<WebApplicationInfo>"); |
| 214 } | 217 } |
| 215 | 218 |
| 216 } // namespace IPC | 219 } // namespace IPC |
| OLD | NEW |