| 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 #endif |
| 7 | 13 |
| 8 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
| 15 #include "SkGr.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 SkSpecialImage* SkSpecialImage::makeTextureImage(SkImageFilter::Proxy* proxy, Gr
Context* context) { |
| 52 #if SK_SUPPORT_GPU |
| 53 if (!context) { |
| 54 return nullptr; |
| 55 } |
| 56 if (GrTexture* peek = as_SIB(this)->peekTexture()) { |
| 57 return peek->getContext() == context ? this : nullptr; |
| 58 } |
| 59 |
| 60 SkBitmap bmp; |
| 61 if (!this->internal_getBM(&bmp)) { |
| 62 return nullptr; |
| 63 } |
| 64 |
| 65 SkAutoTUnref<GrTexture> resultTex( |
| 66 GrRefCachedBitmapTexture(context, bmp, GrTextureParams::ClampNoFilter())
); |
| 67 if (!resultTex) { |
| 68 return nullptr; |
| 69 } |
| 70 |
| 71 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp
e; |
| 72 |
| 73 return SkSpecialImage::NewFromGpu(proxy, |
| 74 SkIRect::MakeWH(resultTex->width(), result
Tex->height()), |
| 75 this->uniqueID(), |
| 76 resultTex, at); |
| 77 #else |
| 78 return nullptr; |
| 79 #endif |
| 80 } |
| 81 |
| 45 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { | 82 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { |
| 46 return as_SIB(this)->onDraw(canvas, x, y, paint); | 83 return as_SIB(this)->onDraw(canvas, x, y, paint); |
| 47 } | 84 } |
| 48 | 85 |
| 49 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { | 86 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { |
| 50 return as_SIB(this)->onPeekPixels(pixmap); | 87 return as_SIB(this)->onPeekPixels(pixmap); |
| 51 } | 88 } |
| 52 | 89 |
| 53 GrTexture* SkSpecialImage::peekTexture() const { | 90 GrTexture* SkSpecialImage::peekTexture() const { |
| 54 return as_SIB(this)->onPeekTexture(); | 91 return as_SIB(this)->onPeekTexture(); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 | 455 |
| 419 SkSpecialImage* SkSpecialImage::NewFromGpu(SkImageFilter::Proxy* proxy, | 456 SkSpecialImage* SkSpecialImage::NewFromGpu(SkImageFilter::Proxy* proxy, |
| 420 const SkIRect& subset, | 457 const SkIRect& subset, |
| 421 uint32_t uniqueID, | 458 uint32_t uniqueID, |
| 422 GrTexture* tex, | 459 GrTexture* tex, |
| 423 SkAlphaType at) { | 460 SkAlphaType at) { |
| 424 return nullptr; | 461 return nullptr; |
| 425 } | 462 } |
| 426 | 463 |
| 427 #endif | 464 #endif |
| OLD | NEW |