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