Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
SkStrokeRec Class Reference

#include <SkStrokeRec.h>

Public Types

enum  InitStyle { kHairline_InitStyle , kFill_InitStyle }
 
enum  Style { kHairline_Style , kFill_Style , kStroke_Style , kStrokeAndFill_Style }
 

Public Member Functions

 SkStrokeRec (InitStyle style)
 
 SkStrokeRec (const SkPaint &, SkPaint::Style, SkScalar resScale=1)
 
 SkStrokeRec (const SkPaint &, SkScalar resScale=1)
 
Style getStyle () const
 
SkScalar getWidth () const
 
SkScalar getMiter () const
 
SkPaint::Cap getCap () const
 
SkPaint::Join getJoin () const
 
bool isHairlineStyle () const
 
bool isFillStyle () const
 
void setFillStyle ()
 
void setHairlineStyle ()
 
void setStrokeStyle (SkScalar width, bool strokeAndFill=false)
 
void setStrokeParams (SkPaint::Cap cap, SkPaint::Join join, SkScalar miterLimit)
 
SkScalar getResScale () const
 
void setResScale (SkScalar rs)
 
bool needToApply () const
 
bool applyToPath (SkPath *dst, const SkPath &src) const
 
void applyToPaint (SkPaint *paint) const
 
SkScalar getInflationRadius () const
 
bool hasEqualEffect (const SkStrokeRec &other) const
 

Static Public Member Functions

static SkScalar GetInflationRadius (const SkPaint &, SkPaint::Style)
 
static SkScalar GetInflationRadius (SkPaint::Join, SkScalar miterLimit, SkPaint::Cap, SkScalar strokeWidth)
 

Static Public Attributes

static constexpr int kStyleCount = kStrokeAndFill_Style + 1
 

Detailed Description

Definition at line 22 of file SkStrokeRec.h.

Member Enumeration Documentation

◆ InitStyle

Enumerator
kHairline_InitStyle 
kFill_InitStyle 

Definition at line 24 of file SkStrokeRec.h.

24 {
27 };
@ kHairline_InitStyle
Definition: SkStrokeRec.h:25

◆ Style

Enumerator
kHairline_Style 
kFill_Style 
kStroke_Style 
kStrokeAndFill_Style 

Definition at line 32 of file SkStrokeRec.h.

Constructor & Destructor Documentation

◆ SkStrokeRec() [1/3]

SkStrokeRec::SkStrokeRec ( InitStyle  style)

Definition at line 18 of file SkStrokeRec.cpp.

18 {
19 fResScale = 1;
21 fMiterLimit = SkPaintDefaults_MiterLimit;
24 fStrokeAndFill = false;
25}
#define SkPaintDefaults_MiterLimit
#define kStrokeRec_FillStyleWidth
Definition: SkStrokeRec.cpp:16
@ kDefault_Cap
equivalent to kButt_Cap
Definition: SkPaint.h:338
@ kDefault_Join
equivalent to kMiter_Join
Definition: SkPaint.h:363
struct MyStruct s

◆ SkStrokeRec() [2/3]

SkStrokeRec::SkStrokeRec ( const SkPaint paint,
SkPaint::Style  styleOverride,
SkScalar  resScale = 1 
)

Definition at line 31 of file SkStrokeRec.cpp.

31 {
32 this->init(paint, styleOverride, resScale);
33}
const Paint & paint
Definition: color_source.cc:38

◆ SkStrokeRec() [3/3]

SkStrokeRec::SkStrokeRec ( const SkPaint paint,
SkScalar  resScale = 1 
)
explicit

Definition at line 27 of file SkStrokeRec.cpp.

27 {
28 this->init(paint, paint.getStyle(), resScale);
29}

Member Function Documentation

◆ applyToPaint()

void SkStrokeRec::applyToPaint ( SkPaint paint) const

Apply these stroke parameters to a paint.

Definition at line 127 of file SkStrokeRec.cpp.

127 {
128 if (fWidth < 0) { // fill
129 paint->setStyle(SkPaint::kFill_Style);
130 return;
131 }
132
133 paint->setStyle(fStrokeAndFill ? SkPaint::kStrokeAndFill_Style : SkPaint::kStroke_Style);
134 paint->setStrokeWidth(fWidth);
135 paint->setStrokeMiter(fMiterLimit);
136 paint->setStrokeCap((SkPaint::Cap)fCap);
137 paint->setStrokeJoin((SkPaint::Join)fJoin);
138}
@ 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

◆ applyToPath()

bool SkStrokeRec::applyToPath ( SkPath dst,
const SkPath src 
) const

Apply these stroke parameters to the src path, returning the result in dst.

