diff --git a/src/core/SkScan.h b/src/core/SkScan.h
index c995542..e5c6047 100644
--- a/src/core/SkScan.h
+++ b/src/core/SkScan.h
@@ -51,7 +51,6 @@
     static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
     static void FillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
     static void AntiFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
-    static void AAAFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
     static void FrameRect(const SkRect&, const SkPoint& strokeSize,
                           const SkRasterClip&, SkBlitter*);
     static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
@@ -68,6 +67,9 @@
     static void HairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
     static void AntiHairRoundPath(const SkPath&, const SkRasterClip&, SkBlitter*);
 
+    // Needed by do_fill_path in SkScanPriv.h
+    static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
+
 private:
     friend class SkAAClip;
     friend class SkRegion;
@@ -77,7 +79,6 @@
     static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
     static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
     static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*);
-    static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
     static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*,
                              bool forceRLE = false);
     static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
diff --git a/src/core/SkScanPriv.h b/src/core/SkScanPriv.h
index eca3c9c..f8d3bb2 100644
--- a/src/core/SkScanPriv.h
+++ b/src/core/SkScanPriv.h
@@ -9,6 +9,7 @@
 #ifndef SkScanPriv_DEFINED
 #define SkScanPriv_DEFINED
 
+#include "SkPath.h"
 #include "SkScan.h"
 #include "SkBlitter.h"
 
@@ -77,4 +78,132 @@
     return prev;
 }
 
+static bool fitsInsideLimit(const SkRect& r, SkScalar max) {
+    const SkScalar min = -max;
+    return  r.fLeft > min && r.fTop > min &&
+            r.fRight < max && r.fBottom < max;
+}
+
+static int overflows_short_shift(int value, int shift) {
+    const int s = 16 + shift;
+    return (SkLeftShift(value, s) >> s) - value;
+}
+
+/**
+  Would any of the coordinates of this rectangle not fit in a short,
+  when left-shifted by shift?
+*/
+static int rect_overflows_short_shift(SkIRect rect, int shift) {
+    SkASSERT(!overflows_short_shift(8191, shift));
+    SkASSERT(overflows_short_shift(8192, shift));
+    SkASSERT(!overflows_short_shift(32767, 0));
+    SkASSERT(overflows_short_shift(32768, 0));
+
+    // Since we expect these to succeed, we bit-or together
+    // for a tiny extra bit of speed.
+    return overflows_short_shift(rect.fLeft, shift) |
+           overflows_short_shift(rect.fRight, shift) |
+           overflows_short_shift(rect.fTop, shift) |
+           overflows_short_shift(rect.fBottom, shift);
+}
+
+static bool safeRoundOut(const SkRect& src, SkIRect* dst, int32_t maxInt) {
+    const SkScalar maxScalar = SkIntToScalar(maxInt);
+
+    if (fitsInsideLimit(src, maxScalar)) {
+        src.roundOut(dst);
+        return true;
+    }
+    return false;
+}
+
+using FillPathFunc = std::function<void(const SkPath& path, SkBlitter* blitter, bool isInverse,
+        const SkIRect& ir, const SkRegion* clipRgn, const SkIRect* clipRect, bool forceRLE)>;
+
+static inline void do_fill_path(const SkPath& path, const SkRegion& origClip, SkBlitter* blitter,
+        bool forceRLE, const int SHIFT, FillPathFunc fillPathFunc) {
+    if (origClip.isEmpty()) {
+        return;
+    }
+
+    const bool isInverse = path.isInverseFillType();
+    SkIRect ir;
+
+    if (!safeRoundOut(path.getBounds(), &ir, SK_MaxS32 >> SHIFT)) {
+        // Bounds can't fit in SkIRect; we'll return without drawing
+        return;
+    }
+    if (ir.isEmpty()) {
+        if (isInverse) {
+            blitter->blitRegion(origClip);
+        }
+        return;
+    }
+
+    // If the intersection of the path bounds and the clip bounds
+    // will overflow 32767 when << by SHIFT, we can't supersample,
+    // so draw without antialiasing.
+    SkIRect clippedIR;
+    if (isInverse) {
+       // If the path is an inverse fill, it's going to fill the entire
+       // clip, and we care whether the entire clip exceeds our limits.
+       clippedIR = origClip.getBounds();
+    } else {
+       if (!clippedIR.intersect(ir, origClip.getBounds())) {
+           return;
+       }
+    }
+    if (rect_overflows_short_shift(clippedIR, SHIFT)) {
+        SkScan::FillPath(path, origClip, blitter);
+        return;
+    }
+
+    // Our antialiasing can't handle a clip larger than 32767, so we restrict
+    // the clip to that limit here. (the runs[] uses int16_t for its index).
+    //
+    // A more general solution (one that could also eliminate the need to
+    // disable aa based on ir bounds (see overflows_short_shift) would be
+    // to tile the clip/target...
+    SkRegion tmpClipStorage;
+    const SkRegion* clipRgn = &origClip;
+    {
+        static const int32_t kMaxClipCoord = 32767;
+        const SkIRect& bounds = origClip.getBounds();
+        if (bounds.fRight > kMaxClipCoord || bounds.fBottom > kMaxClipCoord) {
+            SkIRect limit = { 0, 0, kMaxClipCoord, kMaxClipCoord };
+            tmpClipStorage.op(origClip, limit, SkRegion::kIntersect_Op);
+            clipRgn = &tmpClipStorage;
+        }
+    }
+    // for here down, use clipRgn, not origClip
+
+    SkScanClipper   clipper(blitter, clipRgn, ir);
+    const SkIRect*  clipRect = clipper.getClipRect();
+
+    if (clipper.getBlitter() == nullptr) { // clipped out
+        if (isInverse) {
+            blitter->blitRegion(*clipRgn);
+        }
+        return;
+    }
+
+    SkASSERT(clipper.getClipRect() == nullptr ||
+            *clipper.getClipRect() == clipRgn->getBounds());
+
+    // now use the (possibly wrapped) blitter
+    blitter = clipper.getBlitter();
+
+    if (isInverse) {
+        sk_blit_above(blitter, ir, *clipRgn);
+    }
+
+    SkASSERT(SkIntToScalar(ir.fTop) <= path.getBounds().fTop);
+
+    fillPathFunc(path, blitter, isInverse, ir, clipRgn, clipRect, forceRLE);
+
+    if (isInverse) {
+        sk_blit_below(blitter, ir, *clipRgn);
+    }
+}
+
 #endif
