From ac04fef619ad3939a25e66bdaef6f6b1e7f5ca50 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Fri, 13 Jan 2017 17:34:33 -0500 Subject: [PATCH] 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 Commit-Queue: Herb Derby --- bench/SkLinearBitmapPipelineBench.cpp | 2 +- gn/core.gni | 4 +- gn/tests.gni | 2 +- include/core/SkColorFilter.h | 6 +- include/core/SkShader.h | 6 +- include/effects/SkLumaColorFilter.h | 2 +- src/core/{SkFixedAlloc.cpp => SkArenaAlloc.cpp} | 46 +---------- src/core/{SkFixedAlloc.h => SkArenaAlloc.h} | 99 ------------------------ src/core/SkColorFilter.cpp | 6 +- src/core/SkColorMatrixFilterRowMajor255.cpp | 2 +- src/core/SkColorMatrixFilterRowMajor255.h | 2 +- src/core/SkColorShader.cpp | 6 +- src/core/SkColorShader.h | 4 +- src/core/SkLinearBitmapPipeline.cpp | 2 +- src/core/SkLinearBitmapPipeline.h | 2 +- src/core/SkModeColorFilter.cpp | 4 +- src/core/SkModeColorFilter.h | 2 +- src/core/SkPM4fPriv.h | 4 +- src/core/SkRasterPipelineBlitter.cpp | 11 +-- src/core/SkShader.cpp | 2 +- src/effects/SkLumaColorFilter.cpp | 2 +- src/image/SkImageShader.cpp | 4 +- src/image/SkImageShader.h | 2 +- tests/{FixedAllocTest.cpp => ArenaAllocTest.cpp} | 88 +-------------------- 24 files changed, 39 insertions(+), 271 deletions(-) rename src/core/{SkFixedAlloc.cpp => SkArenaAlloc.cpp} (81%) rename src/core/{SkFixedAlloc.h => SkArenaAlloc.h} (68%) rename tests/{FixedAllocTest.cpp => ArenaAllocTest.cpp} (56%) diff --git a/bench/SkLinearBitmapPipelineBench.cpp b/bench/SkLinearBitmapPipelineBench.cpp index 020ce7f..4e892b6 100644 --- a/bench/SkLinearBitmapPipelineBench.cpp +++ b/bench/SkLinearBitmapPipelineBench.cpp @@ -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" diff --git a/gn/core.gni b/gn/core.gni index e5d72b3..4325263 100644 --- a/gn/core.gni +++ b/gn/core.gni @@ -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", diff --git a/gn/tests.gni b/gn/tests.gni index caafae4..483f574 100644 --- a/gn/tests.gni +++ b/gn/tests.gni @@ -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", diff --git a/include/core/SkColorFilter.h b/include/core/SkColorFilter.h index fd3ccbc..a593087 100644 --- a/include/core/SkColorFilter.h +++ b/include/core/SkColorFilter.h @@ -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: diff --git a/include/core/SkShader.h b/include/core/SkShader.h index 6d24c1a..4bb887e 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -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; } diff --git a/include/effects/SkLumaColorFilter.h b/include/effects/SkLumaColorFilter.h index 5cddec6..2093944 100644 --- a/include/effects/SkLumaColorFilter.h +++ b/include/effects/SkLumaColorFilter.h @@ -42,7 +42,7 @@ protected: private: SkLumaColorFilter(); - bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkFallbackAlloc*, + bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*, bool shaderIsOpaque) const override; typedef SkColorFilter INHERITED; 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 - -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 68% 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 #include -// 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 - 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)...); - } - - // 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 - 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(std::forward(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)...); - } - - - // 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 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 @@ sk_sp 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; } 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 @@ 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, 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 @@ protected: 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 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_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(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 @@ 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: 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 #include -#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 @@ sk_sp SkModeColorFilter::CreateProc(SkReadBuffer& buffer) { bool SkModeColorFilter::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, - SkFallbackAlloc* scratch, + SkArenaAlloc* scratch, bool shaderIsOpaque) const { auto color = scratch->make(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 @@ protected: 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 @@ 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()->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 @@ 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(); } 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 @@ 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); 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 @@ 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; 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 @@ 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)) { 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 @@ 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 fImage; diff --git a/tests/FixedAllocTest.cpp b/tests/ArenaAllocTest.cpp similarity index 56% rename from tests/FixedAllocTest.cpp rename to tests/ArenaAllocTest.cpp index 75bc232..647ea25 100644 --- a/tests/FixedAllocTest.cpp +++ b/tests/ArenaAllocTest.cpp @@ -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(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(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(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(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(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(2); - auto big = fallback.make(); - auto smallB = fallback.make(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); - } -- 2.7.4