зеркало из https://github.com/mozilla/moz-skia.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
This commit is contained in:
Родитель
9d696c0d04
Коммит
2972bb5fd2
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче