robertphillips 2016-03-31 09:05:49 -07:00 committed by Commit bot
parent 865a289bfe
commit 51a315eff9
17 changed files with 183 additions and 130 deletions

View File

@ -73,8 +73,7 @@ protected:
SkIntToScalar(fCheckerboard.height()));
const SkImageFilter::CropRect cropRect(bmpRect.makeInset(10.f, 10.f));
const SkImageFilter::CropRect cropRectLarge(bmpRect);
SkAutoTUnref<SkImageFilter> noOpCropped(SkOffsetImageFilter::Create(0, 0, nullptr,
&cropRect));
sk_sp<SkImageFilter> noOpCropped(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect));
SkImageFilter* input = fIsExpanded ? noOpCropped.get() : nullptr;

View File

@ -150,9 +150,10 @@ static void create_paints(SkImageFilter* source, SkTArray<SkPaint>* paints) {
}
{
SkAutoTUnref<SkImageFilter> oif(SkOffsetImageFilter::Create(15, 15, source));
sk_sp<SkImageFilter> oif(SkOffsetImageFilter::Make(15, 15,
sk_ref_sp<SkImageFilter>(source)));
add_paint(oif, paints);
add_paint(oif.get(), paints);
}
}

View File

@ -108,7 +108,9 @@ protected:
checkerboard.get()),
SkDilateImageFilter::Create(2, 2, checkerboard.get()),
SkErodeImageFilter::Create(2, 2, checkerboard.get()),
SkOffsetImageFilter::Create(SkIntToScalar(-16), SkIntToScalar(32)),
SkOffsetImageFilter::Make(SkIntToScalar(-16),
SkIntToScalar(32),
nullptr).release(),
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1, SkIntToScalar(2), checkerboard.get()),

View File

@ -50,8 +50,7 @@ protected:
SkAutoTUnref<SkImageFilter> gradientCircleSource(
SkImageSource::Create(gradientCircle.get()));
SkAutoTUnref<SkImageFilter> noopCropped(
SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect));
sk_sp<SkImageFilter> noopCropped(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect));
SkScalar sk255 = SkIntToScalar(255);
SkScalar matrix[20] = { 1, 0, 0, 0, 0,
0, 1, 0, 0, sk255,
@ -77,40 +76,63 @@ protected:
SkIntToScalar(outset));
SkImageFilter::CropRect bigRect(rect, SkImageFilter::CropRect::kHasAll_CropEdge);
Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Create(
cfAlphaTrans.get(), noopCropped.get(), &bigRect));
Draw(canvas, checkerboard, rect, SkBlurImageFilter::Create(
0.3f, 0.3f, noopCropped.get(), &bigRect));
Draw(canvas, checkerboard, rect, SkBlurImageFilter::Create(
8.0f, 8.0f, noopCropped.get(), &bigRect));
Draw(canvas, checkerboard, rect, SkDilateImageFilter::Create(
2, 2, noopCropped.get(), &bigRect));
Draw(canvas, checkerboard, rect, SkErodeImageFilter::Create(
2, 2, noopCropped.get(), &bigRect));
Draw(canvas, checkerboard, rect, SkDropShadowImageFilter::Create(
SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(3), SkIntToScalar(3),
SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
noopCropped.get(), &bigRect));
Draw(canvas, checkerboard, rect, SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kR_ChannelSelectorType,
SkDisplacementMapEffect::kR_ChannelSelectorType,
SkIntToScalar(12),
gradientCircleSource.get(),
noopCropped.get(),
&bigRect));
Draw(canvas, checkerboard, rect, SkOffsetImageFilter::Create(
SkIntToScalar(-8), SkIntToScalar(16), noopCropped.get(), &bigRect));
Draw(canvas, checkerboard, rect,
sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cfAlphaTrans.get(),
noopCropped.get(),
&bigRect)));
Draw(canvas, checkerboard, rect,
SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE,
surfaceScale, kd, noopCropped.get(), &bigRect));
sk_sp<SkImageFilter>(SkBlurImageFilter::Create(0.3f, 0.3f,
noopCropped.get(),
&bigRect)));
Draw(canvas, checkerboard, rect,
sk_sp<SkImageFilter>(SkBlurImageFilter::Create(8.0f, 8.0f,
noopCropped.get(),
&bigRect)));
Draw(canvas, checkerboard, rect,
sk_sp<SkImageFilter>(SkDilateImageFilter::Create(2, 2,
noopCropped.get(),
&bigRect)));
Draw(canvas, checkerboard, rect,
sk_sp<SkImageFilter>(SkErodeImageFilter::Create(2, 2,
noopCropped.get(),
&bigRect)));
Draw(canvas, checkerboard, rect,
sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(
SkIntToScalar(10),
SkIntToScalar(10),
SkIntToScalar(3),
SkIntToScalar(3),
SK_ColorBLUE,
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
noopCropped.get(),
&bigRect)));
Draw(canvas, checkerboard, rect,
sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kR_ChannelSelectorType,
SkDisplacementMapEffect::kR_ChannelSelectorType,
SkIntToScalar(12),
gradientCircleSource.get(),
noopCropped.get(),
&bigRect)));
Draw(canvas, checkerboard, rect,
SkOffsetImageFilter::Make(SkIntToScalar(-8), SkIntToScalar(16),
noopCropped,
&bigRect));
Draw(canvas, checkerboard, rect,
sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation,
SK_ColorWHITE,
surfaceScale,
kd,
noopCropped.get(),
&bigRect)));
canvas->restore();
canvas->translate(0, SkIntToScalar(80));
@ -157,9 +179,10 @@ private:
return surface->makeImageSnapshot();
}
static void Draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rect, SkImageFilter* filter) {
static void Draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rect,
sk_sp<SkImageFilter> filter) {
SkPaint paint;
paint.setImageFilter(filter)->unref();
paint.setImageFilter(std::move(filter));
canvas->saveLayer(&rect, &paint);
canvas->drawBitmap(bitmap, 0, 0);
canvas->restore();

View File

@ -119,8 +119,9 @@ protected:
SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge);
SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge);
SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create(
SkIntToScalar(-10), SkIntToScalar(-10)));
sk_sp<SkImageFilter> offset(SkOffsetImageFilter::Make(SkIntToScalar(-10),
SkIntToScalar(-10),
nullptr));
sk_sp<SkImageFilter> cfOffset(SkColorFilterImageFilter::Create(cf.get(), offset.get()));

