| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 : INHERITED(subset, uniqueID, props) { | 25 : INHERITED(subset, uniqueID, props) { |
| 26 } | 26 } |
| 27 ~SkSpecialImage_Base() override { } | 27 ~SkSpecialImage_Base() override { } |
| 28 | 28 |
| 29 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; | 29 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const
= 0; |
| 30 | 30 |
| 31 virtual bool onGetROPixels(SkBitmap*) const = 0; | 31 virtual bool onGetROPixels(SkBitmap*) const = 0; |
| 32 | 32 |
| 33 virtual GrTexture* onPeekTexture() const { return nullptr; } | 33 virtual GrTexture* onPeekTexture() const { return nullptr; } |
| 34 | 34 |
| 35 virtual GrTexture* onAsTextureRef(GrContext* context) const = 0; | 35 #if SK_SUPPORT_GPU |
| 36 virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0; |
| 37 #endif |
| 36 | 38 |
| 37 // Delete this entry point ASAP (see skbug.com/4965) | 39 // Delete this entry point ASAP (see skbug.com/4965) |
| 38 virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; | 40 virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; |
| 39 | 41 |
| 40 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; | 42 virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; |
| 41 | 43 |
| 42 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const
= 0; | 44 virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const
= 0; |
| 43 | 45 |
| 44 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; | 46 virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; |
| 45 | 47 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 73 | 75 |
| 74 SkBitmap bmp; | 76 SkBitmap bmp; |
| 75 if (!this->internal_getBM(&bmp)) { | 77 if (!this->internal_getBM(&bmp)) { |
| 76 return nullptr; | 78 return nullptr; |
| 77 } | 79 } |
| 78 | 80 |
| 79 if (bmp.empty()) { | 81 if (bmp.empty()) { |
| 80 return SkSpecialImage::MakeFromRaster(SkIRect::MakeEmpty(), bmp, &this->
props()); | 82 return SkSpecialImage::MakeFromRaster(SkIRect::MakeEmpty(), bmp, &this->
props()); |
| 81 } | 83 } |
| 82 | 84 |
| 83 SkAutoTUnref<GrTexture> resultTex( | 85 sk_sp<GrTexture> resultTex(GrRefCachedBitmapTexture(context, |
| 84 GrRefCachedBitmapTexture(context, bmp, GrTextureParams::ClampNoFilter())
); | 86 bmp, |
| 87 GrTextureParams::ClampNo
Filter())); |
| 85 if (!resultTex) { | 88 if (!resultTex) { |
| 86 return nullptr; | 89 return nullptr; |
| 87 } | 90 } |
| 88 | 91 |
| 89 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp
e; | 92 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp
e; |
| 90 | 93 |
| 91 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(resultTex->width(), resul
tTex->height()), | 94 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(resultTex->width(), resul
tTex->height()), |
| 92 this->uniqueID(), | 95 this->uniqueID(), |
| 93 resultTex, &this->props(), at); | 96 resultTex, &this->props(), at); |
| 94 #else | 97 #else |
| (...skipping 21 matching lines...) Expand all Loading... |
| 116 #if SK_SUPPORT_GPU | 119 #if SK_SUPPORT_GPU |
| 117 GrTexture* texture = as_SIB(this)->onPeekTexture(); | 120 GrTexture* texture = as_SIB(this)->onPeekTexture(); |
| 118 | 121 |
| 119 if (texture) { | 122 if (texture) { |
| 120 return texture->getContext(); | 123 return texture->getContext(); |
| 121 } | 124 } |
| 122 #endif | 125 #endif |
| 123 return nullptr; | 126 return nullptr; |
| 124 } | 127 } |
| 125 | 128 |
| 126 | 129 #if SK_SUPPORT_GPU |
| 127 GrTexture* SkSpecialImage::asTextureRef(GrContext* context) const { | 130 sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const { |
| 128 return as_SIB(this)->onAsTextureRef(context); | 131 return as_SIB(this)->onAsTextureRef(context); |
| 129 } | 132 } |
| 133 #endif |
| 130 | 134 |
| 131 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) con
st { | 135 sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) con
st { |
| 132 return as_SIB(this)->onMakeSurface(info); | 136 return as_SIB(this)->onMakeSurface(info); |
| 133 } | 137 } |
| 134 | 138 |
| 135 sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const
{ | 139 sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const
{ |
| 136 return as_SIB(this)->onMakeTightSurface(info); | 140 return as_SIB(this)->onMakeTightSurface(info); |
| 137 } | 141 } |
| 138 | 142 |
| 139 sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { | 143 sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { |
| 140 return as_SIB(this)->onMakeSubset(subset); | 144 return as_SIB(this)->onMakeSubset(subset); |
| 141 } | 145 } |
| 142 | 146 |
| 143 sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const { | 147 sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const { |
| 144 return as_SIB(this)->onMakeTightSubset(subset); | 148 return as_SIB(this)->onMakeTightSubset(subset); |
| 145 } | 149 } |
| 146 | 150 |
| 147 #if SK_SUPPORT_GPU | 151 #if SK_SUPPORT_GPU |
| 148 #include "SkGr.h" | 152 #include "SkGr.h" |
| 149 #include "SkGrPixelRef.h" | 153 #include "SkGrPixelRef.h" |
| 150 #endif | 154 #endif |
| 151 | 155 |
| 152 sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(const SkBitmap& src, | 156 sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(const SkBitmap& src, |
| 153 const SkSurfaceProps* prop
s) { | 157 const SkSurfaceProps* prop
s) { |
| 158 #if SK_SUPPORT_GPU |
| 154 // Need to test offset case! (see skbug.com/4967) | 159 // Need to test offset case! (see skbug.com/4967) |
| 155 if (src.getTexture()) { | 160 if (src.getTexture()) { |
| 156 return SkSpecialImage::MakeFromGpu(src.bounds(), | 161 return SkSpecialImage::MakeFromGpu(src.bounds(), |
| 157 src.getGenerationID(), | 162 src.getGenerationID(), |
| 158 src.getTexture(), | 163 sk_ref_sp(src.getTexture()), |
| 159 props); | 164 props); |
| 160 } | 165 } |
| 166 #endif |
| 161 | 167 |
| 162 return SkSpecialImage::MakeFromRaster(src.bounds(), src, props); | 168 return SkSpecialImage::MakeFromRaster(src.bounds(), src, props); |
| 163 } | 169 } |
| 164 | 170 |
| 165 bool SkSpecialImage::internal_getBM(SkBitmap* result) { | 171 bool SkSpecialImage::internal_getBM(SkBitmap* result) { |
| 166 const SkSpecialImage_Base* ib = as_SIB(this); | 172 const SkSpecialImage_Base* ib = as_SIB(this); |
| 167 | 173 |
| 168 // TODO: need to test offset case! (see skbug.com/4967) | 174 // TODO: need to test offset case! (see skbug.com/4967) |
| 169 return ib->getBitmapDeprecated(result); | 175 return ib->getBitmapDeprecated(result); |
| 170 } | 176 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 canvas->drawImageRect(fImage.get(), this->subset(), | 216 canvas->drawImageRect(fImage.get(), this->subset(), |
| 211 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 217 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 212 } | 218 } |
| 213 | 219 |
| 214 bool onGetROPixels(SkBitmap* bm) const override { | 220 bool onGetROPixels(SkBitmap* bm) const override { |
| 215 return as_IB(fImage)->getROPixels(bm); | 221 return as_IB(fImage)->getROPixels(bm); |
| 216 } | 222 } |
| 217 | 223 |
| 218 GrTexture* onPeekTexture() const override { return as_IB(fImage)->peekTextur
e(); } | 224 GrTexture* onPeekTexture() const override { return as_IB(fImage)->peekTextur
e(); } |
| 219 | 225 |
| 220 GrTexture* onAsTextureRef(GrContext* context) const override { | |
| 221 #if SK_SUPPORT_GPU | 226 #if SK_SUPPORT_GPU |
| 222 return as_IB(fImage)->asTextureRef(context, GrTextureParams::ClampNoFilt
er()); | 227 sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override { |
| 223 #else | 228 return sk_sp<GrTexture>(as_IB(fImage)->asTextureRef(context, |
| 224 return nullptr; | 229 GrTextureParams::Cla
mpNoFilter())); |
| 230 } |
| 225 #endif | 231 #endif |
| 226 } | |
| 227 | 232 |
| 228 bool getBitmapDeprecated(SkBitmap* result) const override { | 233 bool getBitmapDeprecated(SkBitmap* result) const override { |
| 229 #if SK_SUPPORT_GPU | 234 #if SK_SUPPORT_GPU |
| 230 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { | 235 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { |
| 231 const SkImageInfo info = GrMakeInfoFromTexture(texture, | 236 const SkImageInfo info = GrMakeInfoFromTexture(texture, |
| 232 fImage->width(), fIma
ge->height(), | 237 fImage->width(), fIma
ge->height(), |
| 233 fImage->isOpaque()); | 238 fImage->isOpaque()); |
| 234 if (!result->setInfo(info)) { | 239 if (!result->setInfo(info)) { |
| 235 return false; | 240 return false; |
| 236 } | 241 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 354 |
| 350 canvas->drawBitmapRect(fBitmap, this->subset(), | 355 canvas->drawBitmapRect(fBitmap, this->subset(), |
| 351 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 356 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 352 } | 357 } |
| 353 | 358 |
| 354 bool onGetROPixels(SkBitmap* bm) const override { | 359 bool onGetROPixels(SkBitmap* bm) const override { |
| 355 *bm = fBitmap; | 360 *bm = fBitmap; |
| 356 return true; | 361 return true; |
| 357 } | 362 } |
| 358 | 363 |
| 359 GrTexture* onAsTextureRef(GrContext* context) const override { | |
| 360 #if SK_SUPPORT_GPU | 364 #if SK_SUPPORT_GPU |
| 365 sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override { |
| 361 if (context) { | 366 if (context) { |
| 362 return GrRefCachedBitmapTexture(context, fBitmap, GrTextureParams::C
lampNoFilter()); | 367 return sk_ref_sp(GrRefCachedBitmapTexture(context, |
| 368 fBitmap, |
| 369 GrTextureParams::ClampNoFi
lter())); |
| 363 } | 370 } |
| 364 #endif | |
| 365 | 371 |
| 366 return nullptr; | 372 return nullptr; |
| 367 } | 373 } |
| 374 #endif |
| 368 | 375 |
| 369 bool getBitmapDeprecated(SkBitmap* result) const override { | 376 bool getBitmapDeprecated(SkBitmap* result) const override { |
| 370 *result = fBitmap; | 377 *result = fBitmap; |
| 371 return true; | 378 return true; |
| 372 } | 379 } |
| 373 | 380 |
| 374 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 381 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
| 375 return SkSpecialSurface::MakeRaster(info, nullptr); | 382 return SkSpecialSurface::MakeRaster(info, nullptr); |
| 376 } | 383 } |
| 377 | 384 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 437 |
| 431 | 438 |
| 432 #if SK_SUPPORT_GPU | 439 #if SK_SUPPORT_GPU |
| 433 /////////////////////////////////////////////////////////////////////////////// | 440 /////////////////////////////////////////////////////////////////////////////// |
| 434 #include "GrTexture.h" | 441 #include "GrTexture.h" |
| 435 #include "SkImage_Gpu.h" | 442 #include "SkImage_Gpu.h" |
| 436 | 443 |
| 437 class SkSpecialImage_Gpu : public SkSpecialImage_Base { | 444 class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
| 438 public: | 445 public: |
| 439 SkSpecialImage_Gpu(const SkIRect& subset, | 446 SkSpecialImage_Gpu(const SkIRect& subset, |
| 440 uint32_t uniqueID, GrTexture* tex, SkAlphaType at, | 447 uint32_t uniqueID, sk_sp<GrTexture> tex, SkAlphaType at, |
| 441 const SkSurfaceProps* props) | 448 const SkSurfaceProps* props) |
| 442 : INHERITED(subset, uniqueID, props) | 449 : INHERITED(subset, uniqueID, props) |
| 443 , fTexture(SkRef(tex)) | 450 , fTexture(std::move(tex)) |
| 444 , fAlphaType(at) | 451 , fAlphaType(at) |
| 445 , fAddedRasterVersionToCache(false) { | 452 , fAddedRasterVersionToCache(false) { |
| 446 } | 453 } |
| 447 | 454 |
| 448 ~SkSpecialImage_Gpu() override { | 455 ~SkSpecialImage_Gpu() override { |
| 449 if (fAddedRasterVersionToCache.load()) { | 456 if (fAddedRasterVersionToCache.load()) { |
| 450 SkNotifyBitmapGenIDIsStale(this->uniqueID()); | 457 SkNotifyBitmapGenIDIsStale(this->uniqueID()); |
| 451 } | 458 } |
| 452 } | 459 } |
| 453 | 460 |
| 454 bool isOpaque() const override { | 461 bool isOpaque() const override { |
| 455 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaqu
e_SkAlphaType; | 462 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaqu
e_SkAlphaType; |
| 456 } | 463 } |
| 457 | 464 |
| 458 size_t getSize() const override { return fTexture->gpuMemorySize(); } | 465 size_t getSize() const override { return fTexture->gpuMemorySize(); } |
| 459 | 466 |
| 460 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { | 467 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
| 461 SkRect dst = SkRect::MakeXYWH(x, y, | 468 SkRect dst = SkRect::MakeXYWH(x, y, |
| 462 this->subset().width(), this->subset().hei
ght()); | 469 this->subset().width(), this->subset().hei
ght()); |
| 463 | 470 |
| 464 SkBitmap bm; | 471 SkBitmap bm; |
| 465 | 472 |
| 466 GrWrapTextureInBitmap(fTexture, | 473 GrWrapTextureInBitmap(fTexture.get(), |
| 467 fTexture->width(), fTexture->height(), this->isOpa
que(), &bm); | 474 fTexture->width(), fTexture->height(), this->isOpa
que(), &bm); |
| 468 | 475 |
| 469 canvas->drawBitmapRect(bm, this->subset(), | 476 canvas->drawBitmapRect(bm, this->subset(), |
| 470 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 477 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 471 } | 478 } |
| 472 | 479 |
| 473 GrTexture* onPeekTexture() const override { return fTexture; } | 480 GrTexture* onPeekTexture() const override { return fTexture.get(); } |
| 474 | 481 |
| 475 GrTexture* onAsTextureRef(GrContext*) const override { return SkRef(fTexture
.get()); } | 482 sk_sp<GrTexture> onAsTextureRef(GrContext*) const override { return fTexture
; } |
| 476 | 483 |
| 477 bool onGetROPixels(SkBitmap* dst) const override { | 484 bool onGetROPixels(SkBitmap* dst) const override { |
| 478 if (SkBitmapCache::Find(this->uniqueID(), dst)) { | 485 if (SkBitmapCache::Find(this->uniqueID(), dst)) { |
| 479 SkASSERT(dst->getGenerationID() == this->uniqueID()); | 486 SkASSERT(dst->getGenerationID() == this->uniqueID()); |
| 480 SkASSERT(dst->isImmutable()); | 487 SkASSERT(dst->isImmutable()); |
| 481 SkASSERT(dst->getPixels()); | 488 SkASSERT(dst->getPixels()); |
| 482 return true; | 489 return true; |
| 483 } | 490 } |
| 484 | 491 |
| 485 SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(), | 492 SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(), |
| 486 this->isOpaque() ? kOpaque_SkAlp
haType | 493 this->isOpaque() ? kOpaque_SkAlp
haType |
| 487 : kPremul_SkAlp
haType); | 494 : kPremul_SkAlp
haType); |
| 488 | 495 |
| 489 if (!dst->tryAllocPixels(info)) { | 496 if (!dst->tryAllocPixels(info)) { |
| 490 return false; | 497 return false; |
| 491 } | 498 } |
| 492 | 499 |
| 493 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_G
rPixelConfig, | 500 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_G
rPixelConfig, |
| 494 dst->getPixels(), dst->rowBytes())) { | 501 dst->getPixels(), dst->rowBytes())) { |
| 495 return false; | 502 return false; |
| 496 } | 503 } |
| 497 | 504 |
| 498 dst->pixelRef()->setImmutableWithID(this->uniqueID()); | 505 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
| 499 SkBitmapCache::Add(this->uniqueID(), *dst); | 506 SkBitmapCache::Add(this->uniqueID(), *dst); |
| 500 fAddedRasterVersionToCache.store(true); | 507 fAddedRasterVersionToCache.store(true); |
| 501 return true; | 508 return true; |
| 502 } | 509 } |
| 503 | 510 |
| 504 bool getBitmapDeprecated(SkBitmap* result) const override { | 511 bool getBitmapDeprecated(SkBitmap* result) const override { |
| 505 const SkImageInfo info = GrMakeInfoFromTexture(fTexture, | 512 const SkImageInfo info = GrMakeInfoFromTexture(fTexture.get(), |
| 506 this->width(), this->heig
ht(), | 513 this->width(), this->heig
ht(), |
| 507 this->isOpaque()); | 514 this->isOpaque()); |
| 508 if (!result->setInfo(info)) { | 515 if (!result->setInfo(info)) { |
| 509 return false; | 516 return false; |
| 510 } | 517 } |
| 511 | 518 |
| 512 const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->heig
ht()); | 519 const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->heig
ht()); |
| 513 | 520 |
| 514 SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture)); | 521 SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture.ge
t())); |
| 515 result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop)
; | 522 result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop)
; |
| 516 return true; | 523 return true; |
| 517 } | 524 } |
| 518 | 525 |
| 519 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 526 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
| 520 if (!fTexture->getContext()) { | 527 if (!fTexture->getContext()) { |
| 521 return nullptr; | 528 return nullptr; |
| 522 } | 529 } |
| 523 | 530 |
| 524 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *fTexture->getContex
t()->caps()); | 531 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *fTexture->getContex
t()->caps()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 535 fAlphaType); | 542 fAlphaType); |
| 536 } | 543 } |
| 537 | 544 |
| 538 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { | 545 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| 539 if (0 == subset.fLeft && 0 == subset.fTop && | 546 if (0 == subset.fLeft && 0 == subset.fTop && |
| 540 fTexture->width() == subset.width() && | 547 fTexture->width() == subset.width() && |
| 541 fTexture->height() == subset.height()) { | 548 fTexture->height() == subset.height()) { |
| 542 // The existing GrTexture is already tight so reuse it in the SkImag
e | 549 // The existing GrTexture is already tight so reuse it in the SkImag
e |
| 543 return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height()
, | 550 return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height()
, |
| 544 kNeedNewImageUniqueID, | 551 kNeedNewImageUniqueID, |
| 545 fAlphaType, fTexture, SkBudgeted::kYe
s); | 552 fAlphaType, fTexture.get(), SkBudgete
d::kYes); |
| 546 } | 553 } |
| 547 | 554 |
| 548 GrContext* ctx = fTexture->getContext(); | 555 GrContext* ctx = fTexture->getContext(); |
| 549 GrSurfaceDesc desc = fTexture->desc(); | 556 GrSurfaceDesc desc = fTexture->desc(); |
| 550 desc.fWidth = subset.width(); | 557 desc.fWidth = subset.width(); |
| 551 desc.fHeight = subset.height(); | 558 desc.fHeight = subset.height(); |
| 552 | 559 |
| 553 SkAutoTUnref<GrTexture> subTx(ctx->textureProvider()->createTexture(desc
, | 560 sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, SkBud
geted::kYes)); |
| 554 SkBu
dgeted::kYes)); | |
| 555 if (!subTx) { | 561 if (!subTx) { |
| 556 return nullptr; | 562 return nullptr; |
| 557 } | 563 } |
| 558 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); | 564 ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0,
0)); |
| 559 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageU
niqueID, | 565 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageU
niqueID, |
| 560 fAlphaType, subTx, SkBudgeted::kYes); | 566 fAlphaType, subTx.get(), SkBudgeted::kYes
); |
| 561 } | 567 } |
| 562 | 568 |
| 563 sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override
{ | 569 sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override
{ |
| 564 return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::k
Yes, info); | 570 return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::k
Yes, info); |
| 565 } | 571 } |
| 566 | 572 |
| 567 private: | 573 private: |
| 568 SkAutoTUnref<GrTexture> fTexture; | 574 sk_sp<GrTexture> fTexture; |
| 569 const SkAlphaType fAlphaType; | 575 const SkAlphaType fAlphaType; |
| 570 mutable SkAtomic<bool> fAddedRasterVersionToCache; | 576 mutable SkAtomic<bool> fAddedRasterVersionToCache; |
| 571 | 577 |
| 572 typedef SkSpecialImage_Base INHERITED; | 578 typedef SkSpecialImage_Base INHERITED; |
| 573 }; | 579 }; |
| 574 | 580 |
| 575 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, | 581 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, |
| 576 uint32_t uniqueID, | 582 uint32_t uniqueID, |
| 577 GrTexture* tex, | 583 sk_sp<GrTexture> tex, |
| 578 const SkSurfaceProps* props, | 584 const SkSurfaceProps* props, |
| 579 SkAlphaType at) { | 585 SkAlphaType at) { |
| 580 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 586 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
| 581 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, tex, at, props); | 587 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
props); |
| 582 } | |
| 583 | |
| 584 #else | |
| 585 | |
| 586 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, | |
| 587 uint32_t uniqueID, | |
| 588 GrTexture* tex, | |
| 589 const SkSurfaceProps* props, | |
| 590 SkAlphaType at) { | |
| 591 return nullptr; | |
| 592 } | 588 } |
| 593 | 589 |
| 594 #endif | 590 #endif |
| OLD | NEW |