From 525e13c1d318b067e679d7ca540fc1436c38385b Mon Sep 17 00:00:00 2001 From: liyuqian Date: Sat, 5 Nov 2016 06:34:22 -0700 Subject: [PATCH] Fix the sum of alpha = 254 instead of 255 by rounding This patch is a subpatch from https://codereview.chromium.org/2471133002/ I created this CL mainly for Florin to land before he rebaseline the Chrome layout tests. (Landing the whole patch of 2471133002 would be nice but most people already left for the weekend so I'd rather not take the risk to break the Skia during the weekend.) BUG=skia: TBR=reed@google.com, mtklein@google.com, fmalita@chromium.org GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2483523002 Review-Url: https://codereview.chromium.org/2483523002 --- src/core/SkAntiRun.h | 7 ++++++- src/core/SkScan_AAAPath.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/SkAntiRun.h b/src/core/SkAntiRun.h index 8214e28d5b..5ac0e62a6c 100644 --- a/src/core/SkAntiRun.h +++ b/src/core/SkAntiRun.h @@ -21,6 +21,11 @@ public: int16_t* fRuns; uint8_t* fAlpha; + // Return 0-255 given 0-256 + static inline SkAlpha CatchOverflow(int alpha) { + return alpha - (alpha >> 8); + } + /// Returns true if the scanline contains only a single run, /// of alpha value 0. bool empty() const { @@ -79,7 +84,7 @@ public: runs += x; x = 0; do { - alpha[0] = SkToU8(alpha[0] + maxValue); + alpha[0] = SkToU8(CatchOverflow(alpha[0] + maxValue)); int n = runs[0]; SkASSERT(n <= middleCount); alpha += n; diff --git a/src/core/SkScan_AAAPath.cpp b/src/core/SkScan_AAAPath.cpp index 3325249833..91b6e397ae 100644 --- a/src/core/SkScan_AAAPath.cpp +++ b/src/core/SkScan_AAAPath.cpp @@ -83,9 +83,9 @@ number of scan lines in our algorithm is only about 3 + H while the /////////////////////////////////////////////////////////////////////////////// -inline void addAlpha(SkAlpha& alpha, SkAlpha delta) { - SkASSERT(alpha + (int)delta <= 0xFF); - alpha += delta; +static inline void addAlpha(SkAlpha& alpha, SkAlpha delta) { + SkASSERT(alpha + (int)delta <= 256); + alpha = SkAlphaRuns::CatchOverflow(alpha + (int)delta); } class AdditiveBlitter : public SkBlitter { @@ -481,7 +481,7 @@ static inline SkAlpha partialTriangleToAlpha(SkFixed a, SkFixed b) { } static inline SkAlpha getPartialAlpha(SkAlpha alpha, SkFixed partialHeight) { - return (alpha * partialHeight) >> 16; + return (alpha * partialHeight + SK_FixedHalf) >> 16; } static inline SkAlpha getPartialAlpha(SkAlpha alpha, SkAlpha fullAlpha) {