Pack and align SkStrokeRec to 4-byte boundary.
The new key for the distance field path cache will contain an SkStrokeRec. This change guarantees that we don't have any hidden padding that has garbage values, thereby preventing apparently equal keys from hashing to two different values. This also has the nice effect of reducing the size of SkStrokeRec from 24 bytes to 16 bytes. Review URL: https://codereview.chromium.org/1465773003
This commit is contained in:
parent
179a8f5f7f
commit
897c993763
@ -35,8 +35,8 @@ public:
|
|||||||
Style getStyle() const;
|
Style getStyle() const;
|
||||||
SkScalar getWidth() const { return fWidth; }
|
SkScalar getWidth() const { return fWidth; }
|
||||||
SkScalar getMiter() const { return fMiterLimit; }
|
SkScalar getMiter() const { return fMiterLimit; }
|
||||||
SkPaint::Cap getCap() const { return fCap; }
|
SkPaint::Cap getCap() const { return (SkPaint::Cap)fCap; }
|
||||||
SkPaint::Join getJoin() const { return fJoin; }
|
SkPaint::Join getJoin() const { return (SkPaint::Join)fJoin; }
|
||||||
|
|
||||||
bool isHairlineStyle() const {
|
bool isHairlineStyle() const {
|
||||||
return kHairline_Style == this->getStyle();
|
return kHairline_Style == this->getStyle();
|
||||||
@ -115,9 +115,15 @@ private:
|
|||||||
SkScalar fResScale;
|
SkScalar fResScale;
|
||||||
SkScalar fWidth;
|
SkScalar fWidth;
|
||||||
SkScalar fMiterLimit;
|
SkScalar fMiterLimit;
|
||||||
SkPaint::Cap fCap;
|
// The following three members are packed together into a single u32.
|
||||||
SkPaint::Join fJoin;
|
// This is to avoid unnecessary padding and ensure binary equality for
|
||||||
bool fStrokeAndFill;
|
// hashing (because the padded areas might contain garbage values).
|
||||||
|
//
|
||||||
|
// fCap and fJoin are larger than needed to avoid having to initialize
|
||||||
|
// any pad values
|
||||||
|
uint32_t fCap : 16; // SkPaint::Cap
|
||||||
|
uint32_t fJoin : 15; // SkPaint::Join
|
||||||
|
uint32_t fStrokeAndFill : 1; // bool
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -108,8 +108,8 @@ bool SkStrokeRec::applyToPath(SkPath* dst, const SkPath& src) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkStroke stroker;
|
SkStroke stroker;
|
||||||
stroker.setCap(fCap);
|
stroker.setCap((SkPaint::Cap)fCap);
|
||||||
stroker.setJoin(fJoin);
|
stroker.setJoin((SkPaint::Join)fJoin);
|
||||||
stroker.setMiterLimit(fMiterLimit);
|
stroker.setMiterLimit(fMiterLimit);
|
||||||
stroker.setWidth(fWidth);
|
stroker.setWidth(fWidth);
|
||||||
stroker.setDoFill(fStrokeAndFill);
|
stroker.setDoFill(fStrokeAndFill);
|
||||||
@ -131,6 +131,6 @@ void SkStrokeRec::applyToPaint(SkPaint* paint) const {
|
|||||||
paint->setStyle(fStrokeAndFill ? SkPaint::kStrokeAndFill_Style : SkPaint::kStroke_Style);
|
paint->setStyle(fStrokeAndFill ? SkPaint::kStrokeAndFill_Style : SkPaint::kStroke_Style);
|
||||||
paint->setStrokeWidth(fWidth);
|
paint->setStrokeWidth(fWidth);
|
||||||
paint->setStrokeMiter(fMiterLimit);
|
paint->setStrokeMiter(fMiterLimit);
|
||||||
paint->setStrokeCap(fCap);
|
paint->setStrokeCap((SkPaint::Cap)fCap);
|
||||||
paint->setStrokeJoin(fJoin);
|
paint->setStrokeJoin((SkPaint::Join)fJoin);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user