From 91d06bcc6c099515ebcfaa90017aec0713e1dc1f Mon Sep 17 00:00:00 2001 From: robertphillips Date: Wed, 6 May 2015 04:38:36 -0700 Subject: [PATCH] Reduce the API surface of GrBufferAllocPool and its derivatives This utility class is going to be revamped and moved. This CL shrinks it a bit so there will be less to shuffle around. Review URL: https://codereview.chromium.org/1126753003 --- src/gpu/GrBufferAllocPool.cpp | 45 +++-------------------- src/gpu/GrBufferAllocPool.h | 85 +------------------------------------------ 2 files changed, 7 insertions(+), 123 deletions(-) diff --git a/src/gpu/GrBufferAllocPool.cpp b/src/gpu/GrBufferAllocPool.cpp index d1ae037..82ec432 100644 --- a/src/gpu/GrBufferAllocPool.cpp +++ b/src/gpu/GrBufferAllocPool.cpp @@ -38,8 +38,8 @@ do { GrBufferAllocPool::GrBufferAllocPool(GrGpu* gpu, BufferType bufferType, size_t blockSize, - int preallocBufferCnt) : - fBlocks(SkTMax(8, 2*preallocBufferCnt)) { + int preallocBufferCnt) + : fBlocks(SkTMax(8, 2*preallocBufferCnt)) { fGpu = SkRef(gpu); @@ -68,7 +68,7 @@ GrBufferAllocPool::~GrBufferAllocPool() { } } while (!fBlocks.empty()) { - destroyBlock(); + this->destroyBlock(); } fPreallocBuffers.unrefAll(); fGpu->unref(); @@ -191,7 +191,7 @@ void* GrBufferAllocPool::makeSpace(size_t size, // updateData() if the amount of data passed is less than the full buffer // size. - if (!createBlock(size)) { + if (!this->createBlock(size)) { return NULL; } SkASSERT(fBufferPtr); @@ -205,27 +205,6 @@ void* GrBufferAllocPool::makeSpace(size_t size, return fBufferPtr; } -int GrBufferAllocPool::currentBufferItems(size_t itemSize) const { - VALIDATE(); - if (fBufferPtr) { - const BufferBlock& back = fBlocks.back(); - size_t usedBytes = back.fBuffer->gpuMemorySize() - back.fBytesFree; - size_t pad = GrSizeAlignUpPad(usedBytes, itemSize); - return static_cast((back.fBytesFree - pad) / itemSize); - } else if (fPreallocBuffersInUse < fPreallocBuffers.count()) { - return static_cast(fMinBlockSize / itemSize); - } - return 0; -} - -int GrBufferAllocPool::preallocatedBuffersRemaining() const { - return fPreallocBuffers.count() - fPreallocBuffersInUse; -} - -int GrBufferAllocPool::preallocatedBufferCount() const { - return fPreallocBuffers.count(); -} - void GrBufferAllocPool::putBack(size_t bytes) { VALIDATE(); @@ -236,7 +215,7 @@ void GrBufferAllocPool::putBack(size_t bytes) { int preallocBuffersInUse = fPreallocBuffersInUse; while (bytes) { - // caller shouldnt try to put back more than they've taken + // caller shouldn't try to put back more than they've taken SkASSERT(!fBlocks.empty()); BufferBlock& block = fBlocks.back(); size_t bytesUsed = block.fBuffer->gpuMemorySize() - block.fBytesFree; @@ -407,14 +386,6 @@ void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize, return ptr; } -int GrVertexBufferAllocPool::preallocatedBufferVertices(size_t vertexSize) const { - return static_cast(INHERITED::preallocatedBufferSize() / vertexSize); -} - -int GrVertexBufferAllocPool::currentBufferVertices(size_t vertexSize) const { - return currentBufferItems(vertexSize); -} - //////////////////////////////////////////////////////////////////////////////// GrIndexBufferAllocPool::GrIndexBufferAllocPool(GrGpu* gpu, @@ -447,10 +418,4 @@ void* GrIndexBufferAllocPool::makeSpace(int indexCount, return ptr; } -int GrIndexBufferAllocPool::preallocatedBufferIndices() const { - return static_cast(INHERITED::preallocatedBufferSize() / sizeof(uint16_t)); -} -int GrIndexBufferAllocPool::currentBufferIndices() const { - return currentBufferItems(sizeof(uint16_t)); -} diff --git a/src/gpu/GrBufferAllocPool.h b/src/gpu/GrBufferAllocPool.h index 9ea33f7..df0a0cc 100644 --- a/src/gpu/GrBufferAllocPool.h +++ b/src/gpu/GrBufferAllocPool.h @@ -41,25 +41,10 @@ public: void reset(); /** - * Gets the number of preallocated buffers that are yet to be used. - */ - int preallocatedBuffersRemaining() const; - - /** - * gets the number of preallocated buffers - */ - int preallocatedBufferCount() const; - - /** * Frees data from makeSpaces in LIFO order. */ void putBack(size_t bytes); - /** - * Gets the GrGpu that this pool is associated with. - */ - GrGpu* getGpu() { return fGpu; } - protected: /** * Used to determine what type of buffers to create. We could make the @@ -91,15 +76,6 @@ protected: virtual ~GrBufferAllocPool(); /** - * Gets the size of the preallocated buffers. - * - * @return the size of preallocated buffers. - */ - size_t preallocatedBufferSize() const { - return fPreallocBuffers.count() ? fMinBlockSize : 0; - } - - /** * Returns a block of memory to hold data. A buffer designated to hold the * data is given to the caller. The buffer may or may not be locked. The * returned ptr remains valid until any of the following: @@ -123,25 +99,9 @@ protected: const GrGeometryBuffer** buffer, size_t* offset); - /** - * Gets the number of items of a size that can be added to the current - * buffer without spilling to another buffer. If the pool has been reset, or - * the previous makeSpace completely exhausted a buffer then the returned - * size will be the size of the next available preallocated buffer, or zero - * if no preallocated buffer remains available. It is assumed that items - * should be itemSize-aligned from the start of a buffer. - * - * @return the number of items that would fit in the current buffer. - */ - int currentBufferItems(size_t itemSize) const; - GrGeometryBuffer* createBuffer(size_t size); private: - - // The GrGpu must be able to clear the ref of pools it creates as members - friend class GrGpu; - struct BufferBlock { size_t fBytesFree; GrGeometryBuffer* fBuffer; @@ -181,7 +141,7 @@ public: * Constructor * * @param gpu The GrGpu used to create the vertex buffers. - * @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. * @param preallocBufferCnt The pool will allocate this number of VBs at * bufferSize and keep them until it is @@ -215,29 +175,6 @@ public: const GrVertexBuffer** buffer, int* startVertex); - /** - * Gets the number of vertices that can be added to the current VB without - * spilling to another VB. If the pool has been reset, or the previous - * makeSpace completely exhausted a VB then the returned number of vertices - * would fit in the next available preallocated buffer. If any makeSpace - * would force a new VB to be created the return value will be zero. - * - * @param the size of a vertex to compute space for. - * @return the number of vertices that would fit in the current buffer. - */ - int currentBufferVertices(size_t vertexSize) const; - - /** - * Gets the number of vertices that can fit in a preallocated vertex buffer. - * Zero if no preallocated buffers. - * - * @param the size of a vertex to compute space for. - * - * @return number of vertices that fit in one of the preallocated vertex - * buffers. - */ - int preallocatedBufferVertices(size_t vertexSize) const; - private: typedef GrBufferAllocPool INHERITED; }; @@ -253,7 +190,7 @@ public: * Constructor * * @param gpu The GrGpu used to create the index buffers. - * @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. * @param preallocBufferCnt The pool will allocate this number of VBs at * bufferSize and keep them until it is @@ -285,24 +222,6 @@ public: const GrIndexBuffer** buffer, int* startIndex); - /** - * Gets the number of indices that can be added to the current IB without - * spilling to another IB. If the pool has been reset, or the previous - * makeSpace completely exhausted a IB then the returned number of indices - * would fit in the next available preallocated buffer. If any makeSpace - * would force a new IB to be created the return value will be zero. - */ - int currentBufferIndices() const; - - /** - * Gets the number of indices that can fit in a preallocated index buffer. - * Zero if no preallocated buffers. - * - * @return number of indices that fit in one of the preallocated index - * buffers. - */ - int preallocatedBufferIndices() const; - private: typedef GrBufferAllocPool INHERITED; }; -- 2.7.4