• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GrDiscardBatch_DEFINED
9 #define GrDiscardBatch_DEFINED
10 
11 #include "GrBatch.h"
12 #include "GrBatchFlushState.h"
13 #include "GrGpu.h"
14 #include "GrRenderTarget.h"
15 
16 class GrDiscardBatch final : public GrBatch {
17 public:
18     DEFINE_BATCH_CLASS_ID
19 
GrDiscardBatch(GrRenderTarget * rt)20     GrDiscardBatch(GrRenderTarget* rt)
21         : INHERITED(ClassID())
22         , fRenderTarget(rt) {
23         fBounds = SkRect::MakeWH(SkIntToScalar(rt->width()), SkIntToScalar(rt->height()));
24     }
25 
name()26     const char* name() const override { return "Discard"; }
27 
renderTargetUniqueID()28     uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); }
renderTarget()29     GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); }
30 
dumpInfo()31     SkString dumpInfo() const override {
32         SkString string;
33         string.printf("RT: %d", fRenderTarget.get()->getUniqueID());
34         return string;
35     }
36 
37 private:
onCombineIfPossible(GrBatch * that,const GrCaps & caps)38     bool onCombineIfPossible(GrBatch* that, const GrCaps& caps) override {
39         return fRenderTarget == that->cast<GrDiscardBatch>()->fRenderTarget;
40     }
41 
onPrepare(GrBatchFlushState *)42     void onPrepare(GrBatchFlushState*) override {}
43 
onDraw(GrBatchFlushState * state)44     void onDraw(GrBatchFlushState* state) override {
45         state->gpu()->discard(fRenderTarget.get());
46     }
47 
48     GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
49 
50     typedef GrBatch INHERITED;
51 };
52 
53 #endif
54