diff options
author | jvanverth <jvanverth@google.com> | 2015-07-21 08:38:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-21 08:38:06 -0700 |
commit | 02781977e00d88a7b0a3bbd6de158a9f3fecfd46 (patch) | |
tree | ff102f9a6f7c18b8ca495bdc5c590442f89ec28b /gm | |
parent | 374b2f7cea8b1117f0dd17cdecd2b3ec85b141d4 (diff) |
Run noise shader separately in imagefiltersclipped
BUG=skia:4079
Review URL: https://codereview.chromium.org/1245983002
Diffstat (limited to 'gm')
-rw-r--r-- | gm/imagefiltersclipped.cpp | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/gm/imagefiltersclipped.cpp b/gm/imagefiltersclipped.cpp index cc636aa276..28f3e0bde9 100644 --- a/gm/imagefiltersclipped.cpp +++ b/gm/imagefiltersclipped.cpp @@ -59,6 +59,25 @@ protected: canvas.drawCircle(x, y, radius, paint); } + 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 onDraw(SkCanvas* canvas) override { if (!fInitialized) { fCheckerboard.allocN32Pixels(64, 64); @@ -91,7 +110,6 @@ protected: SkErodeImageFilter::Create(2, 2, checkerboard.get()), SkOffsetImageFilter::Create(SkIntToScalar(-16), SkIntToScalar(32)), SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality), - SkRectShaderImageFilter::Create(noise), }; SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); @@ -99,33 +117,31 @@ protected: SkRect bounds = r; bounds.outset(margin, margin); + canvas->save(); for (int xOffset = 0; xOffset < 80; xOffset += 16) { canvas->save(); bounds.fLeft = SkIntToScalar(xOffset); for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { - SkPaint paint; - paint.setColor(SK_ColorWHITE); - paint.setImageFilter(filters[i]); - paint.setAntiAlias(true); - canvas->save(); - canvas->clipRect(bounds); - 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(r.centerX(), r.centerY(), r.width() * 2 / 5, paint); - canvas->restore(); + draw_clipped_filter(canvas, filters[i], i, r, bounds); canvas->translate(r.width() + margin, 0); } canvas->restore(); canvas->translate(0, r.height() + margin); } + canvas->restore(); for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { SkSafeUnref(filters[i]); } + + SkImageFilter* rectFilter = SkRectShaderImageFilter::Create(noise); + canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0); + for (int xOffset = 0; xOffset < 80; xOffset += 16) { + bounds.fLeft = SkIntToScalar(xOffset); + draw_clipped_filter(canvas, rectFilter, 0, r, bounds); + canvas->translate(0, r.height() + margin); + } + SkSafeUnref(rectFilter); } private: |