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