bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #include "GrStencilAndCoverPathRenderer.h" |
| 11 | #include "GrContext.h" |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 12 | #include "GrDrawTargetCaps.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 13 | #include "GrGpu.h" |
| 14 | #include "GrPath.h" |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 15 | #include "SkStrokeRec.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 16 | |
| 17 | GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrContext* context) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 18 | SkASSERT(NULL != context); |
| 19 | SkASSERT(NULL != context->getGpu()); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 20 | if (context->getGpu()->caps()->pathRenderingSupport()) { |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 21 | return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (context->getGpu())); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 22 | } else { |
| 23 | return NULL; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrGpu* gpu) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 28 | SkASSERT(gpu->caps()->pathRenderingSupport()); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 29 | fGpu = gpu; |
| 30 | gpu->ref(); |
| 31 | } |
| 32 | |
| 33 | GrStencilAndCoverPathRenderer::~GrStencilAndCoverPathRenderer() { |
| 34 | fGpu->unref(); |
| 35 | } |
| 36 | |
| 37 | bool GrStencilAndCoverPathRenderer::canDrawPath(const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 38 | const SkStrokeRec& stroke, |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 39 | const GrDrawTarget* target, |
| 40 | bool antiAlias) const { |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 41 | return !stroke.isHairlineStyle() && |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 42 | !antiAlias && // doesn't do per-path AA, relies on the target having MSAA |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 43 | NULL != target->getDrawState().getRenderTarget()->getStencilBuffer() && |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 44 | target->getDrawState().getStencil().isDisabled(); |
| 45 | } |
| 46 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 47 | GrPathRenderer::StencilSupport GrStencilAndCoverPathRenderer::onGetStencilSupport( |
| 48 | const SkPath&, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 49 | const SkStrokeRec& , |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 50 | const GrDrawTarget*) const { |
| 51 | return GrPathRenderer::kStencilOnly_StencilSupport; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 52 | } |
| 53 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 54 | void GrStencilAndCoverPathRenderer::onStencilPath(const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 55 | const SkStrokeRec& stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 56 | GrDrawTarget* target) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 57 | SkASSERT(!path.isInverseFillType()); |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 58 | SkAutoTUnref<GrPath> p(fGpu->createPath(path, stroke)); |
| 59 | target->stencilPath(p, path.getFillType()); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 63 | const SkStrokeRec& stroke, |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 64 | GrDrawTarget* target, |
bsalomon@google.com | 0f11e1a | 2012-10-08 14:48:36 +0000 | [diff] [blame] | 65 | bool antiAlias) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 66 | SkASSERT(!antiAlias); |
| 67 | SkASSERT(!stroke.isHairlineStyle()); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 68 | |
| 69 | GrDrawState* drawState = target->drawState(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 70 | SkASSERT(drawState->getStencil().isDisabled()); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 71 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 72 | SkAutoTUnref<GrPath> p(fGpu->createPath(path, stroke)); |
bsalomon@google.com | 0f11e1a | 2012-10-08 14:48:36 +0000 | [diff] [blame] | 73 | |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 74 | if (path.isInverseFillType()) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 75 | GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, |
| 76 | kZero_StencilOp, |
| 77 | kZero_StencilOp, |
bsalomon@google.com | 05a718c | 2012-06-29 14:01:53 +0000 | [diff] [blame] | 78 | // We know our rect will hit pixels outside the clip and the user bits will be 0 |
| 79 | // outside the clip. So we can't just fill where the user bits are 0. We also need to |
| 80 | // check that the clip bit is set. |
| 81 | kEqualIfInClip_StencilFunc, |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 82 | 0xffff, |
| 83 | 0x0000, |
| 84 | 0xffff); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 85 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 86 | *drawState->stencil() = kInvertedStencilPass; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 87 | } else { |
| 88 | GR_STATIC_CONST_SAME_STENCIL(kStencilPass, |
| 89 | kZero_StencilOp, |
| 90 | kZero_StencilOp, |
| 91 | kNotEqual_StencilFunc, |
| 92 | 0xffff, |
| 93 | 0x0000, |
| 94 | 0xffff); |
| 95 | |
| 96 | *drawState->stencil() = kStencilPass; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 97 | } |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 98 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 99 | target->drawPath(p, path.getFillType()); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 100 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 101 | target->drawState()->stencil()->setDisabled(); |
| 102 | return true; |
| 103 | } |