Flutter Engine
The Flutter Engine
emptypath.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
11#include "include/core/SkFont.h"
15#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
21#include "src/base/SkRandom.h"
22#include "tools/ToolUtils.h"
24
25namespace skiagm {
26
27class EmptyPathGM : public GM {
28 SkString getName() const override { return SkString("emptypath"); }
29
30 SkISize getISize() override { return {600, 280}; }
31
32 void drawEmpty(SkCanvas* canvas,
34 const SkRect& clip,
35 SkPaint::Style style,
36 SkPathFillType fill) {
38 path.setFillType(fill);
40 paint.setColor(color);
41 paint.setStyle(style);
42 canvas->save();
43 canvas->clipRect(clip);
44 canvas->drawPath(path, paint);
45 canvas->restore();
46 }
47
48 void onDraw(SkCanvas* canvas) override {
49 struct FillAndName {
50 SkPathFillType fFill;
51 const char* fName;
52 };
53 constexpr FillAndName gFills[] = {
54 {SkPathFillType::kWinding, "Winding"},
55 {SkPathFillType::kEvenOdd, "Even / Odd"},
56 {SkPathFillType::kInverseWinding, "Inverse Winding"},
57 {SkPathFillType::kInverseEvenOdd, "Inverse Even / Odd"},
58 };
59 struct StyleAndName {
61 const char* fName;
62 };
63 constexpr StyleAndName gStyles[] = {
64 {SkPaint::kFill_Style, "Fill"},
65 {SkPaint::kStroke_Style, "Stroke"},
66 {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"},
67 };
68
70 const char title[] = "Empty Paths Drawn Into Rectangle Clips With "
71 "Indicated Style and Fill";
72 canvas->drawString(title, 20.0f, 20.0f, font, SkPaint());
73
74 SkRandom rand;
76 int i = 0;
77 canvas->save();
78 canvas->translate(10 * SK_Scalar1, 0);
79 canvas->save();
80 for (size_t style = 0; style < std::size(gStyles); ++style) {
81 for (size_t fill = 0; fill < std::size(gFills); ++fill) {
82 if (0 == i % 4) {
83 canvas->restore();
84 canvas->translate(0, rect.height() + 40 * SK_Scalar1);
85 canvas->save();
86 } else {
87 canvas->translate(rect.width() + 40 * SK_Scalar1, 0);
88 }
89 ++i;
90
91
92 SkColor color = rand.nextU();
93 color = 0xff000000 | color; // force solid
95 this->drawEmpty(canvas, color, rect,
96 gStyles[style].fStyle, gFills[fill].fFill);
97
98 SkPaint rectPaint;
99 rectPaint.setColor(SK_ColorBLACK);
101 rectPaint.setStrokeWidth(-1);
102 rectPaint.setAntiAlias(true);
103 canvas->drawRect(rect, rectPaint);
104
105 SkPaint labelPaint;
106 labelPaint.setColor(color);
108 canvas->drawString(gStyles[style].fName, 0, rect.height() + 15.0f,
109 labelFont, labelPaint);
110 canvas->drawString(gFills[fill].fName, 0, rect.height() + 28.0f,
111 labelFont, labelPaint);
112 }
113 }
114 canvas->restore();
115 canvas->restore();
116 }
117};
118DEF_GM( return new EmptyPathGM; )
119
120//////////////////////////////////////////////////////////////////////////////
121
122static constexpr int kPtsCount = 3;
123static constexpr SkPoint kPts[kPtsCount] = {
124 {40, 40},
125 {80, 40},
126 {120, 40},
127};
128
131 for (SkPoint p : kPts) {
132 builder.moveTo(p);
133 }
134 return builder.detach();
135}
136
139 for (SkPoint p : kPts) {
140 builder.moveTo(p).close();
141 }
142 return builder.detach();
143}
144
147 for (SkPoint p : kPts) {
148 builder.moveTo(p).lineTo(p);
149 }
150 return builder.detach();
151}
152
154 return SkPathBuilder().moveTo(kPts[0])
155 .moveTo(kPts[1]).close()
156 .moveTo(kPts[2]).lineTo(kPts[2])
157 .detach();
158}
159
160class EmptyStrokeGM : public GM {
161 SkString getName() const override { return SkString("emptystroke"); }
162
163 SkISize getISize() override { return {200, 240}; }
164
165 void onDraw(SkCanvas* canvas) override {
166 static constexpr SkPath (*kProcs[])() = {
167 make_path_move, // expect red red red
168 make_path_move_close, // expect black black black
169 make_path_move_line, // expect black black black
170 make_path_move_mix, // expect red black black,
171 };
172
173 SkPaint strokePaint;
174 strokePaint.setStyle(SkPaint::kStroke_Style);
175 strokePaint.setStrokeWidth(21);
177
178 SkPaint dotPaint;
179 dotPaint.setColor(SK_ColorRED);
180 strokePaint.setStyle(SkPaint::kStroke_Style);
181 dotPaint.setStrokeWidth(7);
182
183 for (auto proc : kProcs) {
185 canvas->drawPath(proc(), strokePaint);
186 canvas->translate(0, 40);
187 }
188 }
189};
190DEF_GM( return new EmptyStrokeGM; )
191
192} // namespace skiagm
SkStrokeRec::Style fStyle
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
SkPathFillType
Definition: SkPathTypes.h:11
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
#define SK_Scalar1
Definition: SkScalar.h:18
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
Definition: SkCanvas.cpp:1710
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
@ kPoints_PointMode
draw each point separately
Definition: SkCanvas.h:1241
Definition: SkFont.h:35
@ kSquare_Cap
adds square
Definition: SkPaint.h:336
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setStrokeCap(Cap cap)
Definition: SkPaint.cpp:179
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
@ kStrokeAndFill_Style
sets to stroke and fill geometry
Definition: SkPaint.h:195
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
SkPathBuilder & close()
SkPathBuilder & lineTo(SkPoint pt)
SkPathBuilder & moveTo(SkPoint pt)
Definition: SkPath.h:59
uint32_t nextU()
Definition: SkRandom.h:42
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
DlColor color
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
sk_sp< SkTypeface > DefaultPortableTypeface()
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
static SkPath make_path_move()
Definition: emptypath.cpp:129
static constexpr SkPoint kPts[kPtsCount]
Definition: emptypath.cpp:123
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
const char * fName
static SkPath make_path_move_close()
Definition: emptypath.cpp:137
static SkPath make_path_move_mix()
Definition: emptypath.cpp:153
static SkPath make_path_move_line()
Definition: emptypath.cpp:145
static constexpr int kPtsCount
Definition: emptypath.cpp:122
Definition: SkSize.h:16
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static constexpr SkFontStyle gStyles[]
Definition: typeface.cpp:89