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(); } |
| 31 | |
Brian Salomon | 9dc2a9a | 2015-08-18 12:46:51 -0400 | [diff] [blame] | 32 | SkString dumpInfo() const override { |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 33 | 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 | |
| 40 | private: |
| 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; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame^] | 55 | |
| 56 | typedef GrBatch INHERITED; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 59 | class GrClearStencilClipBatch final : public GrBatch { |
| 60 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame^] | 61 | DEFINE_BATCH_CLASS_ID |
| 62 | |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 63 | GrClearStencilClipBatch(const SkIRect& rect, bool insideClip, GrRenderTarget* rt) |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame^] | 64 | : INHERITED(ClassID()) |
| 65 | , fRect(rect) |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 66 | , fInsideClip(insideClip) |
| 67 | , fRenderTarget(rt) { |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 68 | 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 | |
| 83 | private: |
| 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; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame^] | 95 | |
| 96 | typedef GrBatch INHERITED; |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 99 | #endif |