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

#include <GrStyledShape.h>

Public Types

enum class  DoSimplify : bool { kNo = false , kYes }
 
enum class  FillInversion { kPreserve , kFlip , kForceNoninverted , kForceInverted }
 

Public Member Functions

 GrStyledShape ()
 
 GrStyledShape (const SkPath &path, DoSimplify doSimplify=DoSimplify::kYes)
 
 GrStyledShape (const SkRRect &rrect, DoSimplify doSimplify=DoSimplify::kYes)
 
 GrStyledShape (const SkRect &rect, DoSimplify doSimplify=DoSimplify::kYes)
 
 GrStyledShape (const SkPath &path, const SkPaint &paint, DoSimplify doSimplify=DoSimplify::kYes)
 
 GrStyledShape (const SkRRect &rrect, const SkPaint &paint, DoSimplify doSimplify=DoSimplify::kYes)
 
 GrStyledShape (const SkRect &rect, const SkPaint &paint, DoSimplify doSimplify=DoSimplify::kYes)
 
 GrStyledShape (const SkPath &path, const GrStyle &style, DoSimplify doSimplify=DoSimplify::kYes)
 
 GrStyledShape (const SkRRect &rrect, const GrStyle &style, DoSimplify doSimplify=DoSimplify::kYes)
 
 GrStyledShape (const SkRRect &rrect, SkPathDirection dir, unsigned start, bool inverted, const GrStyle &style, DoSimplify doSimplify=DoSimplify::kYes)
 
 GrStyledShape (const SkRect &rect, const GrStyle &style, DoSimplify doSimplify=DoSimplify::kYes)
 
 GrStyledShape (const GrStyledShape &)
 
GrStyledShapeoperator= (const GrStyledShape &that)
 
const GrStylestyle () const
 
bool simplified () const
 
GrStyledShape applyStyle (GrStyle::Apply apply, SkScalar scale) const
 
bool isRect () const
 
bool asRRect (SkRRect *rrect, bool *inverted) const
 
bool asLine (SkPoint pts[2], bool *inverted) const
 
bool asNestedRects (SkRect rects[2]) const
 
void asPath (SkPath *out) const
 
bool isEmpty () const
 
SkRect bounds () const
 
SkRect styledBounds () const
 
bool knownToBeConvex () const
 
bool knownDirection () const
 
bool inverseFilled () const
 
bool mayBeInverseFilledAfterStyling () const
 
bool knownToBeClosed () const
 
uint32_t segmentMask () const
 
int unstyledKeySize () const
 
bool hasUnstyledKey () const
 
void writeUnstyledKey (uint32_t *key) const
 
void addGenIDChangeListener (sk_sp< SkIDChangeListener >) const
 
uint32_t testingOnly_getOriginalGenerationID () const
 
bool testingOnly_isPath () const
 
bool testingOnly_isNonVolatilePath () const
 
void simplify ()
 

Static Public Member Functions

static GrStyledShape MakeArc (const SkArc &arc, const GrStyle &style, DoSimplify=DoSimplify::kYes)
 
static GrStyledShape MakeFilled (const GrStyledShape &original, FillInversion=FillInversion::kPreserve)
 

Static Public Attributes

static constexpr int kMaxKeyFromDataVerbCnt = 10
 

Detailed Description

Represents a geometric shape (rrect or path) and the GrStyle that it should be rendered with. It is possible to apply the style to the GrStyledShape to produce a new GrStyledShape where the geometry reflects the styling information (e.g. is stroked). It is also possible to apply just the path effect from the style. In this case the resulting shape will include any remaining stroking information that is to be applied after the path effect.

Shapes can produce keys that represent only the geometry information, not the style. Note that when styling information is applied to produce a new shape then the style has been converted to geometric information and is included in the new shape's key. When the same style is applied to two shapes that reflect the same underlying geometry the computed keys of the stylized shapes will be the same.

Currently this can only be constructed from a path, rect, or rrect though it can become a path applying style to the geometry. The idea is to expand this to cover most or all of the geometries that have fast paths in the GPU backend.

Definition at line 49 of file GrStyledShape.h.

Member Enumeration Documentation

◆ DoSimplify

enum class GrStyledShape::DoSimplify : bool
strong
Enumerator
kNo 
kYes 

Definition at line 57 of file GrStyledShape.h.

57: bool { kNo = false, kYes };
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.

◆ FillInversion

enum class GrStyledShape::FillInversion
strong

