robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 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.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 10 | #include "SkRandom.h" |
| 11 | |
| 12 | namespace skiagm { |
| 13 | |
skia.committer@gmail.com | 9e1ec1a | 2013-07-10 07:00:58 +0000 | [diff] [blame] | 14 | // This GM draws a lot of arcs in a 'Z' shape. It particularly exercises |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 15 | // the 'drawArc' code near a singularly of its processing (i.e., near the |
| 16 | // edge of one of its underlying quads). |
| 17 | class ArcOfZorroGM : public GM { |
| 18 | public: |
| 19 | ArcOfZorroGM() { |
caryclark | 65cdba6 | 2015-06-15 06:51:08 -0700 | [diff] [blame] | 20 | this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 24 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 25 | SkString onShortName() override { |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 26 | return SkString("arcofzorro"); |
| 27 | } |
| 28 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 29 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 30 | return SkISize::Make(1000, 1000); |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 31 | } |
| 32 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 33 | void onDraw(SkCanvas* canvas) override { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 34 | SkRandom rand; |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 35 | |
| 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 | |
| 77 | private: |
| 78 | typedef GM INHERITED; |
| 79 | }; |
| 80 | |
| 81 | ////////////////////////////////////////////////////////////////////////////// |
| 82 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 83 | DEF_GM(return new ArcOfZorroGM;) |
robertphillips@google.com | e1b75b4 | 2013-07-09 15:03:59 +0000 | [diff] [blame] | 84 | } |