• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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/gm.h"
9 #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"
16 #include "src/base/SkRandom.h"
17 
18 namespace skiagm {
19 
20 // This GM draws a lot of arcs in a 'Z' shape. It particularly exercises
21 // the 'drawArc' code near a singularly of its processing (i.e., near the
22 // edge of one of its underlying quads).
23 class ArcOfZorroGM : public GM {
24 public:
ArcOfZorroGM()25     ArcOfZorroGM() {
26         this->setBGColor(0xFFCCCCCC);
27     }
28 
29 protected:
30 
onShortName()31     SkString onShortName() override {
32         return SkString("arcofzorro");
33     }
34 
onISize()35     SkISize onISize() override {
36         return SkISize::Make(1000, 1000);
37     }
38 
onDraw(SkCanvas * canvas)39     void onDraw(SkCanvas* canvas) override {
40         SkRandom rand;
41 
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 
83 private:
84     using INHERITED = GM;
85 };
86 
87 //////////////////////////////////////////////////////////////////////////////
88 
89 DEF_GM(return new ArcOfZorroGM;)
90 }  // namespace skiagm
91