Informs MakeFilled on how to modify that shape's fill rule when making a simple filled version of the shape.

Enumerator
kPreserve 
kFlip 
kForceNoninverted 
kForceInverted 

Definition at line 124 of file GrStyledShape.h.

124 {
125 kPreserve,
126 kFlip,
127 kForceNoninverted,
128 kForceInverted
129 };

Constructor & Destructor Documentation

◆ GrStyledShape() [1/12]

GrStyledShape::GrStyledShape ( )
inline

Definition at line 55 of file GrStyledShape.h.

55{}

◆ GrStyledShape() [2/12]

GrStyledShape::GrStyledShape ( const SkPath path,
DoSimplify  doSimplify = DoSimplify::kYes 
)
inlineexplicit

Definition at line 59 of file GrStyledShape.h.

60 : GrStyledShape(path, GrStyle::SimpleFill(), doSimplify) {}
static const GrStyle & SimpleFill()
Definition: GrStyle.h:30
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

◆ GrStyledShape() [3/12]

GrStyledShape::GrStyledShape ( const SkRRect rrect,
DoSimplify  doSimplify = DoSimplify::kYes 
)
inlineexplicit

Definition at line 62 of file GrStyledShape.h.

63 : GrStyledShape(rrect, GrStyle::SimpleFill(), doSimplify) {}
SkRRect rrect
Definition: SkRecords.h:232

◆ GrStyledShape() [4/12]

GrStyledShape::GrStyledShape ( const SkRect rect,
DoSimplify  doSimplify = DoSimplify::kYes 
)
inlineexplicit

Definition at line 65 of file GrStyledShape.h.

66 : GrStyledShape(rect, GrStyle::SimpleFill(), doSimplify) {}
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ GrStyledShape() [5/12]

GrStyledShape::GrStyledShape ( const SkPath path,
const SkPaint paint,
DoSimplify  doSimplify = DoSimplify::kYes 
)
inline

Definition at line 68 of file GrStyledShape.h.

70 : GrStyledShape(path, GrStyle(paint), doSimplify) {}
const Paint & paint
Definition: color_source.cc:38

◆ GrStyledShape() [6/12]

GrStyledShape::GrStyledShape ( const SkRRect rrect,
const SkPaint paint,
DoSimplify  doSimplify = DoSimplify::kYes 
)
inline

Definition at line 72 of file GrStyledShape.h.

74 : GrStyledShape(rrect, GrStyle(paint), doSimplify) {}

◆ GrStyledShape() [7/12]

GrStyledShape::GrStyledShape ( const SkRect rect,
const SkPaint paint,
DoSimplify  doSimplify = DoSimplify::kYes 
)
inline

Definition at line 76 of file GrStyledShape.h.

78 : GrStyledShape(rect, GrStyle(paint), doSimplify) {}

◆ GrStyledShape() [8/12]

GrStyledShape::GrStyledShape ( const SkPath path,
const GrStyle style,
DoSimplify  doSimplify = DoSimplify::kYes 
)
inline

Definition at line 80 of file GrStyledShape.h.

82 : fShape(path), fStyle(style) {
83 if (doSimplify == DoSimplify::kYes) {
84 this->simplify();
85 }
86 }
const GrStyle & style() const

◆ GrStyledShape() [9/12]

GrStyledShape::GrStyledShape ( const SkRRect rrect,
const GrStyle style,
DoSimplify  doSimplify = DoSimplify::kYes 
)
inline

Definition at line 88 of file GrStyledShape.h.

91 : GrStyledShape(rrect, SkPathDirection::kCW, 6, false, style, doSimplify) {}

◆ GrStyledShape() [10/12]

GrStyledShape::GrStyledShape ( const SkRRect rrect,
SkPathDirection  dir,
unsigned  start,
bool  inverted,
const GrStyle style,
DoSimplify  doSimplify = DoSimplify::kYes 
)
inline

Definition at line 93 of file GrStyledShape.h.

95 : fShape(rrect)
96 , fStyle(style) {
98 fShape.setInverted(inverted);
99 if (doSimplify == DoSimplify::kYes) {
100 this->simplify();
101 }
102 }
void setPathWindingParams(SkPathDirection dir, unsigned start)
Definition: GrShape.h:112
void setInverted(bool inverted)
Definition: GrShape.h:119
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145

◆ GrStyledShape() [11/12]

GrStyledShape::GrStyledShape ( const SkRect rect,
const GrStyle style,
DoSimplify  doSimplify = DoSimplify::kYes 
)
inline

