From: robertphillips@google.com Date: Tue, 7 Aug 2012 17:32:51 +0000 (+0000) Subject: Adding storage of SkPath::fIsOval X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~15260 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2972bb5fd2441709026b350c6b9b66eecd80f868;p=platform%2Fupstream%2FlibSkiaSharp.git Adding storage of SkPath::fIsOval http://codereview.appspot.com/6453085/ git-svn-id: http://skia.googlecode.com/svn/trunk@4991 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index 22d3d86..4483388 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -1709,7 +1709,9 @@ uint32_t SkPath::writeToMemory(void* storage) const { SkWBuffer buffer(storage); buffer.write32(fPts.count()); buffer.write32(fVerbs.count()); - buffer.write32((fFillType << 8) | fSegmentMask); + int32_t packed = (fIsOval << 24) | (fConvexity << 16) | + (fFillType << 8) | fSegmentMask; + buffer.write32(packed); buffer.write(fPts.begin(), sizeof(SkPoint) * fPts.count()); buffer.write(fVerbs.begin(), fVerbs.count()); buffer.padToAlign4(); @@ -1721,7 +1723,7 @@ uint32_t SkPath::readFromMemory(const void* storage) { fPts.setCount(buffer.readS32()); fVerbs.setCount(buffer.readS32()); uint32_t packed = buffer.readS32(); - fFillType = packed >> 8; + fFillType = (packed >> 8) & 0xFF; fSegmentMask = packed & 0xFF; buffer.read(fPts.begin(), sizeof(SkPoint) * fPts.count()); buffer.read(fVerbs.begin(), fVerbs.count()); @@ -1729,6 +1731,9 @@ uint32_t SkPath::readFromMemory(const void* storage) { 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/tests/PathTest.cpp b/tests/PathTest.cpp index 79b79b3..8c00efb 100644 --- a/tests/PathTest.cpp +++ b/tests/PathTest.cpp @@ -752,6 +752,31 @@ static void test_isRect(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); } +static void write_and_read_back(skiatest::Reporter* reporter, + const SkPath& p) { + SkWriter32 writer(100); + writer.writePath(p); + size_t size = writer.size(); + SkAutoMalloc storage(size); + writer.flatten(storage.get()); + SkReader32 reader(storage.get(), size); + + SkPath readBack; + REPORTER_ASSERT(reporter, readBack != p); + reader.readPath(&readBack); + REPORTER_ASSERT(reporter, readBack == p); + + REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() == + p.getConvexityOrUnknown()); + + REPORTER_ASSERT(reporter, readBack.isOval(NULL) == p.isOval(NULL)); + + const SkRect& origBounds = p.getBounds(); + const SkRect& readBackBounds = readBack.getBounds(); + + REPORTER_ASSERT(reporter, origBounds == readBackBounds); +} + static void test_flattening(skiatest::Reporter* reporter) { SkPath p; @@ -766,17 +791,7 @@ static void test_flattening(skiatest::Reporter* reporter) { p.quadTo(pts[2], pts[3]); p.cubicTo(pts[4], pts[5], pts[6]); - SkWriter32 writer(100); - writer.writePath(p); - size_t size = writer.size(); - SkAutoMalloc storage(size); - writer.flatten(storage.get()); - SkReader32 reader(storage.get(), size); - - SkPath p1; - REPORTER_ASSERT(reporter, p1 != p); - reader.readPath(&p1); - REPORTER_ASSERT(reporter, p1 == p); + write_and_read_back(reporter, p); // create a buffer that should be much larger than the path so we don't // kill our stack if writer goes too far. @@ -794,6 +809,15 @@ static void test_flattening(skiatest::Reporter* reporter) { size3 = p2.writeToMemory(buffer2); REPORTER_ASSERT(reporter, size1 == size3); REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0); + + // test persistence of the oval flag & convexity + { + SkPath oval; + SkRect rect = SkRect::MakeWH(10, 10); + oval.addOval(rect); + + write_and_read_back(reporter, oval); + } } static void test_transform(skiatest::Reporter* reporter) {