From c4b015ad5f3b85b0c77d01ce1ce042294a3dd362 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Mon, 9 Oct 2017 14:11:34 -0400 Subject: [PATCH] use unsigned to allow for using all 32bits for approx distance Bug:757146 Change-Id: If783f1b36fc70c443d0808947275acf003a872ee Reviewed-on: https://skia-review.googlesource.com/57109 Commit-Queue: Mike Reed Commit-Queue: Ben Wagner Reviewed-by: Ben Wagner --- src/core/SkScan_Hairline.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/SkScan_Hairline.cpp b/src/core/SkScan_Hairline.cpp index 84278f4182..ec6acb9b1f 100644 --- a/src/core/SkScan_Hairline.cpp +++ b/src/core/SkScan_Hairline.cpp @@ -196,7 +196,7 @@ void SkScan::HairRect(const SkRect& rect, const SkRasterClip& clip, #define kMaxCubicSubdivideLevel 9 #define kMaxQuadSubdivideLevel 5 -static int compute_int_quad_dist(const SkPoint pts[3]) { +static uint32_t compute_int_quad_dist(const SkPoint pts[3]) { // compute the vector between the control point ([1]) and the middle of the // line connecting the start and end ([0] and [2]) SkScalar dx = SkScalarHalf(pts[0].fX + pts[2].fX) - pts[1].fX; @@ -204,9 +204,11 @@ static int compute_int_quad_dist(const SkPoint pts[3]) { // we want everyone to be positive dx = SkScalarAbs(dx); dy = SkScalarAbs(dy); - // convert to whole pixel values (use ceiling to be conservative) - int idx = SkScalarCeilToInt(dx); - int idy = SkScalarCeilToInt(dy); + // convert to whole pixel values (use ceiling to be conservative). + // assign to unsigned so we can safely add 1/2 of the smaller and still fit in + // uint32_t, since SkScalarCeilToInt() returns 31 bits at most. + uint32_t idx = SkScalarCeilToInt(dx); + uint32_t idy = SkScalarCeilToInt(dy); // use the cheap approx for distance if (idx > idy) { return idx + (idy >> 1); @@ -404,7 +406,7 @@ static inline void haircubic(const SkPoint pts[4], const SkRegion* clip, const S } static int compute_quad_level(const SkPoint pts[3]) { - int d = compute_int_quad_dist(pts); + uint32_t d = compute_int_quad_dist(pts); /* quadratics approach the line connecting their start and end points 4x closer with each subdivision, so we compute the number of subdivisions to be the minimum need to get that distance to be less