Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
GrStyle Class Reference

#include <GrStyle.h>

Public Types

enum class  Apply { kPathEffectOnly , kPathEffectAndStrokeRec }
 
enum  KeyFlags { kClosed_KeyFlag = 0x1 , kNoJoins_KeyFlag = 0x2 }
 

Public Member Functions

 GrStyle ()
 
 GrStyle (SkStrokeRec::InitStyle initStyle)
 
 GrStyle (const SkStrokeRec &strokeRec, sk_sp< SkPathEffect > pe)
 
 GrStyle (const GrStyle &that)=default
 
 GrStyle (const SkPaint &paint)
 
 GrStyle (const SkPaint &paint, SkPaint::Style overrideStyle)
 
GrStyleoperator= (const GrStyle &that)
 
void resetToInitStyle (SkStrokeRec::InitStyle fillOrHairline)
 
bool isSimpleFill () const
 
bool isSimpleHairline () const
 
SkPathEffectpathEffect () const
 
sk_sp< SkPathEffectrefPathEffect () const
 
bool hasPathEffect () const
 
bool hasNonDashPathEffect () const
 
bool isDashed () const
 
SkScalar dashPhase () const
 
int dashIntervalCnt () const
 
const SkScalardashIntervals () const
 
const SkStrokeRecstrokeRec () const
 
bool applies () const
 
bool applyPathEffectToPath (SkPath *dst, SkStrokeRec *remainingStoke, const SkPath &src, SkScalar scale) const
 
bool applyToPath (SkPath *dst, SkStrokeRec::InitStyle *fillOrHairline, const SkPath &src, SkScalar scale) const
 
void adjustBounds (SkRect *dst, const SkRect &src) const
 

Static Public Member Functions

static const GrStyleSimpleFill ()
 
static const GrStyleSimpleHairline ()
 
static int KeySize (const GrStyle &, Apply, uint32_t flags=0)
 
static void WriteKey (uint32_t *, const GrStyle &, Apply, SkScalar scale, uint32_t flags=0)
 
static SkScalar MatrixToScaleFactor (const SkMatrix &matrix)
 

Detailed Description

Represents the various ways that a GrStyledShape can be styled. It has fill/stroking information as well as an optional path effect. If the path effect represents dashing, the dashing information is extracted from the path effect and stored explicitly.

This will replace GrStrokeInfo as GrStyledShape is deployed.

Definition at line 24 of file GrStyle.h.

Member Enumeration Documentation

◆ Apply

enum class GrStyle::Apply
strong
Enumerator
kPathEffectOnly 
kPathEffectAndStrokeRec 

Definition at line 44 of file GrStyle.h.

◆ KeyFlags

Optional flags for computing keys that may remove unnecessary variation in the key due to style settings that don't affect particular classes of geometry.

Enumerator
kClosed_KeyFlag 
kNoJoins_KeyFlag 

Definition at line 53 of file GrStyle.h.

53 {
54 // The shape being styled has no open contours.
55 kClosed_KeyFlag = 0x1,
56 // The shape being styled doesn't have any joins and so isn't affected by join type.
58 };
@ kNoJoins_KeyFlag
Definition GrStyle.h:57
@ kClosed_KeyFlag
Definition GrStyle.h:55

Constructor & Destructor Documentation

◆ GrStyle() [1/6]

GrStyle::GrStyle ( )
inline

Definition at line 77 of file GrStyle.h.

◆ GrStyle() [2/6]

GrStyle::GrStyle ( SkStrokeRec::InitStyle  initStyle)
inlineexplicit

Definition at line 79 of file GrStyle.h.

79: fStrokeRec(initStyle) {}

◆ GrStyle() [3/6]

GrStyle::GrStyle ( const SkStrokeRec strokeRec,
sk_sp< SkPathEffect pe 
)
inline

Definition at line 81 of file GrStyle.h.

