Update internal testing ImageFilters to sk_sp

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1854023003

Review URL: https://codereview.chromium.org/1854023003
This commit is contained in:
robertphillips 2016-04-04 05:05:11 -07:00 committed by Commit bot
parent 33550dab45
commit 43c2ad4e8f
4 changed files with 67 additions and 47 deletions

View File

@ -26,13 +26,15 @@ public:
FailImageFilter::GetFlattenableType());
}
};
static FailImageFilter* Create() { return new FailImageFilter; }
static sk_sp<SkImageFilter> Make() {
return sk_sp<SkImageFilter>(new FailImageFilter);
}
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter)
protected:
FailImageFilter() : INHERITED(0, nullptr) {}
FailImageFilter() : INHERITED(nullptr, 0, nullptr) {}
bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const override {
@ -47,7 +49,7 @@ static FailImageFilter::Registrar gReg0;
sk_sp<SkFlattenable> FailImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0);
return sk_sp<SkFlattenable>(FailImageFilter::Create());
return FailImageFilter::Make();
}
#ifndef SK_IGNORE_TO_STRING
@ -67,15 +69,14 @@ public:
IdentityImageFilter::GetFlattenableType());
}
};
static IdentityImageFilter* Create(SkImageFilter* input = nullptr) {
return new IdentityImageFilter(input);
static sk_sp<SkImageFilter> Make(sk_sp<SkImageFilter> input) {
return sk_sp<SkImageFilter>(new IdentityImageFilter(std::move(input)));
}
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(IdentityImageFilter)
protected:
IdentityImageFilter(SkImageFilter* input) : INHERITED(1, &input) {}
protected:
bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const override {
*result = src;
@ -84,6 +85,8 @@ protected:
}
private:
IdentityImageFilter(sk_sp<SkImageFilter> input) : INHERITED(&input, 1, nullptr) {}
typedef SkImageFilter INHERITED;
};
@ -91,7 +94,7 @@ static IdentityImageFilter::Registrar gReg1;
sk_sp<SkFlattenable> IdentityImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
return sk_sp<SkFlattenable>(IdentityImageFilter::Create(common.getInput(0).get()));
return IdentityImageFilter::Make(common.getInput(0));
}
#ifndef SK_IGNORE_TO_STRING
@ -195,8 +198,8 @@ protected:
auto cf = SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode);
SkImageFilter* filters[] = {
nullptr,
IdentityImageFilter::Create(),
FailImageFilter::Create(),
IdentityImageFilter::Make(nullptr).release(),
FailImageFilter::Make().release(),
SkColorFilterImageFilter::Create(cf.get()),
SkBlurImageFilter::Make(12.0f, 0.0f, nullptr).release(),
SkDropShadowImageFilter::Create(10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE,

View File

@ -35,10 +35,14 @@ public:
SimpleOffsetFilter::GetFlattenableType());
}
};
static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input) {
return new SimpleOffsetFilter(dx, dy, input);
static sk_sp<SkImageFilter> Make(SkScalar dx, SkScalar dy, sk_sp<SkImageFilter> input) {
return sk_sp<SkImageFilter>(new SimpleOffsetFilter(dx, dy, std::move(input)));
}
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SimpleOffsetFilter);
protected:
bool onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* dst, SkIPoint* offset) const override {
SkBitmap source = src;
@ -63,10 +67,6 @@ public:
return true;
}
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SimpleOffsetFilter);
protected:
void flatten(SkWriteBuffer& buffer) const override {
this->INHERITED::flatten(buffer);
buffer.writeScalar(fDX);
@ -74,8 +74,11 @@ protected:
}
private:
SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input)
: SkImageFilter(1, &input), fDX(dx), fDY(dy) {}
SimpleOffsetFilter(SkScalar dx, SkScalar dy, sk_sp<SkImageFilter> input)
: SkImageFilter(&input, 1, nullptr)
, fDX(dx)
, fDY(dy) {
}
SkScalar fDX, fDY;
@ -88,7 +91,7 @@ sk_sp<SkFlattenable> SimpleOffsetFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
SkScalar dx = buffer.readScalar();
SkScalar dy = buffer.readScalar();
return sk_sp<SkFlattenable>(Create(dx, dy, common.getInput(0).get()));
return Make(dx, dy, common.getInput(0));
}
#ifndef SK_IGNORE_TO_STRING
@ -132,18 +135,20 @@ protected:
canvas->translate(SkIntToScalar(100), 0);
}
{
SkAutoTUnref<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5));
sk_sp<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5));
SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
0, SK_Scalar1, 0, 0, 0,
0, 0, SK_Scalar1, 0, 0,
0, 0, 0, 0.5f, 0 };
auto matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter.get(), morph));
sk_sp<SkColorFilter> matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter.get(),
morph.get()));
SkPaint paint;
paint.setImageFilter(SkXfermodeImageFilter::Make(
SkXfermode::Make(SkXfermode::kSrcOver_Mode), colorMorph));
SkXfermode::Make(SkXfermode::kSrcOver_Mode),
colorMorph.get()));
DrawClippedImage(canvas, fImage.get(), paint);
canvas->translate(SkIntToScalar(100), 0);
@ -153,15 +158,14 @@ protected:
0, SK_Scalar1, 0, 0, 0,
0, 0, SK_Scalar1, 0, 0,
0, 0, 0, 0.5f, 0 };
auto matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Create(matrixCF.get()));
SkAutoTUnref<SkImageFilter> offsetFilter(
SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter));
sk_sp<SkColorFilter> matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Create(matrixCF.get()));
sk_sp<SkImageFilter> offsetFilter(SimpleOffsetFilter::Make(10.0f, 10.f, matrixFilter));
SkPaint paint;
paint.setImageFilter(
SkXfermodeImageFilter::Make(SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0),
matrixFilter, offsetFilter, nullptr));
matrixFilter.get(), offsetFilter.get(), nullptr));
DrawClippedImage(canvas, fImage.get(), paint);
canvas->translate(SkIntToScalar(100), 0);

