Add GrSTAllocator subclass, hide cons in GrTAllocator that takes ptr
Review URL: http://codereview.appspot.com/5147045/
git-svn-id: http://skia.googlecode.com/svn/trunk@2355 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrAllocator.h b/gpu/include/GrAllocator.h
index 7f1fe5b..21c79ec 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 @@
int fItemsPerBlock;
bool fOwnFirstBlock;
int fCount;
+
+ typedef GrNoncopyable INHERITED;
};
template <typename T>
-class GrTAllocator {
-private:
- GrAllocator fAllocator;
-
+class GrTAllocator : GrNoncopyable {
+
public:
virtual ~GrTAllocator() {};
@@ -151,20 +151,10 @@
* 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 <int N>
- explicit GrTAllocator(SkAlignedSTStorage<N,T>* initialBlock)
- : fAllocator(sizeof(T), N, initialBlock->get()) {}
-
- /**
* Adds an item and returns it.
*
* @return the added item.
@@ -232,7 +222,28 @@
*/
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 <int N, typename T> class GrSTAllocator : public GrTAllocator<T> {
+private:
+ typedef GrTAllocator<T> INHERITED;
+
+public:
+ GrSTAllocator() : INHERITED(N, fStorage.get()) {
+ }
+
+private:
+ SkAlignedSTStorage<N, T> fStorage;
};
#endif
diff --git a/gpu/src/GrInOrderDrawBuffer.cpp b/gpu/src/GrInOrderDrawBuffer.cpp
index 3d78da3..946d31c 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 122be53..3d1ec8c 100644
--- a/gpu/src/GrInOrderDrawBuffer.h
+++ b/gpu/src/GrInOrderDrawBuffer.h
@@ -144,13 +144,22 @@
void pushState();
void pushClip();
+
+ enum {
+ kDrawPreallocCnt = 8,
+ kStatePreallocCnt = 8,
+ kClipPreallocCnt = 8,
+ kClearPreallocCnt = 4,
+ kGeoPoolStatePreAllocCnt = 4,
+ };
const GrGpu* fGpu;
- GrTAllocator<Draw> fDraws;
- GrTAllocator<SavedDrawState> fStates;
- GrTAllocator<Clear> fClears;
- GrTAllocator<GrClip> fClips;
+ GrSTAllocator<kDrawPreallocCnt, Draw> fDraws;
+ GrSTAllocator<kStatePreallocCnt, SavedDrawState> fStates;
+ GrSTAllocator<kClearPreallocCnt, Clear> fClears;
+ GrSTAllocator<kClipPreallocCnt, GrClip> fClips;
+
bool fClipSet;
GrVertexLayout fLastRectVertexLayout;
@@ -162,14 +171,6 @@
GrIndexBufferAllocPool& fIndexPool;
- enum {
- kDrawPreallocCnt = 8,
- kStatePreallocCnt = 8,
- kClipPreallocCnt = 8,
- kClearPreallocCnt = 4,
- kGeoPoolStatePreAllocCnt = 4,
- };
-
struct GeometryPoolState {
const GrVertexBuffer* fPoolVertexBuffer;
int fPoolStartVertex;
@@ -183,11 +184,6 @@
};
SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> fGeoPoolStateStack;
- SkAlignedSTStorage<kDrawPreallocCnt, Draw> fDrawStorage;
- SkAlignedSTStorage<kStatePreallocCnt, SavedDrawState> fStateStorage;
- SkAlignedSTStorage<kClipPreallocCnt, GrClip> fClipStorage;
- SkAlignedSTStorage<kClearPreallocCnt, Clear> fClearStorage;
-
typedef GrDrawTarget INHERITED;
};