blob: b6f9ff50261457b670f9bc0346cad01925492c77 [file] [log] [blame]
joshualitt5acfea72014-08-11 13:55:34 -07001/*
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 Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
joshualitt5acfea72014-08-11 13:55:34 -070010#include "SkBlurImageFilter.h"
11#include "SkRandom.h"
12
13// TODO deprecate imageblur
14
15#define WIDTH 500
16#define HEIGHT 500
17
mtkleindbfd7ab2016-09-01 11:24:54 -070018constexpr float kBlurSigmas[] = {
joshualitt5acfea72014-08-11 13:55:34 -070019 0.0, 0.3f, 0.5f, 2.0f, 32.0f, 80.0f };
20
21const char* kTestStrings[] = {
22 "The quick`~",
23 "brown fox[]",
24 "jumped over",
25 "the lazy@#$",
26 "dog.{}!%^&",
27 "*()+=-\\'\"/",
28};
29
30namespace skiagm {
31
32class BlurImageFilter : public GM {
33public:
34 BlurImageFilter() {
35 this->setBGColor(0xFFFFFFFF);
36 fName.printf("imageblur2");
37 }
38
39protected:
joshualitt5acfea72014-08-11 13:55:34 -070040
mtklein36352bf2015-03-25 18:17:31 -070041 SkString onShortName() override {
joshualitt5acfea72014-08-11 13:55:34 -070042 return fName;
43 }
44
mtklein36352bf2015-03-25 18:17:31 -070045 SkISize onISize() override {
joshualitt5acfea72014-08-11 13:55:34 -070046 return SkISize::Make(WIDTH, HEIGHT);
47 }
48
mtklein36352bf2015-03-25 18:17:31 -070049 void onDraw(SkCanvas* canvas) override {
joshualitt5acfea72014-08-11 13:55:34 -070050 const int sigmaCount = SK_ARRAY_COUNT(kBlurSigmas);
51 const int testStringCount = SK_ARRAY_COUNT(kTestStrings);
52 SkScalar dx = WIDTH / sigmaCount;
53 SkScalar dy = HEIGHT / sigmaCount;
54 const SkScalar textSize = 12;
55
56 for (int x = 0; x < sigmaCount; x++) {
57 SkScalar sigmaX = kBlurSigmas[x];
58 for (int y = 0; y < sigmaCount; y++) {
59 SkScalar sigmaY = kBlurSigmas[y];
60
61 SkPaint paint;
robertphillips6e7025a2016-04-04 04:31:25 -070062 paint.setImageFilter(SkBlurImageFilter::Make(sigmaX, sigmaY, nullptr));
halcanary96fcdcc2015-08-27 07:41:13 -070063 canvas->saveLayer(nullptr, &paint);
joshualitt5acfea72014-08-11 13:55:34 -070064
65 SkRandom rand;
66 SkPaint textPaint;
67 textPaint.setAntiAlias(false);
caryclarkf597c422015-07-28 10:37:53 -070068 textPaint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
69 sk_tool_utils::set_portable_typeface(&textPaint);
joshualitt5acfea72014-08-11 13:55:34 -070070 textPaint.setTextSize(textSize);
71
72 for (int i = 0; i < testStringCount; i++) {
Cary Clark2a475ea2017-04-28 15:35:12 -040073 canvas->drawString(kTestStrings[i],
74 SkIntToScalar(x * dx),
75 SkIntToScalar(y * dy + textSize * i + textSize),
76 textPaint);
joshualitt5acfea72014-08-11 13:55:34 -070077 }
78 canvas->restore();
79 }
80 }
81 }
82
83private:
84 SkString fName;
85
86 typedef GM INHERITED;
87};
88
89//////////////////////////////////////////////////////////////////////////////
90
robertphillips6e7025a2016-04-04 04:31:25 -070091DEF_GM(return new BlurImageFilter;)
joshualitt5acfea72014-08-11 13:55:34 -070092
93}