81 : fStrokeRec(strokeRec) {
82 this->initPathEffect(std::move(pe));
83 }
const SkStrokeRec & strokeRec() const
Definition GrStyle.h:140

◆ GrStyle() [4/6]

GrStyle::GrStyle ( const GrStyle that)
default

◆ GrStyle() [5/6]

GrStyle::GrStyle ( const SkPaint paint)
inlineexplicit

Definition at line 87 of file GrStyle.h.

87 : fStrokeRec(paint) {
88 this->initPathEffect(paint.refPathEffect());
89 }
const Paint & paint

◆ GrStyle() [6/6]

GrStyle::GrStyle ( const SkPaint paint,
SkPaint::Style  overrideStyle 
)
inlineexplicit

Definition at line 91 of file GrStyle.h.

92 : fStrokeRec(paint, overrideStyle) {
93 this->initPathEffect(paint.refPathEffect());
94 }

Member Function Documentation

◆ adjustBounds()

void GrStyle::adjustBounds ( SkRect dst,
const SkRect src 
) const
inline

Given bounds of a path compute the bounds of path with the style applied.

Definition at line 173 of file GrStyle.h.

173 {
174 *dst = src;
175 auto pe = as_PEB(this->pathEffect());
176 if (pe && !pe->computeFastBounds(dst)) {
177 // Restore dst == src since ComputeFastBounds leaves it undefined when returning false
178 *dst = src;
179 }
180
181 // This may not be the correct SkStrokeRec to use if there's a path effect: skbug.com/5299
182 // It happens to work for dashing.
183 SkScalar radius = fStrokeRec.getInflationRadius();
184 dst->outset(radius, radius);
185 }
static SkPathEffectBase * as_PEB(SkPathEffect *effect)
SkPathEffect * pathEffect() const
Definition GrStyle.h:119
SkScalar getInflationRadius() const
float SkScalar
Definition extension.cpp:12
dst
Definition cp.py:12

◆ applies()

bool GrStyle::applies ( ) const
inline

Hairline or fill styles without path effects make no alterations to a geometry.

Definition at line 143 of file GrStyle.h.

143 {
144 return this->pathEffect() || (!fStrokeRec.isFillStyle() && !fStrokeRec.isHairlineStyle());
145 }
bool isHairlineStyle() const
Definition SkStrokeRec.h:47
bool isFillStyle() const
Definition SkStrokeRec.h:51

◆ applyPathEffectToPath()

bool GrStyle::applyPathEffectToPath ( SkPath dst,
SkStrokeRec remainingStoke,
const SkPath src,
SkScalar  scale 
) const

Applies just the path effect and returns remaining stroke information. This will fail if there is no path effect. dst may or may not have been overwritten on failure. Scale controls geometric approximations made by the path effect. It is typically computed from the view matrix.

Definition at line 163 of file GrStyle.cpp.

164 {
165 SkASSERT(dst);
166 SkStrokeRec strokeRec = fStrokeRec;
167 strokeRec.setResScale(resScale);
168 if (!this->applyPathEffect(dst, &strokeRec, src)) {
169 return false;
170 }
171 *remainingStroke = strokeRec;
172 return true;
173}
#define SkASSERT(cond)
Definition SkAssert.h:116
void setResScale(SkScalar rs)
Definition SkStrokeRec.h:75

◆ applyToPath()

bool GrStyle::applyToPath ( SkPath dst,
SkStrokeRec::InitStyle fillOrHairline,
const SkPath src,
SkScalar  scale 
) const

If this succeeds then the result path should be filled or hairlined as indicated by the returned SkStrokeRec::InitStyle value. Will fail if there is no path effect and the strokerec doesn't change the geometry. When this fails the outputs may or may not have been overwritten. Scale controls geometric approximations made by the path effect and stroker. It is typically computed from the view matrix.

Definition at line 175 of file GrStyle.cpp.

