joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [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 | |
| 8 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 10 | #include "SkBlurImageFilter.h" |
| 11 | #include "SkRandom.h" |
| 12 | |
| 13 | // TODO deprecate imageblur |
| 14 | |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame^] | 15 | constexpr int kWidth = 500; |
| 16 | constexpr int kHeight = 500; |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 17 | |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame^] | 18 | DEF_SIMPLE_GM(imageblur2, canvas, kWidth, kHeight) { |
| 19 | constexpr float kBlurSigmas[] = { 0.0, 0.3f, 0.5f, 2.0f, 32.0f, 80.0f }; |
| 20 | const char* kTestStrings[] = { |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 21 | "The quick`~", |
| 22 | "brown fox[]", |
| 23 | "jumped over", |
| 24 | "the lazy@#$", |
| 25 | "dog.{}!%^&", |
| 26 | "*()+=-\\'\"/", |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame^] | 27 | }; |
| 28 | constexpr int sigmaCount = SK_ARRAY_COUNT(kBlurSigmas); |
| 29 | constexpr int testStringCount = SK_ARRAY_COUNT(kTestStrings); |
| 30 | constexpr SkScalar dx = kWidth / sigmaCount; |
| 31 | constexpr SkScalar dy = kHeight / sigmaCount; |
| 32 | constexpr SkScalar textSize = 12; |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 33 | |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame^] | 34 | SkFont font(sk_tool_utils::create_portable_typeface(), textSize); |
| 35 | font.setEdging(SkFont::Edging::kAlias); |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 36 | |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame^] | 37 | for (int x = 0; x < sigmaCount; x++) { |
| 38 | SkScalar sigmaX = kBlurSigmas[x]; |
| 39 | for (int y = 0; y < sigmaCount; y++) { |
| 40 | SkScalar sigmaY = kBlurSigmas[y]; |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 41 | |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame^] | 42 | SkPaint paint; |
| 43 | paint.setImageFilter(SkBlurImageFilter::Make(sigmaX, sigmaY, nullptr)); |
| 44 | canvas->saveLayer(nullptr, &paint); |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 45 | |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame^] | 46 | SkRandom rand; |
| 47 | SkPaint textPaint; |
| 48 | textPaint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000)); |
| 49 | for (int i = 0; i < testStringCount; i++) { |
| 50 | canvas->drawString(kTestStrings[i], |
| 51 | SkIntToScalar(x * dx), |
| 52 | SkIntToScalar(y * dy + textSize * i + textSize), |
| 53 | font, |
| 54 | textPaint); |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 55 | } |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame^] | 56 | canvas->restore(); |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
joshualitt | 5acfea7 | 2014-08-11 13:55:34 -0700 | [diff] [blame] | 59 | } |