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 GrClearBatch_DEFINED |
| 9 | #define GrClearBatch_DEFINED |
| 10 | |
| 11 | #include "GrBatch.h" |
| 12 | #include "GrBatchFlushState.h" |
| 13 | #include "GrGpu.h" |
| 14 | #include "GrRenderTarget.h" |
| 15 | |
| 16 | class GrClearBatch 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 | GrClearBatch(const SkIRect& rect, GrColor color, GrRenderTarget* rt) |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 21 | : INHERITED(ClassID()) |
| 22 | , fRect(rect) |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 23 | , fColor(color) |
| 24 | , fRenderTarget(rt) { |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 25 | 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(); } |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 31 | GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); } |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 32 | |
Brian Salomon | 9dc2a9a | 2015-08-18 12:46:51 -0400 | [diff] [blame] | 33 | SkString dumpInfo() const override { |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 34 | SkString string; |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 35 | string.printf("Color: 0x%08x, Rect [L: %d, T: %d, R: %d, B: %d], RT: %d", |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 36 | fColor, fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 37 | fRenderTarget.get()->getUniqueID()); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 38 | return string; |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 43 | // 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 | } |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 56 | 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; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 68 | |
| 69 | typedef GrBatch INHERITED; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 72 | class GrClearStencilClipBatch final : public GrBatch { |
| 73 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 74 | DEFINE_BATCH_CLASS_ID |
| 75 | |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 76 | GrClearStencilClipBatch(const SkIRect& rect, bool insideClip, GrRenderTarget* rt) |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 77 | : INHERITED(ClassID()) |
| 78 | , fRect(rect) |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 79 | , fInsideClip(insideClip) |
| 80 | , fRenderTarget(rt) { |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 81 | 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(); } |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 87 | GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); } |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 88 | |
| 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 | |
| 97 | private: |
| 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; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 109 | |
| 110 | typedef GrBatch INHERITED; |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 113 | #endif |