Remove SkFallbackAlloc and SkFixedAlloc.

CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-ASAN;skia.primary:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-MSAN

TBR=reed@google.com

Change-Id: I1000dc9ed8ad65b249798759d9af99f47fc237d2
Reviewed-on: https://skia-review.googlesource.com/6809
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/core/SkFixedAlloc.cpp b/src/core/SkArenaAlloc.cpp
similarity index 81%
rename from src/core/SkFixedAlloc.cpp
rename to src/core/SkArenaAlloc.cpp
index c6b0725..d6c249b 100644
--- a/src/core/SkFixedAlloc.cpp
+++ b/src/core/SkArenaAlloc.cpp
@@ -5,52 +5,8 @@
  * found in the LICENSE file.
  */
 
-#include "SkFixedAlloc.h"
-
 #include <algorithm>
-
-SkFixedAlloc::SkFixedAlloc(void* ptr, size_t len)
-    : fStorage((char*)ptr), fCursor(fStorage), fEnd(fStorage + len) {}
-
-void SkFixedAlloc::undo() {
-    // This function is essentially make() in reverse.
-
-    // First, read the Footer we stamped at the end.
-    Footer footer;
-    memcpy(&footer, fCursor - sizeof(Footer), sizeof(Footer));
-
-    Releaser releaser = (Releaser)((char*)Base + (footer >> 5));
-    ptrdiff_t padding = footer & 31;
-
-    fCursor = releaser(fCursor);
-    fCursor -= padding;
-}
-
-void SkFixedAlloc::reset() {
-    while (fCursor > fStorage) {
-        this->undo();
-    }
-}
-
-void SkFixedAlloc::Base() { }
-
-SkFallbackAlloc::SkFallbackAlloc(SkFixedAlloc* fixed) : fFixedAlloc(fixed) {}
-
-void SkFallbackAlloc::undo() {
-    if (fHeapAllocs.empty()) {
-        return fFixedAlloc->undo();
-    }
-    HeapAlloc alloc = fHeapAllocs.back();
-    alloc.deleter(alloc.ptr);
-    fHeapAllocs.pop_back();
-}
-
-void SkFallbackAlloc::reset() {
-    while (!fHeapAllocs.empty()) {
-        this->undo();
-    }
-    fFixedAlloc->reset();
-}
+#include "SkArenaAlloc.h"
 
 struct Skipper {
     char* operator()(char* objEnd, ptrdiff_t size) { return objEnd + size; }
diff --git a/src/core/SkFixedAlloc.h b/src/core/SkArenaAlloc.h
similarity index 69%
rename from src/core/SkFixedAlloc.h
rename to src/core/SkArenaAlloc.h
index acb6895..8152c94 100644
--- a/src/core/SkFixedAlloc.h
+++ b/src/core/SkArenaAlloc.h
@@ -16,105 +16,6 @@
 #include <utility>
 #include <vector>
 
-// SkFixedAlloc allocates objects out of a fixed-size buffer and destroys them when destroyed.
-class SkFixedAlloc {
-public:
-    SkFixedAlloc(void* ptr, size_t len);
-    ~SkFixedAlloc() { this->reset(); }
-
-    // Allocates a new T in the buffer if possible.  If not, returns nullptr.
-    // Assumptions:
-    // * max alignment value is 32 - if alignment is greater than 32, the allocation is best effort.
-    // * footer is 32 bits - 5 bits of alignment and 27 bits of deleter difference from Base.
-    // * deleter difference - the difference D is -2^26 <= D < 2^26.
-    template <typename T, typename... Args>
-    T* make(Args&&... args) {
-        auto mask = alignof(T) - 1;
-
-        // Align fCursor for this allocation.
-        char* objStart = (char*)((uintptr_t)(fCursor + mask) & ~mask);
-        ptrdiff_t padding = objStart - fCursor;
-        Releaser releaser = [](char* objEnd) {
-            char* objStart = objEnd - (sizeof(T) + sizeof(Footer));
-            ((T*)objStart)->~T();
-            return objStart;
-        };
-
-        ptrdiff_t deleterDiff = (char*)releaser - (char*)Base;
-
-        if (objStart + sizeof(T) + sizeof(Footer) > fEnd
-            || padding >= 32
-            || deleterDiff >= (1 << 26)
-            || deleterDiff < -(1 << 26)) {
-            // Ran out of space, or code not store info in the Footer.
-            return nullptr;
-        }
-
-        // Advance cursor to end of the object.
-        fCursor = objStart + sizeof(T);
-
-        Footer footer = (Footer)(SkLeftShift((int64_t)deleterDiff, 5) | padding);
-        memcpy(fCursor, &footer, sizeof(Footer));
-        fCursor += sizeof(Footer);
-
-        return new (objStart) T(std::forward<Args>(args)...);
-    }
-
-    // Destroys the last object allocated and frees its space in the buffer.
-    void undo();
-
-    // Destroys all objects and frees all space in the buffer.
-    void reset();
-
-private:
-    using Footer  = int32_t;
-    using Releaser = char*(*)(char*);
-
-    // A function pointer to use for offsets of releasers.
-    static void Base();
-
-    char* const fStorage;
-    char*       fCursor;
-    char* const fEnd;
-};
-
-class SkFallbackAlloc {
-public:
-    explicit SkFallbackAlloc(SkFixedAlloc*);
-    ~SkFallbackAlloc() { this->reset(); }
-
-    // Allocates a new T with the SkFixedAlloc if possible.  If not, uses the heap.
-    template <typename T, typename... Args>
-    T* make(Args&&... args) {
-        // Once we go heap we never go back to fixed.  This keeps destructor ordering sane.
-        if (fHeapAllocs.empty()) {
-            if (T* ptr = fFixedAlloc->make<T>(std::forward<Args>(args)...)) {
-                return ptr;
-            }
-        }
-
-        char* ptr = new char[sizeof(T)];
-        fHeapAllocs.push_back({[](char* ptr) { ((T*)ptr)->~T(); delete [] ptr; }, ptr});
-        return new (ptr) T(std::forward<Args>(args)...);
-    }
-
-
-    // Destroys all objects and frees all space in the SkFixedAlloc.
-    void reset();
-
-private:
-    // Destroys the last object allocated and frees any space it used in the SkFixedAlloc.
-    void undo();
-
-    struct HeapAlloc {
-        void (*deleter)(char*);
-        char* ptr;
-    };
-
-    SkFixedAlloc*          fFixedAlloc;
-    std::vector<HeapAlloc> fHeapAllocs;
-};
-
 // SkArenaAlloc allocates object and destroys the allocated objects when destroyed. It's designed
 // to minimize the number of underlying block allocations. SkArenaAlloc allocates first out of an
 // (optional) user-provided block of memory, and when that's exhausted it allocates on the heap,
diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp
index 664109a..d835853 100644
--- a/src/core/SkColorFilter.cpp
+++ b/src/core/SkColorFilter.cpp
@@ -6,7 +6,7 @@
  */
 
 #include "SkColorFilter.h"
-#include "SkFixedAlloc.h"
+#include "SkArenaAlloc.h"
 #include "SkReadBuffer.h"
 #include "SkRefCnt.h"
 #include "SkString.h"
@@ -40,12 +40,12 @@
 
 bool SkColorFilter::appendStages(SkRasterPipeline* pipeline,
                                  SkColorSpace* dst,
-                                 SkFallbackAlloc* scratch,
+                                 SkArenaAlloc* scratch,
                                  bool shaderIsOpaque) const {
     return this->onAppendStages(pipeline, dst, scratch, shaderIsOpaque);
 }
 
-bool SkColorFilter::onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*, bool) const {
+bool SkColorFilter::onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*, bool) const {
     return false;
 }
 
