| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 165 } |
| 166 | 166 |
| 167 TransportDIB* ImageDataPlatformBackend::GetTransportDIB() const { | 167 TransportDIB* ImageDataPlatformBackend::GetTransportDIB() const { |
| 168 return dib_.get(); | 168 return dib_.get(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void* ImageDataPlatformBackend::Map() { | 171 void* ImageDataPlatformBackend::Map() { |
| 172 if (!mapped_canvas_) { | 172 if (!mapped_canvas_) { |
| 173 const bool is_opaque = false; | 173 const bool is_opaque = false; |
| 174 mapped_canvas_ = | 174 mapped_canvas_ = |
| 175 skia::AdoptRef(dib_->GetPlatformCanvas(width_, height_, is_opaque)); | 175 sk_sp<SkCanvas>(dib_->GetPlatformCanvas(width_, height_, is_opaque)); |
| 176 if (!mapped_canvas_) | 176 if (!mapped_canvas_) |
| 177 return NULL; | 177 return NULL; |
| 178 } | 178 } |
| 179 SkPixmap pixmap; | 179 SkPixmap pixmap; |
| 180 skia::GetWritablePixels(mapped_canvas_.get(), &pixmap); | 180 skia::GetWritablePixels(mapped_canvas_.get(), &pixmap); |
| 181 DCHECK(pixmap.addr()); | 181 DCHECK(pixmap.addr()); |
| 182 // SkPixmap does not manage the lifetime of this pointer, so it remains | 182 // SkPixmap does not manage the lifetime of this pointer, so it remains |
| 183 // valid after the object goes out of scope. It will become invalid if | 183 // valid after the object goes out of scope. It will become invalid if |
| 184 // the canvas' backing is destroyed or a pending saveLayer() is resolved. | 184 // the canvas' backing is destroyed or a pending saveLayer() is resolved. |
| 185 return pixmap.writable_addr32(0, 0); | 185 return pixmap.writable_addr32(0, 0); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 TransportDIB* ImageDataSimpleBackend::GetTransportDIB() const { return NULL; } | 236 TransportDIB* ImageDataSimpleBackend::GetTransportDIB() const { return NULL; } |
| 237 | 237 |
| 238 void* ImageDataSimpleBackend::Map() { | 238 void* ImageDataSimpleBackend::Map() { |
| 239 DCHECK(shared_memory_.get()); | 239 DCHECK(shared_memory_.get()); |
| 240 if (map_count_++ == 0) { | 240 if (map_count_++ == 0) { |
| 241 shared_memory_->Map(skia_bitmap_.getSize()); | 241 shared_memory_->Map(skia_bitmap_.getSize()); |
| 242 skia_bitmap_.setPixels(shared_memory_->memory()); | 242 skia_bitmap_.setPixels(shared_memory_->memory()); |
| 243 // Our platform bitmaps are set to opaque by default, which we don't want. | 243 // Our platform bitmaps are set to opaque by default, which we don't want. |
| 244 skia_bitmap_.setAlphaType(kPremul_SkAlphaType); | 244 skia_bitmap_.setAlphaType(kPremul_SkAlphaType); |
| 245 skia_canvas_ = skia::AdoptRef(new SkCanvas(skia_bitmap_)); | 245 skia_canvas_ = sk_make_sp<SkCanvas>(skia_bitmap_); |
| 246 return skia_bitmap_.getAddr32(0, 0); | 246 return skia_bitmap_.getAddr32(0, 0); |
| 247 } | 247 } |
| 248 return shared_memory_->memory(); | 248 return shared_memory_->memory(); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void ImageDataSimpleBackend::Unmap() { | 251 void ImageDataSimpleBackend::Unmap() { |
| 252 if (--map_count_ == 0) | 252 if (--map_count_ == 0) |
| 253 shared_memory_->Unmap(); | 253 shared_memory_->Unmap(); |
| 254 } | 254 } |
| 255 | 255 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 270 return skia_canvas_.get(); | 270 return skia_canvas_.get(); |
| 271 } | 271 } |
| 272 | 272 |
| 273 const SkBitmap* ImageDataSimpleBackend::GetMappedBitmap() const { | 273 const SkBitmap* ImageDataSimpleBackend::GetMappedBitmap() const { |
| 274 if (!IsMapped()) | 274 if (!IsMapped()) |
| 275 return NULL; | 275 return NULL; |
| 276 return &skia_bitmap_; | 276 return &skia_bitmap_; |
| 277 } | 277 } |
| 278 | 278 |
| 279 } // namespace content | 279 } // namespace content |
| OLD | NEW |