blob: bb688b9c1bf447ad826f52249444b1e9a68c6f37 [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(
63 SkIntToScalar(20), gRecs[i].fStyle, flags
64 );
reed@google.comc96e5c22011-02-16 21:50:04 +000065 paint.setMaskFilter(mf)->unref();
66 } else {
67 paint.setMaskFilter(NULL);
68 }
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000069 canvas->drawCircle(SkIntToScalar(200 + gRecs[i].fCx*100)
70 , SkIntToScalar(200 + gRecs[i].fCy*100)
71 , SkIntToScalar(50)
72 , paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000073 }
74 // draw text
75 {
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000076 SkMaskFilter* mf = SkBlurMaskFilter::Create(
77 SkIntToScalar(4)
78 , SkBlurMaskFilter::kNormal_BlurStyle
79 , flags
80 );
reed@google.comc96e5c22011-02-16 21:50:04 +000081 paint.setMaskFilter(mf)->unref();
82 SkScalar x = SkIntToScalar(70);
83 SkScalar y = SkIntToScalar(400);
84 paint.setColor(SK_ColorBLACK);
85 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000086 canvas->drawText("Hamburgefons Style", 18
87 , x, y + SkIntToScalar(50), paint);
reed@google.comc96e5c22011-02-16 21:50:04 +000088 paint.setMaskFilter(NULL);
89 paint.setColor(SK_ColorWHITE);
90 x -= SkIntToScalar(2);
91 y -= SkIntToScalar(2);
92 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
93 }
94 canvas->restore();
reed@google.com11a5ff32011-02-18 20:20:51 +000095 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000096 canvas->translate(SkIntToScalar(350), SkIntToScalar(0));
reed@google.comc96e5c22011-02-16 21:50:04 +000097 }
98 }
99
100private:
101 typedef GM INHERITED;
102};
103
104//////////////////////////////////////////////////////////////////////////////
105
106static GM* MyFactory(void*) { return new BlursGM; }
107static GMRegistry reg(MyFactory);
108
109}
110