Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 | 158 |
| 159 private: | 159 private: |
| 160 SkScalar fRotate; | 160 SkScalar fRotate; |
| 161 | 161 |
| 162 typedef skiagm::GM INHERITED; | 162 typedef skiagm::GM INHERITED; |
| 163 }; | 163 }; |
| 164 DEF_GM( return new StrokeCircleGM; ) | 164 DEF_GM( return new StrokeCircleGM; ) |
| 165 | 165 |
| 166 ////////////////////// | 166 ////////////////////// |
| 167 | 167 |
| 168 // Fill circles and rotate them to test our Analytic Anti-Aliasing. | |
| 169 // This test is based on StrokeCircleGM. | |
| 170 class FillCircleGM : public skiagm::GM { | |
| 171 public: | |
| 172 FillCircleGM() : fRotate(0) {} | |
| 173 | |
| 174 protected: | |
| 175 SkString onShortName() override { return SkString("fillcircle"); } | |
| 176 | |
| 177 SkISize onISize() override { return SkISize::Make(520, 520); } | |
| 178 | |
| 179 void onDraw(SkCanvas* canvas) override { | |
| 180 canvas->scale(20, 20); | |
| 181 canvas->translate(13, 13); | |
| 182 | |
| 183 SkPaint paint; | |
| 184 paint.setAntiAlias(true); | |
| 185 paint.setStyle(SkPaint::kStroke_Style); | |
| 186 paint.setStrokeWidth(SK_Scalar1 / 2); | |
| 187 | |
|
robertphillips
2016/10/07 14:12:46
Don't we just know strokeWidth is SK_Scalar1 / 2 (
liyuqian
2016/10/07 14:15:50
Yes, I was just copying from the StrokeCircleGM wh
| |
| 188 const SkScalar strokeWidth = paint.getStrokeWidth(); | |
| 189 const SkScalar delta = strokeWidth * 3 / 2; | |
| 190 SkRect r = SkRect::MakeXYWH(-12, -12, 24, 24); | |
| 191 SkRandom rand; | |
| 192 | |
| 193 // Reset style to fill. We only need stroke stype for producing delta an d strokeWidth | |
| 194 paint.setStyle(SkPaint::kFill_Style); | |
| 195 | |
| 196 SkScalar sign = 1; | |
| 197 while (r.width() > strokeWidth * 2) { | |
| 198 SkAutoCanvasRestore acr(canvas, true); | |
| 199 canvas->rotate(fRotate * sign); | |
| 200 paint.setColor(sk_tool_utils::color_to_565(rand.nextU() | (0xFF << 2 4))); | |
| 201 canvas->drawOval(r, paint); | |
| 202 r.inset(delta, delta); | |
| 203 sign = -sign; | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 bool onAnimate(const SkAnimTimer& timer) override { | |
| 208 fRotate = timer.scaled(60, 360); | |
| 209 return true; | |
| 210 } | |
| 211 | |
| 212 private: | |
| 213 SkScalar fRotate; | |
| 214 | |
| 215 typedef skiagm::GM INHERITED; | |
| 216 }; | |
| 217 DEF_GM( return new FillCircleGM; ) | |
| 218 | |
| 219 ////////////////////// | |
| 220 | |
| 168 static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, Sk Scalar start, | 221 static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, Sk Scalar start, |
| 169 SkScalar end, bool ccw) { | 222 SkScalar end, bool ccw) { |
| 170 SkRect bounds = { x - r, y - r, x + r, y + r }; | 223 SkRect bounds = { x - r, y - r, x + r, y + r }; |
| 171 SkScalar sweep = ccw ? end - start : start - end; | 224 SkScalar sweep = ccw ? end - start : start - end; |
| 172 path->arcTo(bounds, start, sweep, false); | 225 path->arcTo(bounds, start, sweep, false); |
| 173 } | 226 } |
| 174 | 227 |
| 175 // Lifted from canvas-arc-circumference-fill-diffs.html | 228 // Lifted from canvas-arc-circumference-fill-diffs.html |
| 176 class ManyArcsGM : public skiagm::GM { | 229 class ManyArcsGM : public skiagm::GM { |
| 177 public: | 230 public: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 } | 276 } |
| 224 canvas->restore(); | 277 canvas->restore(); |
| 225 canvas->translate(0, 40); | 278 canvas->translate(0, 40); |
| 226 } | 279 } |
| 227 } | 280 } |
| 228 | 281 |
| 229 private: | 282 private: |
| 230 typedef skiagm::GM INHERITED; | 283 typedef skiagm::GM INHERITED; |
| 231 }; | 284 }; |
| 232 DEF_GM( return new ManyArcsGM; ) | 285 DEF_GM( return new ManyArcsGM; ) |
| OLD | NEW |