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" |
| 9 | #include "SkBlurImageFilter.h" |
| 10 | #include "SkRandom.h" |
| 11 | |
| 12 | #define WIDTH 640 |
| 13 | #define HEIGHT 480 |
| 14 | |
| 15 | namespace skiagm { |
| 16 | |
| 17 | class ImageBlurTiledGM : public GM { |
| 18 | public: |
| 19 | ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY) |
| 20 | : fSigmaX(sigmaX), fSigmaY(sigmaY) { |
| 21 | } |
| 22 | |
| 23 | protected: |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 24 | SkString onShortName() override { |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 25 | return SkString("imageblurtiled"); |
| 26 | } |
| 27 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 28 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 29 | return SkISize::Make(WIDTH, HEIGHT); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 30 | } |
| 31 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 32 | void onDraw(SkCanvas* canvas) override { |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 33 | SkPaint paint; |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 34 | paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr)); |
| 35 | const SkScalar tileSize = SkIntToScalar(128); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 36 | SkRect bounds; |
reed@google.com | 76b12b7 | 2014-04-10 21:15:30 +0000 | [diff] [blame] | 37 | if (!canvas->getClipBounds(&bounds)) { |
| 38 | bounds.setEmpty(); |
| 39 | } |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 40 | for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) { |
| 41 | for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) { |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 42 | canvas->save(); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 43 | canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 44 | canvas->saveLayer(nullptr, &paint); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 45 | const char* str[] = { |
| 46 | "The quick", |
| 47 | "brown fox", |
| 48 | "jumped over", |
| 49 | "the lazy dog.", |
| 50 | }; |
| 51 | SkPaint textPaint; |
| 52 | textPaint.setAntiAlias(true); |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 53 | sk_tool_utils::set_portable_typeface(&textPaint); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 54 | textPaint.setTextSize(SkIntToScalar(100)); |
| 55 | int posY = 0; |
| 56 | for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { |
| 57 | posY += 100; |
| 58 | canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0), |
| 59 | SkIntToScalar(posY), textPaint); |
| 60 | } |
| 61 | canvas->restore(); |
| 62 | canvas->restore(); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | private: |
| 68 | SkScalar fSigmaX; |
| 69 | SkScalar fSigmaY; |
| 70 | |
| 71 | typedef GM INHERITED; |
| 72 | }; |
| 73 | |
| 74 | ////////////////////////////////////////////////////////////////////////////// |
| 75 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 76 | DEF_GM(return new ImageBlurTiledGM(3.0f, 3.0f);) |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 77 | |
| 78 | } |