| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "GrStencilAndCoverPathRenderer.h" | 9 #include "GrStencilAndCoverPathRenderer.h" |
| 10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
| 11 #include "GrContext.h" | 11 #include "GrContext.h" |
| 12 #include "GrDrawPathBatch.h" | 12 #include "GrDrawPathBatch.h" |
| 13 #include "GrGpu.h" | 13 #include "GrGpu.h" |
| 14 #include "GrPath.h" | 14 #include "GrPath.h" |
| 15 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
| 16 #include "GrResourceProvider.h" | 16 #include "GrResourceProvider.h" |
| 17 #include "GrStyle.h" | 17 #include "GrStrokeInfo.h" |
| 18 #include "batches/GrRectBatchFactory.h" | 18 #include "batches/GrRectBatchFactory.h" |
| 19 | 19 |
| 20 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrResourceProvider* resour
ceProvider, | 20 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrResourceProvider* resour
ceProvider, |
| 21 const GrCaps& caps) { | 21 const GrCaps& caps) { |
| 22 if (caps.shaderCaps()->pathRenderingSupport()) { | 22 if (caps.shaderCaps()->pathRenderingSupport()) { |
| 23 return new GrStencilAndCoverPathRenderer(resourceProvider); | 23 return new GrStencilAndCoverPathRenderer(resourceProvider); |
| 24 } else { | 24 } else { |
| 25 return nullptr; | 25 return nullptr; |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrResourceProvider*
resourceProvider) | 29 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrResourceProvider*
resourceProvider) |
| 30 : fResourceProvider(resourceProvider) { | 30 : fResourceProvider(resourceProvider) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 bool GrStencilAndCoverPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c
onst { | 33 bool GrStencilAndCoverPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c
onst { |
| 34 // GrPath doesn't support hairline paths. Also, an arbitrary path effect cou
ld change | 34 if (args.fStroke->isHairlineStyle()) { |
| 35 // the style type to hairline. | |
| 36 if (!args.fStyle->hasNonDashPathEffect() || args.fStyle->strokeRec().isHairl
ineStyle()) { | |
| 37 return false; | 35 return false; |
| 38 } | 36 } |
| 39 if (!args.fIsStencilDisabled) { | 37 if (!args.fIsStencilDisabled) { |
| 40 return false; | 38 return false; |
| 41 } | 39 } |
| 42 if (args.fAntiAlias) { | 40 if (args.fAntiAlias) { |
| 43 return args.fIsStencilBufferMSAA; | 41 return args.fIsStencilBufferMSAA; |
| 44 } else { | 42 } else { |
| 45 return true; // doesn't do per-path AA, relies on the target having MSAA | 43 return true; // doesn't do per-path AA, relies on the target having MSAA |
| 46 } | 44 } |
| 47 } | 45 } |
| 48 | 46 |
| 49 static GrPath* get_gr_path(GrResourceProvider* resourceProvider, const SkPath& s
kPath, | 47 static GrPath* get_gr_path(GrResourceProvider* resourceProvider, const SkPath& s
kPath, |
| 50 const GrStyle& style) { | 48 const GrStrokeInfo& stroke) { |
| 51 GrUniqueKey key; | 49 GrUniqueKey key; |
| 52 bool isVolatile; | 50 bool isVolatile; |
| 53 GrPath::ComputeKey(skPath, style, &key, &isVolatile); | 51 GrPath::ComputeKey(skPath, stroke, &key, &isVolatile); |
| 54 SkAutoTUnref<GrPath> path( | 52 SkAutoTUnref<GrPath> path( |
| 55 static_cast<GrPath*>(resourceProvider->findAndRefResourceByUniqueKey(key
))); | 53 static_cast<GrPath*>(resourceProvider->findAndRefResourceByUniqueKey(key
))); |
| 56 if (!path) { | 54 if (!path) { |
| 57 path.reset(resourceProvider->createPath(skPath, style)); | 55 path.reset(resourceProvider->createPath(skPath, stroke)); |
| 58 if (!isVolatile) { | 56 if (!isVolatile) { |
| 59 resourceProvider->assignUniqueKeyToResource(key, path); | 57 resourceProvider->assignUniqueKeyToResource(key, path); |
| 60 } | 58 } |
| 61 } else { | 59 } else { |
| 62 SkASSERT(path->isEqualTo(skPath, style)); | 60 SkASSERT(path->isEqualTo(skPath, stroke)); |
| 63 } | 61 } |
| 64 return path.release(); | 62 return path.release(); |
| 65 } | 63 } |
| 66 | 64 |
| 67 void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) { | 65 void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) { |
| 68 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), | 66 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), |
| 69 "GrStencilAndCoverPathRenderer::onStencilPath"); | 67 "GrStencilAndCoverPathRenderer::onStencilPath"); |
| 70 SkASSERT(!args.fPath->isInverseFillType()); | 68 SkASSERT(!args.fPath->isInverseFillType()); |
| 71 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fPath, GrStyle::
SimpleFill())); | 69 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fPath, GrStrokeI
nfo::FillInfo())); |
| 72 args.fTarget->stencilPath(*args.fPipelineBuilder, *args.fViewMatrix, p, p->g
etFillType()); | 70 args.fTarget->stencilPath(*args.fPipelineBuilder, *args.fViewMatrix, p, p->g
etFillType()); |
| 73 } | 71 } |
| 74 | 72 |
| 75 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { | 73 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { |
| 76 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), | 74 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), |
| 77 "GrStencilAndCoverPathRenderer::onDrawPath"); | 75 "GrStencilAndCoverPathRenderer::onDrawPath"); |
| 78 SkASSERT(!args.fStyle->strokeRec().isHairlineStyle()); | 76 SkASSERT(!args.fStroke->isHairlineStyle()); |
| 79 const SkPath& path = *args.fPath; | 77 const SkPath& path = *args.fPath; |
| 80 GrPipelineBuilder* pipelineBuilder = args.fPipelineBuilder; | 78 GrPipelineBuilder* pipelineBuilder = args.fPipelineBuilder; |
| 81 const SkMatrix& viewMatrix = *args.fViewMatrix; | 79 const SkMatrix& viewMatrix = *args.fViewMatrix; |
| 82 | 80 |
| 83 SkASSERT(pipelineBuilder->getStencil().isDisabled()); | 81 SkASSERT(pipelineBuilder->getStencil().isDisabled()); |
| 84 | 82 |
| 85 if (args.fAntiAlias) { | 83 if (args.fAntiAlias) { |
| 86 SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled
()); | 84 SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled
()); |
| 87 pipelineBuilder->enableState(GrPipelineBuilder::kHWAntialias_Flag); | 85 pipelineBuilder->enableState(GrPipelineBuilder::kHWAntialias_Flag); |
| 88 } | 86 } |
| 89 | 87 |
| 90 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, *args.fStyle)); | 88 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, *args.fStroke)); |
| 91 | 89 |
| 92 if (path.isInverseFillType()) { | 90 if (path.isInverseFillType()) { |
| 93 static constexpr GrStencilSettings kInvertedStencilPass( | 91 static constexpr GrStencilSettings kInvertedStencilPass( |
| 94 kKeep_StencilOp, | 92 kKeep_StencilOp, |
| 95 kZero_StencilOp, | 93 kZero_StencilOp, |
| 96 // We know our rect will hit pixels outside the clip and the user bi
ts will be 0 | 94 // We know our rect will hit pixels outside the clip and the user bi
ts will be 0 |
| 97 // outside the clip. So we can't just fill where the user bits are 0
. We also need to | 95 // outside the clip. So we can't just fill where the user bits are 0
. We also need to |
| 98 // check that the clip bit is set. | 96 // check that the clip bit is set. |
| 99 kEqualIfInClip_StencilFunc, | 97 kEqualIfInClip_StencilFunc, |
| 100 0xffff, | 98 0xffff, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 141 |
| 144 pipelineBuilder->setStencil(kStencilPass); | 142 pipelineBuilder->setStencil(kStencilPass); |
| 145 SkAutoTUnref<GrDrawPathBatchBase> batch( | 143 SkAutoTUnref<GrDrawPathBatchBase> batch( |
| 146 GrDrawPathBatch::Create(viewMatrix, args.fColor, p->getFillType(
), p)); | 144 GrDrawPathBatch::Create(viewMatrix, args.fColor, p->getFillType(
), p)); |
| 147 args.fTarget->drawPathBatch(*pipelineBuilder, batch); | 145 args.fTarget->drawPathBatch(*pipelineBuilder, batch); |
| 148 } | 146 } |
| 149 | 147 |
| 150 pipelineBuilder->stencil()->setDisabled(); | 148 pipelineBuilder->stencil()->setDisabled(); |
| 151 return true; | 149 return true; |
| 152 } | 150 } |
| OLD | NEW |