View File

@ -84,7 +84,7 @@ protected:
checkerboard.get()),
SkDilateImageFilter::Create(1, 1, checkerboard.get()),
SkErodeImageFilter::Create(1, 1, checkerboard.get()),
SkOffsetImageFilter::Create(SkIntToScalar(32), 0),
SkOffsetImageFilter::Make(SkIntToScalar(32), 0, nullptr).release(),
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
SkPaintImageFilter::Make(noisePaint).release(),
SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd),

View File

@ -61,7 +61,7 @@ protected:
SkBlurImageFilter::Create(5, 5),
SkDropShadowImageFilter::Create(10, 10, 3, 3, SK_ColorGREEN,
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
SkOffsetImageFilter::Create(-16, 32),
SkOffsetImageFilter::Make(-16, 32, nullptr).release(),
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
};

View File

@ -80,7 +80,7 @@ protected:
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65));
SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100));
SkAutoTUnref<SkImageFilter> noopCropped(SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect));
sk_sp<SkImageFilter> noopCropped(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect));
int y = 0;
for (int i = 0; i < 3; i++) {

View File

@ -68,7 +68,7 @@ protected:
IFCCast([]{ return SkBlurImageFilter::Create(8, 8); }),
IFCCast([]{ return SkDilateImageFilter::Create(8, 8); }),
IFCCast([]{ return SkErodeImageFilter::Create(8, 8); }),
IFCCast([]{ return SkOffsetImageFilter::Create(8, 8); }),
IFCCast([]{ return SkOffsetImageFilter::Make(8, 8, nullptr).release(); }),
};
const SkMatrix matrices[] = {

View File

@ -53,20 +53,17 @@ protected:
image->width() - i * 8,
image->height() - i * 12);
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image));
sk_sp<SkImageFilter> tileInput(SkImageSource::Create(image));
SkScalar dx = SkIntToScalar(i*5);
SkScalar dy = SkIntToScalar(i*10);
SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(dx, dy, tileInput,
&rect));
paint.setImageFilter(filter);
paint.setImageFilter(SkOffsetImageFilter::Make(dx, dy, std::move(tileInput), &rect));
DrawClippedImage(canvas, image, paint, 1, cropRect);
canvas->translate(SkIntToScalar(image->width() + MARGIN), 0);
}
SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100);
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10, nullptr, &rect));
paint.setImageFilter(filter);
paint.setImageFilter(SkOffsetImageFilter::Make(-5, -10, nullptr, &rect));
DrawClippedImage(canvas, fBitmap.get(), paint, 2, cropRect);
}
private:
@ -111,7 +108,7 @@ protected:
SkISize onISize() override { return SkISize::Make(640, 200); }
void doDraw(SkCanvas* canvas, const SkRect& r, SkImageFilter* imgf,
void doDraw(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imgf,
const SkRect* clipR = nullptr) {
SkPaint p;
@ -139,7 +136,7 @@ protected:
canvas->clipRect(*clipR);
}
if (imgf) {
p.setImageFilter(imgf)->unref();
p.setImageFilter(std::move(imgf));
}
p.setColor(0x66FF0000);
canvas->drawRect(r, p);
@ -162,20 +159,20 @@ protected:
this->doDraw(canvas, r, nullptr);
canvas->translate(100, 0);
this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20));
this->doDraw(canvas, r, SkOffsetImageFilter::Make(20, 20, nullptr));
canvas->translate(100, 0);
this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, &cr0));
this->doDraw(canvas, r, SkOffsetImageFilter::Make(20, 20, nullptr, &cr0));
canvas->translate(100, 0);
this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20), &r);
this->doDraw(canvas, r, SkOffsetImageFilter::Make(20, 20, nullptr), &r);
canvas->translate(100, 0);
this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, &cr1));
this->doDraw(canvas, r, SkOffsetImageFilter::Make(20, 20, nullptr, &cr1));
SkRect clipR = SkRect::MakeXYWH(40, 40, 40, 40);
canvas->translate(100, 0);
this->doDraw(canvas, r, SkOffsetImageFilter::Create(20, 20, nullptr, nullptr), &clipR);
this->doDraw(canvas, r, SkOffsetImageFilter::Make(20, 20, nullptr, nullptr), &clipR);
canvas->restore();
// 2nd row
@ -186,19 +183,19 @@ protected:
*/
// crop==clip==src
this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr0), &r);
this->doDraw(canvas, r, SkOffsetImageFilter::Make(40, 0, nullptr, &cr0), &r);
// crop==src, clip==dst
canvas->translate(100, 0);
this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr0), &r2);
this->doDraw(canvas, r, SkOffsetImageFilter::Make(40, 0, nullptr, &cr0), &r2);
// crop==dst, clip==src
canvas->translate(100, 0);
this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2), &r);
this->doDraw(canvas, r, SkOffsetImageFilter::Make(40, 0, nullptr, &cr2), &r);
// crop==clip==dst
canvas->translate(100, 0);
this->doDraw(canvas, r, SkOffsetImageFilter::Create(40, 0, nullptr, &cr2), &r2);
this->doDraw(canvas, r, SkOffsetImageFilter::Make(40, 0, nullptr, &cr2), &r2);
}
private:

