| 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 "SkCanvas.h" | 16 #include "SkCanvas.h" |
| 16 #include "SkImage_Base.h" | 17 #include "SkImage_Base.h" |
| 17 #include "SkSpecialSurface.h" | 18 #include "SkSpecialSurface.h" |
| 18 #include "SkSurfacePriv.h" | 19 #include "SkSurfacePriv.h" |
| 19 | 20 |
| 20 /////////////////////////////////////////////////////////////////////////////// | 21 /////////////////////////////////////////////////////////////////////////////// |
| 21 class SkSpecialImage_Base : public SkSpecialImage { | 22 class SkSpecialImage_Base : public SkSpecialImage { |
| 22 public: | 23 public: |
| 23 SkSpecialImage_Base(SkImageFilter::Proxy* proxy, const SkIRect& subset, uint
32_t uniqueID, | 24 SkSpecialImage_Base(SkImageFilter::Proxy* proxy, const SkIRect& subset, uint
32_t uniqueID, |
| 24 const SkSurfaceProps* props) | 25 const SkSurfaceProps* props) |
| 25 : INHERITED(proxy, subset, uniqueID, props) { | 26 : INHERITED(proxy, subset, uniqueID, props) { |
| 26 } | 27 } |
| 27 virtual ~SkSpecialImage_Base() { } | 28 virtual ~SkSpecialImage_Base() { } |
| 28 | 29 |
| 29 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; | 30 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; |
| 30 | 31 |
| 31 virtual bool onPeekPixels(SkPixmap*) const { return false; } | 32 virtual bool onGetROPixels(SkBitmap*) const = 0; |
| 32 | 33 |
| 33 virtual GrTexture* onPeekTexture() const { return nullptr; } | 34 virtual GrTexture* onPeekTexture() const { return nullptr; } |
| 34 | 35 |
| 35 virtual bool testingOnlyOnGetROPixels(SkBitmap*) const = 0; | 36 virtual GrTexture* onAsTextureRef(GrContext* context) const = 0; |
| 36 | 37 |
| 37 // Delete this entry point ASAP (see skbug.com/4965) | 38 // Delete this entry point ASAP (see skbug.com/4965) |
| 38 virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; | 39 virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; |
| 39 | 40 |
| 40 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; | 41 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; |
| 41 | 42 |
| 42 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const
= 0; | 43 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const
= 0; |
| 43 | 44 |
| 44 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; | 45 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; |
| 45 | 46 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 63 , fUniqueID(kNeedNewImageUniqueID_SpecialImage == uniqueID ? SkNextID::Image
ID() : uniqueID) | 64 , fUniqueID(kNeedNewImageUniqueID_SpecialImage == uniqueID ? SkNextID::Image
ID() : uniqueID) |
| 64 , fProxy(proxy) { | 65 , fProxy(proxy) { |
| 65 } | 66 } |
| 66 | 67 |
| 67 sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(SkImageFilter::Proxy* pro
xy, | 68 sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(SkImageFilter::Proxy* pro
xy, |
| 68 GrContext* context) { | 69 GrContext* context) { |
| 69 #if SK_SUPPORT_GPU | 70 #if SK_SUPPORT_GPU |
| 70 if (!context) { | 71 if (!context) { |
| 71 return nullptr; | 72 return nullptr; |
| 72 } | 73 } |
| 73 if (GrTexture* peek = as_SIB(this)->peekTexture()) { | 74 if (GrTexture* peek = as_SIB(this)->onPeekTexture()) { |
| 74 return peek->getContext() == context ? sk_sp<SkSpecialImage>(SkRef(this)
) : nullptr; | 75 return peek->getContext() == context ? sk_sp<SkSpecialImage>(SkRef(this)
) : nullptr; |
| 75 } | 76 } |
| 76 | 77 |
| 77 SkBitmap bmp; | 78 SkBitmap bmp; |
| 78 if (!this->internal_getBM(&bmp)) { | 79 if (!this->internal_getBM(&bmp)) { |
| 79 return nullptr; | 80 return nullptr; |
| 80 } | 81 } |
| 81 | 82 |
| 82 if (bmp.empty()) { | 83 if (bmp.empty()) { |
| 83 return SkSpecialImage::MakeFromRaster(proxy, SkIRect::MakeEmpty(), bmp,
&this->props()); | 84 return SkSpecialImage::MakeFromRaster(proxy, SkIRect::MakeEmpty(), bmp,
&this->props()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 97 resultTex, &this->props(), at); | 98 resultTex, &this->props(), at); |
| 98 #else | 99 #else |
| 99 return nullptr; | 100 return nullptr; |
| 100 #endif | 101 #endif |
| 101 } | 102 } |
| 102 | 103 |
| 103 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { | 104 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain
t* paint) const { |
| 104 return as_SIB(this)->onDraw(canvas, x, y, paint); | 105 return as_SIB(this)->onDraw(canvas, x, y, paint); |
| 105 } | 106 } |
| 106 | 107 |
| 107 bool SkSpecialImage::peekPixels(SkPixmap* pixmap) const { | 108 bool SkSpecialImage::getROPixels(SkBitmap* bm) const { |
| 108 return as_SIB(this)->onPeekPixels(pixmap); | 109 return as_SIB(this)->onGetROPixels(bm); |
| 109 } | 110 } |
| 110 | 111 |
| 111 GrTexture* SkSpecialImage::peekTexture() const { | 112 bool SkSpecialImage::isTextureBacked() const { |
| 112 return as_SIB(this)->onPeekTexture(); | 113 #if SK_SUPPORT_GPU |
| 114 return as_SIB(this)->onPeekTexture() && as_SIB(this)->onPeekTexture()->getCo
ntext(); |
| 115 #else |
| 116 return false; |
| 117 #endif |
| 113 } | 118 } |
| 114 | 119 |
| 115 bool SkSpecialImage::testingOnlyGetROPixels(SkBitmap* result) const { | 120 GrContext* SkSpecialImage::getContext() const { |
| 116 return as_SIB(this)->testingOnlyOnGetROPixels(result); | 121 #if SK_SUPPORT_GPU |
| 122 GrTexture* texture = as_SIB(this)->onPeekTexture(); |
| 123 |
| 124 if (texture) { |
| 125 return texture->getContext(); |
| 126 } |
| 127 #endif |
| 128 return nullptr; |
| 129 } |
| 130 |
| 131 |
| 132 GrTexture* SkSpecialImage::asTextureRef(GrContext* context) const { |
| 133 return as_SIB(this)->onAsTextureRef(context); |
| 117 } | 134 } |
| 118 | 135 |
| 119 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) con
st { | 136 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) con
st { |
| 120 return as_SIB(this)->onMakeSurface(info); | 137 return as_SIB(this)->onMakeSurface(info); |
| 121 } | 138 } |
| 122 | 139 |
| 123 sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const
{ | 140 sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const
{ |
| 124 return as_SIB(this)->onMakeTightSurface(info); | 141 return as_SIB(this)->onMakeTightSurface(info); |
| 125 } | 142 } |
| 126 | 143 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 return 0; | 216 return 0; |
| 200 } | 217 } |
| 201 | 218 |
| 202 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { | 219 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
| 203 SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset
().height()); | 220 SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset
().height()); |
| 204 | 221 |
| 205 canvas->drawImageRect(fImage.get(), this->subset(), | 222 canvas->drawImageRect(fImage.get(), this->subset(), |
| 206 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 223 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 207 } | 224 } |
| 208 | 225 |
| 209 bool onPeekPixels(SkPixmap* pixmap) const override { | 226 bool onGetROPixels(SkBitmap* bm) const override { |
| 210 return fImage->peekPixels(pixmap); | 227 return as_IB(fImage)->getROPixels(bm); |
| 211 } | 228 } |
| 212 | 229 |
| 213 GrTexture* onPeekTexture() const override { return as_IB(fImage.get())->peek
Texture(); } | 230 GrTexture* onPeekTexture() const override { return as_IB(fImage)->peekTextur
e(); } |
| 231 |
| 232 GrTexture* onAsTextureRef(GrContext* context) const override { |
| 233 #if SK_SUPPORT_GPU |
| 234 return as_IB(fImage)->asTextureRef(context, GrTextureParams::ClampNoFilt
er()); |
| 235 #else |
| 236 return nullptr; |
| 237 #endif |
| 238 } |
| 214 | 239 |
| 215 bool getBitmapDeprecated(SkBitmap* result) const override { | 240 bool getBitmapDeprecated(SkBitmap* result) const override { |
| 216 #if SK_SUPPORT_GPU | 241 #if SK_SUPPORT_GPU |
| 217 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { | 242 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { |
| 218 const SkImageInfo info = GrMakeInfoFromTexture(texture, | 243 const SkImageInfo info = GrMakeInfoFromTexture(texture, |
| 219 fImage->width(), fIma
ge->height(), | 244 fImage->width(), fIma
ge->height(), |
| 220 fImage->isOpaque()); | 245 fImage->isOpaque()); |
| 221 if (!result->setInfo(info)) { | 246 if (!result->setInfo(info)) { |
| 222 return false; | 247 return false; |
| 223 } | 248 } |
| 224 | 249 |
| 225 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); | 250 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); |
| 226 return true; | 251 return true; |
| 227 } | 252 } |
| 228 #endif | 253 #endif |
| 229 | 254 |
| 230 return as_IB(fImage.get())->asBitmapForImageFilters(result); | 255 return as_IB(fImage.get())->asBitmapForImageFilters(result); |
| 231 } | 256 } |
| 232 | 257 |
| 233 bool testingOnlyOnGetROPixels(SkBitmap* result) const override { | |
| 234 return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode); | |
| 235 } | |
| 236 | |
| 237 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 258 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
| 238 #if SK_SUPPORT_GPU | 259 #if SK_SUPPORT_GPU |
| 239 GrTexture* texture = as_IB(fImage.get())->peekTexture(); | 260 GrTexture* texture = as_IB(fImage.get())->peekTexture(); |
| 240 if (texture) { | 261 if (texture) { |
| 241 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *texture->getCon
text()->caps()); | 262 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *texture->getCon
text()->caps()); |
| 242 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 263 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 243 | 264 |
| 244 return SkSpecialSurface::MakeRenderTarget(this->proxy(), texture->ge
tContext(), desc); | 265 return SkSpecialSurface::MakeRenderTarget(this->proxy(), texture->ge
tContext(), desc); |
| 245 } | 266 } |
| 246 #endif | 267 #endif |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 size_t getSize() const override { return fBitmap.getSize(); } | 360 size_t getSize() const override { return fBitmap.getSize(); } |
| 340 | 361 |
| 341 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { | 362 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
| 342 SkRect dst = SkRect::MakeXYWH(x, y, | 363 SkRect dst = SkRect::MakeXYWH(x, y, |
| 343 this->subset().width(), this->subset().hei
ght()); | 364 this->subset().width(), this->subset().hei
ght()); |
| 344 | 365 |
| 345 canvas->drawBitmapRect(fBitmap, this->subset(), | 366 canvas->drawBitmapRect(fBitmap, this->subset(), |
| 346 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 367 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 347 } | 368 } |
| 348 | 369 |
| 349 bool onPeekPixels(SkPixmap* pixmap) const override { | 370 bool onGetROPixels(SkBitmap* bm) const override { |
| 350 const SkImageInfo info = fBitmap.info(); | 371 *bm = fBitmap; |
| 372 return true; |
| 373 } |
| 351 | 374 |
| 352 if (kUnknown_SkColorType == info.colorType()) { | 375 GrTexture* onAsTextureRef(GrContext* context) const override { |
| 353 return false; | 376 #if SK_SUPPORT_GPU |
| 377 if (context) { |
| 378 return GrRefCachedBitmapTexture(context, fBitmap, GrTextureParams::C
lampNoFilter()); |
| 354 } | 379 } |
| 380 #endif |
| 355 | 381 |
| 356 if (!fBitmap.peekPixels(pixmap)) { | 382 return nullptr; |
| 357 fBitmap.lockPixels(); | |
| 358 } | |
| 359 | |
| 360 return fBitmap.peekPixels(pixmap); | |
| 361 } | 383 } |
| 362 | 384 |
| 363 bool getBitmapDeprecated(SkBitmap* result) const override { | 385 bool getBitmapDeprecated(SkBitmap* result) const override { |
| 364 *result = fBitmap; | 386 *result = fBitmap; |
| 365 return true; | 387 return true; |
| 366 } | 388 } |
| 367 | 389 |
| 368 bool testingOnlyOnGetROPixels(SkBitmap* result) const override { | |
| 369 *result = fBitmap; | |
| 370 return true; | |
| 371 } | |
| 372 | |
| 373 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 390 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
| 374 return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr); | 391 return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr); |
| 375 } | 392 } |
| 376 | 393 |
| 377 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { | 394 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
| 378 SkBitmap subsetBM; | 395 SkBitmap subsetBM; |
| 379 | 396 |
| 380 if (!fBitmap.extractSubset(&subsetBM, subset)) { | 397 if (!fBitmap.extractSubset(&subsetBM, subset)) { |
| 381 return nullptr; | 398 return nullptr; |
| 382 } | 399 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 #include "GrTexture.h" | 453 #include "GrTexture.h" |
| 437 #include "SkImage_Gpu.h" | 454 #include "SkImage_Gpu.h" |
| 438 | 455 |
| 439 class SkSpecialImage_Gpu : public SkSpecialImage_Base { | 456 class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
| 440 public: | 457 public: |
| 441 SkSpecialImage_Gpu(SkImageFilter::Proxy* proxy, const SkIRect& subset, | 458 SkSpecialImage_Gpu(SkImageFilter::Proxy* proxy, const SkIRect& subset, |
| 442 uint32_t uniqueID, GrTexture* tex, SkAlphaType at, | 459 uint32_t uniqueID, GrTexture* tex, SkAlphaType at, |
| 443 const SkSurfaceProps* props) | 460 const SkSurfaceProps* props) |
| 444 : INHERITED(proxy, subset, uniqueID, props) | 461 : INHERITED(proxy, subset, uniqueID, props) |
| 445 , fTexture(SkRef(tex)) | 462 , fTexture(SkRef(tex)) |
| 446 , fAlphaType(at) { | 463 , fAlphaType(at) |
| 464 , fAddedRasterVersionToCache(false) { |
| 447 } | 465 } |
| 448 | 466 |
| 449 ~SkSpecialImage_Gpu() override { } | 467 ~SkSpecialImage_Gpu() override { |
| 468 if (fAddedRasterVersionToCache.load()) { |
| 469 SkNotifyBitmapGenIDIsStale(this->uniqueID()); |
| 470 } |
| 471 } |
| 450 | 472 |
| 451 bool isOpaque() const override { | 473 bool isOpaque() const override { |
| 452 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaqu
e_SkAlphaType; | 474 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaqu
e_SkAlphaType; |
| 453 } | 475 } |
| 454 | 476 |
| 455 size_t getSize() const override { return fTexture->gpuMemorySize(); } | 477 size_t getSize() const override { return fTexture->gpuMemorySize(); } |
| 456 | 478 |
| 457 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { | 479 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
| 458 SkRect dst = SkRect::MakeXYWH(x, y, | 480 SkRect dst = SkRect::MakeXYWH(x, y, |
| 459 this->subset().width(), this->subset().hei
ght()); | 481 this->subset().width(), this->subset().hei
ght()); |
| 460 | 482 |
| 461 SkBitmap bm; | 483 SkBitmap bm; |
| 462 | 484 |
| 463 GrWrapTextureInBitmap(fTexture, | 485 GrWrapTextureInBitmap(fTexture, |
| 464 fTexture->width(), fTexture->height(), this->isOpa
que(), &bm); | 486 fTexture->width(), fTexture->height(), this->isOpa
que(), &bm); |
| 465 | 487 |
| 466 canvas->drawBitmapRect(bm, this->subset(), | 488 canvas->drawBitmapRect(bm, this->subset(), |
| 467 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 489 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 468 } | 490 } |
| 469 | 491 |
| 470 GrTexture* onPeekTexture() const override { return fTexture; } | 492 GrTexture* onPeekTexture() const override { return fTexture; } |
| 471 | 493 |
| 494 GrTexture* onAsTextureRef(GrContext*) const override { return SkRef(fTexture
.get()); } |
| 495 |
| 496 bool onGetROPixels(SkBitmap* dst) const override { |
| 497 if (SkBitmapCache::Find(this->uniqueID(), dst)) { |
| 498 SkASSERT(dst->getGenerationID() == this->uniqueID()); |
| 499 SkASSERT(dst->isImmutable()); |
| 500 SkASSERT(dst->getPixels()); |
| 501 return true; |
| 502 } |
| 503 |
| 504 SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(), |
| 505 this->isOpaque() ? kOpaque_SkAlp
haType |
| 506 : kPremul_SkAlp
haType); |
| 507 |
| 508 if (!dst->tryAllocPixels(info)) { |
| 509 return false; |
| 510 } |
| 511 |
| 512 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_G
rPixelConfig, |
| 513 dst->getPixels(), dst->rowBytes())) { |
| 514 return false; |
| 515 } |
| 516 |
| 517 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
| 518 SkBitmapCache::Add(this->uniqueID(), *dst); |
| 519 fAddedRasterVersionToCache.store(true); |
| 520 return true; |
| 521 } |
| 522 |
| 472 bool getBitmapDeprecated(SkBitmap* result) const override { | 523 bool getBitmapDeprecated(SkBitmap* result) const override { |
| 473 const SkImageInfo info = GrMakeInfoFromTexture(fTexture, | 524 const SkImageInfo info = GrMakeInfoFromTexture(fTexture, |
| 474 this->width(), this->heig
ht(), | 525 this->width(), this->heig
ht(), |
| 475 this->isOpaque()); | 526 this->isOpaque()); |
| 476 if (!result->setInfo(info)) { | 527 if (!result->setInfo(info)) { |
| 477 return false; | 528 return false; |
| 478 } | 529 } |
| 479 | 530 |
| 480 const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->heig
ht()); | 531 const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->heig
ht()); |
| 481 | 532 |
| 482 SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture)); | 533 SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture)); |
| 483 result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop)
; | 534 result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop)
; |
| 484 return true; | 535 return true; |
| 485 } | 536 } |
| 486 | 537 |
| 487 bool testingOnlyOnGetROPixels(SkBitmap* result) const override { | |
| 488 | |
| 489 const SkImageInfo info = SkImageInfo::MakeN32(this->width(), | |
| 490 this->height(), | |
| 491 this->isOpaque() ? kOpaque
_SkAlphaType | |
| 492 : kPremul
_SkAlphaType); | |
| 493 if (!result->tryAllocPixels(info)) { | |
| 494 return false; | |
| 495 } | |
| 496 | |
| 497 if (!fTexture->readPixels(0, 0, result->width(), result->height(), kSkia
8888_GrPixelConfig, | |
| 498 result->getPixels(), result->rowBytes())) { | |
| 499 return false; | |
| 500 } | |
| 501 | |
| 502 result->pixelRef()->setImmutable(); | |
| 503 return true; | |
| 504 } | |
| 505 | |
| 506 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 538 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
| 507 if (!fTexture->getContext()) { | 539 if (!fTexture->getContext()) { |
| 508 return nullptr; | 540 return nullptr; |
| 509 } | 541 } |
| 510 | 542 |
| 511 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *fTexture->getContex
t()->caps()); | 543 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *fTexture->getContex
t()->caps()); |
| 512 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 544 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 513 | 545 |
| 514 return SkSpecialSurface::MakeRenderTarget(this->proxy(), fTexture->getCo
ntext(), desc); | 546 return SkSpecialSurface::MakeRenderTarget(this->proxy(), fTexture->getCo
ntext(), desc); |
| 515 } | 547 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 fAlphaType, subTx, SkBudgeted::kYes); | 580 fAlphaType, subTx, SkBudgeted::kYes); |
| 549 } | 581 } |
| 550 | 582 |
| 551 sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override
{ | 583 sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override
{ |
| 552 return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::k
Yes, info); | 584 return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::k
Yes, info); |
| 553 } | 585 } |
| 554 | 586 |
| 555 private: | 587 private: |
| 556 SkAutoTUnref<GrTexture> fTexture; | 588 SkAutoTUnref<GrTexture> fTexture; |
| 557 const SkAlphaType fAlphaType; | 589 const SkAlphaType fAlphaType; |
| 590 mutable SkAtomic<bool> fAddedRasterVersionToCache; |
| 558 | 591 |
| 559 typedef SkSpecialImage_Base INHERITED; | 592 typedef SkSpecialImage_Base INHERITED; |
| 560 }; | 593 }; |
| 561 | 594 |
| 562 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, | 595 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
| 563 const SkIRect& subset, | 596 const SkIRect& subset, |
| 564 uint32_t uniqueID, | 597 uint32_t uniqueID, |
| 565 GrTexture* tex, | 598 GrTexture* tex, |
| 566 const SkSurfaceProps* props, | 599 const SkSurfaceProps* props, |
| 567 SkAlphaType at) { | 600 SkAlphaType at) { |
| 568 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 601 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
| 569 return sk_make_sp<SkSpecialImage_Gpu>(proxy, subset, uniqueID, tex, at, prop
s); | 602 return sk_make_sp<SkSpecialImage_Gpu>(proxy, subset, uniqueID, tex, at, prop
s); |
| 570 } | 603 } |
| 571 | 604 |
| 572 #else | 605 #else |
| 573 | 606 |
| 574 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, | 607 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
| 575 const SkIRect& subset, | 608 const SkIRect& subset, |
| 576 uint32_t uniqueID, | 609 uint32_t uniqueID, |
| 577 GrTexture* tex, | 610 GrTexture* tex, |
| 578 const SkSurfaceProps* props, | 611 const SkSurfaceProps* props, |
| 579 SkAlphaType at) { | 612 SkAlphaType at) { |
| 580 return nullptr; | 613 return nullptr; |
| 581 } | 614 } |
| 582 | 615 |
| 583 #endif | 616 #endif |
| OLD | NEW |