senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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/SkColor.h" |
| 11 | #include "include/core/SkFont.h" |
| 12 | #include "include/core/SkImageFilter.h" |
| 13 | #include "include/core/SkPaint.h" |
| 14 | #include "include/core/SkScalar.h" |
| 15 | #include "include/core/SkTypeface.h" |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 16 | #include "include/effects/SkImageFilters.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "include/utils/SkRandom.h" |
| 18 | #include "tools/ToolUtils.h" |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 19 | |
senorblanco@chromium.org | 54e01b2 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 20 | #define WIDTH 500 |
| 21 | #define HEIGHT 500 |
| 22 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 23 | void imageblurgm_draw(SkScalar fSigmaX, SkScalar fSigmaY, SkCanvas* canvas) { |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 24 | SkPaint paint; |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 25 | paint.setImageFilter(SkImageFilters::Blur(fSigmaX, fSigmaY, nullptr)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 26 | canvas->saveLayer(nullptr, &paint); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 27 | const char* str = "The quick brown fox jumped over the lazy dog."; |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 28 | |
| 29 | SkRandom rand; |
senorblanco@chromium.org | 1e95d71 | 2012-07-18 19:52:53 +0000 | [diff] [blame] | 30 | SkPaint textPaint; |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 31 | SkFont font(ToolUtils::create_portable_typeface()); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 32 | for (int i = 0; i < 25; ++i) { |
mtklein@google.com | cfa7ba7 | 2013-09-16 18:19:30 +0000 | [diff] [blame] | 33 | int x = rand.nextULessThan(WIDTH); |
| 34 | int y = rand.nextULessThan(HEIGHT); |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 35 | textPaint.setColor(ToolUtils::color_to_565(rand.nextBits(24) | 0xFF000000)); |
Mike Reed | 1af9b48 | 2019-01-07 11:01:57 -0500 | [diff] [blame] | 36 | font.setSize(rand.nextRangeScalar(0, 300)); |
| 37 | canvas->drawString(str, SkIntToScalar(x), SkIntToScalar(y), font, textPaint); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 38 | } |
| 39 | canvas->restore(); |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 40 | } |
| 41 | DEF_SIMPLE_GM_BG(imageblur, canvas, WIDTH, HEIGHT, SK_ColorBLACK) { |
| 42 | imageblurgm_draw(24.0f, 0.0f, canvas); |
| 43 | } |
| 44 | DEF_SIMPLE_GM_BG(imageblur_large, canvas, WIDTH, HEIGHT, SK_ColorBLACK) { |
| 45 | imageblurgm_draw(80.0f, 80.0f, canvas); |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 46 | } |