1 /* 2 * Copyright 2015 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/SkPaint.h" 11 #include "include/core/SkPath.h" 12 #include "include/core/SkScalar.h" 13 #include "include/core/SkSize.h" 14 #include "include/core/SkString.h" 15 #include "include/private/SkTArray.h" 16 17 namespace skiagm { 18 19 // this GM tests hairlines which fill nearly the entire render target 20 class StLouisArchGM : public GM { 21 protected: onShortName()22 SkString onShortName() override { 23 return SkString("stlouisarch"); 24 } 25 onISize()26 SkISize onISize() override { return SkISize::Make((int)kWidth, (int)kHeight); } 27 onOnceBeforeDraw()28 void onOnceBeforeDraw() override { 29 { 30 SkPath* bigQuad = &fPaths.push_back(); 31 bigQuad->moveTo(0, 0); 32 bigQuad->quadTo(kWidth/2, kHeight, kWidth, 0); 33 } 34 35 { 36 SkPath* degenBigQuad = &fPaths.push_back(); 37 SkScalar yPos = kHeight / 2 + 10; 38 degenBigQuad->moveTo(0, yPos); 39 degenBigQuad->quadTo(0, yPos, kWidth, yPos); 40 } 41 42 43 { 44 SkPath* bigCubic = &fPaths.push_back(); 45 bigCubic->moveTo(0, 0); 46 bigCubic->cubicTo(0, kHeight, 47 kWidth, kHeight, 48 kWidth, 0); 49 } 50 51 { 52 SkPath* degenBigCubic = &fPaths.push_back(); 53 SkScalar yPos = kHeight / 2; 54 degenBigCubic->moveTo(0, yPos); 55 degenBigCubic->cubicTo(0, yPos, 56 0, yPos, 57 kWidth, yPos); 58 } 59 60 { 61 SkPath* bigConic = &fPaths.push_back(); 62 bigConic->moveTo(0, 0); 63 bigConic->conicTo(kWidth/2, kHeight, kWidth, 0, .5); 64 } 65 66 { 67 SkPath* degenBigConic = &fPaths.push_back(); 68 SkScalar yPos = kHeight / 2 - 10; 69 degenBigConic->moveTo(0, yPos); 70 degenBigConic->conicTo(0, yPos, kWidth, yPos, .5); 71 } 72 } 73 onDraw(SkCanvas * canvas)74 void onDraw(SkCanvas* canvas) override { 75 canvas->save(); 76 canvas->scale(1, -1); 77 canvas->translate(0, -kHeight); 78 for (int p = 0; p < fPaths.count(); ++p) { 79 SkPaint paint; 80 paint.setARGB(0xff, 0, 0, 0); 81 paint.setAntiAlias(true); 82 paint.setStyle(SkPaint::kStroke_Style); 83 paint.setStrokeWidth(0); 84 canvas->drawPath(fPaths[p], paint); 85 } 86 canvas->restore(); 87 } 88 89 const SkScalar kWidth = 256; 90 const SkScalar kHeight = 256; 91 92 private: 93 SkTArray<SkPath> fPaths; 94 using INHERITED = GM; 95 }; 96 97 ////////////////////////////////////////////////////////////////////////////// 98 99 DEF_GM( return new StLouisArchGM; ) 100 101 } // namespace skiagm 102