removing setVertexArraySource from drawtarget

BUG=skia:

Review URL: https://codereview.chromium.org/699733002
This commit is contained in:
joshualitt 2014-11-04 07:47:55 -08:00 committed by Commit bot
parent 7a10fb6bea
commit d1aa8ff870
10 changed files with 23 additions and 231 deletions

View File

@ -419,22 +419,6 @@ void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize,
return ptr; return ptr;
} }
bool GrVertexBufferAllocPool::appendVertices(size_t vertexSize,
int vertexCount,
const void* vertices,
const GrVertexBuffer** buffer,
int* startVertex) {
void* space = makeSpace(vertexSize, vertexCount, buffer, startVertex);
if (space) {
memcpy(space,
vertices,
vertexSize * vertexCount);
return true;
} else {
return false;
}
}
int GrVertexBufferAllocPool::preallocatedBufferVertices(size_t vertexSize) const { int GrVertexBufferAllocPool::preallocatedBufferVertices(size_t vertexSize) const {
return static_cast<int>(INHERITED::preallocatedBufferSize() / vertexSize); return static_cast<int>(INHERITED::preallocatedBufferSize() / vertexSize);
} }
@ -477,19 +461,6 @@ void* GrIndexBufferAllocPool::makeSpace(int indexCount,
return ptr; return ptr;
} }
bool GrIndexBufferAllocPool::appendIndices(int indexCount,
const void* indices,
const GrIndexBuffer** buffer,
int* startIndex) {
void* space = makeSpace(indexCount, buffer, startIndex);
if (space) {
memcpy(space, indices, sizeof(uint16_t) * indexCount);
return true;
} else {
return false;
}
}
int GrIndexBufferAllocPool::preallocatedBufferIndices() const { int GrIndexBufferAllocPool::preallocatedBufferIndices() const {
return static_cast<int>(INHERITED::preallocatedBufferSize() / sizeof(uint16_t)); return static_cast<int>(INHERITED::preallocatedBufferSize() / sizeof(uint16_t));
} }

View File

