blob: f3808d27c9cdedc8a6e0bd7f873332077620ab32 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@google.comc96e5c22011-02-16 21:50:04 +00008#include "gm.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkBlurMask.h"
reed@google.comc96e5c22011-02-16 21:50:04 +000010#include "SkBlurMaskFilter.h"
11
12namespace skiagm {
13
14class BlursGM : public GM {
15public:
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000016 BlursGM() {
17 this->setBGColor(0xFFDDDDDD);
18 }
reed@google.comc96e5c22011-02-16 21:50:04 +000019
20protected:
scroggo@google.comb340cf72012-06-29 19:25:21 +000021#ifdef SK_SCALAR_IS_FIXED
scroggo@google.com3ab31752012-06-28 16:09:39 +000022 virtual uint32_t onGetFlags() const SK_OVERRIDE {
scroggo@google.comb340cf72012-06-29 19:25:21 +000023 // SkCanvas::drawCircle, used by this test, performs a quick reject.
24 // The large size given to the device used by SkGPipeCanvas means that
25 // the device clip will not be set properly and circles will be
26 // rejected when in FIXED.
scroggo@google.com3ab31752012-06-28 16:09:39 +000027 return this->INHERITED::onGetFlags() | GM::kSkipPipe_Flag;
28 }
scroggo@google.comb340cf72012-06-29 19:25:21 +000029#endif
scroggo@google.com3ab31752012-06-28 16:09:39 +000030
reed@google.comc96e5c22011-02-16 21:50:04 +000031 virtual SkString onShortName() {
32 return SkString("blurs");
33 }
34
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000035 virtual SkISize onISize() {
reed@google.comc96e5c22011-02-16 21:50:04 +000036 return make_isize(700, 500);
37 }
38
reed@google.comc96e5c22011-02-16 21:50:04 +000039 virtual void onDraw(SkCanvas* canvas) {
reed@google.comc96e5c22011-02-16 21:50:04 +000040 SkBlurMaskFilter::BlurStyle NONE = SkBlurMaskFilter::BlurStyle(-999);
41 static const struct {
42 SkBlurMaskFilter::BlurStyle fStyle;
43 int fCx, fCy;
44 } gRecs[] = {
45 { NONE, 0, 0 },
46 { SkBlurMaskFilter::kInner_BlurStyle, -1, 0 },
47 { SkBlurMaskFilter::kNormal_BlurStyle, 0, 1 },
48 { SkBlurMaskFilter::kSolid_BlurStyle, 0, -1 },
49 { SkBlurMaskFilter::kOuter_BlurStyle, 1, 0 },
50 };
51
52 SkPaint paint;
53 paint.setAntiAlias(true);
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000054 paint.setTextSize(SkIntToScalar(25));
55 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000056
57 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
58 for (int j = 0; j < 2; j++) {
59 canvas->save();
60 paint.setColor(SK_ColorBLUE);
61 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
62 if (gRecs[i].fStyle != NONE) {
robertphillips@google.comb7061172013-09-06 14:16:12 +000063 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle,
64 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(20)),
65 flags);
reed@google.comc96e5c22011-02-16 21:50:04 +000066 paint.setMaskFilter(mf)->unref();
67 } else {
68 paint.setMaskFilter(NULL);
69 }
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000070 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
71 SkIntToScalar(200 + gRecs[i].fCy*100),
72 SkIntToScalar(50),
73 paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000074 }
75 // draw text
76 {
robertphillips@google.comb7061172013-09-06 14:16:12 +000077 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_BlurStyle,
78 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)),
79 flags);
reed@google.comc96e5c22011-02-16 21:50:04 +000080 paint.setMaskFilter(mf)->unref();
81 SkScalar x = SkIntToScalar(70);
82 SkScalar y = SkIntToScalar(400);
83 paint.setColor(SK_ColorBLACK);
84 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000085 canvas->drawText("Hamburgefons Style", 18,
86 x, y + SkIntToScalar(50), paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000087 paint.setMaskFilter(NULL);
88 paint.setColor(SK_ColorWHITE);
89 x -= SkIntToScalar(2);
90 y -= SkIntToScalar(2);
91 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
92 }
93 canvas->restore();
reed@google.com11a5ff32011-02-18 20:20:51 +000094 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000095 canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000096 }
97 }
98
99private:
100 typedef GM INHERITED;
101};
102
103//////////////////////////////////////////////////////////////////////////////
104
105static GM* MyFactory(void*) { return new BlursGM; }
106static GMRegistry reg(MyFactory);
107
108}