If there was no change (i.e. style == hairline or fill) this returns false and dst is unchanged. Otherwise returns true and the result is stored in dst.

src and dst may be the same path.

Definition at line 107 of file SkStrokeRec.cpp.

107 {
108 if (fWidth <= 0) { // hairline or fill
109 return false;
110 }
111
112 SkStroke stroker;
113 stroker.setCap((SkPaint::Cap)fCap);
114 stroker.setJoin((SkPaint::Join)fJoin);
115 stroker.setMiterLimit(fMiterLimit);
116 stroker.setWidth(fWidth);
117 stroker.setDoFill(fStrokeAndFill);
118#ifdef SK_DEBUG
119 stroker.setResScale(gDebugStrokerErrorSet ? gDebugStrokerError : fResScale);
120#else
121 stroker.setResScale(fResScale);
122#endif
123 stroker.strokePath(src, dst);
124 return true;
125}
void strokePath(const SkPath &path, SkPath *) const
Definition: SkStroke.cpp:1433
void setWidth(SkScalar)
Definition: SkStroke.cpp:1385
void setCap(SkPaint::Cap)
Definition: SkStroke.cpp:1395
void setDoFill(bool doFill)
Definition: SkStroke.h:52
void setResScale(SkScalar rs)
Definition: SkStroke.h:63
void setJoin(SkPaint::Join)
Definition: SkStroke.cpp:1400
void setMiterLimit(SkScalar)
Definition: SkStroke.cpp:1390
dst
Definition: cp.py:12

◆ getCap()

SkPaint::Cap SkStrokeRec::getCap ( ) const
inline

Definition at line 44 of file SkStrokeRec.h.

44{ return (SkPaint::Cap)fCap; }

◆ getInflationRadius()

SkScalar SkStrokeRec::getInflationRadius ( ) const

Gives a conservative value for the outset that should applied to a geometries bounds to account for any inflation due to applying this strokeRec to the geometry.

Definition at line 140 of file SkStrokeRec.cpp.

140 {
141 return GetInflationRadius((SkPaint::Join)fJoin, fMiterLimit, (SkPaint::Cap)fCap, fWidth);
142}
static SkScalar GetInflationRadius(const SkPaint &, SkPaint::Style)

◆ GetInflationRadius() [1/2]

SkScalar SkStrokeRec::GetInflationRadius ( const SkPaint paint,
SkPaint::Style  style 
)
static

Equivalent to: SkStrokeRec rec(paint, style); rec.getInflationRadius(); This does not account for other effects on the paint (i.e. path effect).

Definition at line 144 of file SkStrokeRec.cpp.

144 {
145 SkScalar width = SkPaint::kFill_Style == style ? -SK_Scalar1 : paint.getStrokeWidth();
146 return GetInflationRadius(paint.getStrokeJoin(), paint.getStrokeMiter(), paint.getStrokeCap(),
147 width);
148
149}
#define SK_Scalar1
Definition: SkScalar.h:18
float SkScalar
Definition: extension.cpp:12
int32_t width

◆ GetInflationRadius() [2/2]

SkScalar SkStrokeRec::GetInflationRadius ( SkPaint::Join  join,
SkScalar  miterLimit,
SkPaint::Cap  cap,
SkScalar  strokeWidth 
)
static

Definition at line 151 of file SkStrokeRec.cpp.

152 {
153 if (strokeWidth < 0) { // fill
154 return 0;
155 } else if (0 == strokeWidth) {
156 // FIXME: We need a "matrixScale" parameter here in order to properly handle hairlines.
157 // Their with is determined in device space, unlike other strokes.
158 // http://skbug.com/8157
159 return SK_Scalar1;
160 }
161
162 // since we're stroked, outset the rect by the radius (and join type, caps)
163 SkScalar multiplier = SK_Scalar1;
164 if (SkPaint::kMiter_Join == join) {
165 multiplier = std::max(multiplier, miterLimit);
166 }
167 if (SkPaint::kSquare_Cap == cap) {
168 multiplier = std::max(multiplier, SK_ScalarSqrt2);
169 }
170 return strokeWidth/2 * multiplier;
171}
static const int strokeWidth
Definition: BlurTest.cpp:60
#define SK_ScalarSqrt2
Definition: SkScalar.h:20
@ kSquare_Cap
adds square
Definition: SkPaint.h:336
@ kMiter_Join
extends to miter limit
Definition: SkPaint.h:359
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ getJoin()

SkPaint::Join SkStrokeRec::getJoin ( ) const
inline

Definition at line 45 of file SkStrokeRec.h.

45{ return (SkPaint::Join)fJoin; }

◆ getMiter()

SkScalar SkStrokeRec::getMiter ( ) const
inline

