blob: 480f09390f27bd5ac999e279793bd960bbcf16a2 [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"
9#include "SkBlurImageFilter.h"
10#include "SkRandom.h"
11
12// TODO deprecate imageblur
13
14#define WIDTH 500
15#define HEIGHT 500
16
17static const float kBlurSigmas[] = {
18 0.0, 0.3f, 0.5f, 2.0f, 32.0f, 80.0f };
19
20const char* kTestStrings[] = {
21 "The quick`~",
22 "brown fox[]",
23 "jumped over",
24 "the lazy@#$",
25 "dog.{}!%^&",
26 "*()+=-\\'\"/",
27};
28
29namespace skiagm {
30
31class BlurImageFilter : public GM {
32public:
33 BlurImageFilter() {
34 this->setBGColor(0xFFFFFFFF);
35 fName.printf("imageblur2");
36 }
37
38protected:
joshualitt5acfea72014-08-11 13:55:34 -070039
mtklein36352bf2015-03-25 18:17:31 -070040 SkString onShortName() override {
joshualitt5acfea72014-08-11 13:55:34 -070041 return fName;
42 }
43
mtklein36352bf2015-03-25 18:17:31 -070044 SkISize onISize() override {
joshualitt5acfea72014-08-11 13:55:34 -070045 return SkISize::Make(WIDTH, HEIGHT);
46 }
47
mtklein36352bf2015-03-25 18:17:31 -070048 void onDraw(SkCanvas* canvas) override {
joshualitt5acfea72014-08-11 13:55:34 -070049 const int sigmaCount = SK_ARRAY_COUNT(kBlurSigmas);
50 const int testStringCount = SK_ARRAY_COUNT(kTestStrings);
51 SkScalar dx = WIDTH / sigmaCount;
52 SkScalar dy = HEIGHT / sigmaCount;
53 const SkScalar textSize = 12;
54
55 for (int x = 0; x < sigmaCount; x++) {
56 SkScalar sigmaX = kBlurSigmas[x];
57 for (int y = 0; y < sigmaCount; y++) {
58 SkScalar sigmaY = kBlurSigmas[y];
59
60 SkPaint paint;
61 paint.setImageFilter(SkBlurImageFilter::Create(sigmaX, sigmaY))->unref();
62 canvas->saveLayer(NULL, &paint);
63
64 SkRandom rand;
65 SkPaint textPaint;
66 textPaint.setAntiAlias(false);
67 textPaint.setColor(rand.nextBits(24) | 0xFF000000);
68 textPaint.setTextSize(textSize);
69
70 for (int i = 0; i < testStringCount; i++) {
71 canvas->drawText(kTestStrings[i],
72 strlen(kTestStrings[i]),
73 SkIntToScalar(x * dx),
74 SkIntToScalar(y * dy + textSize * i + textSize),
75 textPaint);
76 }
77 canvas->restore();
78 }
79 }
80 }
81
82private:
83 SkString fName;
84
85 typedef GM INHERITED;
86};
87
88//////////////////////////////////////////////////////////////////////////////
89
90static GM* MyFactory(void*) { return new BlurImageFilter; }
91static GMRegistry reg(MyFactory);
92
93}