Definition at line 104 of file GrStyledShape.h.

106 : fShape(rect), fStyle(style) {
107 if (doSimplify == DoSimplify::kYes) {
108 this->simplify();
109 }
110 }

◆ GrStyledShape() [12/12]

GrStyledShape::GrStyledShape ( const GrStyledShape that)

Definition at line 330 of file GrStyledShape.cpp.

331 : fShape(that.fShape)
332 , fStyle(that.fStyle)
333 , fGenID(that.fGenID)
334 , fSimplified(that.fSimplified) {
335 fInheritedKey.reset(that.fInheritedKey.count());
336 sk_careful_memcpy(fInheritedKey.get(), that.fInheritedKey.get(),
337 sizeof(uint32_t) * fInheritedKey.count());
338 if (that.fInheritedPathForListeners.isValid()) {
339 fInheritedPathForListeners.set(*that.fInheritedPathForListeners);
340 }
341}
static void * sk_careful_memcpy(void *dst, const void *src, size_t len)
Definition: SkMalloc.h:125
bool isValid() const
Definition: SkTLazy.h:77
T * set(const T &src)
Definition: SkTLazy.h:56
void reset(int count)
Definition: SkTemplates.h:195

Member Function Documentation

◆ addGenIDChangeListener()

void GrStyledShape::addGenIDChangeListener ( sk_sp< SkIDChangeListener listener) const

Adds a listener to the original path. Typically used to invalidate cached resources when a path is no longer in-use. If the shape started out as something other than a path, this does nothing.

Definition at line 311 of file GrStyledShape.cpp.

311 {
312 if (const auto* lp = this->originalPathForListeners()) {
313 SkPathPriv::AddGenIDChangeListener(*lp, std::move(listener));
314 }
315}
static void AddGenIDChangeListener(const SkPath &path, sk_sp< SkIDChangeListener > listener)
Definition: SkPathPriv.h:106

◆ applyStyle()

GrStyledShape GrStyledShape::applyStyle ( GrStyle::Apply  apply,
SkScalar  scale 
) const
inline

Returns a shape that has either applied the path effect or path effect and stroking information from this shape's style to its geometry. Scale is used when approximating the output geometry and typically is computed from the view matrix

Definition at line 150 of file GrStyledShape.h.

150 {
151 return GrStyledShape(*this, apply, scale);
152 }
static bool apply(Pass *pass, SkRecord *record)
const Scalar scale

◆ asLine()

bool GrStyledShape::asLine ( SkPoint  pts[2],
bool *  inverted 
) const

If the unstyled shape is a straight line segment, returns true and sets pts to the endpoints. An inverse filled line path is still considered a line.

Definition at line 453 of file GrStyledShape.cpp.

453 {
454 if (!fShape.isLine()) {
455 return false;
456 }
457
458 if (pts) {
459 pts[0] = fShape.line().fP1;
460 pts[1] = fShape.line().fP2;
461 }
462 if (inverted) {
463 *inverted = fShape.inverted();
464 }
465 return true;
466}
bool isLine() const
Definition: GrShape.h:90
GrLineSegment & line()
Definition: GrShape.h:146
bool inverted() const
Definition: GrShape.h:99
SkPoint fP2
Definition: GrShape.h:28
SkPoint fP1
Definition: GrShape.h:27

◆ asNestedRects()

bool GrStyledShape::asNestedRects ( SkRect  rects[2]) const

Definition at line 468 of file GrStyledShape.cpp.

