| 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 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "content/common/pepper_file_util.h" | 12 #include "content/common/pepper_file_util.h" |
| 13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 14 #include "content/renderer/render_thread_impl.h" | 14 #include "content/renderer/render_thread_impl.h" |
| 15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
| 16 #include "ppapi/c/pp_instance.h" | 16 #include "ppapi/c/pp_instance.h" |
| 17 #include "ppapi/c/pp_resource.h" | 17 #include "ppapi/c/pp_resource.h" |
| 18 #include "ppapi/c/ppb_image_data.h" | 18 #include "ppapi/c/ppb_image_data.h" |
| 19 #include "ppapi/thunk/thunk.h" | 19 #include "ppapi/thunk/thunk.h" |
| 20 #include "skia/ext/cdl_canvas.h" |
| 20 #include "skia/ext/platform_canvas.h" | 21 #include "skia/ext/platform_canvas.h" |
| 21 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
| 22 #include "third_party/skia/include/core/SkColorPriv.h" | 23 #include "third_party/skia/include/core/SkColorPriv.h" |
| 23 #include "third_party/skia/include/core/SkDevice.h" | 24 #include "third_party/skia/include/core/SkDevice.h" |
| 24 #include "third_party/skia/include/core/SkPixmap.h" | 25 #include "third_party/skia/include/core/SkPixmap.h" |
| 25 #include "ui/surface/transport_dib.h" | 26 #include "ui/surface/transport_dib.h" |
| 26 | 27 |
| 27 using ppapi::thunk::PPB_ImageData_API; | 28 using ppapi::thunk::PPB_ImageData_API; |
| 28 | 29 |
| 29 namespace content { | 30 namespace content { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 107 |
| 107 void* PPB_ImageData_Impl::Map() { return backend_->Map(); } | 108 void* PPB_ImageData_Impl::Map() { return backend_->Map(); } |
| 108 | 109 |
| 109 void PPB_ImageData_Impl::Unmap() { backend_->Unmap(); } | 110 void PPB_ImageData_Impl::Unmap() { backend_->Unmap(); } |
| 110 | 111 |
| 111 int32_t PPB_ImageData_Impl::GetSharedMemory(base::SharedMemory** shm, | 112 int32_t PPB_ImageData_Impl::GetSharedMemory(base::SharedMemory** shm, |
| 112 uint32_t* byte_count) { | 113 uint32_t* byte_count) { |
| 113 return backend_->GetSharedMemory(shm, byte_count); | 114 return backend_->GetSharedMemory(shm, byte_count); |
| 114 } | 115 } |
| 115 | 116 |
| 116 SkCanvas* PPB_ImageData_Impl::GetPlatformCanvas() { | 117 CdlCanvas* PPB_ImageData_Impl::GetPlatformCanvas() { |
| 117 return backend_->GetPlatformCanvas(); | 118 return backend_->GetPlatformCanvas(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 SkCanvas* PPB_ImageData_Impl::GetCanvas() { return backend_->GetCanvas(); } | 121 CdlCanvas* PPB_ImageData_Impl::GetCanvas() { |
| 122 return backend_->GetCanvas(); |
| 123 } |
| 121 | 124 |
| 122 void PPB_ImageData_Impl::SetIsCandidateForReuse() { | 125 void PPB_ImageData_Impl::SetIsCandidateForReuse() { |
| 123 // Nothing to do since we don't support image data re-use in-process. | 126 // Nothing to do since we don't support image data re-use in-process. |
| 124 } | 127 } |
| 125 | 128 |
| 126 SkBitmap PPB_ImageData_Impl::GetMappedBitmap() const { | 129 SkBitmap PPB_ImageData_Impl::GetMappedBitmap() const { |
| 127 return backend_->GetMappedBitmap(); | 130 return backend_->GetMappedBitmap(); |
| 128 } | 131 } |
| 129 | 132 |
| 130 // ImageDataPlatformBackend ---------------------------------------------------- | 133 // ImageDataPlatformBackend ---------------------------------------------------- |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // in the future to save some memory. | 194 // in the future to save some memory. |
| 192 } | 195 } |
| 193 | 196 |
| 194 int32_t ImageDataPlatformBackend::GetSharedMemory(base::SharedMemory** shm, | 197 int32_t ImageDataPlatformBackend::GetSharedMemory(base::SharedMemory** shm, |
| 195 uint32_t* byte_count) { | 198 uint32_t* byte_count) { |
| 196 *byte_count = dib_->size(); | 199 *byte_count = dib_->size(); |
| 197 *shm = dib_->shared_memory(); | 200 *shm = dib_->shared_memory(); |
| 198 return PP_OK; | 201 return PP_OK; |
| 199 } | 202 } |
| 200 | 203 |
| 201 SkCanvas* ImageDataPlatformBackend::GetPlatformCanvas() { | 204 CdlCanvas* ImageDataPlatformBackend::GetPlatformCanvas() { |
| 202 return mapped_canvas_.get(); | 205 return mapped_canvas_.get(); |
| 203 } | 206 } |
| 204 | 207 |
| 205 SkCanvas* ImageDataPlatformBackend::GetCanvas() { return mapped_canvas_.get(); } | 208 CdlCanvas* ImageDataPlatformBackend::GetCanvas() { |
| 209 return mapped_canvas_.get(); |
| 210 } |
| 206 | 211 |
| 207 SkBitmap ImageDataPlatformBackend::GetMappedBitmap() const { | 212 SkBitmap ImageDataPlatformBackend::GetMappedBitmap() const { |
| 208 SkBitmap bitmap; | 213 SkBitmap bitmap; |
| 209 if (!mapped_canvas_) | 214 if (!mapped_canvas_) |
| 210 return bitmap; | 215 return bitmap; |
| 211 | 216 |
| 212 SkPixmap pixmap; | 217 SkPixmap pixmap; |
| 213 skia::GetWritablePixels(mapped_canvas_.get(), &pixmap); | 218 skia::GetWritablePixels(mapped_canvas_.get(), &pixmap); |
| 214 // SkPixmap does not manage the lifetime of this pointer, so it remains | 219 // SkPixmap does not manage the lifetime of this pointer, so it remains |
| 215 // valid after the object goes out of scope. It will become invalid if | 220 // valid after the object goes out of scope. It will become invalid if |
| (...skipping 26 matching lines...) Expand all Loading... |
| 242 | 247 |
| 243 TransportDIB* ImageDataSimpleBackend::GetTransportDIB() const { return NULL; } | 248 TransportDIB* ImageDataSimpleBackend::GetTransportDIB() const { return NULL; } |
| 244 | 249 |
| 245 void* ImageDataSimpleBackend::Map() { | 250 void* ImageDataSimpleBackend::Map() { |
| 246 DCHECK(shared_memory_.get()); | 251 DCHECK(shared_memory_.get()); |
| 247 if (map_count_++ == 0) { | 252 if (map_count_++ == 0) { |
| 248 shared_memory_->Map(skia_bitmap_.getSize()); | 253 shared_memory_->Map(skia_bitmap_.getSize()); |
| 249 skia_bitmap_.setPixels(shared_memory_->memory()); | 254 skia_bitmap_.setPixels(shared_memory_->memory()); |
| 250 // Our platform bitmaps are set to opaque by default, which we don't want. | 255 // Our platform bitmaps are set to opaque by default, which we don't want. |
| 251 skia_bitmap_.setAlphaType(kPremul_SkAlphaType); | 256 skia_bitmap_.setAlphaType(kPremul_SkAlphaType); |
| 252 skia_canvas_ = base::MakeUnique<SkCanvas>(skia_bitmap_); | 257 skia_canvas_ = base::MakeUnique<CdlCanvas>(skia_bitmap_); |
| 253 return skia_bitmap_.getAddr32(0, 0); | 258 return skia_bitmap_.getAddr32(0, 0); |
| 254 } | 259 } |
| 255 return shared_memory_->memory(); | 260 return shared_memory_->memory(); |
| 256 } | 261 } |
| 257 | 262 |
| 258 void ImageDataSimpleBackend::Unmap() { | 263 void ImageDataSimpleBackend::Unmap() { |
| 259 if (--map_count_ == 0) | 264 if (--map_count_ == 0) |
| 260 shared_memory_->Unmap(); | 265 shared_memory_->Unmap(); |
| 261 } | 266 } |
| 262 | 267 |
| 263 int32_t ImageDataSimpleBackend::GetSharedMemory(base::SharedMemory** shm, | 268 int32_t ImageDataSimpleBackend::GetSharedMemory(base::SharedMemory** shm, |
| 264 uint32_t* byte_count) { | 269 uint32_t* byte_count) { |
| 265 *byte_count = skia_bitmap_.getSize(); | 270 *byte_count = skia_bitmap_.getSize(); |
| 266 *shm = shared_memory_.get(); | 271 *shm = shared_memory_.get(); |
| 267 return PP_OK; | 272 return PP_OK; |
| 268 } | 273 } |
| 269 | 274 |
| 270 SkCanvas* ImageDataSimpleBackend::GetPlatformCanvas() { | 275 CdlCanvas* ImageDataSimpleBackend::GetPlatformCanvas() { |
| 271 return NULL; | 276 return NULL; |
| 272 } | 277 } |
| 273 | 278 |
| 274 SkCanvas* ImageDataSimpleBackend::GetCanvas() { | 279 CdlCanvas* ImageDataSimpleBackend::GetCanvas() { |
| 275 if (!IsMapped()) | 280 if (!IsMapped()) |
| 276 return NULL; | 281 return NULL; |
| 277 return skia_canvas_.get(); | 282 return skia_canvas_.get(); |
| 278 } | 283 } |
| 279 | 284 |
| 280 SkBitmap ImageDataSimpleBackend::GetMappedBitmap() const { | 285 SkBitmap ImageDataSimpleBackend::GetMappedBitmap() const { |
| 281 if (!IsMapped()) | 286 if (!IsMapped()) |
| 282 return SkBitmap(); | 287 return SkBitmap(); |
| 283 return skia_bitmap_; | 288 return skia_bitmap_; |
| 284 } | 289 } |
| 285 | 290 |
| 286 } // namespace content | 291 } // namespace content |
| OLD | NEW |