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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 bool isOpaque() const override { | 460 bool isOpaque() const override { |
461 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaqu
e_SkAlphaType; | 461 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaqu
e_SkAlphaType; |
462 } | 462 } |
463 | 463 |
464 size_t getSize() const override { return fTexture->gpuMemorySize(); } | 464 size_t getSize() const override { return fTexture->gpuMemorySize(); } |
465 | 465 |
466 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { | 466 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
const override { |
467 SkRect dst = SkRect::MakeXYWH(x, y, | 467 SkRect dst = SkRect::MakeXYWH(x, y, |
468 this->subset().width(), this->subset().hei
ght()); | 468 this->subset().width(), this->subset().hei
ght()); |
469 | 469 |
| 470 // TODO: Supply correct color space after we're storing it here |
470 auto img = sk_sp<SkImage>(new SkImage_Gpu(fTexture->width(), fTexture->h
eight(), | 471 auto img = sk_sp<SkImage>(new SkImage_Gpu(fTexture->width(), fTexture->h
eight(), |
471 this->uniqueID(), fAlphaType,
fTexture.get(), | 472 this->uniqueID(), fAlphaType,
fTexture.get(), |
472 SkBudgeted::kNo)); | 473 nullptr, SkBudgeted::kNo)); |
473 | 474 |
474 canvas->drawImageRect(img, this->subset(), | 475 canvas->drawImageRect(img, this->subset(), |
475 dst, paint, SkCanvas::kStrict_SrcRectConstraint); | 476 dst, paint, SkCanvas::kStrict_SrcRectConstraint); |
476 } | 477 } |
477 | 478 |
478 GrTexture* onPeekTexture() const override { return fTexture.get(); } | 479 GrTexture* onPeekTexture() const override { return fTexture.get(); } |
479 | 480 |
480 sk_sp<GrTexture> onAsTextureRef(GrContext*) const override { return fTexture
; } | 481 sk_sp<GrTexture> onAsTextureRef(GrContext*) const override { return fTexture
; } |
481 | 482 |
482 bool onGetROPixels(SkBitmap* dst) const override { | 483 bool onGetROPixels(SkBitmap* dst) const override { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 fTexture, | 540 fTexture, |
540 &this->props(), | 541 &this->props(), |
541 fAlphaType); | 542 fAlphaType); |
542 } | 543 } |
543 | 544 |
544 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { | 545 sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { |
545 if (0 == subset.fLeft && 0 == subset.fTop && | 546 if (0 == subset.fLeft && 0 == subset.fTop && |
546 fTexture->width() == subset.width() && | 547 fTexture->width() == subset.width() && |
547 fTexture->height() == subset.height()) { | 548 fTexture->height() == subset.height()) { |
548 // 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 |
| 550 // TODO: Supply correct color space after we're storing it here |
549 return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height()
, | 551 return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height()
, |
550 kNeedNewImageUniqueID, | 552 kNeedNewImageUniqueID, |
551 fAlphaType, fTexture.get(), SkBudgete
d::kYes); | 553 fAlphaType, fTexture.get(), nullptr,
SkBudgeted::kYes); |
552 } | 554 } |
553 | 555 |
554 GrContext* ctx = fTexture->getContext(); | 556 GrContext* ctx = fTexture->getContext(); |
555 GrSurfaceDesc desc = fTexture->desc(); | 557 GrSurfaceDesc desc = fTexture->desc(); |
556 desc.fWidth = subset.width(); | 558 desc.fWidth = subset.width(); |
557 desc.fHeight = subset.height(); | 559 desc.fHeight = subset.height(); |
558 | 560 |
559 sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, SkBud
geted::kYes)); | 561 sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, SkBud
geted::kYes)); |
560 if (!subTx) { | 562 if (!subTx) { |
561 return nullptr; | 563 return nullptr; |
562 } | 564 } |
563 ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0,
0)); | 565 ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0,
0)); |
| 566 // TODO: Supply correct color space after we're storing it here |
564 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageU
niqueID, | 567 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageU
niqueID, |
565 fAlphaType, subTx.get(), SkBudgeted::kYes
); | 568 fAlphaType, subTx.get(), nullptr, SkBudge
ted::kYes); |
566 } | 569 } |
567 | 570 |
568 sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override
{ | 571 sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override
{ |
569 return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::k
Yes, info); | 572 return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::k
Yes, info); |
570 } | 573 } |
571 | 574 |
572 private: | 575 private: |
573 sk_sp<GrTexture> fTexture; | 576 sk_sp<GrTexture> fTexture; |
574 const SkAlphaType fAlphaType; | 577 const SkAlphaType fAlphaType; |
575 mutable SkAtomic<bool> fAddedRasterVersionToCache; | 578 mutable SkAtomic<bool> fAddedRasterVersionToCache; |
576 | 579 |
577 typedef SkSpecialImage_Base INHERITED; | 580 typedef SkSpecialImage_Base INHERITED; |
578 }; | 581 }; |
579 | 582 |
580 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, | 583 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, |
581 uint32_t uniqueID, | 584 uint32_t uniqueID, |
582 sk_sp<GrTexture> tex, | 585 sk_sp<GrTexture> tex, |
583 const SkSurfaceProps* props, | 586 const SkSurfaceProps* props, |
584 SkAlphaType at) { | 587 SkAlphaType at) { |
585 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 588 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
586 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
props); | 589 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
props); |
587 } | 590 } |
588 | 591 |
589 #endif | 592 #endif |
OLD | NEW |