@ -230,15 +230,6 @@ public:
const GrVertexBuffer** buffer, const GrVertexBuffer** buffer,
int* startVertex); int* startVertex);
/**
* Shortcut to make space and then write verts into the made space.
*/
bool appendVertices(size_t vertexSize,
int vertexCount,
const void* vertices,
const GrVertexBuffer** buffer,
int* startVertex);
/** /**
* Gets the number of vertices that can be added to the current VB without * 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 * spilling to another VB. If the pool has been reset, or the previous
@ -314,14 +305,6 @@ public:
const GrIndexBuffer** buffer, const GrIndexBuffer** buffer,
int* startIndex); int* startIndex);
/**
* Shortcut to make space and then write indices into the made space.
*/
bool appendIndices(int indexCount,
const void* indices,
const GrIndexBuffer** buffer,
int* startIndex);
/** /**
* Gets the number of indices that can be added to the current IB without * 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 * spilling to another IB. If the pool has been reset, or the previous

View File

@ -910,35 +910,32 @@ void GrContext::drawVertices(const GrPaint& paint,
set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset); set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset);
size_t VertexStride = drawState->getVertexStride(); size_t VertexStride = drawState->getVertexStride();
if (sizeof(SkPoint) != VertexStride) { if (!geo.set(target, vertexCount, indexCount)) {
if (!geo.set(target, vertexCount, 0)) { SkDebugf("Failed to get space for vertices!\n");
SkDebugf("Failed to get space for vertices!\n"); return;
return; }
} void* curVertex = geo.vertices();
void* curVertex = geo.vertices();
for (int i = 0; i < vertexCount; ++i) { for (int i = 0; i < vertexCount; ++i) {
*((SkPoint*)curVertex) = positions[i]; *((SkPoint*)curVertex) = positions[i];
if (texOffset >= 0) { if (texOffset >= 0) {
*(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i]; *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i];
}
if (colorOffset >= 0) {
*(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i];
}
curVertex = (void*)((intptr_t)curVertex + VertexStride);
} }
} else { if (colorOffset >= 0) {
target->setVertexSourceToArray(positions, vertexCount); *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i];
}
curVertex = (void*)((intptr_t)curVertex + VertexStride);
} }
// we don't currently apply offscreen AA to this path. Need improved // we don't currently apply offscreen AA to this path. Need improved
// management of GrDrawTarget's geometry to avoid copying points per-tile. // management of GrDrawTarget's geometry to avoid copying points per-tile.
if (indices) { if (indices) {
target->setIndexSourceToArray(indices, indexCount); uint16_t* curIndex = (uint16_t*)geo.indices();
for (int i = 0; i < indexCount; ++i) {
curIndex[i] = indices[i];
}
target->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount); target->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount);
target->resetIndexSource();
} else { } else {
target->drawNonIndexed(primitiveType, 0, vertexCount); target->drawNonIndexed(primitiveType, 0, vertexCount);
} }

View File

@ -232,9 +232,6 @@ void GrDrawTarget::releasePreviousVertexSource() {
switch (geoSrc.fVertexSrc) { switch (geoSrc.fVertexSrc) {
case kNone_GeometrySrcType: case kNone_GeometrySrcType:
break; break;
case kArray_GeometrySrcType:
this->releaseVertexArray();
break;
case kReserved_GeometrySrcType: case kReserved_GeometrySrcType:
this->releaseReservedVertexSpace(); this->releaseReservedVertexSpace();
break; break;
@ -255,9 +252,6 @@ void GrDrawTarget::releasePreviousIndexSource() {
switch (geoSrc.fIndexSrc) { switch (geoSrc.fIndexSrc) {
case kNone_GeometrySrcType: // these two don't require case kNone_GeometrySrcType: // these two don't require
break; break;
case kArray_GeometrySrcType:
this->releaseIndexArray();
break;
case kReserved_GeometrySrcType: case kReserved_GeometrySrcType:
this->releaseReservedIndexSpace(); this->releaseReservedIndexSpace();
break; break;
@ -273,25 +267,6 @@ void GrDrawTarget::releasePreviousIndexSource() {
} }
} }
void GrDrawTarget::setVertexSourceToArray(const void* vertexArray,
int vertexCount) {
this->releasePreviousVertexSource();
GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
geoSrc.fVertexSrc = kArray_GeometrySrcType;
geoSrc.fVertexSize = this->drawState()->getVertexStride();
geoSrc.fVertexCount = vertexCount;
this->onSetVertexSourceToArray(vertexArray, vertexCount);
}
void GrDrawTarget::setIndexSourceToArray(const void* indexArray,
int indexCount) {
this->releasePreviousIndexSource();
GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
geoSrc.fIndexSrc = kArray_GeometrySrcType;
geoSrc.fIndexCount = indexCount;
this->onSetIndexSourceToArray(indexArray, indexCount);
}
void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) { void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) {
this->releasePreviousVertexSource(); this->releasePreviousVertexSource();
GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
@ -358,7 +333,6 @@ bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
case kNone_GeometrySrcType: case kNone_GeometrySrcType:
SkFAIL("Attempting to draw without vertex src."); SkFAIL("Attempting to draw without vertex src.");
case kReserved_GeometrySrcType: // fallthrough case kReserved_GeometrySrcType: // fallthrough
case kArray_GeometrySrcType:
maxValidVertex = geoSrc.fVertexCount; maxValidVertex = geoSrc.fVertexCount;
break; break;
case kBuffer_GeometrySrcType: case kBuffer_GeometrySrcType:
@ -375,7 +349,6 @@ bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
case kNone_GeometrySrcType: case kNone_GeometrySrcType:
SkFAIL("Attempting to draw indexed geom without index src."); SkFAIL("Attempting to draw indexed geom without index src.");
case kReserved_GeometrySrcType: // fallthrough case kReserved_GeometrySrcType: // fallthrough
case kArray_GeometrySrcType:
maxValidIndex = geoSrc.fIndexCount; maxValidIndex = geoSrc.fIndexCount;
break; break;
case kBuffer_GeometrySrcType: case kBuffer_GeometrySrcType:

View File

@ -200,25 +200,6 @@ public:
virtual bool geometryHints(int* vertexCount, virtual bool geometryHints(int* vertexCount,
int* indexCount) const; int* indexCount) const;
/**
* Sets source of vertex data for the next draw. Array must contain
* the vertex data when this is called.
*
* @param vertexArray cpu array containing vertex data.
* @param vertexCount the number of vertices in the array. Vertex size is
* queried from the current GrDrawState.
*/
void setVertexSourceToArray(const void* vertexArray, int vertexCount);
/**
* Sets source of index data for the next indexed draw. Array must contain
* the indices when this is called.
*
* @param indexArray cpu array containing index data.
* @param indexCount the number of indices in the array.
*/
void setIndexSourceToArray(const void* indexArray, int indexCount);
/** /**
* Sets source of vertex data for the next draw. Data does not have to be * Sets source of vertex data for the next draw. Data does not have to be
* in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
@ -700,7 +681,6 @@ protected:
enum GeometrySrcType { enum GeometrySrcType {
kNone_GeometrySrcType, //<! src has not been specified kNone_GeometrySrcType, //<! src has not been specified
kReserved_GeometrySrcType, //<! src was set using reserve*Space kReserved_GeometrySrcType, //<! src was set using reserve*Space
kArray_GeometrySrcType, //<! src was set using set*SourceToArray
kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
}; };
@ -730,7 +710,6 @@ protected:
case kNone_GeometrySrcType: case kNone_GeometrySrcType:
return 0; return 0;
case kReserved_GeometrySrcType: case kReserved_GeometrySrcType:
case kArray_GeometrySrcType:
return src.fIndexCount; return src.fIndexCount;
case kBuffer_GeometrySrcType: case kBuffer_GeometrySrcType:
return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t)); return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
@ -853,12 +832,6 @@ private:
// 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;
virtual void releaseReservedIndexSpace() = 0; virtual void releaseReservedIndexSpace() = 0;
// subclass must consume array contents when set
virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCount) = 0;
virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) = 0;
// subclass is notified that geom source will be set away from an array
virtual void releaseVertexArray() = 0;
virtual void releaseIndexArray() = 0;
// subclass overrides to be notified just before geo src state is pushed/popped. // subclass overrides to be notified just before geo src state is pushed/popped.
virtual void geometrySourceWillPush() = 0; virtual void geometrySourceWillPush() = 0;
virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;

View File

@ -291,12 +291,10 @@ bool GrGpu::setupClipAndFlushState(DrawType type,
void GrGpu::geometrySourceWillPush() { void GrGpu::geometrySourceWillPush() {
const GeometrySrcState& geoSrc = this->getGeomSrc(); const GeometrySrcState& geoSrc = this->getGeomSrc();
if (kArray_GeometrySrcType == geoSrc.fVertexSrc || if (kReserved_GeometrySrcType == geoSrc.fVertexSrc) {
kReserved_GeometrySrcType == geoSrc.fVertexSrc) {
this->finalizeReservedVertices(); this->finalizeReservedVertices();
} }
if (kArray_GeometrySrcType == geoSrc.fIndexSrc || if (kReserved_GeometrySrcType == geoSrc.fIndexSrc) {
kReserved_GeometrySrcType == geoSrc.fIndexSrc) {
this->finalizeReservedIndices(); this->finalizeReservedIndices();
} }
GeometryPoolState& newState = fGeomPoolStateStack.push_back(); GeometryPoolState& newState = fGeomPoolStateStack.push_back();
@ -514,50 +512,3 @@ void GrGpu::releaseReservedIndexSpace() {
fIndexPool->putBack(bytes); fIndexPool->putBack(bytes);
--fIndexPoolUseCnt; --fIndexPoolUseCnt;
} }
void GrGpu::onSetVertexSourceToArray(const void* vertexArray, int vertexCount) {
this->prepareVertexPool();
GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
#ifdef SK_DEBUG
bool success =
#endif
fVertexPool->appendVertices(this->getVertexSize(),
vertexCount,
vertexArray,
&geomPoolState.fPoolVertexBuffer,
&geomPoolState.fPoolStartVertex);
++fVertexPoolUseCnt;
GR_DEBUGASSERT(success);
}
void GrGpu::onSetIndexSourceToArray(const void* indexArray, int indexCount) {
this->prepareIndexPool();
GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
#ifdef SK_DEBUG
bool success =
#endif
fIndexPool->appendIndices(indexCount,
indexArray,
&geomPoolState.fPoolIndexBuffer,
&geomPoolState.fPoolStartIndex);
++fIndexPoolUseCnt;
GR_DEBUGASSERT(success);
}
void GrGpu::releaseVertexArray() {
// if vertex source was array, we stowed data in the pool
const GeometrySrcState& geoSrc = this->getGeomSrc();
SkASSERT(kArray_GeometrySrcType == geoSrc.fVertexSrc);
size_t bytes = geoSrc.fVertexCount * geoSrc.fVertexSize;
fVertexPool->putBack(bytes);
--fVertexPoolUseCnt;
}
void GrGpu::releaseIndexArray() {
// if index source was array, we stowed data in the pool
const GeometrySrcState& geoSrc = this->getGeomSrc();
SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc);
size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t);
fIndexPool->putBack(bytes);
--fIndexPoolUseCnt;
}

View File

@ -372,10 +372,6 @@ private:
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;
virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCount) SK_OVERRIDE;
virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) SK_OVERRIDE;
virtual void releaseVertexArray() 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;

View File

@ -709,8 +709,7 @@ void GrInOrderDrawBuffer::releaseReservedVertexSpace() {
// If we get a release vertex space call then our current source should either be reserved // If we get a release vertex space call then our current source should either be reserved
// or array (which we copied into reserved space). // or array (which we copied into reserved space).
SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc || SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc);
kArray_GeometrySrcType == geoSrc.fVertexSrc);
// When the caller reserved vertex buffer space we gave it back a pointer // When the caller reserved vertex buffer space we gave it back a pointer
// provided by the vertex buffer pool. At each draw we tracked the largest // provided by the vertex buffer pool. At each draw we tracked the largest
@ -730,8 +729,7 @@ void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
// If we get a release index space call then our current source should either be reserved // If we get a release index space call then our current source should either be reserved
// or array (which we copied into reserved space). // or array (which we copied into reserved space).
SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc || SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc);
kArray_GeometrySrcType == geoSrc.fIndexSrc);
// Similar to releaseReservedVertexSpace we return any unused portion at // Similar to releaseReservedVertexSpace we return any unused portion at
// the tail // the tail
@ -742,46 +740,6 @@ void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
poolState.fPoolStartIndex = 0; poolState.fPoolStartIndex = 0;
} }
void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray, int vertexCount) {
GeometryPoolState& poolState = fGeoPoolStateStack.back();
SkASSERT(0 == poolState.fUsedPoolVertexBytes);
#ifdef SK_DEBUG
bool success =
#endif
fVertexPool.appendVertices(this->getVertexSize(),
vertexCount,
vertexArray,
&poolState.fPoolVertexBuffer,
&poolState.fPoolStartVertex);
GR_DEBUGASSERT(success);
}
void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray,
int indexCount) {
GeometryPoolState& poolState = fGeoPoolStateStack.back();
SkASSERT(0 == poolState.fUsedPoolIndexBytes);
#ifdef SK_DEBUG
bool success =
#endif
fIndexPool.appendIndices(indexCount,
indexArray,
&poolState.fPoolIndexBuffer,
&poolState.fPoolStartIndex);
GR_DEBUGASSERT(success);
}
void GrInOrderDrawBuffer::releaseVertexArray() {
// When the client provides an array as the vertex source we handled it
// by copying their array into reserved space.
this->GrInOrderDrawBuffer::releaseReservedVertexSpace();
}
void GrInOrderDrawBuffer::releaseIndexArray() {
// When the client provides an array as the index source we handled it
// by copying their array into reserved space.
this->GrInOrderDrawBuffer::releaseReservedIndexSpace();
}
void GrInOrderDrawBuffer::geometrySourceWillPush() { void GrInOrderDrawBuffer::geometrySourceWillPush() {
GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
poolState.fUsedPoolVertexBytes = 0; poolState.fUsedPoolVertexBytes = 0;
@ -801,12 +759,10 @@ void GrInOrderDrawBuffer::geometrySourceWillPop(const GeometrySrcState& restored
// we have to assume that any slack we had in our vertex/index data // we have to assume that any slack we had in our vertex/index data
// is now unreleasable because data may have been appended later in the // is now unreleasable because data may have been appended later in the
// pool. // pool.
if (kReserved_GeometrySrcType == restoredState.fVertexSrc || if (kReserved_GeometrySrcType == restoredState.fVertexSrc) {
kArray_GeometrySrcType == restoredState.fVertexSrc) {
poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount; poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
} }
if (kReserved_GeometrySrcType == restoredState.fIndexSrc || if (kReserved_GeometrySrcType == restoredState.fIndexSrc) {
kArray_GeometrySrcType == restoredState.fIndexSrc) {
poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * poolState.fUsedPoolIndexBytes = sizeof(uint16_t) *
restoredState.fIndexCount; restoredState.fIndexCount;
} }

View File

@ -282,12 +282,6 @@ private:
void** indices) SK_OVERRIDE; void** indices) SK_OVERRIDE;
virtual void releaseReservedVertexSpace() SK_OVERRIDE; virtual void releaseReservedVertexSpace() SK_OVERRIDE;
virtual void releaseReservedIndexSpace() SK_OVERRIDE; virtual void releaseReservedIndexSpace() SK_OVERRIDE;
virtual void onSetVertexSourceToArray(const void* vertexArray,
int vertexCount) SK_OVERRIDE;
virtual void onSetIndexSourceToArray(const void* indexArray,
int indexCount) SK_OVERRIDE;
virtual void releaseVertexArray() 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(int vertexCount, virtual void willReserveVertexAndIndexSpace(int vertexCount,

View File

@ -290,7 +290,6 @@ void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
case kBuffer_GeometrySrcType: case kBuffer_GeometrySrcType:
vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer; vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer;
break; break;
case kArray_GeometrySrcType:
case kReserved_GeometrySrcType: case kReserved_GeometrySrcType:
this->finalizeReservedVertices(); this->finalizeReservedVertices();
vertexOffsetInBytes += geoPoolState.fPoolStartVertex * this->getGeomSrc().fVertexSize; vertexOffsetInBytes += geoPoolState.fPoolStartVertex * this->getGeomSrc().fVertexSize;
@ -314,7 +313,6 @@ void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
*indexOffsetInBytes = 0; *indexOffsetInBytes = 0;
ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer; ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
break; break;
case kArray_GeometrySrcType:
case kReserved_GeometrySrcType: case kReserved_GeometrySrcType:
this->finalizeReservedIndices(); this->finalizeReservedIndices();
*indexOffsetInBytes = geoPoolState.fPoolStartIndex * sizeof(GrGLushort); *indexOffsetInBytes = geoPoolState.fPoolStartIndex * sizeof(GrGLushort);