diff --git a/src/core/SkColorMatrixFilterRowMajor255.cpp b/src/core/SkColorMatrixFilterRowMajor255.cpp
index e17f73a..778fe98 100644
--- a/src/core/SkColorMatrixFilterRowMajor255.cpp
+++ b/src/core/SkColorMatrixFilterRowMajor255.cpp
@@ -233,7 +233,7 @@
 
 bool SkColorMatrixFilterRowMajor255::onAppendStages(SkRasterPipeline* p,
                                                     SkColorSpace* dst,
-                                                    SkFallbackAlloc* scratch,
+                                                    SkArenaAlloc* scratch,
                                                     bool shaderIsOpaque) const {
     bool willStayOpaque = shaderIsOpaque && (fFlags & kAlphaUnchanged_Flag);
     bool needsClamp0 = false,
diff --git a/src/core/SkColorMatrixFilterRowMajor255.h b/src/core/SkColorMatrixFilterRowMajor255.h
index f4312c5..5c2d616 100644
--- a/src/core/SkColorMatrixFilterRowMajor255.h
+++ b/src/core/SkColorMatrixFilterRowMajor255.h
@@ -36,7 +36,7 @@
     void flatten(SkWriteBuffer&) const override;
 
 private:
-    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                         bool shaderIsOpaque) const override;
 
     SkScalar        fMatrix[20];
