| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/ppb_image_data_impl.h" | 5 #include "content/renderer/pepper/ppb_image_data_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 bool PPB_ImageData_Impl::Init(PP_ImageDataFormat format, | 58 bool PPB_ImageData_Impl::Init(PP_ImageDataFormat format, |
| 59 int width, | 59 int width, |
| 60 int height, | 60 int height, |
| 61 bool init_to_zero) { | 61 bool init_to_zero) { |
| 62 // TODO(brettw) this should be called only on the main thread! | 62 // TODO(brettw) this should be called only on the main thread! |
| 63 if (!IsImageDataFormatSupported(format)) | 63 if (!IsImageDataFormatSupported(format)) |
| 64 return false; // Only support this one format for now. | 64 return false; // Only support this one format for now. |
| 65 if (width <= 0 || height <= 0) | 65 if (width <= 0 || height <= 0) |
| 66 return false; | 66 return false; |
| 67 if (static_cast<int64>(width) * static_cast<int64>(height) >= | 67 if (static_cast<int64_t>(width) * static_cast<int64_t>(height) >= |
| 68 std::numeric_limits<int32>::max() / 4) | 68 std::numeric_limits<int32_t>::max() / 4) |
| 69 return false; // Prevent overflow of signed 32-bit ints. | 69 return false; // Prevent overflow of signed 32-bit ints. |
| 70 | 70 |
| 71 format_ = format; | 71 format_ = format; |
| 72 width_ = width; | 72 width_ = width; |
| 73 height_ = height; | 73 height_ = height; |
| 74 return backend_->Init(this, format, width, height, init_to_zero); | 74 return backend_->Init(this, format, width, height, init_to_zero); |
| 75 } | 75 } |
| 76 | 76 |
| 77 // static | 77 // static |
| 78 PP_Resource PPB_ImageData_Impl::Create(PP_Instance instance, | 78 PP_Resource PPB_ImageData_Impl::Create(PP_Instance instance, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool ImageDataPlatformBackend::Init(PPB_ImageData_Impl* impl, | 137 bool ImageDataPlatformBackend::Init(PPB_ImageData_Impl* impl, |
| 138 PP_ImageDataFormat format, | 138 PP_ImageDataFormat format, |
| 139 int width, | 139 int width, |
| 140 int height, | 140 int height, |
| 141 bool init_to_zero) { | 141 bool init_to_zero) { |
| 142 // TODO(brettw) use init_to_zero when we implement caching. | 142 // TODO(brettw) use init_to_zero when we implement caching. |
| 143 width_ = width; | 143 width_ = width; |
| 144 height_ = height; | 144 height_ = height; |
| 145 uint32 buffer_size = width_ * height_ * 4; | 145 uint32_t buffer_size = width_ * height_ * 4; |
| 146 scoped_ptr<base::SharedMemory> shared_memory = | 146 scoped_ptr<base::SharedMemory> shared_memory = |
| 147 RenderThread::Get()->HostAllocateSharedMemoryBuffer(buffer_size); | 147 RenderThread::Get()->HostAllocateSharedMemoryBuffer(buffer_size); |
| 148 if (!shared_memory) | 148 if (!shared_memory) |
| 149 return false; | 149 return false; |
| 150 | 150 |
| 151 // The TransportDIB is always backed by shared memory, so give the shared | 151 // The TransportDIB is always backed by shared memory, so give the shared |
| 152 // memory handle to it. | 152 // memory handle to it. |
| 153 base::SharedMemoryHandle handle; | 153 base::SharedMemoryHandle handle; |
| 154 if (!shared_memory->GiveToProcess(base::GetCurrentProcessHandle(), &handle)) | 154 if (!shared_memory->GiveToProcess(base::GetCurrentProcessHandle(), &handle)) |
| 155 return false; | 155 return false; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 return skia_canvas_.get(); | 268 return skia_canvas_.get(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 const SkBitmap* ImageDataSimpleBackend::GetMappedBitmap() const { | 271 const SkBitmap* ImageDataSimpleBackend::GetMappedBitmap() const { |
| 272 if (!IsMapped()) | 272 if (!IsMapped()) |
| 273 return NULL; | 273 return NULL; |
| 274 return &skia_bitmap_; | 274 return &skia_bitmap_; |
| 275 } | 275 } |
| 276 | 276 |
| 277 } // namespace content | 277 } // namespace content |
| OLD | NEW |