blob: 296d98b94e50e332c910ccd484802f35bce9120c [file] [log] [blame]
robertphillips@google.come1b75b42013-07-09 15:03:59 +00001/*
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 "SkRandom.h"
10
11namespace skiagm {
12
skia.committer@gmail.com9e1ec1a2013-07-10 07:00:58 +000013// This GM draws a lot of arcs in a 'Z' shape. It particularly exercises
robertphillips@google.come1b75b42013-07-09 15:03:59 +000014// the 'drawArc' code near a singularly of its processing (i.e., near the
15// edge of one of its underlying quads).
16class ArcOfZorroGM : public GM {
17public:
18 ArcOfZorroGM() {
Mike Kleind46dce32018-08-16 10:17:03 -040019 this->setBGColor(0xFFCCCCCC);
robertphillips@google.come1b75b42013-07-09 15:03:59 +000020 }
21
22protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000023
mtklein36352bf2015-03-25 18:17:31 -070024 SkString onShortName() override {
robertphillips@google.come1b75b42013-07-09 15:03:59 +000025 return SkString("arcofzorro");
26 }
27
mtklein36352bf2015-03-25 18:17:31 -070028 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070029 return SkISize::Make(1000, 1000);
robertphillips@google.come1b75b42013-07-09 15:03:59 +000030 }
31
mtklein36352bf2015-03-25 18:17:31 -070032 void onDraw(SkCanvas* canvas) override {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000033 SkRandom rand;
robertphillips@google.come1b75b42013-07-09 15:03:59 +000034
35 SkRect rect = SkRect::MakeXYWH(10, 10, 200, 200);
36
37 SkPaint p;
38
39 p.setStyle(SkPaint::kStroke_Style);
40 p.setStrokeWidth(35);
41 int xOffset = 0, yOffset = 0;
42 int direction = 0;
43
44 for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) {
45 SkColor color = rand.nextU();
46 color |= 0xff000000;
47 p.setColor(color);
48
49 canvas->save();
50 canvas->translate(SkIntToScalar(xOffset), SkIntToScalar(yOffset));
51 canvas->drawArc(rect, 0, arc, false, p);
52 canvas->restore();
53
54 switch (direction) {
55 case 0:
56 xOffset += 10;
57 if (xOffset >= 700) {
58 direction = 1;
59 }
60 break;
61 case 1:
62 xOffset -= 10;
63 yOffset += 10;
64 if (xOffset < 50) {
65 direction = 2;
66 }
67 break;
68 case 2:
69 xOffset += 10;
70 break;
71 }
72 }
73
74 }
75
76private:
77 typedef GM INHERITED;
78};
79
80//////////////////////////////////////////////////////////////////////////////
81
halcanary385fe4d2015-08-26 13:07:48 -070082DEF_GM(return new ArcOfZorroGM;)
robertphillips@google.come1b75b42013-07-09 15:03:59 +000083}