| 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkImage_Base.h" |
| 9 #include "SkSpecialImage.h" | 10 #include "SkSpecialImage.h" |
| 10 #include "SkSpecialSurface.h" | 11 #include "SkSpecialSurface.h" |
| 11 | 12 |
| 12 /////////////////////////////////////////////////////////////////////////////// | 13 /////////////////////////////////////////////////////////////////////////////// |
| 13 class SkSpecialImage_Base : public SkSpecialImage { | 14 class SkSpecialImage_Base : public SkSpecialImage { |
| 14 public: | 15 public: |
| 15 SkSpecialImage_Base(SkImageFilter::Proxy* proxy, const SkIRect& subset, uint
32_t uniqueID) | 16 SkSpecialImage_Base(SkImageFilter::Proxy* proxy, const SkIRect& subset, uint
32_t uniqueID) |
| 16 : INHERITED(proxy, subset, uniqueID) { | 17 : INHERITED(proxy, subset, uniqueID) { |
| 17 } | 18 } |
| 18 virtual ~SkSpecialImage_Base() { } | 19 virtual ~SkSpecialImage_Base() { } |
| 19 | 20 |
| 20 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; | 21 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; |
| 21 | 22 |
| 22 virtual bool onPeekPixels(SkPixmap*) const { return false; } | 23 virtual bool onPeekPixels(SkPixmap*) const { return false; } |
| 23 | 24 |
| 24 virtual GrTexture* onPeekTexture() const { return nullptr; } | 25 virtual GrTexture* onPeekTexture() const { return nullptr; } |
| 25 | 26 |
| 26 // Delete this entry point ASAP (see skbug.com/4965) | 27 // Delete this entry point ASAP (see skbug.com/4965) |
| 27 virtual bool getBitmap(SkBitmap* result) const = 0; | 28 virtual bool getBitmap(SkBitmap* result) const = 0; |
| 28 | 29 |
| 29 virtual SkSpecialSurface* onNewSurface(const SkImageInfo& info) const { retu
rn nullptr; } | 30 virtual SkSpecialSurface* onNewSurface(const SkImageInfo& info) const { retu
rn nullptr; } |
| 30 | 31 |
| 31 private: | 32 private: |
| 32 typedef SkSpecialImage INHERITED; | 33 typedef SkSpecialImage INHERITED; |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 /////////////////////////////////////////////////////////////////////////////// | 36 /////////////////////////////////////////////////////////////////////////////// |
| 36 static inline const SkSpecialImage_Base* as_IB(const SkSpecialImage* image) { | 37 static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { |
| 37 return static_cast<const SkSpecialImage_Base*>(image); | 38 return static_cast<const SkSpecialImage_Base*>(image); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { | 41 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { |
| 41 return as_IB(this)->onDraw(canvas, x, y, paint); | 42 return as_SIB(this)->onDraw(canvas, x, y, paint); |
| 42 } | 43 } |
| 43 | 44 |
| 44 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { | 45 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { |
| 45 return as_IB(this)->onPeekPixels(pixmap); | 46 return as_SIB(this)->onPeekPixels(pixmap); |
| 46 } | 47 } |
| 47 | 48 |
| 48 GrTexture* SkSpecialImage::peekTexture() const { | 49 GrTexture* SkSpecialImage::peekTexture() const { |
| 49 return as_IB(this)->onPeekTexture(); | 50 return as_SIB(this)->onPeekTexture(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 SkSpecialSurface* SkSpecialImage::newSurface(const SkImageInfo& info) const { | 53 SkSpecialSurface* SkSpecialImage::newSurface(const SkImageInfo& info) const { |
| 53 return as_IB(this)->onNewSurface(info); | 54 return as_SIB(this)->onNewSurface(info); |
| 54 } | 55 } |
| 55 | 56 |
| 56 #if SK_SUPPORT_GPU | 57 #if SK_SUPPORT_GPU |
| 57 #include "SkGr.h" | 58 #include "SkGr.h" |
| 58 #include "SkGrPixelRef.h" | 59 #include "SkGrPixelRef.h" |
| 59 #endif | 60 #endif |
| 60 | 61 |
| 61 SkSpecialImage* SkSpecialImage::internal_fromBM(SkImageFilter::Proxy* proxy, | 62 SkSpecialImage* SkSpecialImage::internal_fromBM(SkImageFilter::Proxy* proxy, |
| 62 const SkBitmap& src) { | 63 const SkBitmap& src) { |
| 63 // Need to test offset case! (see skbug.com/4967) | 64 // Need to test offset case! (see skbug.com/4967) |
| 64 if (src.getTexture()) { | 65 if (src.getTexture()) { |
| 65 return SkSpecialImage::NewFromGpu(proxy, | 66 return SkSpecialImage::NewFromGpu(proxy, |
| 66 src.bounds(), | 67 src.bounds(), |
| 67 src.getGenerationID(), | 68 src.getGenerationID(), |
| 68 src.getTexture()); | 69 src.getTexture()); |
| 69 } | 70 } |
| 70 | 71 |
| 71 return SkSpecialImage::NewFromRaster(proxy, src.bounds(), src); | 72 return SkSpecialImage::NewFromRaster(proxy, src.bounds(), src); |
| 72 } | 73 } |
| 73 | 74 |
| 74 bool SkSpecialImage::internal_getBM(SkBitmap* result) { | 75 bool SkSpecialImage::internal_getBM(SkBitmap* result) { |
| 75 const SkSpecialImage_Base* ib = as_IB(this); | 76 const SkSpecialImage_Base* ib = as_SIB(this); |
| 76 | 77 |
| 77 // TODO: need to test offset case! (see skbug.com/4967) | 78 // TODO: need to test offset case! (see skbug.com/4967) |
| 78 return ib->getBitmap(result); | 79 return ib->getBitmap(result); |
| 79 } | 80 } |
| 80 | 81 |
| 81 SkImageFilter::Proxy* SkSpecialImage::internal_getProxy() { | 82 SkImageFilter::Proxy* SkSpecialImage::internal_getProxy() { |
| 82 SkASSERT(fProxy); | 83 SkASSERT(fProxy); |
| 83 return fProxy; | 84 return fProxy; |
| 84 } | 85 } |
| 85 | 86 |
| 86 /////////////////////////////////////////////////////////////////////////////// | 87 /////////////////////////////////////////////////////////////////////////////// |
| 87 #include "SkImage.h" | 88 #include "SkImage.h" |
| 88 #if SK_SUPPORT_GPU | 89 #if SK_SUPPORT_GPU |
| 89 #include "SkGrPriv.h" | 90 #include "SkGrPriv.h" |
| 90 #endif | 91 #endif |
| 91 | 92 |
| 92 class SkSpecialImage_Image : public SkSpecialImage_Base { | 93 class SkSpecialImage_Image : public SkSpecialImage_Base { |
| 93 public: | 94 public: |
| 94 SkSpecialImage_Image(SkImageFilter::Proxy* proxy, const SkIRect& subset, con
st SkImage* image) | 95 SkSpecialImage_Image(SkImageFilter::Proxy* proxy, const SkIRect& subset, con
st SkImage* image) |
| 95 : INHERITED(proxy, subset, image->uniqueID()) | 96 : INHERITED(proxy, subset, image->uniqueID()) |
| 96 , fImage(SkRef(image)) { | 97 , fImage(SkRef(image)) { |
| 97 } | 98 } |
| 98 | 99 |
| 99 ~SkSpecialImage_Image() override { } | 100 ~SkSpecialImage_Image() override { } |
| 100 | 101 |
| 101 bool isOpaque() const override { return fImage->isOpaque(); } | 102 bool isOpaque() const override { return fImage->isOpaque(); } |
| 102 | 103 |
| 103 size_t getSize() const override { | 104 size_t getSize() const override { |
| 104 #if SK_SUPPORT_GPU | 105 #if SK_SUPPORT_GPU |
| 105 if (fImage->getTexture()) { | 106 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { |
| 106 return fImage->getTexture()->gpuMemorySize(); | 107 return texture->gpuMemorySize(); |
| 107 } else | 108 } else |
| 108 #endif | 109 #endif |
| 109 { | 110 { |
| 110 SkImageInfo info; | 111 SkImageInfo info; |
| 111 size_t rowBytes; | 112 size_t rowBytes; |
| 112 | 113 |
| 113 if (fImage->peekPixels(&info, &rowBytes)) { | 114 if (fImage->peekPixels(&info, &rowBytes)) { |
| 114 return info.height() * rowBytes; | 115 return info.height() * rowBytes; |
| 115 } | 116 } |
| 116 } | 117 } |
| 117 return 0; | 118 return 0; |
| 118 } | 119 } |
| 119 | 120 |
| 120 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { | 121 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
| 121 SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset
().height()); | 122 SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset
().height()); |
| 122 | 123 |
| 123 canvas->drawImageRect(fImage, this->subset(), | 124 canvas->drawImageRect(fImage, this->subset(), |
| 124 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 125 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 125 } | 126 } |
| 126 | 127 |
| 127 bool onPeekPixels(SkPixmap* pixmap) const override { | 128 bool onPeekPixels(SkPixmap* pixmap) const override { |
| 128 return fImage->peekPixels(pixmap); | 129 return fImage->peekPixels(pixmap); |
| 129 } | 130 } |
| 130 | 131 |
| 131 GrTexture* onPeekTexture() const override { return fImage->getTexture(); } | 132 GrTexture* onPeekTexture() const override { return as_IB(fImage.get())->peek
Texture(); } |
| 132 | 133 |
| 133 bool getBitmap(SkBitmap* result) const override { | 134 bool getBitmap(SkBitmap* result) const override { |
| 134 return false; | 135 return false; |
| 135 } | 136 } |
| 136 | 137 |
| 137 SkSpecialSurface* onNewSurface(const SkImageInfo& info) const override { | 138 SkSpecialSurface* onNewSurface(const SkImageInfo& info) const override { |
| 138 #if SK_SUPPORT_GPU | 139 #if SK_SUPPORT_GPU |
| 139 GrTexture* texture = fImage->getTexture(); | 140 GrTexture* texture = as_IB(fImage.get())->peekTexture(); |
| 140 if (texture) { | 141 if (texture) { |
| 141 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info); | 142 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info); |
| 142 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 143 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 143 | 144 |
| 144 return SkSpecialSurface::NewRenderTarget(this->proxy(), texture->get
Context(), desc); | 145 return SkSpecialSurface::NewRenderTarget(this->proxy(), texture->get
Context(), desc); |
| 145 } | 146 } |
| 146 #endif | 147 #endif |
| 147 return SkSpecialSurface::NewRaster(this->proxy(), info, nullptr); | 148 return SkSpecialSurface::NewRaster(this->proxy(), info, nullptr); |
| 148 } | 149 } |
| 149 | 150 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 312 |
| 312 SkSpecialImage* SkSpecialImage::NewFromGpu(SkImageFilter::Proxy* proxy, | 313 SkSpecialImage* SkSpecialImage::NewFromGpu(SkImageFilter::Proxy* proxy, |
| 313 const SkIRect& subset, | 314 const SkIRect& subset, |
| 314 uint32_t uniqueID, | 315 uint32_t uniqueID, |
| 315 GrTexture* tex, | 316 GrTexture* tex, |
| 316 SkAlphaType at) { | 317 SkAlphaType at) { |
| 317 return nullptr; | 318 return nullptr; |
| 318 } | 319 } |
| 319 | 320 |
| 320 #endif | 321 #endif |
| OLD | NEW |