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: getName() const30 SkString getName() const override { return SkString("arcofzorro"); } 31 getISize()32 SkISize getISize() override { return SkISize::Make(1000, 1000); } 33 onDraw(SkCanvas * canvas)34 void onDraw(SkCanvas* canvas) override { 35 SkRandom rand; 36 37 SkRect rect = SkRect::MakeXYWH(10, 10, 200, 200); 38 39 SkPaint p; 40 41 p.setStyle(SkPaint::kStroke_Style); 42 p.setStrokeWidth(35); 43 int xOffset = 0, yOffset = 0; 44 int direction = 0; 45 46 for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) { 47 SkColor color = rand.nextU(); 48 color |= 0xff000000; 49 p.setColor(color); 50 51 canvas->save(); 52 canvas->translate(SkIntToScalar(xOffset), SkIntToScalar(yOffset)); 53 canvas->drawArc(rect, 0, arc, false, p); 54 canvas->restore(); 55 56 switch (direction) { 57 case 0: 58 xOffset += 10; 59 if (xOffset >= 700) { 60 direction = 1; 61 } 62 break; 63 case 1: 64 xOffset -= 10; 65 yOffset += 10; 66 if (xOffset < 50) { 67 direction = 2; 68 } 69 break; 70 case 2: 71 xOffset += 10; 72 break; 73 } 74 } 75 76 } 77 78 private: 79 using INHERITED = GM; 80 }; 81 82 ////////////////////////////////////////////////////////////////////////////// 83 84 DEF_GM(return new ArcOfZorroGM;) 85 } // namespace skiagm 86