Remove SkFallbackAlloc and SkFixedAlloc.
authorHerb Derby <herb@google.com>
Fri, 13 Jan 2017 22:34:33 +0000 (17:34 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 16 Jan 2017 17:01:57 +0000 (17:01 +0000)
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>

24 files changed:
bench/SkLinearBitmapPipelineBench.cpp
gn/core.gni
gn/tests.gni
include/core/SkColorFilter.h
include/core/SkShader.h
include/effects/SkLumaColorFilter.h
src/core/SkArenaAlloc.cpp [moved from src/core/SkFixedAlloc.cpp with 81% similarity]
src/core/SkArenaAlloc.h [moved from src/core/SkFixedAlloc.h with 68% similarity]
src/core/SkColorFilter.cpp
src/core/SkColorMatrixFilterRowMajor255.cpp
src/core/SkColorMatrixFilterRowMajor255.h
src/core/SkColorShader.cpp
src/core/SkColorShader.h
src/core/SkLinearBitmapPipeline.cpp
src/core/SkLinearBitmapPipeline.h
src/core/SkModeColorFilter.cpp
src/core/SkModeColorFilter.h
src/core/SkPM4fPriv.h
src/core/SkRasterPipelineBlitter.cpp
src/core/SkShader.cpp
src/effects/SkLumaColorFilter.cpp
src/image/SkImageShader.cpp
src/image/SkImageShader.h
tests/ArenaAllocTest.cpp [moved from tests/FixedAllocTest.cpp with 56% similarity]

index 020ce7f..4e892b6 100644 (file)
@@ -9,7 +9,7 @@
 #include "Benchmark.h"
 #include "SkBitmapProcShader.h"
 #include "SkColor.h"
-#include "SkFixedAlloc.h"
+#include "SkArenaAlloc.h"
 #include "SkImage.h"
 #include "SkLinearBitmapPipeline.h"
 #include "SkPM4f.h"
index e5d72b3..4325263 100644 (file)
@@ -130,8 +130,8 @@ skia_core_sources = [
   "$_src/core/SkFilterProc.cpp",
   "$_src/core/SkFilterProc.h",
   "$_src/core/SkFindAndPlaceGlyph.h",
-  "$_src/core/SkFixedAlloc.cpp",
-  "$_src/core/SkFixedAlloc.h",
+  "$_src/core/SkArenaAlloc.cpp",
+  "$_src/core/SkArenaAlloc.h",
   "$_src/core/SkFlattenable.cpp",
   "$_src/core/SkFlattenableSerialization.cpp",
   "$_src/core/SkFont.cpp",
index caafae4..483f574 100644 (file)
@@ -10,6 +10,7 @@ tests_sources = [
   "$_tests/AAClipTest.cpp",
   "$_tests/AnnotationTest.cpp",
   "$_tests/ApplyGammaTest.cpp",
+  "$_tests/ArenaAllocTest.cpp",
   "$_tests/AsADashTest.cpp",
   "$_tests/BadIcoTest.cpp",
   "$_tests/BitmapCopyTest.cpp",
@@ -62,7 +63,6 @@ tests_sources = [
   "$_tests/ExifTest.cpp",
   "$_tests/FillPathTest.cpp",
   "$_tests/FitsInTest.cpp",
-  "$_tests/FixedAllocTest.cpp",
   "$_tests/FlattenableCustomFactory.cpp",
   "$_tests/FlattenableFactoryToName.cpp",
   "$_tests/FlattenDrawableTest.cpp",
index fd3ccbc..a593087 100644 (file)
@@ -15,9 +15,9 @@
 
 class GrContext;
 class GrFragmentProcessor;
+class SkArenaAlloc;
 class SkBitmap;
 class SkColorSpace;
-class SkFallbackAlloc;
 class SkRasterPipeline;
 
 /**
@@ -73,7 +73,7 @@ public:
 
     virtual void filterSpan4f(const SkPM4f src[], int count, SkPM4f result[]) const;
 
-    bool appendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool appendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                       bool shaderIsOpaque) const;
 
     enum Flags {
@@ -160,7 +160,7 @@ public:
 protected:
     SkColorFilter() {}
 
-    virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                                 bool shaderIsOpaque) const;
 
 private:
index 6d24c1a..4bb887e 100644 (file)
@@ -19,7 +19,7 @@
 
 class SkColorFilter;
 class SkColorSpace;
-class SkFallbackAlloc;
+class SkArenaAlloc;
 class SkImage;
 class SkPath;
 class SkPicture;
@@ -475,7 +475,7 @@ public:
     SK_DEFINE_FLATTENABLE_TYPE(SkShader)
     SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
 
-    bool appendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool appendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                       const SkMatrix& ctm, const SkPaint&) const;
 
 protected:
@@ -509,7 +509,7 @@ protected:
         return nullptr;
     }
 
-    virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    virtual bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                                 const SkMatrix&, const SkPaint&) const {
         return false;
     }
index 5cddec6..2093944 100644 (file)
@@ -42,7 +42,7 @@ protected:
 
 private:
     SkLumaColorFilter();
-    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                         bool shaderIsOpaque) const override;
 
     typedef SkColorFilter INHERITED;
similarity index 81%
rename from src/core/SkFixedAlloc.cpp
rename to src/core/SkArenaAlloc.cpp
index c6b0725..d6c249b 100644 (file)
@@ -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; }
similarity index 68%
rename from src/core/SkFixedAlloc.h
rename to src/core/SkArenaAlloc.h
index acb6895..8152c94 100644 (file)
 #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,
index 664109a..d835853 100644 (file)
@@ -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 @@ sk_sp<GrFragmentProcessor> SkColorFilter::asFragmentProcessor(GrContext*, SkColo
 
 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;
 }
 
index e17f73a..778fe98 100644 (file)
@@ -233,7 +233,7 @@ static void set_concat(SkScalar result[20], const SkScalar outer[20], const SkSc
 
 bool SkColorMatrixFilterRowMajor255::onAppendStages(SkRasterPipeline* p,
                                                     SkColorSpace* dst,
-                                                    SkFallbackAlloc* scratch,
+                                                    SkArenaAlloc* scratch,
                                                     bool shaderIsOpaque) const {
     bool willStayOpaque = shaderIsOpaque && (fFlags & kAlphaUnchanged_Flag);
     bool needsClamp0 = false,
index f4312c5..5c2d616 100644 (file)
@@ -36,7 +36,7 @@ protected:
     void flatten(SkWriteBuffer&) const override;
 
 private:
-    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                         bool shaderIsOpaque) const override;
 
     SkScalar        fMatrix[20];
index da87cdf..725bbf0 100644 (file)
@@ -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 SkColor4Shader::Color4Context::onChooseBlitProcs(const SkImageInfo& info, B
 
 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 SkColorShader::onAppendStages(SkRasterPipeline* p,
 
 bool SkColor4Shader::onAppendStages(SkRasterPipeline* p,
                                     SkColorSpace* dst,
-                                    SkFallbackAlloc* scratch,
+                                    SkArenaAlloc* scratch,
                                     const SkMatrix& ctm,
                                     const SkPaint&) const {
     auto color = scratch->make<SkPM4f>(fColor4.premul());
index 19c106d..3f00317 100644 (file)
@@ -65,7 +65,7 @@ protected:
         *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 @@ protected:
         *lum = fCachedByteColor;
         return true;
     }
-    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                         const SkMatrix& ctm, const SkPaint&) const override;
 
 private:
index 1c3b7a5..2878f19 100644 (file)
@@ -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"
index 237a165..8ce0200 100644 (file)
@@ -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"
index 9c76f9e..fb09c27 100644 (file)
@@ -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 @@ sk_sp<SkFlattenable> SkModeColorFilter::CreateProc(SkReadBuffer& buffer) {
 
 bool SkModeColorFilter::onAppendStages(SkRasterPipeline* p,
                                        SkColorSpace* dst,
-                                       SkFallbackAlloc* scratch,
+                                       SkArenaAlloc* scratch,
                                        bool shaderIsOpaque) const {
     auto color = scratch->make<SkPM4f>(SkPM4f_from_SkColor(fColor, dst));
 
index 8e03744..4d0b172 100644 (file)
@@ -44,7 +44,7 @@ protected:
 
     void flatten(SkWriteBuffer&) const override;
 
-    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*,
+    bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*,
                         bool shaderIsOpaque) const override;
 
 private:
index 26d8b7d..dd0e550 100644 (file)
@@ -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 @@ static inline bool append_gamut_transform(SkRasterPipeline* p, float scratch_mat
     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);
index 4d21b19..7f91cbf 100644 (file)
@@ -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 @@ public:
         : 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 @@ private:
 
     // 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 @@ SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
     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 @@ SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
     }
 
     if (colorFilter) {
-        if (!colorFilter->appendStages(pipeline, dst.colorSpace(), &blitter->fScratchFallback,
+        if (!colorFilter->appendStages(pipeline, dst.colorSpace(), &blitter->fArena,
                                        is_opaque)) {
             return earlyOut();
         }
index 87b2cc3..3a2ec7b 100644 (file)
@@ -259,7 +259,7 @@ void SkShader::toString(SkString* str) const {
 
 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);
index 6845c50..bd5c146 100644 (file)
@@ -40,7 +40,7 @@ void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count,
 
 bool SkLumaColorFilter::onAppendStages(SkRasterPipeline* p,
                                        SkColorSpace* dst,
-                                       SkFallbackAlloc* scratch,
+                                       SkArenaAlloc* scratch,
                                        bool shaderIsOpaque) const {
     p->append(SkRasterPipeline::luminance_to_alpha);
     return true;
index 1417ac8..5b79fb1 100644 (file)
@@ -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 @@ SkFlattenable::Register("SkBitmapProcShader", SkBitmapProcShader_CreateProc, kSk
 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)) {
index 074ecca..fa77928 100644 (file)
@@ -37,7 +37,7 @@ protected:
 #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;
similarity index 56%
rename from tests/FixedAllocTest.cpp
rename to tests/ArenaAllocTest.cpp
index 75bc232..647ea25 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #include "Test.h"
-#include "SkFixedAlloc.h"
+#include "SkArenaAlloc.h"
 
 namespace {
 
@@ -28,91 +28,6 @@ namespace {
 
 }
 
-DEF_TEST(FixedAlloc, r) {
-    // Basic mechanics.
-    {
-        uint8_t buf[128];
-        SkFixedAlloc fa(buf, sizeof(buf));
-
-        Foo* foo = fa.make<Foo>(3, 4.0f);
-        REPORTER_ASSERT(r, foo);
-        REPORTER_ASSERT(r, foo->x == 3);
-        REPORTER_ASSERT(r, foo->y == 4.0f);
-        REPORTER_ASSERT(r, created == 1);
-        REPORTER_ASSERT(r, destroyed == 0);
-
-        Foo* bar = fa.make<Foo>(8, 1.0f);
-        REPORTER_ASSERT(r, bar);
-        REPORTER_ASSERT(r, bar->x == 8);
-        REPORTER_ASSERT(r, bar->y == 1.0f);
-        REPORTER_ASSERT(r, created == 2);
-        REPORTER_ASSERT(r, destroyed == 0);
-
-        fa.undo();
-        REPORTER_ASSERT(r, created == 2);
-        REPORTER_ASSERT(r, destroyed == 1);
-    }
-    REPORTER_ASSERT(r, created == 2);
-    REPORTER_ASSERT(r, destroyed == 2);
-
-    {
-        // Test alignment gurantees.
-        uint8_t buf[64];
-        SkFixedAlloc fa(buf+3, sizeof(buf)-3);
-
-        Foo* foo = fa.make<Foo>(3, 4.0f);
-        REPORTER_ASSERT(r, SkIsAlign4((uintptr_t)foo));
-        REPORTER_ASSERT(r, created == 3);
-        REPORTER_ASSERT(r, destroyed == 2);
-
-        // Might as well test reset() while we're at it.
-        fa.reset();
-        REPORTER_ASSERT(r, created == 3);
-        REPORTER_ASSERT(r, destroyed == 3);
-    }
-    REPORTER_ASSERT(r, created == 3);
-    REPORTER_ASSERT(r, destroyed == 3);
-}
-
-DEF_TEST(FallbackAlloc, r) {
-    // SkFixedAlloc will eventually fail when it runs out of space in its buffer.
-    int buf[32];
-    SkFixedAlloc fixed(buf, sizeof(buf));
-    bool fixed_failed = false;
-    for (int i = 0; i < 32; i++) {
-        // (Remember, there is some overhead to each make() call.)
-        fixed_failed = fixed_failed || (fixed.make<int>(i) == nullptr);
-    }
-    REPORTER_ASSERT(r, fixed_failed);
-
-
-    // SkFallbackAlloc will always succeed, using the heap as required.
-    fixed.reset();
-    SkFallbackAlloc fallback(&fixed);
-
-    bool fallback_failed = false;
-    for (int i = 0; i < 32; i++) {
-        fallback_failed = fallback_failed || (fallback.make<int>(i) == nullptr);
-    }
-    REPORTER_ASSERT(r, !fallback_failed);
-
-
-    // Test small, big, small allocations to make sure once we go to the heap we stay there.
-    fallback.reset();
-    auto smallA = fallback.make<int>(2);
-    auto    big = fallback.make<Big>();
-    auto smallB = fallback.make<int>(3);
-
-    auto in_buf = [&](void* ptr) {
-        return (uintptr_t)(buf+0 ) <= (uintptr_t)ptr
-            && (uintptr_t)(buf+32) >  (uintptr_t)ptr;
-    };
-
-    REPORTER_ASSERT(r,  in_buf(smallA));
-    REPORTER_ASSERT(r, !in_buf(big));
-    REPORTER_ASSERT(r, !in_buf(smallB));
-}
-
 struct WithDtor {
     ~WithDtor() { }
 };
@@ -198,5 +113,4 @@ DEF_TEST(ArenaAlloc, r) {
     }
     REPORTER_ASSERT(r, created == 11);
     REPORTER_ASSERT(r, destroyed == 11);
-
 }