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" | |
14 #include "GrPath.h" | 13 #include "GrPath.h" |
15 #include "GrRenderTarget.h" | 14 #include "GrRenderTarget.h" |
16 #include "GrRenderTargetPriv.h" | |
17 #include "GrResourceProvider.h" | 15 #include "GrResourceProvider.h" |
18 #include "GrStrokeInfo.h" | 16 #include "GrStrokeInfo.h" |
19 | 17 |
20 /* | 18 /* |
21 * For now paths only natively support winding and even odd fill types | 19 * For now paths only natively support winding and even odd fill types |
22 */ | 20 */ |
23 static GrPathRendering::FillType convert_skpath_filltype(SkPath::FillType fill)
{ | 21 static GrPathRendering::FillType convert_skpath_filltype(SkPath::FillType fill)
{ |
24 switch (fill) { | 22 switch (fill) { |
25 default: | 23 default: |
26 SkFAIL("Incomplete Switch\n"); | 24 SkFAIL("Incomplete Switch\n"); |
27 case SkPath::kWinding_FillType: | 25 case SkPath::kWinding_FillType: |
28 case SkPath::kInverseWinding_FillType: | 26 case SkPath::kInverseWinding_FillType: |
29 return GrPathRendering::kWinding_FillType; | 27 return GrPathRendering::kWinding_FillType; |
30 case SkPath::kEvenOdd_FillType: | 28 case SkPath::kEvenOdd_FillType: |
31 case SkPath::kInverseEvenOdd_FillType: | 29 case SkPath::kInverseEvenOdd_FillType: |
32 return GrPathRendering::kEvenOdd_FillType; | 30 return GrPathRendering::kEvenOdd_FillType; |
33 } | 31 } |
34 } | 32 } |
35 | 33 |
36 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrContext* context) { | 34 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrResourceProvider* resour
ceProvider, |
37 SkASSERT(context); | 35 const GrCaps& caps) { |
38 SkASSERT(context->getGpu()); | 36 if (caps.shaderCaps()->pathRenderingSupport()) { |
39 if (context->getGpu()->caps()->shaderCaps()->pathRenderingSupport()) { | 37 return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (resourceProvider)); |
40 return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (context->getGpu())); | |
41 } else { | 38 } else { |
42 return NULL; | 39 return NULL; |
43 } | 40 } |
44 } | 41 } |
45 | 42 |
46 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrGpu* gpu) { | 43 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrResourceProvider*
resourceProvider) |
47 SkASSERT(gpu->caps()->shaderCaps()->pathRenderingSupport()); | 44 : fResourceProvider(resourceProvider) { |
48 fGpu = gpu; | |
49 gpu->ref(); | |
50 } | |
51 | |
52 GrStencilAndCoverPathRenderer::~GrStencilAndCoverPathRenderer() { | |
53 fGpu->unref(); | |
54 } | 45 } |
55 | 46 |
56 bool GrStencilAndCoverPathRenderer::canDrawPath(const GrDrawTarget* target, | 47 bool GrStencilAndCoverPathRenderer::canDrawPath(const GrDrawTarget* target, |
57 const GrPipelineBuilder* pipelin
eBuilder, | 48 const GrPipelineBuilder* pipelin
eBuilder, |
58 const SkMatrix& viewMatrix, | 49 const SkMatrix& viewMatrix, |
59 const SkPath& path, | 50 const SkPath& path, |
60 const GrStrokeInfo& stroke, | 51 const GrStrokeInfo& stroke, |
61 bool antiAlias) const { | 52 bool antiAlias) const { |
62 return !stroke.isHairlineStyle() && | 53 return !stroke.isHairlineStyle() && |
63 !antiAlias && // doesn't do per-path AA, relies on the target having MSA
A | 54 !antiAlias && // doesn't do per-path AA, relies on the target having MSA
A |
64 pipelineBuilder->getStencil().isDisabled(); | 55 pipelineBuilder->getStencil().isDisabled(); |
65 } | 56 } |
66 | 57 |
67 GrPathRenderer::StencilSupport | 58 GrPathRenderer::StencilSupport |
68 GrStencilAndCoverPathRenderer::onGetStencilSupport(const GrDrawTarget*, | 59 GrStencilAndCoverPathRenderer::onGetStencilSupport(const GrDrawTarget*, |
69 const GrPipelineBuilder*, | 60 const GrPipelineBuilder*, |
70 const SkPath&, | 61 const SkPath&, |
71 const GrStrokeInfo&) const { | 62 const GrStrokeInfo&) const { |
72 return GrPathRenderer::kStencilOnly_StencilSupport; | 63 return GrPathRenderer::kStencilOnly_StencilSupport; |
73 } | 64 } |
74 | 65 |
75 static GrPath* get_gr_path(GrGpu* gpu, const SkPath& skPath, const GrStrokeInfo&
stroke) { | 66 static GrPath* get_gr_path(GrResourceProvider* resourceProvider, const SkPath& s
kPath, |
76 GrContext* ctx = gpu->getContext(); | 67 const GrStrokeInfo& stroke) { |
77 GrUniqueKey key; | 68 GrUniqueKey key; |
78 bool isVolatile; | 69 bool isVolatile; |
79 GrPath::ComputeKey(skPath, stroke, &key, &isVolatile); | 70 GrPath::ComputeKey(skPath, stroke, &key, &isVolatile); |
80 SkAutoTUnref<GrPath> path( | 71 SkAutoTUnref<GrPath> path( |
81 static_cast<GrPath*>(ctx->resourceProvider()->findAndRefResourceByUnique
Key(key))); | 72 static_cast<GrPath*>(resourceProvider->findAndRefResourceByUniqueKey(key
))); |
82 if (NULL == path) { | 73 if (!path) { |
83 path.reset(gpu->pathRendering()->createPath(skPath, stroke)); | 74 path.reset(resourceProvider->createPath(skPath, stroke)); |
84 if (!isVolatile) { | 75 if (!isVolatile) { |
85 ctx->resourceProvider()->assignUniqueKeyToResource(key, path); | 76 resourceProvider->assignUniqueKeyToResource(key, path); |
86 } | 77 } |
87 } else { | 78 } else { |
88 SkASSERT(path->isEqualTo(skPath, stroke)); | 79 SkASSERT(path->isEqualTo(skPath, stroke)); |
89 } | 80 } |
90 return path.detach(); | 81 return path.detach(); |
91 } | 82 } |
92 | 83 |
93 void GrStencilAndCoverPathRenderer::onStencilPath(GrDrawTarget* target, | 84 void GrStencilAndCoverPathRenderer::onStencilPath(GrDrawTarget* target, |
94 GrPipelineBuilder* pipelineBui
lder, | 85 GrPipelineBuilder* pipelineBui
lder, |
95 const SkMatrix& viewMatrix, | 86 const SkMatrix& viewMatrix, |
96 const SkPath& path, | 87 const SkPath& path, |
97 const GrStrokeInfo& stroke) { | 88 const GrStrokeInfo& stroke) { |
98 SkASSERT(!path.isInverseFillType()); | 89 SkASSERT(!path.isInverseFillType()); |
99 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE, view
Matrix)); | 90 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE, view
Matrix)); |
100 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); | 91 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, stroke)); |
101 target->stencilPath(pipelineBuilder, pp, p, convert_skpath_filltype(path.get
FillType())); | 92 target->stencilPath(pipelineBuilder, pp, p, convert_skpath_filltype(path.get
FillType())); |
102 } | 93 } |
103 | 94 |
104 bool GrStencilAndCoverPathRenderer::onDrawPath(GrDrawTarget* target, | 95 bool GrStencilAndCoverPathRenderer::onDrawPath(GrDrawTarget* target, |
105 GrPipelineBuilder* pipelineBuilde
r, | 96 GrPipelineBuilder* pipelineBuilde
r, |
106 GrColor color, | 97 GrColor color, |
107 const SkMatrix& viewMatrix, | 98 const SkMatrix& viewMatrix, |
108 const SkPath& path, | 99 const SkPath& path, |
109 const GrStrokeInfo& stroke, | 100 const GrStrokeInfo& stroke, |
110 bool antiAlias) { | 101 bool antiAlias) { |
111 SkASSERT(!antiAlias); | 102 SkASSERT(!antiAlias); |
112 SkASSERT(!stroke.isHairlineStyle()); | 103 SkASSERT(!stroke.isHairlineStyle()); |
113 SkASSERT(pipelineBuilder->getStencil().isDisabled()); | 104 SkASSERT(pipelineBuilder->getStencil().isDisabled()); |
114 | 105 |
115 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); | 106 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, stroke)); |
116 | 107 |
117 if (path.isInverseFillType()) { | 108 if (path.isInverseFillType()) { |
118 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, | 109 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, |
119 kZero_StencilOp, | 110 kZero_StencilOp, |
120 kZero_StencilOp, | 111 kZero_StencilOp, |
121 // We know our rect will hit pixels outside the clip and the user bi
ts will be 0 | 112 // We know our rect will hit pixels outside the clip and the user bi
ts will be 0 |
122 // outside the clip. So we can't just fill where the user bits are 0
. We also need to | 113 // outside the clip. So we can't just fill where the user bits are 0
. We also need to |
123 // check that the clip bit is set. | 114 // check that the clip bit is set. |
124 kEqualIfInClip_StencilFunc, | 115 kEqualIfInClip_StencilFunc, |
125 0xffff, | 116 0xffff, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 0xffff); | 152 0xffff); |
162 | 153 |
163 pipelineBuilder->setStencil(kStencilPass); | 154 pipelineBuilder->setStencil(kStencilPass); |
164 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(color, viewMatr
ix)); | 155 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(color, viewMatr
ix)); |
165 target->drawPath(pipelineBuilder, pp, p, convert_skpath_filltype(path.ge
tFillType())); | 156 target->drawPath(pipelineBuilder, pp, p, convert_skpath_filltype(path.ge
tFillType())); |
166 } | 157 } |
167 | 158 |
168 pipelineBuilder->stencil()->setDisabled(); | 159 pipelineBuilder->stencil()->setDisabled(); |
169 return true; | 160 return true; |
170 } | 161 } |
OLD | NEW |