blob: 988fbe2943b761d40ca62788e513a6b79ab5a6bc [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"
9#include "SkBlurMaskFilter.h"
10
11namespace skiagm {
12
13class BlursGM : public GM {
14public:
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000015 BlursGM() {
16 this->setBGColor(0xFFDDDDDD);
17 }
reed@google.comc96e5c22011-02-16 21:50:04 +000018
19protected:
scroggo@google.comb340cf72012-06-29 19:25:21 +000020#ifdef SK_SCALAR_IS_FIXED
scroggo@google.com3ab31752012-06-28 16:09:39 +000021 virtual uint32_t onGetFlags() const SK_OVERRIDE {
scroggo@google.comb340cf72012-06-29 19:25:21 +000022 // SkCanvas::drawCircle, used by this test, performs a quick reject.
23 // The large size given to the device used by SkGPipeCanvas means that
24 // the device clip will not be set properly and circles will be
25 // rejected when in FIXED.
scroggo@google.com3ab31752012-06-28 16:09:39 +000026 return this->INHERITED::onGetFlags() | GM::kSkipPipe_Flag;
27 }
scroggo@google.comb340cf72012-06-29 19:25:21 +000028#endif
scroggo@google.com3ab31752012-06-28 16:09:39 +000029
reed@google.comc96e5c22011-02-16 21:50:04 +000030 virtual SkString onShortName() {
31 return SkString("blurs");
32 }
33
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000034 virtual SkISize onISize() {
reed@google.comc96e5c22011-02-16 21:50:04 +000035 return make_isize(700, 500);
36 }
37
reed@google.comc96e5c22011-02-16 21:50:04 +000038 virtual void onDraw(SkCanvas* canvas) {
reed@google.comc96e5c22011-02-16 21:50:04 +000039 SkBlurMaskFilter::BlurStyle NONE = SkBlurMaskFilter::BlurStyle(-999);
40 static const struct {
41 SkBlurMaskFilter::BlurStyle fStyle;
42 int fCx, fCy;
43 } gRecs[] = {
44 { NONE, 0, 0 },
45 { SkBlurMaskFilter::kInner_BlurStyle, -1, 0 },
46 { SkBlurMaskFilter::kNormal_BlurStyle, 0, 1 },
47 { SkBlurMaskFilter::kSolid_BlurStyle, 0, -1 },
48 { SkBlurMaskFilter::kOuter_BlurStyle, 1, 0 },
49 };
50
51 SkPaint paint;
52 paint.setAntiAlias(true);
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000053 paint.setTextSize(SkIntToScalar(25));
54 canvas->translate(SkIntToScalar(-40), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000055
56 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
57 for (int j = 0; j < 2; j++) {
58 canvas->save();
59 paint.setColor(SK_ColorBLUE);
60 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
61 if (gRecs[i].fStyle != NONE) {
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000062 SkMaskFilter* mf = SkBlurMaskFilter::Create(
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000063 SkIntToScalar(20), gRecs[i].fStyle, flags);
reed@google.comc96e5c22011-02-16 21:50:04 +000064 paint.setMaskFilter(mf)->unref();
65 } else {
66 paint.setMaskFilter(NULL);
67 }
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000068 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100),
69 SkIntToScalar(200 + gRecs[i].fCy*100),
70 SkIntToScalar(50),
71 paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000072 }
73 // draw text
74 {
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000075 SkMaskFilter* mf = SkBlurMaskFilter::Create(
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000076 SkIntToScalar(4),
77 SkBlurMaskFilter::kNormal_BlurStyle,
78 flags);
reed@google.comc96e5c22011-02-16 21:50:04 +000079 paint.setMaskFilter(mf)->unref();
80 SkScalar x = SkIntToScalar(70);
81 SkScalar y = SkIntToScalar(400);
82 paint.setColor(SK_ColorBLACK);
83 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000084 canvas->drawText("Hamburgefons Style", 18,
85 x, y + SkIntToScalar(50), paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000086 paint.setMaskFilter(NULL);
87 paint.setColor(SK_ColorWHITE);
88 x -= SkIntToScalar(2);
89 y -= SkIntToScalar(2);
90 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
91 }
92 canvas->restore();
reed@google.com11a5ff32011-02-18 20:20:51 +000093 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000094 canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000095 }
96 }
97
98private:
99 typedef GM INHERITED;
100};
101
102//////////////////////////////////////////////////////////////////////////////
103
104static GM* MyFactory(void*) { return new BlursGM; }
105static GMRegistry reg(MyFactory);
106
107}