diff --git a/gn/flutter_defines.gni b/gn/flutter_defines.gni index 91083c760a..e7938f273e 100644 --- a/gn/flutter_defines.gni +++ b/gn/flutter_defines.gni @@ -7,4 +7,8 @@ flutter_defines = [ "SK_DISABLE_RENDER_TARGET_SORTING", "SK_SUPPORT_LEGACY_VULKAN_INTERFACE", "SK_LEGACY_SKCODEC_NONE_ENUM", + + # Remove software rasterizers to save some code size. + "SK_DISABLE_AAA", + "SK_DISABLE_DAA", ] diff --git a/src/core/SkScan_AntiPath.cpp b/src/core/SkScan_AntiPath.cpp index 02d8618593..fe26b17e57 100644 --- a/src/core/SkScan_AntiPath.cpp +++ b/src/core/SkScan_AntiPath.cpp @@ -600,14 +600,11 @@ static SkIRect safeRoundOut(const SkRect& src) { } constexpr int kSampleSize = 8; -constexpr SkScalar kComplexityThreshold = 0.25; -constexpr SkScalar kSmallCubicThreshold = 16; +#if !defined(SK_DISABLE_DAA) || !defined(SK_DISABLE_AAA) + constexpr SkScalar kComplexityThreshold = 0.25; +#endif -static inline SkScalar sqr(SkScalar x) { - return x * x; -} - -static void ComputeComplexity(const SkPath& path, SkScalar& avgLength, SkScalar& complexity) { +static void compute_complexity(const SkPath& path, SkScalar& avgLength, SkScalar& complexity) { int n = path.countPoints(); if (n < kSampleSize || path.getBounds().isEmpty()) { // set to invalid value to indicate that we failed to compute @@ -624,6 +621,8 @@ static void ComputeComplexity(const SkPath& path, SkScalar& avgLength, SkScalar& } avgLength = sumLength / (kSampleSize - 1); + auto sqr = [](SkScalar x) { return x*x; }; + SkScalar diagonalSqr = sqr(path.getBounds().width()) + sqr(path.getBounds().height()); // If the path consists of random line segments, the number of intersections should be @@ -639,6 +638,11 @@ static void ComputeComplexity(const SkPath& path, SkScalar& avgLength, SkScalar& } static bool ShouldUseDAA(const SkPath& path, SkScalar avgLength, SkScalar complexity) { +#if defined(SK_DISABLE_DAA) + return false; +#else + constexpr SkScalar kSmallCubicThreshold = 16; + if (gSkForceDeltaAA) { return true; } @@ -646,10 +650,10 @@ static bool ShouldUseDAA(const SkPath& path, SkScalar avgLength, SkScalar comple return false; } -#ifdef SK_SUPPORT_LEGACY_AA_CHOICE + #ifdef SK_SUPPORT_LEGACY_AA_CHOICE const SkRect& bounds = path.getBounds(); return !path.isConvex() && path.countPoints() >= SkTMax(bounds.width(), bounds.height()) / 8; -#else + #else if (avgLength < 0 || complexity < 0 || path.getBounds().isEmpty() || path.isConvex()) { return false; } @@ -674,10 +678,14 @@ static bool ShouldUseDAA(const SkPath& path, SkScalar avgLength, SkScalar comple } return complexity >= kComplexityThreshold; + #endif #endif } static bool ShouldUseAAA(const SkPath& path, SkScalar avgLength, SkScalar complexity) { +#if defined(SK_DISABLE_AAA) + return false; +#else if (gSkForceAnalyticAA) { return true; } @@ -688,7 +696,7 @@ static bool ShouldUseAAA(const SkPath& path, SkScalar avgLength, SkScalar comple return true; } -#ifdef SK_SUPPORT_LEGACY_AAA_CHOICE + #ifdef SK_SUPPORT_LEGACY_AAA_CHOICE const SkRect& bounds = path.getBounds(); // When the path have so many points compared to the size of its bounds/resolution, // it indicates that the path is not quite smooth in the current resolution: @@ -696,7 +704,7 @@ static bool ShouldUseAAA(const SkPath& path, SkScalar avgLength, SkScalar comple // zero. Hence Aanlytic AA is not likely to produce visible quality improvements, and Analytic // AA might be slower than supersampling. return path.countPoints() < SkTMax(bounds.width(), bounds.height()) / 2 - 10; -#else + #else if (path.countPoints() >= path.getBounds().height()) { // SAA is faster than AAA in this case even if there are no intersections because AAA will // have too many scan lines. See skbug.com/8272 @@ -705,6 +713,7 @@ static bool ShouldUseAAA(const SkPath& path, SkScalar avgLength, SkScalar comple // We will use AAA if the number of verbs < kSampleSize and therefore complexity < 0 return complexity < kComplexityThreshold; + #endif #endif } @@ -824,7 +833,7 @@ void SkScan::AntiFillPath(const SkPath& path, const SkRegion& origClip, } SkScalar avgLength, complexity; - ComputeComplexity(path, avgLength, complexity); + compute_complexity(path, avgLength, complexity); if (daaRecord || ShouldUseDAA(path, avgLength, complexity)) { SkScan::DAAFillPath(path, blitter, ir, clipRgn->getBounds(), forceRLE, daaRecord);