blob: aafd01e5b58c31ebaef83a7594202bbd0dd7bb38 [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:
mtklein72c9faa2015-01-09 10:06:39 -080039 uint32_t onGetFlags() const SK_OVERRIDE {
joshualitt5acfea72014-08-11 13:55:34 -070040 return kSkipTiled_Flag;
41 }
42
mtklein72c9faa2015-01-09 10:06:39 -080043 SkString onShortName() SK_OVERRIDE {
joshualitt5acfea72014-08-11 13:55:34 -070044 return fName;
45 }
46
mtklein72c9faa2015-01-09 10:06:39 -080047 SkISize onISize() SK_OVERRIDE {
joshualitt5acfea72014-08-11 13:55:34 -070048 return SkISize::Make(WIDTH, HEIGHT);
49 }
50
mtklein72c9faa2015-01-09 10:06:39 -080051 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
joshualitt5acfea72014-08-11 13:55:34 -070052 const int sigmaCount = SK_ARRAY_COUNT(kBlurSigmas);
53 const int testStringCount = SK_ARRAY_COUNT(kTestStrings);
54 SkScalar dx = WIDTH / sigmaCount;
55 SkScalar dy = HEIGHT / sigmaCount;
56 const SkScalar textSize = 12;
57
58 for (int x = 0; x < sigmaCount; x++) {
59 SkScalar sigmaX = kBlurSigmas[x];
60 for (int y = 0; y < sigmaCount; y++) {
61 SkScalar sigmaY = kBlurSigmas[y];
62
63 SkPaint paint;
64 paint.setImageFilter(SkBlurImageFilter::Create(sigmaX, sigmaY))->unref();
65 canvas->saveLayer(NULL, &paint);
66
67 SkRandom rand;
68 SkPaint textPaint;
69 textPaint.setAntiAlias(false);
70 textPaint.setColor(rand.nextBits(24) | 0xFF000000);
71 textPaint.setTextSize(textSize);
72
73 for (int i = 0; i < testStringCount; i++) {
74 canvas->drawText(kTestStrings[i],
75 strlen(kTestStrings[i]),
76 SkIntToScalar(x * dx),
77 SkIntToScalar(y * dy + textSize * i + textSize),
78 textPaint);
79 }
80 canvas->restore();
81 }
82 }
83 }
84
85private:
86 SkString fName;
87
88 typedef GM INHERITED;
89};
90
91//////////////////////////////////////////////////////////////////////////////
92
93static GM* MyFactory(void*) { return new BlurImageFilter; }
94static GMRegistry reg(MyFactory);
95
96}