| 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 |
| 21 // Currently the raster imagefilters can only handle certain imageinfos. Call th
is to know if |
| 22 // a given info is supported. |
| 23 static bool valid_for_imagefilters(const SkImageInfo& info) { |
| 24 // no support for other swizzles/depths yet |
| 25 return info.colorType() == kN32_SkColorType; |
| 26 } |
| 27 |
| 21 /////////////////////////////////////////////////////////////////////////////// | 28 /////////////////////////////////////////////////////////////////////////////// |
| 22 class SkSpecialImage_Base : public SkSpecialImage { | 29 class SkSpecialImage_Base : public SkSpecialImage { |
| 23 public: | 30 public: |
| 24 SkSpecialImage_Base(const SkIRect& subset, uint32_t uniqueID, const SkSurfac
eProps* props) | 31 SkSpecialImage_Base(const SkIRect& subset, uint32_t uniqueID, const SkSurfac
eProps* props) |
| 25 : INHERITED(subset, uniqueID, props) { | 32 : INHERITED(subset, uniqueID, props) { |
| 26 } | 33 } |
| 27 ~SkSpecialImage_Base() override { } | 34 ~SkSpecialImage_Base() override { } |
| 28 | 35 |
| 29 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; | 36 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; |
| 30 | 37 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 rect.fTop >= 0 && rect.fTop < height && rect.fTop < rect.fBottom && | 315 rect.fTop >= 0 && rect.fTop < height && rect.fTop < rect.fBottom && |
| 309 rect.fBottom >= 0 && rect.fBottom <= height; | 316 rect.fBottom >= 0 && rect.fBottom <= height; |
| 310 } | 317 } |
| 311 #endif | 318 #endif |
| 312 | 319 |
| 313 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(const SkIRect& subset, | 320 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(const SkIRect& subset, |
| 314 sk_sp<SkImage> image, | 321 sk_sp<SkImage> image, |
| 315 const SkSurfaceProps* props)
{ | 322 const SkSurfaceProps* props)
{ |
| 316 SkASSERT(rect_fits(subset, image->width(), image->height())); | 323 SkASSERT(rect_fits(subset, image->width(), image->height())); |
| 317 | 324 |
| 318 return sk_make_sp<SkSpecialImage_Image>(subset, image, props); | 325 if (valid_for_imagefilters(as_IB(image.get())->onImageInfo())) { |
| 326 return sk_make_sp<SkSpecialImage_Image>(subset, image, props); |
| 327 } else { |
| 328 return nullptr; |
| 329 } |
| 319 } | 330 } |
| 320 | 331 |
| 321 /////////////////////////////////////////////////////////////////////////////// | 332 /////////////////////////////////////////////////////////////////////////////// |
| 322 #include "SkBitmap.h" | 333 #include "SkBitmap.h" |
| 323 #include "SkImageInfo.h" | 334 #include "SkImageInfo.h" |
| 324 #include "SkPixelRef.h" | 335 #include "SkPixelRef.h" |
| 325 | 336 |
| 326 class SkSpecialImage_Raster : public SkSpecialImage_Base { | 337 class SkSpecialImage_Raster : public SkSpecialImage_Base { |
| 327 public: | 338 public: |
| 328 SkSpecialImage_Raster(const SkIRect& subset, const SkBitmap& bm, const SkSur
faceProps* props) | 339 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 | 416 |
| 406 typedef SkSpecialImage_Base INHERITED; | 417 typedef SkSpecialImage_Base INHERITED; |
| 407 }; | 418 }; |
| 408 | 419 |
| 409 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, | 420 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, |
| 410 const SkBitmap& bm, | 421 const SkBitmap& bm, |
| 411 const SkSurfaceProps* props
) { | 422 const SkSurfaceProps* props
) { |
| 412 SkASSERT(nullptr == bm.getTexture()); | 423 SkASSERT(nullptr == bm.getTexture()); |
| 413 SkASSERT(rect_fits(subset, bm.width(), bm.height())); | 424 SkASSERT(rect_fits(subset, bm.width(), bm.height())); |
| 414 | 425 |
| 415 return sk_make_sp<SkSpecialImage_Raster>(subset, bm, props); | 426 const SkBitmap* srcBM = &bm; |
| 427 SkBitmap tmpStorage; |
| 428 // ImageFilters only handle N32 at the moment, so force our src to be that |
| 429 if (!valid_for_imagefilters(bm.info())) { |
| 430 if (!bm.copyTo(&tmpStorage, kN32_SkColorType)) { |
| 431 return nullptr; |
| 432 } |
| 433 srcBM = &tmpStorage; |
| 434 } |
| 435 return sk_make_sp<SkSpecialImage_Raster>(subset, *srcBM, props); |
| 416 } | 436 } |
| 417 | 437 |
| 418 #if SK_SUPPORT_GPU | 438 #if SK_SUPPORT_GPU |
| 419 /////////////////////////////////////////////////////////////////////////////// | 439 /////////////////////////////////////////////////////////////////////////////// |
| 420 #include "GrTexture.h" | 440 #include "GrTexture.h" |
| 421 #include "SkImage_Gpu.h" | 441 #include "SkImage_Gpu.h" |
| 422 | 442 |
| 423 class SkSpecialImage_Gpu : public SkSpecialImage_Base { | 443 class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
| 424 public: | 444 public: |
| 425 SkSpecialImage_Gpu(const SkIRect& subset, | 445 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, | 580 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, |
| 561 uint32_t uniqueID, | 581 uint32_t uniqueID, |
| 562 sk_sp<GrTexture> tex, | 582 sk_sp<GrTexture> tex, |
| 563 const SkSurfaceProps* props, | 583 const SkSurfaceProps* props, |
| 564 SkAlphaType at) { | 584 SkAlphaType at) { |
| 565 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 585 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
| 566 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
props); | 586 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
props); |
| 567 } | 587 } |
| 568 | 588 |
| 569 #endif | 589 #endif |
| OLD | NEW |