Switch SkSpecialImage & SkSpecialSurface classes over to smart pointers
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1812023002
Review URL: https://codereview.chromium.org/1812023002
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index d60e0e9..3acb913 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1407,12 +1407,13 @@
SkAutoTUnref<SkImageFilter::Cache> cache(dstDev->getImageFilterCache());
SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
- SkAutoTUnref<SkSpecialImage> srcImg(SkSpecialImage::internal_fromBM(&proxy, srcBM));
+ sk_sp<SkSpecialImage> srcImg(SkSpecialImage::internal_fromBM(&proxy, srcBM));
if (!srcImg) {
continue; // something disastrous happened
}
- SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset));
+ SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx,
+ &offset));
if (resultImg) {
SkPaint tmpUnfiltered(*paint);
tmpUnfiltered.setImageFilter(nullptr);
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index aff1551..90be52b 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -416,12 +416,12 @@
SkAutoTUnref<SkImageFilter::Cache> cache(this->getImageFilterCache());
SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
- SkAutoTUnref<SkSpecialImage> srcImg(SkSpecialImage::internal_fromBM(&proxy, bitmap));
+ sk_sp<SkSpecialImage> srcImg(SkSpecialImage::internal_fromBM(&proxy, bitmap));
if (!srcImg) {
return; // something disastrous happened
}
- SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset));
+ SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset));
if (resultImg) {
SkPaint tmpUnfiltered(paint);
tmpUnfiltered.setImageFilter(nullptr);
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 85f4e46..1a4c876 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -275,12 +275,12 @@
return true;
}
- SkAutoTUnref<SkSpecialImage> specialSrc(SkSpecialImage::internal_fromBM(proxy, src));
+ sk_sp<SkSpecialImage> specialSrc(SkSpecialImage::internal_fromBM(proxy, src));
if (!specialSrc) {
return false;
}
- SkAutoTUnref<SkSpecialImage> tmp(input->onFilterImage(specialSrc,
+ SkAutoTUnref<SkSpecialImage> tmp(input->onFilterImage(specialSrc.get(),
this->mapContext(ctx),
offset));
if (!tmp) {
@@ -367,7 +367,7 @@
return nullptr;
}
- return SkSpecialImage::internal_fromBM(src->internal_getProxy(), resultBM);
+ return SkSpecialImage::internal_fromBM(src->internal_getProxy(), resultBM).release();
}
bool SkImageFilter::canFilterImageGPU() const {
@@ -484,11 +484,11 @@
// Return a larger (newWidth x newHeight) copy of 'src' with black padding
// around it.
-static SkSpecialImage* pad_image(SkSpecialImage* src,
- int newWidth, int newHeight, int offX, int offY) {
+static sk_sp<SkSpecialImage> pad_image(SkSpecialImage* src,
+ int newWidth, int newHeight, int offX, int offY) {
SkImageInfo info = SkImageInfo::MakeN32Premul(newWidth, newHeight);
- SkAutoTUnref<SkSpecialSurface> surf(src->newSurface(info));
+ sk_sp<SkSpecialSurface> surf(src->makeSurface(info));
if (!surf) {
return nullptr;
}
@@ -500,7 +500,7 @@
src->draw(canvas, offX, offY, nullptr);
- return surf->newImageSnapshot();
+ return surf->makeImageSnapshot();
}
SkSpecialImage* SkImageFilter::applyCropRect(const Context& ctx,
@@ -520,12 +520,12 @@
if (srcBounds.contains(*bounds)) {
return SkRef(src);
} else {
- SkSpecialImage* img = pad_image(src,
- bounds->width(), bounds->height(),
- srcOffset->x() - bounds->x(),
- srcOffset->y() - bounds->y());
+ sk_sp<SkSpecialImage> img(pad_image(src,
+ bounds->width(), bounds->height(),
+ srcOffset->x() - bounds->x(),
+ srcOffset->y() - bounds->y()));
*srcOffset = SkIPoint::Make(bounds->x(), bounds->y());
- return img;
+ return img.release();
}
}
@@ -609,12 +609,12 @@
return true;
}
- SkAutoTUnref<SkSpecialImage> specialSrc(SkSpecialImage::internal_fromBM(proxy, src));
+ sk_sp<SkSpecialImage> specialSrc(SkSpecialImage::internal_fromBM(proxy, src));
if (!specialSrc) {
return false;
}
- SkAutoTUnref<SkSpecialImage> tmp(input->onFilterImage(specialSrc,
+ SkAutoTUnref<SkSpecialImage> tmp(input->onFilterImage(specialSrc.get(),
this->mapContext(ctx),
offset));
if (!tmp) {
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index b17d5d4..e90c655 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -29,9 +29,9 @@
// Delete this entry point ASAP (see skbug.com/4965)
virtual bool getBitmapDeprecated(SkBitmap* result) const = 0;
- virtual SkSpecialSurface* onNewSurface(const SkImageInfo& info) const = 0;
+ virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const = 0;
- virtual SkSpecialImage* onExtractSubset(const SkIRect& subset) const = 0;
+ virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0;
private:
typedef SkSpecialImage INHERITED;
@@ -58,12 +58,12 @@
return as_SIB(this)->testingOnlyOnGetROPixels(result);
}
-SkSpecialSurface* SkSpecialImage::newSurface(const SkImageInfo& info) const {
- return as_SIB(this)->onNewSurface(info);
+sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) const {
+ return as_SIB(this)->onMakeSurface(info);
}
-SkSpecialImage* SkSpecialImage::extractSubset(const SkIRect& subset) const {
- return as_SIB(this)->onExtractSubset(subset);
+sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const {
+ return as_SIB(this)->onMakeSubset(subset);
}
#if SK_SUPPORT_GPU
@@ -71,17 +71,17 @@
#include "SkGrPixelRef.h"
#endif
-SkSpecialImage* SkSpecialImage::internal_fromBM(SkImageFilter::Proxy* proxy,
- const SkBitmap& src) {
+sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(SkImageFilter::Proxy* proxy,
+ const SkBitmap& src) {
// Need to test offset case! (see skbug.com/4967)
if (src.getTexture()) {
- return SkSpecialImage::NewFromGpu(proxy,
- src.bounds(),
- src.getGenerationID(),
- src.getTexture());
+ return SkSpecialImage::MakeFromGpu(proxy,
+ src.bounds(),
+ src.getGenerationID(),
+ src.getTexture());
}
- return SkSpecialImage::NewFromRaster(proxy, src.bounds(), src);
+ return SkSpecialImage::MakeFromRaster(proxy, src.bounds(), src);
}
bool SkSpecialImage::internal_getBM(SkBitmap* result) {
@@ -103,13 +103,15 @@
class SkSpecialImage_Image : public SkSpecialImage_Base {
public:
- SkSpecialImage_Image(SkImageFilter::Proxy* proxy, const SkIRect& subset, const SkImage* image)
+ SkSpecialImage_Image(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset,
+ sk_sp<SkImage> image)
: INHERITED(proxy, subset, image->uniqueID())
- , fImage(SkRef(image)) {
+ , fImage(image) {
}
~SkSpecialImage_Image() override { }
-
+
bool isOpaque() const override { return fImage->isOpaque(); }
size_t getSize() const override {
@@ -130,7 +132,7 @@
void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset().height());
- canvas->drawImageRect(fImage, this->subset(),
+ canvas->drawImageRect(fImage.get(), this->subset(),
dst, paint, SkCanvas::kStrict_SrcRectConstraint);
}
@@ -162,32 +164,32 @@
return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode);
}
- SkSpecialSurface* onNewSurface(const SkImageInfo& info) const override {
+ sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
#if SK_SUPPORT_GPU
GrTexture* texture = as_IB(fImage.get())->peekTexture();
if (texture) {
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info);
desc.fFlags = kRenderTarget_GrSurfaceFlag;
- return SkSpecialSurface::NewRenderTarget(this->proxy(), texture->getContext(), desc);
+ return SkSpecialSurface::MakeRenderTarget(this->proxy(), texture->getContext(), desc);
}
#endif
- return SkSpecialSurface::NewRaster(this->proxy(), info, nullptr);
+ return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr);
}
- SkSpecialImage* onExtractSubset(const SkIRect& subset) const override {
- SkAutoTUnref<SkImage> subsetImg(fImage->newSubset(subset));
+ sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override {
+ sk_sp<SkImage> subsetImg(fImage->makeSubset(subset));
if (!subsetImg) {
return nullptr;
}
- return SkSpecialImage::NewFromImage(this->internal_getProxy(),
- SkIRect::MakeWH(subset.width(), subset.height()),
- subsetImg);
+ return SkSpecialImage::MakeFromImage(this->internal_getProxy(),
+ SkIRect::MakeWH(subset.width(), subset.height()),
+ subsetImg);
}
private:
- SkAutoTUnref<const SkImage> fImage;
+ sk_sp<SkImage> fImage;
typedef SkSpecialImage_Base INHERITED;
};
@@ -206,11 +208,12 @@
}
#endif
-SkSpecialImage* SkSpecialImage::NewFromImage(SkImageFilter::Proxy* proxy,
- const SkIRect& subset,
- const SkImage* image) {
+sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset,
+ sk_sp<SkImage> image) {
SkASSERT(rect_fits(subset, image->width(), image->height()));
- return new SkSpecialImage_Image(proxy, subset, image);
+
+ return sk_make_sp<SkSpecialImage_Image>(proxy, subset, image);
}
///////////////////////////////////////////////////////////////////////////////
@@ -233,8 +236,8 @@
SkSpecialImage_Raster(SkImageFilter::Proxy* proxy,
const SkIRect& subset,
const SkPixmap& pixmap,
- void (*releaseProc)(void* addr, void* context),
- void* context)
+ RasterReleaseProc releaseProc,
+ ReleaseContext context)
: INHERITED(proxy, subset, kNeedNewImageUniqueID_SpecialImage) {
fBitmap.installPixels(pixmap.info(), pixmap.writable_addr(),
pixmap.rowBytes(), pixmap.ctable(),
@@ -274,20 +277,20 @@
return true;
}
- SkSpecialSurface* onNewSurface(const SkImageInfo& info) const override {
- return SkSpecialSurface::NewRaster(this->proxy(), info, nullptr);
+ sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
+ return SkSpecialSurface::MakeRaster(this->proxy(), info, nullptr);
}
- SkSpecialImage* onExtractSubset(const SkIRect& subset) const override {
+ sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override {
SkBitmap subsetBM;
if (!fBitmap.extractSubset(&subsetBM, subset)) {
return nullptr;
}
- return SkSpecialImage::NewFromRaster(this->internal_getProxy(),
- SkIRect::MakeWH(subset.width(), subset.height()),
- subsetBM);
+ return SkSpecialImage::MakeFromRaster(this->internal_getProxy(),
+ SkIRect::MakeWH(subset.width(), subset.height()),
+ subsetBM);
}
private:
@@ -296,20 +299,25 @@
typedef SkSpecialImage_Base INHERITED;
};
-SkSpecialImage* SkSpecialImage::NewFromRaster(SkImageFilter::Proxy* proxy,
- const SkIRect& subset,
- const SkBitmap& bm) {
+sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset,
+ const SkBitmap& bm) {
SkASSERT(nullptr == bm.getTexture());
SkASSERT(rect_fits(subset, bm.width(), bm.height()));
- return new SkSpecialImage_Raster(proxy, subset, bm);
+
+ return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, bm);
}
-SkSpecialImage* SkSpecialImage::NewFromPixmap(SkImageFilter::Proxy* proxy,
- const SkIRect& subset,
- const SkPixmap& src,
- void (*releaseProc)(void* addr, void* context),
- void* context) {
- return new SkSpecialImage_Raster(proxy, subset, src, releaseProc, context);
+sk_sp<SkSpecialImage> SkSpecialImage::MakeFromPixmap(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset,
+ const SkPixmap& src,
+ RasterReleaseProc releaseProc,
+ ReleaseContext context) {
+ if (!src.addr()) {
+ return nullptr;
+ }
+
+ return sk_make_sp<SkSpecialImage_Raster>(proxy, subset, src, releaseProc, context);
}
@@ -383,19 +391,19 @@
return true;
}
- SkSpecialSurface* onNewSurface(const SkImageInfo& info) const override {
+ sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info);
desc.fFlags = kRenderTarget_GrSurfaceFlag;
- return SkSpecialSurface::NewRenderTarget(this->proxy(), fTexture->getContext(), desc);
+ return SkSpecialSurface::MakeRenderTarget(this->proxy(), fTexture->getContext(), desc);
}
- SkSpecialImage* onExtractSubset(const SkIRect& subset) const override {
- return SkSpecialImage::NewFromGpu(this->internal_getProxy(),
- subset,
- this->uniqueID(),
- fTexture,
- fAlphaType);
+ sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override {
+ return SkSpecialImage::MakeFromGpu(this->internal_getProxy(),
+ subset,
+ this->uniqueID(),
+ fTexture,
+ fAlphaType);
}
private:
@@ -405,22 +413,22 @@
typedef SkSpecialImage_Base INHERITED;
};
-SkSpecialImage* SkSpecialImage::NewFromGpu(SkImageFilter::Proxy* proxy,
- const SkIRect& subset,
- uint32_t uniqueID,
- GrTexture* tex,
- SkAlphaType at) {
+sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset,
+ uint32_t uniqueID,
+ GrTexture* tex,
+ SkAlphaType at) {
SkASSERT(rect_fits(subset, tex->width(), tex->height()));
- return new SkSpecialImage_Gpu(proxy, subset, uniqueID, tex, at);
+ return sk_make_sp<SkSpecialImage_Gpu>(proxy, subset, uniqueID, tex, at);
}
#else
-SkSpecialImage* SkSpecialImage::NewFromGpu(SkImageFilter::Proxy* proxy,
- const SkIRect& subset,
- uint32_t uniqueID,
- GrTexture* tex,
- SkAlphaType at) {
+sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset,
+ uint32_t uniqueID,
+ GrTexture* tex,
+ SkAlphaType at) {
return nullptr;
}
diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h
index b1b6a28..1a01a5a 100644
--- a/src/core/SkSpecialImage.h
+++ b/src/core/SkSpecialImage.h
@@ -39,6 +39,9 @@
*/
class SkSpecialImage : public SkRefCnt {
public:
+ typedef void* ReleaseContext;
+ typedef void(*RasterReleaseProc)(void* pixels, ReleaseContext);
+
int width() const { return fSubset.width(); }
int height() const { return fSubset.height(); }
const SkIRect& subset() const { return fSubset; }
@@ -52,37 +55,37 @@
*/
void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const;
- static SkSpecialImage* NewFromImage(SkImageFilter::Proxy*,
- const SkIRect& subset,
- const SkImage*);
- static SkSpecialImage* NewFromRaster(SkImageFilter::Proxy*,
- const SkIRect& subset,
- const SkBitmap&);
- static SkSpecialImage* NewFromGpu(SkImageFilter::Proxy*,
- const SkIRect& subset,
- uint32_t uniqueID,
- GrTexture*,
- SkAlphaType at = kPremul_SkAlphaType);
- static SkSpecialImage* NewFromPixmap(SkImageFilter::Proxy*,
- const SkIRect& subset,
- const SkPixmap&,
- void (*releaseProc)(void* addr, void* context),
- void* context);
+ static sk_sp<SkSpecialImage> MakeFromImage(SkImageFilter::Proxy*,
+ const SkIRect& subset,
+ sk_sp<SkImage>);
+ static sk_sp<SkSpecialImage> MakeFromRaster(SkImageFilter::Proxy*,
+ const SkIRect& subset,
+ const SkBitmap&);
+ static sk_sp<SkSpecialImage> MakeFromGpu(SkImageFilter::Proxy*,
+ const SkIRect& subset,
+ uint32_t uniqueID,
+ GrTexture*,
+ SkAlphaType at = kPremul_SkAlphaType);
+ static sk_sp<SkSpecialImage> MakeFromPixmap(SkImageFilter::Proxy*,
+ const SkIRect& subset,
+ const SkPixmap&,
+ RasterReleaseProc,
+ ReleaseContext);
/**
* Create a new surface with a backend that is compatible with this image.
*/
- SkSpecialSurface* newSurface(const SkImageInfo&) const;
+ sk_sp<SkSpecialSurface> makeSurface(const SkImageInfo&) const;
/**
* Extract a subset of this special image and return it as a special image.
* It may or may not point to the same backing memory.
*/
- SkSpecialImage* extractSubset(const SkIRect& subset) const;
+ sk_sp<SkSpecialImage> makeSubset(const SkIRect& subset) const;
// These three internal methods will go away (see skbug.com/4965)
bool internal_getBM(SkBitmap* result);
- static SkSpecialImage* internal_fromBM(SkImageFilter::Proxy*, const SkBitmap&);
+ static sk_sp<SkSpecialImage> internal_fromBM(SkImageFilter::Proxy*, const SkBitmap&);
SkImageFilter::Proxy* internal_getProxy() const;
// TODO: hide this when GrLayerHoister uses SkSpecialImages more fully (see skbug.com/5063)
diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp
index 429badd..c1b06dd 100644
--- a/src/core/SkSpecialSurface.cpp
+++ b/src/core/SkSpecialSurface.cpp
@@ -27,7 +27,7 @@
// This can return nullptr if reset has already been called or something when wrong in the ctor
SkCanvas* onGetCanvas() { return fCanvas; }
- virtual SkSpecialImage* onNewImageSnapshot() = 0;
+ virtual sk_sp<SkSpecialImage> onMakeImageSnapshot() = 0;
protected:
SkAutoTUnref<SkCanvas> fCanvas; // initialized by derived classes in ctors
@@ -55,8 +55,8 @@
return as_SB(this)->onGetCanvas();
}
-SkSpecialImage* SkSpecialSurface::newImageSnapshot() {
- SkSpecialImage* image = as_SB(this)->onNewImageSnapshot();
+sk_sp<SkSpecialImage> SkSpecialSurface::makeImageSnapshot() {
+ sk_sp<SkSpecialImage> image(as_SB(this)->onMakeImageSnapshot());
as_SB(this)->reset();
return image; // the caller gets the creation ref
}
@@ -81,8 +81,8 @@
~SkSpecialSurface_Raster() override { }
- SkSpecialImage* onNewImageSnapshot() override {
- return SkSpecialImage::NewFromRaster(this->proxy(), this->subset(), fBitmap);
+ sk_sp<SkSpecialImage> onMakeImageSnapshot() override {
+ return SkSpecialImage::MakeFromRaster(this->proxy(), this->subset(), fBitmap);
}
private:
@@ -91,15 +91,15 @@
typedef SkSpecialSurface_Base INHERITED;
};
-SkSpecialSurface* SkSpecialSurface::NewFromBitmap(SkImageFilter::Proxy* proxy,
- const SkIRect& subset, SkBitmap& bm,
- const SkSurfaceProps* props) {
- return new SkSpecialSurface_Raster(proxy, bm.pixelRef(), subset, props);
+sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromBitmap(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset, SkBitmap& bm,
+ const SkSurfaceProps* props) {
+ return sk_make_sp<SkSpecialSurface_Raster>(proxy, bm.pixelRef(), subset, props);
}
-SkSpecialSurface* SkSpecialSurface::NewRaster(SkImageFilter::Proxy* proxy,
- const SkImageInfo& info,
- const SkSurfaceProps* props) {
+sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(SkImageFilter::Proxy* proxy,
+ const SkImageInfo& info,
+ const SkSurfaceProps* props) {
SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, 0, nullptr));
if (nullptr == pr.get()) {
return nullptr;
@@ -107,7 +107,7 @@
const SkIRect subset = SkIRect::MakeWH(pr->info().width(), pr->info().height());
- return new SkSpecialSurface_Raster(proxy, pr, subset, props);
+ return sk_make_sp<SkSpecialSurface_Raster>(proxy, pr, subset, props);
}
#if SK_SUPPORT_GPU
@@ -137,9 +137,9 @@
~SkSpecialSurface_Gpu() override { }
- SkSpecialImage* onNewImageSnapshot() override {
- return SkSpecialImage::NewFromGpu(this->proxy(), this->subset(),
- kNeedNewImageUniqueID_SpecialImage, fTexture);
+ sk_sp<SkSpecialImage> onMakeImageSnapshot() override {
+ return SkSpecialImage::MakeFromGpu(this->proxy(), this->subset(),
+ kNeedNewImageUniqueID_SpecialImage, fTexture);
}
private:
@@ -148,21 +148,21 @@
typedef SkSpecialSurface_Base INHERITED;
};
-SkSpecialSurface* SkSpecialSurface::NewFromTexture(SkImageFilter::Proxy* proxy,
- const SkIRect& subset,
- GrTexture* texture,
- const SkSurfaceProps* props) {
+sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset,
+ GrTexture* texture,
+ const SkSurfaceProps* props) {
if (!texture->asRenderTarget()) {
return nullptr;
}
- return new SkSpecialSurface_Gpu(proxy, texture, subset, props);
+ return sk_make_sp<SkSpecialSurface_Gpu>(proxy, texture, subset, props);
}
-SkSpecialSurface* SkSpecialSurface::NewRenderTarget(SkImageFilter::Proxy* proxy,
- GrContext* context,
- const GrSurfaceDesc& desc,
- const SkSurfaceProps* props) {
+sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(SkImageFilter::Proxy* proxy,
+ GrContext* context,
+ const GrSurfaceDesc& desc,
+ const SkSurfaceProps* props) {
if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
return nullptr;
}
@@ -174,22 +174,22 @@
const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
- return new SkSpecialSurface_Gpu(proxy, temp, subset, props);
+ return sk_make_sp<SkSpecialSurface_Gpu>(proxy, temp, subset, props);
}
#else
-SkSpecialSurface* SkSpecialSurface::NewFromTexture(SkImageFilter::Proxy* proxy,
- const SkIRect& subset,
- GrTexture*,
- const SkSurfaceProps*) {
+sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset,
+ GrTexture*,
+ const SkSurfaceProps*) {
return nullptr;
}
-SkSpecialSurface* SkSpecialSurface::NewRenderTarget(SkImageFilter::Proxy* proxy,
- GrContext* context,
- const GrSurfaceDesc& desc,
- const SkSurfaceProps* props) {
+sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(SkImageFilter::Proxy* proxy,
+ GrContext* context,
+ const GrSurfaceDesc& desc,
+ const SkSurfaceProps* props) {
return nullptr;
}
diff --git a/src/core/SkSpecialSurface.h b/src/core/SkSpecialSurface.h
index 546ec0c..098baa4 100644
--- a/src/core/SkSpecialSurface.h
+++ b/src/core/SkSpecialSurface.h
@@ -48,29 +48,29 @@
*
* Note: the caller inherits a ref from this call that must be balanced
*/
- SkSpecialImage* newImageSnapshot();
+ sk_sp<SkSpecialImage> makeImageSnapshot();
/**
* Use an existing (renderTarget-capable) GrTexture as the backing store.
*/
- static SkSpecialSurface* NewFromTexture(SkImageFilter::Proxy* proxy,
- const SkIRect& subset, GrTexture*,
- const SkSurfaceProps* = nullptr);
+ static sk_sp<SkSpecialSurface> MakeFromTexture(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset, GrTexture*,
+ const SkSurfaceProps* = nullptr);
/**
* Allocate a new GPU-backed SkSpecialSurface. If the requested surface cannot
* be created, nullptr will be returned.
*/
- static SkSpecialSurface* NewRenderTarget(SkImageFilter::Proxy* proxy,
- GrContext*, const GrSurfaceDesc&,
- const SkSurfaceProps* = nullptr);
+ static sk_sp<SkSpecialSurface> MakeRenderTarget(SkImageFilter::Proxy* proxy,
+ GrContext*, const GrSurfaceDesc&,
+ const SkSurfaceProps* = nullptr);
/**
* Use and existing SkBitmap as the backing store.
*/
- static SkSpecialSurface* NewFromBitmap(SkImageFilter::Proxy* proxy,
- const SkIRect& subset, SkBitmap& bm,
- const SkSurfaceProps* = nullptr);
+ static sk_sp<SkSpecialSurface> MakeFromBitmap(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset, SkBitmap& bm,
+ const SkSurfaceProps* = nullptr);
/**
* Return a new CPU-backed surface, with the memory for the pixels automatically
@@ -79,8 +79,9 @@
* If the requested surface cannot be created, or the request is not a
* supported configuration, nullptr will be returned.
*/
- static SkSpecialSurface* NewRaster(SkImageFilter::Proxy* proxy,
- const SkImageInfo&, const SkSurfaceProps* = nullptr);
+ static sk_sp<SkSpecialSurface> MakeRaster(SkImageFilter::Proxy* proxy,
+ const SkImageInfo&,
+ const SkSurfaceProps* = nullptr);
protected:
SkSpecialSurface(SkImageFilter::Proxy*, const SkIRect& subset, const SkSurfaceProps*);
diff --git a/src/effects/SkImageSource.cpp b/src/effects/SkImageSource.cpp
index 25d37e3..c0a8dee 100644
--- a/src/effects/SkImageSource.cpp
+++ b/src/effects/SkImageSource.cpp
@@ -15,25 +15,25 @@
#include "SkWriteBuffer.h"
#include "SkString.h"
-SkImageFilter* SkImageSource::Create(const SkImage* image) {
+SkImageFilter* SkImageSource::Create(SkImage* image) {
return image ? new SkImageSource(image) : nullptr;
}
-SkImageFilter* SkImageSource::Create(const SkImage* image,
+SkImageFilter* SkImageSource::Create(SkImage* image,
const SkRect& srcRect,
const SkRect& dstRect,
SkFilterQuality filterQuality) {
return image ? new SkImageSource(image, srcRect, dstRect, filterQuality) : nullptr;
}
-SkImageSource::SkImageSource(const SkImage* image)
+SkImageSource::SkImageSource(SkImage* image)
: INHERITED(0, nullptr)
, fImage(SkRef(image))
, fSrcRect(SkRect::MakeIWH(image->width(), image->height()))
, fDstRect(fSrcRect)
, fFilterQuality(kHigh_SkFilterQuality) { }
-SkImageSource::SkImageSource(const SkImage* image,
+SkImageSource::SkImageSource(SkImage* image,
const SkRect& srcRect,
const SkRect& dstRect,
SkFilterQuality filterQuality)
@@ -62,7 +62,7 @@
buffer.writeInt(fFilterQuality);
buffer.writeRect(fSrcRect);
buffer.writeRect(fDstRect);
- buffer.writeImage(fImage);
+ buffer.writeImage(fImage.get());
}
SkSpecialImage* SkImageSource::onFilterImage(SkSpecialImage* source, const Context& ctx,
@@ -74,9 +74,9 @@
if (fSrcRect == bounds && dstRect == bounds) {
// No regions cropped out or resized; return entire image.
offset->fX = offset->fY = 0;
- return SkSpecialImage::NewFromImage(source->internal_getProxy(),
- SkIRect::MakeWH(fImage->width(), fImage->height()),
- fImage);
+ return SkSpecialImage::MakeFromImage(source->internal_getProxy(),
+ SkIRect::MakeWH(fImage->width(), fImage->height()),
+ fImage).release();
}
const SkIRect dstIRect = dstRect.roundOut();
@@ -84,7 +84,7 @@
const SkImageInfo info = SkImageInfo::MakeN32(dstIRect.width(), dstIRect.height(),
kPremul_SkAlphaType);
- SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
if (!surf) {
return nullptr;
}
@@ -105,11 +105,12 @@
paint.setFilterQuality(
fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height() ?
kNone_SkFilterQuality : fFilterQuality);
- canvas->drawImageRect(fImage, fSrcRect, dstRect, &paint, SkCanvas::kStrict_SrcRectConstraint);
+ canvas->drawImageRect(fImage.get(), fSrcRect, dstRect, &paint,
+ SkCanvas::kStrict_SrcRectConstraint);
offset->fX = dstIRect.fLeft;
offset->fY = dstIRect.fTop;
- return surf->newImageSnapshot();
+ return surf->makeImageSnapshot().release();
}
void SkImageSource::computeFastBounds(const SkRect& src, SkRect* dst) const {
diff --git a/src/effects/SkMergeImageFilter.cpp b/src/effects/SkMergeImageFilter.cpp
index e6761e9..01373b2 100755
--- a/src/effects/SkMergeImageFilter.cpp
+++ b/src/effects/SkMergeImageFilter.cpp
@@ -98,7 +98,7 @@
SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
kPremul_SkAlphaType);
- SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
if (!surf) {
return nullptr;
}
@@ -126,7 +126,7 @@
offset->fX = bounds.left();
offset->fY = bounds.top();
- return surf->newImageSnapshot();
+ return surf->makeImageSnapshot().release();
}
SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) {
diff --git a/src/effects/SkOffsetImageFilter.cpp b/src/effects/SkOffsetImageFilter.cpp
index 77cf442..f3d2bb0 100644
--- a/src/effects/SkOffsetImageFilter.cpp
+++ b/src/effects/SkOffsetImageFilter.cpp
@@ -41,7 +41,7 @@
SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
kPremul_SkAlphaType);
- SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
if (!surf) {
return nullptr;
}
@@ -61,7 +61,7 @@
offset->fX = bounds.fLeft;
offset->fY = bounds.fTop;
- return surf->newImageSnapshot();
+ return surf->makeImageSnapshot().release();
}
}
diff --git a/src/effects/SkPaintImageFilter.cpp b/src/effects/SkPaintImageFilter.cpp
index 6ae62d9..02387ce 100644
--- a/src/effects/SkPaintImageFilter.cpp
+++ b/src/effects/SkPaintImageFilter.cpp
@@ -45,7 +45,7 @@
SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
kPremul_SkAlphaType);
- SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
if (!surf) {
return nullptr;
}
@@ -67,7 +67,7 @@
offset->fX = bounds.fLeft;
offset->fY = bounds.fTop;
- return surf->newImageSnapshot();
+ return surf->makeImageSnapshot().release();
}
bool SkPaintImageFilter::canComputeFastBounds() const {
diff --git a/src/gpu/GrLayerHoister.cpp b/src/gpu/GrLayerHoister.cpp
index a446be8..0fef0ef 100644
--- a/src/gpu/GrLayerHoister.cpp
+++ b/src/gpu/GrLayerHoister.cpp
@@ -304,12 +304,12 @@
// TODO: should the layer hoister store stand alone layers as SkSpecialImages internally?
const SkIRect subset = SkIRect::MakeWH(layer->texture()->width(), layer->texture()->height());
- SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromGpu(&proxy, subset,
- kNeedNewImageUniqueID_SpecialImage,
- layer->texture()));
+ sk_sp<SkSpecialImage> img(SkSpecialImage::MakeFromGpu(&proxy, subset,
+ kNeedNewImageUniqueID_SpecialImage,
+ layer->texture()));
SkIPoint offset = SkIPoint::Make(0, 0);
- SkAutoTUnref<SkSpecialImage> result(layer->filter()->filterImage(img,
+ SkAutoTUnref<SkSpecialImage> result(layer->filter()->filterImage(img.get(),
filterContext,
&offset));
if (!result) {