Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 | |
| 2 /* | |
|
robertphillips
2013/04/17 21:48:58
wrong date
Not Intel either
| |
| 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" | |
| 9 #include "SkTArray.h" | |
| 10 #include "SkRandom.h" | |
| 11 #include "SkMatrix.h" | |
| 12 #include "SkBlurMaskFilter.h" | |
| 13 #include "SkGradientShader.h" | |
| 14 #include "SkBlurDrawLooper.h" | |
| 15 #include "SkRect.h" | |
| 16 | |
| 17 namespace skiagm { | |
| 18 | |
| 19 class OvalGM : public GM { | |
| 20 public: | |
| 21 OvalGM() { | |
| 22 this->setBGColor(0xFF000000); | |
| 23 this->makePaints(); | |
| 24 this->makeMatrices(); | |
| 25 } | |
| 26 | |
| 27 protected: | |
| 28 virtual SkString onShortName() SK_OVERRIDE { | |
| 29 return SkString("ovals"); | |
| 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 stroke style | |
| 52 SkPaint p; | |
| 53 p.setAntiAlias(true); | |
| 54 p.setStyle(SkPaint::kStroke_Style); | |
| 55 p.setStrokeWidth(SkIntToScalar(5)); | |
| 56 fPaints.push_back(p); | |
| 57 } | |
| 58 | |
| 59 { | |
| 60 // AA with stroke style, width = 0 | |
| 61 SkPaint p; | |
| 62 p.setAntiAlias(true); | |
| 63 p.setStyle(SkPaint::kStroke_Style); | |
| 64 fPaints.push_back(p); | |
| 65 } | |
| 66 | |
| 67 { | |
| 68 // AA with stroke and fill style | |
| 69 SkPaint p; | |
| 70 p.setAntiAlias(true); | |
| 71 p.setStyle(SkPaint::kStrokeAndFill_Style); | |
| 72 p.setStrokeWidth(SkIntToScalar(3)); | |
| 73 fPaints.push_back(p); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 void makeMatrices() { | |
| 78 { | |
| 79 SkMatrix m; | |
| 80 m.setIdentity(); | |
| 81 fMatrices.push_back(m); | |
| 82 } | |
| 83 | |
| 84 { | |
| 85 SkMatrix m; | |
| 86 m.setScale(SkIntToScalar(3), SkIntToScalar(2)); | |
| 87 fMatrices.push_back(m); | |
| 88 } | |
| 89 | |
| 90 { | |
| 91 SkMatrix m; | |
| 92 m.setScale(SkIntToScalar(2), SkIntToScalar(2)); | |
| 93 fMatrices.push_back(m); | |
| 94 } | |
| 95 | |
| 96 { | |
| 97 SkMatrix m; | |
| 98 m.setScale(SkIntToScalar(1), SkIntToScalar(2)); | |
| 99 fMatrices.push_back(m); | |
| 100 } | |
| 101 | |
| 102 { | |
| 103 SkMatrix m; | |
| 104 m.setScale(SkIntToScalar(4), SkIntToScalar(1)); | |
| 105 fMatrices.push_back(m); | |
| 106 } | |
| 107 | |
| 108 { | |
| 109 SkMatrix m; | |
| 110 m.setRotate(SkIntToScalar(90)); | |
| 111 fMatrices.push_back(m); | |
| 112 } | |
| 113 | |
| 114 { | |
| 115 SkMatrix m; | |
| 116 m.setSkew(SkIntToScalar(2), SkIntToScalar(3)); | |
| 117 fMatrices.push_back(m); | |
| 118 } | |
| 119 | |
| 120 { | |
| 121 SkMatrix m; | |
| 122 m.setRotate(SkIntToScalar(60)); | |
| 123 fMatrices.push_back(m); | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | |
| 128 SkMWCRandom rand(1); | |
| 129 canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1); | |
| 130 SkRect oval = SkRect::MakeLTRB(-20, -30, 20, 30); | |
| 131 | |
| 132 const SkScalar kXStart = 60.0f; | |
| 133 const SkScalar kYStart = 80.0f; | |
| 134 const int kXStep = 150; | |
| 135 const int kYStep = 160; | |
| 136 int maxX = fMatrices.count(); | |
| 137 | |
| 138 SkPaint rectPaint; | |
| 139 rectPaint.setAntiAlias(true); | |
| 140 rectPaint.setStyle(SkPaint::kStroke_Style); | |
| 141 rectPaint.setStrokeWidth(SkIntToScalar(0)); | |
| 142 rectPaint.setColor(SK_ColorLTGRAY); | |
| 143 | |
|
robertphillips
2013/04/17 21:48:58
k could use a better name (e.g., testCount)
| |
| 144 int k = 0; | |
| 145 for (int i = 0; i < fPaints.count(); ++i) { | |
| 146 for (int j = 0; j < fMatrices.count(); ++j) { | |
| 147 canvas->save(); | |
| 148 SkMatrix mat = fMatrices[j]; | |
|
robertphillips
2013/04/17 21:48:58
update comment - not a path
| |
| 149 // position the path, and make it at off-integer coords. | |
| 150 mat.postTranslate(kXStart + SK_Scalar1 * kXStep * (k % maxX) + S K_Scalar1 / 4, | |
| 151 kYStart + SK_Scalar1 * kYStep * (k / maxX) + 3 * SK_Scalar1 / 4); | |
| 152 canvas->concat(mat); | |
| 153 | |
| 154 SkColor color = rand.nextU(); | |
| 155 color |= 0xff000000; | |
| 156 fPaints[i].setColor(color); | |
| 157 | |
| 158 canvas->drawRect(oval, rectPaint); | |
| 159 canvas->drawOval(oval, fPaints[i]); | |
| 160 | |
| 161 canvas->restore(); | |
| 162 | |
| 163 ++k; | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 // special cases | |
| 168 | |
| 169 // non-scaled tall and skinny oval | |
| 170 for (int i = 0; i < fPaints.count(); ++i) { | |
| 171 SkRect oval = SkRect::MakeLTRB(-20, -60, 20, 60); | |
| 172 canvas->save(); | |
|
robertphillips
2013/04/17 21:48:58
update comment?
| |
| 173 // position the path, and make it at off-integer coords. | |
| 174 canvas->translate(kXStart + SK_Scalar1 * kXStep * 2.55f + SK_Scalar1 / 4, | |
| 175 kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4); | |
| 176 | |
| 177 SkColor color = rand.nextU(); | |
| 178 color |= 0xff000000; | |
| 179 fPaints[i].setColor(color); | |
| 180 | |
| 181 canvas->drawRect(oval, rectPaint); | |
| 182 canvas->drawOval(oval, fPaints[i]); | |
| 183 canvas->restore(); | |
| 184 } | |
| 185 | |
| 186 // non-scaled wide and short oval | |
| 187 for (int i = 0; i < fPaints.count(); ++i) { | |
| 188 SkRect oval = SkRect::MakeLTRB(-80, -30, 80, 30); | |
| 189 canvas->save(); | |
|
robertphillips
2013/04/17 21:48:58
ditto + all following
| |
| 190 // position the path, and make it at off-integer coords. | |
| 191 canvas->translate(kXStart + SK_Scalar1 * kXStep * 4 + SK_Scalar1 / 4 , | |
| 192 kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 + | |
| 193 SK_ScalarHalf * kYStep); | |
| 194 | |
| 195 SkColor color = rand.nextU(); | |
| 196 color |= 0xff000000; | |
| 197 fPaints[i].setColor(color); | |
| 198 | |
| 199 canvas->drawRect(oval, rectPaint); | |
| 200 canvas->drawOval(oval, fPaints[i]); | |
| 201 canvas->restore(); | |
| 202 } | |
| 203 | |
| 204 // super skinny oval | |
| 205 for (int i = 0; i < fPaints.count(); ++i) { | |
| 206 SkRect oval = SkRect::MakeLTRB(0, -60, 1, 60); | |
| 207 canvas->save(); | |
| 208 // position the path, and make it at off-integer coords. | |
| 209 canvas->translate(kXStart + SK_Scalar1 * kXStep * 3.25f + SK_Scalar1 / 4, | |
| 210 kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4); | |
| 211 | |
| 212 SkColor color = rand.nextU(); | |
| 213 color |= 0xff000000; | |
| 214 fPaints[i].setColor(color); | |
| 215 | |
| 216 canvas->drawOval(oval, fPaints[i]); | |
| 217 canvas->restore(); | |
| 218 } | |
| 219 | |
| 220 // super short oval | |
| 221 for (int i = 0; i < fPaints.count(); ++i) { | |
| 222 SkRect oval = SkRect::MakeLTRB(-80, -1, 80, 0); | |
| 223 canvas->save(); | |
| 224 // position the path, and make it at off-integer coords. | |
| 225 canvas->translate(kXStart + SK_Scalar1 * kXStep * 2.5f + SK_Scalar1 / 4, | |
| 226 kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 + | |
| 227 SK_ScalarHalf * kYStep); | |
| 228 | |
| 229 SkColor color = rand.nextU(); | |
| 230 color |= 0xff000000; | |
| 231 fPaints[i].setColor(color); | |
| 232 | |
| 233 canvas->drawOval(oval, fPaints[i]); | |
| 234 canvas->restore(); | |
| 235 } | |
| 236 | |
| 237 // radial gradient | |
| 238 SkPoint center = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0)); | |
| 239 SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN }; | |
| 240 SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 }; | |
|
robertphillips
2013/04/17 21:48:58
Use AutoTUnref?
| |
| 241 SkShader* s = SkGradientShader::CreateRadial(center, | |
| 242 SkIntToScalar(20), | |
| 243 colors, | |
| 244 pos, | |
| 245 SK_ARRAY_COUNT(colors), | |
| 246 SkShader::kClamp_TileMode); | |
| 247 | |
| 248 for (int i = 0; i < fPaints.count(); ++i) { | |
| 249 canvas->save(); | |
| 250 // position the path, and make it at off-integer coords. | |
| 251 canvas->translate(kXStart + SK_Scalar1 * kXStep * 0 + SK_Scalar1 / 4 , | |
| 252 kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 + | |
| 253 SK_ScalarHalf * kYStep); | |
| 254 | |
| 255 SkColor color = rand.nextU(); | |
| 256 color |= 0xff000000; | |
| 257 fPaints[i].setColor(color); | |
| 258 fPaints[i].setShader(s); | |
| 259 | |
| 260 canvas->drawRect(oval, rectPaint); | |
| 261 canvas->drawOval(oval, fPaints[i]); | |
| 262 canvas->restore(); | |
| 263 } | |
| 264 | |
| 265 s->unref(); | |
| 266 } | |
| 267 | |
| 268 private: | |
|
robertphillips
2013/04/17 21:48:58
The INHERITED should go last
| |
| 269 typedef GM INHERITED; | |
| 270 SkTArray<SkPaint> fPaints; | |
| 271 SkTArray<SkMatrix> fMatrices; | |
| 272 }; | |
| 273 | |
| 274 ////////////////////////////////////////////////////////////////////////////// | |
| 275 | |
| 276 static GM* MyFactory(void*) { return new OvalGM; } | |
| 277 static GMRegistry reg(MyFactory); | |
| 278 | |
| 279 } | |
| OLD | NEW |