Index: gm/imagefilterscropexpand.cpp |
diff --git a/gm/imagefilterscropexpand.cpp b/gm/imagefilterscropexpand.cpp |
index cfbf13a759fb53d0fc506ed1d121a1d1ed83f1c8..2e452ee577cb9bac935f001e19d262e91f602eb8 100644 |
--- a/gm/imagefilterscropexpand.cpp |
+++ b/gm/imagefilterscropexpand.cpp |
@@ -11,16 +11,17 @@ |
#include "SkColorPriv.h" |
#include "SkShader.h" |
-#include "SkBitmapSource.h" |
#include "SkBlurImageFilter.h" |
#include "SkColorMatrixFilter.h" |
#include "SkDisplacementMapEffect.h" |
#include "SkDropShadowImageFilter.h" |
#include "SkGradientShader.h" |
+#include "SkImageSource.h" |
#include "SkMorphologyImageFilter.h" |
#include "SkColorFilterImageFilter.h" |
#include "SkMergeImageFilter.h" |
#include "SkOffsetImageFilter.h" |
+#include "SkSurface.h" |
/////////////////////////////////////////////////////////////////////////////// |
@@ -30,13 +31,84 @@ public: |
protected: |
- virtual SkString onShortName() { |
+ SkString onShortName() override { |
return SkString("imagefilterscropexpand"); |
} |
- virtual SkISize onISize() { return SkISize::Make(570, 650); } |
+ SkISize onISize() override { return SkISize::Make(570, 650); } |
- void make_checkerboard(SkBitmap* bitmap) { |
+ void onDraw(SkCanvas* canvas) override { |
+ SkAutoTUnref<SkColorFilter> cf( |
+ SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); |
+ SkImageFilter::CropRect cropRect( |
+ SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), |
+ SkImageFilter::CropRect::kHasAll_CropEdge); |
+ |
+ SkAutoTUnref<SkImage> gradientCircle(MakeGradientCircle(64, 64)); |
+ SkBitmap checkerboard; |
+ MakeCheckerboard(&checkerboard); |
+ |
+ SkAutoTUnref<SkImageFilter> gradientCircleSource( |
+ SkImageSource::Create(gradientCircle)); |
+ SkAutoTUnref<SkImageFilter> noopCropped( |
+ SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect)); |
+ SkScalar sk255 = SkIntToScalar(255); |
+ SkScalar matrix[20] = { 1, 0, 0, 0, 0, |
+ 0, 1, 0, 0, sk255, |
+ 0, 0, 1, 0, 0, |
+ 0, 0, 0, 0, sk255 }; |
+ SkAutoTUnref<SkColorFilter> cfAlphaTrans(SkColorMatrixFilter::Create(matrix)); |
+ |
+ SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
+ SkScalar MARGIN = SkIntToScalar(12); |
+ |
+ SkIRect bounds; |
+ r.roundOut(&bounds); |
+ |
+ SkPaint paint; |
+ canvas->translate(MARGIN, MARGIN); |
+ for (int outset = -15; outset <= 20; outset += 5) { |
+ canvas->save(); |
+ SkRect rect = cropRect.rect(); |
+ rect.outset(SkIntToScalar(outset), |
+ SkIntToScalar(outset)); |
+ SkImageFilter::CropRect big_rect(rect, SkImageFilter::CropRect::kHasAll_CropEdge); |
+ |
+ Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Create( |
+ cfAlphaTrans, noopCropped.get(), &big_rect)); |
+ |
+ Draw(canvas, checkerboard, rect, SkBlurImageFilter::Create( |
+ 8.0f, 8.0f, noopCropped.get(), &big_rect)); |
+ |
+ Draw(canvas, checkerboard, rect, SkDilateImageFilter::Create( |
+ 2, 2, noopCropped.get(), &big_rect)); |
+ |
+ Draw(canvas, checkerboard, rect, SkErodeImageFilter::Create( |
+ 2, 2, noopCropped.get(), &big_rect)); |
+ |
+ Draw(canvas, checkerboard, rect, SkDropShadowImageFilter::Create( |
+ SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(3), SkIntToScalar(3), |
+ SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
+ noopCropped.get(), &big_rect)); |
+ |
+ Draw(canvas, checkerboard, rect, SkDisplacementMapEffect::Create( |
+ SkDisplacementMapEffect::kR_ChannelSelectorType, |
+ SkDisplacementMapEffect::kR_ChannelSelectorType, |
+ SkIntToScalar(12), |
+ gradientCircleSource.get(), |
+ noopCropped.get(), |
+ &big_rect)); |
+ |
+ Draw(canvas, checkerboard, rect, SkOffsetImageFilter::Create( |
+ SkIntToScalar(-8), SkIntToScalar(16), noopCropped.get(), &big_rect)); |
+ |
+ canvas->restore(); |
+ canvas->translate(0, SkIntToScalar(80)); |
+ } |
+ } |
+ |
+private: |
+ static void MakeCheckerboard(SkBitmap* bitmap) { |
bitmap->allocN32Pixels(64, 64); |
SkCanvas canvas(*bitmap); |
canvas.clear(0xFFFF0000); |
@@ -57,13 +129,13 @@ protected: |
} |
} |
- void make_gradient_circle(int width, int height, SkBitmap* bitmap) { |
+ static SkImage* MakeGradientCircle(int width, int height) { |
SkScalar x = SkIntToScalar(width / 2); |
SkScalar y = SkIntToScalar(height / 2); |
SkScalar radius = SkMinScalar(x, y) * 0.8f; |
- bitmap->allocN32Pixels(width, height); |
- SkCanvas canvas(*bitmap); |
- canvas.clear(0x00000000); |
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, height)); |
+ SkCanvas* canvas = surface->getCanvas(); |
+ canvas->clear(0x00000000); |
SkColor colors[2]; |
colors[0] = SK_ColorWHITE; |
colors[1] = SK_ColorBLACK; |
@@ -73,10 +145,12 @@ protected: |
); |
SkPaint paint; |
paint.setShader(shader); |
- canvas.drawCircle(x, y, radius, paint); |
+ canvas->drawCircle(x, y, radius, paint); |
+ |
+ return surface->newImageSnapshot(); |
} |
- static void draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rect, SkImageFilter* filter) { |
+ static void Draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rect, SkImageFilter* filter) { |
SkPaint paint; |
paint.setImageFilter(filter)->unref(); |
canvas->saveLayer(&rect, &paint); |
@@ -91,77 +165,6 @@ protected: |
canvas->translate(SkIntToScalar(80), 0); |
} |
- virtual void onDraw(SkCanvas* canvas) { |
- SkAutoTUnref<SkColorFilter> cf( |
- SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); |
- SkImageFilter::CropRect crop_rect( |
- SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), |
- SkImageFilter::CropRect::kHasAll_CropEdge); |
- |
- SkBitmap gradient_circle, checkerboard; |
- make_gradient_circle(64, 64, &gradient_circle); |
- make_checkerboard(&checkerboard); |
- |
- SkAutoTUnref<SkImageFilter> gradient_circle_source( |
- SkBitmapSource::Create(gradient_circle)); |
- SkAutoTUnref<SkImageFilter> noop_cropped( |
- SkOffsetImageFilter::Create(0, 0, nullptr, &crop_rect)); |
- SkScalar sk255 = SkIntToScalar(255); |
- SkScalar matrix[20] = { 1, 0, 0, 0, 0, |
- 0, 1, 0, 0, sk255, |
- 0, 0, 1, 0, 0, |
- 0, 0, 0, 0, sk255 }; |
- SkAutoTUnref<SkColorFilter> cf_alpha_trans(SkColorMatrixFilter::Create(matrix)); |
- |
- SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
- SkScalar MARGIN = SkIntToScalar(12); |
- |
- SkIRect bounds; |
- r.roundOut(&bounds); |
- |
- SkPaint paint; |
- canvas->translate(MARGIN, MARGIN); |
- for (int outset = -15; outset <= 20; outset += 5) { |
- canvas->save(); |
- SkRect rect = crop_rect.rect(); |
- rect.outset(SkIntToScalar(outset), |
- SkIntToScalar(outset)); |
- SkImageFilter::CropRect big_rect(rect, SkImageFilter::CropRect::kHasAll_CropEdge); |
- |
- draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Create( |
- cf_alpha_trans, noop_cropped.get(), &big_rect)); |
- |
- draw(canvas, checkerboard, rect, SkBlurImageFilter::Create( |
- 8.0f, 8.0f, noop_cropped.get(), &big_rect)); |
- |
- draw(canvas, checkerboard, rect, SkDilateImageFilter::Create( |
- 2, 2, noop_cropped.get(), &big_rect)); |
- |
- draw(canvas, checkerboard, rect, SkErodeImageFilter::Create( |
- 2, 2, noop_cropped.get(), &big_rect)); |
- |
- draw(canvas, checkerboard, rect, SkDropShadowImageFilter::Create( |
- SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(3), SkIntToScalar(3), |
- SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
- noop_cropped.get(), &big_rect)); |
- |
- draw(canvas, checkerboard, rect, SkDisplacementMapEffect::Create( |
- SkDisplacementMapEffect::kR_ChannelSelectorType, |
- SkDisplacementMapEffect::kR_ChannelSelectorType, |
- SkIntToScalar(12), |
- gradient_circle_source.get(), |
- noop_cropped.get(), |
- &big_rect)); |
- |
- draw(canvas, checkerboard, rect, SkOffsetImageFilter::Create( |
- SkIntToScalar(-8), SkIntToScalar(16), noop_cropped.get(), &big_rect)); |
- |
- canvas->restore(); |
- canvas->translate(0, SkIntToScalar(80)); |
- } |
- } |
- |
-private: |
typedef GM INHERITED; |
}; |