From a63389843dd18003382d61c2e4610af09ed07d38 Mon Sep 17 00:00:00 2001 From: "jvanverth@google.com" Date: Thu, 31 Jan 2013 21:34:25 +0000 Subject: [PATCH] Change vertex buffer allocator functions to take size rather than layout, take two. Resubmission of r7498. https://codereview.appspot.com/7228078 git-svn-id: http://skia.googlecode.com/svn/trunk@7501 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrBufferAllocPool.cpp | 26 ++++++++++++-------------- src/gpu/GrBufferAllocPool.h | 14 +++++++------- src/gpu/GrDrawTarget.cpp | 6 +++--- src/gpu/GrDrawTarget.h | 8 ++++---- src/gpu/GrGpu.cpp | 6 +++--- src/gpu/GrGpu.h | 2 +- src/gpu/GrInOrderDrawBuffer.cpp | 16 ++++++++-------- src/gpu/GrInOrderDrawBuffer.h | 6 +++--- src/gpu/GrTextContext.cpp | 4 ++-- 9 files changed, 43 insertions(+), 45 deletions(-) diff --git a/src/gpu/GrBufferAllocPool.cpp b/src/gpu/GrBufferAllocPool.cpp index 831c430891..ec8a9c9545 100644 --- a/src/gpu/GrBufferAllocPool.cpp +++ b/src/gpu/GrBufferAllocPool.cpp @@ -373,7 +373,7 @@ GrVertexBufferAllocPool::GrVertexBufferAllocPool(GrGpu* gpu, preallocBufferCnt) { } -void* GrVertexBufferAllocPool::makeSpace(GrVertexLayout layout, +void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize, int vertexCount, const GrVertexBuffer** buffer, int* startVertex) { @@ -382,43 +382,41 @@ void* GrVertexBufferAllocPool::makeSpace(GrVertexLayout layout, GrAssert(NULL != buffer); GrAssert(NULL != startVertex); - size_t vSize = GrDrawState::VertexSize(layout); size_t offset = 0; // assign to suppress warning const GrGeometryBuffer* geomBuffer = NULL; // assign to suppress warning - void* ptr = INHERITED::makeSpace(vSize * vertexCount, - vSize, + void* ptr = INHERITED::makeSpace(vertexSize * vertexCount, + vertexSize, &geomBuffer, &offset); *buffer = (const GrVertexBuffer*) geomBuffer; - GrAssert(0 == offset % vSize); - *startVertex = offset / vSize; + GrAssert(0 == offset % vertexSize); + *startVertex = offset / vertexSize; return ptr; } -bool GrVertexBufferAllocPool::appendVertices(GrVertexLayout layout, +bool GrVertexBufferAllocPool::appendVertices(size_t vertexSize, int vertexCount, const void* vertices, const GrVertexBuffer** buffer, int* startVertex) { - void* space = makeSpace(layout, vertexCount, buffer, startVertex); + void* space = makeSpace(vertexSize, vertexCount, buffer, startVertex); if (NULL != space) { memcpy(space, vertices, - GrDrawState::VertexSize(layout) * vertexCount); + vertexSize * vertexCount); return true; } else { return false; } } -int GrVertexBufferAllocPool::preallocatedBufferVertices(GrVertexLayout layout) const { - return INHERITED::preallocatedBufferSize() / - GrDrawState::VertexSize(layout); +int GrVertexBufferAllocPool::preallocatedBufferVertices(size_t vertexSize) const { + return INHERITED::preallocatedBufferSize() / vertexSize; } -int GrVertexBufferAllocPool::currentBufferVertices(GrVertexLayout layout) const { - return currentBufferItems(GrDrawState::VertexSize(layout)); +int GrVertexBufferAllocPool::currentBufferVertices(size_t vertexSize) const { + return currentBufferItems(vertexSize); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/GrBufferAllocPool.h b/src/gpu/GrBufferAllocPool.h index 654ba744f9..ffd8c34092 100644 --- a/src/gpu/GrBufferAllocPool.h +++ b/src/gpu/GrBufferAllocPool.h @@ -222,7 +222,7 @@ public: * the buffer at the offset indicated by startVertex. Until that time they * may be in temporary storage and/or the buffer may be locked. * - * @param layout specifies type of vertices to allocate space for + * @param vertexSize specifies size of a vertex to allocate space for * @param vertexCount number of vertices to allocate space for * @param buffer returns the vertex buffer that will hold the * vertices. @@ -230,7 +230,7 @@ public: * In units of the size of a vertex from layout param. * @return pointer to first vertex. */ - void* makeSpace(GrVertexLayout layout, + void* makeSpace(size_t vertexSize, int vertexCount, const GrVertexBuffer** buffer, int* startVertex); @@ -238,7 +238,7 @@ public: /** * Shortcut to make space and then write verts into the made space. */ - bool appendVertices(GrVertexLayout layout, + bool appendVertices(size_t vertexSize, int vertexCount, const void* vertices, const GrVertexBuffer** buffer, @@ -251,21 +251,21 @@ public: * 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 format of vertices to compute space for. + * @param the size of a vertex to compute space for. * @return the number of vertices that would fit in the current buffer. */ - int currentBufferVertices(GrVertexLayout layout) const; + 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 format of vertices to compute space for. + * @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(GrVertexLayout layout) const; + int preallocatedBufferVertices(size_t vertexSize) const; private: typedef GrBufferAllocPool INHERITED; diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp index d2d1d8d347..04ffaa4451 100644 --- a/src/gpu/GrDrawTarget.cpp +++ b/src/gpu/GrDrawTarget.cpp @@ -86,7 +86,7 @@ bool GrDrawTarget::reserveVertexSpace(GrVertexLayout vertexLayout, this->releasePreviousVertexSource(); geoSrc.fVertexSrc = kNone_GeometrySrcType; - acquired = this->onReserveVertexSpace(vertexLayout, + acquired = this->onReserveVertexSpace(GrDrawState::VertexSize(vertexLayout), vertexCount, vertices); } @@ -126,7 +126,7 @@ bool GrDrawTarget::reserveVertexAndIndexSpace(GrVertexLayout vertexLayout, int indexCount, void** vertices, void** indices) { - this->willReserveVertexAndIndexSpace(vertexLayout, vertexCount, indexCount); + this->willReserveVertexAndIndexSpace(GrDrawState::VertexSize(vertexLayout), vertexCount, indexCount); if (vertexCount) { if (!this->reserveVertexSpace(vertexLayout, vertexCount, vertices)) { if (indexCount) { @@ -146,7 +146,7 @@ bool GrDrawTarget::reserveVertexAndIndexSpace(GrVertexLayout vertexLayout, return true; } -bool GrDrawTarget::geometryHints(GrVertexLayout vertexLayout, +bool GrDrawTarget::geometryHints(size_t vertexSize, int32_t* vertexCount, int32_t* indexCount) const { if (NULL != vertexCount) { diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h index 2d1ca6cbaf..1c8ada11f3 100644 --- a/src/gpu/GrDrawTarget.h +++ b/src/gpu/GrDrawTarget.h @@ -254,7 +254,7 @@ public: * Also may hint whether the draw target should be flushed first. This is * useful for deferred targets. * - * @param vertexLayout layout of vertices caller would like to reserve + * @param vertexSize size of vertices caller would like to reserve * @param vertexCount in: hint about how many vertices the caller would * like to allocate. * out: a hint about the number of vertices that can be @@ -268,7 +268,7 @@ public: * * @return true if target should be flushed based on the input values. */ - virtual bool geometryHints(GrVertexLayout vertexLayout, + virtual bool geometryHints(size_t vertexSize, int* vertexCount, int* indexCount) const; @@ -761,10 +761,10 @@ protected: private: // A subclass can optionally overload this function to be notified before // vertex and index space is reserved. - virtual void willReserveVertexAndIndexSpace(GrVertexLayout,int vertexCount, int indexCount) {} + virtual void willReserveVertexAndIndexSpace(size_t vertexSize, int vertexCount, int indexCount) {} // implemented by subclass to allocate space for reserved geom - virtual bool onReserveVertexSpace(GrVertexLayout, int vertexCount, void** vertices) = 0; + virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0; virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; // implemented by subclass to handle release of reserved geom space virtual void releaseReservedVertexSpace() = 0; diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index b0ce7fe82e..4cce03f16e 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -429,7 +429,7 @@ void GrGpu::prepareIndexPool() { } } -bool GrGpu::onReserveVertexSpace(GrVertexLayout vertexLayout, +bool GrGpu::onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) { GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); @@ -439,7 +439,7 @@ bool GrGpu::onReserveVertexSpace(GrVertexLayout vertexLayout, this->prepareVertexPool(); - *vertices = fVertexPool->makeSpace(vertexLayout, + *vertices = fVertexPool->makeSpace(vertexSize, vertexCount, &geomPoolState.fPoolVertexBuffer, &geomPoolState.fPoolStartVertex); @@ -490,7 +490,7 @@ void GrGpu::onSetVertexSourceToArray(const void* vertexArray, int vertexCount) { #if GR_DEBUG bool success = #endif - fVertexPool->appendVertices(this->getVertexLayout(), + fVertexPool->appendVertices(GrDrawState::VertexSize(this->getVertexLayout()), vertexCount, vertexArray, &geomPoolState.fPoolVertexBuffer, diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index ebfc60fdd8..bcda2574f5 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -423,7 +423,7 @@ protected: private: // GrDrawTarget overrides - virtual bool onReserveVertexSpace(GrVertexLayout, int vertexCount, void** vertices) SK_OVERRIDE; + virtual bool onReserveVertexSpace(size_t vSize, int vertexCount, void** vertices) SK_OVERRIDE; virtual bool onReserveIndexSpace(int indexCount, void** indices) SK_OVERRIDE; virtual void releaseReservedVertexSpace() SK_OVERRIDE; virtual void releaseReservedIndexSpace() SK_OVERRIDE; diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp index 197cf0bac2..a0e3e99fe7 100644 --- a/src/gpu/GrInOrderDrawBuffer.cpp +++ b/src/gpu/GrInOrderDrawBuffer.cpp @@ -592,7 +592,7 @@ void GrInOrderDrawBuffer::setAutoFlushTarget(GrDrawTarget* target) { } void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace( - GrVertexLayout vertexLayout, + size_t vertexSize, int vertexCount, int indexCount) { if (NULL != fAutoFlushTarget) { @@ -624,14 +624,14 @@ void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace( !unreleasedVertexSpace && !unreleasedIndexSpace && !targetHasReservedGeom && - this->geometryHints(vertexLayout, &vcount, &icount)) { + this->geometryHints(vertexSize, &vcount, &icount)) { this->flushTo(fAutoFlushTarget); } } } -bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout, +bool GrInOrderDrawBuffer::geometryHints(size_t vertexSize, int* vertexCount, int* indexCount) const { // we will recommend a flush if the data could fit in a single @@ -649,10 +649,10 @@ bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout, *indexCount = currIndices; } if (NULL != vertexCount) { - int32_t currVertices = fVertexPool.currentBufferVertices(vertexLayout); + int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize); if (*vertexCount > currVertices && (!fVertexPool.preallocatedBuffersRemaining() && - *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexLayout))) { + *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) { flush = true; } @@ -661,7 +661,7 @@ bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout, return flush; } -bool GrInOrderDrawBuffer::onReserveVertexSpace(GrVertexLayout vertexLayout, +bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) { GeometryPoolState& poolState = fGeoPoolStateStack.back(); @@ -669,7 +669,7 @@ bool GrInOrderDrawBuffer::onReserveVertexSpace(GrVertexLayout vertexLayout, GrAssert(NULL != vertices); GrAssert(0 == poolState.fUsedPoolVertexBytes); - *vertices = fVertexPool.makeSpace(vertexLayout, + *vertices = fVertexPool.makeSpace(vertexSize, vertexCount, &poolState.fPoolVertexBuffer, &poolState.fPoolStartVertex); @@ -736,7 +736,7 @@ void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray, #if GR_DEBUG bool success = #endif - fVertexPool.appendVertices(this->getVertexLayout(), + fVertexPool.appendVertices(GrDrawState::VertexSize(this->getVertexLayout()), vertexCount, vertexArray, &poolState.fPoolVertexBuffer, diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h index 353d5bff52..21011c9650 100644 --- a/src/gpu/GrInOrderDrawBuffer.h +++ b/src/gpu/GrInOrderDrawBuffer.h @@ -100,7 +100,7 @@ public: int indicesPerInstance) SK_OVERRIDE; - virtual bool geometryHints(GrVertexLayout vertexLayout, + virtual bool geometryHints(size_t vertexSize, int* vertexCount, int* indexCount) const SK_OVERRIDE; @@ -152,7 +152,7 @@ private: // overrides from GrDrawTarget virtual void onDraw(const DrawInfo&) SK_OVERRIDE; virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType) SK_OVERRIDE; - virtual bool onReserveVertexSpace(GrVertexLayout layout, + virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) SK_OVERRIDE; virtual bool onReserveIndexSpace(int indexCount, @@ -167,7 +167,7 @@ private: virtual void releaseIndexArray() SK_OVERRIDE; virtual void geometrySourceWillPush() SK_OVERRIDE; virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE; - virtual void willReserveVertexAndIndexSpace(GrVertexLayout vertexLayout, + virtual void willReserveVertexAndIndexSpace(size_t vertexSize, int vertexCount, int indexCount) SK_OVERRIDE; diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp index 206f4ca3fb..97e92fa1ef 100644 --- a/src/gpu/GrTextContext.cpp +++ b/src/gpu/GrTextContext.cpp @@ -204,7 +204,7 @@ HAS_ATLAS: // a number of verts to reserve and whether to perform a flush. fMaxVertices = kMinRequestedVerts; bool flush = (NULL != fDrawTarget) && - fDrawTarget->geometryHints(fVertexLayout, + fDrawTarget->geometryHints(GrDrawState::VertexSize(fVertexLayout), &fMaxVertices, NULL); if (flush) { @@ -214,7 +214,7 @@ HAS_ATLAS: fDrawTarget = fContext->getTextTarget(fPaint); fMaxVertices = kDefaultRequestedVerts; // ignore return, no point in flushing again. - fDrawTarget->geometryHints(fVertexLayout, + fDrawTarget->geometryHints(GrDrawState::VertexSize(fVertexLayout), &fMaxVertices, NULL);