View File

@ -51,20 +51,21 @@ namespace {
class MatrixTestImageFilter : public SkImageFilter {
public:
MatrixTestImageFilter(skiatest::Reporter* reporter, const SkMatrix& expectedMatrix)
: SkImageFilter(0, nullptr), fReporter(reporter), fExpectedMatrix(expectedMatrix) {
}
bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const override {
REPORTER_ASSERT(fReporter, ctx.ctm() == fExpectedMatrix);
return true;
static sk_sp<SkImageFilter> Make(skiatest::Reporter* reporter,
const SkMatrix& expectedMatrix) {
return sk_sp<SkImageFilter>(new MatrixTestImageFilter(reporter, expectedMatrix));
}
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(MatrixTestImageFilter)
protected:
bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const override {
REPORTER_ASSERT(fReporter, ctx.ctm() == fExpectedMatrix);
return true;
}
void flatten(SkWriteBuffer& buffer) const override {
this->INHERITED::flatten(buffer);
buffer.writeFunctionPtr(fReporter);
@ -72,6 +73,12 @@ protected:
}
private:
MatrixTestImageFilter(skiatest::Reporter* reporter, const SkMatrix& expectedMatrix)
: INHERITED(nullptr, 0, nullptr)
, fReporter(reporter)
, fExpectedMatrix(expectedMatrix) {
}
skiatest::Reporter* fReporter;
SkMatrix fExpectedMatrix;
@ -250,7 +257,7 @@ sk_sp<SkFlattenable> MatrixTestImageFilter::CreateProc(SkReadBuffer& buffer) {
skiatest::Reporter* reporter = (skiatest::Reporter*)buffer.readFunctionPtr();
SkMatrix matrix;
buffer.readMatrix(&matrix);
return sk_make_sp<MatrixTestImageFilter>(reporter, matrix);
return MatrixTestImageFilter::Make(reporter, matrix);
}
#ifndef SK_IGNORE_TO_STRING
@ -1027,9 +1034,7 @@ DEF_TEST(ImageFilterMatrix, reporter) {
SkCanvas* recordingCanvas = recorder.beginRecording(100, 100, &factory, 0);
SkPaint paint;
SkAutoTUnref<MatrixTestImageFilter> imageFilter(
new MatrixTestImageFilter(reporter, expectedMatrix));
paint.setImageFilter(imageFilter.get());
paint.setImageFilter(MatrixTestImageFilter::Make(reporter, expectedMatrix));
recordingCanvas->saveLayer(nullptr, &paint);
SkPaint solidPaint;
solidPaint.setColor(0xFFFFFFFF);

View File

@ -364,8 +364,15 @@ namespace {
class DummyImageFilter : public SkImageFilter {
public:
DummyImageFilter(bool visited = false) : SkImageFilter(0, nullptr), fVisited(visited) {}
~DummyImageFilter() override {}
static sk_sp<DummyImageFilter> Make(bool visited = false) {
return sk_sp<DummyImageFilter>(new DummyImageFilter(visited));
}
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(DummyImageFilter)
bool visited() const { return fVisited; }
protected:
bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const override {
fVisited = true;
@ -373,18 +380,19 @@ public:
*result = src;
return true;
}
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(DummyImageFilter)
bool visited() const { return fVisited; }
private:
DummyImageFilter(bool visited) : INHERITED(nullptr, 0, nullptr), fVisited(visited) {}
mutable bool fVisited;
typedef SkImageFilter INHERITED;
};
sk_sp<SkFlattenable> DummyImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0);
bool visited = buffer.readBool();
return sk_make_sp<DummyImageFilter>(visited);
return DummyImageFilter::Make(visited);
}
#ifndef SK_IGNORE_TO_STRING
@ -403,7 +411,7 @@ DEF_TEST(PDFImageFilter, reporter) {
sk_sp<SkDocument> doc(SkDocument::CreatePDF(&stream));
SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
sk_sp<DummyImageFilter> filter(new DummyImageFilter());
sk_sp<DummyImageFilter> filter(DummyImageFilter::Make());
// Filter just created; should be unvisited.
REPORTER_ASSERT(reporter, !filter->visited());