Update SkMatrixImageFilter to sk_sp
TBR=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1858353002 Review URL: https://codereview.chromium.org/1858353002
This commit is contained in:
parent
77304a5b76
commit
ae8c933ca8
@ -594,13 +594,11 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
|
||||
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(),
|
||||
(SkFilterQuality)R(4),
|
||||
subFilter.get()));
|
||||
case MATRIX:
|
||||
filter = SkImageFilter::MakeMatrixFilter(make_matrix(),
|
||||
(SkFilterQuality)R(4),
|
||||
make_image_filter());
|
||||
break;
|
||||
}
|
||||
case MATRIX_CONVOLUTION: {
|
||||
SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
|
||||
SkIntToScalar(kBitmapSize)));
|
||||
|
@ -95,7 +95,7 @@ static void create_paints(SkTArray<SkPaint>* paints, sk_sp<SkImageFilter> source
|
||||
scale.setScale(2.0f, 2.0f);
|
||||
|
||||
sk_sp<SkImageFilter> scaleMIF(
|
||||
SkImageFilter::CreateMatrixFilter(scale, kLow_SkFilterQuality, source.get()));
|
||||
SkImageFilter::MakeMatrixFilter(scale, kLow_SkFilterQuality, source));
|
||||
|
||||
add_paint(paints, std::move(scaleMIF));
|
||||
}
|
||||
@ -105,7 +105,7 @@ static void create_paints(SkTArray<SkPaint>* paints, sk_sp<SkImageFilter> source
|
||||
rot.setRotate(-33.3f);
|
||||
|
||||
sk_sp<SkImageFilter> rotMIF(
|
||||
SkImageFilter::CreateMatrixFilter(rot, kLow_SkFilterQuality, source.get()));
|
||||
SkImageFilter::MakeMatrixFilter(rot, kLow_SkFilterQuality, source));
|
||||
|
||||
add_paint(paints, std::move(rotMIF));
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
*
|
||||
* see https://bug.skia.org/3741
|
||||
*/
|
||||
static void do_draw(SkCanvas* canvas, SkXfermode::Mode mode, SkImageFilter* imf) {
|
||||
static void do_draw(SkCanvas* canvas, SkXfermode::Mode mode, sk_sp<SkImageFilter> imf) {
|
||||
SkAutoCanvasRestore acr(canvas, true);
|
||||
canvas->clipRect(SkRect::MakeWH(220, 220));
|
||||
|
||||
@ -39,7 +39,7 @@ static void do_draw(SkCanvas* canvas, SkXfermode::Mode mode, SkImageFilter* imf)
|
||||
canvas->drawOval(r0, paint);
|
||||
|
||||
paint.setColor(0x660000FF);
|
||||
paint.setImageFilter(imf);
|
||||
paint.setImageFilter(std::move(imf));
|
||||
paint.setXfermodeMode(mode);
|
||||
canvas->drawOval(r1, paint);
|
||||
}
|
||||
@ -48,8 +48,9 @@ DEF_SIMPLE_GM(imagefilters_xfermodes, canvas, 480, 480) {
|
||||
canvas->translate(10, 10);
|
||||
|
||||
// just need an imagefilter to trigger the code-path (which creates a tmp layer)
|
||||
SkAutoTUnref<SkImageFilter> imf(SkImageFilter::CreateMatrixFilter(SkMatrix::I(),
|
||||
kNone_SkFilterQuality));
|
||||
sk_sp<SkImageFilter> imf(SkImageFilter::MakeMatrixFilter(SkMatrix::I(),
|
||||
kNone_SkFilterQuality,
|
||||
nullptr));
|
||||
|
||||
const SkXfermode::Mode modes[] = {
|
||||
SkXfermode::kSrcATop_Mode, SkXfermode::kDstIn_Mode
|
||||
|
@ -106,7 +106,7 @@ protected:
|
||||
SkDilateImageFilter::Make(2, 2, checkerboard).release(),
|
||||
SkErodeImageFilter::Make(2, 2, checkerboard).release(),
|
||||
SkOffsetImageFilter::Make(SkIntToScalar(-16), SkIntToScalar(32), nullptr).release(),
|
||||
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
|
||||
SkImageFilter::MakeMatrixFilter(resizeMatrix, kNone_SkFilterQuality, nullptr).release(),
|
||||
SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1,
|
||||
SkIntToScalar(2), checkerboard.get()),
|
||||
|
||||
|
@ -85,7 +85,7 @@ protected:
|
||||
SkDilateImageFilter::Make(1, 1, checkerboard).release(),
|
||||
SkErodeImageFilter::Make(1, 1, checkerboard).release(),
|
||||
SkOffsetImageFilter::Make(SkIntToScalar(32), 0, nullptr).release(),
|
||||
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
|
||||
SkImageFilter::MakeMatrixFilter(resizeMatrix, kNone_SkFilterQuality, nullptr).release(),
|
||||
SkPaintImageFilter::Make(noisePaint).release(),
|
||||
SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd),
|
||||
SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent,
|
||||
|
@ -57,12 +57,12 @@ protected:
|
||||
SkMatrix resizeMatrix;
|
||||
resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y);
|
||||
|
||||
SkImageFilter* filters[] = {
|
||||
SkBlurImageFilter::Make(5, 5, nullptr).release(),
|
||||
SkDropShadowImageFilter::Create(10, 10, 3, 3, SK_ColorGREEN,
|
||||
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
|
||||
SkOffsetImageFilter::Make(-16, 32, nullptr).release(),
|
||||
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
|
||||
sk_sp<SkImageFilter> filters[] = {
|
||||
SkBlurImageFilter::Make(5, 5, nullptr),
|
||||
sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(10, 10, 3, 3, SK_ColorGREEN,
|
||||
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)),
|
||||
SkOffsetImageFilter::Make(-16, 32, nullptr),
|
||||
SkImageFilter::MakeMatrixFilter(resizeMatrix, kNone_SkFilterQuality, nullptr),
|
||||
};
|
||||
|
||||
SkRect r = SkRect::MakeWH(64, 64);
|
||||
@ -95,10 +95,6 @@ protected:
|
||||
canvas->restore();
|
||||
canvas->translate(0, r.height());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
|
||||
SkSafeUnref(filters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -18,9 +18,9 @@ DEF_SIMPLE_GM(imageresizetiled, canvas, WIDTH, HEIGHT) {
|
||||
SkPaint paint;
|
||||
SkMatrix matrix;
|
||||
matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR);
|
||||
SkAutoTUnref<SkImageFilter> imageFilter(
|
||||
SkImageFilter::CreateMatrixFilter(matrix, kNone_SkFilterQuality));
|
||||
paint.setImageFilter(imageFilter.get());
|
||||
paint.setImageFilter(SkImageFilter::MakeMatrixFilter(matrix,
|
||||
kNone_SkFilterQuality,
|
||||
nullptr));
|
||||
const SkScalar tile_size = SkIntToScalar(100);
|
||||
SkRect bounds;
|
||||
canvas->getClipBounds(&bounds);
|
||||
|
@ -11,10 +11,8 @@
|
||||
|
||||
static void draw(SkCanvas* canvas, const SkRect& rect, const SkBitmap& bitmap,
|
||||
const SkMatrix& matrix, SkFilterQuality filter) {
|
||||
SkAutoTUnref<SkImageFilter> imageFilter(
|
||||
SkImageFilter::CreateMatrixFilter(matrix, filter));
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(imageFilter.get());
|
||||
paint.setImageFilter(SkImageFilter::MakeMatrixFilter(matrix, filter, nullptr));
|
||||
canvas->saveLayer(&rect, &paint);
|
||||
canvas->drawBitmap(bitmap, 0, 0);
|
||||
canvas->restore();
|
||||
|
@ -39,9 +39,9 @@ protected:
|
||||
canvas->translate(-rect.x(), -rect.y());
|
||||
SkMatrix matrix;
|
||||
matrix.setScale(SkScalarInvert(deviceScaleX), SkScalarInvert(deviceScaleY));
|
||||
sk_sp<SkImageFilter> filter(SkImageFilter::CreateMatrixFilter(matrix,
|
||||
filterQuality,
|
||||
input.get()));
|
||||
sk_sp<SkImageFilter> filter(SkImageFilter::MakeMatrixFilter(matrix,
|
||||
filterQuality,
|
||||
std::move(input)));
|
||||
SkPaint filteredPaint;
|
||||
filteredPaint.setImageFilter(std::move(filter));
|
||||
canvas->saveLayer(&rect, &filteredPaint);
|
||||
|
@ -270,9 +270,17 @@ public:
|
||||
/**
|
||||
* Create an SkMatrixImageFilter, which transforms its input by the given matrix.
|
||||
*/
|
||||
static sk_sp<SkImageFilter> MakeMatrixFilter(const SkMatrix& matrix,
|
||||
SkFilterQuality,
|
||||
sk_sp<SkImageFilter> input);
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* CreateMatrixFilter(const SkMatrix& matrix,
|
||||
SkFilterQuality,
|
||||
SkImageFilter* input = NULL);
|
||||
SkFilterQuality filterQuality,
|
||||
SkImageFilter* input = nullptr) {
|
||||
return MakeMatrixFilter(matrix, filterQuality, sk_ref_sp<SkImageFilter>(input)).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
sk_sp<SkSpecialImage> filterInput(int index,
|
||||
SkSpecialImage* src,
|
||||
|
@ -597,13 +597,11 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
|
||||
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(),
|
||||
(SkFilterQuality)R(4),
|
||||
subFilter.get()));
|
||||
case MATRIX:
|
||||
filter = SkImageFilter::MakeMatrixFilter(make_matrix(),
|
||||
(SkFilterQuality)R(4),
|
||||
make_image_filter());
|
||||
break;
|
||||
}
|
||||
case MATRIX_CONVOLUTION: {
|
||||
SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
|
||||
SkIntToScalar(kBitmapSize)));
|
||||
|
@ -573,10 +573,10 @@ bool SkImageFilter::asFragmentProcessor(GrFragmentProcessor**, GrTexture*,
|
||||
return false;
|
||||
}
|
||||
|
||||
SkImageFilter* SkImageFilter::CreateMatrixFilter(const SkMatrix& matrix,
|
||||
SkFilterQuality filterQuality,
|
||||
SkImageFilter* input) {
|
||||
return SkMatrixImageFilter::Create(matrix, filterQuality, input);
|
||||
sk_sp<SkImageFilter> SkImageFilter::MakeMatrixFilter(const SkMatrix& matrix,
|
||||
SkFilterQuality filterQuality,
|
||||
sk_sp<SkImageFilter> input) {
|
||||
return SkMatrixImageFilter::Make(matrix, filterQuality, std::move(input));
|
||||
}
|
||||
|
||||
sk_sp<SkImageFilter> SkImageFilter::makeWithLocalMatrix(const SkMatrix& matrix) const {
|
||||
|
@ -16,16 +16,18 @@
|
||||
|
||||
SkMatrixImageFilter::SkMatrixImageFilter(const SkMatrix& transform,
|
||||
SkFilterQuality filterQuality,
|
||||
SkImageFilter* input)
|
||||
: INHERITED(1, &input)
|
||||
sk_sp<SkImageFilter> input)
|
||||
: INHERITED(&input, 1, nullptr)
|
||||
, fTransform(transform)
|
||||
, fFilterQuality(filterQuality) {
|
||||
}
|
||||
|
||||
SkMatrixImageFilter* SkMatrixImageFilter::Create(const SkMatrix& transform,
|
||||
SkFilterQuality filterQuality,
|
||||
SkImageFilter* input) {
|
||||
return new SkMatrixImageFilter(transform, filterQuality, input);
|
||||
sk_sp<SkImageFilter> SkMatrixImageFilter::Make(const SkMatrix& transform,
|
||||
SkFilterQuality filterQuality,
|
||||
sk_sp<SkImageFilter> input) {
|
||||
return sk_sp<SkImageFilter>(new SkMatrixImageFilter(transform,
|
||||
filterQuality,
|
||||
std::move(input)));
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkMatrixImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
@ -33,7 +35,7 @@ sk_sp<SkFlattenable> SkMatrixImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
SkMatrix matrix;
|
||||
buffer.readMatrix(&matrix);
|
||||
SkFilterQuality quality = static_cast<SkFilterQuality>(buffer.readInt());
|
||||
return sk_sp<SkImageFilter>(Create(matrix, quality, common.getInput(0).get()));
|
||||
return Make(matrix, quality, common.getInput(0));
|
||||
}
|
||||
|
||||
void SkMatrixImageFilter::flatten(SkWriteBuffer& buffer) const {
|
||||
|
@ -25,19 +25,27 @@ public:
|
||||
* passed to filterImage() is used instead.
|
||||
*/
|
||||
|
||||
static SkMatrixImageFilter* Create(const SkMatrix& transform,
|
||||
SkFilterQuality filterQuality,
|
||||
SkImageFilter* input = nullptr);
|
||||
static sk_sp<SkImageFilter> Make(const SkMatrix& transform,
|
||||
SkFilterQuality filterQuality,
|
||||
sk_sp<SkImageFilter> input);
|
||||
|
||||
SkRect computeFastBounds(const SkRect&) const override;
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMatrixImageFilter)
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(const SkMatrix& transform,
|
||||
SkFilterQuality filterQuality,
|
||||
SkImageFilter* input = nullptr) {
|
||||
return Make(transform, filterQuality, sk_ref_sp<SkImageFilter>(input)).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
SkMatrixImageFilter(const SkMatrix& transform,
|
||||
SkFilterQuality,
|
||||
SkImageFilter* input);
|
||||
sk_sp<SkImageFilter> input);
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
|
||||
|
@ -225,8 +225,8 @@ public:
|
||||
cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100),
|
||||
input.get()));
|
||||
if (!cropRect) {
|
||||
this->addFilter("matrix", SkImageFilter::CreateMatrixFilter(
|
||||
matrix, kLow_SkFilterQuality, input.get()));
|
||||
this->addFilter("matrix",
|
||||
SkImageFilter::MakeMatrixFilter(matrix, kLow_SkFilterQuality, input).release());
|
||||
}
|
||||
|
||||
{
|
||||
@ -801,9 +801,9 @@ static void draw_saveLayer_picture(int width, int height, int tileSize,
|
||||
|
||||
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode));
|
||||
sk_sp<SkImageFilter> cfif(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
|
||||
sk_sp<SkImageFilter> imageFilter(SkImageFilter::CreateMatrixFilter(matrix,
|
||||
kNone_SkFilterQuality,
|
||||
cfif.get()));
|
||||
sk_sp<SkImageFilter> imageFilter(SkImageFilter::MakeMatrixFilter(matrix,
|
||||
kNone_SkFilterQuality,
|
||||
std::move(cfif)));
|
||||
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(std::move(imageFilter));
|
||||
@ -1397,15 +1397,15 @@ DEF_TEST(ImageFilterNestedSaveLayer, reporter) {
|
||||
SkMatrix matrix;
|
||||
matrix.setScale(SkIntToScalar(2), SkIntToScalar(2));
|
||||
matrix.postTranslate(SkIntToScalar(-20), SkIntToScalar(-20));
|
||||
SkAutoTUnref<SkImageFilter> matrixFilter(
|
||||
SkImageFilter::CreateMatrixFilter(matrix, kLow_SkFilterQuality));
|
||||
sk_sp<SkImageFilter> matrixFilter(
|
||||
SkImageFilter::MakeMatrixFilter(matrix, kLow_SkFilterQuality, nullptr));
|
||||
|
||||
// Test that saveLayer() with a filter nested inside another saveLayer() applies the
|
||||
// correct offset to the filter matrix.
|
||||
SkRect bounds1 = SkRect::MakeXYWH(10, 10, 30, 30);
|
||||
canvas.saveLayer(&bounds1, nullptr);
|
||||
SkPaint filterPaint;
|
||||
filterPaint.setImageFilter(matrixFilter);
|
||||
filterPaint.setImageFilter(std::move(matrixFilter));
|
||||
SkRect bounds2 = SkRect::MakeXYWH(20, 20, 10, 10);
|
||||
canvas.saveLayer(&bounds2, &filterPaint);
|
||||
SkPaint greenPaint;
|
||||
|
Loading…
Reference in New Issue
Block a user