View File

@ -21,55 +21,63 @@
#define FILTER_WIDTH SkIntToScalar(150)
#define FILTER_HEIGHT SkIntToScalar(200)
static SkImageFilter* make0() {
return SkDownSampleImageFilter::Create(SK_Scalar1 / 5);
static sk_sp<SkImageFilter> make0() {
return sk_sp<SkImageFilter>(SkDownSampleImageFilter::Create(SK_Scalar1 / 5));
}
static SkImageFilter* make1() {
return SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16));
static sk_sp<SkImageFilter> make1() {
return SkOffsetImageFilter::Make(SkIntToScalar(16), SkIntToScalar(16), nullptr);
}
static SkImageFilter* make2() {
static sk_sp<SkImageFilter> make2() {
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
return SkColorFilterImageFilter::Create(cf.get());
return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get()));
}
static SkImageFilter* make3() {
return SkBlurImageFilter::Create(8, 0);
static sk_sp<SkImageFilter> make3() {
return sk_sp<SkImageFilter>(SkBlurImageFilter::Create(8, 0));
}
static SkImageFilter* make4() {
sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)));
static sk_sp<SkImageFilter> make4() {
sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Make(SkIntToScalar(16),
SkIntToScalar(16),
nullptr));
sk_sp<SkImageFilter> inner(SkDownSampleImageFilter::Create(SK_Scalar1 / 5));
return SkComposeImageFilter::Make(std::move(outer), std::move(inner)).release();
return SkComposeImageFilter::Make(std::move(outer), std::move(inner));
}
static SkImageFilter* make5() {
sk_sp<SkImageFilter> first(SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)));
static sk_sp<SkImageFilter> make5() {
sk_sp<SkImageFilter> first(SkOffsetImageFilter::Make(SkIntToScalar(16),
SkIntToScalar(16),
nullptr));
sk_sp<SkImageFilter> second(SkDownSampleImageFilter::Create(SK_Scalar1 / 5));
return SkMergeImageFilter::Make(std::move(first), std::move(second)).release();
return SkMergeImageFilter::Make(std::move(first), std::move(second));
}
static SkImageFilter* make6() {
sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)));
static sk_sp<SkImageFilter> make6() {
sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Make(SkIntToScalar(16),
SkIntToScalar(16),
nullptr));
sk_sp<SkImageFilter> inner(SkDownSampleImageFilter::Create(SK_Scalar1 / 5));
sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner)));
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode));
sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Create(cf.get()));
return SkMergeImageFilter::Make(std::move(compose), std::move(blue)).release();
return SkMergeImageFilter::Make(std::move(compose), std::move(blue));
}
static SkImageFilter* make7() {
sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)));
static sk_sp<SkImageFilter> make7() {
sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Make(SkIntToScalar(16),
SkIntToScalar(16),
nullptr));
sk_sp<SkImageFilter> inner(make3());
sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner)));
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode));
sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Create(cf.get()));
return SkMergeImageFilter::Make(std::move(compose), std::move(blue)).release();
return SkMergeImageFilter::Make(std::move(compose), std::move(blue));
}
static void draw0(SkCanvas* canvas) {
@ -96,7 +104,7 @@ protected:
void onDraw(SkCanvas* canvas) override {
// this->drawSizeBounds(canvas, 0xFFCCCCCC);
static SkImageFilter* (*gFilterProc[])() = {
static sk_sp<SkImageFilter> (*gFilterProc[])() = {
make0, make1, make2, make3, make4, make5, make6, make7
};
@ -119,7 +127,7 @@ protected:
canvas->drawRect(bounds, p);
SkPaint paint;
paint.setImageFilter(gFilterProc[i]())->unref();
paint.setImageFilter(gFilterProc[i]());
canvas->saveLayer(&bounds, &paint);
draw0(canvas);
}

View File

@ -85,10 +85,10 @@ protected:
};
int x = 0, y = 0;
SkAutoTUnref<SkImageFilter> background(SkImageSource::Create(fCheckerboard.get()));
sk_sp<SkImageFilter> background(SkImageSource::Create(fCheckerboard.get()));
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(gModes[i].fMode),
background));
background.get()));
DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -98,7 +98,8 @@ protected:
}
// Test arithmetic mode as image filter
paint.setImageFilter(SkXfermodeImageFilter::Make(
SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0), background));
SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0),
background.get()));
DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -106,7 +107,7 @@ protected:
y += fBitmap.height() + MARGIN;
}
// Test nullptr mode
paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background));
paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background.get()));
DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -117,14 +118,18 @@ protected:
SkIntToScalar(fBitmap.height() + 4));
// Test offsets on SrcMode (uses fixed-function blend)
sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap));
SkAutoTUnref<SkImageFilter> foreground(SkImageSource::Create(bitmapImage.get()));
SkAutoTUnref<SkImageFilter> offsetForeground(SkOffsetImageFilter::Create(
SkIntToScalar(4), SkIntToScalar(-4), foreground));
SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create(
SkIntToScalar(4), SkIntToScalar(4), background));
sk_sp<SkImageFilter> foreground(SkImageSource::Create(bitmapImage.get()));
sk_sp<SkImageFilter> offsetForeground(SkOffsetImageFilter::Make(SkIntToScalar(4),
SkIntToScalar(-4),
foreground));
sk_sp<SkImageFilter> offsetBackground(SkOffsetImageFilter::Make(SkIntToScalar(4),
SkIntToScalar(4),
background));
paint.setImageFilter(SkXfermodeImageFilter::Make(
SkXfermode::Make(SkXfermode::kSrcOver_Mode), offsetBackground,
offsetForeground, nullptr));
SkXfermode::Make(SkXfermode::kSrcOver_Mode),
offsetBackground.get(),
offsetForeground.get(),
nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -133,7 +138,9 @@ protected:
}
// Test offsets on Darken (uses shader blend)
paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kDarken_Mode),
offsetBackground, offsetForeground, nullptr));
offsetBackground.get(),
offsetForeground.get(),
nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -154,8 +161,10 @@ protected:
fBitmap.width() + offsets[i][2],
fBitmap.height() + offsets[i][3]);
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
paint.setImageFilter(SkXfermodeImageFilter::Make(
SkXfermode::Make(sampledModes[i]), offsetBackground, offsetForeground, &rect));
paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(sampledModes[i]),
offsetBackground.get(),
offsetForeground.get(),
&rect));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -166,9 +175,9 @@ protected:
// Test small bg, large fg with Screen (uses shader blend)
auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode);
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60));
SkAutoTUnref<SkImageFilter> cropped(
SkOffsetImageFilter::Create(0, 0, foreground, &cropRect));
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped, background, nullptr));
sk_sp<SkImageFilter> cropped(SkOffsetImageFilter::Make(0, 0, foreground, &cropRect));
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped.get(),
background.get(), nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -176,7 +185,8 @@ protected:
y += fBitmap.height() + MARGIN;
}
// Test small fg, large bg with Screen (uses shader blend)
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropped, nullptr));
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background.get(),
cropped.get(), nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -188,7 +198,8 @@ protected:
// the region outside the foreground.
mode = SkXfermode::Make(SkXfermode::kSrcIn_Mode);
SkImageFilter::CropRect cropRectFull(SkRect::MakeXYWH(0, 0, 80, 80));
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropped, &cropRectFull));
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background.get(),
cropped.get(), &cropRectFull));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {

View File

@ -13,12 +13,14 @@
class SK_API SkOffsetImageFilter : public SkImageFilter {
public:
static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input = NULL,
const CropRect* cropRect = NULL) {
static sk_sp<SkImageFilter> Make(SkScalar dx, SkScalar dy,
sk_sp<SkImageFilter> input,
const CropRect* cropRect = nullptr) {
if (!SkScalarIsFinite(dx) || !SkScalarIsFinite(dy)) {
return NULL;
return nullptr;
}
return new SkOffsetImageFilter(dx, dy, input, cropRect);
return sk_sp<SkImageFilter>(new SkOffsetImageFilter(dx, dy, std::move(input), cropRect));
}
SkRect computeFastBounds(const SkRect& src) const override;
@ -26,6 +28,13 @@ public:
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkOffsetImageFilter)
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input = nullptr,
const CropRect* cropRect = nullptr) {
return Make(dx, dy, sk_ref_sp(input), cropRect).release();
}
#endif
protected:
void flatten(SkWriteBuffer&) const override;
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
@ -33,7 +42,7 @@ protected:
SkIRect onFilterNodeBounds(const SkIRect&, const SkMatrix&, MapDirection) const override;
private:
SkOffsetImageFilter(SkScalar dx, SkScalar dy, SkImageFilter* input, const CropRect*);
SkOffsetImageFilter(SkScalar dx, SkScalar dy, sk_sp<SkImageFilter> input, const CropRect*);
SkVector fOffset;

