Change vertex buffer allocator functions to take size rather than layout.

https://codereview.appspot.com/7228078


git-svn-id: http://skia.googlecode.com/svn/trunk@7498 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
jvanverth@google.com 2013-01-31 20:15:36 +00:00
parent cfcb1bef94
commit 84cd77c4eb
9 changed files with 43 additions and 45 deletions

View File

@ -373,7 +373,7 @@ GrVertexBufferAllocPool::GrVertexBufferAllocPool(GrGpu* gpu,
preallocBufferCnt) { preallocBufferCnt) {
} }
void* GrVertexBufferAllocPool::makeSpace(GrVertexLayout layout, void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize,
int vertexCount, int vertexCount,
const GrVertexBuffer** buffer, const GrVertexBuffer** buffer,
int* startVertex) { int* startVertex) {
@ -382,43 +382,41 @@ void* GrVertexBufferAllocPool::makeSpace(GrVertexLayout layout,
GrAssert(NULL != buffer); GrAssert(NULL != buffer);
GrAssert(NULL != startVertex); GrAssert(NULL != startVertex);
size_t vSize = GrDrawState::VertexSize(layout);
size_t offset = 0; // assign to suppress warning size_t offset = 0; // assign to suppress warning
const GrGeometryBuffer* geomBuffer = NULL; // assign to suppress warning const GrGeometryBuffer* geomBuffer = NULL; // assign to suppress warning
void* ptr = INHERITED::makeSpace(vSize * vertexCount, void* ptr = INHERITED::makeSpace(vertexSize * vertexCount,
vSize, vertexSize,
&geomBuffer, &geomBuffer,
&offset); &offset);
*buffer = (const GrVertexBuffer*) geomBuffer; *buffer = (const GrVertexBuffer*) geomBuffer;
GrAssert(0 == offset % vSize); GrAssert(0 == offset % vertexSize);
*startVertex = offset / vSize; *startVertex = offset / vertexSize;
return ptr; return ptr;
} }
bool GrVertexBufferAllocPool::appendVertices(GrVertexLayout layout, bool GrVertexBufferAllocPool::appendVertices(size_t vertexSize,
int vertexCount, int vertexCount,
const void* vertices, const void* vertices,
const GrVertexBuffer** buffer, const GrVertexBuffer** buffer,
int* startVertex) { int* startVertex) {
void* space = makeSpace(layout, vertexCount, buffer, startVertex); void* space = makeSpace(vertexSize, vertexCount, buffer, startVertex);
if (NULL != space) { if (NULL != space) {
memcpy(space, memcpy(space,
vertices, vertices,
GrDrawState::VertexSize(layout) * vertexCount); vertexSize * vertexCount);
return true; return true;
} else { } else {
return false; return false;
} }
} }
int GrVertexBufferAllocPool::preallocatedBufferVertices(GrVertexLayout layout) const { int GrVertexBufferAllocPool::preallocatedBufferVertices(size_t vertexSize) const {
return INHERITED::preallocatedBufferSize() / return INHERITED::preallocatedBufferSize() / vertexSize;
GrDrawState::VertexSize(layout);
} }
int GrVertexBufferAllocPool::currentBufferVertices(GrVertexLayout layout) const { int GrVertexBufferAllocPool::currentBufferVertices(size_t vertexSize) const {
return currentBufferItems(GrDrawState::VertexSize(layout)); return currentBufferItems(vertexSize);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -222,7 +222,7 @@ public:
* the buffer at the offset indicated by startVertex. Until that time they * the buffer at the offset indicated by startVertex. Until that time they
* may be in temporary storage and/or the buffer may be locked. * 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 vertexCount number of vertices to allocate space for
* @param buffer returns the vertex buffer that will hold the * @param buffer returns the vertex buffer that will hold the
* vertices. * vertices.
@ -230,7 +230,7 @@ public:
* In units of the size of a vertex from layout param. * In units of the size of a vertex from layout param.
* @return pointer to first vertex. * @return pointer to first vertex.
*/ */
void* makeSpace(GrVertexLayout layout, void* makeSpace(size_t vertexSize,
int vertexCount, int vertexCount,
const GrVertexBuffer** buffer, const GrVertexBuffer** buffer,
int* startVertex); int* startVertex);
@ -238,7 +238,7 @@ public:
/** /**
* Shortcut to make space and then write verts into the made space. * Shortcut to make space and then write verts into the made space.
*/ */
bool appendVertices(GrVertexLayout layout, bool appendVertices(size_t vertexSize,
int vertexCount, int vertexCount,
const void* vertices, const void* vertices,
const GrVertexBuffer** buffer, const GrVertexBuffer** buffer,
@ -251,21 +251,21 @@ public:
* would fit in the next available preallocated buffer. If any makeSpace * 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. * 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. * @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. * Gets the number of vertices that can fit in a preallocated vertex buffer.
* Zero if no preallocated buffers. * 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 * @return number of vertices that fit in one of the preallocated vertex
* buffers. * buffers.
*/ */
int preallocatedBufferVertices(GrVertexLayout layout) const; int preallocatedBufferVertices(size_t vertexSize) const;
private: private:
typedef GrBufferAllocPool INHERITED; typedef GrBufferAllocPool INHERITED;

View File

@ -86,7 +86,7 @@ bool GrDrawTarget::reserveVertexSpace(GrVertexLayout vertexLayout,
this->releasePreviousVertexSource(); this->releasePreviousVertexSource();
geoSrc.fVertexSrc = kNone_GeometrySrcType; geoSrc.fVertexSrc = kNone_GeometrySrcType;
acquired = this->onReserveVertexSpace(vertexLayout, acquired = this->onReserveVertexSpace(GrDrawState::VertexSize(vertexLayout),
vertexCount, vertexCount,
vertices); vertices);
} }
@ -126,7 +126,7 @@ bool GrDrawTarget::reserveVertexAndIndexSpace(GrVertexLayout vertexLayout,
int indexCount, int indexCount,
void** vertices, void** vertices,
void** indices) { void** indices) {
this->willReserveVertexAndIndexSpace(vertexLayout, vertexCount, indexCount); this->willReserveVertexAndIndexSpace(GrDrawState::VertexSize(vertexLayout), vertexCount, indexCount);
if (vertexCount) { if (vertexCount) {
if (!this->reserveVertexSpace(vertexLayout, vertexCount, vertices)) { if (!this->reserveVertexSpace(vertexLayout, vertexCount, vertices)) {
if (indexCount) { if (indexCount) {
@ -146,7 +146,7 @@ bool GrDrawTarget::reserveVertexAndIndexSpace(GrVertexLayout vertexLayout,
return true; return true;
} }
bool GrDrawTarget::geometryHints(GrVertexLayout vertexLayout, bool GrDrawTarget::geometryHints(size_t vertexSize,
int32_t* vertexCount, int32_t* vertexCount,
int32_t* indexCount) const { int32_t* indexCount) const {
if (NULL != vertexCount) { if (NULL != vertexCount) {

View File

@ -254,7 +254,7 @@ public:
* Also may hint whether the draw target should be flushed first. This is * Also may hint whether the draw target should be flushed first. This is
* useful for deferred targets. * 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 * @param vertexCount in: hint about how many vertices the caller would
* like to allocate. * like to allocate.
* out: a hint about the number of vertices that can be * 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. * @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* vertexCount,
int* indexCount) const; int* indexCount) const;
@ -761,10 +761,10 @@ protected:
private: private:
// A subclass can optionally overload this function to be notified before // A subclass can optionally overload this function to be notified before
// vertex and index space is reserved. // 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 // 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; virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
// implemented by subclass to handle release of reserved geom space // implemented by subclass to handle release of reserved geom space
virtual void releaseReservedVertexSpace() = 0; virtual void releaseReservedVertexSpace() = 0;

View File

@ -429,7 +429,7 @@ void GrGpu::prepareIndexPool() {
} }
} }
bool GrGpu::onReserveVertexSpace(GrVertexLayout vertexLayout, bool GrGpu::onReserveVertexSpace(size_t vertexSize,
int vertexCount, int vertexCount,
void** vertices) { void** vertices) {
GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
@ -439,7 +439,7 @@ bool GrGpu::onReserveVertexSpace(GrVertexLayout vertexLayout,
this->prepareVertexPool(); this->prepareVertexPool();
*vertices = fVertexPool->makeSpace(vertexLayout, *vertices = fVertexPool->makeSpace(vertexSize,
vertexCount, vertexCount,
&geomPoolState.fPoolVertexBuffer, &geomPoolState.fPoolVertexBuffer,
&geomPoolState.fPoolStartVertex); &geomPoolState.fPoolStartVertex);
@ -490,7 +490,7 @@ void GrGpu::onSetVertexSourceToArray(const void* vertexArray, int vertexCount) {
#if GR_DEBUG #if GR_DEBUG
bool success = bool success =
#endif #endif
fVertexPool->appendVertices(this->getVertexLayout(), fVertexPool->appendVertices(GrDrawState::VertexSize(this->getVertexLayout()),
vertexCount, vertexCount,
vertexArray, vertexArray,
&geomPoolState.fPoolVertexBuffer, &geomPoolState.fPoolVertexBuffer,

View File

@ -423,7 +423,7 @@ protected:
private: private:
// GrDrawTarget overrides // 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 bool onReserveIndexSpace(int indexCount, void** indices) SK_OVERRIDE;
virtual void releaseReservedVertexSpace() SK_OVERRIDE; virtual void releaseReservedVertexSpace() SK_OVERRIDE;
virtual void releaseReservedIndexSpace() SK_OVERRIDE; virtual void releaseReservedIndexSpace() SK_OVERRIDE;

View File

@ -592,7 +592,7 @@ void GrInOrderDrawBuffer::setAutoFlushTarget(GrDrawTarget* target) {
} }
void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace( void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
GrVertexLayout vertexLayout, size_t vertexSize,
int vertexCount, int vertexCount,
int indexCount) { int indexCount) {
if (NULL != fAutoFlushTarget) { if (NULL != fAutoFlushTarget) {
@ -624,14 +624,14 @@ void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
!unreleasedVertexSpace && !unreleasedVertexSpace &&
!unreleasedIndexSpace && !unreleasedIndexSpace &&
!targetHasReservedGeom && !targetHasReservedGeom &&
this->geometryHints(vertexLayout, &vcount, &icount)) { this->geometryHints(vertexSize, &vcount, &icount)) {
this->flushTo(fAutoFlushTarget); this->flushTo(fAutoFlushTarget);
} }
} }
} }
bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout, bool GrInOrderDrawBuffer::geometryHints(size_t vertexSize,
int* vertexCount, int* vertexCount,
int* indexCount) const { int* indexCount) const {
// we will recommend a flush if the data could fit in a single // we will recommend a flush if the data could fit in a single
@ -649,10 +649,10 @@ bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout,
*indexCount = currIndices; *indexCount = currIndices;
} }
if (NULL != vertexCount) { if (NULL != vertexCount) {
int32_t currVertices = fVertexPool.currentBufferVertices(vertexLayout); int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
if (*vertexCount > currVertices && if (*vertexCount > currVertices &&
(!fVertexPool.preallocatedBuffersRemaining() && (!fVertexPool.preallocatedBuffersRemaining() &&
*vertexCount <= fVertexPool.preallocatedBufferVertices(vertexLayout))) { *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) {
flush = true; flush = true;
} }
@ -661,7 +661,7 @@ bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout,
return flush; return flush;
} }
bool GrInOrderDrawBuffer::onReserveVertexSpace(GrVertexLayout vertexLayout, bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize,
int vertexCount, int vertexCount,
void** vertices) { void** vertices) {
GeometryPoolState& poolState = fGeoPoolStateStack.back(); GeometryPoolState& poolState = fGeoPoolStateStack.back();
@ -669,7 +669,7 @@ bool GrInOrderDrawBuffer::onReserveVertexSpace(GrVertexLayout vertexLayout,
GrAssert(NULL != vertices); GrAssert(NULL != vertices);
GrAssert(0 == poolState.fUsedPoolVertexBytes); GrAssert(0 == poolState.fUsedPoolVertexBytes);
*vertices = fVertexPool.makeSpace(vertexLayout, *vertices = fVertexPool.makeSpace(vertexSize,
vertexCount, vertexCount,
&poolState.fPoolVertexBuffer, &poolState.fPoolVertexBuffer,
&poolState.fPoolStartVertex); &poolState.fPoolStartVertex);
@ -736,7 +736,7 @@ void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray,
#if GR_DEBUG #if GR_DEBUG
bool success = bool success =
#endif #endif
fVertexPool.appendVertices(this->getVertexLayout(), fVertexPool.appendVertices(GrDrawState::VertexSize(this->getVertexLayout()),
vertexCount, vertexCount,
vertexArray, vertexArray,
&poolState.fPoolVertexBuffer, &poolState.fPoolVertexBuffer,

View File

@ -100,7 +100,7 @@ public:
int indicesPerInstance) int indicesPerInstance)
SK_OVERRIDE; SK_OVERRIDE;
virtual bool geometryHints(GrVertexLayout vertexLayout, virtual bool geometryHints(size_t vertexSize,
int* vertexCount, int* vertexCount,
int* indexCount) const SK_OVERRIDE; int* indexCount) const SK_OVERRIDE;
@ -152,7 +152,7 @@ private:
// overrides from GrDrawTarget // overrides from GrDrawTarget
virtual void onDraw(const DrawInfo&) SK_OVERRIDE; virtual void onDraw(const DrawInfo&) SK_OVERRIDE;
virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType) 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, int vertexCount,
void** vertices) SK_OVERRIDE; void** vertices) SK_OVERRIDE;
virtual bool onReserveIndexSpace(int indexCount, virtual bool onReserveIndexSpace(int indexCount,
@ -167,7 +167,7 @@ private:
virtual void releaseIndexArray() SK_OVERRIDE; virtual void releaseIndexArray() SK_OVERRIDE;
virtual void geometrySourceWillPush() SK_OVERRIDE; virtual void geometrySourceWillPush() SK_OVERRIDE;
virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE; virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE;
virtual void willReserveVertexAndIndexSpace(GrVertexLayout vertexLayout, virtual void willReserveVertexAndIndexSpace(size_t vertexSize,
int vertexCount, int vertexCount,
int indexCount) SK_OVERRIDE; int indexCount) SK_OVERRIDE;

View File

@ -204,7 +204,7 @@ HAS_ATLAS:
// a number of verts to reserve and whether to perform a flush. // a number of verts to reserve and whether to perform a flush.
fMaxVertices = kMinRequestedVerts; fMaxVertices = kMinRequestedVerts;
bool flush = (NULL != fDrawTarget) && bool flush = (NULL != fDrawTarget) &&
fDrawTarget->geometryHints(fVertexLayout, fDrawTarget->geometryHints(GrDrawState::VertexSize(fVertexLayout),
&fMaxVertices, &fMaxVertices,
NULL); NULL);
if (flush) { if (flush) {
@ -214,7 +214,7 @@ HAS_ATLAS:
fDrawTarget = fContext->getTextTarget(fPaint); fDrawTarget = fContext->getTextTarget(fPaint);
fMaxVertices = kDefaultRequestedVerts; fMaxVertices = kDefaultRequestedVerts;
// ignore return, no point in flushing again. // ignore return, no point in flushing again.
fDrawTarget->geometryHints(fVertexLayout, fDrawTarget->geometryHints(GrDrawState::VertexSize(fVertexLayout),
&fMaxVertices, &fMaxVertices,
NULL); NULL);