senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 10 | #include "SkBlurImageFilter.h" |
| 11 | #include "SkRandom.h" |
| 12 | |
| 13 | #define WIDTH 640 |
| 14 | #define HEIGHT 480 |
| 15 | |
| 16 | namespace skiagm { |
| 17 | |
| 18 | class ImageBlurTiledGM : public GM { |
| 19 | public: |
| 20 | ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY) |
| 21 | : fSigmaX(sigmaX), fSigmaY(sigmaY) { |
| 22 | } |
| 23 | |
| 24 | protected: |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 25 | SkString onShortName() override { |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 26 | return SkString("imageblurtiled"); |
| 27 | } |
| 28 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 29 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 30 | return SkISize::Make(WIDTH, HEIGHT); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 31 | } |
| 32 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 33 | void onDraw(SkCanvas* canvas) override { |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 34 | SkPaint paint; |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 35 | paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr)); |
| 36 | const SkScalar tileSize = SkIntToScalar(128); |
Mike Reed | 918e144 | 2017-01-23 11:39:45 -0500 | [diff] [blame] | 37 | SkRect bounds = canvas->getLocalClipBounds(); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 38 | for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) { |
| 39 | for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) { |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 40 | canvas->save(); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 41 | canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 42 | canvas->saveLayer(nullptr, &paint); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 43 | const char* str[] = { |
| 44 | "The quick", |
| 45 | "brown fox", |
| 46 | "jumped over", |
| 47 | "the lazy dog.", |
| 48 | }; |
Mike Reed | 1af9b48 | 2019-01-07 11:01:57 -0500 | [diff] [blame] | 49 | SkFont font(sk_tool_utils::create_portable_typeface(), 100); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 50 | int posY = 0; |
| 51 | for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { |
| 52 | posY += 100; |
Mike Reed | 1af9b48 | 2019-01-07 11:01:57 -0500 | [diff] [blame] | 53 | canvas->drawString(str[i], 0, SkIntToScalar(posY), font, SkPaint()); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 54 | } |
| 55 | canvas->restore(); |
| 56 | canvas->restore(); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | private: |
| 62 | SkScalar fSigmaX; |
| 63 | SkScalar fSigmaY; |
| 64 | |
| 65 | typedef GM INHERITED; |
| 66 | }; |
| 67 | |
| 68 | ////////////////////////////////////////////////////////////////////////////// |
| 69 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 70 | DEF_GM(return new ImageBlurTiledGM(3.0f, 3.0f);) |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 71 | |
| 72 | } |