Improved SkPath packing

sizeof(SkPath): 24 -> 16 (on 64bit)

Change-Id: Iea0d363b70209eb984c816f9fba59c461fe42cec
Reviewed-on: https://skia-review.googlesource.com/154041
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Florin Malita 2018-09-12 14:30:13 -04:00 committed by Mike Klein
parent 858f648bda
commit d661474866
2 changed files with 22 additions and 8 deletions

View File

@ -1674,11 +1674,11 @@ public:
private:
sk_sp<SkPathRef> fPathRef;
int fLastMoveToIndex;
uint8_t fFillType;
mutable SkAtomic<Convexity, sk_memory_order_relaxed> fConvexity;
mutable SkAtomic<uint8_t, sk_memory_order_relaxed> fFirstDirection;// SkPathPriv::FirstDirection
bool fIsVolatile;
bool fIsBadForDAA = false;
mutable SkAtomic<uint8_t, sk_memory_order_relaxed> fFirstDirection; // SkPathPriv::FirstDirection
uint8_t fFillType : 2; // SkPath::Convexity
uint8_t fIsVolatile : 1;
uint8_t fIsBadForDAA : 1;
/** Resets all fields other than fPathRef to their initial 'empty' values.
* Assumes the caller has already emptied fPathRef.

View File

@ -25,6 +25,15 @@
#include <cmath>
#include <utility>
struct SkPath_Storage_Equivalent {
void* fPtr;
int32_t fIndex;
uint32_t fFlags;
};
static_assert(sizeof(SkPath) == sizeof(SkPath_Storage_Equivalent),
"Please keep an eye on SkPath packing.");
static float poly_eval(float A, float B, float C, float t) {
return (A * t + B) * t + C;
}
@ -203,11 +212,16 @@ bool operator==(const SkPath& a, const SkPath& b) {
void SkPath::swap(SkPath& that) {
if (this != &that) {
using std::swap;
fPathRef.swap(that.fPathRef);
swap(fLastMoveToIndex, that.fLastMoveToIndex);
swap(fFillType, that.fFillType);
swap(fIsVolatile, that.fIsVolatile);
std::swap(fLastMoveToIndex, that.fLastMoveToIndex);
const auto ft = fFillType;
fFillType = that.fFillType;
that.fFillType = ft;
const auto iv = fIsVolatile;
fIsVolatile = that.fIsVolatile;
that.fIsVolatile = iv;
// Non-atomic swaps of atomic values.
Convexity c = fConvexity.load();