diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkImageFilter.cpp | 3 | ||||
-rw-r--r-- | src/core/SkSpecialImage.cpp | 74 | ||||
-rw-r--r-- | src/core/SkSpecialImage.h | 8 | ||||
-rw-r--r-- | src/core/SkSpecialSurface.cpp | 32 | ||||
-rw-r--r-- | src/core/SkSpecialSurface.h | 4 |
5 files changed, 55 insertions, 66 deletions
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index ab1758844c..fdd78f8f73 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -313,8 +313,7 @@ sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context, return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()), kNeedNewImageUniqueID_SpecialImage, - dst.get()); - + std::move(dst)); } #endif diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index bbc7635b66..f18e6a7c7c 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -32,7 +32,9 @@ public: virtual GrTexture* onPeekTexture() const { return nullptr; } - virtual GrTexture* onAsTextureRef(GrContext* context) const = 0; +#if SK_SUPPORT_GPU + virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0; +#endif // Delete this entry point ASAP (see skbug.com/4965) virtual bool getBitmapDeprecated(SkBitmap* result) const = 0; @@ -80,8 +82,9 @@ sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(GrContext* context) { return SkSpecialImage::MakeFromRaster(SkIRect::MakeEmpty(), bmp, &this->props()); } - SkAutoTUnref<GrTexture> resultTex( - GrRefCachedBitmapTexture(context, bmp, GrTextureParams::ClampNoFilter())); + sk_sp<GrTexture> resultTex(GrRefCachedBitmapTexture(context, + bmp, + GrTextureParams::ClampNoFilter())); if (!resultTex) { return nullptr; } @@ -123,10 +126,11 @@ GrContext* SkSpecialImage::getContext() const { return nullptr; } - -GrTexture* SkSpecialImage::asTextureRef(GrContext* context) const { +#if SK_SUPPORT_GPU +sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const { return as_SIB(this)->onAsTextureRef(context); } +#endif sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) const { return as_SIB(this)->onMakeSurface(info); @@ -151,13 +155,15 @@ sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const { sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(const SkBitmap& src, const SkSurfaceProps* props) { +#if SK_SUPPORT_GPU // Need to test offset case! (see skbug.com/4967) if (src.getTexture()) { return SkSpecialImage::MakeFromGpu(src.bounds(), src.getGenerationID(), - src.getTexture(), + sk_ref_sp(src.getTexture()), props); } +#endif return SkSpecialImage::MakeFromRaster(src.bounds(), src, props); } @@ -217,13 +223,12 @@ public: GrTexture* onPeekTexture() const override { return as_IB(fImage)->peekTexture(); } - GrTexture* onAsTextureRef(GrContext* context) const override { #if SK_SUPPORT_GPU - return as_IB(fImage)->asTextureRef(context, GrTextureParams::ClampNoFilter()); -#else - return nullptr; -#endif + sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override { + return sk_sp<GrTexture>(as_IB(fImage)->asTextureRef(context, + GrTextureParams::ClampNoFilter())); } +#endif bool getBitmapDeprecated(SkBitmap* result) const override { #if SK_SUPPORT_GPU @@ -356,15 +361,17 @@ public: return true; } - GrTexture* onAsTextureRef(GrContext* context) const override { #if SK_SUPPORT_GPU + sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override { if (context) { - return GrRefCachedBitmapTexture(context, fBitmap, GrTextureParams::ClampNoFilter()); + return sk_ref_sp(GrRefCachedBitmapTexture(context, + fBitmap, + GrTextureParams::ClampNoFilter())); } -#endif return nullptr; } +#endif bool getBitmapDeprecated(SkBitmap* result) const override { *result = fBitmap; @@ -437,10 +444,10 @@ sk_sp<SkSpecialImage> SkSpecialImage::MakeFromPixmap(const SkIRect& subset, class SkSpecialImage_Gpu : public SkSpecialImage_Base { public: SkSpecialImage_Gpu(const SkIRect& subset, - uint32_t uniqueID, GrTexture* tex, SkAlphaType at, + uint32_t uniqueID, sk_sp<GrTexture> tex, SkAlphaType at, const SkSurfaceProps* props) : INHERITED(subset, uniqueID, props) - , fTexture(SkRef(tex)) + , fTexture(std::move(tex)) , fAlphaType(at) , fAddedRasterVersionToCache(false) { } @@ -463,16 +470,16 @@ public: SkBitmap bm; - GrWrapTextureInBitmap(fTexture, + GrWrapTextureInBitmap(fTexture.get(), fTexture->width(), fTexture->height(), this->isOpaque(), &bm); canvas->drawBitmapRect(bm, this->subset(), dst, paint, SkCanvas::kStrict_SrcRectConstraint); } - GrTexture* onPeekTexture() const override { return fTexture; } + GrTexture* onPeekTexture() const override { return fTexture.get(); } - GrTexture* onAsTextureRef(GrContext*) const override { return SkRef(fTexture.get()); } + sk_sp<GrTexture> onAsTextureRef(GrContext*) const override { return fTexture; } bool onGetROPixels(SkBitmap* dst) const override { if (SkBitmapCache::Find(this->uniqueID(), dst)) { @@ -502,7 +509,7 @@ public: } bool getBitmapDeprecated(SkBitmap* result) const override { - const SkImageInfo info = GrMakeInfoFromTexture(fTexture, + const SkImageInfo info = GrMakeInfoFromTexture(fTexture.get(), this->width(), this->height(), this->isOpaque()); if (!result->setInfo(info)) { @@ -511,7 +518,7 @@ public: const SkImageInfo prInfo = info.makeWH(fTexture->width(), fTexture->height()); - SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture)); + SkAutoTUnref<SkGrPixelRef> pixelRef(new SkGrPixelRef(prInfo, fTexture.get())); result->setPixelRef(pixelRef, this->subset().fLeft, this->subset().fTop); return true; } @@ -542,7 +549,7 @@ public: // The existing GrTexture is already tight so reuse it in the SkImage return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height(), kNeedNewImageUniqueID, - fAlphaType, fTexture, SkBudgeted::kYes); + fAlphaType, fTexture.get(), SkBudgeted::kYes); } GrContext* ctx = fTexture->getContext(); @@ -550,14 +557,13 @@ public: desc.fWidth = subset.width(); desc.fHeight = subset.height(); - SkAutoTUnref<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, - SkBudgeted::kYes)); + sk_sp<GrTexture> subTx(ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes)); if (!subTx) { return nullptr; } - ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); + ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0, 0)); return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, - fAlphaType, subTx, SkBudgeted::kYes); + fAlphaType, subTx.get(), SkBudgeted::kYes); } sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override { @@ -565,7 +571,7 @@ public: } private: - SkAutoTUnref<GrTexture> fTexture; + sk_sp<GrTexture> fTexture; const SkAlphaType fAlphaType; mutable SkAtomic<bool> fAddedRasterVersionToCache; @@ -574,21 +580,11 @@ private: sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, uint32_t uniqueID, - GrTexture* tex, + sk_sp<GrTexture> tex, const SkSurfaceProps* props, SkAlphaType at) { SkASSERT(rect_fits(subset, tex->width(), tex->height())); - return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, tex, at, props); -} - -#else - -sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, - uint32_t uniqueID, - GrTexture* tex, - const SkSurfaceProps* props, - SkAlphaType at) { - return nullptr; + return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, props); } #endif diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h index d6497a035e..6771f257e3 100644 --- a/src/core/SkSpecialImage.h +++ b/src/core/SkSpecialImage.h @@ -73,11 +73,13 @@ public: static sk_sp<SkSpecialImage> MakeFromRaster(const SkIRect& subset, const SkBitmap&, const SkSurfaceProps* = nullptr); +#if SK_SUPPORT_GPU static sk_sp<SkSpecialImage> MakeFromGpu(const SkIRect& subset, uint32_t uniqueID, - GrTexture*, + sk_sp<GrTexture>, const SkSurfaceProps* = nullptr, SkAlphaType at = kPremul_SkAlphaType); +#endif static sk_sp<SkSpecialImage> MakeFromPixmap(const SkIRect& subset, const SkPixmap&, RasterReleaseProc, @@ -123,11 +125,13 @@ public: */ GrContext* getContext() const; +#if SK_SUPPORT_GPU /** * Regardless of the underlying backing store, return the contents as a GrTexture. * The active portion of the texture can be retrieved via 'subset'. */ - GrTexture* asTextureRef(GrContext*) const; + sk_sp<GrTexture> asTextureRef(GrContext*) const; +#endif // TODO: hide this whe the imagefilter all have a consistent draw path (see skbug.com/5063) /** diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp index 2e2d8cc54a..2973aa1f9b 100644 --- a/src/core/SkSpecialSurface.cpp +++ b/src/core/SkSpecialSurface.cpp @@ -112,11 +112,11 @@ sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(const SkImageInfo& info, class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { public: - SkSpecialSurface_Gpu(GrTexture* texture, + SkSpecialSurface_Gpu(sk_sp<GrTexture> texture, const SkIRect& subset, const SkSurfaceProps* props) : INHERITED(subset, props) - , fTexture(SkRef(texture)) { + , fTexture(std::move(texture)) { SkASSERT(fTexture->asRenderTarget()); @@ -133,25 +133,27 @@ public: ~SkSpecialSurface_Gpu() override { } sk_sp<SkSpecialImage> onMakeImageSnapshot() override { + // Note: we are intentionally zeroing out 'fTexture' here return SkSpecialImage::MakeFromGpu(this->subset(), - kNeedNewImageUniqueID_SpecialImage, fTexture, + kNeedNewImageUniqueID_SpecialImage, + std::move(fTexture), &this->props()); } private: - SkAutoTUnref<GrTexture> fTexture; + sk_sp<GrTexture> fTexture; typedef SkSpecialSurface_Base INHERITED; }; sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset, - GrTexture* texture, + sk_sp<GrTexture> texture, const SkSurfaceProps* props) { if (!texture->asRenderTarget()) { return nullptr; } - return sk_make_sp<SkSpecialSurface_Gpu>(texture, subset, props); + return sk_make_sp<SkSpecialSurface_Gpu>(std::move(texture), subset, props); } sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context, @@ -161,28 +163,14 @@ sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context, return nullptr; } - SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture(desc)); + sk_sp<GrTexture> temp(context->textureProvider()->createApproxTexture(desc)); if (!temp) { return nullptr; } const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); - return sk_make_sp<SkSpecialSurface_Gpu>(temp, subset, props); -} - -#else - -sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset, - GrTexture*, - const SkSurfaceProps*) { - return nullptr; -} - -sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context, - const GrSurfaceDesc& desc, - const SkSurfaceProps* props) { - return nullptr; + return sk_make_sp<SkSpecialSurface_Gpu>(std::move(temp), subset, props); } #endif diff --git a/src/core/SkSpecialSurface.h b/src/core/SkSpecialSurface.h index 6ed8a77da5..2135347e35 100644 --- a/src/core/SkSpecialSurface.h +++ b/src/core/SkSpecialSurface.h @@ -50,10 +50,11 @@ public: */ sk_sp<SkSpecialImage> makeImageSnapshot(); +#if SK_SUPPORT_GPU /** * Use an existing (renderTarget-capable) GrTexture as the backing store. */ - static sk_sp<SkSpecialSurface> MakeFromTexture(const SkIRect& subset, GrTexture*, + static sk_sp<SkSpecialSurface> MakeFromTexture(const SkIRect& subset, sk_sp<GrTexture>, const SkSurfaceProps* = nullptr); /** @@ -62,6 +63,7 @@ public: */ static sk_sp<SkSpecialSurface> MakeRenderTarget(GrContext*, const GrSurfaceDesc&, const SkSurfaceProps* = nullptr); +#endif /** * Use and existing SkBitmap as the backing store. |