#include "GrConfig.h"
#include "SkTArray.h"
-class GrAllocator {
+class GrAllocator : GrNoncopyable {
public:
- virtual ~GrAllocator() {
+ ~GrAllocator() {
reset();
}
int fItemsPerBlock;
bool fOwnFirstBlock;
int fCount;
+
+ typedef GrNoncopyable INHERITED;
};
template <typename T>
-class GrTAllocator {
-private:
- GrAllocator fAllocator;
-
+class GrTAllocator : GrNoncopyable {
+
public:
virtual ~GrTAllocator() {};
* 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.
*/
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
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) {
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;
GrIndexBufferAllocPool& fIndexPool;
- enum {
- kDrawPreallocCnt = 8,
- kStatePreallocCnt = 8,
- kClipPreallocCnt = 8,
- kClearPreallocCnt = 4,
- kGeoPoolStatePreAllocCnt = 4,
- };
-
struct GeometryPoolState {
const GrVertexBuffer* fPoolVertexBuffer;
int fPoolStartVertex;
};
SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> fGeoPoolStateStack;
- SkAlignedSTStorage<kDrawPreallocCnt, Draw> fDrawStorage;
- SkAlignedSTStorage<kStatePreallocCnt, SavedDrawState> fStateStorage;
- SkAlignedSTStorage<kClipPreallocCnt, GrClip> fClipStorage;
- SkAlignedSTStorage<kClearPreallocCnt, Clear> fClearStorage;
-
typedef GrDrawTarget INHERITED;
};