| 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 "SkImage_Base.h" |
| 10 #include "SkSpecialImage.h" | 10 #include "SkSpecialImage.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 virtual bool onPeekPixels(SkPixmap*) const { return false; } | 23 virtual bool onPeekPixels(SkPixmap*) const { return false; } |
| 24 | 24 |
| 25 virtual GrTexture* onPeekTexture() const { return nullptr; } | 25 virtual GrTexture* onPeekTexture() const { return nullptr; } |
| 26 | 26 |
| 27 virtual bool testingOnlyOnGetROPixels(SkBitmap*) const = 0; | 27 virtual bool testingOnlyOnGetROPixels(SkBitmap*) const = 0; |
| 28 | 28 |
| 29 // Delete this entry point ASAP (see skbug.com/4965) | 29 // Delete this entry point ASAP (see skbug.com/4965) |
| 30 virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; | 30 virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; |
| 31 | 31 |
| 32 virtual SkSpecialSurface* onNewSurface(const SkImageInfo& info) const = 0; | 32 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const
= 0; |
| 33 | 33 |
| 34 virtual SkSpecialImage* onExtractSubset(const SkIRect& subset) const = 0; | 34 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 typedef SkSpecialImage INHERITED; | 37 typedef SkSpecialImage INHERITED; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 /////////////////////////////////////////////////////////////////////////////// | 40 /////////////////////////////////////////////////////////////////////////////// |
| 41 static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { | 41 static inline const SkSpecialImage_Base* as_SIB(const SkSpecialImage* image) { |
| 42 return static_cast<const SkSpecialImage_Base*>(image); | 42 return static_cast<const SkSpecialImage_Base*>(image); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { | 45 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { |
| 46 return as_SIB(this)->onDraw(canvas, x, y, paint); | 46 return as_SIB(this)->onDraw(canvas, x, y, paint); |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { | 49 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { |
| 50 return as_SIB(this)->onPeekPixels(pixmap); | 50 return as_SIB(this)->onPeekPixels(pixmap); |
| 51 } | 51 } |
| 52 | 52 |
| 53 GrTexture* SkSpecialImage::peekTexture() const { | 53 GrTexture* SkSpecialImage::peekTexture() const { |
| 54 return as_SIB(this)->onPeekTexture(); | 54 return as_SIB(this)->onPeekTexture(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool SkSpecialImage::testingOnlyGetROPixels(SkBitmap* result) const { | 57 bool SkSpecialImage::testingOnlyGetROPixels(SkBitmap* result) const { |
| 58 return as_SIB(this)->testingOnlyOnGetROPixels(result); | 58 return as_SIB(this)->testingOnlyOnGetROPixels(result); |
| 59 } | 59 } |
| 60 | 60 |
| 61 SkSpecialSurface* SkSpecialImage::newSurface(const SkImageInfo& info) const { | 61 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) con
st { |
| 62 return as_SIB(this)->onNewSurface(info); | 62 return as_SIB(this)->onMakeSurface(info); |
| 63 } | 63 } |
| 64 | 64 |
| 65 SkSpecialImage* SkSpecialImage::extractSubset(const SkIRect& subset) const { | 65 sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { |
| 66 return as_SIB(this)->onExtractSubset(subset); | 66 return as_SIB(this)->onMakeSubset(subset); |
| 67 } | 67 } |
| 68 | 68 |
| 69 #if SK_SUPPORT_GPU | 69 #if SK_SUPPORT_GPU |
| 70 #include "SkGr.h" | 70 #include "SkGr.h" |
| 71 #include "SkGrPixelRef.h" | 71 #include "SkGrPixelRef.h" |
| 72 #endif | 72 #endif |
| 73 | 73 |
| 74 SkSpecialImage* SkSpecialImage::internal_fromBM(SkImageFilter::Proxy* proxy, | 74 sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(SkImageFilter::Proxy* prox
y, |
| 75 const SkBitmap& src) { | 75 const SkBitmap& src) { |
| 76 // Need to test offset case! (see skbug.com/4967) | 76 // Need to test offset case! (see skbug.com/4967) |
| 77 if (src.getTexture()) { | 77 if (src.getTexture()) { |
| 78 return SkSpecialImage::NewFromGpu(proxy, | 78 return SkSpecialImage::MakeFromGpu(proxy, |
| 79 src.bounds(), | 79 src.bounds(), |
| 80 src.getGenerationID(), | 80 src.getGenerationID(), |
| 81 src.getTexture()); | 81 src.getTexture()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 return SkSpecialImage::NewFromRaster(proxy, src.bounds(), src); | 84 return SkSpecialImage::MakeFromRaster(proxy, src.bounds(), src); |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool SkSpecialImage::internal_getBM(SkBitmap* result) { | 87 bool SkSpecialImage::internal_getBM(SkBitmap* result) { |
| 88 const SkSpecialImage_Base* ib = as_SIB(this); | 88 const SkSpecialImage_Base* ib = as_SIB(this); |
| 89 | 89 |
| 90 // TODO: need to test offset case! (see skbug.com/4967) | 90 // TODO: need to test offset case! (see skbug.com/4967) |
| 91 return ib->getBitmapDeprecated(result); | 91 return ib->getBitmapDeprecated(result); |
| 92 } | 92 } |
| 93 | 93 |
| 94 SkImageFilter::Proxy* SkSpecialImage::internal_getProxy() const { | 94 SkImageFilter::Proxy* SkSpecialImage::internal_getProxy() const { |
| 95 return fProxy; | 95 return fProxy; |
| 96 } | 96 } |
| 97 | 97 |
| 98 /////////////////////////////////////////////////////////////////////////////// | 98 /////////////////////////////////////////////////////////////////////////////// |
| 99 #include "SkImage.h" | 99 #include "SkImage.h" |
| 100 #if SK_SUPPORT_GPU | 100 #if SK_SUPPORT_GPU |
| 101 #include "SkGrPriv.h" | 101 #include "SkGrPriv.h" |
| 102 #endif | 102 #endif |
| 103 | 103 |
| 104 class SkSpecialImage_Image : public SkSpecialImage_Base { | 104 class SkSpecialImage_Image : public SkSpecialImage_Base { |
| 105 public: | 105 public: |
| 106 SkSpecialImage_Image(SkImageFilter::Proxy* proxy, const SkIRect& subset, con
st SkImage* image) | 106 SkSpecialImage_Image(SkImageFilter::Proxy* proxy, |
| 107 const SkIRect& subset, |
| 108 sk_sp<SkImage> image) |
| 107 : INHERITED(proxy, subset, image->uniqueID()) | 109 : INHERITED(proxy, subset, image->uniqueID()) |
| 108 , fImage(SkRef(image)) { | 110 , fImage(image) { |
| 109 } | 111 } |
| 110 | 112 |
| 111 ~SkSpecialImage_Image() override { } | 113 ~SkSpecialImage_Image() override { } |
| 112 | 114 |
| 113 bool isOpaque() const override { return fImage->isOpaque(); } | 115 bool isOpaque() const override { return fImage->isOpaque(); } |
| 114 | 116 |
| 115 size_t getSize() const override { | 117 size_t getSize() const override { |
| 116 #if SK_SUPPORT_GPU | 118 #if SK_SUPPORT_GPU |
| 117 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { | 119 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { |
| 118 return texture->gpuMemorySize(); | 120 return texture->gpuMemorySize(); |
| 119 } else | 121 } else |
| 120 #endif | 122 #endif |
| 121 { | 123 { |
| 122 SkPixmap pm; | 124 SkPixmap pm; |
| 123 if (fImage->peekPixels(&pm)) { | 125 if (fImage->peekPixels(&pm)) { |
| 124 return pm.height() * pm.rowBytes(); | 126 return pm.height() * pm.rowBytes(); |
| 125 } | 127 } |
| 126 } | 128 } |
| 127 return 0; | 129 return 0; |
| 128 } | 130 } |
| 129 | 131 |
| 130 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { | 132 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
| 131 SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset
().height()); | 133 SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset
().height()); |
| 132 | 134 |
| 133 canvas->drawImageRect(fImage, this->subset(), | 135 canvas->drawImageRect(fImage.get(), this->subset(), |
| 134 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 136 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 135 } | 137 } |
| 136 | 138 |
| 137 bool onPeekPixels(SkPixmap* pixmap) const override { | 139 bool onPeekPixels(SkPixmap* pixmap) const override { |
| 138 return fImage->peekPixels(pixmap); | 140 return fImage->peekPixels(pixmap); |
| 139 } | 141 } |
| 140 | 142 |
| 141 GrTexture* onPeekTexture() const override { return as_IB(fImage.get())->peek
Texture(); } | 143 GrTexture* onPeekTexture() const override { return as_IB(fImage.get())->peek
Texture(); } |
| 142 | 144 |
| 143 bool getBitmapDeprecated(SkBitmap* result) const override { | 145 bool getBitmapDeprecated(SkBitmap* result) const override { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 155 } | 157 } |
| 156 #endif | 158 #endif |
| 157 | 159 |
| 158 return as_IB(fImage.get())->asBitmapForImageFilters(result); | 160 return as_IB(fImage.get())->asBitmapForImageFilters(result); |
| 159 } | 161 } |
| 160 | 162 |
| 161 bool testingOnlyOnGetROPixels(SkBitmap* result) const override { | 163 bool testingOnlyOnGetROPixels(SkBitmap* result) const override { |
| 162 return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode); | 164 return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode); |
| 163 } | 165 } |
| 164 | 166 |
| 165 SkSpecialSurface* onNewSurface(const SkImageInfo& info) const override { | 167 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
| 166 #if SK_SUPPORT_GPU | 168 #if SK_SUPPORT_GPU |
| 167 GrTexture* texture = as_IB(fImage.get())->peekTexture(); | 169 GrTexture* texture = as_IB(fImage.get())->peekTexture(); |
| 168 if (texture) { | 170 if (texture) { |
| 169 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info); | 171 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info); |
| 170 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 172 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 171 | 173 |
| 172 return SkSpecialSurface::NewRenderTarget(this->proxy(), texture->get
Context(), desc); | 174 return SkSpecialSurface::MakeRenderTarget(this->proxy(), texture->ge
tContext(), desc); |
| 173 } | 175 } |
| 174 #endif | 176 #endif |
| 175 return SkSpecialSurface::NewRaster(this->proxy(), info, nullptr); | 177 return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr); |
| 176 } | 178 } |
| 177 | 179 |
| 178 SkSpecialImage* onExtractSubset(const SkIRect& subset) const override { | 180 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
| 179 SkAutoTUnref<SkImage> subsetImg(fImage->newSubset(subset)); | 181 sk_sp<SkImage> subsetImg(fImage->makeSubset(subset)); |
| 180 if (!subsetImg) { | 182 if (!subsetImg) { |
| 181 return nullptr; | 183 return nullptr; |
| 182 } | 184 } |
| 183 | 185 |
| 184 return SkSpecialImage::NewFromImage(this->internal_getProxy(), | 186 return SkSpecialImage::MakeFromImage(this->internal_getProxy(), |
| 185 SkIRect::MakeWH(subset.width(), subs
et.height()), | 187 SkIRect::MakeWH(subset.width(), sub
set.height()), |
| 186 subsetImg); | 188 subsetImg); |
| 187 } | 189 } |
| 188 | 190 |
| 189 private: | 191 private: |
| 190 SkAutoTUnref<const SkImage> fImage; | 192 sk_sp<SkImage> fImage; |
| 191 | 193 |
| 192 typedef SkSpecialImage_Base INHERITED; | 194 typedef SkSpecialImage_Base INHERITED; |
| 193 }; | 195 }; |
| 194 | 196 |
| 195 #ifdef SK_DEBUG | 197 #ifdef SK_DEBUG |
| 196 static bool rect_fits(const SkIRect& rect, int width, int height) { | 198 static bool rect_fits(const SkIRect& rect, int width, int height) { |
| 197 if (0 == width && 0 == height) { | 199 if (0 == width && 0 == height) { |
| 198 SkASSERT(0 == rect.fLeft && 0 == rect.fRight && 0 == rect.fTop && 0 == r
ect.fBottom); | 200 SkASSERT(0 == rect.fLeft && 0 == rect.fRight && 0 == rect.fTop && 0 == r
ect.fBottom); |
| 199 return true; | 201 return true; |
| 200 } | 202 } |
| 201 | 203 |
| 202 return rect.fLeft >= 0 && rect.fLeft < width && rect.fLeft < rect.fRight && | 204 return rect.fLeft >= 0 && rect.fLeft < width && rect.fLeft < rect.fRight && |
| 203 rect.fRight >= 0 && rect.fRight <= width && | 205 rect.fRight >= 0 && rect.fRight <= width && |
| 204 rect.fTop >= 0 && rect.fTop < height && rect.fTop < rect.fBottom && | 206 rect.fTop >= 0 && rect.fTop < height && rect.fTop < rect.fBottom && |
| 205 rect.fBottom >= 0 && rect.fBottom <= height; | 207 rect.fBottom >= 0 && rect.fBottom <= height; |
| 206 } | 208 } |
| 207 #endif | 209 #endif |
| 208 | 210 |
| 209 SkSpecialImage* SkSpecialImage::NewFromImage(SkImageFilter::Proxy* proxy, | 211 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(SkImageFilter::Proxy* proxy, |
| 210 const SkIRect& subset, | 212 const SkIRect& subset, |
| 211 const SkImage* image) { | 213 sk_sp<SkImage> image) { |
| 212 SkASSERT(rect_fits(subset, image->width(), image->height())); | 214 SkASSERT(rect_fits(subset, image->width(), image->height())); |
| 213 return new SkSpecialImage_Image(proxy, subset, image); | 215 |
| 216 return sk_make_sp<SkSpecialImage_Image>(proxy, subset, image); |
| 214 } | 217 } |
| 215 | 218 |
| 216 /////////////////////////////////////////////////////////////////////////////// | 219 /////////////////////////////////////////////////////////////////////////////// |
| 217 #include "SkBitmap.h" | 220 #include "SkBitmap.h" |
| 218 #include "SkImageInfo.h" | 221 #include "SkImageInfo.h" |
| 219 #include "SkPixelRef.h" | 222 #include "SkPixelRef.h" |
| 220 | 223 |
| 221 class SkSpecialImage_Raster : public SkSpecialImage_Base { | 224 class SkSpecialImage_Raster : public SkSpecialImage_Base { |
| 222 public: | 225 public: |
| 223 SkSpecialImage_Raster(SkImageFilter::Proxy* proxy, const SkIRect& subset, co
nst SkBitmap& bm) | 226 SkSpecialImage_Raster(SkImageFilter::Proxy* proxy, const SkIRect& subset, co
nst SkBitmap& bm) |
| 224 : INHERITED(proxy, subset, bm.getGenerationID()) | 227 : INHERITED(proxy, subset, bm.getGenerationID()) |
| 225 , fBitmap(bm) { | 228 , fBitmap(bm) { |
| 226 if (bm.pixelRef() && bm.pixelRef()->isPreLocked()) { | 229 if (bm.pixelRef() && bm.pixelRef()->isPreLocked()) { |
| 227 // we only preemptively lock if there is no chance of triggering som
ething expensive | 230 // we only preemptively lock if there is no chance of triggering som
ething expensive |
| 228 // like a lazy decode or imagegenerator. PreLocked means it is flat
pixels already. | 231 // like a lazy decode or imagegenerator. PreLocked means it is flat
pixels already. |
| 229 fBitmap.lockPixels(); | 232 fBitmap.lockPixels(); |
| 230 } | 233 } |
| 231 } | 234 } |
| 232 | 235 |
| 233 SkSpecialImage_Raster(SkImageFilter::Proxy* proxy, | 236 SkSpecialImage_Raster(SkImageFilter::Proxy* proxy, |
| 234 const SkIRect& subset, | 237 const SkIRect& subset, |
| 235 const SkPixmap& pixmap, | 238 const SkPixmap& pixmap, |
| 236 void (*releaseProc)(void* addr, void* context), | 239 RasterReleaseProc releaseProc, |
| 237 void* context) | 240 ReleaseContext context) |
| 238 : INHERITED(proxy, subset, kNeedNewImageUniqueID_SpecialImage) { | 241 : INHERITED(proxy, subset, kNeedNewImageUniqueID_SpecialImage) { |
| 239 fBitmap.installPixels(pixmap.info(), pixmap.writable_addr(), | 242 fBitmap.installPixels(pixmap.info(), pixmap.writable_addr(), |
| 240 pixmap.rowBytes(), pixmap.ctable(), | 243 pixmap.rowBytes(), pixmap.ctable(), |
| 241 releaseProc, context); | 244 releaseProc, context); |
| 242 } | 245 } |
| 243 | 246 |
| 244 ~SkSpecialImage_Raster() override { } | 247 ~SkSpecialImage_Raster() override { } |
| 245 | 248 |
| 246 bool isOpaque() const override { return fBitmap.isOpaque(); } | 249 bool isOpaque() const override { return fBitmap.isOpaque(); } |
| 247 | 250 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 267 bool getBitmapDeprecated(SkBitmap* result) const override { | 270 bool getBitmapDeprecated(SkBitmap* result) const override { |
| 268 *result = fBitmap; | 271 *result = fBitmap; |
| 269 return true; | 272 return true; |
| 270 } | 273 } |
| 271 | 274 |
| 272 bool testingOnlyOnGetROPixels(SkBitmap* result) const override { | 275 bool testingOnlyOnGetROPixels(SkBitmap* result) const override { |
| 273 *result = fBitmap; | 276 *result = fBitmap; |
| 274 return true; | 277 return true; |
| 275 } | 278 } |
| 276 | 279 |
| 277 SkSpecialSurface* onNewSurface(const SkImageInfo& info) const override { | 280 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
| 278 return SkSpecialSurface::NewRaster(this->proxy(), info, nullptr); | 281 return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr); |
| 279 } | 282 } |
| 280 | 283 |
| 281 SkSpecialImage* onExtractSubset(const SkIRect& subset) const override { | 284 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
| 282 SkBitmap subsetBM; | 285 SkBitmap subsetBM; |
| 283 | 286 |
| 284 if (!fBitmap.extractSubset(&subsetBM, subset)) { | 287 if (!fBitmap.extractSubset(&subsetBM, subset)) { |
| 285 return nullptr; | 288 return nullptr; |
| 286 } | 289 } |
| 287 | 290 |
| 288 return SkSpecialImage::NewFromRaster(this->internal_getProxy(), | 291 return SkSpecialImage::MakeFromRaster(this->internal_getProxy(), |
| 289 SkIRect::MakeWH(subset.width(), sub
set.height()), | 292 SkIRect::MakeWH(subset.width(), su
bset.height()), |
| 290 subsetBM); | 293 subsetBM); |
| 291 } | 294 } |
| 292 | 295 |
| 293 private: | 296 private: |
| 294 SkBitmap fBitmap; | 297 SkBitmap fBitmap; |
| 295 | 298 |
| 296 typedef SkSpecialImage_Base INHERITED; | 299 typedef SkSpecialImage_Base INHERITED; |
| 297 }; | 300 }; |
| 298 | 301 |
| 299 SkSpecialImage* SkSpecialImage::NewFromRaster(SkImageFilter::Proxy* proxy, | 302 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(SkImageFilter::Proxy* proxy
, |
| 300 const SkIRect& subset, | 303 const SkIRect& subset, |
| 301 const SkBitmap& bm) { | 304 const SkBitmap& bm) { |
| 302 SkASSERT(nullptr == bm.getTexture()); | 305 SkASSERT(nullptr == bm.getTexture()); |
| 303 SkASSERT(rect_fits(subset, bm.width(), bm.height())); | 306 SkASSERT(rect_fits(subset, bm.width(), bm.height())); |
| 304 return new SkSpecialImage_Raster(proxy, subset, bm); | 307 |
| 308 return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, bm); |
| 305 } | 309 } |
| 306 | 310 |
| 307 SkSpecialImage* SkSpecialImage::NewFromPixmap(SkImageFilter::Proxy* proxy, | 311 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromPixmap(SkImageFilter::Proxy* proxy
, |
| 308 const SkIRect& subset, | 312 const SkIRect& subset, |
| 309 const SkPixmap& src, | 313 const SkPixmap& src, |
| 310 void (*releaseProc)(void* addr, vo
id* context), | 314 RasterReleaseProc releasePr
oc, |
| 311 void* context) { | 315 ReleaseContext context) { |
| 312 return new SkSpecialImage_Raster(proxy, subset, src, releaseProc, context); | 316 if (!src.addr()) { |
| 317 return nullptr; |
| 318 } |
| 319 |
| 320 return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, src, releaseProc, co
ntext); |
| 313 } | 321 } |
| 314 | 322 |
| 315 | 323 |
| 316 #if SK_SUPPORT_GPU | 324 #if SK_SUPPORT_GPU |
| 317 /////////////////////////////////////////////////////////////////////////////// | 325 /////////////////////////////////////////////////////////////////////////////// |
| 318 #include "GrTexture.h" | 326 #include "GrTexture.h" |
| 319 | 327 |
| 320 class SkSpecialImage_Gpu : public SkSpecialImage_Base { | 328 class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
| 321 public: | 329 public: |
| 322 SkSpecialImage_Gpu(SkImageFilter::Proxy* proxy, const SkIRect& subset, | 330 SkSpecialImage_Gpu(SkImageFilter::Proxy* proxy, const SkIRect& subset, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 384 |
| 377 if (!fTexture->readPixels(0, 0, result->width(), result->height(), kSkia
8888_GrPixelConfig, | 385 if (!fTexture->readPixels(0, 0, result->width(), result->height(), kSkia
8888_GrPixelConfig, |
| 378 result->getPixels(), result->rowBytes())) { | 386 result->getPixels(), result->rowBytes())) { |
| 379 return false; | 387 return false; |
| 380 } | 388 } |
| 381 | 389 |
| 382 result->pixelRef()->setImmutable(); | 390 result->pixelRef()->setImmutable(); |
| 383 return true; | 391 return true; |
| 384 } | 392 } |
| 385 | 393 |
| 386 SkSpecialSurface* onNewSurface(const SkImageInfo& info) const override { | 394 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
| 387 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info); | 395 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info); |
| 388 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 396 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 389 | 397 |
| 390 return SkSpecialSurface::NewRenderTarget(this->proxy(), fTexture->getCon
text(), desc); | 398 return SkSpecialSurface::MakeRenderTarget(this->proxy(), fTexture->getCo
ntext(), desc); |
| 391 } | 399 } |
| 392 | 400 |
| 393 SkSpecialImage* onExtractSubset(const SkIRect& subset) const override { | 401 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
| 394 return SkSpecialImage::NewFromGpu(this->internal_getProxy(), | 402 return SkSpecialImage::MakeFromGpu(this->internal_getProxy(), |
| 395 subset, | 403 subset, |
| 396 this->uniqueID(), | 404 this->uniqueID(), |
| 397 fTexture, | 405 fTexture, |
| 398 fAlphaType); | 406 fAlphaType); |
| 399 } | 407 } |
| 400 | 408 |
| 401 private: | 409 private: |
| 402 SkAutoTUnref<GrTexture> fTexture; | 410 SkAutoTUnref<GrTexture> fTexture; |
| 403 const SkAlphaType fAlphaType; | 411 const SkAlphaType fAlphaType; |
| 404 | 412 |
| 405 typedef SkSpecialImage_Base INHERITED; | 413 typedef SkSpecialImage_Base INHERITED; |
| 406 }; | 414 }; |
| 407 | 415 |
| 408 SkSpecialImage* SkSpecialImage::NewFromGpu(SkImageFilter::Proxy* proxy, | 416 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
| 409 const SkIRect& subset, | 417 const SkIRect& subset, |
| 410 uint32_t uniqueID, | 418 uint32_t uniqueID, |
| 411 GrTexture* tex, | 419 GrTexture* tex, |
| 412 SkAlphaType at) { | 420 SkAlphaType at) { |
| 413 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 421 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
| 414 return new SkSpecialImage_Gpu(proxy, subset, uniqueID, tex, at); | 422 return sk_make_sp<SkSpecialImage_Gpu>(proxy, subset, uniqueID, tex, at); |
| 415 } | 423 } |
| 416 | 424 |
| 417 #else | 425 #else |
| 418 | 426 |
| 419 SkSpecialImage* SkSpecialImage::NewFromGpu(SkImageFilter::Proxy* proxy, | 427 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
| 420 const SkIRect& subset, | 428 const SkIRect& subset, |
| 421 uint32_t uniqueID, | 429 uint32_t uniqueID, |
| 422 GrTexture* tex, | 430 GrTexture* tex, |
| 423 SkAlphaType at) { | 431 SkAlphaType at) { |
| 424 return nullptr; | 432 return nullptr; |
| 425 } | 433 } |
| 426 | 434 |
| 427 #endif | 435 #endif |
| OLD | NEW |