diff --git a/src/gpu/GrCommandBuilder.cpp b/src/gpu/GrCommandBuilder.cpp index b3f6d7185b..6b56dea421 100644 --- a/src/gpu/GrCommandBuilder.cpp +++ b/src/gpu/GrCommandBuilder.cpp @@ -32,6 +32,11 @@ GrTargetCommands::Cmd* GrCommandBuilder::recordClear(const SkIRect* rect, r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); rect = &r; } + + SkASSERT(color == GrColor_ILLEGAL || + canIgnoreRect || + (rect->fLeft <= rect->fRight && rect->fTop <= rect->fBottom)); + Clear* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), Clear, (renderTarget)); GrColorIsPMAssert(color); clr->fColor = color; diff --git a/src/gpu/GrReorderCommandBuilder.cpp b/src/gpu/GrReorderCommandBuilder.cpp index 14279de824..e373381cb2 100644 --- a/src/gpu/GrReorderCommandBuilder.cpp +++ b/src/gpu/GrReorderCommandBuilder.cpp @@ -7,7 +7,8 @@ #include "GrReorderCommandBuilder.h" -static bool intersect(const SkRect& a, const SkRect& b) { +template +static bool intersect(const Left& a, const Right& b) { SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && b.fLeft <= b.fRight && b.fTop <= b.fBottom); return a.fLeft < b.fRight && b.fLeft < a.fRight && @@ -37,6 +38,16 @@ GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(State* state, Gr if (intersect(previous->fBatch->bounds(), batch->bounds())) { break; } + } else if (Cmd::kClear_CmdType == reverseIter->type()) { + Clear* previous = static_cast(reverseIter.get()); + + // We set the color to illegal if we are doing a discard. + // If we can ignore the rect, then we do a full clear + if (previous->fColor == GrColor_ILLEGAL || + previous->fCanIgnoreRect || + intersect(batch->bounds(), previous->fRect)) { + break; + } } else { // TODO temporary until we can navigate the other types of commands break; diff --git a/src/gpu/GrTargetCommands.h b/src/gpu/GrTargetCommands.h index 2f9909bb02..e5f3cd5a11 100644 --- a/src/gpu/GrTargetCommands.h +++ b/src/gpu/GrTargetCommands.h @@ -35,11 +35,12 @@ public: kStencilPath_CmdType = 1, kSetState_CmdType = 2, kClear_CmdType = 3, - kCopySurface_CmdType = 4, - kDrawPath_CmdType = 5, - kDrawPaths_CmdType = 6, - kDrawBatch_CmdType = 7, - kXferBarrier_CmdType = 8, + kClearStencil_CmdType = 4, + kCopySurface_CmdType = 5, + kDrawPath_CmdType = 6, + kDrawPaths_CmdType = 7, + kDrawBatch_CmdType = 8, + kXferBarrier_CmdType = 9, }; Cmd(CmdType type) : fMarkerID(-1), fType(type) {} @@ -190,7 +191,7 @@ private: // This command is ONLY used by the clip mask manager to clear the stencil clip bits struct ClearStencilClip : public Cmd { - ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_CmdType), fRenderTarget(rt) {} + ClearStencilClip(GrRenderTarget* rt) : Cmd(kClearStencil_CmdType), fRenderTarget(rt) {} GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }