robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 GrClearStencilClipBatch_DEFINED |
| 9 | #define GrClearStencilClipBatch_DEFINED |
| 10 | |
| 11 | #include "GrBatch.h" |
| 12 | #include "GrBatchFlushState.h" |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 13 | #include "GrFixedClip.h" |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 14 | #include "GrGpu.h" |
| 15 | #include "GrGpuCommandBuffer.h" |
| 16 | #include "GrRenderTarget.h" |
| 17 | |
| 18 | class GrClearStencilClipBatch final : public GrBatch { |
| 19 | public: |
| 20 | DEFINE_BATCH_CLASS_ID |
| 21 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 22 | GrClearStencilClipBatch(const GrFixedClip& clip, bool insideStencilMask, GrRenderTarget* rt) |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 23 | : INHERITED(ClassID()) |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 24 | , fClip(clip) |
| 25 | , fInsideStencilMask(insideStencilMask) |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 26 | , fRenderTarget(rt) { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 27 | const SkRect& bounds = fClip.scissorEnabled() ? SkRect::Make(fClip.scissorRect()) |
| 28 | : SkRect::MakeIWH(rt->width(), rt->height()); |
| 29 | this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | const char* name() const override { return "ClearStencilClip"; } |
| 33 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame^] | 34 | // TODO: this needs to be updated to return GrSurfaceProxy::UniqueID |
| 35 | GrGpuResource::UniqueID renderTargetUniqueID() const override { |
| 36 | return fRenderTarget.get()->uniqueID(); |
| 37 | } |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 38 | GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); } |
| 39 | |
| 40 | SkString dumpInfo() const override { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 41 | SkString string("Scissor ["); |
| 42 | if (fClip.scissorEnabled()) { |
| 43 | const SkIRect& r = fClip.scissorRect(); |
| 44 | string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 45 | } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame^] | 46 | string.appendf("], IC: %d, RT: %d", fInsideStencilMask, |
| 47 | fRenderTarget.get()->uniqueID().asUInt()); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 48 | string.append(INHERITED::dumpInfo()); |
| 49 | return string; |
| 50 | } |
| 51 | |
| 52 | private: |
| 53 | bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; } |
| 54 | |
| 55 | void onPrepare(GrBatchFlushState*) override {} |
| 56 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 57 | void onDraw(GrBatchFlushState* state, const SkRect& /*bounds*/) override { |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 58 | state->commandBuffer()->clearStencilClip(fClip, fInsideStencilMask); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 59 | } |
| 60 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 61 | const GrFixedClip fClip; |
| 62 | const bool fInsideStencilMask; |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 63 | GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
| 64 | |
| 65 | typedef GrBatch INHERITED; |
| 66 | }; |
| 67 | |
| 68 | #endif |