• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
9 #include "sk_tool_utils.h"
10 #include "SkBlurImageFilter.h"
11 #include "SkRandom.h"
12 
13 // TODO deprecate imageblur
14 
15 constexpr int kWidth  = 500;
16 constexpr int kHeight = 500;
17 
DEF_SIMPLE_GM(imageblur2,canvas,kWidth,kHeight)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[] = {
21         "The quick`~",
22         "brown fox[]",
23         "jumped over",
24         "the lazy@#$",
25         "dog.{}!%^&",
26         "*()+=-\\'\"/",
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;
33 
34     SkFont font(sk_tool_utils::create_portable_typeface(), textSize);
35     font.setEdging(SkFont::Edging::kAlias);
36 
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];
41 
42             SkPaint paint;
43             paint.setImageFilter(SkBlurImageFilter::Make(sigmaX, sigmaY, nullptr));
44             canvas->saveLayer(nullptr, &paint);
45 
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);
55             }
56             canvas->restore();
57         }
58     }
59 }
60