diff --git a/src/core/SkColorShader.cpp b/src/core/SkColorShader.cpp
index da87cdf..725bbf0 100644
--- a/src/core/SkColorShader.cpp
+++ b/src/core/SkColorShader.cpp
@@ -5,9 +5,9 @@
  * found in the LICENSE file.
  */
 
+#include "SkArenaAlloc.h"
 #include "SkColorShader.h"
 #include "SkColorSpace.h"
-#include "SkFixedAlloc.h"
 #include "SkPM4fPriv.h"
 #include "SkRasterPipeline.h"
 #include "SkReadBuffer.h"
@@ -311,7 +311,7 @@
 
 bool SkColorShader::onAppendStages(SkRasterPipeline* p,
                                    SkColorSpace* dst,
-                                   SkFallbackAlloc* scratch,
+                                   SkArenaAlloc* scratch,
                                    const SkMatrix& ctm,
                                    const SkPaint&) const {
     auto color = scratch->make<SkPM4f>(SkPM4f_from_SkColor(fColor, dst));
@@ -322,7 +322,7 @@
 
 bool SkColor4Shader::onAppendStages(SkRasterPipeline* p,
                                     SkColorSpace* dst,
-                                    SkFallbackAlloc* scratch,
+                                    SkArenaAlloc* scratch,
                                     const SkMatrix& ctm,
                                     const SkPaint&) const {
     auto color = scratch->make<SkPM4f>(fColor4.premul());
diff --git a/src/core/SkColorShader.h b/src/core/SkColorShader.h
index 19c106d..3f00317 100644
--- a/src/core/SkColorShader.h
+++ b/src/core/SkColorShader.h
@@ -65,7 +65,7 @@
         *lum = fColor;
         return true;
     }
-    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                         const SkMatrix& ctm, const SkPaint&) const override;
 
 private:
@@ -121,7 +121,7 @@
         *lum = fCachedByteColor;
         return true;
     }
-    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                         const SkMatrix& ctm, const SkPaint&) const override;
 
 private:
diff --git a/src/core/SkLinearBitmapPipeline.cpp b/src/core/SkLinearBitmapPipeline.cpp
index 1c3b7a5..2878f19 100644
--- a/src/core/SkLinearBitmapPipeline.cpp
+++ b/src/core/SkLinearBitmapPipeline.cpp
@@ -12,7 +12,7 @@
 #include <limits>
 #include <tuple>
 
-#include "SkFixedAlloc.h"
+#include "SkArenaAlloc.h"
 #include "SkLinearBitmapPipeline_core.h"
 #include "SkLinearBitmapPipeline_matrix.h"
 #include "SkLinearBitmapPipeline_tile.h"
