From 6a20c88a59553c79547c15da2810cdbc82407ea3 Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Tue, 23 May 2017 11:53:04 +0800 Subject: [PATCH] Bug 1366027 - Calculate shrink clipped rect with double precision; r=lsalzman MozReview-Commit-ID: 1y2oUkDfnu6 --HG-- extra : rebase_source : 97949c6d03925cd72974a21e630ba850ad2e5c2c --- .../reftest/clipped-dash-stroke-rect-ref.html | 19 +++++++++++ .../reftest/clipped-dash-stroke-rect.html | 19 +++++++++++ dom/canvas/test/reftest/reftest.list | 3 ++ gfx/2d/DrawTargetSkia.cpp | 34 ++++++++++++------- gfx/2d/Rect.h | 2 +- gfx/2d/Types.h | 1 + 6 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 dom/canvas/test/reftest/clipped-dash-stroke-rect-ref.html create mode 100644 dom/canvas/test/reftest/clipped-dash-stroke-rect.html diff --git a/dom/canvas/test/reftest/clipped-dash-stroke-rect-ref.html b/dom/canvas/test/reftest/clipped-dash-stroke-rect-ref.html new file mode 100644 index 000000000000..117bf4fbca17 --- /dev/null +++ b/dom/canvas/test/reftest/clipped-dash-stroke-rect-ref.html @@ -0,0 +1,19 @@ + + + + diff --git a/dom/canvas/test/reftest/clipped-dash-stroke-rect.html b/dom/canvas/test/reftest/clipped-dash-stroke-rect.html new file mode 100644 index 000000000000..0e44254ec312 --- /dev/null +++ b/dom/canvas/test/reftest/clipped-dash-stroke-rect.html @@ -0,0 +1,19 @@ + + + + diff --git a/dom/canvas/test/reftest/reftest.list b/dom/canvas/test/reftest/reftest.list index fd5643e8b3ec..d24eb07e0021 100644 --- a/dom/canvas/test/reftest/reftest.list +++ b/dom/canvas/test/reftest/reftest.list @@ -171,3 +171,6 @@ include filters/reftest.list # Bug 1305963 == mozCurrentTransform.html mozCurrentTransform-ref.html == mozCurrentTransformInverse.html mozCurrentTransform-ref.html + +# Bug 1366027 +== clipped-dash-stroke-rect.html clipped-dash-stroke-rect-ref.html diff --git a/gfx/2d/DrawTargetSkia.cpp b/gfx/2d/DrawTargetSkia.cpp index 77a817bc9d0b..485e434abdae 100644 --- a/gfx/2d/DrawTargetSkia.cpp +++ b/gfx/2d/DrawTargetSkia.cpp @@ -804,10 +804,10 @@ DrawTargetSkia::Stroke(const Path *aPath, mCanvas->drawPath(skiaPath->GetPath(), paint.mPaint); } -static Float +static Double DashPeriodLength(const StrokeOptions& aStrokeOptions) { - Float length = 0; + Double length = 0; for (size_t i = 0; i < aStrokeOptions.mDashLength; i++) { length += aStrokeOptions.mDashPattern[i]; } @@ -820,10 +820,10 @@ DashPeriodLength(const StrokeOptions& aStrokeOptions) return length; } -static inline Float -RoundDownToMultiple(Float aValue, Float aFactor) +static inline Double +RoundDownToMultiple(Double aValue, Double aFactor) { - return floorf(aValue / aFactor) * aFactor; + return floor(aValue / aFactor) * aFactor; } static Rect @@ -847,24 +847,32 @@ ShrinkClippedStrokedRect(const Rect &aStrokedRect, const IntRect &aDeviceClip, { Rect userSpaceStrokeClip = UserSpaceStrokeClip(aDeviceClip, aTransform, aStrokeOptions); - - Rect intersection = aStrokedRect.Intersect(userSpaceStrokeClip); - Float dashPeriodLength = DashPeriodLength(aStrokeOptions); + RectDouble strokedRectDouble( + aStrokedRect.x, aStrokedRect.y, aStrokedRect.width, aStrokedRect.height); + RectDouble intersection = + strokedRectDouble.Intersect(RectDouble(userSpaceStrokeClip.x, + userSpaceStrokeClip.y, + userSpaceStrokeClip.width, + userSpaceStrokeClip.height)); + Double dashPeriodLength = DashPeriodLength(aStrokeOptions); if (intersection.IsEmpty() || dashPeriodLength == 0.0f) { - return intersection; + return Rect( + intersection.x, intersection.y, intersection.width, intersection.height); } // Reduce the rectangle side lengths in multiples of the dash period length // so that the visible dashes stay in the same place. - Margin insetBy = aStrokedRect - intersection; + MarginDouble insetBy = strokedRectDouble - intersection; insetBy.top = RoundDownToMultiple(insetBy.top, dashPeriodLength); insetBy.right = RoundDownToMultiple(insetBy.right, dashPeriodLength); insetBy.bottom = RoundDownToMultiple(insetBy.bottom, dashPeriodLength); insetBy.left = RoundDownToMultiple(insetBy.left, dashPeriodLength); - Rect shrunkRect = aStrokedRect; - shrunkRect.Deflate(insetBy); - return shrunkRect; + strokedRectDouble.Deflate(insetBy); + return Rect(strokedRectDouble.x, + strokedRectDouble.y, + strokedRectDouble.width, + strokedRectDouble.height); } void diff --git a/gfx/2d/Rect.h b/gfx/2d/Rect.h index 942cb200db48..cce467076838 100644 --- a/gfx/2d/Rect.h +++ b/gfx/2d/Rect.h @@ -53,7 +53,7 @@ typedef IntMarginTyped IntMargin; template struct MarginTyped: - public BaseMargin >, + public BaseMargin >, public units { static_assert(IsPixel::value, "'units' must be a coordinate system tag"); diff --git a/gfx/2d/Types.h b/gfx/2d/Types.h index 4da43aff7359..28d203bb0562 100644 --- a/gfx/2d/Types.h +++ b/gfx/2d/Types.h @@ -16,6 +16,7 @@ namespace mozilla { namespace gfx { typedef float Float; +typedef double Double; enum class SurfaceType : int8_t { DATA, /* Data surface - bitmap in memory */