176 {
177 SkASSERT(style);
178 SkASSERT(dst);
179 SkStrokeRec strokeRec = fStrokeRec;
180 strokeRec.setResScale(resScale);
181 const SkPath* pathForStrokeRec = &src;
182 if (this->applyPathEffect(dst, &strokeRec, src)) {
183 pathForStrokeRec = dst;
184 } else if (fPathEffect) {
185 return false;
186 }
187 if (strokeRec.needToApply()) {
188 if (!strokeRec.applyToPath(dst, *pathForStrokeRec)) {
189 return false;
190 }
191 dst->setIsVolatile(true);
193 } else if (!fPathEffect) {
194 // Nothing to do for path effect or stroke, fail.
195 return false;
196 } else {
202 }
203 return true;
204}
@ kHairline_InitStyle
Definition SkStrokeRec.h:25
Style getStyle() const
bool needToApply() const
Definition SkStrokeRec.h:84
bool applyToPath(SkPath *dst, const SkPath &src) const

◆ dashIntervalCnt()

int GrStyle::dashIntervalCnt ( ) const
inline

Definition at line 131 of file GrStyle.h.

131 {
132 SkASSERT(this->isDashed());
133 return fDashInfo.fIntervals.count();
134 }
bool isDashed() const
Definition GrStyle.h:126

◆ dashIntervals()

const SkScalar * GrStyle::dashIntervals ( ) const
inline

Definition at line 135 of file GrStyle.h.

135 {
136 SkASSERT(this->isDashed());
137 return fDashInfo.fIntervals.get();
138 }

◆ dashPhase()

SkScalar GrStyle::dashPhase ( ) const
inline

Definition at line 127 of file GrStyle.h.

127 {
128 SkASSERT(this->isDashed());
129 return fDashInfo.fPhase;
130 }

◆ hasNonDashPathEffect()

bool GrStyle::hasNonDashPathEffect ( ) const
inline

Definition at line 124 of file GrStyle.h.

124{ return fPathEffect.get() && !this->isDashed(); }
T * get() const
Definition SkRefCnt.h:303

◆ hasPathEffect()

bool GrStyle::hasPathEffect ( ) const
inline

Definition at line 122 of file GrStyle.h.

122{ return SkToBool(fPathEffect.get()); }
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35

◆ isDashed()

bool GrStyle::isDashed ( ) const
inline

Definition at line 126 of file GrStyle.h.

126{ return SkPathEffect::kDash_DashType == fDashInfo.fType; }
@ kDash_DashType
fills in all of the info parameter

◆ isSimpleFill()

bool GrStyle::isSimpleFill ( ) const
inline

Is this style a fill with no path effect?

Definition at line 114 of file GrStyle.h.

114{ return fStrokeRec.isFillStyle() && !fPathEffect; }

◆ isSimpleHairline()

bool GrStyle::isSimpleHairline ( ) const
inline

Is this style a hairline with no path effect?

Definition at line 117 of file GrStyle.h.

117{ return fStrokeRec.isHairlineStyle() && !fPathEffect; }

◆ KeySize()

int GrStyle::KeySize ( const GrStyle style,
Apply  apply,
uint32_t  flags = 0 
)
static

Computes the key length for a GrStyle. The return will be negative if it cannot be turned into a key. This occurs when there is a path effect that is not a dash. The key can either reflect just the path effect (if one) or the path effect and the strokerec. Note that a simple fill has a zero sized key.

Definition at line 11 of file GrStyle.cpp.

11 {
12 static_assert(sizeof(uint32_t) == sizeof(SkScalar));
13 int size = 0;
14 if (style.isDashed()) {
15 // One scalar for scale, one for dash phase, and one for each dash value.
16 size += 2 + style.dashIntervalCnt();
17 } else if (style.pathEffect()) {
18 // No key for a generic path effect.
19 return -1;
20 }
21
23 return size;
24 }
25
26 if (style.strokeRec().needToApply()) {
27 // One for res scale, one for style/cap/join, one for miter limit, and one for width.
28 size += 4;
29 }
30 return size;
31}
static bool apply(Pass *pass, SkRecord *record)
int dashIntervalCnt() const
Definition GrStyle.h:131
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

