From bb39a297727fd70ba6b690b8bdfc62200854df86 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 18 Apr 2012 21:19:26 +0000 Subject: mirror 3713 for non-antialiased-hairlines. clamp lines to 32K to avoid fixedpoint overflow fixes crbug.com/123105 git-svn-id: http://skia.googlecode.com/svn/trunk@3729 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkScan_Hairline.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/SkScan_Hairline.cpp b/src/core/SkScan_Hairline.cpp index 412ec03186..ffdf92f1fa 100644 --- a/src/core/SkScan_Hairline.cpp +++ b/src/core/SkScan_Hairline.cpp @@ -33,6 +33,11 @@ static void vertline(int y, int stopy, SkFixed fx, SkFixed dx, } while (++y < stopy); } +static bool canConvertFDot6ToFixed(SkFDot6 x) { + const int maxDot6 = SK_MaxS32 >> (16 - 6); + return SkAbs32(x) <= maxDot6; +} + void SkScan::HairLineRgn(const SkPoint& pt0, const SkPoint& pt1, const SkRegion* clip, SkBlitter* blitter) { SkBlitterClipper clipper; @@ -40,6 +45,19 @@ void SkScan::HairLineRgn(const SkPoint& pt0, const SkPoint& pt1, SkIRect clipR, ptsR; SkPoint pts[2] = { pt0, pt1 }; +#ifdef SK_SCALAR_IS_FLOAT + // We have to pre-clip the line to fit in a SkFixed, so we just chop + // the line. TODO find a way to actually draw beyond that range. + { + SkRect fixedBounds; + const SkScalar max = SkIntToScalar(32767); + fixedBounds.set(-max, -max, max, max); + if (!SkLineClipper::IntersectLine(pts, fixedBounds, pts)) { + return; + } + } +#endif + if (clip) { // Perform a clip in scalar space, so we catch huge values which might // be missed after we convert to SkFDot6 (overflow) @@ -53,7 +71,12 @@ void SkScan::HairLineRgn(const SkPoint& pt0, const SkPoint& pt1, SkFDot6 y0 = SkScalarToFDot6(pts[0].fY); SkFDot6 x1 = SkScalarToFDot6(pts[1].fX); SkFDot6 y1 = SkScalarToFDot6(pts[1].fY); - + + SkASSERT(canConvertFDot6ToFixed(x0)); + SkASSERT(canConvertFDot6ToFixed(y0)); + SkASSERT(canConvertFDot6ToFixed(x1)); + SkASSERT(canConvertFDot6ToFixed(y1)); + if (clip) { // now perform clipping again, as the rounding to dot6 can wiggle us // our rects are really dot6 rects, but since we've already used -- cgit v1.2.3