removing setVertexArraySource from drawtarget
BUG=skia: Review URL: https://codereview.chromium.org/699733002
This commit is contained in:
parent
7a10fb6bea
commit
d1aa8ff870
@ -419,22 +419,6 @@ void* GrVertexBufferAllocPool::makeSpace(size_t vertexSize,
|
||||
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 {
|
||||
return static_cast<int>(INHERITED::preallocatedBufferSize() / vertexSize);
|
||||
}
|
||||
@ -477,19 +461,6 @@ void* GrIndexBufferAllocPool::makeSpace(int indexCount,
|
||||
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 {
|
||||
return static_cast<int>(INHERITED::preallocatedBufferSize() / sizeof(uint16_t));
|
||||
}
|
||||
|
@ -230,15 +230,6 @@ public:
|
||||
const GrVertexBuffer** buffer,
|
||||
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
|
||||
* spilling to another VB. If the pool has been reset, or the previous
|
||||
@ -314,14 +305,6 @@ public:
|
||||
const GrIndexBuffer** buffer,
|
||||
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
|
||||
* spilling to another IB. If the pool has been reset, or the previous
|
||||
|
@ -910,8 +910,7 @@ void GrContext::drawVertices(const GrPaint& paint,
|
||||
set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset);
|
||||
|
||||
size_t VertexStride = drawState->getVertexStride();
|
||||
if (sizeof(SkPoint) != VertexStride) {
|
||||
if (!geo.set(target, vertexCount, 0)) {
|
||||
if (!geo.set(target, vertexCount, indexCount)) {
|
||||
SkDebugf("Failed to get space for vertices!\n");
|
||||
return;
|
||||
}
|
||||
@ -928,17 +927,15 @@ void GrContext::drawVertices(const GrPaint& paint,
|
||||
}
|
||||
curVertex = (void*)((intptr_t)curVertex + VertexStride);
|
||||
}
|
||||
} else {
|
||||
target->setVertexSourceToArray(positions, vertexCount);
|
||||
}
|
||||
|
||||
// we don't currently apply offscreen AA to this path. Need improved
|
||||
// management of GrDrawTarget's geometry to avoid copying points per-tile.
|
||||
|
||||
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->resetIndexSource();
|
||||
} else {
|
||||
target->drawNonIndexed(primitiveType, 0, vertexCount);
|
||||
}
|
||||
|
@ -232,9 +232,6 @@ void GrDrawTarget::releasePreviousVertexSource() {
|
||||
switch (geoSrc.fVertexSrc) {
|
||||
case kNone_GeometrySrcType:
|
||||
break;
|
||||
case kArray_GeometrySrcType:
|
||||
this->releaseVertexArray();
|
||||
break;
|
||||
case kReserved_GeometrySrcType:
|
||||
this->releaseReservedVertexSpace();
|
||||
break;
|
||||
@ -255,9 +252,6 @@ void GrDrawTarget::releasePreviousIndexSource() {
|
||||
switch (geoSrc.fIndexSrc) {
|
||||
case kNone_GeometrySrcType: // these two don't require
|
||||
break;
|
||||
case kArray_GeometrySrcType:
|
||||
this->releaseIndexArray();
|
||||
break;
|
||||
case kReserved_GeometrySrcType:
|
||||
this->releaseReservedIndexSpace();
|
||||
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) {
|
||||
this->releasePreviousVertexSource();
|
||||
GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
|
||||
@ -358,7 +333,6 @@ bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
|
||||
case kNone_GeometrySrcType:
|
||||
SkFAIL("Attempting to draw without vertex src.");
|
||||
case kReserved_GeometrySrcType: // fallthrough
|
||||
case kArray_GeometrySrcType:
|
||||
maxValidVertex = geoSrc.fVertexCount;
|
||||
break;
|
||||
case kBuffer_GeometrySrcType:
|
||||
@ -375,7 +349,6 @@ bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
|
||||
case kNone_GeometrySrcType:
|
||||
SkFAIL("Attempting to draw indexed geom without index src.");
|
||||
case kReserved_GeometrySrcType: // fallthrough
|
||||
case kArray_GeometrySrcType:
|
||||
maxValidIndex = geoSrc.fIndexCount;
|
||||
break;
|
||||
case kBuffer_GeometrySrcType:
|
||||
|
@ -200,25 +200,6 @@ public:
|
||||
virtual bool geometryHints(int* vertexCount,
|
||||
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
|
||||
* in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
|
||||
@ -700,7 +681,6 @@ protected:
|
||||
enum GeometrySrcType {
|
||||
kNone_GeometrySrcType, //<! src has not been specified
|
||||
kReserved_GeometrySrcType, //<! src was set using reserve*Space
|
||||
kArray_GeometrySrcType, //<! src was set using set*SourceToArray
|
||||
kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
|
||||
};
|
||||
|
||||
@ -730,7 +710,6 @@ protected:
|
||||
case kNone_GeometrySrcType:
|
||||
return 0;
|
||||
case kReserved_GeometrySrcType:
|
||||
case kArray_GeometrySrcType:
|
||||
return src.fIndexCount;
|
||||
case kBuffer_GeometrySrcType:
|
||||
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
|
||||
virtual void releaseReservedVertexSpace() = 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.
|
||||
virtual void geometrySourceWillPush() = 0;
|
||||
virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
|
||||
|
@ -291,12 +291,10 @@ bool GrGpu::setupClipAndFlushState(DrawType type,
|
||||
|
||||
void GrGpu::geometrySourceWillPush() {
|
||||
const GeometrySrcState& geoSrc = this->getGeomSrc();
|
||||
if (kArray_GeometrySrcType == geoSrc.fVertexSrc ||
|
||||
kReserved_GeometrySrcType == geoSrc.fVertexSrc) {
|
||||
if (kReserved_GeometrySrcType == geoSrc.fVertexSrc) {
|
||||
this->finalizeReservedVertices();
|
||||
}
|
||||
if (kArray_GeometrySrcType == geoSrc.fIndexSrc ||
|
||||
kReserved_GeometrySrcType == geoSrc.fIndexSrc) {
|
||||
if (kReserved_GeometrySrcType == geoSrc.fIndexSrc) {
|
||||
this->finalizeReservedIndices();
|
||||
}
|
||||
GeometryPoolState& newState = fGeomPoolStateStack.push_back();
|
||||
@ -514,50 +512,3 @@ void GrGpu::releaseReservedIndexSpace() {
|
||||
fIndexPool->putBack(bytes);
|
||||
--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;
|
||||
}
|
||||
|
@ -372,10 +372,6 @@ private:
|
||||
virtual bool onReserveIndexSpace(int indexCount, void** indices) SK_OVERRIDE;
|
||||
virtual void releaseReservedVertexSpace() 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 geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE;
|
||||
|
||||
|
@ -709,8 +709,7 @@ void GrInOrderDrawBuffer::releaseReservedVertexSpace() {
|
||||
|
||||
// If we get a release vertex space call then our current source should either be reserved
|
||||
// or array (which we copied into reserved space).
|
||||
SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc ||
|
||||
kArray_GeometrySrcType == geoSrc.fVertexSrc);
|
||||
SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc);
|
||||
|
||||
// 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
|
||||
@ -730,8 +729,7 @@ void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
|
||||
|
||||
// If we get a release index space call then our current source should either be reserved
|
||||
// or array (which we copied into reserved space).
|
||||
SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc ||
|
||||
kArray_GeometrySrcType == geoSrc.fIndexSrc);
|
||||
SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc);
|
||||
|
||||
// Similar to releaseReservedVertexSpace we return any unused portion at
|
||||
// the tail
|
||||
@ -742,46 +740,6 @@ void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
|
||||
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() {
|
||||
GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
|
||||
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
|
||||
// is now unreleasable because data may have been appended later in the
|
||||
// pool.
|
||||
if (kReserved_GeometrySrcType == restoredState.fVertexSrc ||
|
||||
kArray_GeometrySrcType == restoredState.fVertexSrc) {
|
||||
if (kReserved_GeometrySrcType == restoredState.fVertexSrc) {
|
||||
poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
|
||||
}
|
||||
if (kReserved_GeometrySrcType == restoredState.fIndexSrc ||
|
||||
kArray_GeometrySrcType == restoredState.fIndexSrc) {
|
||||
if (kReserved_GeometrySrcType == restoredState.fIndexSrc) {
|
||||
poolState.fUsedPoolIndexBytes = sizeof(uint16_t) *
|
||||
restoredState.fIndexCount;
|
||||
}
|
||||
|
@ -282,12 +282,6 @@ private:
|
||||
void** indices) SK_OVERRIDE;
|
||||
virtual void releaseReservedVertexSpace() 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 geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE;
|
||||
virtual void willReserveVertexAndIndexSpace(int vertexCount,
|
||||
|
@ -290,7 +290,6 @@ void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
|
||||
case kBuffer_GeometrySrcType:
|
||||
vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer;
|
||||
break;
|
||||
case kArray_GeometrySrcType:
|
||||
case kReserved_GeometrySrcType:
|
||||
this->finalizeReservedVertices();
|
||||
vertexOffsetInBytes += geoPoolState.fPoolStartVertex * this->getGeomSrc().fVertexSize;
|
||||
@ -314,7 +313,6 @@ void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
|
||||
*indexOffsetInBytes = 0;
|
||||
ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
|
||||
break;
|
||||
case kArray_GeometrySrcType:
|
||||
case kReserved_GeometrySrcType:
|
||||
this->finalizeReservedIndices();
|
||||
*indexOffsetInBytes = geoPoolState.fPoolStartIndex * sizeof(GrGLushort);
|
||||
|
Loading…
Reference in New Issue
Block a user