Remove unneeded features from GrBufferAllocPool

Review URL: https://codereview.chromium.org/1103423004
This commit is contained in:
bsalomon 2015-04-29 04:33:52 -07:00 committed by Commit bot
parent 280a9c81aa
commit ecb8e3e394
3 changed files with 12 additions and 54 deletions

View File

@ -37,18 +37,13 @@ do {
GrBufferAllocPool::GrBufferAllocPool(GrGpu* gpu, GrBufferAllocPool::GrBufferAllocPool(GrGpu* gpu,
BufferType bufferType, BufferType bufferType,
bool frequentResetHint,
size_t blockSize, size_t blockSize,
int preallocBufferCnt) : int preallocBufferCnt) :
fBlocks(SkTMax(8, 2*preallocBufferCnt)) { fBlocks(SkTMax(8, 2*preallocBufferCnt)) {
SkASSERT(gpu); fGpu = SkRef(gpu);
fGpu = gpu;
fGpu->ref();
fGpuIsReffed = true;
fBufferType = bufferType; fBufferType = bufferType;
fFrequentResetHint = frequentResetHint;
fBufferPtr = NULL; fBufferPtr = NULL;
fMinBlockSize = SkTMax(GrBufferAllocPool_MIN_BLOCK_SIZE, blockSize); fMinBlockSize = SkTMax(GrBufferAllocPool_MIN_BLOCK_SIZE, blockSize);
@ -76,14 +71,7 @@ GrBufferAllocPool::~GrBufferAllocPool() {
destroyBlock(); destroyBlock();
} }
fPreallocBuffers.unrefAll(); fPreallocBuffers.unrefAll();
releaseGpuRef(); fGpu->unref();
}
void GrBufferAllocPool::releaseGpuRef() {
if (fGpuIsReffed) {
fGpu->unref();
fGpuIsReffed = false;
}
} }
void GrBufferAllocPool::reset() { void GrBufferAllocPool::reset() {
@ -317,17 +305,11 @@ bool GrBufferAllocPool::createBlock(size_t requestSize) {
SkASSERT(NULL == fBufferPtr); SkASSERT(NULL == fBufferPtr);
// If the buffer is CPU-backed we map it because it is free to do so and saves a copy. // If the buffer is CPU-backed we map it because it is free to do so and saves a copy.
// Otherwise when buffer mapping is supported: // Otherwise when buffer mapping is supported we map if the buffer size is greater than the
// a) If the frequently reset hint is set we only map when the requested size meets a // threshold.
// threshold (since we don't expect it is likely that we will see more vertex data)
// b) If the hint is not set we map if the buffer size is greater than the threshold.
bool attemptMap = block.fBuffer->isCPUBacked(); bool attemptMap = block.fBuffer->isCPUBacked();
if (!attemptMap && GrDrawTargetCaps::kNone_MapFlags != fGpu->caps()->mapBufferFlags()) { if (!attemptMap && GrDrawTargetCaps::kNone_MapFlags != fGpu->caps()->mapBufferFlags()) {
if (fFrequentResetHint) { attemptMap = size > GR_GEOM_BUFFER_MAP_THRESHOLD;
attemptMap = requestSize > GR_GEOM_BUFFER_MAP_THRESHOLD;
} else {
attemptMap = size > GR_GEOM_BUFFER_MAP_THRESHOLD;
}
} }
if (attemptMap) { if (attemptMap) {
@ -395,12 +377,10 @@ GrGeometryBuffer* GrBufferAllocPool::createBuffer(size_t size) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
GrVertexBufferAllocPool::GrVertexBufferAllocPool(GrGpu* gpu, GrVertexBufferAllocPool::GrVertexBufferAllocPool(GrGpu* gpu,
bool frequentResetHint,
size_t bufferSize, size_t bufferSize,
int preallocBufferCnt) int preallocBufferCnt)
: GrBufferAllocPool(gpu, : GrBufferAllocPool(gpu,
kVertex_BufferType, kVertex_BufferType,
frequentResetHint,
bufferSize, bufferSize,
preallocBufferCnt) { preallocBufferCnt) {
} }
@ -438,12 +418,10 @@ int GrVertexBufferAllocPool::currentBufferVertices(size_t vertexSize) const {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
GrIndexBufferAllocPool::GrIndexBufferAllocPool(GrGpu* gpu, GrIndexBufferAllocPool::GrIndexBufferAllocPool(GrGpu* gpu,
bool frequentResetHint,
size_t bufferSize, size_t bufferSize,
int preallocBufferCnt) int preallocBufferCnt)
: GrBufferAllocPool(gpu, : GrBufferAllocPool(gpu,
kIndex_BufferType, kIndex_BufferType,
frequentResetHint,
bufferSize, bufferSize,
preallocBufferCnt) { preallocBufferCnt) {
} }

View File

@ -76,10 +76,6 @@ protected:
* *
* @param gpu The GrGpu used to create the buffers. * @param gpu The GrGpu used to create the buffers.
* @param bufferType The type of buffers to create. * @param bufferType The type of buffers to create.
* @param frequentResetHint A hint that indicates that the pool
* should expect frequent unmap() calls
* (as opposed to many makeSpace / acquires
* between resets).
* @param bufferSize The minimum size of created buffers. * @param bufferSize The minimum size of created buffers.
* This value will be clamped to some * This value will be clamped to some
* reasonable minimum. * reasonable minimum.
@ -89,7 +85,6 @@ protected:
*/ */
GrBufferAllocPool(GrGpu* gpu, GrBufferAllocPool(GrGpu* gpu,
BufferType bufferType, BufferType bufferType,
bool frequentResetHint,
size_t bufferSize = 0, size_t bufferSize = 0,
int preallocBufferCnt = 0); int preallocBufferCnt = 0);
@ -146,7 +141,6 @@ private:
// The GrGpu must be able to clear the ref of pools it creates as members // The GrGpu must be able to clear the ref of pools it creates as members
friend class GrGpu; friend class GrGpu;
void releaseGpuRef();
struct BufferBlock { struct BufferBlock {
size_t fBytesFree; size_t fBytesFree;
@ -163,8 +157,6 @@ private:
size_t fBytesInUse; size_t fBytesInUse;
GrGpu* fGpu; GrGpu* fGpu;
bool fGpuIsReffed;
bool fFrequentResetHint;
SkTDArray<GrGeometryBuffer*> fPreallocBuffers; SkTDArray<GrGeometryBuffer*> fPreallocBuffers;
size_t fMinBlockSize; size_t fMinBlockSize;
BufferType fBufferType; BufferType fBufferType;
@ -189,20 +181,13 @@ public:
* Constructor * Constructor
* *
* @param gpu The GrGpu used to create the vertex buffers. * @param gpu The GrGpu used to create the vertex buffers.
* @param frequentResetHint A hint that indicates that the pool
* should expect frequent unmap() calls
* (as opposed to many makeSpace / acquires
* between resets).
* @param bufferSize The minimum size of created VBs This value * @param bufferSize The minimum size of created VBs This value
* will be clamped to some reasonable minimum. * will be clamped to some reasonable minimum.
* @param preallocBufferCnt The pool will allocate this number of VBs at * @param preallocBufferCnt The pool will allocate this number of VBs at
* bufferSize and keep them until it is * bufferSize and keep them until it is
* destroyed. * destroyed.
*/ */
GrVertexBufferAllocPool(GrGpu* gpu, GrVertexBufferAllocPool(GrGpu* gpu, size_t bufferSize = 0, int preallocBufferCnt = 0);
bool frequentResetHint,
size_t bufferSize = 0,
int preallocBufferCnt = 0);
/** /**
* Returns a block of memory to hold vertices. A buffer designated to hold * Returns a block of memory to hold vertices. A buffer designated to hold
@ -268,10 +253,6 @@ public:
* Constructor * Constructor
* *
* @param gpu The GrGpu used to create the index buffers. * @param gpu The GrGpu used to create the index buffers.
* @param frequentResetHint A hint that indicates that the pool
* should expect frequent unmap() calls
* (as opposed to many makeSpace / acquires
* between resets).
* @param bufferSize The minimum size of created IBs This value * @param bufferSize The minimum size of created IBs This value
* will be clamped to some reasonable minimum. * will be clamped to some reasonable minimum.
* @param preallocBufferCnt The pool will allocate this number of VBs at * @param preallocBufferCnt The pool will allocate this number of VBs at
@ -279,7 +260,6 @@ public:
* destroyed. * destroyed.
*/ */
GrIndexBufferAllocPool(GrGpu* gpu, GrIndexBufferAllocPool(GrGpu* gpu,
bool frequentResetHint,
size_t bufferSize = 0, size_t bufferSize = 0,
int preallocBufferCnt = 0); int preallocBufferCnt = 0);

View File

@ -1905,13 +1905,13 @@ void GrContext::setupDrawBuffer() {
SkASSERT(NULL == fDrawBufferIBAllocPool); SkASSERT(NULL == fDrawBufferIBAllocPool);
fDrawBufferVBAllocPool = fDrawBufferVBAllocPool =
SkNEW_ARGS(GrVertexBufferAllocPool, (fGpu, false, SkNEW_ARGS(GrVertexBufferAllocPool, (fGpu,
DRAW_BUFFER_VBPOOL_BUFFER_SIZE, DRAW_BUFFER_VBPOOL_BUFFER_SIZE,
DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS)); DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS));
fDrawBufferIBAllocPool = fDrawBufferIBAllocPool =
SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false, SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu,
DRAW_BUFFER_IBPOOL_BUFFER_SIZE, DRAW_BUFFER_IBPOOL_BUFFER_SIZE,
DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS));
fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (this, fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (this,
fDrawBufferVBAllocPool, fDrawBufferVBAllocPool,