Debian Codegraph @

gm/stlouisarch.cpp

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