Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Unified Diff: src/core/SkSpecialImage.cpp

Issue 1812023002: Switch SkSpecialImage & SkSpecialSurface classes over to smart pointers (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT (again) Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkSpecialImage.cpp
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index b59bb414056867fa833c985b3fc279e36afa6ab0..76de18147bf01cb44c5ebcbd9e3bcf0add41ad98 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -31,9 +31,9 @@ public:
// 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;
@@ -60,12 +60,12 @@ bool SkSpecialImage::testingOnlyGetROPixels(SkBitmap* result) const {
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
@@ -73,17 +73,17 @@ SkSpecialImage* SkSpecialImage::extractSubset(const SkIRect& subset) const {
#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) {
@@ -105,13 +105,15 @@ SkImageFilter::Proxy* SkSpecialImage::internal_getProxy() const {
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,
+ const sk_sp<const 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 {
@@ -132,7 +134,7 @@ public:
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);
}
@@ -164,32 +166,32 @@ public:
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, *texture->getContext()->caps());
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<const SkImage> fImage;
typedef SkSpecialImage_Base INHERITED;
};
@@ -208,11 +210,12 @@ static bool rect_fits(const SkIRect& rect, int width, int height) {
}
#endif
-SkSpecialImage* SkSpecialImage::NewFromImage(SkImageFilter::Proxy* proxy,
- const SkIRect& subset,
- const SkImage* image) {
+sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(SkImageFilter::Proxy* proxy,
+ const SkIRect& subset,
+ const sk_sp<const 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);
}
///////////////////////////////////////////////////////////////////////////////
@@ -235,8 +238,8 @@ public:
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(),
@@ -276,20 +279,20 @@ public:
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:
@@ -298,20 +301,25 @@ private:
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);
}
@@ -385,19 +393,19 @@ public:
return true;
}
- SkSpecialSurface* onNewSurface(const SkImageInfo& info) const override {
+ sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *fTexture->getContext()->caps());
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:
@@ -407,22 +415,22 @@ private:
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;
}

Powered by Google App Engine
This is Rietveld 408576698