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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkPath.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 12 | #include "include/core/SkScalar.h" |
| 13 | #include "include/core/SkSize.h" |
| 14 | #include "include/core/SkString.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "include/private/SkTArray.h" |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 16 | |
| 17 | namespace skiagm { |
| 18 | |
| 19 | // this GM tests hairlines which fill nearly the entire render target |
| 20 | class StLouisArchGM : public GM { |
| 21 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 22 | SkString onShortName() override { |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 23 | return SkString("stlouisarch"); |
| 24 | } |
| 25 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 26 | SkISize onISize() override { return SkISize::Make((int)kWidth, (int)kHeight); } |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 27 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 28 | void onOnceBeforeDraw() override { |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 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 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 74 | void onDraw(SkCanvas* canvas) override { |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 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 | typedef GM INHERITED; |
| 95 | }; |
| 96 | |
| 97 | ////////////////////////////////////////////////////////////////////////////// |
| 98 | |
Hal Canary | e964c18 | 2019-01-23 10:22:01 -0500 | [diff] [blame] | 99 | DEF_GM( return new StLouisArchGM; ) |
joshualitt | 6364807 | 2015-02-19 10:25:21 -0800 | [diff] [blame] | 100 | |
| 101 | } |