Definition at line 43 of file SkStrokeRec.h.

43{ return fMiterLimit; }

◆ getResScale()

SkScalar SkStrokeRec::getResScale ( ) const
inline

Definition at line 71 of file SkStrokeRec.h.

71 {
72 return fResScale;
73 }

◆ getStyle()

SkStrokeRec::Style SkStrokeRec::getStyle ( ) const

Definition at line 71 of file SkStrokeRec.cpp.

71 {
72 if (fWidth < 0) {
73 return kFill_Style;
74 } else if (0 == fWidth) {
75 return kHairline_Style;
76 } else {
77 return fStrokeAndFill ? kStrokeAndFill_Style : kStroke_Style;
78 }
79}

◆ getWidth()

SkScalar SkStrokeRec::getWidth ( ) const
inline

Definition at line 42 of file SkStrokeRec.h.

42{ return fWidth; }

◆ hasEqualEffect()

bool SkStrokeRec::hasEqualEffect ( const SkStrokeRec other) const
inline

Compare if two SkStrokeRecs have an equal effect on a path. Equal SkStrokeRecs produce equal paths. Equality of produced paths does not take the ResScale parameter into account.

Definition at line 130 of file SkStrokeRec.h.

130 {
131 if (!this->needToApply()) {
132 return this->getStyle() == other.getStyle();
133 }
134 return fWidth == other.fWidth &&
135 (fJoin != SkPaint::kMiter_Join || fMiterLimit == other.fMiterLimit) &&
136 fCap == other.fCap &&
137 fJoin == other.fJoin &&
138 fStrokeAndFill == other.fStrokeAndFill;
139 }
Style getStyle() const
Definition: SkStrokeRec.cpp:71
bool needToApply() const
Definition: SkStrokeRec.h:84

◆ isFillStyle()

bool SkStrokeRec::isFillStyle ( ) const
inline

Definition at line 51 of file SkStrokeRec.h.

51 {
52 return kFill_Style == this->getStyle();
53 }

◆ isHairlineStyle()

bool SkStrokeRec::isHairlineStyle ( ) const
inline

Definition at line 47 of file SkStrokeRec.h.

47 {
48 return kHairline_Style == this->getStyle();
49 }

◆ needToApply()

bool SkStrokeRec::needToApply ( ) const
inline

Returns true if this specifes any thick stroking, i.e. applyToPath() will return true.

Definition at line 84 of file SkStrokeRec.h.

84 {
85 Style style = this->getStyle();
86 return (kStroke_Style == style) || (kStrokeAndFill_Style == style);
87 }

◆ setFillStyle()

void SkStrokeRec::setFillStyle ( )

Definition at line 81 of file SkStrokeRec.cpp.

81 {
83 fStrokeAndFill = false;
84}

◆ setHairlineStyle()

void SkStrokeRec::setHairlineStyle ( )

Definition at line 86 of file SkStrokeRec.cpp.

86 {
87 fWidth = 0;
88 fStrokeAndFill = false;
89}

◆ setResScale()

void SkStrokeRec::setResScale ( SkScalar  rs)
inline

Definition at line 75 of file SkStrokeRec.h.

75 {
76 SkASSERT(rs > 0 && std::isfinite(rs));
77 fResScale = rs;
78 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
SINT bool isfinite(const Vec< N, T > &v)
Definition: SkVx.h:1003

◆ setStrokeParams()

void SkStrokeRec::setStrokeParams ( SkPaint::Cap  cap,
SkPaint::Join  join,
SkScalar  miterLimit 
)
inline

Definition at line 65 of file SkStrokeRec.h.

65 {
66 fCap = cap;
67 fJoin = join;
68 fMiterLimit = miterLimit;
69 }

◆ setStrokeStyle()

void SkStrokeRec::setStrokeStyle ( SkScalar  width,
bool  strokeAndFill = false 
)

Specify the strokewidth, and optionally if you want stroke + fill. Note, if width==0, then this request is taken to mean: strokeAndFill==true -> new style will be Fill strokeAndFill==false -> new style will be Hairline

Definition at line 91 of file SkStrokeRec.cpp.

91 {
92 if (strokeAndFill && (0 == width)) {
93 // hairline+fill == fill
94 this->setFillStyle();
95 } else {
96 fWidth = width;
97 fStrokeAndFill = strokeAndFill;
98 }
99}
void setFillStyle()
Definition: SkStrokeRec.cpp:81

Member Data Documentation

◆ kStyleCount

constexpr int SkStrokeRec::kStyleCount = kStrokeAndFill_Style + 1
staticconstexpr

Definition at line 39 of file SkStrokeRec.h.


The documentation for this class was generated from the following files: