diff --git a/gpu/include/GrAllocator.h b/gpu/include/GrAllocator.h index 7f1fe5b7e7..21c79ec7aa 100755 --- a/gpu/include/GrAllocator.h +++ b/gpu/include/GrAllocator.h @@ -14,9 +14,9 @@ #include "GrConfig.h" #include "SkTArray.h" -class GrAllocator { +class GrAllocator : GrNoncopyable { public: - virtual ~GrAllocator() { + ~GrAllocator() { reset(); } @@ -133,13 +133,13 @@ private: int fItemsPerBlock; bool fOwnFirstBlock; int fCount; + + typedef GrNoncopyable INHERITED; }; template -class GrTAllocator { -private: - GrAllocator fAllocator; - +class GrTAllocator : GrNoncopyable { + public: virtual ~GrTAllocator() {}; @@ -151,19 +151,9 @@ public: * Must be at least size(T)*itemsPerBlock sized. * Caller is responsible for freeing this memory. */ - explicit GrTAllocator(int itemsPerBlock, void* initialBlock = NULL) - : fAllocator(sizeof(T), itemsPerBlock, initialBlock) {} + explicit GrTAllocator(int itemsPerBlock) + : fAllocator(sizeof(T), itemsPerBlock, NULL) {} - /** - * Create an allocator using a GrAlignedTAlloc as the initial block. - * - * @param initialBlock specifies the storage for the initial block - * and the size of subsequent blocks. - */ - template - explicit GrTAllocator(SkAlignedSTStorage* initialBlock) - : fAllocator(sizeof(T), N, initialBlock->get()) {} - /** * Adds an item and returns it. * @@ -232,7 +222,28 @@ public: */ const T& operator[] (int i) const { return *(const T*)(fAllocator[i]); - } + } + +protected: + GrTAllocator(int itemsPerBlock, void* initialBlock) + : fAllocator(sizeof(T), itemsPerBlock, initialBlock) { + } + +private: + GrAllocator fAllocator; + typedef GrNoncopyable INHERITED; +}; + +template class GrSTAllocator : public GrTAllocator { +private: + typedef GrTAllocator INHERITED; + +public: + GrSTAllocator() : INHERITED(N, fStorage.get()) { + } + +private: + SkAlignedSTStorage fStorage; }; #endif diff --git a/gpu/src/GrInOrderDrawBuffer.cpp b/gpu/src/GrInOrderDrawBuffer.cpp index 3d78da398c..946d31cee2 100644 --- a/gpu/src/GrInOrderDrawBuffer.cpp +++ b/gpu/src/GrInOrderDrawBuffer.cpp @@ -18,17 +18,11 @@ GrInOrderDrawBuffer::GrInOrderDrawBuffer(const GrGpu* gpu, GrVertexBufferAllocPool* vertexPool, GrIndexBufferAllocPool* indexPool) - : fDraws(&fDrawStorage) - , fStates(&fStateStorage) - , fClears(&fClearStorage) - , fClips(&fClipStorage) - , fClipSet(true) - + : fClipSet(true) , fLastRectVertexLayout(0) , fQuadIndexBuffer(NULL) , fMaxQuads(0) , fCurrQuad(0) - , fVertexPool(*vertexPool) , fIndexPool(*indexPool) { diff --git a/gpu/src/GrInOrderDrawBuffer.h b/gpu/src/GrInOrderDrawBuffer.h index 122be53997..3d1ec8c4d9 100644 --- a/gpu/src/GrInOrderDrawBuffer.h +++ b/gpu/src/GrInOrderDrawBuffer.h @@ -144,13 +144,22 @@ private: void pushState(); void pushClip(); + + enum { + kDrawPreallocCnt = 8, + kStatePreallocCnt = 8, + kClipPreallocCnt = 8, + kClearPreallocCnt = 4, + kGeoPoolStatePreAllocCnt = 4, + }; const GrGpu* fGpu; - GrTAllocator fDraws; - GrTAllocator fStates; - GrTAllocator fClears; - GrTAllocator fClips; + GrSTAllocator fDraws; + GrSTAllocator fStates; + GrSTAllocator fClears; + GrSTAllocator fClips; + bool fClipSet; GrVertexLayout fLastRectVertexLayout; @@ -162,14 +171,6 @@ private: GrIndexBufferAllocPool& fIndexPool; - enum { - kDrawPreallocCnt = 8, - kStatePreallocCnt = 8, - kClipPreallocCnt = 8, - kClearPreallocCnt = 4, - kGeoPoolStatePreAllocCnt = 4, - }; - struct GeometryPoolState { const GrVertexBuffer* fPoolVertexBuffer; int fPoolStartVertex; @@ -183,11 +184,6 @@ private: }; SkSTArray fGeoPoolStateStack; - SkAlignedSTStorage fDrawStorage; - SkAlignedSTStorage fStateStorage; - SkAlignedSTStorage fClipStorage; - SkAlignedSTStorage fClearStorage; - typedef GrDrawTarget INHERITED; };