diff options
author | robertphillips <robertphillips@google.com> | 2016-04-01 09:28:51 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-01 09:28:51 -0700 |
commit | 549c8991959333e5c0f53faebcbbd5d6bc8f6a56 (patch) | |
tree | db498c61ef16f570f8c43b5c7bf462529134704a /gm | |
parent | f27002947d40ab884e13d39ee2ef0ac4ccadcd6a (diff) |
Update SkImageSource to sk_sp
TBR=reed@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1842243002
Review URL: https://codereview.chromium.org/1842243002
Diffstat (limited to 'gm')
-rw-r--r-- | gm/bigtileimagefilter.cpp | 29 | ||||
-rw-r--r-- | gm/displacement.cpp | 60 | ||||
-rw-r--r-- | gm/filterfastbounds.cpp | 4 | ||||
-rw-r--r-- | gm/imagefiltersclipped.cpp | 85 | ||||
-rw-r--r-- | gm/imagefilterscropexpand.cpp | 3 | ||||
-rw-r--r-- | gm/imagefiltersgraph.cpp | 2 | ||||
-rw-r--r-- | gm/imagefiltersscaled.cpp | 4 | ||||
-rw-r--r-- | gm/imagefilterstransformed.cpp | 4 | ||||
-rw-r--r-- | gm/imagesource.cpp | 62 | ||||
-rw-r--r-- | gm/imagesource2.cpp | 12 | ||||
-rw-r--r-- | gm/offsetimagefilter.cpp | 6 | ||||
-rw-r--r-- | gm/resizeimagefilter.cpp | 73 | ||||
-rw-r--r-- | gm/tileimagefilter.cpp | 9 | ||||
-rw-r--r-- | gm/xfermodeimagefilter.cpp | 7 |
14 files changed, 183 insertions, 177 deletions
diff --git a/gm/bigtileimagefilter.cpp b/gm/bigtileimagefilter.cpp index 7d3d3afeed..5c12f94ea0 100644 --- a/gm/bigtileimagefilter.cpp +++ b/gm/bigtileimagefilter.cpp @@ -54,13 +54,15 @@ protected: { SkPaint p; - SkRect bound = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)); - sk_sp<SkImageFilter> imageSource(SkImageSource::Create(fRedImage.get())); - SkAutoTUnref<SkImageFilter> tif(SkTileImageFilter::Create( - SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)), - SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)), - imageSource.get())); - p.setImageFilter(tif); + const SkRect bound = SkRect::MakeIWH(kWidth, kHeight); + sk_sp<SkImageFilter> imageSource(SkImageSource::Make(fRedImage)); + + sk_sp<SkImageFilter> tif(SkTileImageFilter::Create( + SkRect::MakeIWH(kBitmapSize, kBitmapSize), + SkRect::MakeIWH(kWidth, kHeight), + imageSource.get())); + + p.setImageFilter(std::move(tif)); canvas->saveLayer(&bound, &p); canvas->restore(); @@ -69,13 +71,14 @@ protected: { SkPaint p2; - SkRect bound2 = SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)); + const SkRect bound2 = SkRect::MakeIWH(kBitmapSize, kBitmapSize); + + sk_sp<SkImageFilter> tif(SkTileImageFilter::Create( + SkRect::MakeIWH(kBitmapSize, kBitmapSize), + SkRect::MakeIWH(kBitmapSize, kBitmapSize), + nullptr)); - SkAutoTUnref<SkImageFilter> tif2(SkTileImageFilter::Create( - SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)), - SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)), - nullptr)); - p2.setImageFilter(tif2); + p2.setImageFilter(std::move(tif)); canvas->translate(320, 320); canvas->saveLayer(&bound2, &p2); diff --git a/gm/displacement.cpp b/gm/displacement.cpp index a3fb9e5e5b..9b62a60ab3 100644 --- a/gm/displacement.cpp +++ b/gm/displacement.cpp @@ -57,133 +57,133 @@ protected: void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); SkPaint paint; - SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard.get())); + sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unref(); + SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 0, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unref(); + SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 100, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unref(); + SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 200, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ))->unref(); + SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 300, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ))->unref(); + SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 400, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ))->unref(); + SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 0, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); + SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 100, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ))->unref(); + SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 200, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); + SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 300, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); + SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 400, 100, paint); SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(30, 30, 40, 40)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, - 0.0f, displ, nullptr, &cropRect))->unref(); + 0.0f, displ.get(), nullptr, &cropRect))->unref(); drawClippedBitmap(canvas, 0, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 16.0f, displ, nullptr, &cropRect))->unref(); + 16.0f, displ.get(), nullptr, &cropRect))->unref(); drawClippedBitmap(canvas, 100, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, - 32.0f, displ, nullptr, &cropRect))->unref(); + 32.0f, displ.get(), nullptr, &cropRect))->unref(); drawClippedBitmap(canvas, 200, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 48.0f, displ, nullptr, &cropRect))->unref(); + 48.0f, displ.get(), nullptr, &cropRect))->unref(); drawClippedBitmap(canvas, 300, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 64.0f, displ, nullptr, &cropRect))->unref(); + 64.0f, displ.get(), nullptr, &cropRect))->unref(); drawClippedBitmap(canvas, 400, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, - 40.0f, displ, nullptr, &cropRect))->unref(); + 40.0f, displ.get(), nullptr, &cropRect))->unref(); drawClippedBitmap(canvas, 0, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, displ, nullptr, &cropRect))->unref(); + 40.0f, displ.get(), nullptr, &cropRect))->unref(); drawClippedBitmap(canvas, 100, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, - 40.0f, displ, nullptr, &cropRect))->unref(); + 40.0f, displ.get(), nullptr, &cropRect))->unref(); drawClippedBitmap(canvas, 200, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, displ, nullptr, &cropRect))->unref(); + 40.0f, displ.get(), nullptr, &cropRect))->unref(); drawClippedBitmap(canvas, 300, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, displ, nullptr, &cropRect))->unref(); + 40.0f, displ.get(), nullptr, &cropRect))->unref(); drawClippedBitmap(canvas, 400, 300, paint); // Test for negative scale. paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - -40.0f, displ))->unref(); + -40.0f, displ.get()))->unref(); this->drawClippedBitmap(canvas, 500, 0, paint); // Tests for images of different sizes - displ.reset(SkImageSource::Create(fSmall.get())); + displ = SkImageSource::Make(fSmall); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, - 40.0f, displ))->unref(); + 40.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 0, 400, paint); - displ.reset(SkImageSource::Create(fLarge.get())); + displ = SkImageSource::Make(fLarge); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, displ))->unref(); + 40.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 100, 400, paint); - displ.reset(SkImageSource::Create(fLargeW.get())); + displ = SkImageSource::Make(fLargeW); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, - 40.0f, displ))->unref(); + 40.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 200, 400, paint); - displ.reset(SkImageSource::Create(fLargeH.get())); + displ = SkImageSource::Make(fLargeH); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, displ))->unref(); + 40.0f, displ.get()))->unref(); drawClippedBitmap(canvas, 300, 400, paint); // Test for no given displacement input. In this case, both displacement diff --git a/gm/filterfastbounds.cpp b/gm/filterfastbounds.cpp index 8bc186e48d..9d07095855 100644 --- a/gm/filterfastbounds.cpp +++ b/gm/filterfastbounds.cpp @@ -277,10 +277,10 @@ protected: } sk_sp<SkImage> image(surface->makeImageSnapshot()); - SkAutoTUnref<SkImageFilter> imageSource(SkImageSource::Create(image.get())); + sk_sp<SkImageFilter> imageSource(SkImageSource::Make(std::move(image))); SkTArray<SkPaint> bmsPaints; - create_paints(imageSource, &bmsPaints); + create_paints(imageSource.get(), &bmsPaints); //----------- SkASSERT(paints.count() == kNumVertTiles); diff --git a/gm/imagefiltersclipped.cpp b/gm/imagefiltersclipped.cpp index a0c74db10e..31f8ad2787 100644 --- a/gm/imagefiltersclipped.cpp +++ b/gm/imagefiltersclipped.cpp @@ -26,6 +26,41 @@ #define RESIZE_FACTOR_X SkIntToScalar(2) #define RESIZE_FACTOR_Y SkIntToScalar(5) +static sk_sp<SkImage> make_gradient_circle(int width, int height) { + SkScalar x = SkIntToScalar(width / 2); + SkScalar y = SkIntToScalar(height / 2); + SkScalar radius = SkMinScalar(x, y) * 0.8f; + auto surface(SkSurface::MakeRasterN32Premul(width, height)); + SkCanvas* canvas = surface->getCanvas(); + canvas->clear(0x00000000); + SkColor colors[2]; + colors[0] = SK_ColorWHITE; + colors[1] = SK_ColorBLACK; + SkPaint paint; + paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr, + 2, SkShader::kClamp_TileMode)); + canvas->drawCircle(x, y, radius, paint); + return surface->makeImageSnapshot(); +} + +static void draw_clipped_filter(SkCanvas* canvas, SkImageFilter* filter, size_t i, + const SkRect& primBounds, const SkRect& clipBounds) { + SkPaint paint; + paint.setColor(SK_ColorWHITE); + paint.setImageFilter(filter); + paint.setAntiAlias(true); + canvas->save(); + canvas->clipRect(clipBounds); + if (5 == i) { + canvas->translate(SkIntToScalar(16), SkIntToScalar(-32)); + } else if (6 == i) { + canvas->scale(SkScalarInvert(RESIZE_FACTOR_X), SkScalarInvert(RESIZE_FACTOR_Y)); + } + canvas->drawCircle(primBounds.centerX(), primBounds.centerY(), + primBounds.width() * 2 / 5, paint); + canvas->restore(); +} + namespace skiagm { class ImageFiltersClippedGM : public GM { @@ -43,55 +78,17 @@ protected: return SkISize::Make(860, 500); } - void makeGradientCircle(int width, int height) { - SkScalar x = SkIntToScalar(width / 2); - SkScalar y = SkIntToScalar(height / 2); - SkScalar radius = SkMinScalar(x, y) * 0.8f; - auto surface(SkSurface::MakeRasterN32Premul(width, height)); - SkCanvas* canvas = surface->getCanvas(); - canvas->clear(0x00000000); - SkColor colors[2]; - colors[0] = SK_ColorWHITE; - colors[1] = SK_ColorBLACK; - SkPaint paint; - paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr, - 2, SkShader::kClamp_TileMode)); - canvas->drawCircle(x, y, radius, paint); - fGradientCircle = surface->makeImageSnapshot(); - } - - static void draw_clipped_filter(SkCanvas* canvas, SkImageFilter* filter, size_t i, - const SkRect& primBounds, const SkRect& clipBounds) { - SkPaint paint; - paint.setColor(SK_ColorWHITE); - paint.setImageFilter(filter); - paint.setAntiAlias(true); - canvas->save(); - canvas->clipRect(clipBounds); - if (5 == i) { - canvas->translate(SkIntToScalar(16), SkIntToScalar(-32)); - } else if (6 == i) { - canvas->scale(SkScalarInvert(RESIZE_FACTOR_X), - SkScalarInvert(RESIZE_FACTOR_Y)); - } - canvas->drawCircle(primBounds.centerX(), primBounds.centerY(), - primBounds.width() * 2 / 5, paint); - canvas->restore(); - } - void onOnceBeforeDraw() override { fCheckerboard = SkImage::MakeFromBitmap (sk_tool_utils::create_checkerboard_bitmap(64, 64, 0xFFA0A0A0, 0xFF404040, 8)); - this->makeGradientCircle(64, 64); + fGradientCircle = make_gradient_circle(64, 64); } void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); - SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCircle.get())); - SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerboard.get())); - sk_sp<SkShader> noise(SkPerlinNoiseShader::MakeFractalNoise( - SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); + sk_sp<SkImageFilter> gradient(SkImageSource::Make(fGradientCircle)); + sk_sp<SkImageFilter> checkerboard(SkImageSource::Make(fCheckerboard)); SkMatrix resizeMatrix; resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y); SkPoint3 pointLocation = SkPoint3::Make(32, 32, SkIntToScalar(10)); @@ -112,7 +109,8 @@ protected: SkIntToScalar(32), nullptr).release(), SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality), - SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1, SkIntToScalar(2), checkerboard.get()), + SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1, + SkIntToScalar(2), checkerboard.get()), }; @@ -139,7 +137,8 @@ protected: } SkPaint noisePaint; - noisePaint.setShader(noise); + noisePaint.setShader(SkPerlinNoiseShader::MakeFractalNoise(0.1f, 0.05f, 1, 0)); + sk_sp<SkImageFilter> rectFilter(SkPaintImageFilter::Make(noisePaint)); canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0); for (int xOffset = 0; xOffset < 80; xOffset += 16) { diff --git a/gm/imagefilterscropexpand.cpp b/gm/imagefilterscropexpand.cpp index 6b2484e1a8..82df81cbdb 100644 --- a/gm/imagefilterscropexpand.cpp +++ b/gm/imagefilterscropexpand.cpp @@ -48,8 +48,7 @@ protected: SkBitmap checkerboard; MakeCheckerboard(&checkerboard); - SkAutoTUnref<SkImageFilter> gradientCircleSource( - SkImageSource::Create(gradientCircle.get())); + sk_sp<SkImageFilter> gradientCircleSource(SkImageSource::Make(std::move(gradientCircle))); sk_sp<SkImageFilter> noopCropped(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect)); SkScalar sk255 = SkIntToScalar(255); SkScalar matrix[20] = { 1, 0, 0, 0, 0, diff --git a/gm/imagefiltersgraph.cpp b/gm/imagefiltersgraph.cpp index e7abdcfc0f..537287124a 100644 --- a/gm/imagefiltersgraph.cpp +++ b/gm/imagefiltersgraph.cpp @@ -118,7 +118,7 @@ protected: void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); { - sk_sp<SkImageFilter> bitmapSource(SkImageSource::Create(fImage.get())); + sk_sp<SkImageFilter> bitmapSource(SkImageSource::Make(fImage)); sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode)); sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0f, bitmapSource.get())); diff --git a/gm/imagefiltersscaled.cpp b/gm/imagefiltersscaled.cpp index d9f38bb443..61eb4690ba 100644 --- a/gm/imagefiltersscaled.cpp +++ b/gm/imagefiltersscaled.cpp @@ -52,8 +52,8 @@ protected: void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); - SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCircle.get())); - SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerboard.get())); + sk_sp<SkImageFilter> gradient(SkImageSource::Make(fGradientCircle)); + sk_sp<SkImageFilter> checkerboard(SkImageSource::Make(fCheckerboard)); sk_sp<SkShader> noise(SkPerlinNoiseShader::MakeFractalNoise( SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); SkPaint noisePaint; diff --git a/gm/imagefilterstransformed.cpp b/gm/imagefilterstransformed.cpp index e9a6a5da6d..a9b1863ace 100644 --- a/gm/imagefilterstransformed.cpp +++ b/gm/imagefilterstransformed.cpp @@ -63,8 +63,8 @@ protected: } void onDraw(SkCanvas* canvas) override { - SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCircle.get())); - SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerboard.get())); + sk_sp<SkImageFilter> gradient(SkImageSource::Make(fGradientCircle)); + sk_sp<SkImageFilter> checkerboard(SkImageSource::Make(fCheckerboard)); SkImageFilter* filters[] = { SkBlurImageFilter::Create(12, 0), SkDropShadowImageFilter::Create(0, 15, 8, 0, SK_ColorGREEN, diff --git a/gm/imagesource.cpp b/gm/imagesource.cpp index 973dc0c6ea..ed7aba1c98 100644 --- a/gm/imagesource.cpp +++ b/gm/imagesource.cpp @@ -12,6 +12,17 @@ // This GM exercises the SkImageSource ImageFilter class. +static void fill_rect_filtered(SkCanvas* canvas, + const SkRect& clipRect, + sk_sp<SkImageFilter> filter) { + SkPaint paint; + paint.setImageFilter(std::move(filter)); + canvas->save(); + canvas->clipRect(clipRect); + canvas->drawPaint(paint); + canvas->restore(); +} + class ImageSourceGM : public skiagm::GM { public: ImageSourceGM() { } @@ -28,44 +39,39 @@ protected: fImage = SkImage::MakeFromBitmap(bm); } - static void FillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkImageFilter* filter) { - SkPaint paint; - paint.setImageFilter(filter); - canvas->save(); - canvas->clipRect(clipRect); - canvas->drawPaint(paint); - canvas->restore(); - } - void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); - { - SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); - SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60); - SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100); - SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height()); - SkAutoTUnref<SkImageFilter> imageSource(SkImageSource::Create(fImage.get())); - SkAutoTUnref<SkImageFilter> imageSourceSrcRect( - SkImageSource::Create(fImage.get(), srcRect, srcRect, kHigh_SkFilterQuality)); - SkAutoTUnref<SkImageFilter> imageSourceSrcRectDstRect( - SkImageSource::Create(fImage.get(), srcRect, dstRect, kHigh_SkFilterQuality)); - SkAutoTUnref<SkImageFilter> imageSourceDstRectOnly( - SkImageSource::Create(fImage.get(), bounds, dstRect, kHigh_SkFilterQuality)); + const SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); + const SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60); + const SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100); + const SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height()); + + { // Draw an unscaled bitmap. - FillRectFiltered(canvas, clipRect, imageSource); + sk_sp<SkImageFilter> imageSource(SkImageSource::Make(fImage)); + fill_rect_filtered(canvas, clipRect, std::move(imageSource)); canvas->translate(SkIntToScalar(100), 0); - + } + { // Draw an unscaled subset of the source bitmap (srcRect -> srcRect). - FillRectFiltered(canvas, clipRect, imageSourceSrcRect); + sk_sp<SkImageFilter> imageSourceSrcRect( + SkImageSource::Make(fImage, srcRect, srcRect, kHigh_SkFilterQuality)); + fill_rect_filtered(canvas, clipRect, std::move(imageSourceSrcRect)); canvas->translate(SkIntToScalar(100), 0); - + } + { // Draw a subset of the bitmap scaled to a destination rect (srcRect -> dstRect). - FillRectFiltered(canvas, clipRect, imageSourceSrcRectDstRect); + sk_sp<SkImageFilter> imageSourceSrcRectDstRect( + SkImageSource::Make(fImage, srcRect, dstRect, kHigh_SkFilterQuality)); + fill_rect_filtered(canvas, clipRect, std::move(imageSourceSrcRectDstRect)); canvas->translate(SkIntToScalar(100), 0); - + } + { // Draw the entire bitmap scaled to a destination rect (bounds -> dstRect). - FillRectFiltered(canvas, clipRect, imageSourceDstRectOnly); + sk_sp<SkImageFilter> imageSourceDstRectOnly( + SkImageSource::Make(fImage, bounds, dstRect, kHigh_SkFilterQuality)); + fill_rect_filtered(canvas, clipRect, std::move(imageSourceDstRectOnly)); canvas->translate(SkIntToScalar(100), 0); } } diff --git a/gm/imagesource2.cpp b/gm/imagesource2.cpp index 3a3d27360d..ba6af46cfb 100644 --- a/gm/imagesource2.cpp +++ b/gm/imagesource2.cpp @@ -60,15 +60,13 @@ protected: } void onDraw(SkCanvas* canvas) override { - SkRect srcRect = SkRect::MakeLTRB(0, 0, - SkIntToScalar(kImageSize), SkIntToScalar(kImageSize)); - SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f); - - SkAutoTUnref<SkImageFilter> filter( - SkImageSource::Create(fImage.get(), srcRect, dstRect, fFilter)); + const SkRect srcRect = SkRect::MakeLTRB(0, 0, + SkIntToScalar(kImageSize), + SkIntToScalar(kImageSize)); + const SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f); SkPaint p; - p.setImageFilter(filter); + p.setImageFilter(SkImageSource::Make(fImage, srcRect, dstRect, fFilter)); canvas->saveLayer(nullptr, &p); canvas->restore(); diff --git a/gm/offsetimagefilter.cpp b/gm/offsetimagefilter.cpp index 51a93f86f1..8f23483212 100644 --- a/gm/offsetimagefilter.cpp +++ b/gm/offsetimagefilter.cpp @@ -47,17 +47,17 @@ protected: SkPaint paint; for (int i = 0; i < 4; i++) { - SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get(); + sk_sp<SkImage> image = (i & 0x01) ? fCheckerboard : fBitmap; SkIRect cropRect = SkIRect::MakeXYWH(i * 12, i * 8, image->width() - i * 8, image->height() - i * 12); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); - sk_sp<SkImageFilter> tileInput(SkImageSource::Create(image)); + sk_sp<SkImageFilter> tileInput(SkImageSource::Make(image)); SkScalar dx = SkIntToScalar(i*5); SkScalar dy = SkIntToScalar(i*10); paint.setImageFilter(SkOffsetImageFilter::Make(dx, dy, std::move(tileInput), &rect)); - DrawClippedImage(canvas, image, paint, 1, cropRect); + DrawClippedImage(canvas, image.get(), paint, 1, cropRect); canvas->translate(SkIntToScalar(image->width() + MARGIN), 0); } diff --git a/gm/resizeimagefilter.cpp b/gm/resizeimagefilter.cpp index b8ed100548..28508fdb33 100644 --- a/gm/resizeimagefilter.cpp +++ b/gm/resizeimagefilter.cpp @@ -20,7 +20,7 @@ public: } protected: - virtual SkString onShortName() { + SkString onShortName() override { return SkString("resizeimagefilter"); } @@ -28,7 +28,7 @@ protected: const SkRect& rect, const SkSize& deviceSize, SkFilterQuality filterQuality, - SkImageFilter* input = nullptr) { + sk_sp<SkImageFilter> input) { SkRect dstRect; canvas->getTotalMatrix().mapRect(&dstRect, rect); canvas->save(); @@ -38,12 +38,12 @@ protected: canvas->scale(deviceScaleX, deviceScaleY); canvas->translate(-rect.x(), -rect.y()); SkMatrix matrix; - matrix.setScale(SkScalarInvert(deviceScaleX), - SkScalarInvert(deviceScaleY)); - SkAutoTUnref<SkImageFilter> imageFilter( - SkImageFilter::CreateMatrixFilter(matrix, filterQuality, input)); + matrix.setScale(SkScalarInvert(deviceScaleX), SkScalarInvert(deviceScaleY)); + sk_sp<SkImageFilter> filter(SkImageFilter::CreateMatrixFilter(matrix, + filterQuality, + input.get())); SkPaint filteredPaint; - filteredPaint.setImageFilter(imageFilter.get()); + filteredPaint.setImageFilter(std::move(filter)); canvas->saveLayer(&rect, &filteredPaint); SkPaint paint; paint.setColor(0xFF00FF00); @@ -54,40 +54,44 @@ protected: canvas->restore(); } - virtual SkISize onISize() { + SkISize onISize() override { return SkISize::Make(520, 100); } - virtual void onDraw(SkCanvas* canvas) { + void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); SkRect srcRect = SkRect::MakeWH(96, 96); SkSize deviceSize = SkSize::Make(16, 16); - draw(canvas, - srcRect, - deviceSize, - kNone_SkFilterQuality); + this->draw(canvas, + srcRect, + deviceSize, + kNone_SkFilterQuality, + nullptr); canvas->translate(srcRect.width() + SkIntToScalar(10), 0); - draw(canvas, - srcRect, - deviceSize, - kLow_SkFilterQuality); + this->draw(canvas, + srcRect, + deviceSize, + kLow_SkFilterQuality, + nullptr); canvas->translate(srcRect.width() + SkIntToScalar(10), 0); - draw(canvas, - srcRect, - deviceSize, - kMedium_SkFilterQuality); + this->draw(canvas, + srcRect, + deviceSize, + kMedium_SkFilterQuality, + nullptr); canvas->translate(srcRect.width() + SkIntToScalar(10), 0); - draw(canvas, - srcRect, - deviceSize, - kHigh_SkFilterQuality); + this->draw(canvas, + srcRect, + deviceSize, + kHigh_SkFilterQuality, + nullptr); - auto surface(SkSurface::MakeRasterN32Premul(16, 16)); + sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(16, 16)); SkCanvas* surfaceCanvas = surface->getCanvas(); surfaceCanvas->clear(0x000000); { @@ -100,14 +104,14 @@ protected: sk_sp<SkImage> image(surface->makeImageSnapshot()); SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20); SkRect outRect = SkRect::MakeXYWH(-24, -24, 120, 120); - SkAutoTUnref<SkImageFilter> source( - SkImageSource::Create(image.get(), inRect, outRect, kHigh_SkFilterQuality)); + sk_sp<SkImageFilter> source( + SkImageSource::Make(std::move(image), inRect, outRect, kHigh_SkFilterQuality)); canvas->translate(srcRect.width() + SkIntToScalar(10), 0); - draw(canvas, - srcRect, - deviceSize, - kHigh_SkFilterQuality, - source.get()); + this->draw(canvas, + srcRect, + deviceSize, + kHigh_SkFilterQuality, + std::move(source)); } private: @@ -116,7 +120,6 @@ private: ////////////////////////////////////////////////////////////////////////////// -static GM* MyFactory(void*) { return new ResizeGM; } -static GMRegistry reg(MyFactory); +DEF_GM(return new ResizeGM; ) } diff --git a/gm/tileimagefilter.cpp b/gm/tileimagefilter.cpp index e067d3ee04..c0cca3c895 100644 --- a/gm/tileimagefilter.cpp +++ b/gm/tileimagefilter.cpp @@ -56,7 +56,7 @@ protected: int x = 0, y = 0; for (size_t i = 0; i < 4; i++) { - SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get(); + sk_sp<SkImage> image = (i & 0x01) ? fCheckerboard : fBitmap; SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(image->width()/4), SkIntToScalar(image->height()/4), SkIntToScalar(image->width()/(i+1)), @@ -65,13 +65,12 @@ protected: SkIntToScalar(i * 4), SkIntToScalar(image->width() - i * 12), SkIntToScalar(image->height()) - i * 12); - SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image)); - SkAutoTUnref<SkImageFilter> filter( - SkTileImageFilter::Create(srcRect, dstRect, tileInput)); + sk_sp<SkImageFilter> tileInput(SkImageSource::Make(image)); + sk_sp<SkImageFilter> filter(SkTileImageFilter::Create(srcRect, dstRect, tileInput.get())); canvas->save(); canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); SkPaint paint; - paint.setImageFilter(filter); + paint.setImageFilter(std::move(filter)); canvas->drawImage(fBitmap.get(), 0, 0, &paint); canvas->drawRect(srcRect, red); canvas->drawRect(dstRect, blue); diff --git a/gm/xfermodeimagefilter.cpp b/gm/xfermodeimagefilter.cpp index dc8cbede21..3293c81ba4 100644 --- a/gm/xfermodeimagefilter.cpp +++ b/gm/xfermodeimagefilter.cpp @@ -85,7 +85,7 @@ protected: }; int x = 0, y = 0; - sk_sp<SkImageFilter> background(SkImageSource::Create(fCheckerboard.get())); + sk_sp<SkImageFilter> background(SkImageSource::Make(fCheckerboard)); for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(gModes[i].fMode), background.get())); @@ -98,8 +98,7 @@ protected: } // Test arithmetic mode as image filter paint.setImageFilter(SkXfermodeImageFilter::Make( - SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0), - background.get())); + 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) { @@ -118,7 +117,7 @@ protected: SkIntToScalar(fBitmap.height() + 4)); // Test offsets on SrcMode (uses fixed-function blend) sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap)); - sk_sp<SkImageFilter> foreground(SkImageSource::Create(bitmapImage.get())); + sk_sp<SkImageFilter> foreground(SkImageSource::Make(std::move(bitmapImage))); sk_sp<SkImageFilter> offsetForeground(SkOffsetImageFilter::Make(SkIntToScalar(4), SkIntToScalar(-4), foreground)); |