468 {
469 if (!fShape.isPath()) {
470 return false;
471 }
472
473 // TODO: it would be better two store DRRects natively in the shape rather than converting
474 // them to a path and then reextracting the nested rects
475 if (fShape.path().isInverseFillType()) {
476 return false;
477 }
478
479 SkPathDirection dirs[2];
480 if (!SkPathPriv::IsNestedFillRects(fShape.path(), rects, dirs)) {
481 return false;
482 }
483
484 if (SkPathFillType::kWinding == fShape.path().getFillType() && dirs[0] == dirs[1]) {
485 // The two rects need to be wound opposite to each other
486 return false;
487 }
488
489 // Right now, nested rects where the margin is not the same width
490 // all around do not render correctly
491 const SkScalar* outer = rects[0].asScalars();
492 const SkScalar* inner = rects[1].asScalars();
493
494 bool allEq = true;
495
496 SkScalar margin = SkScalarAbs(outer[0] - inner[0]);
497 bool allGoE1 = margin >= SK_Scalar1;
498
499 for (int i = 1; i < 4; ++i) {
500 SkScalar temp = SkScalarAbs(outer[i] - inner[i]);
501 if (temp < SK_Scalar1) {
502 allGoE1 = false;
503 }
504 if (!SkScalarNearlyEqual(margin, temp)) {
505 allEq = false;
506 }
507 }
508
509 return allEq || allGoE1;
510}
SkPathDirection
Definition: SkPathTypes.h:34
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkScalarAbs(x)
Definition: SkScalar.h:39
bool isPath() const
Definition: GrShape.h:88
SkPath & path()
Definition: GrShape.h:140
static bool IsNestedFillRects(const SkPath &, SkRect rect[2], SkPathDirection dirs[2]=nullptr)
Definition: SkPath.cpp:3780
bool isInverseFillType() const
Definition: SkPath.h:244
SkPathFillType getFillType() const
Definition: SkPath.h:230
float SkScalar
Definition: extension.cpp:12
const float * asScalars() const
Definition: SkRect.h:1340

◆ asPath()

void GrStyledShape::asPath ( SkPath out) const
inline

Returns the unstyled geometry as a path.

Definition at line 173 of file GrStyledShape.h.

173 {
174 fShape.asPath(out, fStyle.isSimpleFill());
175 }
void asPath(SkPath *out, bool simpleFill=true) const
Definition: GrShape.cpp:423
bool isSimpleFill() const
Definition: GrStyle.h:114

◆ asRRect()

bool GrStyledShape::asRRect ( SkRRect rrect,
bool *  inverted 
) const

Returns the unstyled geometry as a rrect if possible.

Definition at line 437 of file GrStyledShape.cpp.

437 {
438 if (!fShape.isRRect() && !fShape.isRect()) {
439 return false;
440 }
441
442 if (rrect) {
443 *rrect = fShape.isRect() ? SkRRect::MakeRect(fShape.rect()) : fShape.rrect();
444 }
445
446 if (inverted) {
447 *inverted = fShape.inverted();
448 }
449
450 return true;
451}
SkRect & rect()
Definition: GrShape.h:134
bool isRRect() const
Definition: GrShape.h:87
bool isRect() const
Definition: GrShape.h:86
static SkRRect MakeRect(const SkRect &r)
Definition: SkRRect.h:149

◆ bounds()

SkRect GrStyledShape::bounds ( ) const
inline

Gets the bounds of the geometry without reflecting the shape's styling. This ignores the inverse fill nature of the geometry.

Definition at line 187 of file GrStyledShape.h.

187{ return fShape.bounds(); }
SkRect bounds() const
Definition: GrShape.cpp:367

◆ hasUnstyledKey()

bool GrStyledShape::hasUnstyledKey ( ) const
inline

Definition at line 259 of file GrStyledShape.h.

259{ return this->unstyledKeySize() >= 0; }
int unstyledKeySize() const

◆ inverseFilled()

bool GrStyledShape::inverseFilled ( ) const
inline

Is the pre-styled geometry inverse filled?

Definition at line 217 of file GrStyledShape.h.

