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 "GrConfig.h"
|
||||||
#include "SkTArray.h"
|
#include "SkTArray.h"
|
||||||
|
|
||||||
class GrAllocator {
|
class GrAllocator : GrNoncopyable {
|
||||||
public:
|
public:
|
||||||
virtual ~GrAllocator() {
|
~GrAllocator() {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,12 +133,12 @@ private:
|
|||||||
int fItemsPerBlock;
|
int fItemsPerBlock;
|
||||||
bool fOwnFirstBlock;
|
bool fOwnFirstBlock;
|
||||||
int fCount;
|
int fCount;
|
||||||
|
|
||||||
|
typedef GrNoncopyable INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class GrTAllocator {
|
class GrTAllocator : GrNoncopyable {
|
||||||
private:
|
|
||||||
GrAllocator fAllocator;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~GrTAllocator() {};
|
virtual ~GrTAllocator() {};
|
||||||
@ -151,18 +151,8 @@ public:
|
|||||||
* Must be at least size(T)*itemsPerBlock sized.
|
* Must be at least size(T)*itemsPerBlock sized.
|
||||||
* Caller is responsible for freeing this memory.
|
* Caller is responsible for freeing this memory.
|
||||||
*/
|
*/
|
||||||
explicit GrTAllocator(int itemsPerBlock, void* initialBlock = NULL)
|
explicit GrTAllocator(int itemsPerBlock)
|
||||||
: fAllocator(sizeof(T), itemsPerBlock, initialBlock) {}
|
: 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.
|
* Adds an item and returns it.
|
||||||
@ -233,6 +223,27 @@ public:
|
|||||||
const T& operator[] (int i) const {
|
const T& operator[] (int i) const {
|
||||||
return *(const T*)(fAllocator[i]);
|
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
|
#endif
|
||||||
|
@ -18,17 +18,11 @@
|
|||||||
GrInOrderDrawBuffer::GrInOrderDrawBuffer(const GrGpu* gpu,
|
GrInOrderDrawBuffer::GrInOrderDrawBuffer(const GrGpu* gpu,
|
||||||
GrVertexBufferAllocPool* vertexPool,
|
GrVertexBufferAllocPool* vertexPool,
|
||||||
GrIndexBufferAllocPool* indexPool)
|
GrIndexBufferAllocPool* indexPool)
|
||||||
: fDraws(&fDrawStorage)
|
: fClipSet(true)
|
||||||
, fStates(&fStateStorage)
|
|
||||||
, fClears(&fClearStorage)
|
|
||||||
, fClips(&fClipStorage)
|
|
||||||
, fClipSet(true)
|
|
||||||
|
|
||||||
, fLastRectVertexLayout(0)
|
, fLastRectVertexLayout(0)
|
||||||
, fQuadIndexBuffer(NULL)
|
, fQuadIndexBuffer(NULL)
|
||||||
, fMaxQuads(0)
|
, fMaxQuads(0)
|
||||||
, fCurrQuad(0)
|
, fCurrQuad(0)
|
||||||
|
|
||||||
, fVertexPool(*vertexPool)
|
, fVertexPool(*vertexPool)
|
||||||
, fIndexPool(*indexPool) {
|
, fIndexPool(*indexPool) {
|
||||||
|
|
||||||
|
@ -145,12 +145,21 @@ private:
|
|||||||
void pushState();
|
void pushState();
|
||||||
void pushClip();
|
void pushClip();
|
||||||
|
|
||||||
const GrGpu* fGpu;
|
enum {
|
||||||
GrTAllocator<Draw> fDraws;
|
kDrawPreallocCnt = 8,
|
||||||
GrTAllocator<SavedDrawState> fStates;
|
kStatePreallocCnt = 8,
|
||||||
GrTAllocator<Clear> fClears;
|
kClipPreallocCnt = 8,
|
||||||
|
kClearPreallocCnt = 4,
|
||||||
|
kGeoPoolStatePreAllocCnt = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
const GrGpu* fGpu;
|
||||||
|
|
||||||
|
GrSTAllocator<kDrawPreallocCnt, Draw> fDraws;
|
||||||
|
GrSTAllocator<kStatePreallocCnt, SavedDrawState> fStates;
|
||||||
|
GrSTAllocator<kClearPreallocCnt, Clear> fClears;
|
||||||
|
GrSTAllocator<kClipPreallocCnt, GrClip> fClips;
|
||||||
|
|
||||||
GrTAllocator<GrClip> fClips;
|
|
||||||
bool fClipSet;
|
bool fClipSet;
|
||||||
|
|
||||||
GrVertexLayout fLastRectVertexLayout;
|
GrVertexLayout fLastRectVertexLayout;
|
||||||
@ -162,14 +171,6 @@ private:
|
|||||||
|
|
||||||
GrIndexBufferAllocPool& fIndexPool;
|
GrIndexBufferAllocPool& fIndexPool;
|
||||||
|
|
||||||
enum {
|
|
||||||
kDrawPreallocCnt = 8,
|
|
||||||
kStatePreallocCnt = 8,
|
|
||||||
kClipPreallocCnt = 8,
|
|
||||||
kClearPreallocCnt = 4,
|
|
||||||
kGeoPoolStatePreAllocCnt = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct GeometryPoolState {
|
struct GeometryPoolState {
|
||||||
const GrVertexBuffer* fPoolVertexBuffer;
|
const GrVertexBuffer* fPoolVertexBuffer;
|
||||||
int fPoolStartVertex;
|
int fPoolStartVertex;
|
||||||
@ -183,11 +184,6 @@ private:
|
|||||||
};
|
};
|
||||||
SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> fGeoPoolStateStack;
|
SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> fGeoPoolStateStack;
|
||||||
|
|
||||||
SkAlignedSTStorage<kDrawPreallocCnt, Draw> fDrawStorage;
|
|
||||||
SkAlignedSTStorage<kStatePreallocCnt, SavedDrawState> fStateStorage;
|
|
||||||
SkAlignedSTStorage<kClipPreallocCnt, GrClip> fClipStorage;
|
|
||||||
SkAlignedSTStorage<kClearPreallocCnt, Clear> fClearStorage;
|
|
||||||
|
|
||||||
typedef GrDrawTarget INHERITED;
|
typedef GrDrawTarget INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user