| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 class SkSpecialImage_Image : public SkSpecialImage_Base { | 159 class SkSpecialImage_Image : public SkSpecialImage_Base { |
| 160 public: | 160 public: |
| 161 SkSpecialImage_Image(SkImageFilter::Proxy* proxy, | 161 SkSpecialImage_Image(SkImageFilter::Proxy* proxy, |
| 162 const SkIRect& subset, | 162 const SkIRect& subset, |
| 163 sk_sp<SkImage> image) | 163 sk_sp<SkImage> image) |
| 164 : INHERITED(proxy, subset, image->uniqueID()) | 164 : INHERITED(proxy, subset, image->uniqueID()) |
| 165 , fImage(image) { | 165 , fImage(image) { |
| 166 } | 166 } |
| 167 | 167 |
| 168 ~SkSpecialImage_Image() override { } | 168 ~SkSpecialImage_Image() override { } |
| 169 | 169 |
| 170 bool isOpaque() const override { return fImage->isOpaque(); } | 170 bool isOpaque() const override { return fImage->isOpaque(); } |
| 171 | 171 |
| 172 size_t getSize() const override { | 172 size_t getSize() const override { |
| 173 #if SK_SUPPORT_GPU | 173 #if SK_SUPPORT_GPU |
| 174 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { | 174 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { |
| 175 return texture->gpuMemorySize(); | 175 return texture->gpuMemorySize(); |
| 176 } else | 176 } else |
| 177 #endif | 177 #endif |
| 178 { | 178 { |
| 179 SkPixmap pm; | 179 SkPixmap pm; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 193 | 193 |
| 194 bool onPeekPixels(SkPixmap* pixmap) const override { | 194 bool onPeekPixels(SkPixmap* pixmap) const override { |
| 195 return fImage->peekPixels(pixmap); | 195 return fImage->peekPixels(pixmap); |
| 196 } | 196 } |
| 197 | 197 |
| 198 GrTexture* onPeekTexture() const override { return as_IB(fImage.get())->peek
Texture(); } | 198 GrTexture* onPeekTexture() const override { return as_IB(fImage.get())->peek
Texture(); } |
| 199 | 199 |
| 200 bool getBitmapDeprecated(SkBitmap* result) const override { | 200 bool getBitmapDeprecated(SkBitmap* result) const override { |
| 201 #if SK_SUPPORT_GPU | 201 #if SK_SUPPORT_GPU |
| 202 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { | 202 if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) { |
| 203 const SkImageInfo info = GrMakeInfoFromTexture(texture, | 203 const SkImageInfo info = GrMakeInfoFromTexture(texture, |
| 204 fImage->width(), fIma
ge->height(), | 204 fImage->width(), fIma
ge->height(), |
| 205 fImage->isOpaque()); | 205 fImage->isOpaque()); |
| 206 if (!result->setInfo(info)) { | 206 if (!result->setInfo(info)) { |
| 207 return false; | 207 return false; |
| 208 } | 208 } |
| 209 | 209 |
| 210 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); | 210 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); |
| 211 return true; | 211 return true; |
| 212 } | 212 } |
| 213 #endif | 213 #endif |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 *result = fBitmap; | 350 *result = fBitmap; |
| 351 return true; | 351 return true; |
| 352 } | 352 } |
| 353 | 353 |
| 354 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { | 354 sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const overrid
e { |
| 355 return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr); | 355 return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr); |
| 356 } | 356 } |
| 357 | 357 |
| 358 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { | 358 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
| 359 SkBitmap subsetBM; | 359 SkBitmap subsetBM; |
| 360 | 360 |
| 361 if (!fBitmap.extractSubset(&subsetBM, subset)) { | 361 if (!fBitmap.extractSubset(&subsetBM, subset)) { |
| 362 return nullptr; | 362 return nullptr; |
| 363 } | 363 } |
| 364 | 364 |
| 365 return SkSpecialImage::MakeFromRaster(this->internal_getProxy(), | 365 return SkSpecialImage::MakeFromRaster(this->internal_getProxy(), |
| 366 SkIRect::MakeWH(subset.width(), su
bset.height()), | 366 SkIRect::MakeWH(subset.width(), su
bset.height()), |
| 367 subsetBM); | 367 subsetBM); |
| 368 } | 368 } |
| 369 | 369 |
| 370 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { | 370 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, src, releaseProc, co
ntext); | 408 return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, src, releaseProc, co
ntext); |
| 409 } | 409 } |
| 410 | 410 |
| 411 | 411 |
| 412 #if SK_SUPPORT_GPU | 412 #if SK_SUPPORT_GPU |
| 413 /////////////////////////////////////////////////////////////////////////////// | 413 /////////////////////////////////////////////////////////////////////////////// |
| 414 #include "GrTexture.h" | 414 #include "GrTexture.h" |
| 415 #include "SkImage_Gpu.h" | 415 #include "SkImage_Gpu.h" |
| 416 | 416 |
| 417 class SkSpecialImage_Gpu : public SkSpecialImage_Base { | 417 class SkSpecialImage_Gpu : public SkSpecialImage_Base { |
| 418 public: | 418 public: |
| 419 SkSpecialImage_Gpu(SkImageFilter::Proxy* proxy, const SkIRect& subset, | 419 SkSpecialImage_Gpu(SkImageFilter::Proxy* proxy, const SkIRect& subset, |
| 420 uint32_t uniqueID, GrTexture* tex, SkAlphaType at) | 420 uint32_t uniqueID, GrTexture* tex, SkAlphaType at) |
| 421 : INHERITED(proxy, subset, uniqueID) | 421 : INHERITED(proxy, subset, uniqueID) |
| 422 , fTexture(SkRef(tex)) | 422 , fTexture(SkRef(tex)) |
| 423 , fAlphaType(at) { | 423 , fAlphaType(at) { |
| 424 } | 424 } |
| 425 | 425 |
| 426 ~SkSpecialImage_Gpu() override { } | 426 ~SkSpecialImage_Gpu() override { } |
| 427 | 427 |
| 428 bool isOpaque() const override { | 428 bool isOpaque() const override { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 440 GrWrapTextureInBitmap(fTexture, | 440 GrWrapTextureInBitmap(fTexture, |
| 441 fTexture->width(), fTexture->height(), this->isOpa
que(), &bm); | 441 fTexture->width(), fTexture->height(), this->isOpa
que(), &bm); |
| 442 | 442 |
| 443 canvas->drawBitmapRect(bm, this->subset(), | 443 canvas->drawBitmapRect(bm, this->subset(), |
| 444 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 444 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
| 445 } | 445 } |
| 446 | 446 |
| 447 GrTexture* onPeekTexture() const override { return fTexture; } | 447 GrTexture* onPeekTexture() const override { return fTexture; } |
| 448 | 448 |
| 449 bool getBitmapDeprecated(SkBitmap* result) const override { | 449 bool getBitmapDeprecated(SkBitmap* result) const override { |
| 450 const SkImageInfo info = GrMakeInfoFromTexture(fTexture, | 450 const SkImageInfo info = GrMakeInfoFromTexture(fTexture, |
| 451 this->width(), this->heig
ht(), | 451 this->width(), this->heig
ht(), |
| 452 this->isOpaque()); | 452 this->isOpaque()); |
| 453 if (!result->setInfo(info)) { | 453 if (!result->setInfo(info)) { |
| 454 return false; | 454 return false; |
| 455 } | 455 } |
| 456 | 456 |
| 457 const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->heig
ht()); | 457 const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->heig
ht()); |
| 458 | 458 |
| 459 SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture)); | 459 SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture)); |
| 460 result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop)
; | 460 result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop)
; |
| 461 return true; | 461 return true; |
| 462 } | 462 } |
| 463 | 463 |
| 464 bool testingOnlyOnGetROPixels(SkBitmap* result) const override { | 464 bool testingOnlyOnGetROPixels(SkBitmap* result) const override { |
| 465 | 465 |
| 466 const SkImageInfo info = SkImageInfo::MakeN32(this->width(), | 466 const SkImageInfo info = SkImageInfo::MakeN32(this->width(), |
| 467 this->height(), | 467 this->height(), |
| 468 this->isOpaque() ? kOpaque
_SkAlphaType | 468 this->isOpaque() ? kOpaque
_SkAlphaType |
| 469 : kPremul
_SkAlphaType); | 469 : kPremul
_SkAlphaType); |
| 470 if (!result->tryAllocPixels(info)) { | 470 if (!result->tryAllocPixels(info)) { |
| 471 return false; | 471 return false; |
| 472 } | 472 } |
| 473 | 473 |
| 474 if (!fTexture->readPixels(0, 0, result->width(), result->height(), kSkia
8888_GrPixelConfig, | 474 if (!fTexture->readPixels(0, 0, result->width(), result->height(), kSkia
8888_GrPixelConfig, |
| 475 result->getPixels(), result->rowBytes())) { | 475 result->getPixels(), result->rowBytes())) { |
| 476 return false; | 476 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 488 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *fTexture->getContex
t()->caps()); | 488 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *fTexture->getContex
t()->caps()); |
| 489 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 489 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 490 | 490 |
| 491 return SkSpecialSurface::MakeRenderTarget(this->proxy(), fTexture->getCo
ntext(), desc); | 491 return SkSpecialSurface::MakeRenderTarget(this->proxy(), fTexture->getCo
ntext(), desc); |
| 492 } | 492 } |
| 493 | 493 |
| 494 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { | 494 sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { |
| 495 return SkSpecialImage::MakeFromGpu(this->internal_getProxy(), | 495 return SkSpecialImage::MakeFromGpu(this->internal_getProxy(), |
| 496 subset, | 496 subset, |
| 497 this->uniqueID(), | 497 this->uniqueID(), |
| 498 fTexture, | 498 fTexture, |
| 499 fAlphaType); | 499 fAlphaType); |
| 500 } | 500 } |
| 501 | 501 |
| 502 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { | 502 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
| 503 if (0 == subset.fLeft && 0 == subset.fTop && | 503 if (0 == subset.fLeft && 0 == subset.fTop && |
| 504 fTexture->width() == subset.width() && | 504 fTexture->width() == subset.width() && |
| 505 fTexture->height() == subset.height()) { | 505 fTexture->height() == subset.height()) { |
| 506 // The existing GrTexture is already tight so reuse it in the SkImag
e | 506 // The existing GrTexture is already tight so reuse it in the SkImag
e |
| 507 return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height()
, | 507 return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height()
, |
| 508 kNeedNewImageUniqueID, | 508 kNeedNewImageUniqueID, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 529 } | 529 } |
| 530 | 530 |
| 531 private: | 531 private: |
| 532 SkAutoTUnref<GrTexture> fTexture; | 532 SkAutoTUnref<GrTexture> fTexture; |
| 533 const SkAlphaType fAlphaType; | 533 const SkAlphaType fAlphaType; |
| 534 | 534 |
| 535 typedef SkSpecialImage_Base INHERITED; | 535 typedef SkSpecialImage_Base INHERITED; |
| 536 }; | 536 }; |
| 537 | 537 |
| 538 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, | 538 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
| 539 const SkIRect& subset, | 539 const SkIRect& subset, |
| 540 uint32_t uniqueID, | 540 uint32_t uniqueID, |
| 541 GrTexture* tex, | 541 GrTexture* tex, |
| 542 SkAlphaType at) { | 542 SkAlphaType at) { |
| 543 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 543 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
| 544 return sk_make_sp<SkSpecialImage_Gpu>(proxy, subset, uniqueID, tex, at); | 544 return sk_make_sp<SkSpecialImage_Gpu>(proxy, subset, uniqueID, tex, at); |
| 545 } | 545 } |
| 546 | 546 |
| 547 #else | 547 #else |
| 548 | 548 |
| 549 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, | 549 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy, |
| 550 const SkIRect& subset, | 550 const SkIRect& subset, |
| 551 uint32_t uniqueID, | 551 uint32_t uniqueID, |
| 552 GrTexture* tex, | 552 GrTexture* tex, |
| 553 SkAlphaType at) { | 553 SkAlphaType at) { |
| 554 return nullptr; | 554 return nullptr; |
| 555 } | 555 } |
| 556 | 556 |
| 557 #endif | 557 #endif |
| OLD | NEW |