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" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 ctx->addResourceToCache(resourceKey, path); | 78 ctx->addResourceToCache(resourceKey, path); |
79 } | 79 } |
80 return path.detach(); | 80 return path.detach(); |
81 } | 81 } |
82 | 82 |
83 void GrStencilAndCoverPathRenderer::onStencilPath(GrDrawTarget* target, | 83 void GrStencilAndCoverPathRenderer::onStencilPath(GrDrawTarget* target, |
84 GrDrawState* drawState, | 84 GrDrawState* drawState, |
85 const SkPath& path, | 85 const SkPath& path, |
86 const SkStrokeRec& stroke) { | 86 const SkStrokeRec& stroke) { |
87 SkASSERT(!path.isInverseFillType()); | 87 SkASSERT(!path.isInverseFillType()); |
88 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE)); | |
89 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); | 88 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); |
90 target->stencilPath(drawState, pp, p, convert_skpath_filltype(path.getFillTy
pe())); | 89 target->stencilPath(drawState, p, convert_skpath_filltype(path.getFillType()
)); |
91 } | 90 } |
92 | 91 |
93 bool GrStencilAndCoverPathRenderer::onDrawPath(GrDrawTarget* target, | 92 bool GrStencilAndCoverPathRenderer::onDrawPath(GrDrawTarget* target, |
94 GrDrawState* drawState, | 93 GrDrawState* drawState, |
95 GrColor color, | 94 GrColor color, |
96 const SkPath& path, | 95 const SkPath& path, |
97 const SkStrokeRec& stroke, | 96 const SkStrokeRec& stroke, |
98 bool antiAlias) { | 97 bool antiAlias) { |
99 SkASSERT(!antiAlias); | 98 SkASSERT(!antiAlias); |
100 SkASSERT(!stroke.isHairlineStyle()); | 99 SkASSERT(!stroke.isHairlineStyle()); |
(...skipping 10 matching lines...) Expand all Loading... |
111 // outside the clip. So we can't just fill where the user bits are 0
. We also need to | 110 // outside the clip. So we can't just fill where the user bits are 0
. We also need to |
112 // check that the clip bit is set. | 111 // check that the clip bit is set. |
113 kEqualIfInClip_StencilFunc, | 112 kEqualIfInClip_StencilFunc, |
114 0xffff, | 113 0xffff, |
115 0x0000, | 114 0x0000, |
116 0xffff); | 115 0xffff); |
117 | 116 |
118 drawState->setStencil(kInvertedStencilPass); | 117 drawState->setStencil(kInvertedStencilPass); |
119 | 118 |
120 // fake inverse with a stencil and cover | 119 // fake inverse with a stencil and cover |
121 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE))
; | 120 target->stencilPath(drawState, p, convert_skpath_filltype(path.getFillTy
pe())); |
122 target->stencilPath(drawState, pp, p, convert_skpath_filltype(path.getFi
llType())); | |
123 | 121 |
124 GrDrawState::AutoViewMatrixRestore avmr; | 122 GrDrawState::AutoViewMatrixRestore avmr; |
125 SkRect bounds = SkRect::MakeLTRB(0, 0, | 123 SkRect bounds = SkRect::MakeLTRB(0, 0, |
126 SkIntToScalar(drawState->getRenderTarge
t()->width()), | 124 SkIntToScalar(drawState->getRenderTarge
t()->width()), |
127 SkIntToScalar(drawState->getRenderTarge
t()->height())); | 125 SkIntToScalar(drawState->getRenderTarge
t()->height())); |
128 SkMatrix vmi; | 126 SkMatrix vmi; |
129 // mapRect through persp matrix may not be correct | 127 // mapRect through persp matrix may not be correct |
130 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn
verse(&vmi)) { | 128 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn
verse(&vmi)) { |
131 vmi.mapRect(&bounds); | 129 vmi.mapRect(&bounds); |
132 // theoretically could set bloat = 0, instead leave it because of ma
trix inversion | 130 // theoretically could set bloat = 0, instead leave it because of ma
trix inversion |
133 // precision. | 131 // precision. |
134 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala
rHalf; | 132 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala
rHalf; |
135 bounds.outset(bloat, bloat); | 133 bounds.outset(bloat, bloat); |
136 } else { | 134 } else { |
137 avmr.setIdentity(drawState); | 135 avmr.setIdentity(drawState); |
138 } | 136 } |
139 target->drawSimpleRect(drawState, color, bounds); | 137 target->drawSimpleRect(drawState, color, bounds); |
140 } else { | 138 } else { |
141 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, | 139 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, |
142 kZero_StencilOp, | 140 kZero_StencilOp, |
143 kZero_StencilOp, | 141 kZero_StencilOp, |
144 kNotEqual_StencilFunc, | 142 kNotEqual_StencilFunc, |
145 0xffff, | 143 0xffff, |
146 0x0000, | 144 0x0000, |
147 0xffff); | 145 0xffff); |
148 | 146 |
149 drawState->setStencil(kStencilPass); | 147 drawState->setStencil(kStencilPass); |
150 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(color)); | 148 target->drawPath(drawState, color, p, convert_skpath_filltype(path.getFi
llType())); |
151 target->drawPath(drawState, pp, p, convert_skpath_filltype(path.getFillT
ype())); | |
152 } | 149 } |
153 | 150 |
154 drawState->stencil()->setDisabled(); | 151 drawState->stencil()->setDisabled(); |
155 return true; | 152 return true; |
156 } | 153 } |
OLD | NEW |