removing setVertexArraySource from drawtarget
BUG=skia:
Review URL: https://codereview.chromium.org/699733002
diff --git a/src/gpu/GrBufferAllocPool.cpp b/src/gpu/GrBufferAllocPool.cpp
index 226f451..9fafcb3 100644
--- a/src/gpu/GrBufferAllocPool.cpp
+++ b/src/gpu/GrBufferAllocPool.cpp
@@ -419,22 +419,6 @@
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 @@
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));
}
diff --git a/src/gpu/GrBufferAllocPool.h b/src/gpu/GrBufferAllocPool.h
index e3d3982..40904cf 100644
--- a/src/gpu/GrBufferAllocPool.h
+++ b/src/gpu/GrBufferAllocPool.h
@@ -231,15 +231,6 @@
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
* makeSpace completely exhausted a VB then the returned number of vertices
@@ -315,14 +306,6 @@
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
* makeSpace completely exhausted a IB then the returned number of indices
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index d95b4fe..5891840 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -910,35 +910,32 @@
set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset);
size_t VertexStride = drawState->getVertexStride();
- if (sizeof(SkPoint) != VertexStride) {
- if (!geo.set(target, vertexCount, 0)) {
- SkDebugf("Failed to get space for vertices!\n");
- return;
- }
- void* curVertex = geo.vertices();
+ if (!geo.set(target, vertexCount, indexCount)) {
+ SkDebugf("Failed to get space for vertices!\n");
+ return;
+ }
+ void* curVertex = geo.vertices();
- for (int i = 0; i < vertexCount; ++i) {
- *((SkPoint*)curVertex) = positions[i];
+ for (int i = 0; i < vertexCount; ++i) {
+ *((SkPoint*)curVertex) = positions[i];
- if (texOffset >= 0) {
- *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i];
- }
- if (colorOffset >= 0) {
- *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i];
- }
- curVertex = (void*)((intptr_t)curVertex + VertexStride);
+ if (texOffset >= 0) {
+ *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i];
}
- } else {
- target->setVertexSourceToArray(positions, vertexCount);
+ if (colorOffset >= 0) {
+ *(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
// 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);
}
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index cd422ea..8f436f2 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -232,9 +232,6 @@
switch (geoSrc.fVertexSrc) {
case kNone_GeometrySrcType:
break;
- case kArray_GeometrySrcType:
- this->releaseVertexArray();
- break;
case kReserved_GeometrySrcType:
this->releaseReservedVertexSpace();
break;
@@ -255,9 +252,6 @@
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::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 @@
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 @@
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:
diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h
index 4e922d7..b1f758a 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -201,25 +201,6 @@
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 @@
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 @@
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 @@
// 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;
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index f7b9537..8cccd35 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -291,12 +291,10 @@
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 @@
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;
-}
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 5f65055..2dcee06 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -372,10 +372,6 @@
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;
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index 04b9ba2..ec8972c 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -709,8 +709,7 @@
// 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 @@
// 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 @@
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 @@
// 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;
}
diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h
index 1e8b5a6..714d822 100644
--- a/src/gpu/GrInOrderDrawBuffer.h
+++ b/src/gpu/GrInOrderDrawBuffer.h
@@ -282,12 +282,6 @@
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,
diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp
index 330f348..4ad333e 100644
--- a/src/gpu/gl/GrGpuGL_program.cpp
+++ b/src/gpu/gl/GrGpuGL_program.cpp
@@ -290,7 +290,6 @@
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 @@
*indexOffsetInBytes = 0;
ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
break;
- case kArray_GeometrySrcType:
case kReserved_GeometrySrcType:
this->finalizeReservedIndices();
*indexOffsetInBytes = geoPoolState.fPoolStartIndex * sizeof(GrGLushort);