1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef GrDiscardOp_DEFINED
9 #define GrDiscardOp_DEFINED
10 
11 #include "GrGpu.h"
12 #include "GrOp.h"
13 #include "GrOpFlushState.h"
14 #include "GrRenderTarget.h"
15 
16 class GrDiscardOp final : public GrOp {
17 public:
18     DEFINE_OP_CLASS_ID
Make(GrRenderTarget * rt)19     static std::unique_ptr<GrOp> Make(GrRenderTarget* rt) {
20         return std::unique_ptr<GrOp>(new GrDiscardOp(rt));
21     }
22 
name()23     const char* name() const override { return "Discard"; }
24 
dumpInfo()25     SkString dumpInfo() const override {
26         SkString string;
27         string.printf("RT: %d", fRenderTarget.get()->uniqueID().asUInt());
28         string.append(INHERITED::dumpInfo());
29         return string;
30     }
31 
32 private:
GrDiscardOp(GrRenderTarget * rt)33     GrDiscardOp(GrRenderTarget* rt) : INHERITED(ClassID()), fRenderTarget(rt) {
34         this->setBounds(SkRect::MakeIWH(rt->width(), rt->height()), HasAABloat::kNo,
35                         IsZeroArea::kNo);
36     }
37 
onCombineIfPossible(GrOp * that,const GrCaps & caps)38     bool onCombineIfPossible(GrOp* that, const GrCaps& caps) override {
39         return fRenderTarget.get() == that->cast<GrDiscardOp>()->fRenderTarget.get();
40     }
41 
onPrepare(GrOpFlushState *)42     void onPrepare(GrOpFlushState*) override {}
43 
onExecute(GrOpFlushState * state)44     void onExecute(GrOpFlushState* state) override {
45         state->commandBuffer()->discard(fRenderTarget.get());
46     }
47 
48     GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
49 
50     typedef GrOp INHERITED;
51 };
52 
53 #endif
54