diff options
author | 2016-08-31 11:55:52 -0700 | |
---|---|---|
committer | 2016-08-31 11:55:52 -0700 | |
commit | 29df76096fd30941086324902a82656df2d8becd (patch) | |
tree | 37740539e50fcdc09d694bc39e98e55aa26cf3f4 /src/gpu/batches/GrClearBatch.h | |
parent | dc43898bbbd06202562514ae785116e0cc40f825 (diff) |
Define clear regions in terms of GrFixedClip
Updates clear APIs to take GrFixedClip instead of a rectangle. This
will allow us to use window rectangles with clears. Removes stencil
knobs from GrFixedClip.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2262473003
Review-Url: https://codereview.chromium.org/2262473003
Diffstat (limited to 'src/gpu/batches/GrClearBatch.h')
-rw-r--r-- | src/gpu/batches/GrClearBatch.h | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/src/gpu/batches/GrClearBatch.h b/src/gpu/batches/GrClearBatch.h index 8ebf85af2e..7d84bc3859 100644 --- a/src/gpu/batches/GrClearBatch.h +++ b/src/gpu/batches/GrClearBatch.h @@ -10,6 +10,7 @@ #include "GrBatch.h" #include "GrBatchFlushState.h" +#include "GrFixedClip.h" #include "GrGpu.h" #include "GrGpuCommandBuffer.h" #include "GrRenderTarget.h" @@ -18,8 +19,12 @@ class GrClearBatch final : public GrBatch { public: DEFINE_BATCH_CLASS_ID - static sk_sp<GrClearBatch> Make(const SkIRect& rect, GrColor color, GrRenderTarget* rt) { - return sk_sp<GrClearBatch>(new GrClearBatch(rect, color, rt)); + static sk_sp<GrClearBatch> Make(const GrFixedClip& clip, GrColor color, GrRenderTarget* rt) { + sk_sp<GrClearBatch> batch(new GrClearBatch(clip, color, rt)); + if (!batch->renderTarget()) { + return nullptr; // The clip did not contain any pixels within the render target. + } + return batch; } const char* name() const override { return "Clear"; } @@ -28,10 +33,12 @@ public: GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); } SkString dumpInfo() const override { - SkString string; - string.printf("Color: 0x%08x, Rect [L: %d, T: %d, R: %d, B: %d], RT: %d", - fColor, fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, - fRenderTarget.get()->getUniqueID()); + SkString string("Scissor ["); + if (fClip.scissorEnabled()) { + const SkIRect& r = fClip.scissorRect(); + string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom); + } + string.appendf("], Color: 0x%08x, RT: %d", fColor, fRenderTarget.get()->getUniqueID()); string.append(INHERITED::dumpInfo()); return string; } @@ -39,12 +46,23 @@ public: void setColor(GrColor color) { fColor = color; } private: - GrClearBatch(const SkIRect& rect, GrColor color, GrRenderTarget* rt) + GrClearBatch(const GrFixedClip& clip, GrColor color, GrRenderTarget* rt) : INHERITED(ClassID()) - , fRect(rect) - , fColor(color) - , fRenderTarget(rt) { - this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsZeroArea::kNo); + , fClip(clip) + , fColor(color) { + SkIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height()); + if (fClip.scissorEnabled()) { + // Don't let scissors extend outside the RT. This may improve batching. + if (!fClip.intersect(rtRect)) { + return; + } + if (fClip.scissorRect() == rtRect) { + fClip.disableScissor(); + } + } + this->setBounds(SkRect::Make(fClip.scissorEnabled() ? fClip.scissorRect() : rtRect), + HasAABloat::kNo, IsZeroArea::kNo); + fRenderTarget.reset(rt); } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { @@ -53,24 +71,31 @@ private: // same color. GrClearBatch* cb = t->cast<GrClearBatch>(); SkASSERT(cb->fRenderTarget == fRenderTarget); - if (cb->fRect.contains(fRect)) { - fRect = cb->fRect; + if (cb->contains(this)) { + fClip = cb->fClip; this->replaceBounds(*t); fColor = cb->fColor; return true; - } else if (cb->fColor == fColor && fRect.contains(cb->fRect)) { + } else if (cb->fColor == fColor && this->contains(cb)) { return true; } return false; } + bool contains(const GrClearBatch* that) const { + // The constructor ensures that scissor gets disabled on any clip that fills the entire RT. + return !fClip.scissorEnabled() || + (that->fClip.scissorEnabled() && + fClip.scissorRect().contains(that->fClip.scissorRect())); + } + void onPrepare(GrBatchFlushState*) override {} void onDraw(GrBatchFlushState* state) override { - state->commandBuffer()->clear(fRect, fColor, fRenderTarget.get()); + state->commandBuffer()->clear(fClip, fColor, fRenderTarget.get()); } - SkIRect fRect; + GrFixedClip fClip; GrColor fColor; GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |