blob: b973dab5579e5c5c096044b4416f1e66afe95f61 [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(); }
31
Brian Salomon9dc2a9a2015-08-18 12:46:51 -040032 SkString dumpInfo() const override {
bsalomon53469832015-08-18 09:20:09 -070033 SkString string;
34 string.printf("Color: 0x%08x, Rect [L: %d, T: %d, R: %d, B: %d], RT: 0x%p",
35 fColor, fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom,
36 fRenderTarget.get());
37 return string;
38 }
39
40private:
41 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
42 // We could combine clears. TBD how much complexity to put here.
43 return false;
44 }
45
46 void onPrepare(GrBatchFlushState*) override {}
47
48 void onDraw(GrBatchFlushState* state) override {
49 state->gpu()->clear(fRect, fColor, fRenderTarget.get());
50 }
51
52 SkIRect fRect;
53 GrColor fColor;
54 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
reed1b55a962015-09-17 20:16:13 -070055
56 typedef GrBatch INHERITED;
bsalomon53469832015-08-18 09:20:09 -070057};
58
bsalomon5ea03632015-08-18 10:33:30 -070059class GrClearStencilClipBatch final : public GrBatch {
60public:
reed1b55a962015-09-17 20:16:13 -070061 DEFINE_BATCH_CLASS_ID
62
bsalomon5ea03632015-08-18 10:33:30 -070063 GrClearStencilClipBatch(const SkIRect& rect, bool insideClip, GrRenderTarget* rt)
reed1b55a962015-09-17 20:16:13 -070064 : INHERITED(ClassID())
65 , fRect(rect)
bsalomon5ea03632015-08-18 10:33:30 -070066 , fInsideClip(insideClip)
67 , fRenderTarget(rt) {
bsalomon5ea03632015-08-18 10:33:30 -070068 fBounds = SkRect::Make(rect);
69 }
70
71 const char* name() const override { return "ClearStencilClip"; }
72
73 uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); }
74
75 SkString dumpInfo() const override {
76 SkString string;
77 string.printf("Rect [L: %d, T: %d, R: %d, B: %d], IC: %d, RT: 0x%p",
78 fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, fInsideClip,
79 fRenderTarget.get());
80 return string;
81 }
82
83private:
84 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; }
85
86 void onPrepare(GrBatchFlushState*) override {}
87
88 void onDraw(GrBatchFlushState* state) override {
89 state->gpu()->clearStencilClip(fRect, fInsideClip, fRenderTarget.get());
90 }
91
92 SkIRect fRect;
93 bool fInsideClip;
94 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
reed1b55a962015-09-17 20:16:13 -070095
96 typedef GrBatch INHERITED;
bsalomon5ea03632015-08-18 10:33:30 -070097};
98
bsalomon53469832015-08-18 09:20:09 -070099#endif