tweak .clang-format I just spent a bunch of time manually formatting SkScan_AAAPath.cpp so that I could read it, a bunch of really frustrating time. So I decided to see how clang-format would do, and with a couple of tweaks I think I'm happy to let the tool take the wheel. It actually fixed up a few places I missed. Most controversial stuff is proably parameter/argument packing? I find packing these makes it hard to distinguish which and even how many arguments you're passing to a function... it all becomes a bit of a sea of letters and you need to hunt for commas. This way you always see them distinctly, and if things start to look ridiculously tall, it's probably because the _function_ is ridiculous. I'd have even gone as far to set AllowAllArgumentsOnNextLine: false, but it doesn't exist yet. Change-Id: I504dedb50f99d0d935d59e252d30f59eca451a0c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/202000 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Mike Klein <mtklein@google.com>
diff --git a/.clang-format b/.clang-format index eb798ed..9a32eca 100644 --- a/.clang-format +++ b/.clang-format
@@ -14,23 +14,23 @@ # BasedOnStyle: Google AccessModifierOffset: -4 AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true AlignEscapedNewlinesLeft: true AlignOperands: true AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: false -BinPackArguments: true -BinPackParameters: true +BinPackArguments: false +BinPackParameters: false BraceWrapping: AfterClass: false AfterControlStatement: false @@ -57,7 +57,7 @@ Cpp11BracedListStyle: true DerivePointerAlignment: false DisableFormat: false -ExperimentalAutoDetectBinPacking: true +ExperimentalAutoDetectBinPacking: false ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] IncludeCategories: - Regex: '^<.*\.h>' @@ -87,6 +87,7 @@ PointerAlignment: Left ReflowComments: true SortIncludes: true +SortUsingDeclarations: true SpaceAfterCStyleCast: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true @@ -98,30 +99,30 @@ SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: Auto +Standard: Cpp11 TabWidth: 4 UseTab: Never --- Language: ObjC AccessModifierOffset: -4 AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true AlignEscapedNewlinesLeft: true AlignOperands: true AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: false -BinPackArguments: true -BinPackParameters: true +BinPackArguments: false +BinPackParameters: false BraceWrapping: AfterClass: false AfterControlStatement: false @@ -148,7 +149,7 @@ Cpp11BracedListStyle: true DerivePointerAlignment: false DisableFormat: false -ExperimentalAutoDetectBinPacking: true +ExperimentalAutoDetectBinPacking: false ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] IncludeCategories: - Regex: '^<.*\.h>' @@ -193,4 +194,3 @@ TabWidth: 4 UseTab: Never ... -
diff --git a/src/core/SkScan_AAAPath.cpp b/src/core/SkScan_AAAPath.cpp index 74acefb..fd4adb9 100644 --- a/src/core/SkScan_AAAPath.cpp +++ b/src/core/SkScan_AAAPath.cpp
@@ -90,7 +90,6 @@ */ - static void add_alpha(SkAlpha* alpha, SkAlpha delta) { SkASSERT(*alpha + delta <= 256); *alpha = SkAlphaRuns::CatchOverflow(*alpha + delta); @@ -107,8 +106,8 @@ virtual SkBlitter* getRealBlitter(bool forceRealBlitter = false) = 0; virtual void blitAntiH(int x, int y, const SkAlpha antialias[], int len) = 0; - virtual void blitAntiH(int x, int y, const SkAlpha alpha) = 0; - virtual void blitAntiH(int x, int y, int width, const SkAlpha alpha) = 0; + virtual void blitAntiH(int x, int y, const SkAlpha alpha) = 0; + virtual void blitAntiH(int x, int y, int width, const SkAlpha alpha) = 0; void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override { SkDEBUGFAIL("Please call real blitter's blitAntiH instead."); @@ -126,8 +125,8 @@ SkDEBUGFAIL("Please call real blitter's blitRect instead."); } - void blitAntiRect(int x, int y, int width, int height, - SkAlpha leftAlpha, SkAlpha rightAlpha) override { + void blitAntiRect(int x, int y, int width, int height, SkAlpha leftAlpha, SkAlpha rightAlpha) + override { SkDEBUGFAIL("Please call real blitter's blitAntiRect instead."); } @@ -141,11 +140,11 @@ // We need this mask blitter because it significantly accelerates small path filling. class MaskAdditiveBlitter : public AdditiveBlitter { public: - MaskAdditiveBlitter(SkBlitter* realBlitter, const SkIRect& ir, const SkIRect& clipBounds, - bool isInverse); - ~MaskAdditiveBlitter() override { - fRealBlitter->blitMask(fMask, fClipRect); - } + MaskAdditiveBlitter(SkBlitter* realBlitter, + const SkIRect& ir, + const SkIRect& clipBounds, + bool isInverse); + ~MaskAdditiveBlitter() override { fRealBlitter->blitMask(fMask, fClipRect); } // Most of the time, we still consider this mask blitter as the real blitter // so we can accelerate blitRect and others. But sometimes we want to return @@ -163,8 +162,8 @@ void blitAntiH(int x, int y, int width, const SkAlpha alpha) override; void blitV(int x, int y, int height, SkAlpha alpha) override; void blitRect(int x, int y, int width, int height) override; - void blitAntiRect(int x, int y, int width, int height, - SkAlpha leftAlpha, SkAlpha rightAlpha) override; + void blitAntiRect(int x, int y, int width, int height, SkAlpha leftAlpha, SkAlpha rightAlpha) + override; // The flush is only needed for RLE (RunBasedAdditiveBlitter) void flush_if_y_changed(SkFixed y, SkFixed nextY) override {} @@ -187,7 +186,7 @@ // Return a pointer where pointer[x] corresonds to the alpha of (x, y) uint8_t* getRow(int y) { if (y != fY) { - fY = y; + fY = y; fRow = fMask.fImage + (y - fMask.fBounds.fTop) * fMask.fRowBytes - fMask.fBounds.fLeft; } return fRow; @@ -195,34 +194,34 @@ private: // so we don't try to do very wide things, where the RLE blitter would be faster - static const int kMAX_WIDTH = 32; + static const int kMAX_WIDTH = 32; static const int kMAX_STORAGE = 1024; - SkBlitter* fRealBlitter; - SkMask fMask; - SkIRect fClipRect; + SkBlitter* fRealBlitter; + SkMask fMask; + SkIRect fClipRect; // we add 2 because we can write 1 extra byte at either end due to precision error - uint32_t fStorage[(kMAX_STORAGE >> 2) + 2]; + uint32_t fStorage[(kMAX_STORAGE >> 2) + 2]; - uint8_t* fRow; - int fY; + uint8_t* fRow; + int fY; }; -MaskAdditiveBlitter::MaskAdditiveBlitter(SkBlitter* realBlitter, +MaskAdditiveBlitter::MaskAdditiveBlitter(SkBlitter* realBlitter, const SkIRect& ir, const SkIRect& clipBounds, - bool isInverse) { + bool isInverse) { SkASSERT(CanHandleRect(ir)); SkASSERT(!isInverse); fRealBlitter = realBlitter; - fMask.fImage = (uint8_t*)fStorage + 1; // There's 1 extra byte at either end of fStorage + fMask.fImage = (uint8_t*)fStorage + 1; // There's 1 extra byte at either end of fStorage fMask.fBounds = ir; fMask.fRowBytes = ir.width(); fMask.fFormat = SkMask::kA8_Format; - fY = ir.fTop - 1; + fY = ir.fTop - 1; fRow = nullptr; fClipRect = ir; @@ -276,10 +275,10 @@ } } -void MaskAdditiveBlitter::blitAntiRect(int x, - int y, - int width, - int height, +void MaskAdditiveBlitter::blitAntiRect(int x, + int y, + int width, + int height, SkAlpha leftAlpha, SkAlpha rightAlpha) { blitV(x, y, height, leftAlpha); @@ -289,18 +288,14 @@ class RunBasedAdditiveBlitter : public AdditiveBlitter { public: - RunBasedAdditiveBlitter(SkBlitter* realBlitter, + RunBasedAdditiveBlitter(SkBlitter* realBlitter, const SkIRect& ir, const SkIRect& clipBounds, - bool isInverse); + bool isInverse); - ~RunBasedAdditiveBlitter() override { - this->flush(); - } + ~RunBasedAdditiveBlitter() override { this->flush(); } - SkBlitter* getRealBlitter(bool forceRealBlitter) override { - return fRealBlitter; - } + SkBlitter* getRealBlitter(bool forceRealBlitter) override { return fRealBlitter; } void blitAntiH(int x, int y, const SkAlpha antialias[], int len) override; void blitAntiH(int x, int y, const SkAlpha alpha) override; @@ -317,10 +312,10 @@ protected: SkBlitter* fRealBlitter; - int fCurrY; // Current y coordinate. - int fWidth; // Widest row of region to be blitted - int fLeft; // Leftmost x coordinate in any row - int fTop; // Initial y coordinate (top of bounds) + int fCurrY; // Current y coordinate. + int fWidth; // Widest row of region to be blitted + int fLeft; // Leftmost x coordinate in any row + int fTop; // Initial y coordinate (top of bounds) // The next three variables are used to track a circular buffer that // contains the values used in SkAlphaRuns. These variables should only @@ -331,32 +326,27 @@ int fCurrentRun; SkAlphaRuns fRuns; - int fOffsetX; + int fOffsetX; - bool check(int x, int width) const { - return x >= 0 && x + width <= fWidth; - } + bool check(int x, int width) const { return x >= 0 && x + width <= fWidth; } // extra one to store the zero at the end - int getRunsSz() const { return (fWidth + 1 + (fWidth + 2)/2) * sizeof(int16_t); } + int getRunsSz() const { return (fWidth + 1 + (fWidth + 2) / 2) * sizeof(int16_t); } // This function updates the fRuns variable to point to the next buffer space // with adequate storage for a SkAlphaRuns. It mostly just advances fCurrentRun // and resets fRuns to point to an empty scanline. void advanceRuns() { const size_t kRunsSz = this->getRunsSz(); - fCurrentRun = (fCurrentRun + 1) % fRunsToBuffer; - fRuns.fRuns = reinterpret_cast<int16_t*>( - reinterpret_cast<uint8_t*>(fRunsBuffer) + fCurrentRun * kRunsSz); - fRuns.fAlpha = reinterpret_cast<SkAlpha*>(fRuns.fRuns + fWidth + 1); + fCurrentRun = (fCurrentRun + 1) % fRunsToBuffer; + fRuns.fRuns = reinterpret_cast<int16_t*>(reinterpret_cast<uint8_t*>(fRunsBuffer) + + fCurrentRun * kRunsSz); + fRuns.fAlpha = reinterpret_cast<SkAlpha*>(fRuns.fRuns + fWidth + 1); fRuns.reset(fWidth); } // Blitting 0xFF and 0 is much faster so we snap alphas close to them - SkAlpha snapAlpha(SkAlpha alpha) { - return alpha > 247 ? 0xFF : - alpha < 8 ? 0x00 : alpha; - } + SkAlpha snapAlpha(SkAlpha alpha) { return alpha > 247 ? 0xFF : alpha < 8 ? 0x00 : alpha; } void flush() { if (fCurrY >= fTop) { @@ -383,16 +373,16 @@ } }; -RunBasedAdditiveBlitter::RunBasedAdditiveBlitter(SkBlitter* realBlitter, +RunBasedAdditiveBlitter::RunBasedAdditiveBlitter(SkBlitter* realBlitter, const SkIRect& ir, const SkIRect& clipBounds, - bool isInverse) { + bool isInverse) { fRealBlitter = realBlitter; SkIRect sectBounds; if (isInverse) { // We use the clip bounds instead of the ir, since we may be asked to - //draw outside of the rect when we're a inverse filltype + // draw outside of the rect when we're a inverse filltype sectBounds = clipBounds; } else { if (!sectBounds.intersect(ir, clipBounds)) { @@ -400,17 +390,17 @@ } } - const int left = sectBounds.left(); + const int left = sectBounds.left(); const int right = sectBounds.right(); - fLeft = left; + fLeft = left; fWidth = right - left; - fTop = sectBounds.top(); + fTop = sectBounds.top(); fCurrY = fTop - 1; fRunsToBuffer = realBlitter->requestRowsPreserved(); - fRunsBuffer = realBlitter->allocBlitMemory(fRunsToBuffer * this->getRunsSz()); - fCurrentRun = -1; + fRunsBuffer = realBlitter->allocBlitMemory(fRunsToBuffer * this->getRunsSz()); + fCurrentRun = -1; this->advanceRuns(); @@ -433,10 +423,10 @@ fOffsetX = 0; } - fOffsetX = fRuns.add(x, 0, len, 0, 0, fOffsetX); // Break the run + fOffsetX = fRuns.add(x, 0, len, 0, 0, fOffsetX); // Break the run for (int i = 0; i < len; i += fRuns.fRuns[x + i]) { for (int j = 1; j < fRuns.fRuns[x + i]; j++) { - fRuns.fRuns[x + i + j] = 1; + fRuns.fRuns[x + i + j] = 1; fRuns.fAlpha[x + i + j] = fRuns.fAlpha[x + i]; } fRuns.fRuns[x + i] = 1; @@ -476,11 +466,11 @@ // In those cases, we can easily accumulate alpha greater than 0xFF. class SafeRLEAdditiveBlitter : public RunBasedAdditiveBlitter { public: - SafeRLEAdditiveBlitter(SkBlitter* realBlitter, + SafeRLEAdditiveBlitter(SkBlitter* realBlitter, const SkIRect& ir, const SkIRect& clipBounds, - bool isInverse) - : RunBasedAdditiveBlitter(realBlitter, ir, clipBounds, isInverse) {} + bool isInverse) + : RunBasedAdditiveBlitter(realBlitter, ir, clipBounds, isInverse) {} void blitAntiH(int x, int y, const SkAlpha antialias[], int len) override; void blitAntiH(int x, int y, const SkAlpha alpha) override; @@ -503,10 +493,10 @@ fOffsetX = 0; } - fOffsetX = fRuns.add(x, 0, len, 0, 0, fOffsetX); // Break the run + fOffsetX = fRuns.add(x, 0, len, 0, 0, fOffsetX); // Break the run for (int i = 0; i < len; i += fRuns.fRuns[x + i]) { for (int j = 1; j < fRuns.fRuns[x + i]; j++) { - fRuns.fRuns[x + i + j] = 1; + fRuns.fRuns[x + i + j] = 1; fRuns.fAlpha[x + i + j] = fRuns.fAlpha[x + i]; } fRuns.fRuns[x + i] = 1; @@ -542,7 +532,7 @@ if (check(x, width)) { // Break the run fOffsetX = fRuns.add(x, 0, width, 0, 0, fOffsetX); - for(int i = x; i < x + width; i += fRuns.fRuns[i]) { + for (int i = x; i < x + width; i += fRuns.fRuns[i]) { safely_add_alpha(&fRuns.fAlpha[i], alpha); } } @@ -550,8 +540,7 @@ // Return the alpha of a trapezoid whose height is 1 static SkAlpha trapezoid_to_alpha(SkFixed l1, SkFixed l2) { - SkASSERT(l1 >= 0 && - l2 >= 0); + SkASSERT(l1 >= 0 && l2 >= 0); SkFixed area = (l1 + l2) / 2; return SkTo<SkAlpha>(area >> 8); } @@ -595,17 +584,21 @@ // Suppose that line (l1, y)-(r1, y+1) intersects with (l2, y)-(r2, y+1), // approximate (very coarsely) the x coordinate of the intersection. static SkFixed approximate_intersection(SkFixed l1, SkFixed r1, SkFixed l2, SkFixed r2) { - if (l1 > r1) { std::swap(l1, r1); } - if (l2 > r2) { std::swap(l2, r2); } + if (l1 > r1) { + std::swap(l1, r1); + } + if (l2 > r2) { + std::swap(l2, r2); + } return (SkTMax(l1, l2) + SkTMin(r1, r2)) / 2; } // Here we always send in l < SK_Fixed1, and the first alpha we want to compute is alphas[0] static void compute_alpha_above_line(SkAlpha* alphas, - SkFixed l, - SkFixed r, - SkFixed dY, - SkAlpha fullAlpha) { + SkFixed l, + SkFixed r, + SkFixed dY, + SkAlpha fullAlpha) { SkASSERT(l <= r); SkASSERT(l >> 16 == 0); int R = SkFixedCeilToInt(r); @@ -614,11 +607,11 @@ } else if (R == 1) { alphas[0] = get_partial_alpha(((R << 17) - l - r) >> 9, fullAlpha); } else { - SkFixed first = SK_Fixed1 - l; // horizontal edge length of the left-most triangle - SkFixed last = r - ((R - 1) << 16); // horizontal edge length of the right-most triangle - SkFixed firstH = SkFixedMul(first, dY); // vertical edge of the left-most triangle - alphas[0] = SkFixedMul(first, firstH) >> 9; // triangle alpha - SkFixed alpha16 = firstH + (dY >> 1); // rectangle plus triangle + SkFixed first = SK_Fixed1 - l; // horizontal edge length of the left-most triangle + SkFixed last = r - ((R - 1) << 16); // horizontal edge length of the right-most triangle + SkFixed firstH = SkFixedMul(first, dY); // vertical edge of the left-most triangle + alphas[0] = SkFixedMul(first, firstH) >> 9; // triangle alpha + SkFixed alpha16 = firstH + (dY >> 1); // rectangle plus triangle for (int i = 1; i < R - 1; ++i) { alphas[i] = alpha16 >> 8; alpha16 += dY; @@ -629,10 +622,10 @@ // Here we always send in l < SK_Fixed1, and the first alpha we want to compute is alphas[0] static void compute_alpha_below_line(SkAlpha* alphas, - SkFixed l, - SkFixed r, - SkFixed dY, - SkAlpha fullAlpha) { + SkFixed l, + SkFixed r, + SkFixed dY, + SkAlpha fullAlpha) { SkASSERT(l <= r); SkASSERT(l >> 16 == 0); int R = SkFixedCeilToInt(r); @@ -641,11 +634,11 @@ } else if (R == 1) { alphas[0] = get_partial_alpha(trapezoid_to_alpha(l, r), fullAlpha); } else { - SkFixed first = SK_Fixed1 - l; // horizontal edge length of the left-most triangle - SkFixed last = r - ((R - 1) << 16); // horizontal edge length of the right-most triangle - SkFixed lastH = SkFixedMul(last, dY); // vertical edge of the right-most triangle - alphas[R-1] = SkFixedMul(last, lastH) >> 9; // triangle alpha - SkFixed alpha16 = lastH + (dY >> 1); // rectangle plus triangle + SkFixed first = SK_Fixed1 - l; // horizontal edge length of the left-most triangle + SkFixed last = r - ((R - 1) << 16); // horizontal edge length of the right-most triangle + SkFixed lastH = SkFixedMul(last, dY); // vertical edge of the right-most triangle + alphas[R - 1] = SkFixedMul(last, lastH) >> 9; // triangle alpha + SkFixed alpha16 = lastH + (dY >> 1); // rectangle plus triangle for (int i = R - 2; i > 0; i--) { alphas[i] = (alpha16 >> 8) & 0xFF; alpha16 += dY; @@ -656,16 +649,16 @@ // Note that if fullAlpha != 0xFF, we'll multiply alpha by fullAlpha static SK_ALWAYS_INLINE void blit_single_alpha(AdditiveBlitter* blitter, - int y, - int x, - SkAlpha alpha, - SkAlpha fullAlpha, - SkAlpha* maskRow, - bool isUsingMask, - bool noRealBlitter, - bool needSafeCheck) { + int y, + int x, + SkAlpha alpha, + SkAlpha fullAlpha, + SkAlpha* maskRow, + bool isUsingMask, + bool noRealBlitter, + bool needSafeCheck) { if (isUsingMask) { - if (fullAlpha == 0xFF && !noRealBlitter) { // noRealBlitter is needed for concave paths + if (fullAlpha == 0xFF && !noRealBlitter) { // noRealBlitter is needed for concave paths maskRow[x] = alpha; } else if (needSafeCheck) { safely_add_alpha(&maskRow[x], get_partial_alpha(alpha, fullAlpha)); @@ -682,15 +675,15 @@ } static SK_ALWAYS_INLINE void blit_two_alphas(AdditiveBlitter* blitter, - int y, - int x, - SkAlpha a1, - SkAlpha a2, - SkAlpha fullAlpha, - SkAlpha* maskRow, - bool isUsingMask, - bool noRealBlitter, - bool needSafeCheck) { + int y, + int x, + SkAlpha a1, + SkAlpha a2, + SkAlpha fullAlpha, + SkAlpha* maskRow, + bool isUsingMask, + bool noRealBlitter, + bool needSafeCheck) { if (isUsingMask) { if (needSafeCheck) { safely_add_alpha(&maskRow[x], a1); @@ -710,14 +703,14 @@ } static SK_ALWAYS_INLINE void blit_full_alpha(AdditiveBlitter* blitter, - int y, - int x, - int len, - SkAlpha fullAlpha, - SkAlpha* maskRow, - bool isUsingMask, - bool noRealBlitter, - bool needSafeCheck) { + int y, + int x, + int len, + SkAlpha fullAlpha, + SkAlpha* maskRow, + bool isUsingMask, + bool noRealBlitter, + bool needSafeCheck) { if (isUsingMask) { for (int i = 0; i < len; ++i) { if (needSafeCheck) { @@ -736,18 +729,18 @@ } static void blit_aaa_trapezoid_row(AdditiveBlitter* blitter, - int y, - SkFixed ul, - SkFixed ur, - SkFixed ll, - SkFixed lr, - SkFixed lDY, - SkFixed rDY, - SkAlpha fullAlpha, - SkAlpha* maskRow, - bool isUsingMask, - bool noRealBlitter, - bool needSafeCheck) { + int y, + SkFixed ul, + SkFixed ur, + SkFixed ll, + SkFixed lr, + SkFixed lDY, + SkFixed rDY, + SkAlpha fullAlpha, + SkAlpha* maskRow, + bool isUsingMask, + bool noRealBlitter, + bool needSafeCheck) { int L = SkFixedFloorToInt(ul), R = SkFixedCeilToInt(lr); int len = R - L; @@ -766,8 +759,8 @@ } const int kQuickLen = 31; - char quickMemory[(sizeof(SkAlpha) * 2 + sizeof(int16_t)) * (kQuickLen + 1)]; - SkAlpha* alphas; + char quickMemory[(sizeof(SkAlpha) * 2 + sizeof(int16_t)) * (kQuickLen + 1)]; + SkAlpha* alphas; if (len <= kQuickLen) { alphas = (SkAlpha*)quickMemory; @@ -776,29 +769,26 @@ } SkAlpha* tempAlphas = alphas + len + 1; - int16_t* runs = (int16_t*)(alphas + (len + 1) * 2); + int16_t* runs = (int16_t*)(alphas + (len + 1) * 2); for (int i = 0; i < len; ++i) { - runs[i] = 1; + runs[i] = 1; alphas[i] = fullAlpha; } runs[len] = 0; int uL = SkFixedFloorToInt(ul); int lL = SkFixedCeilToInt(ll); - if (uL + 2 == lL) { // We only need to compute two triangles, accelerate this special case - SkFixed first = SkIntToFixed(uL) + SK_Fixed1 - ul; + if (uL + 2 == lL) { // We only need to compute two triangles, accelerate this special case + SkFixed first = SkIntToFixed(uL) + SK_Fixed1 - ul; SkFixed second = ll - ul - first; - SkAlpha a1 = fullAlpha - partial_triangle_to_alpha(first, lDY); - SkAlpha a2 = partial_triangle_to_alpha(second, lDY); - alphas[0] = alphas[0] > a1 ? alphas[0] - a1 : 0; - alphas[1] = alphas[1] > a2 ? alphas[1] - a2 : 0; + SkAlpha a1 = fullAlpha - partial_triangle_to_alpha(first, lDY); + SkAlpha a2 = partial_triangle_to_alpha(second, lDY); + alphas[0] = alphas[0] > a1 ? alphas[0] - a1 : 0; + alphas[1] = alphas[1] > a2 ? alphas[1] - a2 : 0; } else { - compute_alpha_below_line(tempAlphas + uL - L, - ul - SkIntToFixed(uL), - ll - SkIntToFixed(uL), - lDY, - fullAlpha); + compute_alpha_below_line( + tempAlphas + uL - L, ul - SkIntToFixed(uL), ll - SkIntToFixed(uL), lDY, fullAlpha); for (int i = uL; i < lL; ++i) { if (alphas[i - L] > tempAlphas[i - L]) { alphas[i - L] -= tempAlphas[i - L]; @@ -810,19 +800,16 @@ int uR = SkFixedFloorToInt(ur); int lR = SkFixedCeilToInt(lr); - if (uR + 2 == lR) { // We only need to compute two triangles, accelerate this special case - SkFixed first = SkIntToFixed(uR) + SK_Fixed1 - ur; - SkFixed second = lr - ur - first; - SkAlpha a1 = partial_triangle_to_alpha(first, rDY); - SkAlpha a2 = fullAlpha - partial_triangle_to_alpha(second, rDY); - alphas[len-2] = alphas[len-2] > a1 ? alphas[len-2] - a1 : 0; - alphas[len-1] = alphas[len-1] > a2 ? alphas[len-1] - a2 : 0; + if (uR + 2 == lR) { // We only need to compute two triangles, accelerate this special case + SkFixed first = SkIntToFixed(uR) + SK_Fixed1 - ur; + SkFixed second = lr - ur - first; + SkAlpha a1 = partial_triangle_to_alpha(first, rDY); + SkAlpha a2 = fullAlpha - partial_triangle_to_alpha(second, rDY); + alphas[len - 2] = alphas[len - 2] > a1 ? alphas[len - 2] - a1 : 0; + alphas[len - 1] = alphas[len - 1] > a2 ? alphas[len - 1] - a2 : 0; } else { - compute_alpha_above_line(tempAlphas + uR - L, - ur - SkIntToFixed(uR), - lr - SkIntToFixed(uR), - rDY, - fullAlpha); + compute_alpha_above_line( + tempAlphas + uR - L, ur - SkIntToFixed(uR), lr - SkIntToFixed(uR), rDY, fullAlpha); for (int i = uR; i < lR; ++i) { if (alphas[i - L] > tempAlphas[i - L]) { alphas[i - L] -= tempAlphas[i - L]; @@ -850,24 +837,24 @@ } if (len > kQuickLen) { - delete [] alphas; + delete[] alphas; } } static SK_ALWAYS_INLINE void blit_trapezoid_row(AdditiveBlitter* blitter, - int y, - SkFixed ul, - SkFixed ur, - SkFixed ll, - SkFixed lr, - SkFixed lDY, - SkFixed rDY, - SkAlpha fullAlpha, - SkAlpha* maskRow, - bool isUsingMask, - bool noRealBlitter = false, - bool needSafeCheck = false) { - SkASSERT(lDY >= 0 && rDY >= 0); // We should only send in the absolte value + int y, + SkFixed ul, + SkFixed ur, + SkFixed ll, + SkFixed lr, + SkFixed lDY, + SkFixed rDY, + SkAlpha fullAlpha, + SkAlpha* maskRow, + bool isUsingMask, + bool noRealBlitter = false, + bool needSafeCheck = false) { + SkASSERT(lDY >= 0 && rDY >= 0); // We should only send in the absolte value if (ul > ur) { return; @@ -880,67 +867,138 @@ } if (ul == ur && ll == lr) { - return; // empty trapzoid + return; // empty trapzoid } // We're going to use the left line ul-ll and the rite line ur-lr // to exclude the area that's not covered by the path. // Swapping (ul, ll) or (ur, lr) won't affect that exclusion // so we'll do that for simplicity. - if (ul > ll) { std::swap(ul, ll); } - if (ur > lr) { std::swap(ur, lr); } + if (ul > ll) { + std::swap(ul, ll); + } + if (ur > lr) { + std::swap(ur, lr); + } SkFixed joinLeft = SkFixedCeilToFixed(ll); SkFixed joinRite = SkFixedFloorToFixed(ur); - if (joinLeft <= joinRite) { // There's a rect from joinLeft to joinRite that we can blit + if (joinLeft <= joinRite) { // There's a rect from joinLeft to joinRite that we can blit if (ul < joinLeft) { int len = SkFixedCeilToInt(joinLeft - ul); if (len == 1) { SkAlpha alpha = trapezoid_to_alpha(joinLeft - ul, joinLeft - ll); - blit_single_alpha(blitter, y, ul >> 16, alpha, fullAlpha, maskRow, isUsingMask, - noRealBlitter, needSafeCheck); + blit_single_alpha(blitter, + y, + ul >> 16, + alpha, + fullAlpha, + maskRow, + isUsingMask, + noRealBlitter, + needSafeCheck); } else if (len == 2) { - SkFixed first = joinLeft - SK_Fixed1 - ul; + SkFixed first = joinLeft - SK_Fixed1 - ul; SkFixed second = ll - ul - first; - SkAlpha a1 = partial_triangle_to_alpha(first, lDY); - SkAlpha a2 = fullAlpha - partial_triangle_to_alpha(second, lDY); - blit_two_alphas(blitter, y, ul >> 16, a1, a2, fullAlpha, maskRow, isUsingMask, - noRealBlitter, needSafeCheck); + SkAlpha a1 = partial_triangle_to_alpha(first, lDY); + SkAlpha a2 = fullAlpha - partial_triangle_to_alpha(second, lDY); + blit_two_alphas(blitter, + y, + ul >> 16, + a1, + a2, + fullAlpha, + maskRow, + isUsingMask, + noRealBlitter, + needSafeCheck); } else { - blit_aaa_trapezoid_row(blitter, y, ul, joinLeft, ll, joinLeft, lDY, SK_MaxS32, - fullAlpha, maskRow, isUsingMask, noRealBlitter, + blit_aaa_trapezoid_row(blitter, + y, + ul, + joinLeft, + ll, + joinLeft, + lDY, + SK_MaxS32, + fullAlpha, + maskRow, + isUsingMask, + noRealBlitter, needSafeCheck); } } // SkAAClip requires that we blit from left to right. // Hence we must blit [ul, joinLeft] before blitting [joinLeft, joinRite] if (joinLeft < joinRite) { - blit_full_alpha(blitter, y, SkFixedFloorToInt(joinLeft), + blit_full_alpha(blitter, + y, + SkFixedFloorToInt(joinLeft), SkFixedFloorToInt(joinRite - joinLeft), - fullAlpha, maskRow, isUsingMask, noRealBlitter, needSafeCheck); + fullAlpha, + maskRow, + isUsingMask, + noRealBlitter, + needSafeCheck); } if (lr > joinRite) { int len = SkFixedCeilToInt(lr - joinRite); if (len == 1) { SkAlpha alpha = trapezoid_to_alpha(ur - joinRite, lr - joinRite); - blit_single_alpha(blitter, y, joinRite >> 16, alpha, fullAlpha, maskRow, - isUsingMask, noRealBlitter, needSafeCheck); + blit_single_alpha(blitter, + y, + joinRite >> 16, + alpha, + fullAlpha, + maskRow, + isUsingMask, + noRealBlitter, + needSafeCheck); } else if (len == 2) { - SkFixed first = joinRite + SK_Fixed1 - ur; + SkFixed first = joinRite + SK_Fixed1 - ur; SkFixed second = lr - ur - first; - SkAlpha a1 = fullAlpha - partial_triangle_to_alpha(first, rDY); - SkAlpha a2 = partial_triangle_to_alpha(second, rDY); - blit_two_alphas(blitter, y, joinRite >> 16, a1, a2, fullAlpha, maskRow, - isUsingMask, noRealBlitter, needSafeCheck); + SkAlpha a1 = fullAlpha - partial_triangle_to_alpha(first, rDY); + SkAlpha a2 = partial_triangle_to_alpha(second, rDY); + blit_two_alphas(blitter, + y, + joinRite >> 16, + a1, + a2, + fullAlpha, + maskRow, + isUsingMask, + noRealBlitter, + needSafeCheck); } else { - blit_aaa_trapezoid_row(blitter, y, joinRite, ur, joinRite, lr, SK_MaxS32, rDY, - fullAlpha, maskRow, isUsingMask, noRealBlitter, + blit_aaa_trapezoid_row(blitter, + y, + joinRite, + ur, + joinRite, + lr, + SK_MaxS32, + rDY, + fullAlpha, + maskRow, + isUsingMask, + noRealBlitter, needSafeCheck); } } } else { - blit_aaa_trapezoid_row(blitter, y, ul, ur, ll, lr, lDY, rDY, fullAlpha, maskRow, - isUsingMask, noRealBlitter, needSafeCheck); + blit_aaa_trapezoid_row(blitter, + y, + ul, + ur, + ll, + lr, + lDY, + rDY, + fullAlpha, + maskRow, + isUsingMask, + noRealBlitter, + needSafeCheck); } } @@ -967,7 +1025,7 @@ // now make the edges linked in sorted order for (int i = 1; i < count; ++i) { list[i - 1]->fNext = list[i]; - list[i]->fPrev = list[i - 1]; + list[i]->fPrev = list[i - 1]; } *last = list[count - 1]; @@ -982,7 +1040,7 @@ edge->validate(); SkASSERT(y <= edge->fUpperY); - y = edge->fUpperY; + y = edge->fUpperY; edge = (SkAnalyticEdge*)edge->fNext; } #endif @@ -991,12 +1049,10 @@ // For an edge, we consider it smooth if the Dx doesn't change much, and Dy is large enough // For curves that are updating, the Dx is not changing much if fQDx/fCDx and fQDy/fCDy are // relatively large compared to fQDDx/QCDDx and fQDDy/fCDDy -static bool is_smooth_enough(SkAnalyticEdge* thisEdge, - SkAnalyticEdge* nextEdge, - int stop_y) { +static bool is_smooth_enough(SkAnalyticEdge* thisEdge, SkAnalyticEdge* nextEdge, int stop_y) { if (thisEdge->fCurveCount < 0) { - const SkCubicEdge& cEdge = static_cast<SkAnalyticCubicEdge*>(thisEdge)->fCEdge; - int ddshift = cEdge.fCurveShift; + const SkCubicEdge& cEdge = static_cast<SkAnalyticCubicEdge*>(thisEdge)->fCEdge; + int ddshift = cEdge.fCurveShift; return SkAbs32(cEdge.fCDx) >> 1 >= SkAbs32(cEdge.fCDDx) >> ddshift && SkAbs32(cEdge.fCDy) >> 1 >= SkAbs32(cEdge.fCDDy) >> ddshift && // current Dy is (fCDy - (fCDDy >> ddshift)) >> dshift @@ -1008,8 +1064,8 @@ // current Dy is (fQDy - fQDDy) >> shift (qEdge.fQDy - qEdge.fQDDy) >> qEdge.fCurveShift >= SK_Fixed1; } - return SkAbs32(nextEdge->fDX - thisEdge->fDX) <= SK_Fixed1 && // DDx should be small - nextEdge->fLowerY - nextEdge->fUpperY >= SK_Fixed1; // Dy should be large + return SkAbs32(nextEdge->fDX - thisEdge->fDX) <= SK_Fixed1 && // DDx should be small + nextEdge->fLowerY - nextEdge->fUpperY >= SK_Fixed1; // Dy should be large } // Check if the leftE and riteE are changing smoothly in terms of fDX. @@ -1017,19 +1073,19 @@ static bool is_smooth_enough(SkAnalyticEdge* leftE, SkAnalyticEdge* riteE, SkAnalyticEdge* currE, - int stop_y) { + int stop_y) { if (currE->fUpperY >= SkLeftShift(stop_y, 16)) { - return false; // We're at the end so we won't skip anything + return false; // We're at the end so we won't skip anything } if (leftE->fLowerY + SK_Fixed1 < riteE->fLowerY) { - return is_smooth_enough(leftE, currE, stop_y); // Only leftE is changing + return is_smooth_enough(leftE, currE, stop_y); // Only leftE is changing } else if (leftE->fLowerY > riteE->fLowerY + SK_Fixed1) { - return is_smooth_enough(riteE, currE, stop_y); // Only riteE is changing + return is_smooth_enough(riteE, currE, stop_y); // Only riteE is changing } // Now both edges are changing, find the second next edge SkAnalyticEdge* nextCurrE = currE->fNext; - if (nextCurrE->fUpperY >= stop_y << 16) { // Check if we're at the end + if (nextCurrE->fUpperY >= stop_y << 16) { // Check if we're at the end return false; } // Ensure that currE is the next left edge and nextCurrE is the next right edge. Swap if not. @@ -1039,25 +1095,25 @@ return is_smooth_enough(leftE, currE, stop_y) && is_smooth_enough(riteE, nextCurrE, stop_y); } -static void aaa_walk_convex_edges(SkAnalyticEdge* prevHead, +static void aaa_walk_convex_edges(SkAnalyticEdge* prevHead, AdditiveBlitter* blitter, - int start_y, - int stop_y, - SkFixed leftBound, - SkFixed riteBound, - bool isUsingMask) { + int start_y, + int stop_y, + SkFixed leftBound, + SkFixed riteBound, + bool isUsingMask) { validate_sort((SkAnalyticEdge*)prevHead->fNext); - SkAnalyticEdge* leftE = (SkAnalyticEdge*) prevHead->fNext; - SkAnalyticEdge* riteE = (SkAnalyticEdge*) leftE->fNext; - SkAnalyticEdge* currE = (SkAnalyticEdge*) riteE->fNext; + SkAnalyticEdge* leftE = (SkAnalyticEdge*)prevHead->fNext; + SkAnalyticEdge* riteE = (SkAnalyticEdge*)leftE->fNext; + SkAnalyticEdge* currE = (SkAnalyticEdge*)riteE->fNext; SkFixed y = SkTMax(leftE->fUpperY, riteE->fUpperY); for (;;) { // We have to check fLowerY first because some edges might be alone (e.g., there's only // a left edge but no right edge in a given y scan line) due to precision limit. - while (leftE->fLowerY <= y) { // Due to smooth jump, we may pass multiple short edges + while (leftE->fLowerY <= y) { // Due to smooth jump, we may pass multiple short edges if (!leftE->update(y)) { if (SkFixedFloorToInt(currE->fUpperY) >= stop_y) { goto END_WALK; @@ -1066,7 +1122,7 @@ currE = (SkAnalyticEdge*)currE->fNext; } } - while (riteE->fLowerY <= y) { // Due to smooth jump, we may pass multiple short edges + while (riteE->fLowerY <= y) { // Due to smooth jump, we may pass multiple short edges if (!riteE->update(y)) { if (SkFixedFloorToInt(currE->fUpperY) >= stop_y) { goto END_WALK; @@ -1090,8 +1146,7 @@ leftE->goY(y); riteE->goY(y); - if (leftE->fX > riteE->fX || (leftE->fX == riteE->fX && - leftE->fDX > riteE->fDX)) { + if (leftE->fX > riteE->fX || (leftE->fX == riteE->fX && leftE->fDX > riteE->fDX)) { std::swap(leftE, riteE); } @@ -1101,9 +1156,9 @@ } local_bot_fixed = SkMin32(local_bot_fixed, SkIntToFixed(stop_y)); - SkFixed left = SkTMax(leftBound, leftE->fX); + SkFixed left = SkTMax(leftBound, leftE->fX); SkFixed dLeft = leftE->fDX; - SkFixed rite = SkTMin(riteBound, riteE->fX); + SkFixed rite = SkTMin(riteBound, riteE->fX); SkFixed dRite = riteE->fDX; if (0 == (dLeft | dRite)) { int fullLeft = SkFixedCeilToInt(left); @@ -1114,33 +1169,34 @@ int fullBot = SkFixedFloorToInt(local_bot_fixed); SkFixed partialTop = SkIntToFixed(fullTop) - y; SkFixed partialBot = local_bot_fixed - SkIntToFixed(fullBot); - if (fullTop > fullBot) { // The rectangle is within one pixel height... + if (fullTop > fullBot) { // The rectangle is within one pixel height... partialTop -= (SK_Fixed1 - partialBot); partialBot = 0; } if (fullRite >= fullLeft) { - if (partialTop > 0) { // blit first partial row + if (partialTop > 0) { // blit first partial row if (partialLeft > 0) { - blitter->blitAntiH(fullLeft - 1, fullTop - 1, - fixed_to_alpha(SkFixedMul(partialTop, partialLeft))); + blitter->blitAntiH(fullLeft - 1, + fullTop - 1, + fixed_to_alpha(SkFixedMul(partialTop, partialLeft))); } - blitter->blitAntiH(fullLeft, fullTop - 1, fullRite - fullLeft, - fixed_to_alpha(partialTop)); + blitter->blitAntiH( + fullLeft, fullTop - 1, fullRite - fullLeft, fixed_to_alpha(partialTop)); if (partialRite > 0) { - blitter->blitAntiH(fullRite, fullTop - 1, - fixed_to_alpha(SkFixedMul(partialTop, partialRite))); + blitter->blitAntiH(fullRite, + fullTop - 1, + fixed_to_alpha(SkFixedMul(partialTop, partialRite))); } blitter->flush_if_y_changed(y, y + partialTop); } // Blit all full-height rows from fullTop to fullBot if (fullBot > fullTop && - // SkAAClip cannot handle the empty rect so check the non-emptiness here - // (bug chromium:662800) - (fullRite > fullLeft || - fixed_to_alpha(partialLeft) > 0 || - fixed_to_alpha(partialRite) > 0)) { + // SkAAClip cannot handle the empty rect so check the non-emptiness here + // (bug chromium:662800) + (fullRite > fullLeft || fixed_to_alpha(partialLeft) > 0 || + fixed_to_alpha(partialRite) > 0)) { blitter->getRealBlitter()->blitAntiRect(fullLeft - 1, fullTop, fullRite - fullLeft, @@ -1149,23 +1205,21 @@ fixed_to_alpha(partialRite)); } - if (partialBot > 0) { // blit last partial row + if (partialBot > 0) { // blit last partial row if (partialLeft > 0) { blitter->blitAntiH(fullLeft - 1, fullBot, fixed_to_alpha(SkFixedMul(partialBot, partialLeft))); } - blitter->blitAntiH(fullLeft, - fullBot, - fullRite - fullLeft, - fixed_to_alpha(partialBot)); + blitter->blitAntiH( + fullLeft, fullBot, fullRite - fullLeft, fixed_to_alpha(partialBot)); if (partialRite > 0) { blitter->blitAntiH(fullRite, fullBot, fixed_to_alpha(SkFixedMul(partialBot, partialRite))); } } - } else { // left and rite are within the same pixel + } else { // left and rite are within the same pixel if (partialTop > 0) { blitter->blitAntiH(fullLeft - 1, fullTop - 1, @@ -1174,14 +1228,14 @@ blitter->flush_if_y_changed(y, y + partialTop); } if (fullBot > fullTop) { - blitter->getRealBlitter()->blitV(fullLeft - 1, - fullTop, - fullBot - fullTop, - fixed_to_alpha(rite - left)); + blitter->getRealBlitter()->blitV( + fullLeft - 1, fullTop, fullBot - fullTop, fixed_to_alpha(rite - left)); } if (partialBot > 0) { - blitter->blitAntiH(fullLeft - 1, fullBot, 1, - fixed_to_alpha(SkFixedMul(partialBot, rite - left))); + blitter->blitAntiH(fullLeft - 1, + fullBot, + 1, + fixed_to_alpha(SkFixedMul(partialBot, rite - left))); } } @@ -1191,9 +1245,10 @@ // We snap X mainly for speedup (no tiny triangle) and // avoiding edge cases caused by precision errors const SkFixed kSnapDigit = SK_Fixed1 >> 4; - const SkFixed kSnapHalf = kSnapDigit >> 1; - const SkFixed kSnapMask = (-1 ^ (kSnapDigit - 1)); - left += kSnapHalf; rite += kSnapHalf; // For fast rounding + const SkFixed kSnapHalf = kSnapDigit >> 1; + const SkFixed kSnapMask = (-1 ^ (kSnapDigit - 1)); + left += kSnapHalf; + rite += kSnapHalf; // For fast rounding // Number of blit_trapezoid_row calls we'll have int count = SkFixedCeilToInt(local_bot_fixed) - SkFixedFloorToInt(y); @@ -1210,14 +1265,13 @@ // handle partial-row blit and full-row blit separately. It will save us much time // on changing y, left, and rite. if (count > 1) { - if ((int)(y & 0xFFFF0000) != y) { // There's a partial-row on the top + if ((int)(y & 0xFFFF0000) != y) { // There's a partial-row on the top count--; - SkFixed nextY = SkFixedCeilToFixed(y + 1); - SkFixed dY = nextY - y; + SkFixed nextY = SkFixedCeilToFixed(y + 1); + SkFixed dY = nextY - y; SkFixed nextLeft = left + SkFixedMul(dLeft, dY); SkFixed nextRite = rite + SkFixedMul(dRite, dY); - SkASSERT((left & kSnapMask) >= leftBound && - (rite & kSnapMask) <= riteBound && + SkASSERT((left & kSnapMask) >= leftBound && (rite & kSnapMask) <= riteBound && (nextLeft & kSnapMask) >= leftBound && (nextRite & kSnapMask) <= riteBound); blit_trapezoid_row(blitter, @@ -1234,17 +1288,16 @@ blitter->flush_if_y_changed(y, nextY); left = nextLeft; rite = nextRite; - y = nextY; + y = nextY; } - while (count > 1) { // Full rows in the middle + while (count > 1) { // Full rows in the middle count--; if (isUsingMask) { maskRow = static_cast<MaskAdditiveBlitter*>(blitter)->getRow(y >> 16); } SkFixed nextY = y + SK_Fixed1, nextLeft = left + dLeft, nextRite = rite + dRite; - SkASSERT((left & kSnapMask) >= leftBound && - (rite & kSnapMask) <= riteBound && + SkASSERT((left & kSnapMask) >= leftBound && (rite & kSnapMask) <= riteBound && (nextLeft & kSnapMask) >= leftBound && (nextRite & kSnapMask) <= riteBound); blit_trapezoid_row(blitter, @@ -1261,7 +1314,7 @@ blitter->flush_if_y_changed(y, nextY); left = nextLeft; rite = nextRite; - y = nextY; + y = nextY; } } @@ -1269,17 +1322,15 @@ maskRow = static_cast<MaskAdditiveBlitter*>(blitter)->getRow(y >> 16); } - SkFixed dY = local_bot_fixed - y; // partial-row on the bottom + SkFixed dY = local_bot_fixed - y; // partial-row on the bottom SkASSERT(dY <= SK_Fixed1); // Smooth jumping to integer y may make the last nextLeft/nextRite out of bound. // Take them back into the bound here. // Note that we substract kSnapHalf later so we have to add them to leftBound/riteBound SkFixed nextLeft = SkTMax(left + SkFixedMul(dLeft, dY), leftBound + kSnapHalf); SkFixed nextRite = SkTMin(rite + SkFixedMul(dRite, dY), riteBound + kSnapHalf); - SkASSERT((left & kSnapMask) >= leftBound && - (rite & kSnapMask) <= riteBound && - (nextLeft & kSnapMask) >= leftBound && - (nextRite & kSnapMask) <= riteBound); + SkASSERT((left & kSnapMask) >= leftBound && (rite & kSnapMask) <= riteBound && + (nextLeft & kSnapMask) >= leftBound && (nextRite & kSnapMask) <= riteBound); blit_trapezoid_row(blitter, y >> 16, left & kSnapMask, @@ -1294,7 +1345,7 @@ blitter->flush_if_y_changed(y, local_bot_fixed); left = nextLeft; rite = nextRite; - y = local_bot_fixed; + y = local_bot_fixed; left -= kSnapHalf; rite -= kSnapHalf; } @@ -1304,8 +1355,7 @@ leftE->fY = riteE->fY = y; } -END_WALK: - ; +END_WALK:; } static void update_next_next_y(SkFixed y, SkFixed nextY, SkFixed* nextNextY) { @@ -1335,7 +1385,7 @@ } // find first x pos to insert SkAnalyticEdge* start = backward_insert_start(prev, newEdge->fX); - //insert the lot, fixing up the links as we go + // insert the lot, fixing up the links as we go do { SkAnalyticEdge* next = newEdge->fNext; do { @@ -1351,10 +1401,10 @@ } while (true); remove_edge(newEdge); insert_edge_after(newEdge, start); -nextEdge: + nextEdge: check_intersection(newEdge, y, nextNextY); update_next_next_y(newEdge->fLowerY, y, nextNextY); - start = newEdge; + start = newEdge; newEdge = next; } while (newEdge->fUpperY <= y); update_next_next_y(newEdge->fUpperY, y, nextNextY); @@ -1386,8 +1436,8 @@ // However, to handle that case, we have to sacrafice more performance. // I think the current quality is good enough (mainly by looking at Nebraska-StateSeal.svg) // so I'll ignore fDX for performance tradeoff. - return next && prev && next->fUpperY < lowerY && prev->fX + SLACK >= - next->fX - SkAbs32(next->fDX); + return next && prev && next->fUpperY < lowerY && + prev->fX + SLACK >= next->fX - SkAbs32(next->fDX); // The following is more accurate but also slower. // return (prev && prev->fPrev && next && next->fNext != nullptr && next->fUpperY < lowerY && // prev->fX + SkAbs32(prev->fDX) + SLACK >= next->fX - SkAbs32(next->fDX)); @@ -1399,16 +1449,16 @@ return prevRite > SkFixedFloorToInt(ul) || prevRite > SkFixedFloorToInt(ll); } -static void blit_saved_trapezoid(SkAnalyticEdge* leftE, - SkFixed lowerY, - SkFixed lowerLeft, - SkFixed lowerRite, +static void blit_saved_trapezoid(SkAnalyticEdge* leftE, + SkFixed lowerY, + SkFixed lowerLeft, + SkFixed lowerRite, AdditiveBlitter* blitter, - SkAlpha* maskRow, - bool isUsingMask, - bool noRealBlitter, - SkFixed leftClip, - SkFixed rightClip) { + SkAlpha* maskRow, + bool isUsingMask, + bool noRealBlitter, + SkFixed leftClip, + SkFixed rightClip) { SkAnalyticEdge* riteE = leftE->fRiteE; SkASSERT(riteE); SkASSERT(riteE->fNext == nullptr || leftE->fSavedY == riteE->fSavedY); @@ -1417,44 +1467,43 @@ // Instead of using fixed_to_alpha(lowerY - leftE->fSavedY), we use the following fullAlpha // to elimiate cumulative error: if there are many fractional y scan lines within the // same row, the former may accumulate the rounding error while the later won't. - SkAlpha fullAlpha = fixed_to_alpha(lowerY - SkIntToFixed(y)) - - fixed_to_alpha(leftE->fSavedY - SkIntToFixed(y)); + SkAlpha fullAlpha = fixed_to_alpha(lowerY - SkIntToFixed(y)) - + fixed_to_alpha(leftE->fSavedY - SkIntToFixed(y)); // We need fSavedDY because the (quad or cubic) edge might be updated - blit_trapezoid_row(blitter, - y, - SkTMax(leftE->fSavedX, leftClip), - SkTMin(riteE->fSavedX, rightClip), - SkTMax(lowerLeft, leftClip), - SkTMin(lowerRite, rightClip), - leftE->fSavedDY, - riteE->fSavedDY, - fullAlpha, - maskRow, - isUsingMask, - noRealBlitter || - (fullAlpha == 0xFF && - (edges_too_close(leftE->fPrev, leftE, lowerY) || - edges_too_close(riteE, riteE->fNext, lowerY))), - true); + blit_trapezoid_row( + blitter, + y, + SkTMax(leftE->fSavedX, leftClip), + SkTMin(riteE->fSavedX, rightClip), + SkTMax(lowerLeft, leftClip), + SkTMin(lowerRite, rightClip), + leftE->fSavedDY, + riteE->fSavedDY, + fullAlpha, + maskRow, + isUsingMask, + noRealBlitter || (fullAlpha == 0xFF && (edges_too_close(leftE->fPrev, leftE, lowerY) || + edges_too_close(riteE, riteE->fNext, lowerY))), + true); leftE->fRiteE = nullptr; } static void deferred_blit(SkAnalyticEdge* leftE, SkAnalyticEdge* riteE, - SkFixed left, - SkFixed leftDY, // don't save leftE->fX/fDY as they may have been updated + SkFixed left, + SkFixed leftDY, // don't save leftE->fX/fDY as they may have been updated SkFixed y, SkFixed nextY, - bool isIntegralNextY, - bool leftEnds, - bool riteEnds, + bool isIntegralNextY, + bool leftEnds, + bool riteEnds, AdditiveBlitter* blitter, - SkAlpha* maskRow, - bool isUsingMask, - bool noRealBlitter, - SkFixed leftClip, - SkFixed rightClip, - int yShift) { + SkAlpha* maskRow, + bool isUsingMask, + bool noRealBlitter, + SkFixed leftClip, + SkFixed rightClip, + int yShift) { if (leftE->fRiteE && leftE->fRiteE != riteE) { // leftE's right edge changed. Blit the saved trapezoid. SkASSERT(leftE->fRiteE->fNext == nullptr || leftE->fRiteE->fY == y); @@ -1495,26 +1544,26 @@ } } -static void aaa_walk_edges(SkAnalyticEdge* prevHead, - SkAnalyticEdge* nextTail, +static void aaa_walk_edges(SkAnalyticEdge* prevHead, + SkAnalyticEdge* nextTail, SkPath::FillType fillType, AdditiveBlitter* blitter, - int start_y, - int stop_y, - SkFixed leftClip, - SkFixed rightClip, - bool isUsingMask, - bool forceRLE, - bool useDeferred, - bool skipIntersect) { + int start_y, + int stop_y, + SkFixed leftClip, + SkFixed rightClip, + bool isUsingMask, + bool forceRLE, + bool useDeferred, + bool skipIntersect) { prevHead->fX = prevHead->fUpperX = leftClip; nextTail->fX = nextTail->fUpperX = rightClip; - SkFixed y = SkTMax(prevHead->fNext->fUpperY, SkIntToFixed(start_y)); - SkFixed nextNextY = SK_MaxS32; + SkFixed y = SkTMax(prevHead->fNext->fUpperY, SkIntToFixed(start_y)); + SkFixed nextNextY = SK_MaxS32; { SkAnalyticEdge* edge; - for(edge = prevHead->fNext; edge->fUpperY <= y; edge = edge->fNext) { + for (edge = prevHead->fNext; edge->fUpperY <= y; edge = edge->fNext) { edge->goY(y); update_next_next_y(edge->fLowerY, y, &nextNextY); } @@ -1529,14 +1578,12 @@ if (isInverse && SkIntToFixed(start_y) != y) { int width = SkFixedFloorToInt(rightClip - leftClip); if (SkFixedFloorToInt(y) != start_y) { - blitter->getRealBlitter()->blitRect(SkFixedFloorToInt(leftClip), - start_y, - width, - SkFixedFloorToInt(y) - start_y); + blitter->getRealBlitter()->blitRect( + SkFixedFloorToInt(leftClip), start_y, width, SkFixedFloorToInt(y) - start_y); start_y = SkFixedFloorToInt(y); } - SkAlpha* maskRow = isUsingMask ? static_cast<MaskAdditiveBlitter*>(blitter)->getRow(start_y) - : nullptr; + SkAlpha* maskRow = + isUsingMask ? static_cast<MaskAdditiveBlitter*>(blitter)->getRow(start_y) : nullptr; blit_full_alpha(blitter, start_y, SkFixedFloorToInt(leftClip), @@ -1549,25 +1596,25 @@ } while (true) { - int w = 0; - bool in_interval = isInverse; - SkFixed prevX = prevHead->fX; - SkFixed nextY = SkTMin(nextNextY, SkFixedCeilToFixed(y + 1)); - bool isIntegralNextY = (nextY & (SK_Fixed1 - 1)) == 0; - SkAnalyticEdge* currE = prevHead->fNext; - SkAnalyticEdge* leftE = prevHead; - SkFixed left = leftClip; - SkFixed leftDY = 0; - bool leftEnds = false; - int prevRite = SkFixedFloorToInt(leftClip); + int w = 0; + bool in_interval = isInverse; + SkFixed prevX = prevHead->fX; + SkFixed nextY = SkTMin(nextNextY, SkFixedCeilToFixed(y + 1)); + bool isIntegralNextY = (nextY & (SK_Fixed1 - 1)) == 0; + SkAnalyticEdge* currE = prevHead->fNext; + SkAnalyticEdge* leftE = prevHead; + SkFixed left = leftClip; + SkFixed leftDY = 0; + bool leftEnds = false; + int prevRite = SkFixedFloorToInt(leftClip); - nextNextY = SK_MaxS32; + nextNextY = SK_MaxS32; SkASSERT((nextY & ((SK_Fixed1 >> 2) - 1)) == 0); int yShift = 0; if ((nextY - y) & (SK_Fixed1 >> 2)) { yShift = 2; - nextY = y + (SK_Fixed1 >> 2); + nextY = y + (SK_Fixed1 >> 2); } else if ((nextY - y) & (SK_Fixed1 >> 1)) { yShift = 1; SkASSERT(nextY == y + (SK_Fixed1 >> 1)); @@ -1587,7 +1634,7 @@ // Even if next - y == SK_Fixed1, we can still break the left-to-right order requirement // of the SKAAClip: |\| (two trapezoids with overlapping middle wedges) - bool noRealBlitter = forceRLE; // forceRLE && (nextY - y != SK_Fixed1); + bool noRealBlitter = forceRLE; // forceRLE && (nextY - y != SK_Fixed1); while (currE->fUpperY <= y) { SkASSERT(currE->fLowerY >= nextY); @@ -1595,10 +1642,10 @@ w += currE->fWinding; bool prev_in_interval = in_interval; - in_interval = !(w & windingMask) == isInverse; + in_interval = !(w & windingMask) == isInverse; - bool isLeft = in_interval && !prev_in_interval; - bool isRite = !in_interval && prev_in_interval; + bool isLeft = in_interval && !prev_in_interval; + bool isRite = !in_interval && prev_in_interval; bool currEnds = currE->fLowerY == nextY; if (useDeferred) { @@ -1656,39 +1703,38 @@ SkFixed rite = currE->fX; currE->goY(nextY, yShift); SkFixed nextLeft = SkTMax(leftClip, leftE->fX); - rite = SkTMin(rightClip, rite); + rite = SkTMin(rightClip, rite); SkFixed nextRite = SkTMin(rightClip, currE->fX); - blit_trapezoid_row(blitter, - y >> 16, - left, - rite, - nextLeft, - nextRite, - leftDY, - currE->fDY, - fullAlpha, - maskRow, - isUsingMask, - noRealBlitter || - (fullAlpha == 0xFF && - (edges_too_close(prevRite, left, leftE->fX) || - edges_too_close(currE, currE->fNext, nextY))), - true); + blit_trapezoid_row( + blitter, + y >> 16, + left, + rite, + nextLeft, + nextRite, + leftDY, + currE->fDY, + fullAlpha, + maskRow, + isUsingMask, + noRealBlitter || (fullAlpha == 0xFF && + (edges_too_close(prevRite, left, leftE->fX) || + edges_too_close(currE, currE->fNext, nextY))), + true); prevRite = SkFixedCeilToInt(SkTMax(rite, currE->fX)); } } else { if (isLeft) { - left = SkTMax(currE->fX, leftClip); - leftDY = currE->fDY; - leftE = currE; + left = SkTMax(currE->fX, leftClip); + leftDY = currE->fDY; + leftE = currE; leftEnds = leftE->fLowerY == nextY; } currE->goY(nextY, yShift); } - SkAnalyticEdge* next = currE->fNext; - SkFixed newX; + SkFixed newX; while (currE->fLowerY <= nextY) { if (currE->fCurveCount < 0) { @@ -1715,7 +1761,7 @@ update_next_next_y(currE->fLowerY, nextY, &nextNextY); newX = currE->fX; SkASSERT(currE->fLowerY > nextY); - if (newX < prevX) { // ripple currE backwards until it is x-sorted + if (newX < prevX) { // ripple currE backwards until it is x-sorted // If the crossing edge is a right edge, blit the saved trapezoid. if (leftE->fRiteE == currE && useDeferred) { SkASSERT(leftE->fY == nextY && currE->fY == nextY); @@ -1735,7 +1781,7 @@ prevX = newX; } if (!skipIntersect) { - check_intersection(currE, nextY, &nextNextY); + check_intersection(currE, nextY, &nextNextY); } } @@ -1774,9 +1820,8 @@ fullAlpha, maskRow, isUsingMask, - noRealBlitter || - (fullAlpha == 0xFF && - edges_too_close(leftE->fPrev, leftE, nextY)), + noRealBlitter || (fullAlpha == 0xFF && + edges_too_close(leftE->fPrev, leftE, nextY)), true); } } @@ -1795,19 +1840,20 @@ } } -static SK_ALWAYS_INLINE void aaa_fill_path(const SkPath& path, - const SkIRect& clipRect, - AdditiveBlitter* blitter, - int start_y, - int stop_y, - bool pathContainedInClip, - bool isUsingMask, - bool forceRLE) { // forceRLE implies that SkAAClip is calling us +static SK_ALWAYS_INLINE void aaa_fill_path( + const SkPath& path, + const SkIRect& clipRect, + AdditiveBlitter* blitter, + int start_y, + int stop_y, + bool pathContainedInClip, + bool isUsingMask, + bool forceRLE) { // forceRLE implies that SkAAClip is calling us SkASSERT(blitter); SkAnalyticEdgeBuilder builder; - int count = builder.buildEdges(path, pathContainedInClip ? nullptr : &clipRect); - SkAnalyticEdge** list = builder.analyticEdgeList(); + int count = builder.buildEdges(path, pathContainedInClip ? nullptr : &clipRect); + SkAnalyticEdge** list = builder.analyticEdgeList(); SkIRect rect = clipRect; if (0 == count) { @@ -1825,8 +1871,8 @@ rect.fBottom = stop_y; } if (!rect.isEmpty()) { - blitter->getRealBlitter()->blitRect(rect.fLeft, rect.fTop, - rect.width(), rect.height()); + blitter->getRealBlitter()->blitRect( + rect.fLeft, rect.fTop, rect.width(), rect.height()); } } return; @@ -1836,25 +1882,25 @@ // this returns the first and last edge after they're sorted into a dlink list SkAnalyticEdge* edge = sort_edges(list, count, &last); - headEdge.fRiteE = nullptr; - headEdge.fPrev = nullptr; - headEdge.fNext = edge; + headEdge.fRiteE = nullptr; + headEdge.fPrev = nullptr; + headEdge.fNext = edge; headEdge.fUpperY = headEdge.fLowerY = SK_MinS32; - headEdge.fX = SK_MinS32; - headEdge.fDX = 0; - headEdge.fDY = SK_MaxS32; - headEdge.fUpperX = SK_MinS32; - edge->fPrev = &headEdge; + headEdge.fX = SK_MinS32; + headEdge.fDX = 0; + headEdge.fDY = SK_MaxS32; + headEdge.fUpperX = SK_MinS32; + edge->fPrev = &headEdge; - tailEdge.fRiteE = nullptr; - tailEdge.fPrev = last; - tailEdge.fNext = nullptr; + tailEdge.fRiteE = nullptr; + tailEdge.fPrev = last; + tailEdge.fNext = nullptr; tailEdge.fUpperY = tailEdge.fLowerY = SK_MaxS32; - tailEdge.fX = SK_MaxS32; - tailEdge.fDX = 0; - tailEdge.fDY = SK_MaxS32; - tailEdge.fUpperX = SK_MaxS32; - last->fNext = &tailEdge; + tailEdge.fX = SK_MaxS32; + tailEdge.fDX = 0; + tailEdge.fDY = SK_MaxS32; + tailEdge.fUpperX = SK_MaxS32; + last->fNext = &tailEdge; // now edge is the head of the sorted linklist @@ -1865,28 +1911,24 @@ stop_y = clipRect.fBottom; } - SkFixed leftBound = SkIntToFixed(rect.fLeft); + SkFixed leftBound = SkIntToFixed(rect.fLeft); SkFixed rightBound = SkIntToFixed(rect.fRight); if (isUsingMask) { // If we're using mask, then we have to limit the bound within the path bounds. // Otherwise, the edge drift may access an invalid address inside the mask. SkIRect ir; path.getBounds().roundOut(&ir); - leftBound = SkTMax(leftBound, SkIntToFixed(ir.fLeft)); + leftBound = SkTMax(leftBound, SkIntToFixed(ir.fLeft)); rightBound = SkTMin(rightBound, SkIntToFixed(ir.fRight)); } if (!path.isInverseFillType() && path.isConvex() && count >= 2) { - aaa_walk_convex_edges(&headEdge, - blitter, - start_y, - stop_y, - leftBound, - rightBound, - isUsingMask); + aaa_walk_convex_edges( + &headEdge, blitter, start_y, stop_y, leftBound, rightBound, isUsingMask); } else { // Only use deferred blitting if there are many edges. - bool useDeferred = count > + bool useDeferred = + count > (SkFixedFloorToInt(tailEdge.fPrev->fLowerY - headEdge.fNext->fUpperY) + 1) * 4; // We skip intersection computation if there are many points which probably already @@ -1908,13 +1950,13 @@ } } -void SkScan::AAAFillPath(const SkPath& path, - SkBlitter* blitter, +void SkScan::AAAFillPath(const SkPath& path, + SkBlitter* blitter, const SkIRect& ir, const SkIRect& clipBounds, - bool forceRLE) { + bool forceRLE) { bool containedInClip = clipBounds.contains(ir); - bool isInverse = path.isInverseFillType(); + bool isInverse = path.isInverseFillType(); // The mask blitter (where we store intermediate alpha values directly in a mask, and then call // the real blitter once in the end to blit the whole mask) is faster than the RLE blitter when @@ -1966,4 +2008,4 @@ forceRLE); } } -#endif //defined(SK_DISABLE_AAA) +#endif // defined(SK_DISABLE_AAA)