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 #include "SkSpecialImage.h" | 7 #include "SkSpecialImage.h" |
8 | 8 |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
11 #include "GrTextureParams.h" | 11 #include "GrTextureParams.h" |
12 #include "SkGr.h" | 12 #include "SkGr.h" |
13 #endif | 13 #endif |
14 | 14 |
15 #include "SkBitmapCache.h" | 15 #include "SkBitmapCache.h" |
16 #include "SkCanvas.h" | 16 #include "SkCanvas.h" |
17 #include "SkImage_Base.h" | 17 #include "SkImage_Base.h" |
18 #include "SkSpecialSurface.h" | 18 #include "SkSpecialSurface.h" |
19 #include "SkSurfacePriv.h" | 19 #include "SkSurfacePriv.h" |
20 | 20 |
robertphillips
2016/07/20 12:20:05
// The raster-specific image filters are written s
| |
21 static bool valid_for_imagefilters(const SkImageInfo& info) { | |
22 return info.colorType() == kN32_SkColorType; | |
23 } | |
24 | |
21 /////////////////////////////////////////////////////////////////////////////// | 25 /////////////////////////////////////////////////////////////////////////////// |
22 class SkSpecialImage_Base : public SkSpecialImage { | 26 class SkSpecialImage_Base : public SkSpecialImage { |
23 public: | 27 public: |
24 SkSpecialImage_Base(const SkIRect& subset, uint32_t uniqueID, const SkSurfac eProps* props) | 28 SkSpecialImage_Base(const SkIRect& subset, uint32_t uniqueID, const SkSurfac eProps* props) |
25 : INHERITED(subset, uniqueID, props) { | 29 : INHERITED(subset, uniqueID, props) { |
26 } | 30 } |
27 ~SkSpecialImage_Base() override { } | 31 ~SkSpecialImage_Base() override { } |
28 | 32 |
29 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const = 0; | 33 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const = 0; |
30 | 34 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 rect.fRight >= 0 && rect.fRight <= width && | 311 rect.fRight >= 0 && rect.fRight <= width && |
308 rect.fTop >= 0 && rect.fTop < height && rect.fTop < rect.fBottom && | 312 rect.fTop >= 0 && rect.fTop < height && rect.fTop < rect.fBottom && |
309 rect.fBottom >= 0 && rect.fBottom <= height; | 313 rect.fBottom >= 0 && rect.fBottom <= height; |
310 } | 314 } |
311 #endif | 315 #endif |
312 | 316 |
313 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(const SkIRect& subset, | 317 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(const SkIRect& subset, |
314 sk_sp<SkImage> image, | 318 sk_sp<SkImage> image, |
315 const SkSurfaceProps* props) { | 319 const SkSurfaceProps* props) { |
316 SkASSERT(rect_fits(subset, image->width(), image->height())); | 320 SkASSERT(rect_fits(subset, image->width(), image->height())); |
317 | 321 |
robertphillips
2016/07/20 12:20:05
GPU-backed SkImages should work fine
| |
318 return sk_make_sp<SkSpecialImage_Image>(subset, image, props); | 322 if (valid_for_imagefilters(as_IB(image.get())->onImageInfo())) { |
323 return sk_make_sp<SkSpecialImage_Image>(subset, image, props); | |
324 } else { | |
325 return nullptr; | |
326 } | |
319 } | 327 } |
320 | 328 |
321 /////////////////////////////////////////////////////////////////////////////// | 329 /////////////////////////////////////////////////////////////////////////////// |
322 #include "SkBitmap.h" | 330 #include "SkBitmap.h" |
323 #include "SkImageInfo.h" | 331 #include "SkImageInfo.h" |
324 #include "SkPixelRef.h" | 332 #include "SkPixelRef.h" |
325 | 333 |
326 class SkSpecialImage_Raster : public SkSpecialImage_Base { | 334 class SkSpecialImage_Raster : public SkSpecialImage_Base { |
327 public: | 335 public: |
328 SkSpecialImage_Raster(const SkIRect& subset, const SkBitmap& bm, const SkSur faceProps* props) | 336 SkSpecialImage_Raster(const SkIRect& subset, const SkBitmap& bm, const SkSur faceProps* props) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 | 413 |
406 typedef SkSpecialImage_Base INHERITED; | 414 typedef SkSpecialImage_Base INHERITED; |
407 }; | 415 }; |
408 | 416 |
409 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, | 417 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, |
410 const SkBitmap& bm, | 418 const SkBitmap& bm, |
411 const SkSurfaceProps* props ) { | 419 const SkSurfaceProps* props ) { |
412 SkASSERT(nullptr == bm.getTexture()); | 420 SkASSERT(nullptr == bm.getTexture()); |
413 SkASSERT(rect_fits(subset, bm.width(), bm.height())); | 421 SkASSERT(rect_fits(subset, bm.width(), bm.height())); |
414 | 422 |
415 return sk_make_sp<SkSpecialImage_Raster>(subset, bm, props); | 423 const SkBitmap* srcBM = &bm; |
424 SkBitmap tmpStorage; | |
robertphillips
2016/07/20 12:20:05
for -> force
reed1
2016/07/20 12:41:53
Done.
| |
425 // ImageFilters only handle N32 at the moment, so for our src to be that | |
426 if (!valid_for_imagefilters(bm.info())) { | |
427 if (!bm.copyTo(&tmpStorage, kN32_SkColorType)) { | |
428 return nullptr; | |
429 } | |
430 srcBM = &tmpStorage; | |
431 } | |
432 return sk_make_sp<SkSpecialImage_Raster>(subset, *srcBM, props); | |
416 } | 433 } |
417 | 434 |
418 #if SK_SUPPORT_GPU | 435 #if SK_SUPPORT_GPU |
419 /////////////////////////////////////////////////////////////////////////////// | 436 /////////////////////////////////////////////////////////////////////////////// |
420 #include "GrTexture.h" | 437 #include "GrTexture.h" |
421 #include "SkImage_Gpu.h" | 438 #include "SkImage_Gpu.h" |
422 | 439 |
423 class SkSpecialImage_Gpu : public SkSpecialImage_Base { | 440 class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
424 public: | 441 public: |
425 SkSpecialImage_Gpu(const SkIRect& subset, | 442 SkSpecialImage_Gpu(const SkIRect& subset, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, | 577 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, |
561 uint32_t uniqueID, | 578 uint32_t uniqueID, |
562 sk_sp<GrTexture> tex, | 579 sk_sp<GrTexture> tex, |
563 const SkSurfaceProps* props, | 580 const SkSurfaceProps* props, |
564 SkAlphaType at) { | 581 SkAlphaType at) { |
565 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 582 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
566 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, props); | 583 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, props); |
567 } | 584 } |
568 | 585 |
569 #endif | 586 #endif |
OLD | NEW |