Chromium Code Reviews| 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" |
| 11 #include "GrContext.h" | 11 #include "GrContext.h" |
| 12 #include "GrDrawTargetCaps.h" | 12 #include "GrDrawTargetCaps.h" |
| 13 #include "GrGpu.h" | 13 #include "GrGpu.h" |
| 14 #include "GrPath.h" | 14 #include "GrPath.h" |
| 15 #include "SkStrokeRec.h" | 15 #include "SkStrokeRec.h" |
| 16 | 16 |
| 17 /* | |
| 18 * For now paths only natively support winding and even odd fill types | |
| 19 */ | |
| 20 static GrPathRendering::FillType convert_skpath_filltype(SkPath::FillType fill) { | |
| 21 switch (fill) { | |
| 22 default: | |
| 23 SkFAIL("Incomplete Switch\n"); | |
| 24 case SkPath::kWinding_FillType: | |
| 25 case SkPath::kInverseWinding_FillType: | |
| 26 return GrPathRendering::kWinding_FillType; | |
| 27 case SkPath::kEvenOdd_FillType: | |
| 28 case SkPath::kInverseEvenOdd_FillType: | |
| 29 return GrPathRendering::kEvenOdd_FillType; | |
| 30 } | |
| 31 } | |
| 32 | |
| 17 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrContext* context) { | 33 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrContext* context) { |
| 18 SkASSERT(context); | 34 SkASSERT(context); |
| 19 SkASSERT(context->getGpu()); | 35 SkASSERT(context->getGpu()); |
| 20 if (context->getGpu()->caps()->pathRenderingSupport()) { | 36 if (context->getGpu()->caps()->pathRenderingSupport()) { |
| 21 return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (context->getGpu())); | 37 return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (context->getGpu())); |
| 22 } else { | 38 } else { |
| 23 return NULL; | 39 return NULL; |
| 24 } | 40 } |
| 25 } | 41 } |
| 26 | 42 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 37 bool GrStencilAndCoverPathRenderer::canDrawPath(const SkPath& path, | 53 bool GrStencilAndCoverPathRenderer::canDrawPath(const SkPath& path, |
| 38 const SkStrokeRec& stroke, | 54 const SkStrokeRec& stroke, |
| 39 const GrDrawTarget* target, | 55 const GrDrawTarget* target, |
| 40 bool antiAlias) const { | 56 bool antiAlias) const { |
| 41 return !stroke.isHairlineStyle() && | 57 return !stroke.isHairlineStyle() && |
| 42 !antiAlias && // doesn't do per-path AA, relies on the target having MSAA | 58 !antiAlias && // doesn't do per-path AA, relies on the target having MSAA |
| 43 target->getDrawState().getRenderTarget()->getStencilBuffer() && | 59 target->getDrawState().getRenderTarget()->getStencilBuffer() && |
| 44 target->getDrawState().getStencil().isDisabled(); | 60 target->getDrawState().getStencil().isDisabled(); |
| 45 } | 61 } |
| 46 | 62 |
| 47 GrPathRenderer::StencilSupport GrStencilAndCoverPathRenderer::onGetStencilSuppor t( | 63 GrPathRenderer::StencilSupport |
| 48 const SkPath&, | 64 GrStencilAndCoverPathRenderer::onGetStencilSupport(const SkPath&, |
| 49 const SkStrokeRec& , | 65 const SkStrokeRec& , |
| 50 const GrDrawTarget*) con st { | 66 const GrDrawTarget*) const { |
| 51 return GrPathRenderer::kStencilOnly_StencilSupport; | 67 return GrPathRenderer::kStencilOnly_StencilSupport; |
| 52 } | 68 } |
| 53 | 69 |
| 54 static GrPath* get_gr_path(GrGpu* gpu, const SkPath& skPath, const SkStrokeRec& stroke) { | 70 static GrPath* get_gr_path(GrGpu* gpu, const SkPath& skPath, const SkStrokeRec& stroke) { |
| 55 GrContext* ctx = gpu->getContext(); | 71 GrContext* ctx = gpu->getContext(); |
| 56 GrResourceKey resourceKey = GrPath::ComputeKey(skPath, stroke); | 72 GrResourceKey resourceKey = GrPath::ComputeKey(skPath, stroke); |
| 57 SkAutoTUnref<GrPath> path(static_cast<GrPath*>(ctx->findAndRefCachedResource (resourceKey))); | 73 SkAutoTUnref<GrPath> path(static_cast<GrPath*>(ctx->findAndRefCachedResource (resourceKey))); |
| 58 if (NULL == path || !path->isEqualTo(skPath, stroke)) { | 74 if (NULL == path || !path->isEqualTo(skPath, stroke)) { |
| 59 path.reset(gpu->pathRendering()->createPath(skPath, stroke)); | 75 path.reset(gpu->pathRendering()->createPath(skPath, stroke)); |
| 60 ctx->addResourceToCache(resourceKey, path); | 76 ctx->addResourceToCache(resourceKey, path); |
| 61 } | 77 } |
| 62 return path.detach(); | 78 return path.detach(); |
| 63 } | 79 } |
| 64 | 80 |
| 65 void GrStencilAndCoverPathRenderer::onStencilPath(const SkPath& path, | 81 void GrStencilAndCoverPathRenderer::onStencilPath(const SkPath& path, |
| 66 const SkStrokeRec& stroke, | 82 const SkStrokeRec& stroke, |
| 67 GrDrawTarget* target) { | 83 GrDrawTarget* target) { |
| 68 SkASSERT(!path.isInverseFillType()); | 84 SkASSERT(!path.isInverseFillType()); |
| 69 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); | 85 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); |
| 70 target->stencilPath(p, path.getFillType()); | 86 target->stencilPath(p, convert_skpath_filltype(path.getFillType())); |
|
bsalomon
2014/10/30 20:11:01
This function is used by GrCMM to draw paths into
joshualitt
2014/10/30 21:24:33
Would the SkASSERT(!path.isInverseFillType()) catc
| |
| 71 } | 87 } |
| 72 | 88 |
| 73 bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path, | 89 bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path, |
| 74 const SkStrokeRec& stroke, | 90 const SkStrokeRec& stroke, |
| 75 GrDrawTarget* target, | 91 GrDrawTarget* target, |
| 76 bool antiAlias) { | 92 bool antiAlias) { |
| 77 SkASSERT(!antiAlias); | 93 SkASSERT(!antiAlias); |
| 78 SkASSERT(!stroke.isHairlineStyle()); | 94 SkASSERT(!stroke.isHairlineStyle()); |
| 79 | 95 |
| 80 GrDrawState* drawState = target->drawState(); | 96 GrDrawState* drawState = target->drawState(); |
| 81 SkASSERT(drawState->getStencil().isDisabled()); | 97 SkASSERT(drawState->getStencil().isDisabled()); |
| 82 | 98 |
| 83 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); | 99 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); |
| 84 | 100 |
| 85 if (path.isInverseFillType()) { | 101 if (path.isInverseFillType()) { |
| 86 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, | 102 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, |
| 87 kZero_StencilOp, | 103 kZero_StencilOp, |
| 88 kZero_StencilOp, | 104 kZero_StencilOp, |
| 89 // We know our rect will hit pixels outside the clip and the user bi ts will be 0 | 105 // We know our rect will hit pixels outside the clip and the user bi ts will be 0 |
| 90 // outside the clip. So we can't just fill where the user bits are 0 . We also need to | 106 // outside the clip. So we can't just fill where the user bits are 0 . We also need to |
| 91 // check that the clip bit is set. | 107 // check that the clip bit is set. |
| 92 kEqualIfInClip_StencilFunc, | 108 kEqualIfInClip_StencilFunc, |
| 93 0xffff, | 109 0xffff, |
| 94 0x0000, | 110 0x0000, |
| 95 0xffff); | 111 0xffff); |
| 96 | 112 |
| 97 *drawState->stencil() = kInvertedStencilPass; | 113 drawState->setStencil(kInvertedStencilPass); |
|
bsalomon
2014/10/30 20:11:01
prolly want to remove this line
joshualitt
2014/10/30 21:24:33
Acknowledged.
| |
| 114 | |
| 115 // fake inverse with a stencil and cover | |
| 116 target->stencilPath(p, convert_skpath_filltype(path.getFillType())); | |
| 117 | |
| 118 // now draw bounding rectangle | |
| 119 drawState->setStencil(kInvertedStencilPass); | |
| 120 | |
| 121 GrDrawState::AutoViewMatrixRestore avmr; | |
| 122 SkRect bounds = SkRect::MakeLTRB(0, 0, | |
| 123 SkIntToScalar(drawState->getRenderTarge t()->width()), | |
| 124 SkIntToScalar(drawState->getRenderTarge t()->height())); | |
| 125 SkMatrix vmi; | |
| 126 // mapRect through persp matrix may not be correct | |
| 127 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn verse(&vmi)) { | |
| 128 vmi.mapRect(&bounds); | |
| 129 // theoretically could set bloat = 0, instead leave it because of ma trix inversion | |
| 130 // precision. | |
| 131 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala rHalf; | |
| 132 bounds.outset(bloat, bloat); | |
| 133 } else { | |
| 134 avmr.setIdentity(drawState); | |
| 135 } | |
| 136 target->drawSimpleRect(bounds); | |
| 98 } else { | 137 } else { |
| 99 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, | 138 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, |
| 100 kZero_StencilOp, | 139 kZero_StencilOp, |
| 101 kZero_StencilOp, | 140 kZero_StencilOp, |
| 102 kNotEqual_StencilFunc, | 141 kNotEqual_StencilFunc, |
| 103 0xffff, | 142 0xffff, |
| 104 0x0000, | 143 0x0000, |
| 105 0xffff); | 144 0xffff); |
| 106 | 145 |
| 107 *drawState->stencil() = kStencilPass; | 146 drawState->setStencil(kStencilPass); |
| 147 target->drawPath(p, convert_skpath_filltype(path.getFillType())); | |
| 108 } | 148 } |
| 109 | 149 |
| 110 target->drawPath(p, path.getFillType()); | |
| 111 | |
| 112 target->drawState()->stencil()->setDisabled(); | 150 target->drawState()->stencil()->setDisabled(); |
| 113 return true; | 151 return true; |
| 114 } | 152 } |
| OLD | NEW |