Revert "Revert of add Make variations to return SkImage by sk_sp (patchset #5 id:80001 of https://codereview.chromium.org/1778393002/ )"
Fix was to call get() instead of release() when passing the sp to a bare-ptr method.
This reverts commit e683c56115a210b5993df9294260bb147b408bfa.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1789443002
TBR=
Review URL: https://codereview.chromium.org/1789443002
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index b87e50b..6494fd1 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -134,7 +134,7 @@
return true;
}
-SkImage* SkImage_Gpu::onNewSubset(const SkIRect& subset) const {
+sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const {
GrContext* ctx = fTexture->getContext();
GrSurfaceDesc desc = fTexture->desc();
desc.fWidth = subset.width();
@@ -145,16 +145,16 @@
return nullptr;
}
ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0));
- return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAlphaType, subTx,
- fBudgeted);
+ return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
+ fAlphaType, subTx, fBudgeted);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
-static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc,
- SkAlphaType at, GrWrapOwnership ownership,
- SkImage::TextureReleaseProc releaseProc,
- SkImage::ReleaseContext releaseCtx) {
+static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc,
+ SkAlphaType at, GrWrapOwnership ownership,
+ SkImage::TextureReleaseProc releaseProc,
+ SkImage::ReleaseContext releaseCtx) {
if (desc.fWidth <= 0 || desc.fHeight <= 0) {
return nullptr;
}
@@ -167,21 +167,23 @@
}
const SkBudgeted budgeted = SkBudgeted::kNo;
- return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex, budgeted);
+ return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
+ at, tex, budgeted);
}
-SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at,
- TextureReleaseProc releaseP, ReleaseContext releaseC) {
+sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
+ SkAlphaType at, TextureReleaseProc releaseP,
+ ReleaseContext releaseC) {
return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, releaseP, releaseC);
}
-SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
- SkAlphaType at) {
+sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
+ SkAlphaType at) {
return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nullptr, nullptr);
}
-SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc,
- SkAlphaType at) {
+sk_sp<SkImage> SkImage::MakeFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc,
+ SkAlphaType at) {
if (desc.fWidth <= 0 || desc.fHeight <= 0) {
return nullptr;
}
@@ -197,14 +199,14 @@
return nullptr;
}
- return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst,
- SkBudgeted::kYes);
+ return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst,
+ SkBudgeted::kYes);
}
-SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorSpace,
- const GrBackendObject yuvTextureHandles[3],
- const SkISize yuvSizes[3],
- GrSurfaceOrigin origin) {
+sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorSpace,
+ const GrBackendObject yuvTextureHandles[3],
+ const SkISize yuvSizes[3],
+ GrSurfaceOrigin origin) {
const SkBudgeted budgeted = SkBudgeted::kYes;
if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 ||
@@ -275,25 +277,25 @@
drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect);
ctx->flushSurfaceWrites(dst);
- return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueID,
- kOpaque_SkAlphaType, dst, budgeted);
+ return sk_make_sp<SkImage_Gpu>(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueID,
+ kOpaque_SkAlphaType, dst, budgeted);
}
-static SkImage* create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
+static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::ClampNoFilter()));
if (!texture) {
return nullptr;
}
- return new SkImage_Gpu(texture->width(), texture->height(), id, at, texture,
- SkBudgeted::kNo);
+ return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture,
+ SkBudgeted::kNo);
}
-SkImage* SkImage::newTextureImage(GrContext *context) const {
+sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const {
if (!context) {
return nullptr;
}
if (GrTexture* peek = as_IB(this)->peekTexture()) {
- return peek->getContext() == context ? SkRef(const_cast<SkImage*>(this)) : nullptr;
+ return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(this)) : nullptr;
}
// No way to check whether a image is premul or not?
SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
@@ -310,8 +312,8 @@
return create_image_from_maker(&maker, at, this->uniqueID());
}
-SkImage* SkImage::NewTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap,
- SkBudgeted budgeted) {
+sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap,
+ SkBudgeted budgeted) {
if (!ctx) {
return nullptr;
}
@@ -319,8 +321,8 @@
if (!texture) {
return nullptr;
}
- return new SkImage_Gpu(texture->width(), texture->height(), kNeedNewImageUniqueID,
- pixmap.alphaType(), texture, budgeted);
+ return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNewImageUniqueID,
+ pixmap.alphaType(), texture, budgeted);
}
///////////////////////////////////////////////////////////////////////////////////////////////////