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