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