217 {
218 // Since the path tracks inverted-fillness itself, it should match what was recorded.
219 SkASSERT(!fShape.isPath() || fShape.inverted() == fShape.path().isInverseFillType());
220 // Dashing ignores inverseness. We should have caught this earlier. skbug.com/5421
221 SkASSERT(!(fShape.inverted() && this->style().isDashed()));
222 return fShape.inverted();
223 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ isEmpty()

bool GrStyledShape::isEmpty ( ) const
inline

Returns whether the geometry is empty. Note that applying the style could produce a non-empty shape. It also may have an inverse fill.

Definition at line 181 of file GrStyledShape.h.

181{ return fShape.isEmpty(); }
bool isEmpty() const
Definition: GrShape.h:84

◆ isRect()

bool GrStyledShape::isRect ( ) const
inline

Definition at line 154 of file GrStyledShape.h.

154 {
155 // Should have simplified a rrect to a rect if possible already.
156 SkASSERT(!fShape.isRRect() || !fShape.rrect().isRect());
157 return fShape.isRect();
158 }
SkRRect & rrect()
Definition: GrShape.h:137
bool isRect() const
Definition: SkRRect.h:84

◆ knownDirection()

bool GrStyledShape::knownDirection ( ) const
inline

Does the shape have a known winding direction. Some degenerate convex shapes may not have a computable direction, but this is not always a requirement for path renderers so it is kept separate from knownToBeConvex().

Definition at line 209 of file GrStyledShape.h.

209 {
210 // Assuming this is called after knownToBeConvex(), this should just be relying on
211 // cached convexity and direction and will be cheap.
212 return !fShape.isPath() ||
214 }
static SkPathFirstDirection ComputeFirstDirection(const SkPath &)
Definition: SkPath.cpp:2627

◆ knownToBeClosed()

bool GrStyledShape::knownToBeClosed ( ) const
inline

Is it known that the unstyled geometry has no unclosed contours. This means that it will not have any caps if stroked (modulo the effect of any path effect).

Definition at line 243 of file GrStyledShape.h.

243 {
244 // This refers to the base shape and does not depend on invertedness.
245 return fShape.closed();
246 }
bool closed() const
Definition: GrShape.cpp:330

◆ knownToBeConvex()

bool GrStyledShape::knownToBeConvex ( ) const
inline

Is this shape known to be convex, before styling is applied. An unclosed but otherwise convex path is considered to be closed if they styling reflects a fill and not otherwise. This is because filling closes all contours in the path.

Definition at line 200 of file GrStyledShape.h.

200 {
201 return fShape.convex(fStyle.isSimpleFill());
202 }
bool convex(bool simpleFill=true) const
Definition: GrShape.cpp:348

◆ MakeArc()

GrStyledShape GrStyledShape::MakeArc ( const SkArc arc,
const GrStyle style,
DoSimplify  doSimplify = DoSimplify::kYes 
)
static

Definition at line 317 of file GrStyledShape.cpp.

319 {
321 result.fShape.setArc(
323 result.fStyle = style;
324 if (doSimplify == DoSimplify::kYes) {
325 result.simplify();
326 }
327 return result;
328}
GAsyncResult * result
Type fType
Definition: SkArc.h:62
SkScalar fSweepAngle
Definition: SkArc.h:60
SkScalar fStartAngle
Definition: SkArc.h:58
SkRect fOval
Definition: SkArc.h:55
static SkArc Make(const SkRect &oval, SkScalar startAngleDegrees, SkScalar sweepAngleDegrees, Type type)
Definition: SkArc.h:38
SkRect makeSorted() const
Definition: SkRect.h:1330

◆ MakeFilled()

GrStyledShape GrStyledShape::MakeFilled ( const GrStyledShape original,
FillInversion  inversion = FillInversion::kPreserve 
)
static

Makes a filled shape from the pre-styled original shape and optionally modifies whether the fill is inverted or not. It's important to note that the original shape's geometry may already have been modified if doing so was neutral with respect to its style (e.g. filled paths are always closed when stored in a shape and dashed paths are always made non-inverted since dashing ignores inverseness).

Definition at line 56 of file GrStyledShape.cpp.

56 {
57 bool newIsInverted = is_inverted(original.fShape.inverted(), inversion);
58 if (original.style().isSimpleFill() && newIsInverted == original.fShape.inverted()) {
59 // By returning the original rather than falling through we can preserve any inherited style
60 // key. Otherwise, we wipe it out below since the style change invalidates it.
61 return original;
62 }
64 SkASSERT(result.fStyle.isSimpleFill());
65 if (original.fInheritedPathForListeners.isValid()) {
66 result.fInheritedPathForListeners.set(*original.fInheritedPathForListeners);
67 }
68
69 result.fShape = original.fShape;
70 result.fGenID = original.fGenID;
71 result.fShape.setInverted(newIsInverted);
72
73 if (!original.style().isSimpleFill()) {
74 // Going from a non-filled style to fill may allow additional simplifications (e.g.
75 // closing an open rect that wasn't closed in the original shape because it had
76 // stroke style).
77 result.simplify();
78 // The above simplify() call only sets simplified to true if its geometry was changed,
79 // since it already sees its style as a simple fill. Since the original style was not a
80 // simple fill, MakeFilled always simplifies.
81 result.fSimplified = true;
82 }
83
84 // Verify that lines/points were converted to empty by the style change
85 SkASSERT((!original.fShape.isLine() && !original.fShape.isPoint()) || result.fShape.isEmpty());
86
87 // We don't copy the inherited key since it can contain path effect information that we just
88 // stripped.
89 return result;
90}
static bool inversion(Vertex *prev, Vertex *next, Edge *origEdge, const Comparator &c)
static bool is_inverted(bool originalIsInverted, GrStyledShape::FillInversion inversion)
bool isPoint() const
Definition: GrShape.h:85

◆ mayBeInverseFilledAfterStyling()

bool GrStyledShape::mayBeInverseFilledAfterStyling ( ) const
inline

Might applying the styling to the geometry produce an inverse fill. The "may" part comes in because an arbitrary path effect could produce an inverse filled path. In other cases this can be thought of as "inverseFilledAfterStyling()".

Definition at line 230 of file GrStyledShape.h.

230 {
231 // An arbitrary path effect can produce an arbitrary output path, which may be inverse
232 // filled.
233 if (this->style().hasNonDashPathEffect()) {
234 return true;
235 }
236 return this->inverseFilled();
237 }
bool inverseFilled() const

◆ operator=()

GrStyledShape & GrStyledShape::operator= ( const GrStyledShape that)

Definition at line 25 of file GrStyledShape.cpp.

25 {
26 fShape = that.fShape;
27 fStyle = that.fStyle;
28 fGenID = that.fGenID;
29 fSimplified = that.fSimplified;
30
31 fInheritedKey.reset(that.fInheritedKey.count());
32 sk_careful_memcpy(fInheritedKey.get(), that.fInheritedKey.get(),
33 sizeof(uint32_t) * fInheritedKey.count());
34 if (that.fInheritedPathForListeners.isValid()) {
35 fInheritedPathForListeners.set(*that.fInheritedPathForListeners);
36 } else {
37 fInheritedPathForListeners.reset();
38 }
39 return *this;
40}
void reset()
Definition: SkTLazy.h:69

◆ segmentMask()

uint32_t GrStyledShape::segmentMask ( ) const
inline

Definition at line 248 of file GrStyledShape.h.

248 {
249 // This refers to the base shape and does not depend on invertedness.
250 return fShape.segmentMask();
251 }
uint32_t segmentMask() const
Definition: GrShape.cpp:393

◆ simplified()

bool GrStyledShape::simplified ( ) const
inline

Definition at line 143 of file GrStyledShape.h.

143{ return fSimplified; }

◆ simplify()

void GrStyledShape::simplify ( )

Similar to GrShape::simplify but also takes into account style and stroking, possibly applying the style explicitly to produce a new analytic shape with a simpler style. Unless "doSimplify" is kNo, this method gets called automatically during construction.

Definition at line 529 of file GrStyledShape.cpp.

529 {
530 AutoRestoreInverseness ari(&fShape, fStyle);
531
532 unsigned simplifyFlags = 0;
533 if (fStyle.isSimpleFill()) {
534 simplifyFlags = GrShape::kAll_Flags;
535 } else if (!fStyle.hasPathEffect()) {
536 // Everything but arcs with caps that might extend beyond the oval edge can ignore winding
537 if (!fShape.isArc() || fStyle.strokeRec().getCap() == SkPaint::kButt_Cap) {
538 simplifyFlags |= GrShape::kIgnoreWinding_Flag;
539 }
540 simplifyFlags |= GrShape::kMakeCanonical_Flag;
541 } // else if there's a path effect, every destructive simplification is disabledd
542
543 // Remember if the original shape was closed; in the event we simplify to a point or line
544 // because of degenerate geometry, we need to update joins and caps.
545 GrShape::Type oldType = fShape.type();
546 fClosed = fShape.simplify(simplifyFlags);
547 fSimplified = oldType != fShape.type();
548
549 if (fShape.isPath()) {
550 // The shape remains a path, so configure the gen ID and canonicalize fill type if possible
551 if (fInheritedKey.count() || fShape.path().isVolatile()) {
552 fGenID = 0;
553 } else {
554 fGenID = fShape.path().getGenerationID();
555 }
556 if (!fStyle.hasNonDashPathEffect() &&
559 fShape.path().isConvex())) {
560 // Stroke styles don't differentiate between winding and even/odd. There is no
561 // distinction between even/odd and non-zero winding count for convex paths.
562 // Moreover, dashing ignores inverseness (skbug.com/5421)
564 }
565 } else {
566 fInheritedKey.reset(0);
567 // Whenever we simplify to a non-path, break the chain so we no longer refer to the
568 // original path. This prevents attaching genID listeners to temporary paths created when
569 // drawing simple shapes.
570 fInheritedPathForListeners.reset();
571 // Further simplifications to the shape based on the style
572 this->simplifyStroke();
573 }
574}
Type type() const
Definition: GrShape.h:92
@ kMakeCanonical_Flag
Definition: GrShape.h:203
@ kIgnoreWinding_Flag
Definition: GrShape.h:200
@ kAll_Flags
Definition: GrShape.h:205
static constexpr SkPathFillType kDefaultFillType
Definition: GrShape.h:63
bool isArc() const
Definition: GrShape.h:89
bool simplify(unsigned flags=kAll_Flags)
Definition: GrShape.cpp:244
bool hasPathEffect() const
Definition: GrStyle.h:122
bool hasNonDashPathEffect() const
Definition: GrStyle.h:124
const SkStrokeRec & strokeRec() const
Definition: GrStyle.h:140
@ kButt_Cap
no stroke extension
Definition: SkPaint.h:334
uint32_t getGenerationID() const
Definition: SkPath.cpp:366
void setFillType(SkPathFillType ft)
Definition: SkPath.h:235
bool isVolatile() const
Definition: SkPath.h:350
bool isConvex() const
Definition: SkPath.cpp:426
Style getStyle() const
Definition: SkStrokeRec.cpp:71
SkPaint::Cap getCap() const
Definition: SkStrokeRec.h:44

◆ style()

const GrStyle & GrStyledShape::style ( ) const
inline

Definition at line 140 of file GrStyledShape.h.

140{ return fStyle; }

◆ styledBounds()

SkRect GrStyledShape::styledBounds ( ) const

Gets the bounds of the geometry reflecting the shape's styling (ignoring inverse fill status).

Definition at line 92 of file GrStyledShape.cpp.

92 {
93 if (this->isEmpty() && !fStyle.hasNonDashPathEffect()) {
94 return SkRect::MakeEmpty();
95 }
96
98 fStyle.adjustBounds(&bounds, this->bounds());
99 return bounds;
100}
void adjustBounds(SkRect *dst, const SkRect &src) const
Definition: GrStyle.h:173
bool isEmpty() const
SkRect bounds() const
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595

◆ testingOnly_getOriginalGenerationID()

uint32_t GrStyledShape::testingOnly_getOriginalGenerationID ( ) const

Helpers that are only exposed for unit tests, to determine if the shape is a path, and get the generation ID of the original path. This is the path that will receive GenIDChangeListeners added to this shape.

Definition at line 50 of file GrStyledShapeTest.cpp.

50 {
51 if (const auto* lp = this->originalPathForListeners()) {
52 return lp->getGenerationID();
53 }
54 return SkPath().getGenerationID();
55}
Definition: SkPath.h:59

◆ testingOnly_isNonVolatilePath()

bool GrStyledShape::testingOnly_isNonVolatilePath ( ) const

Definition at line 61 of file GrStyledShapeTest.cpp.

61 {
62 return fShape.isPath() && !fShape.path().isVolatile();
63}

◆ testingOnly_isPath()

bool GrStyledShape::testingOnly_isPath ( ) const

Definition at line 57 of file GrStyledShapeTest.cpp.

57 {
58 return fShape.isPath();
59}

◆ unstyledKeySize()

int GrStyledShape::unstyledKeySize ( ) const

Gets the size of the key for the shape represented by this GrStyledShape (ignoring its styling). A negative value is returned if the shape has no key (shouldn't be cached).

Definition at line 144 of file GrStyledShape.cpp.

144 {
145 if (fInheritedKey.count()) {
146 return fInheritedKey.count();
147 }
148
149 int count = 1; // Every key has the state flags from the GrShape
150 switch(fShape.type()) {
152 static_assert(0 == sizeof(SkPoint) % sizeof(uint32_t));
153 count += sizeof(SkPoint) / sizeof(uint32_t);
154 break;
156 static_assert(0 == sizeof(SkRect) % sizeof(uint32_t));
157 count += sizeof(SkRect) / sizeof(uint32_t);
158 break;
160 static_assert(0 == SkRRect::kSizeInMemory % sizeof(uint32_t));
161 count += SkRRect::kSizeInMemory / sizeof(uint32_t);
162 break;
164 static_assert(0 == sizeof(SkArc) % sizeof(uint32_t));
165 count += sizeof(SkArc) / sizeof(uint32_t);
166 break;
168 static_assert(0 == sizeof(GrLineSegment) % sizeof(uint32_t));
169 count += sizeof(GrLineSegment) / sizeof(uint32_t);
170 break;
172 if (0 == fGenID) {
173 return -1; // volatile, so won't be keyed
174 }
175 int dataKeySize = path_key_from_data_size(fShape.path());
176 if (dataKeySize >= 0) {
177 count += dataKeySize;
178 } else {
179 count++; // Just adds the gen ID.
180 }
181 break; }
182 default:
183 // else it's empty, which just needs the state flags for its key
184 SkASSERT(fShape.isEmpty());
185 }
186 return count;
187}
int count
Definition: FontMgrTest.cpp:50
static int path_key_from_data_size(const SkPath &path)
static constexpr size_t kSizeInMemory
Definition: SkRRect.h:422
Definition: SkArc.h:15

◆ writeUnstyledKey()

void GrStyledShape::writeUnstyledKey ( uint32_t *  key) const

Writes unstyledKeySize() bytes into the provided pointer. Assumes that there is enough space allocated for the key and that unstyledKeySize() does not return a negative value for this shape.

Definition at line 189 of file GrStyledShape.cpp.

189 {
190 SkASSERT(this->unstyledKeySize());
191 SkDEBUGCODE(uint32_t* origKey = key;)
192 if (fInheritedKey.count()) {
193 memcpy(key, fInheritedKey.get(), sizeof(uint32_t) * fInheritedKey.count());
194 SkDEBUGCODE(key += fInheritedKey.count();)
195 } else {
196 // Dir and start are only used for rect and rrect shapes, so are not included in other
197 // shape type keys. Make sure that they are the defaults for other shapes so it doesn't
198 // matter that we universally include them in the flag key value.
199 SkASSERT((fShape.isRect() || fShape.isRRect()) ||
200 (fShape.dir() == GrShape::kDefaultDir &&
202
203 // Every key starts with the state from the GrShape (this includes path fill type,
204 // and any tracked winding, start, inversion, as well as the class of geometry).
205 *key++ = fShape.stateKey();
206
207 switch(fShape.type()) {
209 SkASSERT(fGenID != 0);
210 // Ensure that the path's inversion matches our state so that the path's key suffices.
211 SkASSERT(fShape.inverted() == fShape.path().isInverseFillType());
212
213 int dataKeySize = path_key_from_data_size(fShape.path());
214 if (dataKeySize >= 0) {
216 return;
217 } else {
218 *key++ = fGenID;
219 }
220 break; }
222 memcpy(key, &fShape.point(), sizeof(SkPoint));
223 key += sizeof(SkPoint) / sizeof(uint32_t);
224 break;
226 memcpy(key, &fShape.rect(), sizeof(SkRect));
227 key += sizeof(SkRect) / sizeof(uint32_t);
228 break;
230 fShape.rrect().writeToMemory(key);
231 key += SkRRect::kSizeInMemory / sizeof(uint32_t);
232 break;
234 // Write dense floats first
235 memcpy(key, &fShape.arc(), sizeof(SkRect) + 2 * sizeof(float));
236 key += (sizeof(SkArc) / sizeof(uint32_t) - 1);
237 // Then write the final bool as an int, to make sure upper bits are set
238 *key++ = fShape.arc().isWedge() ? 1 : 0;
239 break;
241 memcpy(key, &fShape.line(), sizeof(GrLineSegment));
242 key += sizeof(GrLineSegment) / sizeof(uint32_t);
243 break;
244 default:
245 // Nothing other than the flag state is needed in the key for an empty shape
246 SkASSERT(fShape.isEmpty());
247 }
248 }
249 SkASSERT(key - origKey == this->unstyledKeySize());
250}
static void write_path_key_from_data(const SkPath &path, uint32_t *origKey)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
uint32_t stateKey() const
Definition: GrShape.cpp:49
SkArc & arc()
Definition: GrShape.h:143
SkPathDirection dir() const
Definition: GrShape.h:105
static constexpr SkPathDirection kDefaultDir
Definition: GrShape.h:60
unsigned startIndex() const
Definition: GrShape.h:108
static constexpr unsigned kDefaultStart
Definition: GrShape.h:61
SkPoint & point()
Definition: GrShape.h:131
size_t writeToMemory(void *buffer) const
Definition: SkRRect.cpp:599
bool isWedge() const
Definition: SkArc.h:28

Member Data Documentation

◆ kMaxKeyFromDataVerbCnt

constexpr int GrStyledShape::kMaxKeyFromDataVerbCnt = 10
inlinestaticconstexpr

Definition at line 53 of file GrStyledShape.h.


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