◆ MatrixToScaleFactor()

static SkScalar GrStyle::MatrixToScaleFactor ( const SkMatrix matrix)
inlinestatic

Definition at line 147 of file GrStyle.h.

147 {
148 // getMaxScale will return -1 if the matrix has perspective. In that case we can use a scale
149 // factor of 1. This isn't necessarily a good choice and in the future we might consider
150 // taking a bounds here for the perspective case.
151 return SkScalarAbs(matrix.getMaxScale());
152 }
#define SkScalarAbs(x)
Definition SkScalar.h:39
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258

◆ operator=()

GrStyle & GrStyle::operator= ( const GrStyle that)
inline

Definition at line 96 of file GrStyle.h.

96 {
97 fPathEffect = that.fPathEffect;
98 fDashInfo = that.fDashInfo;
99 fStrokeRec = that.fStrokeRec;
100 return *this;
101 }

◆ pathEffect()

SkPathEffect * GrStyle::pathEffect ( ) const
inline

Definition at line 119 of file GrStyle.h.

119{ return fPathEffect.get(); }

◆ refPathEffect()

sk_sp< SkPathEffect > GrStyle::refPathEffect ( ) const
inline

Definition at line 120 of file GrStyle.h.

120{ return fPathEffect; }

◆ resetToInitStyle()

void GrStyle::resetToInitStyle ( SkStrokeRec::InitStyle  fillOrHairline)
inline

Definition at line 103 of file GrStyle.h.

103 {
104 fDashInfo.reset();
105 fPathEffect.reset(nullptr);
106 if (SkStrokeRec::kFill_InitStyle == fillOrHairline) {
107 fStrokeRec.setFillStyle();
108 } else {
109 fStrokeRec.setHairlineStyle();
110 }
111 }
void setHairlineStyle()
void setFillStyle()
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310

◆ SimpleFill()

static const GrStyle & GrStyle::SimpleFill ( )
inlinestatic

A style object that represents a fill with no path effect. TODO: constexpr with C++14

Definition at line 30 of file GrStyle.h.

30 {
32 return kFill;
33 }

◆ SimpleHairline()

static const GrStyle & GrStyle::SimpleHairline ( )
inlinestatic

A style object that represents a hairline stroke with no path effect. TODO: constexpr with C++14

Definition at line 39 of file GrStyle.h.

39 {
41 return kHairline;
42 }

◆ strokeRec()

const SkStrokeRec & GrStyle::strokeRec ( ) const
inline

Definition at line 140 of file GrStyle.h.

140{ return fStrokeRec; }

◆ WriteKey()

void GrStyle::WriteKey ( uint32_t *  key,
const GrStyle style,
Apply  apply,
SkScalar  scale,
uint32_t  flags = 0 
)
static

Writes a unique key for the style into the provided buffer. This function assumes the buffer has room for at least KeySize() values. It assumes that KeySize() returns a non-negative value for the combination of GrStyle, Apply and flags params. This is written so that the key for just dash application followed by the key for the remaining SkStrokeRec is the same as the key for applying dashing and SkStrokeRec all at once.

Definition at line 33 of file GrStyle.cpp.

