| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "GrStencilAndCoverPathRenderer.h" | 10 #include "GrStencilAndCoverPathRenderer.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrGpu* gpu) { | 27 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrGpu* gpu) { |
| 28 SkASSERT(gpu->caps()->pathStencilingSupport()); | 28 SkASSERT(gpu->caps()->pathStencilingSupport()); |
| 29 fGpu = gpu; | 29 fGpu = gpu; |
| 30 gpu->ref(); | 30 gpu->ref(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 GrStencilAndCoverPathRenderer::~GrStencilAndCoverPathRenderer() { | 33 GrStencilAndCoverPathRenderer::~GrStencilAndCoverPathRenderer() { |
| 34 fGpu->unref(); | 34 fGpu->unref(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool GrStencilAndCoverPathRenderer::canDrawPath(const SkPath& path, | 37 bool GrStencilAndCoverPathRenderer::canDrawPath(const SkStrokeRec& stroke, |
| 38 const SkStrokeRec& stroke, | |
| 39 const GrDrawTarget* target, | 38 const GrDrawTarget* target, |
| 40 bool antiAlias) const { | 39 bool antiAlias) const { |
| 41 return stroke.isFillStyle() && | 40 return stroke.isFillStyle() && |
| 42 !antiAlias && // doesn't do per-path AA, relies on the target having
MSAA | 41 !antiAlias && // doesn't do per-path AA, relies on the target having
MSAA |
| 43 target->getDrawState().getStencil().isDisabled(); | 42 target->getDrawState().getStencil().isDisabled(); |
| 44 } | 43 } |
| 45 | 44 |
| 46 GrPathRenderer::StencilSupport GrStencilAndCoverPathRenderer::onGetStencilSuppor
t( | 45 GrPathRenderer::StencilSupport GrStencilAndCoverPathRenderer::onGetStencilSuppor
t( |
| 47 const SkPath&, | |
| 48 const SkStrokeRec& , | 46 const SkStrokeRec& , |
| 49 const GrDrawTarget*) con
st { | 47 const GrDrawTarget*) con
st { |
| 50 return GrPathRenderer::kStencilOnly_StencilSupport; | 48 return GrPathRenderer::kStencilOnly_StencilSupport; |
| 51 } | 49 } |
| 52 | 50 |
| 53 void GrStencilAndCoverPathRenderer::onStencilPath(const SkPath& path, | 51 void GrStencilAndCoverPathRenderer::onStencilPath(const SkStrokeRec& stroke, |
| 54 const SkStrokeRec& stroke, | |
| 55 GrDrawTarget* target) { | 52 GrDrawTarget* target) { |
| 56 SkASSERT(!path.isInverseFillType()); | 53 SkASSERT(!fPath.isInverseFillType()); |
| 57 SkAutoTUnref<GrPath> p(fGpu->createPath(path)); | 54 SkAutoTUnref<GrPath> p(fGpu->createPath(fPath)); |
| 58 target->stencilPath(p, stroke, path.getFillType()); | 55 target->stencilPath(p, stroke, fPath.getFillType()); |
| 59 } | 56 } |
| 60 | 57 |
| 61 bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path, | 58 bool GrStencilAndCoverPathRenderer::onDrawPath(const SkStrokeRec& stroke, |
| 62 const SkStrokeRec& stroke, | |
| 63 GrDrawTarget* target, | 59 GrDrawTarget* target, |
| 64 bool antiAlias) { | 60 bool antiAlias) { |
| 65 SkASSERT(!antiAlias); | 61 SkASSERT(!antiAlias); |
| 66 SkASSERT(!stroke.isHairlineStyle()); | 62 SkASSERT(!stroke.isHairlineStyle()); |
| 67 | 63 |
| 68 GrDrawState* drawState = target->drawState(); | 64 GrDrawState* drawState = target->drawState(); |
| 69 SkASSERT(drawState->getStencil().isDisabled()); | 65 SkASSERT(drawState->getStencil().isDisabled()); |
| 70 | 66 |
| 71 SkAutoTUnref<GrPath> p(fGpu->createPath(path)); | 67 SkAutoTUnref<GrPath> p(fGpu->createPath(fPath)); |
| 72 | 68 |
| 73 SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(path.
getFillType()); | 69 SkPath::FillType nonInvertedFill = SkPath::ConvertToNonInverseFillType(fPath
.getFillType()); |
| 74 target->stencilPath(p, stroke, nonInvertedFill); | 70 target->stencilPath(p, stroke, nonInvertedFill); |
| 75 | 71 |
| 76 // TODO: Use built in cover operation rather than a rect draw. This will req
uire making our | 72 // TODO: Use built in cover operation rather than a rect draw. This will req
uire making our |
| 77 // fragment shaders be able to eat varyings generated by a matrix. | 73 // fragment shaders be able to eat varyings generated by a matrix. |
| 78 | 74 |
| 79 // fill the path, zero out the stencil | 75 // fill the path, zero out the stencil |
| 80 SkRect bounds = p->getBounds(); | 76 SkRect bounds = p->getBounds(); |
| 81 SkScalar bloat = drawState->getViewMatrix().getMaxStretch() * SK_ScalarHalf; | 77 SkScalar bloat = drawState->getViewMatrix().getMaxStretch() * SK_ScalarHalf; |
| 82 GrDrawState::AutoViewMatrixRestore avmr; | 78 GrDrawState::AutoViewMatrixRestore avmr; |
| 83 | 79 |
| 84 if (nonInvertedFill == path.getFillType()) { | 80 if (nonInvertedFill == fPath.getFillType()) { |
| 85 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, | 81 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, |
| 86 kZero_StencilOp, | 82 kZero_StencilOp, |
| 87 kZero_StencilOp, | 83 kZero_StencilOp, |
| 88 kNotEqual_StencilFunc, | 84 kNotEqual_StencilFunc, |
| 89 0xffff, | 85 0xffff, |
| 90 0x0000, | 86 0x0000, |
| 91 0xffff); | 87 0xffff); |
| 92 *drawState->stencil() = kStencilPass; | 88 *drawState->stencil() = kStencilPass; |
| 93 } else { | 89 } else { |
| 94 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, | 90 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 114 avmr.setIdentity(drawState); | 110 avmr.setIdentity(drawState); |
| 115 bloat = 0; | 111 bloat = 0; |
| 116 } | 112 } |
| 117 *drawState->stencil() = kInvertedStencilPass; | 113 *drawState->stencil() = kInvertedStencilPass; |
| 118 } | 114 } |
| 119 bounds.outset(bloat, bloat); | 115 bounds.outset(bloat, bloat); |
| 120 target->drawSimpleRect(bounds, NULL); | 116 target->drawSimpleRect(bounds, NULL); |
| 121 target->drawState()->stencil()->setDisabled(); | 117 target->drawState()->stencil()->setDisabled(); |
| 122 return true; | 118 return true; |
| 123 } | 119 } |
| OLD | NEW |