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
This commit is contained in:
parent
fc0b6d1053
commit
37bd7c3aca
@ -47,7 +47,7 @@ protected:
|
||||
SkPaint paint;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get();
|
||||
SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get();
|
||||
SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
|
||||
i * 8,
|
||||
image->width() - i * 8,
|
||||
|
@ -56,7 +56,7 @@ protected:
|
||||
|
||||
int x = 0, y = 0;
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
const SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get();
|
||||
SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get();
|
||||
SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(image->width()/4),
|
||||
SkIntToScalar(image->height()/4),
|
||||
SkIntToScalar(image->width()/(i+1)),
|
||||
|
@ -14,8 +14,8 @@ class SkImage;
|
||||
|
||||
class SK_API SkImageSource : public SkImageFilter {
|
||||
public:
|
||||
static SkImageFilter* Create(const SkImage*);
|
||||
static SkImageFilter* Create(const SkImage*,
|
||||
static SkImageFilter* Create(SkImage*);
|
||||
static SkImageFilter* Create(SkImage*,
|
||||
const SkRect& srcRect,
|
||||
const SkRect& dstRect,
|
||||
SkFilterQuality);
|
||||
@ -32,15 +32,15 @@ protected:
|
||||
SkIPoint* offset) const override;
|
||||
|
||||
private:
|
||||
explicit SkImageSource(const SkImage*);
|
||||
SkImageSource(const SkImage*,
|
||||
explicit SkImageSource(SkImage*);
|
||||
SkImageSource(SkImage*,
|
||||
const SkRect& srcRect,
|
||||
const SkRect& dstRect,
|
||||
SkFilterQuality);
|
||||
|
||||
SkAutoTUnref<const SkImage> fImage;
|
||||
SkRect fSrcRect, fDstRect;
|
||||
SkFilterQuality fFilterQuality;
|
||||
sk_sp<SkImage> fImage;
|
||||
SkRect fSrcRect, fDstRect;
|
||||
SkFilterQuality fFilterQuality;
|
||||
|
||||
typedef SkImageFilter INHERITED;
|
||||
};
|
||||
|
@ -1407,12 +1407,13 @@ void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y,
|
||||
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);
|
||||
|
@ -416,12 +416,12 @@ void SkBaseDevice::drawBitmapAsSprite(const SkDraw& draw, const SkBitmap& bitmap
|
||||
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);
|
||||
|
@ -275,12 +275,12 @@ bool SkImageFilter::filterInputDeprecated(int index, Proxy* proxy, const SkBitma
|
||||
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 @@ SkSpecialImage* SkImageFilter::onFilterImage(SkSpecialImage* src, const Context&
|
||||
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 @@ bool SkImageFilter::applyCropRectDeprecated(const Context& ctx, Proxy* proxy, co
|
||||
|
||||
// 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 @@ static SkSpecialImage* pad_image(SkSpecialImage* src,
|
||||
|
||||
src->draw(canvas, offX, offY, nullptr);
|
||||
|
||||
return surf->newImageSnapshot();
|
||||
return surf->makeImageSnapshot();
|
||||
}
|
||||
|
||||
SkSpecialImage* SkImageFilter::applyCropRect(const Context& ctx,
|
||||
@ -520,12 +520,12 @@ SkSpecialImage* SkImageFilter::applyCropRect(const Context& ctx,
|
||||
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 @@ bool SkImageFilter::filterInputGPUDeprecated(int index, SkImageFilter::Proxy* pr
|
||||
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) {
|
||||
|
@ -29,9 +29,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;
|
||||
@ -58,12 +58,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
|
||||
@ -71,17 +71,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) {
|
||||
@ -103,13 +103,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,
|
||||
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 @@ 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);
|
||||
}
|
||||
|
||||
@ -162,32 +164,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);
|
||||
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 @@ 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,
|
||||
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 @@ 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(),
|
||||
@ -274,20 +277,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:
|
||||
@ -296,20 +299,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);
|
||||
}
|
||||
|
||||
|
||||
@ -383,19 +391,19 @@ public:
|
||||
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 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,9 @@ enum {
|
||||
*/
|
||||
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 @@ public:
|
||||
*/
|
||||
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)
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
// 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 @@ SkCanvas* SkSpecialSurface::getCanvas() {
|
||||
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 @@ public:
|
||||
|
||||
~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 @@ private:
|
||||
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 @@ SkSpecialSurface* SkSpecialSurface::NewRaster(SkImageFilter::Proxy* proxy,
|
||||
|
||||
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 @@ public:
|
||||
|
||||
~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 @@ private:
|
||||
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 @@ SkSpecialSurface* SkSpecialSurface::NewRenderTarget(SkImageFilter::Proxy* proxy,
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -48,29 +48,29 @@ public:
|
||||
*
|
||||
* 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 @@ public:
|
||||
* 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*);
|
||||
|
@ -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 @@ void SkImageSource::flatten(SkWriteBuffer& buffer) const {
|
||||
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 @@ SkSpecialImage* SkImageSource::onFilterImage(SkSpecialImage* source, const Conte
|
||||
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 @@ SkSpecialImage* SkImageSource::onFilterImage(SkSpecialImage* source, const Conte
|
||||
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 @@ SkSpecialImage* SkImageSource::onFilterImage(SkSpecialImage* source, const Conte
|
||||
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 {
|
||||
|
@ -98,7 +98,7 @@ SkSpecialImage* SkMergeImageFilter::onFilterImage(SkSpecialImage* source, const
|
||||
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 @@ SkSpecialImage* SkMergeImageFilter::onFilterImage(SkSpecialImage* source, const
|
||||
|
||||
offset->fX = bounds.left();
|
||||
offset->fY = bounds.top();
|
||||
return surf->newImageSnapshot();
|
||||
return surf->makeImageSnapshot().release();
|
||||
}
|
||||
|
||||
SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
|
@ -41,7 +41,7 @@ SkSpecialImage* SkOffsetImageFilter::onFilterImage(SkSpecialImage* source,
|
||||
|
||||
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 @@ SkSpecialImage* SkOffsetImageFilter::onFilterImage(SkSpecialImage* source,
|
||||
|
||||
offset->fX = bounds.fLeft;
|
||||
offset->fY = bounds.fTop;
|
||||
return surf->newImageSnapshot();
|
||||
return surf->makeImageSnapshot().release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ SkSpecialImage* SkPaintImageFilter::onFilterImage(SkSpecialImage* source,
|
||||
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 @@ SkSpecialImage* SkPaintImageFilter::onFilterImage(SkSpecialImage* source,
|
||||
|
||||
offset->fX = bounds.fLeft;
|
||||
offset->fY = bounds.fTop;
|
||||
return surf->newImageSnapshot();
|
||||
return surf->makeImageSnapshot().release();
|
||||
}
|
||||
|
||||
bool SkPaintImageFilter::canComputeFastBounds() const {
|
||||
|
@ -304,12 +304,12 @@ void GrLayerHoister::FilterLayer(GrContext* context,
|
||||
|
||||
// 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) {
|
||||
|
@ -27,8 +27,8 @@ static SkBitmap create_bm() {
|
||||
|
||||
// Ensure the cache can return a cached image
|
||||
static void test_find_existing(skiatest::Reporter* reporter,
|
||||
SkSpecialImage* image,
|
||||
SkSpecialImage* subset) {
|
||||
const sk_sp<SkSpecialImage>& image,
|
||||
const sk_sp<SkSpecialImage>& subset) {
|
||||
static const size_t kCacheSize = 1000000;
|
||||
SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCacheSize));
|
||||
|
||||
@ -37,7 +37,7 @@ static void test_find_existing(skiatest::Reporter* reporter,
|
||||
SkImageFilter::Cache::Key key2(0, SkMatrix::I(), clip, subset->uniqueID(), subset->subset());
|
||||
|
||||
SkIPoint offset = SkIPoint::Make(3, 4);
|
||||
cache->set(key1, image, offset);
|
||||
cache->set(key1, image.get(), offset);
|
||||
|
||||
SkIPoint foundOffset;
|
||||
|
||||
@ -51,8 +51,8 @@ static void test_find_existing(skiatest::Reporter* reporter,
|
||||
// If either id is different or the clip or the matrix are different the
|
||||
// cached image won't be found. Even if it is caching the same bitmap.
|
||||
static void test_dont_find_if_diff_key(skiatest::Reporter* reporter,
|
||||
SkSpecialImage* image,
|
||||
SkSpecialImage* subset) {
|
||||
const sk_sp<SkSpecialImage>& image,
|
||||
const sk_sp<SkSpecialImage>& subset) {
|
||||
static const size_t kCacheSize = 1000000;
|
||||
SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCacheSize));
|
||||
|
||||
@ -66,7 +66,7 @@ static void test_dont_find_if_diff_key(skiatest::Reporter* reporter,
|
||||
SkImageFilter::Cache::Key key4(0, SkMatrix::I(), clip1, subset->uniqueID(), subset->subset());
|
||||
|
||||
SkIPoint offset = SkIPoint::Make(3, 4);
|
||||
cache->set(key0, image, offset);
|
||||
cache->set(key0, image.get(), offset);
|
||||
|
||||
SkIPoint foundOffset;
|
||||
REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset));
|
||||
@ -76,7 +76,7 @@ static void test_dont_find_if_diff_key(skiatest::Reporter* reporter,
|
||||
}
|
||||
|
||||
// Test purging when the max cache size is exceeded
|
||||
static void test_internal_purge(skiatest::Reporter* reporter, SkSpecialImage* image) {
|
||||
static void test_internal_purge(skiatest::Reporter* reporter, const sk_sp<SkSpecialImage>& image) {
|
||||
SkASSERT(image->getSize());
|
||||
const size_t kCacheSize = image->getSize() + 10;
|
||||
SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCacheSize));
|
||||
@ -86,14 +86,14 @@ static void test_internal_purge(skiatest::Reporter* reporter, SkSpecialImage* im
|
||||
SkImageFilter::Cache::Key key2(1, SkMatrix::I(), clip, image->uniqueID(), image->subset());
|
||||
|
||||
SkIPoint offset = SkIPoint::Make(3, 4);
|
||||
cache->set(key1, image, offset);
|
||||
cache->set(key1, image.get(), offset);
|
||||
|
||||
SkIPoint foundOffset;
|
||||
|
||||
REPORTER_ASSERT(reporter, cache->get(key1, &foundOffset));
|
||||
|
||||
// This should knock the first one out of the cache
|
||||
cache->set(key2, image, offset);
|
||||
cache->set(key2, image.get(), offset);
|
||||
|
||||
REPORTER_ASSERT(reporter, cache->get(key2, &foundOffset));
|
||||
REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset));
|
||||
@ -101,8 +101,8 @@ static void test_internal_purge(skiatest::Reporter* reporter, SkSpecialImage* im
|
||||
|
||||
// Exercise the purgeByKeys and purge methods
|
||||
static void test_explicit_purging(skiatest::Reporter* reporter,
|
||||
SkSpecialImage* image,
|
||||
SkSpecialImage* subset) {
|
||||
const sk_sp<SkSpecialImage>& image,
|
||||
const sk_sp<SkSpecialImage>& subset) {
|
||||
static const size_t kCacheSize = 1000000;
|
||||
SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCacheSize));
|
||||
|
||||
@ -111,8 +111,8 @@ static void test_explicit_purging(skiatest::Reporter* reporter,
|
||||
SkImageFilter::Cache::Key key2(1, SkMatrix::I(), clip, subset->uniqueID(), image->subset());
|
||||
|
||||
SkIPoint offset = SkIPoint::Make(3, 4);
|
||||
cache->set(key1, image, offset);
|
||||
cache->set(key2, image, offset);
|
||||
cache->set(key1, image.get(), offset);
|
||||
cache->set(key2, image.get(), offset);
|
||||
|
||||
SkIPoint foundOffset;
|
||||
|
||||
@ -135,11 +135,11 @@ DEF_TEST(ImageFilterCache_RasterBacked, reporter) {
|
||||
|
||||
const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> fullImg(SkSpecialImage::NewFromRaster(nullptr, full, srcBM));
|
||||
sk_sp<SkSpecialImage> fullImg(SkSpecialImage::MakeFromRaster(nullptr, full, srcBM));
|
||||
|
||||
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromRaster(nullptr, subset, srcBM));
|
||||
sk_sp<SkSpecialImage> subsetImg(SkSpecialImage::MakeFromRaster(nullptr, subset, srcBM));
|
||||
|
||||
test_find_existing(reporter, fullImg, subsetImg);
|
||||
test_dont_find_if_diff_key(reporter, fullImg, subsetImg);
|
||||
@ -149,16 +149,14 @@ DEF_TEST(ImageFilterCache_RasterBacked, reporter) {
|
||||
|
||||
|
||||
// Shared test code for both the raster and gpu-backed image cases
|
||||
static void test_image_backed(skiatest::Reporter* reporter, SkImage* srcImage) {
|
||||
static void test_image_backed(skiatest::Reporter* reporter, const sk_sp<SkImage>& srcImage) {
|
||||
const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> fullImg(SkSpecialImage::NewFromImage(nullptr, full, srcImage));
|
||||
sk_sp<SkSpecialImage> fullImg(SkSpecialImage::MakeFromImage(nullptr, full, srcImage));
|
||||
|
||||
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromImage(nullptr,
|
||||
subset,
|
||||
srcImage));
|
||||
sk_sp<SkSpecialImage> subsetImg(SkSpecialImage::MakeFromImage(nullptr, subset, srcImage));
|
||||
|
||||
test_find_existing(reporter, fullImg, subsetImg);
|
||||
test_dont_find_if_diff_key(reporter, fullImg, subsetImg);
|
||||
@ -171,7 +169,7 @@ DEF_TEST(ImageFilterCache_ImageBackedRaster, reporter) {
|
||||
|
||||
sk_sp<SkImage> srcImage(SkImage::MakeFromBitmap(srcBM));
|
||||
|
||||
test_image_backed(reporter, srcImage.get());
|
||||
test_image_backed(reporter, srcImage);
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
@ -207,7 +205,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, co
|
||||
return;
|
||||
}
|
||||
|
||||
test_image_backed(reporter, srcImage.get());
|
||||
test_image_backed(reporter, srcImage);
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, context) {
|
||||
@ -219,15 +217,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, context
|
||||
|
||||
const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> fullImg(SkSpecialImage::NewFromGpu(
|
||||
nullptr, full,
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
srcTexture));
|
||||
sk_sp<SkSpecialImage> fullImg(SkSpecialImage::MakeFromGpu(nullptr, full,
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
srcTexture));
|
||||
|
||||
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromGpu(
|
||||
nullptr, subset,
|
||||
sk_sp<SkSpecialImage> subsetImg(SkSpecialImage::MakeFromGpu(nullptr, subset,
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
srcTexture));
|
||||
|
||||
|
@ -158,27 +158,27 @@ static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropR
|
||||
return SkColorFilterImageFilter::Create(filter, input, cropRect);
|
||||
}
|
||||
|
||||
static SkSpecialSurface* create_empty_special_surface(GrContext* context,
|
||||
SkImageFilter::Proxy* proxy,
|
||||
int widthHeight) {
|
||||
static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context,
|
||||
SkImageFilter::Proxy* proxy,
|
||||
int widthHeight) {
|
||||
if (context) {
|
||||
GrSurfaceDesc desc;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = widthHeight;
|
||||
desc.fHeight = widthHeight;
|
||||
return SkSpecialSurface::NewRenderTarget(proxy, context, desc);
|
||||
return SkSpecialSurface::MakeRenderTarget(proxy, context, desc);
|
||||
} else {
|
||||
const SkImageInfo info = SkImageInfo::MakeN32(widthHeight, widthHeight,
|
||||
kOpaque_SkAlphaType);
|
||||
return SkSpecialSurface::NewRaster(proxy, info);
|
||||
return SkSpecialSurface::MakeRaster(proxy, info);
|
||||
}
|
||||
}
|
||||
|
||||
static SkSpecialImage* create_empty_special_image(GrContext* context,
|
||||
SkImageFilter::Proxy* proxy,
|
||||
int widthHeight) {
|
||||
SkAutoTUnref<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, widthHeight));
|
||||
static sk_sp<SkSpecialImage> create_empty_special_image(GrContext* context,
|
||||
SkImageFilter::Proxy* proxy,
|
||||
int widthHeight) {
|
||||
sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, widthHeight));
|
||||
|
||||
SkASSERT(surf);
|
||||
|
||||
@ -187,7 +187,7 @@ static SkSpecialImage* create_empty_special_image(GrContext* context,
|
||||
|
||||
canvas->clear(0x0);
|
||||
|
||||
return surf->newImageSnapshot();
|
||||
return surf->makeImageSnapshot();
|
||||
}
|
||||
|
||||
|
||||
@ -313,7 +313,7 @@ static void test_crop_rects(SkImageFilter::Proxy* proxy,
|
||||
// Check that all filters offset to their absolute crop rect,
|
||||
// unaffected by the input crop rect.
|
||||
// Tests pass by not asserting.
|
||||
SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100));
|
||||
sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100));
|
||||
SkASSERT(srcImg);
|
||||
|
||||
SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80));
|
||||
@ -357,7 +357,7 @@ static void test_crop_rects(SkImageFilter::Proxy* proxy,
|
||||
SkString str;
|
||||
str.printf("filter %d", static_cast<int>(i));
|
||||
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr);
|
||||
SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset));
|
||||
SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset));
|
||||
REPORTER_ASSERT_MESSAGE(reporter, resultImg, str.c_str());
|
||||
REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, str.c_str());
|
||||
}
|
||||
@ -399,30 +399,31 @@ static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy,
|
||||
SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five, five));
|
||||
|
||||
SkBitmap gradient = make_gradient_circle(width, height);
|
||||
SkAutoTUnref<SkSpecialImage> imgSrc(SkSpecialImage::NewFromRaster(proxy,
|
||||
SkIRect::MakeWH(width,
|
||||
height),
|
||||
gradient));
|
||||
sk_sp<SkSpecialImage> imgSrc(SkSpecialImage::MakeFromRaster(proxy,
|
||||
SkIRect::MakeWH(width, height),
|
||||
gradient));
|
||||
|
||||
SkIPoint offset;
|
||||
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> positiveResult1(positiveFilter->filterImage(imgSrc, ctx, &offset));
|
||||
SkAutoTUnref<SkSpecialImage> positiveResult1(positiveFilter->filterImage(imgSrc.get(),
|
||||
ctx, &offset));
|
||||
REPORTER_ASSERT(reporter, positiveResult1);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> negativeResult1(negativeFilter->filterImage(imgSrc, ctx, &offset));
|
||||
SkAutoTUnref<SkSpecialImage> negativeResult1(negativeFilter->filterImage(imgSrc.get(),
|
||||
ctx, &offset));
|
||||
REPORTER_ASSERT(reporter, negativeResult1);
|
||||
|
||||
SkMatrix negativeScale;
|
||||
negativeScale.setScale(-SK_Scalar1, SK_Scalar1);
|
||||
SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeWH(32, 32), nullptr);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> negativeResult2(positiveFilter->filterImage(imgSrc,
|
||||
SkAutoTUnref<SkSpecialImage> negativeResult2(positiveFilter->filterImage(imgSrc.get(),
|
||||
negativeCTX,
|
||||
&offset));
|
||||
REPORTER_ASSERT(reporter, negativeResult2);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> positiveResult2(negativeFilter->filterImage(imgSrc,
|
||||
SkAutoTUnref<SkSpecialImage> positiveResult2(negativeFilter->filterImage(imgSrc.get(),
|
||||
negativeCTX,
|
||||
&offset));
|
||||
REPORTER_ASSERT(reporter, positiveResult2);
|
||||
@ -520,14 +521,14 @@ static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy,
|
||||
SkAutoTUnref<SkImageFilter> input(SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect));
|
||||
SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(0, 0, input, &cropRect));
|
||||
|
||||
SkAutoTUnref<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, 10));
|
||||
sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, 10));
|
||||
surf->getCanvas()->clear(SK_ColorGREEN);
|
||||
SkAutoTUnref<SkSpecialImage> image(surf->newImageSnapshot());
|
||||
sk_sp<SkSpecialImage> image(surf->makeImageSnapshot());
|
||||
|
||||
SkIPoint offset;
|
||||
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> result(filter->filterImage(image, ctx, &offset));
|
||||
SkAutoTUnref<SkSpecialImage> result(filter->filterImage(image.get(), ctx, &offset));
|
||||
REPORTER_ASSERT(reporter, offset.fX == 5 && offset.fY == 0);
|
||||
REPORTER_ASSERT(reporter, result);
|
||||
REPORTER_ASSERT(reporter, result->width() == 5 && result->height() == 10);
|
||||
@ -828,12 +829,12 @@ static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy,
|
||||
SkAutoTUnref<SkImageFilter> source(SkImageSource::Create(greenImage.get()));
|
||||
SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(source.get(), source.get()));
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 1));
|
||||
sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 1));
|
||||
|
||||
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr);
|
||||
SkIPoint offset;
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> resultImg(merge->filterImage(srcImg, ctx, &offset));
|
||||
SkAutoTUnref<SkSpecialImage> resultImg(merge->filterImage(srcImg.get(), ctx, &offset));
|
||||
REPORTER_ASSERT(reporter, resultImg);
|
||||
|
||||
REPORTER_ASSERT(reporter, resultImg->width() == 20 && resultImg->height() == 20);
|
||||
@ -1091,14 +1092,14 @@ static void test_clipped_picture_imagefilter(SkImageFilter::Proxy* proxy,
|
||||
picture.reset(recorder.endRecording());
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 2));
|
||||
sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 2));
|
||||
|
||||
SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture.get()));
|
||||
|
||||
SkIPoint offset;
|
||||
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nullptr);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> resultImage(imageFilter->filterImage(srcImg, ctx, &offset));
|
||||
SkAutoTUnref<SkSpecialImage> resultImage(imageFilter->filterImage(srcImg.get(), ctx, &offset));
|
||||
REPORTER_ASSERT(reporter, !resultImage);
|
||||
}
|
||||
|
||||
@ -1343,7 +1344,7 @@ DEF_TEST(XfermodeImageFilterCroppedInput, reporter) {
|
||||
static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy,
|
||||
skiatest::Reporter* reporter,
|
||||
GrContext* context) {
|
||||
SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100));
|
||||
sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100));
|
||||
|
||||
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20));
|
||||
SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect));
|
||||
@ -1354,7 +1355,7 @@ static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy,
|
||||
SkIPoint offset;
|
||||
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg, ctx, &offset));
|
||||
SkAutoTUnref<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ctx, &offset));
|
||||
REPORTER_ASSERT(reporter, resultImg);
|
||||
REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0);
|
||||
}
|
||||
@ -1372,7 +1373,7 @@ DEF_GPUTEST_FOR_NATIVE_CONTEXT(ComposedImageFilterOffset_Gpu, reporter, context)
|
||||
static void test_partial_crop_rect(SkImageFilter::Proxy* proxy,
|
||||
skiatest::Reporter* reporter,
|
||||
GrContext* context) {
|
||||
SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100));
|
||||
sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100));
|
||||
|
||||
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30),
|
||||
SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::kHasHeight_CropEdge);
|
||||
@ -1380,7 +1381,7 @@ static void test_partial_crop_rect(SkImageFilter::Proxy* proxy,
|
||||
SkIPoint offset;
|
||||
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset));
|
||||
SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset));
|
||||
REPORTER_ASSERT(reporter, resultImg);
|
||||
|
||||
REPORTER_ASSERT(reporter, offset.fX == 0);
|
||||
|
@ -49,22 +49,23 @@ static SkBitmap create_bm() {
|
||||
}
|
||||
|
||||
// Basic test of the SkSpecialImage public API (e.g., peekTexture, peekPixels & draw)
|
||||
static void test_image(SkSpecialImage* img, skiatest::Reporter* reporter,
|
||||
static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* reporter,
|
||||
bool peekPixelsSucceeds, bool peekTextureSucceeds,
|
||||
int offset, int size) {
|
||||
const SkIRect subset = TestingSpecialImageAccess::Subset(img);
|
||||
const SkIRect subset = TestingSpecialImageAccess::Subset(img.get());
|
||||
REPORTER_ASSERT(reporter, offset == subset.left());
|
||||
REPORTER_ASSERT(reporter, offset == subset.top());
|
||||
REPORTER_ASSERT(reporter, kSmallerSize == subset.width());
|
||||
REPORTER_ASSERT(reporter, kSmallerSize == subset.height());
|
||||
|
||||
//--------------
|
||||
REPORTER_ASSERT(reporter, peekTextureSucceeds == !!TestingSpecialImageAccess::PeekTexture(img));
|
||||
REPORTER_ASSERT(reporter, peekTextureSucceeds ==
|
||||
!!TestingSpecialImageAccess::PeekTexture(img.get()));
|
||||
|
||||
//--------------
|
||||
SkPixmap pixmap;
|
||||
REPORTER_ASSERT(reporter, peekPixelsSucceeds ==
|
||||
!!TestingSpecialImageAccess::PeekPixels(img, &pixmap));
|
||||
!!TestingSpecialImageAccess::PeekPixels(img.get(), &pixmap));
|
||||
if (peekPixelsSucceeds) {
|
||||
REPORTER_ASSERT(reporter, size == pixmap.width());
|
||||
REPORTER_ASSERT(reporter, size == pixmap.height());
|
||||
@ -73,7 +74,7 @@ static void test_image(SkSpecialImage* img, skiatest::Reporter* reporter,
|
||||
//--------------
|
||||
SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlphaType);
|
||||
|
||||
SkAutoTUnref<SkSpecialSurface> surf(img->newSurface(info));
|
||||
sk_sp<SkSpecialSurface> surf(img->makeSurface(info));
|
||||
|
||||
SkCanvas* canvas = surf->getCanvas();
|
||||
|
||||
@ -98,7 +99,7 @@ static void test_image(SkSpecialImage* img, skiatest::Reporter* reporter,
|
||||
DEF_TEST(SpecialImage_Raster, reporter) {
|
||||
SkBitmap bm = create_bm();
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> fullSImage(SkSpecialImage::NewFromRaster(
|
||||
sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromRaster(
|
||||
nullptr,
|
||||
SkIRect::MakeWH(kFullSize, kFullSize),
|
||||
bm));
|
||||
@ -106,12 +107,12 @@ DEF_TEST(SpecialImage_Raster, reporter) {
|
||||
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
{
|
||||
SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromRaster(nullptr, subset, bm));
|
||||
sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromRaster(nullptr, subset, bm));
|
||||
test_image(subSImg1, reporter, true, false, kPad, kFullSize);
|
||||
}
|
||||
|
||||
{
|
||||
SkAutoTUnref<SkSpecialImage> subSImg2(fullSImage->extractSubset(subset));
|
||||
sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset));
|
||||
test_image(subSImg2, reporter, true, false, 0, kSmallerSize);
|
||||
}
|
||||
}
|
||||
@ -121,22 +122,21 @@ DEF_TEST(SpecialImage_Image, reporter) {
|
||||
|
||||
sk_sp<SkImage> fullImage(SkImage::MakeFromBitmap(bm));
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> fullSImage(SkSpecialImage::NewFromImage(
|
||||
sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromImage(
|
||||
nullptr,
|
||||
SkIRect::MakeWH(kFullSize, kFullSize),
|
||||
fullImage.get()));
|
||||
fullImage));
|
||||
|
||||
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
{
|
||||
SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromImage(nullptr,
|
||||
subset,
|
||||
fullImage.get()));
|
||||
sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromImage(nullptr, subset,
|
||||
fullImage));
|
||||
test_image(subSImg1, reporter, true, false, kPad, kFullSize);
|
||||
}
|
||||
|
||||
{
|
||||
SkAutoTUnref<SkSpecialImage> subSImg2(fullSImage->extractSubset(subset));
|
||||
sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset));
|
||||
test_image(subSImg2, reporter, true, false, 0, kSmallerSize);
|
||||
}
|
||||
}
|
||||
@ -154,16 +154,18 @@ DEF_TEST(SpecialImage_Pixmap, reporter) {
|
||||
|
||||
{
|
||||
// The SkAutoPixmapStorage keeps hold of the memory
|
||||
SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromPixmap(nullptr, subset, pixmap,
|
||||
nullptr, nullptr));
|
||||
sk_sp<SkSpecialImage> img(SkSpecialImage::MakeFromPixmap(nullptr, subset, pixmap,
|
||||
nullptr, nullptr));
|
||||
test_image(img, reporter, true, false, kPad, kFullSize);
|
||||
}
|
||||
|
||||
{
|
||||
// The image takes ownership of the memory
|
||||
SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromPixmap(
|
||||
sk_sp<SkSpecialImage> img(SkSpecialImage::MakeFromPixmap(
|
||||
nullptr, subset, pixmap,
|
||||
[] (void* addr, void*) -> void { sk_free(addr); },
|
||||
[] (void* addr, void*) -> void {
|
||||
sk_free(addr);
|
||||
},
|
||||
nullptr));
|
||||
pixmap.release();
|
||||
test_image(img, reporter, true, false, kPad, kFullSize);
|
||||
@ -187,7 +189,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> fullSImg(SkSpecialImage::NewFromGpu(
|
||||
sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeFromGpu(
|
||||
nullptr,
|
||||
SkIRect::MakeWH(kFullSize, kFullSize),
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
@ -196,7 +198,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) {
|
||||
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
{
|
||||
SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromGpu(
|
||||
sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu(
|
||||
nullptr, subset,
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
texture));
|
||||
@ -204,7 +206,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) {
|
||||
}
|
||||
|
||||
{
|
||||
SkAutoTUnref<SkSpecialImage> subSImg2(fullSImg->extractSubset(subset));
|
||||
sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset));
|
||||
test_image(subSImg2, reporter, false, true, kPad, kFullSize);
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,11 @@ static const int kPad = 5;
|
||||
static const int kFullSize = kSmallerSize + 2 * kPad;
|
||||
|
||||
// Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapshot)
|
||||
static void test_surface(SkSpecialSurface* surf, skiatest::Reporter* reporter, int offset) {
|
||||
static void test_surface(const sk_sp<SkSpecialSurface>& surf,
|
||||
skiatest::Reporter* reporter,
|
||||
int offset) {
|
||||
|
||||
const SkIRect surfSubset = TestingSpecialSurfaceAccess::Subset(surf);
|
||||
const SkIRect surfSubset = TestingSpecialSurfaceAccess::Subset(surf.get());
|
||||
REPORTER_ASSERT(reporter, offset == surfSubset.fLeft);
|
||||
REPORTER_ASSERT(reporter, offset == surfSubset.fTop);
|
||||
REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.width());
|
||||
@ -46,10 +48,10 @@ static void test_surface(SkSpecialSurface* surf, skiatest::Reporter* reporter, i
|
||||
|
||||
canvas->clear(SK_ColorRED);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> img(surf->newImageSnapshot());
|
||||
sk_sp<SkSpecialImage> img(surf->makeImageSnapshot());
|
||||
REPORTER_ASSERT(reporter, img);
|
||||
|
||||
const SkIRect imgSubset = TestingSpecialSurfaceAccess::Subset(img);
|
||||
const SkIRect imgSubset = TestingSpecialSurfaceAccess::Subset(img.get());
|
||||
REPORTER_ASSERT(reporter, surfSubset == imgSubset);
|
||||
|
||||
// the canvas was invalidated by the newImageSnapshot call
|
||||
@ -59,7 +61,7 @@ static void test_surface(SkSpecialSurface* surf, skiatest::Reporter* reporter, i
|
||||
DEF_TEST(SpecialSurface_Raster, reporter) {
|
||||
|
||||
SkImageInfo info = SkImageInfo::MakeN32(kSmallerSize, kSmallerSize, kOpaque_SkAlphaType);
|
||||
SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewRaster(nullptr, info));
|
||||
sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRaster(nullptr, info));
|
||||
|
||||
test_surface(surf, reporter, 0);
|
||||
}
|
||||
@ -71,7 +73,7 @@ DEF_TEST(SpecialSurface_Raster2, reporter) {
|
||||
|
||||
const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewFromBitmap(nullptr, subset, bm));
|
||||
sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeFromBitmap(nullptr, subset, bm));
|
||||
|
||||
test_surface(surf, reporter, kPad);
|
||||
|
||||
@ -87,7 +89,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, context) {
|
||||
desc.fWidth = kSmallerSize;
|
||||
desc.fHeight = kSmallerSize;
|
||||
|
||||
SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewRenderTarget(nullptr, context, desc));
|
||||
sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRenderTarget(nullptr, context, desc));
|
||||
|
||||
test_surface(surf, reporter, 0);
|
||||
}
|
||||
@ -105,7 +107,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, context) {
|
||||
|
||||
const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewFromTexture(nullptr, subset, temp));
|
||||
sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeFromTexture(nullptr, subset, temp));
|
||||
|
||||
test_surface(surf, reporter, kPad);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user