diff --git a/src/core/SkLinearBitmapPipeline.h b/src/core/SkLinearBitmapPipeline.h
index 237a165..8ce0200 100644
--- a/src/core/SkLinearBitmapPipeline.h
+++ b/src/core/SkLinearBitmapPipeline.h
@@ -8,8 +8,8 @@
 #ifndef SkLinearBitmapPipeline_DEFINED
 #define SkLinearBitmapPipeline_DEFINED
 
+#include "SkArenaAlloc.h"
 #include "SkColor.h"
-#include "SkFixedAlloc.h"
 #include "SkImageInfo.h"
 #include "SkMatrix.h"
 #include "SkShader.h"
diff --git a/src/core/SkModeColorFilter.cpp b/src/core/SkModeColorFilter.cpp
index 9c76f9e..fb09c27 100644
--- a/src/core/SkModeColorFilter.cpp
+++ b/src/core/SkModeColorFilter.cpp
@@ -9,7 +9,7 @@
 #include "SkBlendModePriv.h"
 #include "SkColorFilter.h"
 #include "SkColorPriv.h"
-#include "SkFixedAlloc.h"
+#include "SkArenaAlloc.h"
 #include "SkModeColorFilter.h"
 #include "SkPM4fPriv.h"
 #include "SkRasterPipeline.h"
@@ -88,7 +88,7 @@
 
 bool SkModeColorFilter::onAppendStages(SkRasterPipeline* p,
                                        SkColorSpace* dst,
-                                       SkFallbackAlloc* scratch,
+                                       SkArenaAlloc* scratch,
                                        bool shaderIsOpaque) const {
     auto color = scratch->make<SkPM4f>(SkPM4f_from_SkColor(fColor, dst));
 
diff --git a/src/core/SkModeColorFilter.h b/src/core/SkModeColorFilter.h
index 8e03744..4d0b172 100644
--- a/src/core/SkModeColorFilter.h
+++ b/src/core/SkModeColorFilter.h
@@ -44,7 +44,7 @@
 
     void flatten(SkWriteBuffer&) const override;
 
-    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                         bool shaderIsOpaque) const override;
 
 private:
diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h
index 26d8b7d..dd0e550 100644
--- a/src/core/SkPM4fPriv.h
+++ b/src/core/SkPM4fPriv.h
@@ -11,7 +11,7 @@
 #include "SkColorPriv.h"
 #include "SkColorSpace.h"
 #include "SkColorSpace_Base.h"
-#include "SkFixedAlloc.h"
+#include "SkArenaAlloc.h"
 #include "SkPM4f.h"
 #include "SkRasterPipeline.h"
 #include "SkSRGB.h"
@@ -130,7 +130,7 @@
     return true;
 }
 
