Fix bound returned by SkPath::isRect when the path contains a trailing moveTo
Oddly enough this was fixed in: https://codereview.chromium.org/16950021/ (add rect-output parameter to isRect, allowing us to return the correct bounds even if a rectagular path has a trailing moveTo) but was reverted here: https://skia.googlesource.com/skia/+/8fd160350ca5f57fbb1b2e03383c5778414a9b48 since it appeared to be crashing Chrome's trybots. I think it just fell through the cracks after that. If this sticks I will land a follow on patch for the stroke issue reported in the original bug (crbug.com/247770). BUG=247770,445368 Review URL: https://codereview.chromium.org/834483002
This commit is contained in:
parent
40d4bd8daf
commit
fe7c427e3d
@ -538,11 +538,20 @@ bool SkPath::isRect(SkRect* rect) const {
|
||||
SkDEBUGCODE(this->validate();)
|
||||
int currVerb = 0;
|
||||
const SkPoint* pts = fPathRef->points();
|
||||
bool result = isRectContour(false, &currVerb, &pts, NULL, NULL);
|
||||
if (result && rect) {
|
||||
*rect = getBounds();
|
||||
const SkPoint* first = pts;
|
||||
bool isClosed;
|
||||
if (!this->isRectContour(false, &currVerb, &pts, &isClosed, NULL)) {
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
if (rect) {
|
||||
if (isClosed) {
|
||||
rect->set(first, SkToS32(pts - first));
|
||||
} else {
|
||||
// 'pts' isn't updated for open rects
|
||||
*rect = this->getBounds();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkPath::isRect(bool* isClosed, Direction* direction) const {
|
||||
|
@ -3712,6 +3712,20 @@ DEF_TEST(Paths, reporter) {
|
||||
p.addRect(bounds);
|
||||
REPORTER_ASSERT(reporter, !p.isRect(NULL));
|
||||
|
||||
// Test an edge case w.r.t. the bound returned by isRect (i.e., the
|
||||
// path has a trailing moveTo. Please see crbug.com\445368)
|
||||
{
|
||||
SkRect r;
|
||||
p.reset();
|
||||
p.addRect(bounds);
|
||||
REPORTER_ASSERT(reporter, p.isRect(&r));
|
||||
REPORTER_ASSERT(reporter, r == bounds);
|
||||
// add a moveTo outside of our bounds
|
||||
p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10);
|
||||
REPORTER_ASSERT(reporter, p.isRect(&r));
|
||||
REPORTER_ASSERT(reporter, r == bounds);
|
||||
}
|
||||
|
||||
test_operatorEqual(reporter);
|
||||
test_isLine(reporter);
|
||||
test_isRect(reporter);
|
||||
|
Loading…
Reference in New Issue
Block a user