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>
This commit is contained in:
Mike Reed 2017-10-09 14:11:34 -04:00 committed by Skia Commit-Bot
parent 37387c80cc
commit c4b015ad5f

View File

@ -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