blob: b97879097c01c1851f94924dbdf88d12013d106a [file] [log] [blame]
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrDiscardOp_DEFINED
#define GrDiscardOp_DEFINED
#include "GrGpu.h"
#include "GrOp.h"
#include "GrOpFlushState.h"
#include "GrRenderTarget.h"
class GrDiscardOp final : public GrOp {
public:
DEFINE_OP_CLASS_ID
static sk_sp<GrOp> Make(GrRenderTarget* rt) { return sk_sp<GrOp>(new GrDiscardOp(rt)); }
const char* name() const override { return "Discard"; }
// TODO: this needs to be updated to return GrSurfaceProxy::UniqueID
GrGpuResource::UniqueID renderTargetUniqueID() const override {
return fRenderTarget.get()->uniqueID();
}
SkString dumpInfo() const override {
SkString string;
string.printf("RT: %d", fRenderTarget.get()->uniqueID().asUInt());
string.append(INHERITED::dumpInfo());
return string;
}
private:
GrDiscardOp(GrRenderTarget* rt) : INHERITED(ClassID()), fRenderTarget(rt) {
this->setBounds(SkRect::MakeIWH(rt->width(), rt->height()), HasAABloat::kNo,
IsZeroArea::kNo);
}
bool onCombineIfPossible(GrOp* that, const GrCaps& caps) override {
return this->renderTargetUniqueID() == that->renderTargetUniqueID();
}
void onPrepare(GrOpFlushState*) override {}
void onDraw(GrOpFlushState* state, const SkRect& /*bounds*/) override {
state->commandBuffer()->discard(fRenderTarget.get());
}
GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
typedef GrOp INHERITED;
};
#endif