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