diff --git a/src/core/SkScan_AAAPath.cpp b/src/core/SkScan_AAAPath.cpp
index cb38d61..7a52922 100644
--- a/src/core/SkScan_AAAPath.cpp
+++ b/src/core/SkScan_AAAPath.cpp
@@ -1682,152 +1682,36 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-static int overflows_short_shift(int value, int shift) {
-    const int s = 16 + shift;
-    return (SkLeftShift(value, s) >> s) - value;
-}
-
-/**
-  Would any of the coordinates of this rectangle not fit in a short,
-  when left-shifted by shift?
-*/
-static int rect_overflows_short_shift(SkIRect rect, int shift) {
-    SkASSERT(!overflows_short_shift(8191, 2));
-    SkASSERT(overflows_short_shift(8192, 2));
-    SkASSERT(!overflows_short_shift(32767, 0));
-    SkASSERT(overflows_short_shift(32768, 0));
-
-    // Since we expect these to succeed, we bit-or together
-    // for a tiny extra bit of speed.
-    return overflows_short_shift(rect.fLeft, 2) |
-           overflows_short_shift(rect.fRight, 2) |
-           overflows_short_shift(rect.fTop, 2) |
-           overflows_short_shift(rect.fBottom, 2);
-}
-
-static bool fitsInsideLimit(const SkRect& r, SkScalar max) {
-    const SkScalar min = -max;
-    return  r.fLeft > min && r.fTop > min &&
-            r.fRight < max && r.fBottom < max;
-}
-
-static bool safeRoundOut(const SkRect& src, SkIRect* dst, int32_t maxInt) {
-    const SkScalar maxScalar = SkIntToScalar(maxInt);
-
-    if (fitsInsideLimit(src, maxScalar)) {
-        src.roundOut(dst);
-        return true;
-    }
-    return false;
-}
-
 void SkScan::AAAFillPath(const SkPath& path, const SkRegion& origClip, SkBlitter* blitter,
                          bool forceRLE) {
-    if (origClip.isEmpty()) {
-        return;
-    }
-
-    const bool isInverse = path.isInverseFillType();
-    SkIRect ir;
-    if (!safeRoundOut(path.getBounds(), &ir, SK_MaxS32 >> 2)) {
-        return;
-    }
-    if (ir.isEmpty()) {
-        if (isInverse) {
-            blitter->blitRegion(origClip);
+    FillPathFunc fillPathFunc = [](const SkPath& path, SkBlitter* blitter, bool isInverse,
+            const SkIRect& ir, const SkRegion* clipRgn, const SkIRect* clipRect, bool forceRLE){
+        // 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 the blit region is small enough (i.e., canHandleRect(ir)).
+        // When isInverse is true, the blit region is no longer ir so we won't use the mask blitter.
+        // The caller may also use the forceRLE flag to force not using the mask blitter.
+        if (MaskAdditiveBlitter::canHandleRect(ir) && !isInverse && !forceRLE) {
+            MaskAdditiveBlitter additiveBlitter(blitter, ir, *clipRgn, isInverse);
+            aaa_fill_path(path, clipRgn->getBounds(), &additiveBlitter, ir.fTop, ir.fBottom,
+                    clipRect == nullptr, true, forceRLE);
+        } else if (!isInverse && path.isConvex()) {
+            // If the filling area is convex (i.e., path.isConvex && !isInverse), our simpler
+            // aaa_walk_convex_edges won't generate alphas above 255. Hence we don't need
+            // SafeRLEAdditiveBlitter (which is slow due to clamping). The basic RLE blitter
+            // RunBasedAdditiveBlitter would suffice.
+            RunBasedAdditiveBlitter additiveBlitter(blitter, ir, *clipRgn, isInverse);
+            aaa_fill_path(path, clipRgn->getBounds(), &additiveBlitter, ir.fTop, ir.fBottom,
+                    clipRect == nullptr, false, forceRLE);
+        } else {
+            // If the filling area might not be convex, the more involved aaa_walk_edges would
+            // be called and we have to clamp the alpha downto 255. The SafeRLEAdditiveBlitter
+            // does that at a cost of performance.
+            SafeRLEAdditiveBlitter additiveBlitter(blitter, ir, *clipRgn, isInverse);
+            aaa_fill_path(path, clipRgn->getBounds(), &additiveBlitter, ir.fTop, ir.fBottom,
+                    clipRect == nullptr, false, forceRLE);
         }
-        return;
-    }
+    };
 
-    SkIRect clippedIR;
-    if (isInverse) {
-       // If the path is an inverse fill, it's going to fill the entire
-       // clip, and we care whether the entire clip exceeds our limits.
-       clippedIR = origClip.getBounds();
-    } else {
-       if (!clippedIR.intersect(ir, origClip.getBounds())) {
-           return;
-       }
-    }
-    // If the intersection of the path bounds and the clip bounds
-    // will overflow 32767 when << by 2, our SkFixed will overflow,
-    // so draw without antialiasing.
-    if (rect_overflows_short_shift(clippedIR, 2)) {
-        SkScan::FillPath(path, origClip, blitter);
-        return;
-    }
-
-    // Our antialiasing can't handle a clip larger than 32767, so we restrict
-    // the clip to that limit here. (the runs[] uses int16_t for its index).
-    //
-    // A more general solution (one that could also eliminate the need to
-    // disable aa based on ir bounds (see overflows_short_shift) would be
-    // to tile the clip/target...
-    SkRegion tmpClipStorage;
-    const SkRegion* clipRgn = &origClip;
-    {
-        static const int32_t kMaxClipCoord = 32767;
-        const SkIRect& bounds = origClip.getBounds();
-        if (bounds.fRight > kMaxClipCoord || bounds.fBottom > kMaxClipCoord) {
-            SkIRect limit = { 0, 0, kMaxClipCoord, kMaxClipCoord };
-            tmpClipStorage.op(origClip, limit, SkRegion::kIntersect_Op);
-            clipRgn = &tmpClipStorage;
-        }
-    }
-    // for here down, use clipRgn, not origClip
-
-    SkScanClipper   clipper(blitter, clipRgn, ir);
-    const SkIRect*  clipRect = clipper.getClipRect();
-
-    if (clipper.getBlitter() == nullptr) { // clipped out
-        if (isInverse) {
-            blitter->blitRegion(*clipRgn);
-        }
-        return;
-    }
-
-    // now use the (possibly wrapped) blitter
-    blitter = clipper.getBlitter();
-
-    if (isInverse) {
-        sk_blit_above(blitter, ir, *clipRgn);
-    }
-
-    SkASSERT(SkIntToScalar(ir.fTop) <= path.getBounds().fTop);
-
-    if (MaskAdditiveBlitter::canHandleRect(ir) && !isInverse && !forceRLE) {
-        MaskAdditiveBlitter additiveBlitter(blitter, ir, *clipRgn, isInverse);
-        aaa_fill_path(path, clipRgn->getBounds(), &additiveBlitter, ir.fTop, ir.fBottom,
-                clipRect == nullptr, true, forceRLE);
-    } else if (!isInverse && path.isConvex()) {
-        RunBasedAdditiveBlitter additiveBlitter(blitter, ir, *clipRgn, isInverse);
-        aaa_fill_path(path, clipRgn->getBounds(), &additiveBlitter, ir.fTop, ir.fBottom,
-                clipRect == nullptr, false, forceRLE);
-    } else {
-        SafeRLEAdditiveBlitter additiveBlitter(blitter, ir, *clipRgn, isInverse);
-        aaa_fill_path(path, clipRgn->getBounds(), &additiveBlitter, ir.fTop, ir.fBottom,
-                clipRect == nullptr, false, forceRLE);
-    }
-
-    if (isInverse) {
-        sk_blit_below(blitter, ir, *clipRgn);
-    }
-}
-
-// This almost copies SkScan::AntiFillPath
-void SkScan::AAAFillPath(const SkPath& path, const SkRasterClip& clip, SkBlitter* blitter) {
-    if (clip.isEmpty()) {
-        return;
-    }
-
-    if (clip.isBW()) {
-        AAAFillPath(path, clip.bwRgn(), blitter);
-    } else {
-        SkRegion        tmp;
-        SkAAClipBlitter aaBlitter;
-
-        tmp.setRect(clip.getBounds());
-        aaBlitter.init(blitter, &clip.aaRgn());
-        AAAFillPath(path, tmp, &aaBlitter, true);
-    }
+    do_fill_path(path, origClip, blitter, forceRLE, 2, std::move(fillPathFunc));
 }
diff --git a/src/core/SkScan_AntiPath.cpp b/src/core/SkScan_AntiPath.cpp
index ac4c8c3..be91007 100644
--- a/src/core/SkScan_AntiPath.cpp
+++ b/src/core/SkScan_AntiPath.cpp
@@ -582,153 +582,34 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-static bool fitsInsideLimit(const SkRect& r, SkScalar max) {
-    const SkScalar min = -max;
-    return  r.fLeft > min && r.fTop > min &&
-            r.fRight < max && r.fBottom < max;
-}
-
-static int overflows_short_shift(int value, int shift) {
-    const int s = 16 + shift;
-    return (SkLeftShift(value, s) >> s) - value;
-}
-
-/**
-  Would any of the coordinates of this rectangle not fit in a short,
-  when left-shifted by shift?
-*/
-static int rect_overflows_short_shift(SkIRect rect, int shift) {
-    SkASSERT(!overflows_short_shift(8191, SHIFT));
-    SkASSERT(overflows_short_shift(8192, SHIFT));
-    SkASSERT(!overflows_short_shift(32767, 0));
-    SkASSERT(overflows_short_shift(32768, 0));
-
-    // Since we expect these to succeed, we bit-or together
-    // for a tiny extra bit of speed.
-    return overflows_short_shift(rect.fLeft, SHIFT) |
-           overflows_short_shift(rect.fRight, SHIFT) |
-           overflows_short_shift(rect.fTop, SHIFT) |
-           overflows_short_shift(rect.fBottom, SHIFT);
-}
-
-static bool safeRoundOut(const SkRect& src, SkIRect* dst, int32_t maxInt) {
-    const SkScalar maxScalar = SkIntToScalar(maxInt);
-
-    if (fitsInsideLimit(src, maxScalar)) {
-        src.roundOut(dst);
-        return true;
-    }
-    return false;
-}
-
 void SkScan::AntiFillPath(const SkPath& path, const SkRegion& origClip,
                           SkBlitter* blitter, bool forceRLE) {
-    if (origClip.isEmpty()) {
-        return;
-    }
-
-    const bool isInverse = path.isInverseFillType();
-    SkIRect ir;
-
-    if (!safeRoundOut(path.getBounds(), &ir, SK_MaxS32 >> SHIFT)) {
-#if 0
-        const SkRect& r = path.getBounds();
-        SkDebugf("--- bounds can't fit in SkIRect\n", r.fLeft, r.fTop, r.fRight, r.fBottom);
-#endif
-        return;
-    }
-    if (ir.isEmpty()) {
-        if (isInverse) {
-            blitter->blitRegion(origClip);
+    FillPathFunc fillPathFunc = [](const SkPath& path, SkBlitter* blitter, bool isInverse,
+            const SkIRect& ir, const SkRegion* clipRgn, const SkIRect* clipRect, bool forceRLE){
+        SkIRect superRect, *superClipRect = nullptr;
+        if (clipRect) {
+            superRect.set(SkLeftShift(clipRect->fLeft, SHIFT),
+                          SkLeftShift(clipRect->fTop, SHIFT),
+                          SkLeftShift(clipRect->fRight, SHIFT),
+                          SkLeftShift(clipRect->fBottom, SHIFT));
+            superClipRect = &superRect;
         }
-        return;
-    }
 
-    // If the intersection of the path bounds and the clip bounds
-    // will overflow 32767 when << by SHIFT, we can't supersample,
-    // so draw without antialiasing.
-    SkIRect clippedIR;
-    if (isInverse) {
-       // If the path is an inverse fill, it's going to fill the entire
-       // clip, and we care whether the entire clip exceeds our limits.
-       clippedIR = origClip.getBounds();
-    } else {
-       if (!clippedIR.intersect(ir, origClip.getBounds())) {
-           return;
-       }
-    }
-    if (rect_overflows_short_shift(clippedIR, SHIFT)) {
-        SkScan::FillPath(path, origClip, blitter);
-        return;
-    }
-
-    // Our antialiasing can't handle a clip larger than 32767, so we restrict
-    // the clip to that limit here. (the runs[] uses int16_t for its index).
-    //
-    // A more general solution (one that could also eliminate the need to
-    // disable aa based on ir bounds (see overflows_short_shift) would be
-    // to tile the clip/target...
-    SkRegion tmpClipStorage;
-    const SkRegion* clipRgn = &origClip;
-    {
-        static const int32_t kMaxClipCoord = 32767;
-        const SkIRect& bounds = origClip.getBounds();
-        if (bounds.fRight > kMaxClipCoord || bounds.fBottom > kMaxClipCoord) {
-            SkIRect limit = { 0, 0, kMaxClipCoord, kMaxClipCoord };
-            tmpClipStorage.op(origClip, limit, SkRegion::kIntersect_Op);
-            clipRgn = &tmpClipStorage;
+        // MaskSuperBlitter can't handle drawing outside of ir, so we can't use it
+        // if we're an inverse filltype
+        if (!isInverse && MaskSuperBlitter::CanHandleRect(ir) && !forceRLE) {
+            MaskSuperBlitter    superBlit(blitter, ir, *clipRgn, isInverse);
+            SkASSERT(SkIntToScalar(ir.fTop) <= path.getBounds().fTop);
+            sk_fill_path(path, clipRgn->getBounds(), &superBlit, ir.fTop, ir.fBottom, SHIFT,
+                    superClipRect == nullptr);
+        } else {
+            SuperBlitter    superBlit(blitter, ir, *clipRgn, isInverse);
+            sk_fill_path(path, clipRgn->getBounds(), &superBlit, ir.fTop, ir.fBottom, SHIFT,
+                    superClipRect == nullptr);
         }
-    }
-    // for here down, use clipRgn, not origClip
+    };
 
-    SkScanClipper   clipper(blitter, clipRgn, ir);
-    const SkIRect*  clipRect = clipper.getClipRect();
-
-    if (clipper.getBlitter() == nullptr) { // clipped out
-        if (isInverse) {
-            blitter->blitRegion(*clipRgn);
-        }
-        return;
-    }
-
-    SkASSERT(clipper.getClipRect() == nullptr ||
-            *clipper.getClipRect() == clipRgn->getBounds());
-
-    // now use the (possibly wrapped) blitter
-    blitter = clipper.getBlitter();
-
-    if (isInverse) {
-        sk_blit_above(blitter, ir, *clipRgn);
-    }
-
-    SkIRect superRect, *superClipRect = nullptr;
-
-    if (clipRect) {
-        superRect.set(SkLeftShift(clipRect->fLeft, SHIFT),
-                      SkLeftShift(clipRect->fTop, SHIFT),
-                      SkLeftShift(clipRect->fRight, SHIFT),
-                      SkLeftShift(clipRect->fBottom, SHIFT));
-        superClipRect = &superRect;
-    }
-
-    SkASSERT(SkIntToScalar(ir.fTop) <= path.getBounds().fTop);
-
-    // MaskSuperBlitter can't handle drawing outside of ir, so we can't use it
-    // if we're an inverse filltype
-    if (!isInverse && MaskSuperBlitter::CanHandleRect(ir) && !forceRLE) {
-        MaskSuperBlitter    superBlit(blitter, ir, *clipRgn, isInverse);
-        SkASSERT(SkIntToScalar(ir.fTop) <= path.getBounds().fTop);
-        sk_fill_path(path, clipRgn->getBounds(), &superBlit, ir.fTop, ir.fBottom, SHIFT,
-                superClipRect == nullptr);
-    } else {
-        SuperBlitter    superBlit(blitter, ir, *clipRgn, isInverse);
-        sk_fill_path(path, clipRgn->getBounds(), &superBlit, ir.fTop, ir.fBottom, SHIFT,
-                superClipRect == nullptr);
-    }
-
-    if (isInverse) {
-        sk_blit_below(blitter, ir, *clipRgn);
-    }
+    do_fill_path(path, origClip, blitter, forceRLE, SHIFT, std::move(fillPathFunc));
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -768,25 +649,27 @@
 
 void SkScan::AntiFillPath(const SkPath& path, const SkRasterClip& clip,
                           SkBlitter* blitter) {
-    // Do not use AAA if path is too complicated:
-    // there won't be any speedup or significant visual improvement.
-    if (gSkUseAnalyticAA.load() && suitableForAAA(path)) {
-        SkScan::AAAFillPath(path, clip, blitter);
-        return;
-    }
-
     if (clip.isEmpty()) {
         return;
     }
 
+    using FillPathProc = void(*)(const SkPath&, const SkRegion&, SkBlitter*, bool);
+    FillPathProc fillPathProc = &SkScan::AntiFillPath;
+
+    // Do not use AAA if path is too complicated:
+    // there won't be any speedup or significant visual improvement.
+    if (gSkUseAnalyticAA.load() && suitableForAAA(path)) {
+        fillPathProc = &SkScan::AAAFillPath;
+    }
+
     if (clip.isBW()) {
-        AntiFillPath(path, clip.bwRgn(), blitter);
+        fillPathProc(path, clip.bwRgn(), blitter, false);
     } else {
         SkRegion        tmp;
         SkAAClipBlitter aaBlitter;
 
         tmp.setRect(clip.getBounds());
         aaBlitter.init(blitter, &clip.aaRgn());
-        SkScan::AntiFillPath(path, tmp, &aaBlitter, true);
+        fillPathProc(path, tmp, &aaBlitter, true);
     }
 }
