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 "GrStrokeInfo.h" | 17 #include "GrStyle.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 if (args.fStroke->isHairlineStyle()) { | 34 // GrPath doesn't support hairline paths. Also, an arbitrary path effect cou
ld change |
| 35 // the style type to hairline. |
| 36 if (!args.fStyle->hasNonDashPathEffect() || args.fStyle->strokeRec().isHairl
ineStyle()) { |
35 return false; | 37 return false; |
36 } | 38 } |
37 if (!args.fIsStencilDisabled) { | 39 if (!args.fIsStencilDisabled) { |
38 return false; | 40 return false; |
39 } | 41 } |
40 if (args.fAntiAlias) { | 42 if (args.fAntiAlias) { |
41 return args.fIsStencilBufferMSAA; | 43 return args.fIsStencilBufferMSAA; |
42 } else { | 44 } else { |
43 return true; // doesn't do per-path AA, relies on the target having MSAA | 45 return true; // doesn't do per-path AA, relies on the target having MSAA |
44 } | 46 } |
45 } | 47 } |
46 | 48 |
47 static GrPath* get_gr_path(GrResourceProvider* resourceProvider, const SkPath& s
kPath, | 49 static GrPath* get_gr_path(GrResourceProvider* resourceProvider, const SkPath& s
kPath, |
48 const GrStrokeInfo& stroke) { | 50 const GrStyle& style) { |
49 GrUniqueKey key; | 51 GrUniqueKey key; |
50 bool isVolatile; | 52 bool isVolatile; |
51 GrPath::ComputeKey(skPath, stroke, &key, &isVolatile); | 53 GrPath::ComputeKey(skPath, style, &key, &isVolatile); |
52 SkAutoTUnref<GrPath> path( | 54 SkAutoTUnref<GrPath> path( |
53 static_cast<GrPath*>(resourceProvider->findAndRefResourceByUniqueKey(key
))); | 55 static_cast<GrPath*>(resourceProvider->findAndRefResourceByUniqueKey(key
))); |
54 if (!path) { | 56 if (!path) { |
55 path.reset(resourceProvider->createPath(skPath, stroke)); | 57 path.reset(resourceProvider->createPath(skPath, style)); |
56 if (!isVolatile) { | 58 if (!isVolatile) { |
57 resourceProvider->assignUniqueKeyToResource(key, path); | 59 resourceProvider->assignUniqueKeyToResource(key, path); |
58 } | 60 } |
59 } else { | 61 } else { |
60 SkASSERT(path->isEqualTo(skPath, stroke)); | 62 SkASSERT(path->isEqualTo(skPath, style)); |
61 } | 63 } |
62 return path.release(); | 64 return path.release(); |
63 } | 65 } |
64 | 66 |
65 void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) { | 67 void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) { |
66 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), | 68 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), |
67 "GrStencilAndCoverPathRenderer::onStencilPath"); | 69 "GrStencilAndCoverPathRenderer::onStencilPath"); |
68 SkASSERT(!args.fPath->isInverseFillType()); | 70 SkASSERT(!args.fPath->isInverseFillType()); |
69 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fPath, GrStrokeI
nfo::FillInfo())); | 71 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fPath, GrStyle::
SimpleFill())); |
70 args.fTarget->stencilPath(*args.fPipelineBuilder, *args.fViewMatrix, p, p->g
etFillType()); | 72 args.fTarget->stencilPath(*args.fPipelineBuilder, *args.fViewMatrix, p, p->g
etFillType()); |
71 } | 73 } |
72 | 74 |
73 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { | 75 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { |
74 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), | 76 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), |
75 "GrStencilAndCoverPathRenderer::onDrawPath"); | 77 "GrStencilAndCoverPathRenderer::onDrawPath"); |
76 SkASSERT(!args.fStroke->isHairlineStyle()); | 78 SkASSERT(!args.fStyle->strokeRec().isHairlineStyle()); |
77 const SkPath& path = *args.fPath; | 79 const SkPath& path = *args.fPath; |
78 GrPipelineBuilder* pipelineBuilder = args.fPipelineBuilder; | 80 GrPipelineBuilder* pipelineBuilder = args.fPipelineBuilder; |
79 const SkMatrix& viewMatrix = *args.fViewMatrix; | 81 const SkMatrix& viewMatrix = *args.fViewMatrix; |
80 | 82 |
81 SkASSERT(pipelineBuilder->getStencil().isDisabled()); | 83 SkASSERT(pipelineBuilder->getStencil().isDisabled()); |
82 | 84 |
83 if (args.fAntiAlias) { | 85 if (args.fAntiAlias) { |
84 SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled
()); | 86 SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled
()); |
85 pipelineBuilder->enableState(GrPipelineBuilder::kHWAntialias_Flag); | 87 pipelineBuilder->enableState(GrPipelineBuilder::kHWAntialias_Flag); |
86 } | 88 } |
87 | 89 |
88 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, *args.fStroke)); | 90 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, *args.fStyle)); |
89 | 91 |
90 if (path.isInverseFillType()) { | 92 if (path.isInverseFillType()) { |
91 static constexpr GrStencilSettings kInvertedStencilPass( | 93 static constexpr GrStencilSettings kInvertedStencilPass( |
92 kKeep_StencilOp, | 94 kKeep_StencilOp, |
93 kZero_StencilOp, | 95 kZero_StencilOp, |
94 // We know our rect will hit pixels outside the clip and the user bi
ts will be 0 | 96 // We know our rect will hit pixels outside the clip and the user bi
ts will be 0 |
95 // outside the clip. So we can't just fill where the user bits are 0
. We also need to | 97 // outside the clip. So we can't just fill where the user bits are 0
. We also need to |
96 // check that the clip bit is set. | 98 // check that the clip bit is set. |
97 kEqualIfInClip_StencilFunc, | 99 kEqualIfInClip_StencilFunc, |
98 0xffff, | 100 0xffff, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 143 |
142 pipelineBuilder->setStencil(kStencilPass); | 144 pipelineBuilder->setStencil(kStencilPass); |
143 SkAutoTUnref<GrDrawPathBatchBase> batch( | 145 SkAutoTUnref<GrDrawPathBatchBase> batch( |
144 GrDrawPathBatch::Create(viewMatrix, args.fColor, p->getFillType(
), p)); | 146 GrDrawPathBatch::Create(viewMatrix, args.fColor, p->getFillType(
), p)); |
145 args.fTarget->drawPathBatch(*pipelineBuilder, batch); | 147 args.fTarget->drawPathBatch(*pipelineBuilder, batch); |
146 } | 148 } |
147 | 149 |
148 pipelineBuilder->stencil()->setDisabled(); | 150 pipelineBuilder->stencil()->setDisabled(); |
149 return true; | 151 return true; |
150 } | 152 } |
OLD | NEW |