-static inline bool append_gamut_transform(SkRasterPipeline* p, SkFallbackAlloc* scratch,
+static inline bool append_gamut_transform(SkRasterPipeline* p, SkArenaAlloc* scratch,
                                           SkColorSpace* src, SkColorSpace* dst) {
     struct matrix_3x4 { float arr[12]; };
     return append_gamut_transform(p, scratch->make<matrix_3x4>()->arr, src, dst);
diff --git a/src/core/SkRasterPipelineBlitter.cpp b/src/core/SkRasterPipelineBlitter.cpp
index 4d21b19..7f91cbf 100644
--- a/src/core/SkRasterPipelineBlitter.cpp
+++ b/src/core/SkRasterPipelineBlitter.cpp
@@ -5,11 +5,11 @@
  * found in the LICENSE file.
  */
 
+#include "SkArenaAlloc.h"
 #include "SkBlitter.h"
 #include "SkBlendModePriv.h"
 #include "SkColor.h"
 #include "SkColorFilter.h"
-#include "SkFixedAlloc.h"
 #include "SkOpts.h"
 #include "SkPM4f.h"
 #include "SkPM4fPriv.h"
@@ -27,8 +27,6 @@
         : fDst(dst)
         , fBlend(blend)
         , fPaintColor(paintColor)
-        , fScratchAlloc(fScratch, sizeof(fScratch))
-        , fScratchFallback(&fScratchAlloc)
     {}
 
     void blitH    (int x, int y, int w)                            override;
@@ -64,8 +62,7 @@
 
     // Scratch space for shaders and color filters to use.
     char            fScratch[64];
-    SkFixedAlloc    fScratchAlloc;
-    SkFallbackAlloc fScratchFallback;
+    SkArenaAlloc    fArena{fScratch, sizeof(fScratch), 128};
 
     typedef SkBlitter INHERITED;
 };
@@ -116,7 +113,7 @@
     bool is_opaque   = paintColor->a() == 1.0f,
          is_constant = true;
     if (shader) {
-        if (!shader->appendStages(pipeline, dst.colorSpace(), &blitter->fScratchFallback,
+        if (!shader->appendStages(pipeline, dst.colorSpace(), &blitter->fArena,
                                   ctm, paint)) {
             return earlyOut();
         }
@@ -132,7 +129,7 @@
     }
 
     if (colorFilter) {
-        if (!colorFilter->appendStages(pipeline, dst.colorSpace(), &blitter->fScratchFallback,
+        if (!colorFilter->appendStages(pipeline, dst.colorSpace(), &blitter->fArena,
                                        is_opaque)) {
             return earlyOut();
         }
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index 87b2cc3..3a2ec7b 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -259,7 +259,7 @@
 
 bool SkShader::appendStages(SkRasterPipeline* pipeline,
                             SkColorSpace* dst,
-                            SkFallbackAlloc* scratch,
+                            SkArenaAlloc* scratch,
                             const SkMatrix& ctm,
                             const SkPaint& paint) const {
     return this->onAppendStages(pipeline, dst, scratch, ctm, paint);
diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp
index 6845c50..bd5c146 100644
--- a/src/effects/SkLumaColorFilter.cpp
+++ b/src/effects/SkLumaColorFilter.cpp
@@ -40,7 +40,7 @@
 
 bool SkLumaColorFilter::onAppendStages(SkRasterPipeline* p,
                                        SkColorSpace* dst,
-                                       SkFallbackAlloc* scratch,
+                                       SkArenaAlloc* scratch,
                                        bool shaderIsOpaque) const {
     p->append(SkRasterPipeline::luminance_to_alpha);
     return true;
diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp
index 1417ac8..5b79fb1 100644
--- a/src/image/SkImageShader.cpp
+++ b/src/image/SkImageShader.cpp
@@ -5,12 +5,12 @@
  * found in the LICENSE file.
  */
 
+#include "SkArenaAlloc.h"
 #include "SkBitmapController.h"
 #include "SkBitmapProcShader.h"
 #include "SkBitmapProvider.h"
 #include "SkColorTable.h"
 #include "SkEmptyShader.h"
-#include "SkFixedAlloc.h"
 #include "SkImage_Base.h"
 #include "SkImageShader.h"
 #include "SkImageShaderContext.h"
@@ -227,7 +227,7 @@
 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
 
 
-bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFallbackAlloc* scratch,
+bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkArenaAlloc* scratch,
                                    const SkMatrix& ctm, const SkPaint& paint) const {
     auto matrix = SkMatrix::Concat(ctm, this->getLocalMatrix());
     if (!matrix.invert(&matrix)) {
diff --git a/src/image/SkImageShader.h b/src/image/SkImageShader.h
index 074ecca..fa77928 100644
--- a/src/image/SkImageShader.h
+++ b/src/image/SkImageShader.h
@@ -37,7 +37,7 @@
 #endif
     SkImage* onIsAImage(SkMatrix*, TileMode*) const override;
 
-    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                         const SkMatrix& ctm, const SkPaint&) const override;
 
     sk_sp<SkImage>  fImage;