| 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" |
| 8 |
| 9 #if SK_SUPPORT_GPU |
| 10 #include "GrTexture.h" |
| 11 #include "GrTextureParams.h" |
| 12 #include "SkGr.h" |
| 13 #endif |
| 7 | 14 |
| 8 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
| 9 #include "SkImage_Base.h" | 16 #include "SkImage_Base.h" |
| 10 #include "SkSpecialImage.h" | |
| 11 #include "SkSpecialSurface.h" | 17 #include "SkSpecialSurface.h" |
| 12 | 18 |
| 13 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
| 14 class SkSpecialImage_Base : public SkSpecialImage { | 20 class SkSpecialImage_Base : public SkSpecialImage { |
| 15 public: | 21 public: |
| 16 SkSpecialImage_Base(SkImageFilter::Proxy* proxy, const SkIRect& subset, uint
32_t uniqueID) | 22 SkSpecialImage_Base(SkImageFilter::Proxy* proxy, const SkIRect& subset, uint
32_t uniqueID) |
| 17 : INHERITED(proxy, subset, uniqueID) { | 23 : INHERITED(proxy, subset, uniqueID) { |
| 18 } | 24 } |
| 19 virtual ~SkSpecialImage_Base() { } | 25 virtual ~SkSpecialImage_Base() { } |
| 20 | 26 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 35 | 41 |
| 36 private: | 42 private: |
| 37 typedef SkSpecialImage INHERITED; | 43 typedef SkSpecialImage INHERITED; |
| 38 }; | 44 }; |
| 39 | 45 |
| 40 /////////////////////////////////////////////////////////////////////////////// | 46 /////////////////////////////////////////////////////////////////////////////// |
| 41 static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { | 47 static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { |
| 42 return static_cast<const SkSpecialImage_Base*>(image); | 48 return static_cast<const SkSpecialImage_Base*>(image); |
| 43 } | 49 } |
| 44 | 50 |
| 51 sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(SkImageFilter::Proxy* pro
xy, |
| 52 GrContext* context) { |
| 53 #if SK_SUPPORT_GPU |
| 54 if (!context) { |
| 55 return nullptr; |
| 56 } |
| 57 if (GrTexture* peek = as_SIB(this)->peekTexture()) { |
| 58 return peek->getContext() == context ? sk_sp<SkSpecialImage>(SkRef(this)
) : nullptr; |
| 59 } |
| 60 |
| 61 SkBitmap bmp; |
| 62 if (!this->internal_getBM(&bmp)) { |
| 63 return nullptr; |
| 64 } |
| 65 |
| 66 SkAutoTUnref<GrTexture> resultTex( |
| 67 GrRefCachedBitmapTexture(context, bmp, GrTextureParams::ClampNoFilter())
); |
| 68 if (!resultTex) { |
| 69 return nullptr; |
| 70 } |
| 71 |
| 72 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp
e; |
| 73 |
| 74 return SkSpecialImage::MakeFromGpu(proxy, |
| 75 SkIRect::MakeWH(resultTex->width(), resul
tTex->height()), |
| 76 this->uniqueID(), |
| 77 resultTex, at); |
| 78 #else |
| 79 return nullptr; |
| 80 #endif |
| 81 } |
| 82 |
| 45 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { | 83 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { |
| 46 return as_SIB(this)->onDraw(canvas, x, y, paint); | 84 return as_SIB(this)->onDraw(canvas, x, y, paint); |
| 47 } | 85 } |
| 48 | 86 |
| 49 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { | 87 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { |
| 50 return as_SIB(this)->onPeekPixels(pixmap); | 88 return as_SIB(this)->onPeekPixels(pixmap); |
| 51 } | 89 } |
| 52 | 90 |
| 53 GrTexture* SkSpecialImage::peekTexture() const { | 91 GrTexture* SkSpecialImage::peekTexture() const { |
| 54 return as_SIB(this)->onPeekTexture(); | 92 return as_SIB(this)->onPeekTexture(); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 464 |
| 427 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, | 465 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
| 428 const SkIRect& subset, | 466 const SkIRect& subset, |
| 429 uint32_t uniqueID, | 467 uint32_t uniqueID, |
| 430 GrTexture* tex, | 468 GrTexture* tex, |
| 431 SkAlphaType at) { | 469 SkAlphaType at) { |
| 432 return nullptr; | 470 return nullptr; |
| 433 } | 471 } |
| 434 | 472 |
| 435 #endif | 473 #endif |
| OLD | NEW |