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
diff --git a/src/gpu/GrBufferAllocPool.cpp b/src/gpu/GrBufferAllocPool.cpp
index 831c430..ec8a9c9 100644
--- a/src/gpu/GrBufferAllocPool.cpp
+++ b/src/gpu/GrBufferAllocPool.cpp
@@ -373,7 +373,7 @@
preallocBufferCnt) {
}
-void* GrVertexBufferAllocPool::makeSpace(GrVertexLayout layout,
+void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize,
int vertexCount,
const GrVertexBuffer** buffer,
int* startVertex) {
@@ -382,43 +382,41 @@
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 654ba74..ffd8c34 100644
--- a/src/gpu/GrBufferAllocPool.h
+++ b/src/gpu/GrBufferAllocPool.h
@@ -222,7 +222,7 @@
* 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 @@
* 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 @@
/**
* 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 @@
* 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 d2d1d8d..04ffaa4 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -86,7 +86,7 @@
this->releasePreviousVertexSource();
geoSrc.fVertexSrc = kNone_GeometrySrcType;
- acquired = this->onReserveVertexSpace(vertexLayout,
+ acquired = this->onReserveVertexSpace(GrDrawState::VertexSize(vertexLayout),
vertexCount,
vertices);
}
@@ -126,7 +126,7 @@
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 @@
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 2d1ca6c..1c8ada1 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -254,7 +254,7 @@
* 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 @@
*
* @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 @@
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 b0ce7fe..4cce03f 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -429,7 +429,7 @@
}
}
-bool GrGpu::onReserveVertexSpace(GrVertexLayout vertexLayout,
+bool GrGpu::onReserveVertexSpace(size_t vertexSize,
int vertexCount,
void** vertices) {
GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
@@ -439,7 +439,7 @@
this->prepareVertexPool();
- *vertices = fVertexPool->makeSpace(vertexLayout,
+ *vertices = fVertexPool->makeSpace(vertexSize,
vertexCount,
&geomPoolState.fPoolVertexBuffer,
&geomPoolState.fPoolStartVertex);
@@ -490,7 +490,7 @@
#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 ebfc60f..bcda257 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -423,7 +423,7 @@
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 197cf0b..a0e3e99 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -592,7 +592,7 @@
}
void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
- GrVertexLayout vertexLayout,
+ size_t vertexSize,
int vertexCount,
int indexCount) {
if (NULL != fAutoFlushTarget) {
@@ -624,14 +624,14 @@
!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 @@
*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 @@
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 @@
GrAssert(NULL != vertices);
GrAssert(0 == poolState.fUsedPoolVertexBytes);
- *vertices = fVertexPool.makeSpace(vertexLayout,
+ *vertices = fVertexPool.makeSpace(vertexSize,
vertexCount,
&poolState.fPoolVertexBuffer,
&poolState.fPoolStartVertex);
@@ -736,7 +736,7 @@
#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 353d5bf..21011c9 100644
--- a/src/gpu/GrInOrderDrawBuffer.h
+++ b/src/gpu/GrInOrderDrawBuffer.h
@@ -100,7 +100,7 @@
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 @@
// 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 @@
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 206f4ca..97e92fa 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -204,7 +204,7 @@
// 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 @@
fDrawTarget = fContext->getTextTarget(fPaint);
fMaxVertices = kDefaultRequestedVerts;
// ignore return, no point in flushing again.
- fDrawTarget->geometryHints(fVertexLayout,
+ fDrawTarget->geometryHints(GrDrawState::VertexSize(fVertexLayout),
&fMaxVertices,
NULL);