blob: 65b6c4bf7d3ab850f0cb5cf0ce46a4088bfeb369 [file] [log] [blame]
bsalomon53469832015-08-18 09:20:09 -07001/*
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
16class GrDiscardBatch final : public GrBatch {
17public:
reed1b55a962015-09-17 20:16:13 -070018 DEFINE_BATCH_CLASS_ID
19
bsalomon53469832015-08-18 09:20:09 -070020 GrDiscardBatch(GrRenderTarget* rt)
reed1b55a962015-09-17 20:16:13 -070021 : INHERITED(ClassID())
22 , fRenderTarget(rt) {
bsalomon53469832015-08-18 09:20:09 -070023 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(); }
bsalomon6dea83f2015-12-03 12:58:06 -080029 GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); }
bsalomon53469832015-08-18 09:20:09 -070030
Brian Salomon9dc2a9a2015-08-18 12:46:51 -040031 SkString dumpInfo() const override {
bsalomon53469832015-08-18 09:20:09 -070032 SkString string;
robertphillipse004bfc2015-11-16 09:06:59 -080033 string.printf("RT: %d", fRenderTarget.get()->getUniqueID());
bsalomon53469832015-08-18 09:20:09 -070034 return string;
35 }
36
37private:
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;
reed1b55a962015-09-17 20:16:13 -070049
50 typedef GrBatch INHERITED;
bsalomon53469832015-08-18 09:20:09 -070051};
52
53#endif