OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file | 5 * found in the LICENSE file |
6 */ | 6 */ |
7 | 7 |
8 #include "SkSpecialImage.h" | 8 #include "SkSpecialImage.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkImage.h" | 10 #include "SkImage.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 202 } |
203 return nullptr; | 203 return nullptr; |
204 } | 204 } |
205 | 205 |
206 /////////////////////////////////////////////////////////////////////////////// | 206 /////////////////////////////////////////////////////////////////////////////// |
207 | 207 |
208 class SkSpecialImage_Raster : public SkSpecialImage_Base { | 208 class SkSpecialImage_Raster : public SkSpecialImage_Base { |
209 public: | 209 public: |
210 SkSpecialImage_Raster(const SkIRect& subset, const SkBitmap& bm, const SkSur
faceProps* props) | 210 SkSpecialImage_Raster(const SkIRect& subset, const SkBitmap& bm, const SkSur
faceProps* props) |
211 : INHERITED(subset, bm.getGenerationID(), props) | 211 : INHERITED(subset, bm.getGenerationID(), props) |
212 , fBitmap(bm) { | 212 , fBitmap(bm) |
213 if (bm.pixelRef() && bm.pixelRef()->isPreLocked()) { | 213 { |
214 // we only preemptively lock if there is no chance of triggering som
ething expensive | 214 SkASSERT(bm.pixelRef()); |
215 // like a lazy decode or imagegenerator. PreLocked means it is flat
pixels already. | 215 |
216 fBitmap.lockPixels(); | 216 // We have to lock now, while bm is still in scope, since it may have co
me from our |
217 } | 217 // cache, which means we need to keep it locked until we (the special) a
re done, since |
| 218 // we cannot re-generate the cache entry (if bm came from a generator). |
| 219 fBitmap.lockPixels(); |
| 220 SkASSERT(fBitmap.getPixels()); |
218 } | 221 } |
219 | 222 |
220 bool isOpaque() const override { return fBitmap.isOpaque(); } | 223 bool isOpaque() const override { return fBitmap.isOpaque(); } |
221 | 224 |
222 size_t getSize() const override { return fBitmap.getSize(); } | 225 size_t getSize() const override { return fBitmap.getSize(); } |
223 | 226 |
224 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { | 227 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
225 SkRect dst = SkRect::MakeXYWH(x, y, | 228 SkRect dst = SkRect::MakeXYWH(x, y, |
226 this->subset().width(), this->subset().hei
ght()); | 229 this->subset().width(), this->subset().hei
ght()); |
227 | 230 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 SkBitmap fBitmap; | 288 SkBitmap fBitmap; |
286 | 289 |
287 typedef SkSpecialImage_Base INHERITED; | 290 typedef SkSpecialImage_Base INHERITED; |
288 }; | 291 }; |
289 | 292 |
290 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, | 293 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, |
291 const SkBitmap& bm, | 294 const SkBitmap& bm, |
292 const SkSurfaceProps* props
) { | 295 const SkSurfaceProps* props
) { |
293 SkASSERT(rect_fits(subset, bm.width(), bm.height())); | 296 SkASSERT(rect_fits(subset, bm.width(), bm.height())); |
294 | 297 |
| 298 if (!bm.pixelRef()) { |
| 299 return nullptr; |
| 300 } |
| 301 |
295 const SkBitmap* srcBM = &bm; | 302 const SkBitmap* srcBM = &bm; |
296 SkBitmap tmpStorage; | 303 SkBitmap tmpStorage; |
297 // ImageFilters only handle N32 at the moment, so force our src to be that | 304 // ImageFilters only handle N32 at the moment, so force our src to be that |
298 if (!valid_for_imagefilters(bm.info())) { | 305 if (!valid_for_imagefilters(bm.info())) { |
299 if (!bm.copyTo(&tmpStorage, kN32_SkColorType)) { | 306 if (!bm.copyTo(&tmpStorage, kN32_SkColorType)) { |
300 return nullptr; | 307 return nullptr; |
301 } | 308 } |
302 srcBM = &tmpStorage; | 309 srcBM = &tmpStorage; |
303 } | 310 } |
304 return sk_make_sp<SkSpecialImage_Raster>(subset, *srcBM, props); | 311 return sk_make_sp<SkSpecialImage_Raster>(subset, *srcBM, props); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 sk_sp<GrTexture> tex, | 452 sk_sp<GrTexture> tex, |
446 sk_sp<SkColorSpace> colorSpace
, | 453 sk_sp<SkColorSpace> colorSpace
, |
447 const SkSurfaceProps* props, | 454 const SkSurfaceProps* props, |
448 SkAlphaType at) { | 455 SkAlphaType at) { |
449 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 456 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
450 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, | 457 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, |
451 std::move(colorSpace), props); | 458 std::move(colorSpace), props); |
452 } | 459 } |
453 | 460 |
454 #endif | 461 #endif |
OLD | NEW |