aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-10-09 14:11:34 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-09 18:37:14 +0000
commitc4b015ad5f3b85b0c77d01ce1ce042294a3dd362 (patch)
tree9b2941c53d1472cb68be66be756a24732b4fa697 /src/core
parent37387c80cc1c0c5f939ab6da485b32fa223ec163 (diff)
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 <reed@google.com> Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkScan_Hairline.cpp12
1 files 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