From 3c2d09f89ae119de506722f550a6e28305d4813f Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Mon, 28 Aug 2017 13:32:37 -0400 Subject: 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 Commit-Queue: Mike Reed --- include/core/SkRect.h | 12 ++++++------ src/gpu/ops/GrAAHairLinePathRenderer.cpp | 2 +- src/gpu/ops/GrDrawAtlasOp.cpp | 8 ++++---- tests/GrShapeTest.cpp | 4 ++-- tools/debugger/SkDrawCommand.cpp | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/core/SkRect.h b/include/core/SkRect.h index a2668d9604..ea09c6bcba 100644 --- a/include/core/SkRect.h +++ b/include/core/SkRect.h @@ -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); } } diff --git a/src/gpu/ops/GrAAHairLinePathRenderer.cpp b/src/gpu/ops/GrAAHairLinePathRenderer.cpp index c5479b7849..e00ca3fd5d 100644 --- a/src/gpu/ops/GrAAHairLinePathRenderer.cpp +++ b/src/gpu/ops/GrAAHairLinePathRenderer.cpp @@ -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) { diff --git a/src/gpu/ops/GrDrawAtlasOp.cpp b/src/gpu/ops/GrDrawAtlasOp.cpp index 6659c6a633..47ebbd5607 100644 --- a/src/gpu/ops/GrDrawAtlasOp.cpp +++ b/src/gpu/ops/GrDrawAtlasOp.cpp @@ -82,25 +82,25 @@ GrDrawAtlasOp::GrDrawAtlasOp(const Helper::MakeArgs& helperArgs, GrColor color, *(reinterpret_cast(currVertex)) = quad[0]; *(reinterpret_cast(currVertex + texOffset)) = SkPoint::Make(currRect.fLeft, currRect.fTop); - bounds.growToInclude(quad[0].fX, quad[0].fY); + bounds.growToInclude(quad[0]); currVertex += vertexStride; *(reinterpret_cast(currVertex)) = quad[1]; *(reinterpret_cast(currVertex + texOffset)) = SkPoint::Make(currRect.fRight, currRect.fTop); - bounds.growToInclude(quad[1].fX, quad[1].fY); + bounds.growToInclude(quad[1]); currVertex += vertexStride; *(reinterpret_cast(currVertex)) = quad[2]; *(reinterpret_cast(currVertex + texOffset)) = SkPoint::Make(currRect.fRight, currRect.fBottom); - bounds.growToInclude(quad[2].fX, quad[2].fY); + bounds.growToInclude(quad[2]); currVertex += vertexStride; *(reinterpret_cast(currVertex)) = quad[3]; *(reinterpret_cast(currVertex + texOffset)) = SkPoint::Make(currRect.fLeft, currRect.fBottom); - bounds.growToInclude(quad[3].fX, quad[3].fY); + bounds.growToInclude(quad[3]); currVertex += vertexStride; } diff --git a/tests/GrShapeTest.cpp b/tests/GrShapeTest.cpp index 646c06c444..3f97288c1c 100644 --- a/tests/GrShapeTest.cpp +++ b/tests/GrShapeTest.cpp @@ -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 Make() { return sk_sp(new AddLineTosPathEffect); } Factory getFactory() const override { return nullptr; } diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp index 8cee07f783..3e05da0572 100644 --- a/tools/debugger/SkDrawCommand.cpp +++ b/tools/debugger/SkDrawCommand.cpp @@ -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); -- cgit v1.2.3