blob: 7b31e54ec8e825a6d6edaf5d23abd8226bfb8c2d [file] [log] [blame]
joshualitt63648072015-02-19 10:25:21 -08001/*
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 Hudson2880df22015-10-29 09:55:42 -040010#include "SkPath.h"
joshualitt63648072015-02-19 10:25:21 -080011#include "SkTArray.h"
12
13namespace skiagm {
14
15// this GM tests hairlines which fill nearly the entire render target
16class StLouisArchGM : public GM {
17protected:
mtklein36352bf2015-03-25 18:17:31 -070018 SkString onShortName() override {
joshualitt63648072015-02-19 10:25:21 -080019 return SkString("stlouisarch");
20 }
21
mtklein36352bf2015-03-25 18:17:31 -070022 SkISize onISize() override { return SkISize::Make((int)kWidth, (int)kHeight); }
joshualitt63648072015-02-19 10:25:21 -080023
mtklein36352bf2015-03-25 18:17:31 -070024 void onOnceBeforeDraw() override {
joshualitt63648072015-02-19 10:25:21 -080025 {
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
mtklein36352bf2015-03-25 18:17:31 -070070 void onDraw(SkCanvas* canvas) override {
joshualitt63648072015-02-19 10:25:21 -080071 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
88private:
89 SkTArray<SkPath> fPaths;
90 typedef GM INHERITED;
91};
92
93//////////////////////////////////////////////////////////////////////////////
94
95static GM* MyFactory(void*) { return new StLouisArchGM; }
96static GMRegistry reg(MyFactory);
97
98}