aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/addarc.cpp
diff options
context:
space:
mode:
authorGravatar liyuqian <liyuqian@google.com>2016-10-03 13:49:37 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-10-03 13:49:37 -0700
commite60d85597f803c4dff6329840215af1d1d9a8fdc (patch)
treef82916ea6f7f539cd4af0e8bda723d82ce58d4ab /gm/addarc.cpp
parentf85d2a4fa1b71e6ee28518431e2a34df5683bc81 (diff)
Add GMs for Analytic Anti-Aliasing
Diffstat (limited to 'gm/addarc.cpp')
-rw-r--r--gm/addarc.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/gm/addarc.cpp b/gm/addarc.cpp
index 9280140794..0a1876b2dc 100644
--- a/gm/addarc.cpp
+++ b/gm/addarc.cpp
@@ -165,6 +165,59 @@ DEF_GM( return new StrokeCircleGM; )
//////////////////////
+// Fill circles and rotate them to test our Analytic Anti-Aliasing.
+// This test is based on StrokeCircleGM.
+class FillCircleGM : public skiagm::GM {
+public:
+ FillCircleGM() : fRotate(0) {}
+
+protected:
+ SkString onShortName() override { return SkString("fillcircle"); }
+
+ SkISize onISize() override { return SkISize::Make(520, 520); }
+
+ void onDraw(SkCanvas* canvas) override {
+ canvas->scale(20, 20);
+ canvas->translate(13, 13);
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeWidth(SK_Scalar1 / 2);
+
+ const SkScalar strokeWidth = paint.getStrokeWidth();
+ const SkScalar delta = strokeWidth * 3 / 2;
+ SkRect r = SkRect::MakeXYWH(-12, -12, 24, 24);
+ SkRandom rand;
+
+ // Reset style to fill. We only need stroke stype for producing delta and strokeWidth
+ paint.setStyle(SkPaint::kFill_Style);
+
+ SkScalar sign = 1;
+ while (r.width() > strokeWidth * 2) {
+ SkAutoCanvasRestore acr(canvas, true);
+ canvas->rotate(fRotate * sign);
+ paint.setColor(sk_tool_utils::color_to_565(rand.nextU() | (0xFF << 24)));
+ canvas->drawOval(r, paint);
+ r.inset(delta, delta);
+ sign = -sign;
+ }
+ }
+
+ bool onAnimate(const SkAnimTimer& timer) override {
+ fRotate = timer.scaled(60, 360);
+ return true;
+ }
+
+private:
+ SkScalar fRotate;
+
+ typedef skiagm::GM INHERITED;
+};
+DEF_GM( return new FillCircleGM; )
+
+//////////////////////
+
static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, SkScalar start,
SkScalar end, bool ccw) {
SkRect bounds = { x - r, y - r, x + r, y + r };