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 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 return !!mapped_canvas_.get(); | 164 return !!mapped_canvas_.get(); |
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_ = dib_->GetPlatformCanvas(width_, height_, is_opaque); | 174 mapped_canvas_ = |
| 175 sk_sp<SkCanvas>(dib_->GetPlatformCanvas(width_, height_, is_opaque)); |
175 if (!mapped_canvas_) | 176 if (!mapped_canvas_) |
176 return NULL; | 177 return NULL; |
177 } | 178 } |
178 SkPixmap pixmap; | 179 SkPixmap pixmap; |
179 skia::GetWritablePixels(mapped_canvas_.get(), &pixmap); | 180 skia::GetWritablePixels(mapped_canvas_.get(), &pixmap); |
180 DCHECK(pixmap.addr()); | 181 DCHECK(pixmap.addr()); |
181 // 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 |
182 // 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 |
183 // the canvas' backing is destroyed or a pending saveLayer() is resolved. | 184 // the canvas' backing is destroyed or a pending saveLayer() is resolved. |
184 return pixmap.writable_addr32(0, 0); | 185 return pixmap.writable_addr32(0, 0); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 243 |
243 TransportDIB* ImageDataSimpleBackend::GetTransportDIB() const { return NULL; } | 244 TransportDIB* ImageDataSimpleBackend::GetTransportDIB() const { return NULL; } |
244 | 245 |
245 void* ImageDataSimpleBackend::Map() { | 246 void* ImageDataSimpleBackend::Map() { |
246 DCHECK(shared_memory_.get()); | 247 DCHECK(shared_memory_.get()); |
247 if (map_count_++ == 0) { | 248 if (map_count_++ == 0) { |
248 shared_memory_->Map(skia_bitmap_.getSize()); | 249 shared_memory_->Map(skia_bitmap_.getSize()); |
249 skia_bitmap_.setPixels(shared_memory_->memory()); | 250 skia_bitmap_.setPixels(shared_memory_->memory()); |
250 // Our platform bitmaps are set to opaque by default, which we don't want. | 251 // Our platform bitmaps are set to opaque by default, which we don't want. |
251 skia_bitmap_.setAlphaType(kPremul_SkAlphaType); | 252 skia_bitmap_.setAlphaType(kPremul_SkAlphaType); |
252 skia_canvas_ = base::MakeUnique<SkCanvas>(skia_bitmap_); | 253 skia_canvas_ = sk_make_sp<SkCanvas>(skia_bitmap_); |
253 return skia_bitmap_.getAddr32(0, 0); | 254 return skia_bitmap_.getAddr32(0, 0); |
254 } | 255 } |
255 return shared_memory_->memory(); | 256 return shared_memory_->memory(); |
256 } | 257 } |
257 | 258 |
258 void ImageDataSimpleBackend::Unmap() { | 259 void ImageDataSimpleBackend::Unmap() { |
259 if (--map_count_ == 0) | 260 if (--map_count_ == 0) |
260 shared_memory_->Unmap(); | 261 shared_memory_->Unmap(); |
261 } | 262 } |
262 | 263 |
(...skipping 14 matching lines...) Expand all Loading... |
277 return skia_canvas_.get(); | 278 return skia_canvas_.get(); |
278 } | 279 } |
279 | 280 |
280 SkBitmap ImageDataSimpleBackend::GetMappedBitmap() const { | 281 SkBitmap ImageDataSimpleBackend::GetMappedBitmap() const { |
281 if (!IsMapped()) | 282 if (!IsMapped()) |
282 return SkBitmap(); | 283 return SkBitmap(); |
283 return skia_bitmap_; | 284 return skia_bitmap_; |
284 } | 285 } |
285 | 286 |
286 } // namespace content | 287 } // namespace content |
OLD | NEW |