bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 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: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 18 | DEFINE_BATCH_CLASS_ID |
| 19 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 20 | GrDiscardBatch(GrRenderTarget* rt) |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 21 | : INHERITED(ClassID()) |
| 22 | , fRenderTarget(rt) { |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 23 | fBounds = SkRect::MakeWH(SkIntToScalar(rt->width()), SkIntToScalar(rt->height())); |
| 24 | } |
| 25 | |
| 26 | const char* name() const override { return "Discard"; } |
| 27 | |
| 28 | uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); } |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 29 | GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); } |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 30 | |
Brian Salomon | 9dc2a9a | 2015-08-18 12:46:51 -0400 | [diff] [blame] | 31 | SkString dumpInfo() const override { |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 32 | SkString string; |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 33 | string.printf("RT: %d", fRenderTarget.get()->getUniqueID()); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 34 | return string; |
| 35 | } |
| 36 | |
| 37 | private: |
| 38 | bool onCombineIfPossible(GrBatch* that, const GrCaps& caps) override { |
| 39 | return fRenderTarget == that->cast<GrDiscardBatch>()->fRenderTarget; |
| 40 | } |
| 41 | |
| 42 | void onPrepare(GrBatchFlushState*) override {} |
| 43 | |
| 44 | void onDraw(GrBatchFlushState* state) override { |
| 45 | state->gpu()->discard(fRenderTarget.get()); |
| 46 | } |
| 47 | |
| 48 | GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 49 | |
| 50 | typedef GrBatch INHERITED; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | #endif |