Create GrOptDrawState directly in the cmd buffer in GrIODB.
Review URL: https://codereview.chromium.org/746243002
This commit is contained in:
parent
735f548c51
commit
932f866987
@ -77,8 +77,6 @@ private:
|
|||||||
called. */
|
called. */
|
||||||
void pendingIOComplete() const;
|
void pendingIOComplete() const;
|
||||||
|
|
||||||
friend class GrDrawState;
|
|
||||||
friend class GrOptDrawState;
|
|
||||||
friend class GrProgramElement;
|
friend class GrProgramElement;
|
||||||
|
|
||||||
GrGpuResource* fResource;
|
GrGpuResource* fResource;
|
||||||
|
@ -20,7 +20,7 @@ GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu,
|
|||||||
GrIndexBufferAllocPool* indexPool)
|
GrIndexBufferAllocPool* indexPool)
|
||||||
: INHERITED(gpu->getContext())
|
: INHERITED(gpu->getContext())
|
||||||
, fCmdBuffer(kCmdBufferInitialSizeInBytes)
|
, fCmdBuffer(kCmdBufferInitialSizeInBytes)
|
||||||
, fLastState(NULL)
|
, fPrevState(NULL)
|
||||||
, fDstGpu(gpu)
|
, fDstGpu(gpu)
|
||||||
, fVertexPool(*vertexPool)
|
, fVertexPool(*vertexPool)
|
||||||
, fIndexPool(*indexPool)
|
, fIndexPool(*indexPool)
|
||||||
@ -435,7 +435,7 @@ void GrInOrderDrawBuffer::reset() {
|
|||||||
this->resetIndexSource();
|
this->resetIndexSource();
|
||||||
|
|
||||||
fCmdBuffer.reset();
|
fCmdBuffer.reset();
|
||||||
fLastState.reset(NULL);
|
fPrevState = NULL;
|
||||||
fVertexPool.reset();
|
fVertexPool.reset();
|
||||||
fIndexPool.reset();
|
fIndexPool.reset();
|
||||||
reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve);
|
reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve);
|
||||||
@ -470,7 +470,7 @@ void GrInOrderDrawBuffer::flush() {
|
|||||||
|
|
||||||
// Updated every time we find a set state cmd to reflect the current state in the playback
|
// Updated every time we find a set state cmd to reflect the current state in the playback
|
||||||
// stream.
|
// stream.
|
||||||
SkAutoTUnref<const GrOptDrawState> currentOptState;
|
const GrOptDrawState* currentOptState = NULL;
|
||||||
|
|
||||||
while (iter.next()) {
|
while (iter.next()) {
|
||||||
GrGpuTraceMarker newMarker("", -1);
|
GrGpuTraceMarker newMarker("", -1);
|
||||||
@ -484,9 +484,9 @@ void GrInOrderDrawBuffer::flush() {
|
|||||||
|
|
||||||
if (kSetState_Cmd == strip_trace_bit(iter->fType)) {
|
if (kSetState_Cmd == strip_trace_bit(iter->fType)) {
|
||||||
SetState* ss = reinterpret_cast<SetState*>(iter.get());
|
SetState* ss = reinterpret_cast<SetState*>(iter.get());
|
||||||
currentOptState.reset(SkRef(ss->fState.get()));
|
currentOptState = &ss->fState;
|
||||||
} else {
|
} else {
|
||||||
iter->execute(this, currentOptState.get());
|
iter->execute(this, currentOptState);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd_has_trace_marker(iter->fType)) {
|
if (cmd_has_trace_marker(iter->fType)) {
|
||||||
@ -502,29 +502,32 @@ void GrInOrderDrawBuffer::flush() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const GrOptDrawState* optState) {
|
void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const GrOptDrawState* optState) {
|
||||||
|
SkASSERT(optState);
|
||||||
buf->fDstGpu->draw(*optState, fInfo);
|
buf->fDstGpu->draw(*optState, fInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf,
|
void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf,
|
||||||
const GrOptDrawState* optState) {
|
const GrOptDrawState* optState) {
|
||||||
|
SkASSERT(optState);
|
||||||
buf->fDstGpu->stencilPath(*optState, this->path(), fStencilSettings);
|
buf->fDstGpu->stencilPath(*optState, this->path(), fStencilSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf,
|
void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf,
|
||||||
const GrOptDrawState* optState) {
|
const GrOptDrawState* optState) {
|
||||||
|
SkASSERT(optState);
|
||||||
buf->fDstGpu->drawPath(*optState, this->path(), fStencilSettings);
|
buf->fDstGpu->drawPath(*optState, this->path(), fStencilSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf,
|
void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf,
|
||||||
const GrOptDrawState* optState) {
|
const GrOptDrawState* optState) {
|
||||||
|
SkASSERT(optState);
|
||||||
buf->fDstGpu->drawPaths(*optState, this->pathRange(),
|
buf->fDstGpu->drawPaths(*optState, this->pathRange(),
|
||||||
&buf->fPathIndexBuffer[fIndicesLocation], fCount,
|
&buf->fPathIndexBuffer[fIndicesLocation], fCount,
|
||||||
&buf->fPathTransformBuffer[fTransformsLocation], fTransformsType,
|
&buf->fPathTransformBuffer[fTransformsLocation], fTransformsType,
|
||||||
fStencilSettings);
|
fStencilSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const GrOptDrawState*) {
|
void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const GrOptDrawState*) {}
|
||||||
}
|
|
||||||
|
|
||||||
void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const GrOptDrawState*) {
|
void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const GrOptDrawState*) {
|
||||||
if (GrColor_ILLEGAL == fColor) {
|
if (GrColor_ILLEGAL == fColor) {
|
||||||
@ -727,15 +730,16 @@ bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds,
|
|||||||
GrGpu::DrawType drawType,
|
GrGpu::DrawType drawType,
|
||||||
const GrClipMaskManager::ScissorState& scissor,
|
const GrClipMaskManager::ScissorState& scissor,
|
||||||
const GrDeviceCoordTexture* dstCopy) {
|
const GrDeviceCoordTexture* dstCopy) {
|
||||||
SkAutoTUnref<GrOptDrawState> optState(
|
SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState,
|
||||||
SkNEW_ARGS(GrOptDrawState, (ds, fDstGpu, scissor, dstCopy, drawType)));
|
(ds, fDstGpu, scissor, dstCopy, drawType));
|
||||||
if (optState->mustSkip()) {
|
if (ss->fState.mustSkip()) {
|
||||||
|
fCmdBuffer.pop_back();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!fLastState || *optState != *fLastState) {
|
if (fPrevState && *fPrevState == ss->fState) {
|
||||||
SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (optState));
|
fCmdBuffer.pop_back();
|
||||||
fLastState.reset(SkRef(optState.get()));
|
} else {
|
||||||
ss->fDrawType = drawType;
|
fPrevState = &ss->fState;
|
||||||
this->recordTraceMarkersIfNecessary();
|
this->recordTraceMarkersIfNecessary();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -118,7 +118,7 @@ private:
|
|||||||
struct Draw : public Cmd {
|
struct Draw : public Cmd {
|
||||||
Draw(const DrawInfo& info) : Cmd(kDraw_Cmd), fInfo(info) {}
|
Draw(const DrawInfo& info) : Cmd(kDraw_Cmd), fInfo(info) {}
|
||||||
|
|
||||||
virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
|
void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
|
||||||
|
|
||||||
DrawInfo fInfo;
|
DrawInfo fInfo;
|
||||||
};
|
};
|
||||||
@ -128,7 +128,7 @@ private:
|
|||||||
|
|
||||||
const GrPath* path() const { return fPath.get(); }
|
const GrPath* path() const { return fPath.get(); }
|
||||||
|
|
||||||
virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
|
void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
|
||||||
|
|
||||||
GrStencilSettings fStencilSettings;
|
GrStencilSettings fStencilSettings;
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ private:
|
|||||||
|
|
||||||
const GrPath* path() const { return fPath.get(); }
|
const GrPath* path() const { return fPath.get(); }
|
||||||
|
|
||||||
virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
|
void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
|
||||||
|
|
||||||
GrStencilSettings fStencilSettings;
|
GrStencilSettings fStencilSettings;
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ private:
|
|||||||
|
|
||||||
const GrPathRange* pathRange() const { return fPathRange.get(); }
|
const GrPathRange* pathRange() const { return fPathRange.get(); }
|
||||||
|
|
||||||
virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
|
void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
|
||||||
|
|
||||||
int fIndicesLocation;
|
int fIndicesLocation;
|
||||||
size_t fCount;
|
size_t fCount;
|
||||||
@ -172,7 +172,7 @@ private:
|
|||||||
|
|
||||||
GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
|
GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
|
||||||
|
|
||||||
virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
|
void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
|
||||||
|
|
||||||
SkIRect fRect;
|
SkIRect fRect;
|
||||||
GrColor fColor;
|
GrColor fColor;
|
||||||
@ -188,7 +188,7 @@ private:
|
|||||||
|
|
||||||
GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
|
GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
|
||||||
|
|
||||||
virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
|
void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
|
||||||
|
|
||||||
SkIRect fRect;
|
SkIRect fRect;
|
||||||
bool fInsideClip;
|
bool fInsideClip;
|
||||||
@ -203,7 +203,7 @@ private:
|
|||||||
GrSurface* dst() const { return fDst.get(); }
|
GrSurface* dst() const { return fDst.get(); }
|
||||||
GrSurface* src() const { return fSrc.get(); }
|
GrSurface* src() const { return fSrc.get(); }
|
||||||
|
|
||||||
virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
|
void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
|
||||||
|
|
||||||
SkIPoint fDstPoint;
|
SkIPoint fDstPoint;
|
||||||
SkIRect fSrcRect;
|
SkIRect fSrcRect;
|
||||||
@ -214,12 +214,15 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct SetState : public Cmd {
|
struct SetState : public Cmd {
|
||||||
SetState(const GrOptDrawState* state) : Cmd(kSetState_Cmd), fState(SkRef(state)) {}
|
SetState(const GrDrawState& drawState, GrGpu* gpu, const ScissorState& scissor,
|
||||||
|
const GrDeviceCoordTexture* dstCopy, GrGpu::DrawType drawType)
|
||||||
|
: Cmd(kSetState_Cmd)
|
||||||
|
, fState(drawState, gpu, scissor, dstCopy, drawType) {}
|
||||||
|
|
||||||
virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
|
void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
|
||||||
|
|
||||||
SkAutoTUnref<const GrOptDrawState> fState;
|
const GrOptDrawState fState;
|
||||||
GrGpu::DrawType fDrawType;
|
GrGpu::DrawType fDrawType;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double.
|
typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double.
|
||||||
@ -310,7 +313,7 @@ private:
|
|||||||
typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateStack;
|
typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateStack;
|
||||||
|
|
||||||
CmdBuffer fCmdBuffer;
|
CmdBuffer fCmdBuffer;
|
||||||
SkAutoTUnref<const GrOptDrawState> fLastState;
|
const GrOptDrawState* fPrevState;
|
||||||
SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers;
|
SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers;
|
||||||
GrGpu* fDstGpu;
|
GrGpu* fDstGpu;
|
||||||
GrVertexBufferAllocPool& fVertexPool;
|
GrVertexBufferAllocPool& fVertexPool;
|
||||||
|
@ -24,7 +24,7 @@ class GrDrawState;
|
|||||||
* Class that holds an optimized version of a GrDrawState. It is meant to be an immutable class,
|
* Class that holds an optimized version of a GrDrawState. It is meant to be an immutable class,
|
||||||
* and contains all data needed to set the state for a gpu draw.
|
* and contains all data needed to set the state for a gpu draw.
|
||||||
*/
|
*/
|
||||||
class GrOptDrawState : public SkRefCnt {
|
class GrOptDrawState {
|
||||||
public:
|
public:
|
||||||
SK_DECLARE_INST_COUNT(GrOptDrawState)
|
SK_DECLARE_INST_COUNT(GrOptDrawState)
|
||||||
|
|
||||||
|
@ -468,12 +468,11 @@ bool GrDrawTarget::programUnitTest(int maxStages) {
|
|||||||
|
|
||||||
// create optimized draw state, setup readDst texture if required, and build a descriptor
|
// create optimized draw state, setup readDst texture if required, and build a descriptor
|
||||||
// and program. ODS creation can fail, so we have to check
|
// and program. ODS creation can fail, so we have to check
|
||||||
SkAutoTUnref<GrOptDrawState> ods
|
GrOptDrawState ods(ds, gpu, scissor, &dstCopy, drawType);
|
||||||
SkNEW_ARGS(GrOptDrawState, (ds, gpu, scissor, &dstCopy, drawType));
|
if (ods.mustSkip()) {
|
||||||
if (ods->mustSkip()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods, drawType, gpu));
|
SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(ods, drawType, gpu));
|
||||||
if (NULL == program.get()) {
|
if (NULL == program.get()) {
|
||||||
SkDebugf("Failed to create program!");
|
SkDebugf("Failed to create program!");
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user