Flutter Engine
The Flutter Engine
SkStrokeRec.h
Go to the documentation of this file.
1/*
2 * Copyright 2012 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#ifndef SkStrokeRec_DEFINED
9#define SkStrokeRec_DEFINED
10
15
16#include <cmath>
17#include <cstdint>
18
19class SkPath;
20
23public:
24 enum InitStyle {
26 kFill_InitStyle
27 };
28 SkStrokeRec(InitStyle style);
29 SkStrokeRec(const SkPaint&, SkPaint::Style, SkScalar resScale = 1);
30 explicit SkStrokeRec(const SkPaint&, SkScalar resScale = 1);
31
32 enum Style {
36 kStrokeAndFill_Style
37 };
38
39 static constexpr int kStyleCount = kStrokeAndFill_Style + 1;
40
41 Style getStyle() const;
42 SkScalar getWidth() const { return fWidth; }
43 SkScalar getMiter() const { return fMiterLimit; }
44 SkPaint::Cap getCap() const { return (SkPaint::Cap)fCap; }
46
47 bool isHairlineStyle() const {
48 return kHairline_Style == this->getStyle();
49 }
50
51 bool isFillStyle() const {
52 return kFill_Style == this->getStyle();
53 }
54
55 void setFillStyle();
56 void setHairlineStyle();
57 /**
58 * Specify the strokewidth, and optionally if you want stroke + fill.
59 * Note, if width==0, then this request is taken to mean:
60 * strokeAndFill==true -> new style will be Fill
61 * strokeAndFill==false -> new style will be Hairline
62 */
63 void setStrokeStyle(SkScalar width, bool strokeAndFill = false);
64
66 fCap = cap;
67 fJoin = join;
68 fMiterLimit = miterLimit;
69 }
70
72 return fResScale;
73 }
74
76 SkASSERT(rs > 0 && std::isfinite(rs));
77 fResScale = rs;
78 }
79
80 /**
81 * Returns true if this specifes any thick stroking, i.e. applyToPath()
82 * will return true.
83 */
84 bool needToApply() const {
85 Style style = this->getStyle();
86 return (kStroke_Style == style) || (kStrokeAndFill_Style == style);
87 }
88
89 /**
90 * Apply these stroke parameters to the src path, returning the result
91 * in dst.
92 *
93 * If there was no change (i.e. style == hairline or fill) this returns
94 * false and dst is unchanged. Otherwise returns true and the result is
95 * stored in dst.
96 *
97 * src and dst may be the same path.
98 */
99 bool applyToPath(SkPath* dst, const SkPath& src) const;
100
101 /**
102 * Apply these stroke parameters to a paint.
103 */
104 void applyToPaint(SkPaint* paint) const;
105
106 /**
107 * Gives a conservative value for the outset that should applied to a
108 * geometries bounds to account for any inflation due to applying this
109 * strokeRec to the geometry.
110 */
111 SkScalar getInflationRadius() const;
112
113 /**
114 * Equivalent to:
115 * SkStrokeRec rec(paint, style);
116 * rec.getInflationRadius();
117 * This does not account for other effects on the paint (i.e. path
118 * effect).
119 */
120 static SkScalar GetInflationRadius(const SkPaint&, SkPaint::Style);
121
122 static SkScalar GetInflationRadius(SkPaint::Join, SkScalar miterLimit, SkPaint::Cap,
124
125 /**
126 * Compare if two SkStrokeRecs have an equal effect on a path.
127 * Equal SkStrokeRecs produce equal paths. Equality of produced
128 * paths does not take the ResScale parameter into account.
129 */
130 bool hasEqualEffect(const SkStrokeRec& other) const {
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 }
140
141private:
142 void init(const SkPaint&, SkPaint::Style, SkScalar resScale);
143
144 SkScalar fResScale;
145 SkScalar fWidth;
147 // The following three members are packed together into a single u32.
148 // This is to avoid unnecessary padding and ensure binary equality for
149 // hashing (because the padded areas might contain garbage values).
150 //
151 // fCap and fJoin are larger than needed to avoid having to initialize
152 // any pad values
153 uint32_t fCap : 16; // SkPaint::Cap
154 uint32_t fJoin : 15; // SkPaint::Join
155 uint32_t fStrokeAndFill : 1; // bool
156};
158
159#endif
SkPaint::Join fJoin
static const int strokeWidth
Definition: BlurTest.cpp:60
#define SK_API
Definition: SkAPI.h:35
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SK_BEGIN_REQUIRE_DENSE
Definition: SkMacros.h:37
#define SK_END_REQUIRE_DENSE
Definition: SkMacros.h:38
@ kMiter_Join
extends to miter limit
Definition: SkPaint.h:359
Definition: SkPath.h:59
@ kHairline_InitStyle
Definition: SkStrokeRec.h:25
Style getStyle() const
Definition: SkStrokeRec.cpp:71
bool needToApply() const
Definition: SkStrokeRec.h:84
bool hasEqualEffect(const SkStrokeRec &other) const
Definition: SkStrokeRec.h:130
bool isHairlineStyle() const
Definition: SkStrokeRec.h:47
SkScalar getWidth() const
Definition: SkStrokeRec.h:42
void setStrokeParams(SkPaint::Cap cap, SkPaint::Join join, SkScalar miterLimit)
Definition: SkStrokeRec.h:65
SkPaint::Join getJoin() const
Definition: SkStrokeRec.h:45
SkPaint::Cap getCap() const
Definition: SkStrokeRec.h:44
SkScalar getResScale() const
Definition: SkStrokeRec.h:71
void setResScale(SkScalar rs)
Definition: SkStrokeRec.h:75
bool isFillStyle() const
Definition: SkStrokeRec.h:51
SkScalar getMiter() const
Definition: SkStrokeRec.h:43
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
static bool init()
dst
Definition: cp.py:12
SINT bool isfinite(const Vec< N, T > &v)
Definition: SkVx.h:1003
int32_t width
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741