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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkFont.h" |
| 11 | #include "include/core/SkImageFilter.h" |
| 12 | #include "include/core/SkPaint.h" |
| 13 | #include "include/core/SkRect.h" |
| 14 | #include "include/core/SkScalar.h" |
| 15 | #include "include/core/SkSize.h" |
| 16 | #include "include/core/SkString.h" |
| 17 | #include "include/core/SkTypeface.h" |
| 18 | #include "include/core/SkTypes.h" |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 19 | #include "include/effects/SkImageFilters.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "tools/ToolUtils.h" |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 21 | |
| 22 | #define WIDTH 640 |
| 23 | #define HEIGHT 480 |
| 24 | |
| 25 | namespace skiagm { |
| 26 | |
| 27 | class ImageBlurTiledGM : public GM { |
| 28 | public: |
| 29 | ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY) |
| 30 | : fSigmaX(sigmaX), fSigmaY(sigmaY) { |
| 31 | } |
| 32 | |
| 33 | protected: |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 34 | SkString onShortName() override { |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 35 | return SkString("imageblurtiled"); |
| 36 | } |
| 37 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 38 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 39 | return SkISize::Make(WIDTH, HEIGHT); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 40 | } |
| 41 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 42 | void onDraw(SkCanvas* canvas) override { |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 43 | SkPaint paint; |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 44 | paint.setImageFilter(SkImageFilters::Blur(fSigmaX, fSigmaY, nullptr)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 45 | const SkScalar tileSize = SkIntToScalar(128); |
Mike Reed | 918e144 | 2017-01-23 11:39:45 -0500 | [diff] [blame] | 46 | SkRect bounds = canvas->getLocalClipBounds(); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 47 | for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) { |
| 48 | for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) { |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 49 | canvas->save(); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 50 | canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 51 | canvas->saveLayer(nullptr, &paint); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 52 | const char* str[] = { |
| 53 | "The quick", |
| 54 | "brown fox", |
| 55 | "jumped over", |
| 56 | "the lazy dog.", |
| 57 | }; |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 58 | SkFont font(ToolUtils::create_portable_typeface(), 100); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 59 | int posY = 0; |
| 60 | for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { |
| 61 | posY += 100; |
Mike Reed | 1af9b48 | 2019-01-07 11:01:57 -0500 | [diff] [blame] | 62 | canvas->drawString(str[i], 0, SkIntToScalar(posY), font, SkPaint()); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 63 | } |
| 64 | canvas->restore(); |
| 65 | canvas->restore(); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | private: |
| 71 | SkScalar fSigmaX; |
| 72 | SkScalar fSigmaY; |
| 73 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 74 | using INHERITED = GM; |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | ////////////////////////////////////////////////////////////////////////////// |
| 78 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 79 | DEF_GM(return new ImageBlurTiledGM(3.0f, 3.0f);) |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 80 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 81 | } // namespace skiagm |