34 {
36 SkASSERT(KeySize(style, apply) >= 0);
37 static_assert(sizeof(uint32_t) == sizeof(SkScalar));
38
39 int i = 0;
40 // The scale can influence both the path effect and stroking. We want to preserve the
41 // property that the following two are equal:
42 // 1. WriteKey with apply == kPathEffectAndStrokeRec
43 // 2. WriteKey with apply == kPathEffectOnly followed by WriteKey of a GrStyle made
44 // from SkStrokeRec output by the the path effect (and no additional path effect).
45 // Since the scale can affect both parts of 2 we write it into the key twice.
46 if (style.isDashed()) {
47 static_assert(sizeof(style.dashPhase()) == sizeof(uint32_t));
48 SkScalar phase = style.dashPhase();
49 memcpy(&key[i++], &scale, sizeof(SkScalar));
50 memcpy(&key[i++], &phase, sizeof(SkScalar));
51
52 int32_t count = style.dashIntervalCnt();
53 // Dash count should always be even.
54 SkASSERT(0 == (count & 0x1));
55 const SkScalar *intervals = style.dashIntervals();
56 int intervalByteCnt = count * sizeof(SkScalar);
57 memcpy(&key[i], intervals, intervalByteCnt);
58 i += count;
59 } else {
60 SkASSERT(!style.pathEffect());
61 }
62
64 memcpy(&key[i++], &scale, sizeof(SkScalar));
65 enum {
66 kStyleBits = 2,
67 kJoinBits = 2,
68 kCapBits = 32 - kStyleBits - kJoinBits,
69
70 kJoinShift = kStyleBits,
71 kCapShift = kJoinShift + kJoinBits,
72 };
73 static_assert(SkStrokeRec::kStyleCount <= (1 << kStyleBits));
74 static_assert(SkPaint::kJoinCount <= (1 << kJoinBits));
75 static_assert(SkPaint::kCapCount <= (1 << kCapBits));
76 // The cap type only matters for unclosed shapes. However, a path effect could unclose
77 // the shape before it is stroked.
79 if (!(flags & kClosed_KeyFlag) || style.pathEffect()) {
80 cap = style.strokeRec().getCap();
81 }
82 SkScalar miter = -1.f;
84
85 // Dashing will not insert joins but other path effects may.
86 if (!(flags & kNoJoins_KeyFlag) || style.hasNonDashPathEffect()) {
87 join = style.strokeRec().getJoin();
88 // Miter limit only affects miter joins
89 if (SkPaint::kMiter_Join == join) {
90 miter = style.strokeRec().getMiter();
91 }
92 }
93
94 key[i++] = style.strokeRec().getStyle() |
95 join << kJoinShift |
96 cap << kCapShift;
97
98 memcpy(&key[i++], &miter, sizeof(miter));
99
100 SkScalar width = style.strokeRec().getWidth();
101 memcpy(&key[i++], &width, sizeof(width));
102 }
103 SkASSERT(KeySize(style, apply) == i);
104}
int count
const SkScalar * dashIntervals() const
Definition GrStyle.h:135
bool hasNonDashPathEffect() const
Definition GrStyle.h:124
SkScalar dashPhase() const
Definition GrStyle.h:127
static int KeySize(const GrStyle &, Apply, uint32_t flags=0)
Definition GrStyle.cpp:11
@ kDefault_Cap
equivalent to kButt_Cap
Definition SkPaint.h:338
static constexpr int kCapCount
Definition SkPaint.h:343
static constexpr int kJoinCount
Definition SkPaint.h:368
@ kDefault_Join
equivalent to kMiter_Join
Definition SkPaint.h:363
@ kMiter_Join
extends to miter limit
Definition SkPaint.h:359
static constexpr int kStyleCount
Definition SkStrokeRec.h:39
SkScalar getWidth() const
Definition SkStrokeRec.h:42
SkPaint::Join getJoin() const
Definition SkStrokeRec.h:45
SkPaint::Cap getCap() const
Definition SkStrokeRec.h:44
SkScalar getMiter() const
Definition SkStrokeRec.h:43
FlutterSemanticsFlag flags
SINT Vec< 2 *N, T > join(const Vec< N, T > &lo, const Vec< N, T > &hi)
Definition SkVx.h:242
int32_t width
const Scalar scale

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