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
This commit is contained in:
bsalomon 2016-08-10 16:31:05 -07:00 committed by Commit bot
parent 0cbe77c383
commit 9f129de595
3 changed files with 19 additions and 0 deletions

View File

@ -203,10 +203,12 @@ void GrDrawContext::clear(const SkIRect* rect,
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 @@ void GrDrawContext::clear(const SkIRect* rect,
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));

View File

@ -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 @@ void GrDrawTarget::addBatch(sk_sp<GrBatch> batch) {
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());

View File

@ -121,6 +121,9 @@ public:
const SkMatrix& viewMatrix,
const GrPath*);
/** Clears the entire render target */
void fullClear(GrRenderTarget*, GrColor color);
/** Discards the contents render target. */
void discard(GrRenderTarget*);