Fix SkPath::reverseAddPath and fuzzing of SkPath enums

Bug: 882423
Change-Id: I2be2863574a5951b86e4d5e213094efee6081098
Reviewed-on: https://skia-review.googlesource.com/154300
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2018-09-13 08:22:15 -04:00 committed by Skia Commit-Bot
parent 637c06aec7
commit 8051d38358
2 changed files with 42 additions and 18 deletions

View File

@ -83,24 +83,33 @@ void FuzzPath(Fuzz* fuzz, SkPath* path, int maxOps) {
path->close(); path->close();
break; break;
case 13: case 13:
fuzz->next(&r, &dir); fuzz->next(&r);
fuzz->nextRange(&ui, 0, 1);
dir = static_cast<SkPath::Direction>(ui);
path->addRect(r, dir); path->addRect(r, dir);
break; break;
case 14: case 14:
fuzz->next(&r, &dir, &ui); fuzz->nextRange(&ui, 0, 1);
dir = static_cast<SkPath::Direction>(ui);
fuzz->next(&r, &ui);
path->addRect(r, dir, ui); path->addRect(r, dir, ui);
break; break;
case 15: case 15:
fuzz->next(&r, &dir); fuzz->nextRange(&ui, 0, 1);
dir = static_cast<SkPath::Direction>(ui);
fuzz->next(&r);
path->addOval(r, dir); path->addOval(r, dir);
break; break;
case 16: case 16:
fuzz->next(&r, &dir, &ui); fuzz->nextRange(&ui, 0, 1);
dir = static_cast<SkPath::Direction>(ui);
fuzz->next(&r, &ui);
path->addOval(r, dir, ui); path->addOval(r, dir, ui);
break; break;
case 17: case 17:
fuzz->nextRange(&ui, 0, 1);
dir = static_cast<SkPath::Direction>(ui);
fuzz_nice_float(fuzz, &a, &b, &c); fuzz_nice_float(fuzz, &a, &b, &c);
fuzz->next(&dir);
path->addCircle(a, b, c, dir); path->addCircle(a, b, c, dir);
break; break;
case 18: case 18:
@ -110,27 +119,35 @@ void FuzzPath(Fuzz* fuzz, SkPath* path, int maxOps) {
break; break;
case 19: case 19:
fuzz_nice_float(fuzz, &a, &b); fuzz_nice_float(fuzz, &a, &b);
fuzz->next(&r, &dir); fuzz->next(&r);
fuzz->nextRange(&ui, 0, 1);
dir = static_cast<SkPath::Direction>(ui);
path->addRoundRect(r, a, b, dir); path->addRoundRect(r, a, b, dir);
break; break;
case 20: case 20:
fuzz->next(&rr, &dir); fuzz->next(&rr);
fuzz->nextRange(&ui, 0, 1);
dir = static_cast<SkPath::Direction>(ui);
path->addRRect(rr, dir); path->addRRect(rr, dir);
break; break;
case 21: case 21:
fuzz->next(&rr, &dir, &ui); fuzz->nextRange(&ui, 0, 1);
dir = static_cast<SkPath::Direction>(ui);
fuzz->next(&rr, &ui);
path->addRRect(rr, dir, ui); path->addRRect(rr, dir, ui);
break; break;
case 22: { case 22: {
SkPath::AddPathMode mode; fuzz->nextRange(&ui, 0, 1);
fuzz->next(&m, &mode); SkPath::AddPathMode mode = static_cast<SkPath::AddPathMode>(ui);
fuzz->next(&m);
FuzzPath(fuzz, &p, maxOps-1); FuzzPath(fuzz, &p, maxOps-1);
path->addPath(p, m, mode); path->addPath(p, m, mode);
break; break;
} }
case 23: { case 23: {
SkPath::AddPathMode mode; fuzz->nextRange(&ui, 0, 1);
fuzz->next(&m, &mode); SkPath::AddPathMode mode = static_cast<SkPath::AddPathMode>(ui);
fuzz->next(&m);
path->addPath(*path, m, mode); path->addPath(*path, m, mode);
break; break;
} }

View File

@ -1708,14 +1708,21 @@ SkPath& SkPath::reversePathTo(const SkPath& path) {
return *this; return *this;
} }
SkPath& SkPath::reverseAddPath(const SkPath& src) { SkPath& SkPath::reverseAddPath(const SkPath& srcPath) {
SkPathRef::Editor ed(&fPathRef, src.fPathRef->countPoints(), src.fPathRef->countVerbs()); // Detect if we're trying to add ourself
const SkPath* src = &srcPath;
SkTLazy<SkPath> tmp;
if (this == src) {
src = tmp.set(srcPath);
}
const SkPoint* pts = src.fPathRef->pointsEnd(); SkPathRef::Editor ed(&fPathRef, src->fPathRef->countPoints(), src->fPathRef->countVerbs());
const SkPoint* pts = src->fPathRef->pointsEnd();
// we will iterator through src's verbs backwards // we will iterator through src's verbs backwards
const uint8_t* verbs = src.fPathRef->verbsMemBegin(); // points at the last verb const uint8_t* verbs = src->fPathRef->verbsMemBegin(); // points at the last verb
const uint8_t* verbsEnd = src.fPathRef->verbs(); // points just past the first verb const uint8_t* verbsEnd = src->fPathRef->verbs(); // points just past the first verb
const SkScalar* conicWeights = src.fPathRef->conicWeightsEnd(); const SkScalar* conicWeights = src->fPathRef->conicWeightsEnd();
bool needMove = true; bool needMove = true;
bool needClose = false; bool needClose = false;