View File

@ -605,12 +605,9 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
nullptr);
break;
}
case OFFSET: {
sk_sp<SkImageFilter> subFilter(make_image_filter());
filter = sk_sp<SkImageFilter>(SkOffsetImageFilter::Create(make_scalar(), make_scalar(),
subFilter.get()));
case OFFSET:
filter = SkOffsetImageFilter::Make(make_scalar(), make_scalar(), make_image_filter());
break;
}
case MATRIX: {
sk_sp<SkImageFilter> subFilter(make_image_filter());
filter = sk_sp<SkImageFilter>(SkImageFilter::CreateMatrixFilter(make_matrix(),

View File

@ -86,7 +86,7 @@ SkFlattenable* SkOffsetImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
SkPoint offset;
buffer.readPoint(&offset);
return Create(offset.x(), offset.y(), common.getInput(0).get(), &common.cropRect());
return Make(offset.x(), offset.y(), common.getInput(0), &common.cropRect()).release();
}
void SkOffsetImageFilter::flatten(SkWriteBuffer& buffer) const {
@ -94,9 +94,10 @@ void SkOffsetImageFilter::flatten(SkWriteBuffer& buffer) const {
buffer.writePoint(fOffset);
}
SkOffsetImageFilter::SkOffsetImageFilter(SkScalar dx, SkScalar dy, SkImageFilter* input,
SkOffsetImageFilter::SkOffsetImageFilter(SkScalar dx, SkScalar dy,
sk_sp<SkImageFilter> input,
const CropRect* cropRect)
: INHERITED(1, &input, cropRect) {
: INHERITED(&input, 1, cropRect) {
fOffset.set(dx, dy);
}

View File

@ -28,9 +28,10 @@ SkImageFilter* SkTileImageFilter::Create(const SkRect& srcRect, const SkRect& ds
return SkSafeRef(input);
}
CropRect cropRect(ir);
return SkOffsetImageFilter::Create(dstRect.x() - srcRect.x(),
dstRect.y() - srcRect.y(),
input, &cropRect);
return SkOffsetImageFilter::Make(dstRect.x() - srcRect.x(),
dstRect.y() - srcRect.y(),
sk_ref_sp<SkImageFilter>(input),
&cropRect).release();
}
return new SkTileImageFilter(srcRect, dstRect, input);
}

View File

@ -119,7 +119,7 @@ public:
sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circle(64, 64)));
SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradientImage.get()));
SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(five, five, input));
sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(five, five, input));
SkMatrix matrix;
matrix.setTranslate(SK_Scalar1, SK_Scalar1);
@ -177,7 +177,9 @@ public:
std::move(paintFilterLeft), std::move(paintFilterRight),
SkXfermode::kSrcOver_Mode, cropRect).release());
this->addFilter("offset",
SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input, cropRect));
SkOffsetImageFilter::Make(SK_Scalar1, SK_Scalar1,
sk_ref_sp<SkImageFilter>(input),
cropRect).release());
this->addFilter("dilate", SkDilateImageFilter::Create(3, 2, input, cropRect));
this->addFilter("erode", SkErodeImageFilter::Create(2, 3, input, cropRect));
this->addFilter("tile", SkTileImageFilter::Create(
@ -188,8 +190,9 @@ public:
this->addFilter("matrix", SkImageFilter::CreateMatrixFilter(
matrix, kLow_SkFilterQuality, input));
}
this->addFilter("blur and offset", SkOffsetImageFilter::Create(
five, five, blur.get(), cropRect));
this->addFilter("blur and offset",
SkOffsetImageFilter::Make(five, five, blur,
cropRect).release());
this->addFilter("picture and blur", SkBlurImageFilter::Create(
five, five, pictureFilter.get(), cropRect));
this->addFilter("paint and blur", SkBlurImageFilter::Create(
@ -595,8 +598,8 @@ static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy,
GrContext* context) {
// Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset works correctly.
SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10)));
SkAutoTUnref<SkImageFilter> input(SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect));
SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(0, 0, input, &cropRect));
sk_sp<SkImageFilter> input(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect));
sk_sp<SkImageFilter> filter(SkBlurImageFilter::Create(0, 0, input.get(), &cropRect));
sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, 10));
surf->getCanvas()->clear(SK_ColorGREEN);
@ -799,7 +802,7 @@ DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) {
}
DEF_TEST(ImageFilterUnionBounds, reporter) {
SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create(50, 0));
sk_sp<SkImageFilter> offset(SkOffsetImageFilter::Make(50, 0, nullptr));
// Regardless of which order they appear in, the image filter bounds should
// be combined correctly.
{
@ -1340,7 +1343,7 @@ static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy,
sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100));
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20));
sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect));
sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect));
sk_sp<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1,
nullptr, &cropRect));
sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(blurFilter),
@ -1379,7 +1382,7 @@ static void test_composed_imagefilter_bounds(SkImageFilter::Proxy* proxy,
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture));
SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100));
sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(-100, 0, nullptr, &cropRect));
sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(-100, 0, nullptr, &cropRect));
sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(offsetFilter),
std::move(pictureFilter)));