OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 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 "SkTArray.h" |
| 10 #include "SkMatrix.h" |
| 11 #include "SkBlurMaskFilter.h" |
| 12 #include "SkGradientShader.h" |
| 13 #include "SkBlurDrawLooper.h" |
| 14 |
| 15 namespace skiagm { |
| 16 |
| 17 class RectsGM : public GM { |
| 18 public: |
| 19 RectsGM() { |
| 20 this->setBGColor(0xFF000000); |
| 21 this->makePaints(); |
| 22 this->makeMatrices(); |
| 23 this->makeRects(); |
| 24 } |
| 25 |
| 26 protected: |
| 27 virtual SkString onShortName() SK_OVERRIDE { |
| 28 return SkString("rects"); |
| 29 } |
| 30 |
| 31 virtual SkISize onISize() SK_OVERRIDE { |
| 32 return make_isize(1200, 900); |
| 33 } |
| 34 |
| 35 void makePaints() { |
| 36 { |
| 37 // no AA |
| 38 SkPaint p; |
| 39 p.setColor(SK_ColorWHITE); |
| 40 fPaints.push_back(p); |
| 41 } |
| 42 |
| 43 { |
| 44 // AA |
| 45 SkPaint p; |
| 46 p.setColor(SK_ColorWHITE); |
| 47 p.setAntiAlias(true); |
| 48 fPaints.push_back(p); |
| 49 } |
| 50 |
| 51 { |
| 52 // AA with mask filter |
| 53 SkPaint p; |
| 54 p.setColor(SK_ColorWHITE); |
| 55 p.setAntiAlias(true); |
| 56 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkIntToScalar(5), |
| 57 SkBlurMaskFilter::kNormal_BlurStyle, |
| 58 SkBlurMaskFilter::kHighQuality_BlurFlag); |
| 59 p.setMaskFilter(mf)->unref(); |
| 60 fPaints.push_back(p); |
| 61 } |
| 62 |
| 63 { |
| 64 // AA with radial shader |
| 65 SkPaint p; |
| 66 p.setColor(SK_ColorWHITE); |
| 67 p.setAntiAlias(true); |
| 68 SkPoint center = SkPoint::Make(SkIntToScalar(-5), SkIntToScalar(30))
; |
| 69 SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN }; |
| 70 SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 }; |
| 71 SkShader* s = SkGradientShader::CreateRadial(center, |
| 72 SkIntToScalar(20), |
| 73 colors, |
| 74 pos, |
| 75 SK_ARRAY_COUNT(colors), |
| 76 SkShader::kClamp_TileMo
de); |
| 77 p.setShader(s)->unref(); |
| 78 fPaints.push_back(p); |
| 79 } |
| 80 |
| 81 { |
| 82 // AA with blur |
| 83 SkPaint p; |
| 84 p.setColor(SK_ColorWHITE); |
| 85 p.setAntiAlias(true); |
| 86 SkBlurDrawLooper* shadowLooper = |
| 87 new SkBlurDrawLooper (SkIntToScalar(10), SkIntToScalar(5), |
| 88 SkIntToScalar(10), SK_ColorWHITE, |
| 89 SkBlurDrawLooper::kIgnoreTransform_BlurFla
g | |
| 90 SkBlurDrawLooper::kOverrideColor_BlurFlag
| |
| 91 SkBlurDrawLooper::kHighQuality_BlurFlag ); |
| 92 SkAutoUnref aurL0(shadowLooper); |
| 93 p.setLooper(shadowLooper); |
| 94 fPaints.push_back(p); |
| 95 } |
| 96 |
| 97 { |
| 98 // AA with stroke style |
| 99 SkPaint p; |
| 100 p.setColor(SK_ColorWHITE); |
| 101 p.setAntiAlias(true); |
| 102 p.setStyle(SkPaint::kStroke_Style); |
| 103 p.setStrokeWidth(SkIntToScalar(3)); |
| 104 fPaints.push_back(p); |
| 105 } |
| 106 |
| 107 { |
| 108 // AA with stroke style, width = 0 |
| 109 SkPaint p; |
| 110 p.setColor(SK_ColorWHITE); |
| 111 p.setAntiAlias(true); |
| 112 p.setStyle(SkPaint::kStroke_Style); |
| 113 fPaints.push_back(p); |
| 114 } |
| 115 |
| 116 { |
| 117 // AA with stroke and fill style |
| 118 SkPaint p; |
| 119 p.setColor(SK_ColorWHITE); |
| 120 p.setAntiAlias(true); |
| 121 p.setStyle(SkPaint::kStrokeAndFill_Style); |
| 122 p.setStrokeWidth(SkIntToScalar(2)); |
| 123 fPaints.push_back(p); |
| 124 } |
| 125 } |
| 126 |
| 127 void makeMatrices() { |
| 128 { |
| 129 // 1x1.5 scale |
| 130 SkMatrix m; |
| 131 m.setScale(1, 1.5); |
| 132 fMatrices.push_back(m); |
| 133 } |
| 134 |
| 135 { |
| 136 // 1.5x1.5 scale |
| 137 SkMatrix m; |
| 138 m.setScale(1.5, 1.5); |
| 139 fMatrices.push_back(m); |
| 140 } |
| 141 |
| 142 { |
| 143 // 1x1.5 skew |
| 144 SkMatrix m; |
| 145 m.setSkew(1, 1.5); |
| 146 fMatrices.push_back(m); |
| 147 } |
| 148 |
| 149 { |
| 150 // 1.5x1.5 skew |
| 151 SkMatrix m; |
| 152 m.setSkew(1.5, 1.5); |
| 153 fMatrices.push_back(m); |
| 154 } |
| 155 |
| 156 { |
| 157 // 30 degree rotation |
| 158 SkMatrix m; |
| 159 m.setRotate(SkIntToScalar(30)); |
| 160 fMatrices.push_back(m); |
| 161 } |
| 162 } |
| 163 |
| 164 void makeRects() { |
| 165 { |
| 166 // small square |
| 167 SkRect r = SkRect::MakeLTRB(0, 0, 30, 30); |
| 168 fRects.push_back(r); |
| 169 } |
| 170 |
| 171 { |
| 172 // thin vertical |
| 173 SkRect r = SkRect::MakeLTRB(0, 0, 2, 40); |
| 174 fRects.push_back(r); |
| 175 } |
| 176 |
| 177 { |
| 178 // thin horizontal |
| 179 SkRect r = SkRect::MakeLTRB(0, 0, 40, 2); |
| 180 fRects.push_back(r); |
| 181 } |
| 182 |
| 183 { |
| 184 // very thin |
| 185 SkRect r = SkRect::MakeLTRB(0, 0, 0.25f, 10); |
| 186 fRects.push_back(r); |
| 187 } |
| 188 |
| 189 { |
| 190 // zaftig |
| 191 SkRect r = SkRect::MakeLTRB(0, 0, 60, 60); |
| 192 fRects.push_back(r); |
| 193 } |
| 194 } |
| 195 |
| 196 // position the current test on the canvas |
| 197 static void position(SkCanvas* canvas, int testCount) { |
| 198 canvas->translate(SK_Scalar1 * 100 * (testCount % 10) + SK_Scalar1 / 4, |
| 199 SK_Scalar1 * 100 * (testCount / 10) + 3 * SK_Scalar1 /
4); |
| 200 } |
| 201 |
| 202 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 203 canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1); |
| 204 |
| 205 int testCount = 0; |
| 206 |
| 207 for (int i = 0; i < fPaints.count(); ++i) { |
| 208 for (int j = 0; j < fRects.count(); ++j, ++testCount) { |
| 209 canvas->save(); |
| 210 this->position(canvas, testCount); |
| 211 canvas->drawRect(fRects[j], fPaints[i]); |
| 212 canvas->restore(); |
| 213 } |
| 214 } |
| 215 |
| 216 SkPaint paint; |
| 217 paint.setColor(SK_ColorWHITE); |
| 218 paint.setAntiAlias(true); |
| 219 |
| 220 for (int i = 0; i < fMatrices.count(); ++i) { |
| 221 for (int j = 0; j < fRects.count(); ++j, ++testCount) { |
| 222 canvas->save(); |
| 223 this->position(canvas, testCount); |
| 224 canvas->concat(fMatrices[i]); |
| 225 canvas->drawRect(fRects[j], paint); |
| 226 canvas->restore(); |
| 227 } |
| 228 } |
| 229 } |
| 230 |
| 231 private: |
| 232 SkTArray<SkPaint> fPaints; |
| 233 SkTArray<SkMatrix> fMatrices; |
| 234 SkTArray<SkRect> fRects; |
| 235 |
| 236 typedef GM INHERITED; |
| 237 }; |
| 238 |
| 239 ////////////////////////////////////////////////////////////////////////////// |
| 240 |
| 241 static GM* MyFactory(void*) { return new RectsGM; } |
| 242 static GMRegistry reg(MyFactory); |
| 243 |
| 244 } |
OLD | NEW |