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
This commit is contained in:
parent
0922fb1be5
commit
4b90c62dfc
@ -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 <typename T>
|
||||
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 <int N>
|
||||
explicit GrTAllocator(SkAlignedSTStorage<N,T>* 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 <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
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -144,13 +144,22 @@ private:
|
||||
|
||||
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 @@ 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<kGeoPoolStatePreAllocCnt, GeometryPoolState> fGeoPoolStateStack;
|
||||
|
||||
SkAlignedSTStorage<kDrawPreallocCnt, Draw> fDrawStorage;
|
||||
SkAlignedSTStorage<kStatePreallocCnt, SavedDrawState> fStateStorage;
|
||||
SkAlignedSTStorage<kClipPreallocCnt, GrClip> fClipStorage;
|
||||
SkAlignedSTStorage<kClearPreallocCnt, Clear> fClearStorage;
|
||||
|
||||
typedef GrDrawTarget INHERITED;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user