bsalomon | a44919e | 2015-08-18 13:28:19 -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 GrStencilPathBatch_DEFINED |
| 9 | #define GrStencilPathBatch_DEFINED |
| 10 | |
| 11 | #include "GrBatch.h" |
| 12 | #include "GrBatchFlushState.h" |
| 13 | #include "GrGpu.h" |
| 14 | #include "GrPath.h" |
| 15 | #include "GrPathRendering.h" |
| 16 | #include "GrRenderTarget.h" |
| 17 | |
| 18 | class GrStencilPathBatch final : public GrBatch { |
| 19 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 20 | DEFINE_BATCH_CLASS_ID |
| 21 | |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 22 | static GrBatch* Create(const SkMatrix& viewMatrix, |
| 23 | bool useHWAA, |
| 24 | const GrStencilSettings& stencil, |
| 25 | const GrScissorState& scissor, |
| 26 | GrRenderTarget* renderTarget, |
| 27 | const GrPath* path) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 28 | return new GrStencilPathBatch(viewMatrix, useHWAA, stencil, scissor, renderTarget, path); |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | const char* name() const override { return "StencilPath"; } |
| 32 | |
mtklein | a4c3244 | 2015-08-19 07:11:34 -0700 | [diff] [blame] | 33 | uint32_t renderTargetUniqueID() const override { return fRenderTarget.get()->getUniqueID(); } |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 34 | GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); } |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 35 | |
| 36 | SkString dumpInfo() const override { |
| 37 | SkString string; |
| 38 | string.printf("PATH: 0x%p, AA:%d", fPath.get(), fUseHWAA); |
| 39 | return string; |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | GrStencilPathBatch(const SkMatrix& viewMatrix, |
| 44 | bool useHWAA, |
| 45 | const GrStencilSettings& stencil, |
| 46 | const GrScissorState& scissor, |
| 47 | GrRenderTarget* renderTarget, |
| 48 | const GrPath* path) |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 49 | : INHERITED(ClassID()) |
| 50 | , fViewMatrix(viewMatrix) |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 51 | , fUseHWAA(useHWAA) |
| 52 | , fStencil(stencil) |
| 53 | , fScissor(scissor) |
| 54 | , fRenderTarget(renderTarget) |
Brian Salomon | 6458b6f | 2015-08-19 09:44:48 -0400 | [diff] [blame] | 55 | , fPath(path) { |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 56 | fBounds = path->getBounds(); |
Brian Salomon | 6458b6f | 2015-08-19 09:44:48 -0400 | [diff] [blame] | 57 | } |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 58 | |
| 59 | bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; } |
| 60 | |
| 61 | void onPrepare(GrBatchFlushState*) override {} |
| 62 | |
| 63 | void onDraw(GrBatchFlushState* state) override { |
| 64 | GrPathRendering::StencilPathArgs args(fUseHWAA, fRenderTarget.get(), &fViewMatrix, |
| 65 | &fScissor, &fStencil); |
| 66 | state->gpu()->pathRendering()->stencilPath(args, fPath.get()); |
| 67 | } |
| 68 | |
| 69 | SkMatrix fViewMatrix; |
| 70 | bool fUseHWAA; |
| 71 | GrStencilSettings fStencil; |
| 72 | GrScissorState fScissor; |
| 73 | GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
| 74 | GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 75 | |
| 76 | typedef GrBatch INHERITED; |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | #endif |