Add a full clear method to GrDrawTarget.
This will allow us to avoid ClearBatch creation for successive clears.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2233043002
Review-Url: https://codereview.chromium.org/2233043002
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index 344ae1c..0a6ab5b 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -203,10 +203,12 @@
const SkIRect rtRect = SkIRect::MakeWH(this->width(), this->height());
SkIRect clippedRect;
+ bool isFull = false;
if (!rect ||
(canIgnoreRect && fContext->caps()->fullClearIsFree()) ||
rect->contains(rtRect)) {
rect = &rtRect;
+ isFull = true;
} else {
clippedRect = *rect;
if (!clippedRect.intersect(rtRect)) {
@@ -228,6 +230,8 @@
paint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode));
this->drawRect(GrNoClip(), paint, SkMatrix::I(), SkRect::Make(*rect));
+ } else if (isFull) {
+ this->getDrawTarget()->fullClear(this->accessRenderTarget(), color);
} else {
sk_sp<GrBatch> batch = GrClearBatch::Make(*rect, color, this->accessRenderTarget());
this->getDrawTarget()->addBatch(std::move(batch));
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 4ab467c..c424f5a 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -26,6 +26,7 @@
#include "SkStrokeRec.h"
+#include "batches/GrClearBatch.h"
#include "batches/GrClearStencilClipBatch.h"
#include "batches/GrCopySurfaceBatch.h"
#include "batches/GrDiscardBatch.h"
@@ -456,7 +457,18 @@
this->recordBatch(batch.get(), batch->bounds());
}
+void GrDrawTarget::fullClear(GrRenderTarget* renderTarget, GrColor color) {
+ // Currently this just inserts a clear batch. However, once in MDB this can remove all the
+ // previously recorded batches and change the load op to clear with supplied color.
+ sk_sp<GrBatch> batch = GrClearBatch::Make(SkIRect::MakeWH(renderTarget->width(),
+ renderTarget->height()),
+ color, renderTarget);
+ this->recordBatch(batch.get(), batch->bounds());
+}
+
void GrDrawTarget::discard(GrRenderTarget* renderTarget) {
+ // Currently this just inserts a discard batch. However, once in MDB this can remove all the
+ // previously recorded batches and change the load op to discard.
if (this->caps()->discardRenderTargetSupport()) {
GrBatch* batch = new GrDiscardBatch(renderTarget);
this->recordBatch(batch, batch->bounds());
diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h
index 6149e92..60a1ec9 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -121,6 +121,9 @@
const SkMatrix& viewMatrix,
const GrPath*);
+ /** Clears the entire render target */
+ void fullClear(GrRenderTarget*, GrColor color);
+
/** Discards the contents render target. */
void discard(GrRenderTarget*);