*/
template <typename T, GrIOType IO_TYPE> class GrPendingIOResource : SkNoncopyable {
public:
- GrPendingIOResource(T* resource) : fResource(resource) {
- if (NULL != fResource) {
+ GrPendingIOResource(T* resource = NULL) : fResource(NULL) {
+ this->reset(resource);
+ }
+
+ void reset(T* resource) {
+ if (resource) {
switch (IO_TYPE) {
case kRead_GrIOType:
- fResource->addPendingRead();
+ resource->addPendingRead();
break;
case kWrite_GrIOType:
- fResource->addPendingWrite();
+ resource->addPendingWrite();
break;
case kRW_GrIOType:
- fResource->addPendingRead();
- fResource->addPendingWrite();
+ resource->addPendingRead();
+ resource->addPendingWrite();
break;
}
}
+ this->release();
+ fResource = resource;
}
~GrPendingIOResource() {
- if (NULL != fResource) {
+ this->release();
+ }
+
+ T* get() const { return fResource; }
+
+private:
+ void release() {
+ if (fResource) {
switch (IO_TYPE) {
case kRead_GrIOType:
fResource->completedRead();
}
}
- T* get() const { return fResource; }
-
-private:
T* fResource;
};
#endif
fDstCopy = di.fDstCopy;
+ this->setVertexBuffer(di.vertexBuffer());
+ this->setIndexBuffer(di.indexBuffer());
+
return *this;
}
if (!this->setupDstReadIfNecessary(ds, &info)) {
return;
}
+
+ this->setDrawBuffers(&info);
+
this->onDraw(*ds, info, scissorState);
}
}
if (!this->setupDstReadIfNecessary(ds, &info)) {
return;
}
+
+ this->setDrawBuffers(&info);
+
this->onDraw(*ds, info, scissorState);
}
}
if (!this->setupDstReadIfNecessary(ds, &info)) {
return;
}
+
while (instanceCount) {
info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw);
info.fVertexCount = info.fInstanceCount * verticesPerInstance;
info.fIndexCount = info.fInstanceCount * indicesPerInstance;
+ this->setDrawBuffers(&info);
+
if (this->checkDraw(*ds,
type,
info.fStartVertex,
#include "GrIndexBuffer.h"
#include "GrPathRendering.h"
#include "GrTraceMarker.h"
+#include "GrVertexBuffer.h"
#include "SkClipStack.h"
#include "SkMatrix.h"
class GrDrawTargetCaps;
class GrPath;
class GrPathRange;
-class GrVertexBuffer;
class GrDrawTarget : public SkRefCnt {
public:
fDevBoundsStorage = bounds;
fDevBounds = &fDevBoundsStorage;
}
+ const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
+ const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); }
+ void setVertexBuffer(const GrVertexBuffer* vb) {
+ fVertexBuffer.reset(vb);
+ }
+ void setIndexBuffer(const GrIndexBuffer* ib) {
+ fIndexBuffer.reset(ib);
+ }
const SkRect* getDevBounds() const { return fDevBounds; }
// NULL if no copy of the dst is needed for the draw.
SkRect fDevBoundsStorage;
SkRect* fDevBounds;
+ GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer;
+ GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer;
+
GrDeviceCoordTexture fDstCopy;
};
+ virtual void setDrawBuffers(DrawInfo*) = 0;;
bool programUnitTest(int maxStages);
protected:
GrGpu::~GrGpu() {
SkSafeSetNull(fQuadIndexBuffer);
- SkSafeUnref(fGeoSrcState.fVertexBuffer);
- SkSafeUnref(fGeoSrcState.fIndexBuffer);
}
void GrGpu::contextAbandoned() {}
}
}
-void GrGpu::setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride) {
- SkSafeUnref(fGeoSrcState.fVertexBuffer);
- fGeoSrcState.fVertexBuffer = buffer;
- buffer->ref();
- fGeoSrcState.fVertexSize = vertexStride;
-}
-
-void GrGpu::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
- SkSafeUnref(fGeoSrcState.fIndexBuffer);
- fGeoSrcState.fIndexBuffer = buffer;
- buffer->ref();
-}
-
////////////////////////////////////////////////////////////////////////////////
static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1;
const SkIRect& srcRect,
const SkIPoint& dstPoint) = 0;
- /**
- * Sets source of vertex data for the next draw. Data does not have to be
- * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
- *
- * @param buffer vertex buffer containing vertex data. Must be
- * unlocked before draw call. Vertex size is queried
- * from current GrDrawState.
- */
- void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride);
-
- /**
- * Sets source of index data for the next indexed draw. Data does not have
- * to be in the buffer until drawIndexed.
- *
- * @param buffer index buffer containing indices. Must be unlocked
- * before indexed draw call.
- */
- void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
-
virtual void draw(const GrOptDrawState&,
const GrDrawTarget::DrawInfo&,
const GrClipMaskManager::ScissorState&);
unsigned int* ref,
unsigned int* mask);
- struct GeometrySrcState {
- GeometrySrcState() : fVertexBuffer(NULL), fIndexBuffer(NULL), fVertexSize(0) {}
- const GrVertexBuffer* fVertexBuffer;
- const GrIndexBuffer* fIndexBuffer;
- size_t fVertexSize;
- };
-
- // accessors for derived classes
- const GeometrySrcState& getGeomSrc() const { return fGeoSrcState; }
-
- // 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.
- SkASSERT(this->getGeomSrc().fVertexBuffer);
- return this->getGeomSrc().fVertexSize;
- }
-
const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; }
GrContext::GPUStats fGPUStats;
}
}
- GeometrySrcState fGeoSrcState;
ResetTimestamp fResetTimestamp;
uint32_t fResetBits;
// these are mutable so they can be created on-demand
if (!draw->fInfo.isInstanced() ||
draw->fInfo.verticesPerInstance() != info.verticesPerInstance() ||
draw->fInfo.indicesPerInstance() != info.indicesPerInstance() ||
- draw->vertexBuffer() != vertexBuffer ||
- draw->indexBuffer() != geomSrc.fIndexBuffer ||
+ draw->fInfo.vertexBuffer() != vertexBuffer ||
+ draw->fInfo.indexBuffer() != geomSrc.fIndexBuffer ||
draw->fScissorState != scissorState) {
return 0;
}
void GrInOrderDrawBuffer::onDraw(const GrDrawState& ds,
const DrawInfo& info,
const GrClipMaskManager::ScissorState& scissorState) {
+ SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer()));
+
GeometryPoolState& poolState = fGeoPoolStateStack.back();
this->recordStateIfNecessary(ds,
GrGpu::PrimTypeToDrawType(info.primitiveType()),
info.getDstCopy());
- const GrVertexBuffer* vb;
- if (kBuffer_GeometrySrcType == this->getGeomSrc().fVertexSrc) {
- vb = this->getGeomSrc().fVertexBuffer;
- } else {
- vb = poolState.fPoolVertexBuffer;
- }
-
- const GrIndexBuffer* ib = NULL;
- if (info.isIndexed()) {
- if (kBuffer_GeometrySrcType == this->getGeomSrc().fIndexSrc) {
- ib = this->getGeomSrc().fIndexBuffer;
- } else {
- ib = poolState.fPoolIndexBuffer;
- }
- }
-
Draw* draw;
if (info.isInstanced()) {
int instancesConcated = this->concatInstancedDraw(ds, info, scissorState);
if (info.instanceCount() > instancesConcated) {
- draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info, scissorState, vb, ib));
+ draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info, scissorState));
draw->fInfo.adjustInstanceCount(-instancesConcated);
} else {
return;
}
} else {
- draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info, scissorState, vb, ib));
+ draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info, scissorState));
}
this->recordTraceMarkersIfNecessary();
this->recordTraceMarkersIfNecessary();
}
+void GrInOrderDrawBuffer::setDrawBuffers(DrawInfo* info) {
+ GeometryPoolState& poolState = fGeoPoolStateStack.back();
+ if (kBuffer_GeometrySrcType == this->getGeomSrc().fVertexSrc) {
+ info->setVertexBuffer(this->getGeomSrc().fVertexBuffer);
+ } else {
+ info->setVertexBuffer(poolState.fPoolVertexBuffer);
+ }
+
+ if (info->isIndexed()) {
+ if (kBuffer_GeometrySrcType == this->getGeomSrc().fIndexSrc) {
+ info->setIndexBuffer(this->getGeomSrc().fIndexBuffer);
+ } else {
+ info->setIndexBuffer(poolState.fPoolIndexBuffer);
+ }
+ }
+}
+
void GrInOrderDrawBuffer::reset() {
SkASSERT(1 == fGeoPoolStateStack.count());
this->resetVertexSource();
if (!optState) {
return;
}
- GrGpu* dstGpu = buf->fDstGpu;
- dstGpu->setVertexSourceToBuffer(this->vertexBuffer(), optState->getVertexStride());
- if (fInfo.isIndexed()) {
- dstGpu->setIndexSourceToBuffer(this->indexBuffer());
- }
- dstGpu->draw(*optState, fInfo, fScissorState);
+ buf->fDstGpu->draw(*optState, fInfo, fScissorState);
}
void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf,
};
struct Draw : public Cmd {
- Draw(const DrawInfo& info,
- const ScissorState& scissorState,
- const GrVertexBuffer* vb,
- const GrIndexBuffer* ib)
+ Draw(const DrawInfo& info, const ScissorState& scissorState)
: Cmd(kDraw_Cmd)
, fInfo(info)
- , fScissorState(scissorState)
- , fVertexBuffer(vb)
- , fIndexBuffer(ib) {}
-
- const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
- const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); }
+ , fScissorState(scissorState){}
virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
DrawInfo fInfo;
ScissorState fScissorState;
-
- private:
- GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer;
- GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer;
};
struct StencilPath : public Cmd {
GrColor color,
bool canIgnoreRect,
GrRenderTarget* renderTarget) SK_OVERRIDE;
+ virtual void setDrawBuffers(DrawInfo*) SK_OVERRIDE;
virtual bool onReserveVertexSpace(size_t vertexSize,
int vertexCount,
size_t vertexOffsetInBytes = stride * info.startVertex();
GrGLVertexBuffer* vbuf;
- vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer;
+ vbuf = (GrGLVertexBuffer*) info.vertexBuffer();
SkASSERT(vbuf);
SkASSERT(!vbuf->isMapped());
SkASSERT(indexOffsetInBytes);
*indexOffsetInBytes = 0;
- ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
+ ibuf = (GrGLIndexBuffer*)info.indexBuffer();
SkASSERT(ibuf);
SkASSERT(!ibuf->isMapped());