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" 9 #include "SkRandom.h" 10 11 namespace skiagm { 12 13 // This GM draws a lot of arcs in a 'Z' shape. It particularly exercises 14 // the 'drawArc' code near a singularly of its processing (i.e., near the 15 // edge of one of its underlying quads). 16 class ArcOfZorroGM : public GM { 17 public: 18 ArcOfZorroGM() { 19 this->setBGColor(0xFFCCCCCC); 20 } 21 22 protected: 23 virtual SkString onShortName() SK_OVERRIDE { 24 return SkString("arcofzorro"); 25 } 26 27 virtual SkISize onISize() SK_OVERRIDE { 28 return make_isize(1000, 1000); 29 } 30 31 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 32 SkRandom rand; 33 34 SkRect rect = SkRect::MakeXYWH(10, 10, 200, 200); 35 36 SkPaint p; 37 38 p.setStyle(SkPaint::kStroke_Style); 39 p.setStrokeWidth(35); 40 int xOffset = 0, yOffset = 0; 41 int direction = 0; 42 43 for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) { 44 SkColor color = rand.nextU(); 45 color |= 0xff000000; 46 p.setColor(color); 47 48 canvas->save(); 49 canvas->translate(SkIntToScalar(xOffset), SkIntToScalar(yOffset)); 50 canvas->drawArc(rect, 0, arc, false, p); 51 canvas->restore(); 52 53 switch (direction) { 54 case 0: 55 xOffset += 10; 56 if (xOffset >= 700) { 57 direction = 1; 58 } 59 break; 60 case 1: 61 xOffset -= 10; 62 yOffset += 10; 63 if (xOffset < 50) { 64 direction = 2; 65 } 66 break; 67 case 2: 68 xOffset += 10; 69 break; 70 } 71 } 72 73 } 74 75 private: 76 typedef GM INHERITED; 77 }; 78 79 ////////////////////////////////////////////////////////////////////////////// 80 81 DEF_GM( return SkNEW(ArcOfZorroGM); ) 82 83 } 84