bsalomon@google.com | 0b26c15 | 2012-04-16 14:19:32 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Intel 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 | */ |
| 8 | #include "gm.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 9 | #include "SkBlurDrawLooper.h" |
| 10 | #include "SkBlurMask.h" |
bsalomon@google.com | 0b26c15 | 2012-04-16 14:19:32 +0000 | [diff] [blame] | 11 | #include "SkBlurMaskFilter.h" |
| 12 | #include "SkGradientShader.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 13 | #include "SkMatrix.h" |
| 14 | #include "SkRandom.h" |
| 15 | #include "SkTArray.h" |
bsalomon@google.com | 0b26c15 | 2012-04-16 14:19:32 +0000 | [diff] [blame] | 16 | |
| 17 | namespace skiagm { |
| 18 | |
| 19 | class CircleGM : public GM { |
| 20 | public: |
| 21 | CircleGM() { |
| 22 | this->setBGColor(0xFF000000); |
| 23 | this->makePaints(); |
| 24 | this->makeMatrices(); |
| 25 | } |
| 26 | |
| 27 | protected: |
| 28 | virtual SkString onShortName() SK_OVERRIDE { |
| 29 | return SkString("circles"); |
| 30 | } |
| 31 | |
| 32 | virtual SkISize onISize() SK_OVERRIDE { |
| 33 | return make_isize(1200, 900); |
| 34 | } |
| 35 | |
| 36 | void makePaints() { |
| 37 | { |
| 38 | // no AA |
| 39 | SkPaint p; |
| 40 | fPaints.push_back(p); |
| 41 | } |
| 42 | |
| 43 | { |
| 44 | // AA |
| 45 | SkPaint p; |
| 46 | p.setAntiAlias(true); |
| 47 | fPaints.push_back(p); |
| 48 | } |
| 49 | |
| 50 | { |
| 51 | // AA with mask filter |
| 52 | SkPaint p; |
| 53 | p.setAntiAlias(true); |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 54 | SkMaskFilter* mf = SkBlurMaskFilter::Create( |
bsalomon@google.com | 0b26c15 | 2012-04-16 14:19:32 +0000 | [diff] [blame] | 55 | SkBlurMaskFilter::kNormal_BlurStyle, |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 56 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), |
bsalomon@google.com | 0b26c15 | 2012-04-16 14:19:32 +0000 | [diff] [blame] | 57 | SkBlurMaskFilter::kHighQuality_BlurFlag); |
| 58 | p.setMaskFilter(mf)->unref(); |
| 59 | fPaints.push_back(p); |
| 60 | } |
| 61 | |
| 62 | { |
| 63 | // AA with radial shader |
| 64 | SkPaint p; |
| 65 | p.setAntiAlias(true); |
| 66 | SkPoint center = SkPoint::Make(SkIntToScalar(40), SkIntToScalar(40)); |
| 67 | SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN }; |
| 68 | SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 }; |
| 69 | SkShader* s = SkGradientShader::CreateRadial(center, |
| 70 | SkIntToScalar(20), |
| 71 | colors, |
| 72 | pos, |
| 73 | SK_ARRAY_COUNT(colors), |
| 74 | SkShader::kClamp_TileMode); |
| 75 | p.setShader(s)->unref(); |
| 76 | fPaints.push_back(p); |
| 77 | } |
| 78 | |
| 79 | { |
| 80 | // AA with blur |
| 81 | SkPaint p; |
| 82 | p.setAntiAlias(true); |
| 83 | SkBlurDrawLooper* shadowLooper = |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 84 | new SkBlurDrawLooper (SK_ColorBLUE, |
| 85 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)), |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 86 | SkIntToScalar(5), SkIntToScalar(10), |
bsalomon@google.com | 0b26c15 | 2012-04-16 14:19:32 +0000 | [diff] [blame] | 87 | SkBlurDrawLooper::kIgnoreTransform_BlurFlag | |
| 88 | SkBlurDrawLooper::kOverrideColor_BlurFlag | |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 89 | SkBlurDrawLooper::kHighQuality_BlurFlag); |
bsalomon@google.com | 0b26c15 | 2012-04-16 14:19:32 +0000 | [diff] [blame] | 90 | SkAutoUnref aurL0(shadowLooper); |
| 91 | p.setLooper(shadowLooper); |
| 92 | fPaints.push_back(p); |
| 93 | } |
| 94 | |
| 95 | { |
| 96 | // AA with stroke style |
| 97 | SkPaint p; |
| 98 | p.setAntiAlias(true); |
| 99 | p.setStyle(SkPaint::kStroke_Style); |
| 100 | p.setStrokeWidth(SkIntToScalar(3)); |
| 101 | fPaints.push_back(p); |
| 102 | } |
| 103 | |
| 104 | { |
| 105 | // AA with stroke style, width = 0 |
| 106 | SkPaint p; |
| 107 | p.setAntiAlias(true); |
| 108 | p.setStyle(SkPaint::kStroke_Style); |
| 109 | fPaints.push_back(p); |
| 110 | } |
| 111 | |
| 112 | { |
| 113 | // AA with stroke and fill style |
| 114 | SkPaint p; |
| 115 | p.setAntiAlias(true); |
| 116 | p.setStyle(SkPaint::kStrokeAndFill_Style); |
| 117 | p.setStrokeWidth(SkIntToScalar(2)); |
| 118 | fPaints.push_back(p); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | void makeMatrices() { |
| 123 | { |
| 124 | SkMatrix m; |
| 125 | m.setScale(SkIntToScalar(2), SkIntToScalar(3)); |
| 126 | fMatrices.push_back(m); |
| 127 | } |
| 128 | |
| 129 | { |
| 130 | SkMatrix m; |
| 131 | m.setScale(SkIntToScalar(2), SkIntToScalar(2)); |
| 132 | fMatrices.push_back(m); |
| 133 | } |
| 134 | |
| 135 | { |
| 136 | SkMatrix m; |
| 137 | m.setSkew(SkIntToScalar(2), SkIntToScalar(3)); |
| 138 | fMatrices.push_back(m); |
| 139 | } |
| 140 | |
| 141 | { |
| 142 | SkMatrix m; |
| 143 | m.setSkew(SkIntToScalar(2), SkIntToScalar(2)); |
| 144 | fMatrices.push_back(m); |
| 145 | } |
| 146 | |
| 147 | { |
| 148 | SkMatrix m; |
| 149 | m.setRotate(SkIntToScalar(30)); |
| 150 | fMatrices.push_back(m); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 155 | SkLCGRandom rand; |
bsalomon@google.com | 0b26c15 | 2012-04-16 14:19:32 +0000 | [diff] [blame] | 156 | canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1); |
bsalomon@google.com | 0b26c15 | 2012-04-16 14:19:32 +0000 | [diff] [blame] | 157 | int i; |
| 158 | for (i = 0; i < fPaints.count(); ++i) { |
| 159 | canvas->save(); |
| 160 | // position the path, and make it at off-integer coords. |
| 161 | canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4, |
| 162 | SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4); |
| 163 | SkColor color = rand.nextU(); |
| 164 | color |= 0xff000000; |
| 165 | fPaints[i].setColor(color); |
| 166 | |
| 167 | canvas->drawCircle(SkIntToScalar(40), SkIntToScalar(40), |
| 168 | SkIntToScalar(20), |
| 169 | fPaints[i]); |
| 170 | canvas->restore(); |
| 171 | } |
| 172 | |
| 173 | for (int j = 0; j < fMatrices.count(); ++j, ++i) { |
| 174 | canvas->save(); |
| 175 | |
| 176 | canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4, |
| 177 | SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4); |
| 178 | |
| 179 | canvas->concat(fMatrices[j]); |
| 180 | |
| 181 | SkPaint paint; |
| 182 | paint.setAntiAlias(true); |
| 183 | |
| 184 | SkColor color = rand.nextU(); |
| 185 | color |= 0xff000000; |
| 186 | paint.setColor(color); |
| 187 | |
| 188 | canvas->drawCircle(SkIntToScalar(40), SkIntToScalar(40), |
| 189 | SkIntToScalar(20), |
| 190 | paint); |
| 191 | |
| 192 | canvas->restore(); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | private: |
| 197 | typedef GM INHERITED; |
| 198 | SkTArray<SkPaint> fPaints; |
| 199 | SkTArray<SkMatrix> fMatrices; |
| 200 | }; |
| 201 | |
| 202 | ////////////////////////////////////////////////////////////////////////////// |
| 203 | |
| 204 | static GM* MyFactory(void*) { return new CircleGM; } |
| 205 | static GMRegistry reg(MyFactory); |
| 206 | |
| 207 | } |