change SkRect::growToInclude to take a point instead of x,y

This avoids the dangerous overload problem of

growToInclude(0, 0)

matching to (const SkPoint[], count) rather than growToInclude(x, y)

Bug: skia:
Change-Id: Iaba8b1a579638ff363fde62e4e3004052dd2b2ac
Reviewed-on: https://skia-review.googlesource.com/39501
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2017-08-28 13:32:37 -04:00 committed by Skia Commit-Bot
parent de67a2c0e0
commit 3c2d09f89a
5 changed files with 14 additions and 14 deletions

View File

@ -790,11 +790,11 @@ public:
* contains(x,y) -> fLeft <= x < fRight && fTop <= y < fBottom. Also note
* that contains(x,y) always returns false if the rect is empty.
*/
void growToInclude(SkScalar x, SkScalar y) {
fLeft = SkMinScalar(x, fLeft);
fRight = SkMaxScalar(x, fRight);
fTop = SkMinScalar(y, fTop);
fBottom = SkMaxScalar(y, fBottom);
void growToInclude(SkPoint pt) {
fLeft = SkMinScalar(pt.fX, fLeft);
fRight = SkMaxScalar(pt.fX, fRight);
fTop = SkMinScalar(pt.fY, fTop);
fBottom = SkMaxScalar(pt.fY, fBottom);
}
/** Bulk version of growToInclude */
@ -808,7 +808,7 @@ public:
SkASSERT(stride >= sizeof(SkPoint));
const SkPoint* end = (const SkPoint*)((intptr_t)pts + count * stride);
for (; pts < end; pts = (const SkPoint*)((intptr_t)pts + stride)) {
this->growToInclude(pts->fX, pts->fY);
this->growToInclude(*pts);
}
}

View File

@ -726,7 +726,7 @@ bool check_bounds(const SkMatrix& viewMatrix, const SkRect& devBounds, void* ver
actualBounds.set(pos.fX, pos.fY, pos.fX, pos.fY);
first = false;
} else {
actualBounds.growToInclude(pos.fX, pos.fY);
actualBounds.growToInclude(pos);
}
}
if (!first) {

View File

@ -82,25 +82,25 @@ GrDrawAtlasOp::GrDrawAtlasOp(const Helper::MakeArgs& helperArgs, GrColor color,
*(reinterpret_cast<SkPoint*>(currVertex)) = quad[0];
*(reinterpret_cast<SkPoint*>(currVertex + texOffset)) =
SkPoint::Make(currRect.fLeft, currRect.fTop);
bounds.growToInclude(quad[0].fX, quad[0].fY);
bounds.growToInclude(quad[0]);
currVertex += vertexStride;
*(reinterpret_cast<SkPoint*>(currVertex)) = quad[1];
*(reinterpret_cast<SkPoint*>(currVertex + texOffset)) =
SkPoint::Make(currRect.fRight, currRect.fTop);
bounds.growToInclude(quad[1].fX, quad[1].fY);
bounds.growToInclude(quad[1]);
currVertex += vertexStride;
*(reinterpret_cast<SkPoint*>(currVertex)) = quad[2];
*(reinterpret_cast<SkPoint*>(currVertex + texOffset)) =
SkPoint::Make(currRect.fRight, currRect.fBottom);
bounds.growToInclude(quad[2].fX, quad[2].fY);
bounds.growToInclude(quad[2]);
currVertex += vertexStride;
*(reinterpret_cast<SkPoint*>(currVertex)) = quad[3];
*(reinterpret_cast<SkPoint*>(currVertex + texOffset)) =
SkPoint::Make(currRect.fLeft, currRect.fBottom);
bounds.growToInclude(quad[3].fX, quad[3].fY);
bounds.growToInclude(quad[3]);
currVertex += vertexStride;
}

View File

@ -1094,8 +1094,8 @@ void test_unknown_path_effect(skiatest::Reporter* reporter, const Geo& geo) {
}
void computeFastBounds(SkRect* dst, const SkRect& src) const override {
*dst = src;
dst->growToInclude(0, 0);
dst->growToInclude(100, 100);
dst->growToInclude({0, 0});
dst->growToInclude({100, 100});
}
static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new AddLineTosPathEffect); }
Factory getFactory() const override { return nullptr; }

View File

@ -2741,7 +2741,7 @@ bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
bounds.setEmpty();
for (unsigned int i = 0; i < fCount; ++i) {
bounds.growToInclude(fPts[i].fX, fPts[i].fY);
bounds.growToInclude(fPts[i]);
}
xlate_and_scale_to_bounds(canvas, bounds);