blob: 225bb0d66ec4cf965d775b42cded287bb55c1f87 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagnerd1701ba2019-04-30 13:44:26 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkColor.h"
11#include "include/core/SkPaint.h"
12#include "include/core/SkRect.h"
13#include "include/core/SkScalar.h"
14#include "include/core/SkSize.h"
15#include "include/core/SkString.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/utils/SkRandom.h"
robertphillips@google.come1b75b42013-07-09 15:03:59 +000017
18namespace skiagm {
19
skia.committer@gmail.com9e1ec1a2013-07-10 07:00:58 +000020// This GM draws a lot of arcs in a 'Z' shape. It particularly exercises
robertphillips@google.come1b75b42013-07-09 15:03:59 +000021// the 'drawArc' code near a singularly of its processing (i.e., near the
22// edge of one of its underlying quads).
23class ArcOfZorroGM : public GM {
24public:
25 ArcOfZorroGM() {
Mike Kleind46dce32018-08-16 10:17:03 -040026 this->setBGColor(0xFFCCCCCC);
robertphillips@google.come1b75b42013-07-09 15:03:59 +000027 }
28
29protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000030
mtklein36352bf2015-03-25 18:17:31 -070031 SkString onShortName() override {
robertphillips@google.come1b75b42013-07-09 15:03:59 +000032 return SkString("arcofzorro");
33 }
34
mtklein36352bf2015-03-25 18:17:31 -070035 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070036 return SkISize::Make(1000, 1000);
robertphillips@google.come1b75b42013-07-09 15:03:59 +000037 }
38
mtklein36352bf2015-03-25 18:17:31 -070039 void onDraw(SkCanvas* canvas) override {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000040 SkRandom rand;
robertphillips@google.come1b75b42013-07-09 15:03:59 +000041
42 SkRect rect = SkRect::MakeXYWH(10, 10, 200, 200);
43
44 SkPaint p;
45
46 p.setStyle(SkPaint::kStroke_Style);
47 p.setStrokeWidth(35);
48 int xOffset = 0, yOffset = 0;
49 int direction = 0;
50
51 for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) {
52 SkColor color = rand.nextU();
53 color |= 0xff000000;
54 p.setColor(color);
55
56 canvas->save();
57 canvas->translate(SkIntToScalar(xOffset), SkIntToScalar(yOffset));
58 canvas->drawArc(rect, 0, arc, false, p);
59 canvas->restore();
60
61 switch (direction) {
62 case 0:
63 xOffset += 10;
64 if (xOffset >= 700) {
65 direction = 1;
66 }
67 break;
68 case 1:
69 xOffset -= 10;
70 yOffset += 10;
71 if (xOffset < 50) {
72 direction = 2;
73 }
74 break;
75 case 2:
76 xOffset += 10;
77 break;
78 }
79 }
80
81 }
82
83private:
84 typedef GM INHERITED;
85};
86
87//////////////////////////////////////////////////////////////////////////////
88
halcanary385fe4d2015-08-26 13:07:48 -070089DEF_GM(return new ArcOfZorroGM;)
robertphillips@google.come1b75b42013-07-09 15:03:59 +000090}