blob: ba4b6d6daeabe94baa4ca052a3247026de9d0094 [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 GrClearBatch_DEFINED
9#define GrClearBatch_DEFINED
10
11#include "GrBatch.h"
12#include "GrBatchFlushState.h"
13#include "GrGpu.h"
14#include "GrRenderTarget.h"
15
16class GrClearBatch final : public GrBatch {
17public:
reed1b55a962015-09-17 20:16:13 -070018 DEFINE_BATCH_CLASS_ID
19
bsalomon53469832015-08-18 09:20:09 -070020 GrClearBatch(const SkIRect& rect, GrColor color, GrRenderTarget* rt)
reed1b55a962015-09-17 20:16:13 -070021 : INHERITED(ClassID())
22 , fRect(rect)
bsalomon53469832015-08-18 09:20:09 -070023 , fColor(color)
24 , fRenderTarget(rt) {
bsalomon53469832015-08-18 09:20:09 -070025 fBounds = SkRect::Make(rect);
26 }
27
28 const char* name() const override { return "Clear"; }
29
30 uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); }
bsalomon6dea83f2015-12-03 12:58:06 -080031 GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); }
bsalomon53469832015-08-18 09:20:09 -070032
Brian Salomon9dc2a9a2015-08-18 12:46:51 -040033 SkString dumpInfo() const override {
bsalomon53469832015-08-18 09:20:09 -070034 SkString string;
robertphillipse004bfc2015-11-16 09:06:59 -080035 string.printf("Color: 0x%08x, Rect [L: %d, T: %d, R: %d, B: %d], RT: %d",
bsalomon53469832015-08-18 09:20:09 -070036 fColor, fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom,
robertphillipse004bfc2015-11-16 09:06:59 -080037 fRenderTarget.get()->getUniqueID());
bsalomon53469832015-08-18 09:20:09 -070038 return string;
39 }
40
41private:
42 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
bsalomone63ffef2016-02-05 07:17:34 -080043 // This could be much more complicated. Currently we look at cases where the new clear
44 // contains the old clear, or when the new clear is a subset of the old clear and is the
45 // same color.
46 GrClearBatch* cb = t->cast<GrClearBatch>();
47 SkASSERT(cb->fRenderTarget == fRenderTarget);
48 if (cb->fRect.contains(fRect)) {
49 fRect = cb->fRect;
50 fBounds = cb->fBounds;
51 fColor = cb->fColor;
52 return true;
53 } else if (cb->fColor == fColor && fRect.contains(cb->fRect)) {
54 return true;
55 }
bsalomon53469832015-08-18 09:20:09 -070056 return false;
57 }
58
59 void onPrepare(GrBatchFlushState*) override {}
60
61 void onDraw(GrBatchFlushState* state) override {
62 state->gpu()->clear(fRect, fColor, fRenderTarget.get());
63 }
64
65 SkIRect fRect;
66 GrColor fColor;
67 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
reed1b55a962015-09-17 20:16:13 -070068
69 typedef GrBatch INHERITED;
bsalomon53469832015-08-18 09:20:09 -070070};
71
bsalomon5ea03632015-08-18 10:33:30 -070072class GrClearStencilClipBatch final : public GrBatch {
73public:
reed1b55a962015-09-17 20:16:13 -070074 DEFINE_BATCH_CLASS_ID
75
bsalomon5ea03632015-08-18 10:33:30 -070076 GrClearStencilClipBatch(const SkIRect& rect, bool insideClip, GrRenderTarget* rt)
reed1b55a962015-09-17 20:16:13 -070077 : INHERITED(ClassID())
78 , fRect(rect)
bsalomon5ea03632015-08-18 10:33:30 -070079 , fInsideClip(insideClip)
80 , fRenderTarget(rt) {
bsalomon5ea03632015-08-18 10:33:30 -070081 fBounds = SkRect::Make(rect);
82 }
83
84 const char* name() const override { return "ClearStencilClip"; }
85
86 uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); }
bsalomon6dea83f2015-12-03 12:58:06 -080087 GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); }
bsalomon5ea03632015-08-18 10:33:30 -070088
89 SkString dumpInfo() const override {
90 SkString string;
91 string.printf("Rect [L: %d, T: %d, R: %d, B: %d], IC: %d, RT: 0x%p",
92 fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, fInsideClip,
93 fRenderTarget.get());
94 return string;
95 }
96
97private:
98 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; }
99
100 void onPrepare(GrBatchFlushState*) override {}
101
102 void onDraw(GrBatchFlushState* state) override {
103 state->gpu()->clearStencilClip(fRect, fInsideClip, fRenderTarget.get());
104 }
105
106 SkIRect fRect;
107 bool fInsideClip;
108 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
reed1b55a962015-09-17 20:16:13 -0700109
110 typedef GrBatch INHERITED;
bsalomon5ea03632015-08-18 10:33:30 -0700111};
112
bsalomon53469832015-08-18 09:20:09 -0700113#endif