return false;
}
- GrDrawTarget::AutoReleaseGeometry arg(target, layout, vCount, iCount);
+ drawState->setVertexLayout(layout);
+ GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount);
if (!arg.succeeded()) {
return false;
}
*lineCnt = lines.count() / 2;
int vertCnt = kVertsPerLineSeg * *lineCnt + kVertsPerQuad * *quadCnt;
- GrAssert(sizeof(Vertex) == GrDrawState::VertexSize(layout));
+ target->drawState()->setVertexLayout(layout);
+ GrAssert(sizeof(Vertex) == target->getDrawState().getVertexSize());
- if (!arg->set(target, layout, vertCnt, 0)) {
+ if (!arg->set(target, vertCnt, 0)) {
return false;
}
const GrRect& devRect,
bool useVertexCoverage) {
GrVertexLayout layout = aa_rect_layout(useVertexCoverage);
+ target->drawState()->setVertexLayout(layout);
- size_t vsize = GrDrawState::VertexSize(layout);
-
- GrDrawTarget::AutoReleaseGeometry geo(target, layout, 8, 0);
+ GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0);
if (!geo.succeeded()) {
GrPrintf("Failed to get space for vertices!\n");
return;
}
intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
+ size_t vsize = target->getDrawState().getVertexSize();
GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts);
GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize);
return;
}
GrVertexLayout layout = aa_rect_layout(useVertexCoverage);
- size_t vsize = GrDrawState::VertexSize(layout);
+ target->drawState()->setVertexLayout(layout);
- GrDrawTarget::AutoReleaseGeometry geo(target, layout, 16, 0);
+ GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0);
if (!geo.succeeded()) {
GrPrintf("Failed to get space for vertices!\n");
return;
}
intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
+ size_t vsize = target->getDrawState().getVertexSize();
// We create vertices for four nested rectangles. There are two ramps from 0 to full
// coverage, one on the exterior of the stroke and the other on the interior.
return NULL;
}
- GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit);
+ GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRInit);
GrDrawState* drawState = fGpu->drawState();
- GrDrawTarget::AutoGeometryPush agp(fGpu);
-
// The top-left of the mask corresponds to the top-left corner of the bounds.
SkVector clipToMaskOffset = {
SkIntToScalar(-clipSpaceIBounds.fLeft),
stencilBuffer->setLastClip(genID, clipSpaceIBounds, clipSpaceToStencilOffset);
- GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit);
+ GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRInit);
drawState = fGpu->drawState();
drawState->setRenderTarget(rt);
- GrDrawTarget::AutoGeometryPush agp(fGpu);
// We set the current clip to the bounds so that our recursive draws are scissored to them.
SkIRect stencilSpaceIBounds(clipSpaceIBounds);
drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params);
static const GrVertexLayout layout = GrDrawState::StageTexCoordVertexLayoutBit(0,0);
- GrDrawTarget::AutoReleaseGeometry arg(fGpu, layout, 4, 0);
+ drawState->setVertexLayout(layout);
+ GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0);
if (arg.succeeded()) {
GrPoint* verts = (GrPoint*) arg.vertices();
// unitSquareVertexBuffer()
static const int worstCaseVertCount = 10;
- GrDrawTarget::AutoReleaseGeometry geo(target, 0, worstCaseVertCount, 0);
+ target->drawState()->setVertexLayout(GrDrawState::kDefault_VertexLayout);
+ GrDrawTarget::AutoReleaseGeometry geo(target, worstCaseVertCount, 0);
if (!geo.succeeded()) {
GrPrintf("Failed to get space for vertices!\n");
if (NULL != colors) {
layout |= GrDrawState::kColor_VertexLayoutBit;
}
- int vertexSize = GrDrawState::VertexSize(layout);
+ target->drawState()->setVertexLayout(layout);
+ int vertexSize = target->getDrawState().getVertexSize();
if (sizeof(GrPoint) != vertexSize) {
- if (!geo.set(target, layout, vertexCount, 0)) {
+ if (!geo.set(target, vertexCount, 0)) {
GrPrintf("Failed to get space for vertices!\n");
return;
}
curVertex = (void*)((intptr_t)curVertex + vertexSize);
}
} else {
- target->setVertexSourceToArray(layout, positions, vertexCount);
+ target->setVertexSourceToArray(positions, vertexCount);
}
// we don't currently apply offscreen AA to this path. Need improved
}
GrVertexLayout layout = GrDrawState::kEdge_VertexLayoutBit;
- GrAssert(sizeof(CircleVertex) == GrDrawState::VertexSize(layout));
+ drawState->setVertexLayout(layout);
+ GrAssert(sizeof(CircleVertex) == drawState->getVertexSize());
- GrDrawTarget::AutoReleaseGeometry geo(target, layout, 4, 0);
+ GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
if (!geo.succeeded()) {
GrPrintf("Failed to get space for vertices!\n");
return;
}
}
-
- if (!arg->set(target, layout, maxPts, maxIdxs)) {
+ target->drawState()->setVertexLayout(layout);
+ if (!arg->set(target, maxPts, maxIdxs)) {
return false;
}
} else {
bounds = path.getBounds();
}
- GrDrawTarget::AutoGeometryPush agp(target);
+ GrDrawTarget::AutoGeometryAndStatePush agasp(target, GrDrawTarget::kPreserve_ASRInit);
target->drawSimpleRect(bounds, NULL);
} else {
if (passCount > 1) {
fRenderTarget.reset(NULL);
fCommon.fColor = 0xffffffff;
+ fCommon.fVertexLayout = kDefault_VertexLayout;
fCommon.fViewMatrix.reset();
fCommon.fSrcBlend = kOne_GrBlendCoeff;
fCommon.fDstBlend = kZero_GrBlendCoeff;
void setFromPaint(const GrPaint& paint);
///////////////////////////////////////////////////////////////////////////
- /// @name Vertex Format
+ /// @name Vertex Layout
////
/**
// make sure we haven't exceeded the number of bits in GrVertexLayout.
GR_STATIC_ASSERT(kHighVertexLayoutBit < ((uint64_t)1 << 8*sizeof(GrVertexLayout)));
+ enum VertexLayout {
+ kDefault_VertexLayout = 0
+ };
+
+ /**
+ * Sets vertex layout for next draw.
+ *
+ * @param layout the vertex layout to set.
+ */
+ void setVertexLayout(GrVertexLayout layout) { fCommon.fVertexLayout = layout; }
+
+ GrVertexLayout getVertexLayout() const { return fCommon.fVertexLayout; }
+ size_t getVertexSize() const { return VertexSize(fCommon.fVertexLayout); }
+
+
////////////////////////////////////////////////////////////////////////////
// Helpers for picking apart vertex layouts
struct CommonState {
// These fields are roughly sorted by decreasing likelihood of being different in op==
GrColor fColor;
+ GrVertexLayout fVertexLayout;
SkMatrix fViewMatrix;
GrBlendCoeff fSrcBlend;
GrBlendCoeff fDstBlend;
DrawFace fDrawFace;
bool operator== (const CommonState& other) const {
return fColor == other.fColor &&
+ fVertexLayout == other.fVertexLayout &&
fViewMatrix.cheapEqualTo(other.fViewMatrix) &&
fSrcBlend == other.fSrcBlend &&
fDstBlend == other.fDstBlend &&
}
}
-bool GrDrawTarget::reserveVertexSpace(GrVertexLayout vertexLayout,
+bool GrDrawTarget::reserveVertexSpace(size_t vertexSize,
int vertexCount,
void** vertices) {
GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
this->releasePreviousVertexSource();
geoSrc.fVertexSrc = kNone_GeometrySrcType;
- acquired = this->onReserveVertexSpace(GrDrawState::VertexSize(vertexLayout),
+ acquired = this->onReserveVertexSpace(vertexSize,
vertexCount,
vertices);
}
if (acquired) {
geoSrc.fVertexSrc = kReserved_GeometrySrcType;
geoSrc.fVertexCount = vertexCount;
- geoSrc.fVertexLayout = vertexLayout;
+ geoSrc.fVertexSize = vertexSize;
} else if (NULL != vertices) {
*vertices = NULL;
}
}
-bool GrDrawTarget::reserveVertexAndIndexSpace(GrVertexLayout vertexLayout,
- int vertexCount,
+bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount,
int indexCount,
void** vertices,
void** indices) {
- this->willReserveVertexAndIndexSpace(GrDrawState::VertexSize(vertexLayout), vertexCount, indexCount);
+ size_t vertexSize = this->drawState()->getVertexSize();
+ this->willReserveVertexAndIndexSpace(vertexCount, indexCount);
if (vertexCount) {
- if (!this->reserveVertexSpace(vertexLayout, vertexCount, vertices)) {
+ if (!this->reserveVertexSpace(vertexSize, vertexCount, vertices)) {
if (indexCount) {
this->resetIndexSource();
}
return true;
}
-bool GrDrawTarget::geometryHints(size_t vertexSize,
- int32_t* vertexCount,
+bool GrDrawTarget::geometryHints(int32_t* vertexCount,
int32_t* indexCount) const {
if (NULL != vertexCount) {
*vertexCount = -1;
}
}
-void GrDrawTarget::setVertexSourceToArray(GrVertexLayout vertexLayout,
- const void* vertexArray,
+void GrDrawTarget::setVertexSourceToArray(const void* vertexArray,
int vertexCount) {
this->releasePreviousVertexSource();
GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
geoSrc.fVertexSrc = kArray_GeometrySrcType;
- geoSrc.fVertexLayout = vertexLayout;
+ geoSrc.fVertexSize = this->drawState()->getVertexSize();
geoSrc.fVertexCount = vertexCount;
this->onSetVertexSourceToArray(vertexArray, vertexCount);
}
this->onSetIndexSourceToArray(indexArray, indexCount);
}
-void GrDrawTarget::setVertexSourceToBuffer(GrVertexLayout vertexLayout,
- const GrVertexBuffer* buffer) {
+void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) {
this->releasePreviousVertexSource();
GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
geoSrc.fVertexSrc = kBuffer_GeometrySrcType;
geoSrc.fVertexBuffer = buffer;
buffer->ref();
- geoSrc.fVertexLayout = vertexLayout;
+ geoSrc.fVertexSize = this->drawState()->getVertexSize();
}
void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
maxValidVertex = geoSrc.fVertexCount;
break;
case kBuffer_GeometrySrcType:
- maxValidVertex = geoSrc.fVertexBuffer->sizeInBytes() / GrDrawState::VertexSize(geoSrc.fVertexLayout);
+ maxValidVertex = geoSrc.fVertexBuffer->sizeInBytes() / geoSrc.fVertexSize;
break;
}
if (maxVertex > maxValidVertex) {
GrBlendCoeff* srcCoeff,
GrBlendCoeff* dstCoeff) const {
+ const GrDrawState& drawState = this->getDrawState();
+
GrVertexLayout layout;
if (kNone_GeometrySrcType == this->getGeomSrc().fVertexSrc) {
layout = default_blend_opts_vertex_layout();
} else {
- layout = this->getVertexLayout();
+ layout = drawState.getVertexLayout();
}
- const GrDrawState& drawState = this->getDrawState();
-
GrBlendCoeff bogusSrcCoeff, bogusDstCoeff;
if (NULL == srcCoeff) {
srcCoeff = &bogusSrcCoeff;
avmr.set(this->drawState(), *matrix, explicitCoordMask);
}
- AutoReleaseGeometry geo(this, layout, 4, 0);
+ this->drawState()->setVertexLayout(layout);
+ AutoReleaseGeometry geo(this, 4, 0);
if (!geo.succeeded()) {
GrPrintf("Failed to get space for vertices!\n");
return;
GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry(
GrDrawTarget* target,
- GrVertexLayout vertexLayout,
int vertexCount,
int indexCount) {
fTarget = NULL;
- this->set(target, vertexLayout, vertexCount, indexCount);
+ this->set(target, vertexCount, indexCount);
}
GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() {
}
bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target,
- GrVertexLayout vertexLayout,
int vertexCount,
int indexCount) {
this->reset();
bool success = true;
if (NULL != fTarget) {
fTarget = target;
- success = target->reserveVertexAndIndexSpace(vertexLayout,
- vertexCount,
+ success = target->reserveVertexAndIndexSpace(vertexCount,
indexCount,
&fVertices,
&fIndices);
* GrDrawTarget subclass. For deferred subclasses the caller has to
* guarantee that the data is still available in the buffers at playback.
* (TODO: Make this more automatic as we have done for read/write pixels)
+ *
+ * The size of each vertex is determined by querying the current GrDrawState.
*/
/**
* popGeomtrySource is called. At that point logically a snapshot of the
* data is made and the pointers are invalid.
*
- * @param vertexLayout the format of vertices (ignored if vertexCount == 0).
* @param vertexCount the number of vertices to reserve space for. Can be
- * 0.
+ * 0. Vertex size is queried from the current GrDrawState.
* @param indexCount the number of indices to reserve space for. Can be 0.
* @param vertices will point to reserved vertex space if vertexCount is
* non-zero. Illegal to pass NULL if vertexCount > 0.
* @param indices will point to reserved index space if indexCount is
* non-zero. Illegal to pass NULL if indexCount > 0.
*/
- bool reserveVertexAndIndexSpace(GrVertexLayout vertexLayout,
- int vertexCount,
+ bool reserveVertexAndIndexSpace(int vertexCount,
int indexCount,
void** vertices,
void** indices);
* Also may hint whether the draw target should be flushed first. This is
* useful for deferred targets.
*
- * @param vertexSize size of vertices caller would like to reserve
* @param vertexCount in: hint about how many vertices the caller would
- * like to allocate.
+ * like to allocate. Vertex size is queried from the
+ * current GrDrawState.
* out: a hint about the number of vertices that can be
* allocated cheaply. Negative means no hint.
* Ignored if NULL.
*
* @return true if target should be flushed based on the input values.
*/
- virtual bool geometryHints(size_t vertexSize,
- int* vertexCount,
+ 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 array cpu array containing vertex data.
- * @param size size of the vertex data.
- * @param vertexCount the number of vertices in the array.
+ * @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(GrVertexLayout vertexLayout,
- const void* vertexArray,
- int vertexCount);
+ 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 array cpu array containing index data.
+ * @param indexArray cpu array containing index data.
* @param indexCount the number of indices in the array.
*/
void setIndexSourceToArray(const void* indexArray, int indexCount);
* in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
*
* @param buffer vertex buffer containing vertex data. Must be
- * unlocked before draw call.
- * @param vertexLayout layout of the vertex data in the buffer.
+ * unlocked before draw call. Vertex size is queried
+ * from current GrDrawState.
*/
- void setVertexSourceToBuffer(GrVertexLayout vertexLayout,
- const GrVertexBuffer* buffer);
+ void setVertexSourceToBuffer(const GrVertexBuffer* buffer);
/**
* Sets source of index data for the next indexed draw. Data does not have
class AutoReleaseGeometry : ::GrNoncopyable {
public:
AutoReleaseGeometry(GrDrawTarget* target,
- GrVertexLayout vertexLayout,
int vertexCount,
int indexCount);
AutoReleaseGeometry();
~AutoReleaseGeometry();
bool set(GrDrawTarget* target,
- GrVertexLayout vertexLayout,
int vertexCount,
int indexCount);
bool succeeded() const { return NULL != fTarget; }
////////////////////////////////////////////////////////////////////////////
- class AutoGeometryPush : ::GrNoncopyable {
+ class AutoGeometryAndStatePush : ::GrNoncopyable {
public:
- AutoGeometryPush(GrDrawTarget* target) {
+ AutoGeometryAndStatePush(GrDrawTarget* target, ASRInit init)
+ : fState(target, init) {
GrAssert(NULL != target);
fTarget = target;
target->pushGeometrySource();
}
- ~AutoGeometryPush() {
+ ~AutoGeometryAndStatePush() {
fTarget->popGeometrySource();
}
private:
- GrDrawTarget* fTarget;
+ GrDrawTarget* fTarget;
+ AutoStateRestore fState;
};
protected:
int fIndexCount;
};
- GrVertexLayout fVertexLayout;
+ size_t fVertexSize;
};
int indexCountInCurrentSource() const {
// accessors for derived classes
const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); }
- // it is preferable to call this rather than getGeomSrc()->fVertexLayout because of the assert.
- GrVertexLayout getVertexLayout() const {
+ // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert.
+ size_t getVertexSize() const {
// the vertex layout is only valid if a vertex source has been specified.
GrAssert(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType);
- return this->getGeomSrc().fVertexLayout;
+ return this->getGeomSrc().fVertexSize;
}
Caps fCaps;
private:
// A subclass can optionally overload this function to be notified before
// vertex and index space is reserved.
- virtual void willReserveVertexAndIndexSpace(size_t vertexSize, int vertexCount, int indexCount) {}
+ virtual void willReserveVertexAndIndexSpace(int vertexCount, int indexCount) {}
// implemented by subclass to allocate space for reserved geom
virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0;
virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill) = 0;
// helpers for reserving vertex and index space.
- bool reserveVertexSpace(GrVertexLayout vertexLayout,
+ bool reserveVertexSpace(size_t vertexSize,
int vertexCount,
void** vertices);
bool reserveIndexSpace(int indexCount, void** indices);
void GrGpu::releaseReservedVertexSpace() {
const GeometrySrcState& geoSrc = this->getGeomSrc();
GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc);
- size_t bytes = geoSrc.fVertexCount * GrDrawState::VertexSize(geoSrc.fVertexLayout);
+ size_t bytes = geoSrc.fVertexCount * geoSrc.fVertexSize;
fVertexPool->putBack(bytes);
--fVertexPoolUseCnt;
}
#if GR_DEBUG
bool success =
#endif
- fVertexPool->appendVertices(GrDrawState::VertexSize(this->getVertexLayout()),
+ fVertexPool->appendVertices(this->getVertexSize(),
vertexCount,
vertexArray,
&geomPoolState.fPoolVertexBuffer,
// if vertex source was array, we stowed data in the pool
const GeometrySrcState& geoSrc = this->getGeomSrc();
GrAssert(kArray_GeometrySrcType == geoSrc.fVertexSrc);
- size_t bytes = geoSrc.fVertexCount * GrDrawState::VertexSize(geoSrc.fVertexLayout);
+ size_t bytes = geoSrc.fVertexCount * geoSrc.fVertexSize;
fVertexPool->putBack(bytes);
--fVertexPoolUseCnt;
}
private:
// GrDrawTarget overrides
- virtual bool onReserveVertexSpace(size_t vSize, int vertexCount, void** vertices) SK_OVERRIDE;
+ virtual bool onReserveVertexSpace(size_t vertexSize, 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;
// dual-source blending isn't available. This comes into play when there is coverage. If colors
// were a stage it could take a hint that every vertex's color will be opaque.
if (this->getCaps().dualSourceBlendingSupport() ||
- this->getDrawState().hasSolidCoverage(this->getGeomSrc().fVertexLayout)) {
+ this->getDrawState().hasSolidCoverage(this->getDrawState().getVertexLayout())) {
layout |= GrDrawState::kColor_VertexLayoutBit;;
// We set the draw state's color to white here. This is done so that any batching performed
// in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color
}
}
- AutoReleaseGeometry geo(this, layout, 4, 0);
+ this->drawState()->setVertexLayout(layout);
+ AutoReleaseGeometry geo(this, 4, 0);
if (!geo.succeeded()) {
GrPrintf("Failed to get space for vertices!\n");
return;
GrAssert(info.isInstanced());
const GeometrySrcState& geomSrc = this->getGeomSrc();
+ const GrDrawState& drawState = this->getDrawState();
// we only attempt to concat the case when reserved verts are used with a client-specified index
// buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
draw->verticesPerInstance() != info.verticesPerInstance() ||
draw->indicesPerInstance() != info.indicesPerInstance() ||
draw->fVertexBuffer != vertexBuffer ||
- draw->fIndexBuffer != geomSrc.fIndexBuffer ||
- draw->fVertexLayout != geomSrc.fVertexLayout) {
+ draw->fIndexBuffer != geomSrc.fIndexBuffer) {
return 0;
}
// info does not yet account for the offset from the start of the pool's VB while the previous
instancesToConcat = GrMin(instancesToConcat, info.instanceCount());
// update the amount of reserved vertex data actually referenced in draws
- size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
- GrDrawState::VertexSize(draw->fVertexLayout);
+ size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
+ drawState.getVertexSize();
poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
draw->adjustInstanceCount(instancesToConcat);
void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) {
GeometryPoolState& poolState = fGeoPoolStateStack.back();
+ const GrDrawState& drawState = this->getDrawState();
AutoClipReenable acr;
- if (this->getDrawState().isClipState() &&
+ if (drawState.isClipState() &&
NULL != info.getDevBounds() &&
this->quickInsideClip(*info.getDevBounds())) {
acr.set(this->drawState());
} else {
draw = this->recordDraw(info);
}
- draw->fVertexLayout = this->getVertexLayout();
switch (this->getGeomSrc().fVertexSrc) {
case kBuffer_GeometrySrcType:
break;
case kReserved_GeometrySrcType: // fallthrough
case kArray_GeometrySrcType: {
- size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
- GrDrawState::VertexSize(draw->fVertexLayout);
+ size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
+ drawState.getVertexSize();
poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
draw->fVertexBuffer = poolState.fPoolVertexBuffer;
draw->adjustStartVertex(poolState.fPoolStartVertex);
fIndexPool.unlock();
GrDrawTarget::AutoClipRestore acr(target);
- AutoGeometryPush agp(target);
+ AutoGeometryAndStatePush agasp(target, kPreserve_ASRInit);
GrDrawState playbackState;
GrDrawState* prevDrawState = target->drawState();
switch (fCmds[c]) {
case kDraw_Cmd: {
const DrawRecord& draw = fDraws[currDraw];
- target->setVertexSourceToBuffer(draw.fVertexLayout, draw.fVertexBuffer);
+ target->setVertexSourceToBuffer(draw.fVertexBuffer);
if (draw.isIndexed()) {
target->setIndexSourceToBuffer(draw.fIndexBuffer);
}
}
void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
- size_t vertexSize,
int vertexCount,
int indexCount) {
if (NULL != fAutoFlushTarget) {
!unreleasedVertexSpace &&
!unreleasedIndexSpace &&
!targetHasReservedGeom &&
- this->geometryHints(vertexSize, &vcount, &icount)) {
+ this->geometryHints(&vcount, &icount)) {
this->flushTo(fAutoFlushTarget);
}
}
}
-bool GrInOrderDrawBuffer::geometryHints(size_t vertexSize,
- int* vertexCount,
+bool GrInOrderDrawBuffer::geometryHints(int* vertexCount,
int* indexCount) const {
// we will recommend a flush if the data could fit in a single
// preallocated buffer but none are left and it can't fit
*indexCount = currIndices;
}
if (NULL != vertexCount) {
+ size_t vertexSize = this->getDrawState().getVertexSize();
int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
if (*vertexCount > currVertices &&
(!fVertexPool.preallocatedBuffersRemaining() &&
// provided by the vertex buffer pool. At each draw we tracked the largest
// offset into the pool's pointer that was referenced. Now we return to the
// pool any portion at the tail of the allocation that no draw referenced.
- size_t reservedVertexBytes = GrDrawState::VertexSize(geoSrc.fVertexLayout) *
- geoSrc.fVertexCount;
+ size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount;
fVertexPool.putBack(reservedVertexBytes -
poolState.fUsedPoolVertexBytes);
poolState.fUsedPoolVertexBytes = 0;
#if GR_DEBUG
bool success =
#endif
- fVertexPool.appendVertices(GrDrawState::VertexSize(this->getVertexLayout()),
+ fVertexPool.appendVertices(this->getVertexSize(),
vertexCount,
vertexArray,
&poolState.fPoolVertexBuffer,
// pool.
if (kReserved_GeometrySrcType == restoredState.fVertexSrc ||
kArray_GeometrySrcType == restoredState.fVertexSrc) {
- poolState.fUsedPoolVertexBytes =
- GrDrawState::VertexSize(restoredState.fVertexLayout) *
- restoredState.fVertexCount;
+ poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
}
if (kReserved_GeometrySrcType == restoredState.fIndexSrc ||
kArray_GeometrySrcType == restoredState.fIndexSrc) {
void setAutoFlushTarget(GrDrawTarget* target);
// overrides from GrDrawTarget
- virtual bool geometryHints(size_t vertexSize,
- int* vertexCount,
+ virtual bool geometryHints(int* vertexCount,
int* indexCount) const SK_OVERRIDE;
virtual void clear(const GrIRect* rect,
GrColor color,
class DrawRecord : public DrawInfo {
public:
DrawRecord(const DrawInfo& info) : DrawInfo(info) {}
- GrVertexLayout fVertexLayout;
const GrVertexBuffer* fVertexBuffer;
const GrIndexBuffer* fIndexBuffer;
};
virtual void releaseIndexArray() SK_OVERRIDE;
virtual void geometrySourceWillPush() SK_OVERRIDE;
virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE;
- virtual void willReserveVertexAndIndexSpace(size_t vertexSize,
- int vertexCount,
+ virtual void willReserveVertexAndIndexSpace(int vertexCount,
int indexCount) SK_OVERRIDE;
bool quickInsideClip(const SkRect& devBounds);
// If we need to reserve vertices allow the draw target to suggest
// a number of verts to reserve and whether to perform a flush.
fMaxVertices = kMinRequestedVerts;
- bool flush = (NULL != fDrawTarget) &&
- fDrawTarget->geometryHints(GrDrawState::VertexSize(fVertexLayout),
- &fMaxVertices,
- NULL);
+ bool flush = false;
+ fDrawTarget = fContext->getTextTarget(fPaint);
+ if (NULL != fDrawTarget) {
+ fDrawTarget->drawState()->setVertexLayout(fVertexLayout);
+ flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
+ }
if (flush) {
this->flushGlyphs();
fContext->flush();
}
- fDrawTarget = fContext->getTextTarget(fPaint);
fMaxVertices = kDefaultRequestedVerts;
// ignore return, no point in flushing again.
- fDrawTarget->geometryHints(GrDrawState::VertexSize(fVertexLayout),
- &fMaxVertices,
+ fDrawTarget->geometryHints(&fMaxVertices,
NULL);
int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads();
fMaxVertices = maxQuadVertices;
}
bool success = fDrawTarget->reserveVertexAndIndexSpace(
- fVertexLayout,
fMaxVertices,
0,
GrTCast<void**>(&fVertices),
const ProgramDesc& desc = fCurrentProgram->getDesc();
const GrDrawState& drawState = this->getDrawState();
- if (this->getVertexLayout() & GrDrawState::kColor_VertexLayoutBit) {
+ if (drawState.getVertexLayout() & GrDrawState::kColor_VertexLayoutBit) {
// color will be specified per-vertex as an attribute
// invalidate the const vertex attrib color
fHWConstAttribColor = GrColor_ILLEGAL;
// const GrDrawState& drawState = this->getDrawState();
- if (this->getVertexLayout() & GrDrawState::kCoverage_VertexLayoutBit) {
+ if (this->getDrawState().getVertexLayout() & GrDrawState::kCoverage_VertexLayoutBit) {
// coverage will be specified per-vertex as an attribute
// invalidate the const vertex attrib coverage
fHWConstAttribCoverage = GrColor_ILLEGAL;
int newTexCoordOffsets[GrDrawState::kMaxTexCoords];
int newEdgeOffset;
- GrVertexLayout currLayout = this->getVertexLayout();
+ GrVertexLayout currLayout = this->getDrawState().getVertexLayout();
GrGLsizei newStride = GrDrawState::VertexSizeAndOffsetsByIdx(currLayout,
newTexCoordOffsets,
// to a canonical value to avoid duplicate programs with different keys.
// Must initialize all fields or cache will have false negatives!
- desc->fVertexLayout = this->getVertexLayout();
+ desc->fVertexLayout = this->getDrawState().getVertexLayout();
desc->fEmitsPointSize = isPoints;