Flutter Engine
The Flutter Engine
Functions
linepaths.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "src/base/SkRandom.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Functions

static void drawPath (SkPath &path, SkCanvas *canvas, SkColor color, const SkRect &clip, SkPaint::Cap cap, SkPaint::Join join, SkPaint::Style style, SkPathFillType fill, SkScalar strokeWidth)
 
static void draw (SkCanvas *canvas, bool doClose)
 
 DEF_SIMPLE_GM (linepath, canvas, 1240, 390)
 
 DEF_SIMPLE_GM (lineclosepath, canvas, 1240, 390)
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/2]

DEF_SIMPLE_GM ( lineclosepath  ,
canvas  ,
1240  ,
390   
)

Definition at line 148 of file linepaths.cpp.

148 {
149 draw(canvas, true);
150}
static void draw(SkCanvas *canvas, bool doClose)
Definition: linepaths.cpp:39

◆ DEF_SIMPLE_GM() [2/2]

DEF_SIMPLE_GM ( linepath  ,
canvas  ,
1240  ,
390   
)

Definition at line 145 of file linepaths.cpp.

145 {
146 draw(canvas, false);
147}

◆ draw()

static void draw ( SkCanvas canvas,
bool  doClose 
)
static

Definition at line 39 of file linepaths.cpp.

39 {
40 struct FillAndName {
41 SkPathFillType fFill;
42 const char* fName;
43 };
44 constexpr FillAndName gFills[] = {
45 {SkPathFillType::kWinding, "Winding"},
46 {SkPathFillType::kEvenOdd, "Even / Odd"},
47 {SkPathFillType::kInverseWinding, "Inverse Winding"},
48 {SkPathFillType::kInverseEvenOdd, "Inverse Even / Odd"},
49 };
50 struct StyleAndName {
52 const char* fName;
53 };
54 constexpr StyleAndName gStyles[] = {
55 {SkPaint::kFill_Style, "Fill"},
56 {SkPaint::kStroke_Style, "Stroke"},
57 {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"},
58 };
59 struct CapAndName {
60 SkPaint::Cap fCap;
62 const char* fName;
63 };
64 constexpr CapAndName gCaps[] = {
68 };
69 struct PathAndName {
71 const char* fName;
72 };
73 PathAndName path;
74 path.fPath.moveTo(25*SK_Scalar1, 15*SK_Scalar1);
75 path.fPath.lineTo(75*SK_Scalar1, 15*SK_Scalar1);
76 if (doClose) {
77 path.fPath.close();
78 path.fName = "moveTo-line-close";
79 } else {
80 path.fName = "moveTo-line";
81 }
82
83 SkPaint titlePaint;
84 titlePaint.setColor(SK_ColorBLACK);
85 titlePaint.setAntiAlias(true);
86
88
89 const char titleNoClose[] = "Line Drawn Into Rectangle Clips With "
90 "Indicated Style, Fill and Linecaps, with stroke width 10";
91 const char titleClose[] = "Line Closed Drawn Into Rectangle Clips With "
92 "Indicated Style, Fill and Linecaps, with stroke width 10";
93 const char* title = doClose ? titleClose : titleNoClose;
94 canvas->drawString(title, 20.0f, 20.0f, font, titlePaint);
95
96 SkRandom rand;
98 canvas->save();
99 canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1);
100 canvas->save();
101 for (size_t cap = 0; cap < std::size(gCaps); ++cap) {
102 if (0 < cap) {
103 canvas->translate((rect.width() + 40 * SK_Scalar1) * std::size(gStyles), 0);
104 }
105 canvas->save();
106 for (size_t fill = 0; fill < std::size(gFills); ++fill) {
107 if (0 < fill) {
108 canvas->translate(0, rect.height() + 40 * SK_Scalar1);
109 }
110 canvas->save();
111 for (size_t style = 0; style < std::size(gStyles); ++style) {
112 if (0 < style) {
113 canvas->translate(rect.width() + 40 * SK_Scalar1, 0);
114 }
115
117 drawPath(path.fPath, canvas, color, rect,
118 gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle,
119 gFills[fill].fFill, SK_Scalar1*10);
120
121 SkPaint rectPaint;
122 rectPaint.setColor(SK_ColorBLACK);
124 rectPaint.setStrokeWidth(-1);
125 rectPaint.setAntiAlias(true);
126 canvas->drawRect(rect, rectPaint);
127
128 SkPaint labelPaint;
129 labelPaint.setColor(color);
130 font.setSize(10);
131 canvas->drawString(gStyles[style].fName, 0, rect.height() + 12.0f,
132 font, labelPaint);
133 canvas->drawString(gFills[fill].fName, 0, rect.height() + 24.0f,
134 font, labelPaint);
135 canvas->drawString(gCaps[cap].fName, 0, rect.height() + 36.0f,
136 font, labelPaint);
137 }
138 canvas->restore();
139 }
140 canvas->restore();
141 }
142 canvas->restore();
143 canvas->restore();
144}
SkPath fPath
SkPaint::Join fJoin
SkStrokeRec::Style fStyle
const char * fName
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
SkPathFillType
Definition: SkPathTypes.h:11
#define SK_Scalar1
Definition: SkScalar.h:18
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
@ kButt_Cap
no stroke extension
Definition: SkPaint.h:334
@ 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
@ 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
@ kRound_Join
adds circle
Definition: SkPaint.h:360
@ kBevel_Join
connects outside edges
Definition: SkPaint.h:361
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
DlColor color
static void drawPath(SkPath &path, SkCanvas *canvas, SkColor color, const SkRect &clip, SkPaint::Cap cap, SkPaint::Join join, SkPaint::Style style, SkPathFillType fill, SkScalar strokeWidth)
Definition: linepaths.cpp:22
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 constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static constexpr SkFontStyle gStyles[]
Definition: typeface.cpp:89

◆ drawPath()

static void drawPath ( SkPath path,
SkCanvas canvas,
SkColor  color,
const SkRect clip,
SkPaint::Cap  cap,
SkPaint::Join  join,
SkPaint::Style  style,
SkPathFillType  fill,
SkScalar  strokeWidth 
)
static

Definition at line 22 of file linepaths.cpp.

25 {
26 path.setFillType(fill);
28 paint.setStrokeCap(cap);
29 paint.setStrokeWidth(strokeWidth);
30 paint.setStrokeJoin(join);
31 paint.setColor(color);
32 paint.setStyle(style);
33 canvas->save();
34 canvas->clipRect(clip);
35 canvas->drawPath(path, paint);
36 canvas->restore();
37}
static const int strokeWidth
Definition: BlurTest.cpp:60
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
const Paint & paint
Definition: color_source.cc:38
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741