diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-17 10:58:49 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-17 10:58:49 +0000 |
commit | 01ec2eb42e9c64f8d06afd51f80c055710147141 (patch) | |
tree | c599956d7d00e3795317abb4ae4f0a35ce0a3395 /src | |
parent | 24a93569abbd53917548f54f236d1e92795306a7 (diff) |
Added Serialization of SkPath's bound
http://codereview.appspot.com/6458143/
git-svn-id: http://skia.googlecode.com/svn/trunk@5143 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPath.cpp | 38 | ||||
-rw-r--r-- | src/core/SkPicture.cpp | 3 |
2 files changed, 31 insertions, 10 deletions
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index 4be1c986fe..674ba980f6 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -1721,18 +1721,33 @@ uint32_t SkPath::writeToMemory(void* storage) const { if (NULL == storage) { const int byteCount = 3 * sizeof(int32_t) + sizeof(SkPoint) * fPts.count() - + sizeof(uint8_t) * fVerbs.count(); + + sizeof(uint8_t) * fVerbs.count() + + sizeof(SkRect); return SkAlign4(byteCount); } SkWBuffer buffer(storage); buffer.write32(fPts.count()); buffer.write32(fVerbs.count()); - int32_t packed = (fIsOval << 24) | (fConvexity << 16) | - (fFillType << 8) | fSegmentMask; + + // Call getBounds() to ensure (as a side-effect) that fBounds + // and fIsFinite are computed. + const SkRect& bounds = this->getBounds(); + SkASSERT(!fBoundsIsDirty); + + int32_t packed = ((fIsFinite & 1) << kIsFinite_SerializationShift) | + ((fIsOval & 1) << kIsOval_SerializationShift) | + (fConvexity << kConvexity_SerializationShift) | + (fFillType << kFillType_SerializationShift) | + (fSegmentMask << kSegmentMask_SerializationShift); + buffer.write32(packed); + buffer.write(fPts.begin(), sizeof(SkPoint) * fPts.count()); buffer.write(fVerbs.begin(), fVerbs.count()); + + buffer.write(&bounds, sizeof(bounds)); + buffer.padToAlign4(); return buffer.pos(); } @@ -1741,18 +1756,23 @@ uint32_t SkPath::readFromMemory(const void* storage) { SkRBuffer buffer(storage); fPts.setCount(buffer.readS32()); fVerbs.setCount(buffer.readS32()); + uint32_t packed = buffer.readS32(); - fFillType = (packed >> 8) & 0xFF; - fSegmentMask = packed & 0xFF; + fIsFinite = (packed >> kIsFinite_SerializationShift) & 1; + fIsOval = (packed >> kIsOval_SerializationShift) & 1; + fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF; + fFillType = (packed >> kFillType_SerializationShift) & 0xFF; + fSegmentMask = (packed >> kSegmentMask_SerializationShift) & 0xFF; + buffer.read(fPts.begin(), sizeof(SkPoint) * fPts.count()); buffer.read(fVerbs.begin(), fVerbs.count()); + + buffer.read(&fBounds, sizeof(fBounds)); + fBoundsIsDirty = false; + buffer.skipToAlign4(); GEN_ID_INC; - DIRTY_AFTER_EDIT; - // DIRTY_AFTER_EDIT resets fIsOval and fConvexity - fIsOval = packed >> 24; - fConvexity = (packed >> 16) & 0xFF; SkDEBUGCODE(this->validate();) return buffer.pos(); diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 9f606f736d..70e329efea 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -200,7 +200,8 @@ void SkPicture::draw(SkCanvas* surface) { // V3 : PictInfo tag at beginning, and EOF tag at the end // V4 : move SkPictInfo to be the header // V5 : don't read/write FunctionPtr on cross-process (we can detect that) -#define PICTURE_VERSION 5 +// V6 : added serialization of SkPath's bounds (and packed its flags tighter) +#define PICTURE_VERSION 6 SkPicture::SkPicture(SkStream* stream) : SkRefCnt() { fRecord = NULL; |