drawinfo carries bufferinfo

BUG=skia:

Review URL: https://codereview.chromium.org/737723003
This commit is contained in:
joshualitt 2014-11-18 14:24:27 -08:00 committed by Commit bot
parent 914dd53a42
commit 7eb8c7b00a
8 changed files with 84 additions and 115 deletions

View File

@ -159,43 +159,53 @@ private:
*/
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) {
switch (IO_TYPE) {
case kRead_GrIOType:
fResource->completedRead();
break;
case kWrite_GrIOType:
fResource->completedWrite();
break;
case kRW_GrIOType:
fResource->completedRead();
fResource->completedWrite();
break;
}
}
this->release();
}
T* get() const { return fResource; }
private:
void release() {
if (fResource) {
switch (IO_TYPE) {
case kRead_GrIOType:
fResource->completedRead();
break;
case kWrite_GrIOType:
fResource->completedWrite();
break;
case kRW_GrIOType:
fResource->completedRead();
fResource->completedWrite();
break;
}
}
}
T* fResource;
};
#endif

View File

@ -43,6 +43,9 @@ GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) {
fDstCopy = di.fDstCopy;
this->setVertexBuffer(di.vertexBuffer());
this->setIndexBuffer(di.indexBuffer());
return *this;
}
@ -469,6 +472,9 @@ void GrDrawTarget::drawIndexed(GrDrawState* ds,
if (!this->setupDstReadIfNecessary(ds, &info)) {
return;
}
this->setDrawBuffers(&info);
this->onDraw(*ds, info, scissorState);
}
}
@ -508,6 +514,9 @@ void GrDrawTarget::drawNonIndexed(GrDrawState* ds,
if (!this->setupDstReadIfNecessary(ds, &info)) {
return;
}
this->setDrawBuffers(&info);
this->onDraw(*ds, info, scissorState);
}
}
@ -754,11 +763,14 @@ void GrDrawTarget::drawIndexedInstances(GrDrawState* ds,
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,

View File

@ -15,6 +15,7 @@
#include "GrIndexBuffer.h"
#include "GrPathRendering.h"
#include "GrTraceMarker.h"
#include "GrVertexBuffer.h"
#include "SkClipStack.h"
#include "SkMatrix.h"
@ -29,7 +30,6 @@ class GrClipData;
class GrDrawTargetCaps;
class GrPath;
class GrPathRange;
class GrVertexBuffer;
class GrDrawTarget : public SkRefCnt {
public:
@ -559,6 +559,14 @@ 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.
@ -589,9 +597,13 @@ public:
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:

View File

@ -30,8 +30,6 @@ GrGpu::GrGpu(GrContext* context)
GrGpu::~GrGpu() {
SkSafeSetNull(fQuadIndexBuffer);
SkSafeUnref(fGeoSrcState.fVertexBuffer);
SkSafeUnref(fGeoSrcState.fIndexBuffer);
}
void GrGpu::contextAbandoned() {}
@ -260,19 +258,6 @@ void GrGpu::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
}
}
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;

View File

@ -356,25 +356,6 @@ public:
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&);
@ -426,23 +407,6 @@ protected:
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;
@ -536,7 +500,6 @@ private:
}
}
GeometrySrcState fGeoSrcState;
ResetTimestamp fResetTimestamp;
uint32_t fResetBits;
// these are mutable so they can be created on-demand

View File

@ -219,8 +219,8 @@ int GrInOrderDrawBuffer::concatInstancedDraw(const GrDrawState& ds,
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;
}
@ -260,39 +260,25 @@ int GrInOrderDrawBuffer::concatInstancedDraw(const GrDrawState& ds,
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();
@ -432,6 +418,23 @@ void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) {
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();
@ -511,12 +514,7 @@ void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const GrOptDra
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,

View File

@ -117,27 +117,15 @@ private:
};
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 {
@ -279,6 +267,7 @@ private:
GrColor color,
bool canIgnoreRect,
GrRenderTarget* renderTarget) SK_OVERRIDE;
virtual void setDrawBuffers(DrawInfo*) SK_OVERRIDE;
virtual bool onReserveVertexSpace(size_t vertexSize,
int vertexCount,

View File

@ -264,7 +264,7 @@ void GrGpuGL::setupGeometry(const GrOptDrawState& optState,
size_t vertexOffsetInBytes = stride * info.startVertex();
GrGLVertexBuffer* vbuf;
vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer;
vbuf = (GrGLVertexBuffer*) info.vertexBuffer();
SkASSERT(vbuf);
SkASSERT(!vbuf->isMapped());
@ -275,7 +275,7 @@ void GrGpuGL::setupGeometry(const GrOptDrawState& optState,
SkASSERT(indexOffsetInBytes);
*indexOffsetInBytes = 0;
ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
ibuf = (GrGLIndexBuffer*)info.indexBuffer();
SkASSERT(ibuf);
SkASSERT(!ibuf->isMapped());