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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 fGpu = gpu; | 45 fGpu = gpu; |
46 gpu->ref(); | 46 gpu->ref(); |
47 } | 47 } |
48 | 48 |
49 GrStencilAndCoverPathRenderer::~GrStencilAndCoverPathRenderer() { | 49 GrStencilAndCoverPathRenderer::~GrStencilAndCoverPathRenderer() { |
50 fGpu->unref(); | 50 fGpu->unref(); |
51 } | 51 } |
52 | 52 |
53 bool GrStencilAndCoverPathRenderer::canDrawPath(const GrDrawTarget* target, | 53 bool GrStencilAndCoverPathRenderer::canDrawPath(const GrDrawTarget* target, |
54 const GrDrawState* drawState, | 54 const GrDrawState* drawState, |
| 55 const SkMatrix& viewMatrix, |
55 const SkPath& path, | 56 const SkPath& path, |
56 const SkStrokeRec& stroke, | 57 const SkStrokeRec& stroke, |
57 bool antiAlias) const { | 58 bool antiAlias) const { |
58 return !stroke.isHairlineStyle() && | 59 return !stroke.isHairlineStyle() && |
59 !antiAlias && // doesn't do per-path AA, relies on the target having
MSAA | 60 !antiAlias && // doesn't do per-path AA, relies on the target having
MSAA |
60 drawState->getRenderTarget()->getStencilBuffer() && | 61 drawState->getRenderTarget()->getStencilBuffer() && |
61 drawState->getStencil().isDisabled(); | 62 drawState->getStencil().isDisabled(); |
62 } | 63 } |
63 | 64 |
64 GrPathRenderer::StencilSupport | 65 GrPathRenderer::StencilSupport |
(...skipping 10 matching lines...) Expand all Loading... |
75 SkAutoTUnref<GrPath> path(static_cast<GrPath*>(ctx->findAndRefCachedResource
(resourceKey))); | 76 SkAutoTUnref<GrPath> path(static_cast<GrPath*>(ctx->findAndRefCachedResource
(resourceKey))); |
76 if (NULL == path || !path->isEqualTo(skPath, stroke)) { | 77 if (NULL == path || !path->isEqualTo(skPath, stroke)) { |
77 path.reset(gpu->pathRendering()->createPath(skPath, stroke)); | 78 path.reset(gpu->pathRendering()->createPath(skPath, stroke)); |
78 ctx->addResourceToCache(resourceKey, path); | 79 ctx->addResourceToCache(resourceKey, path); |
79 } | 80 } |
80 return path.detach(); | 81 return path.detach(); |
81 } | 82 } |
82 | 83 |
83 void GrStencilAndCoverPathRenderer::onStencilPath(GrDrawTarget* target, | 84 void GrStencilAndCoverPathRenderer::onStencilPath(GrDrawTarget* target, |
84 GrDrawState* drawState, | 85 GrDrawState* drawState, |
| 86 const SkMatrix& viewMatrix, |
85 const SkPath& path, | 87 const SkPath& path, |
86 const SkStrokeRec& stroke) { | 88 const SkStrokeRec& stroke) { |
87 SkASSERT(!path.isInverseFillType()); | 89 SkASSERT(!path.isInverseFillType()); |
88 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE)); | 90 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE, view
Matrix)); |
89 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); | 91 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); |
90 target->stencilPath(drawState, pp, p, convert_skpath_filltype(path.getFillTy
pe())); | 92 target->stencilPath(drawState, pp, p, convert_skpath_filltype(path.getFillTy
pe())); |
91 } | 93 } |
92 | 94 |
93 bool GrStencilAndCoverPathRenderer::onDrawPath(GrDrawTarget* target, | 95 bool GrStencilAndCoverPathRenderer::onDrawPath(GrDrawTarget* target, |
94 GrDrawState* drawState, | 96 GrDrawState* drawState, |
95 GrColor color, | 97 GrColor color, |
| 98 const SkMatrix& viewMatrix, |
96 const SkPath& path, | 99 const SkPath& path, |
97 const SkStrokeRec& stroke, | 100 const SkStrokeRec& stroke, |
98 bool antiAlias) { | 101 bool antiAlias) { |
99 SkASSERT(!antiAlias); | 102 SkASSERT(!antiAlias); |
100 SkASSERT(!stroke.isHairlineStyle()); | 103 SkASSERT(!stroke.isHairlineStyle()); |
101 | 104 |
102 SkASSERT(drawState->getStencil().isDisabled()); | 105 SkASSERT(drawState->getStencil().isDisabled()); |
103 | 106 |
104 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); | 107 SkAutoTUnref<GrPath> p(get_gr_path(fGpu, path, stroke)); |
105 | 108 |
106 if (path.isInverseFillType()) { | 109 if (path.isInverseFillType()) { |
107 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, | 110 GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, |
108 kZero_StencilOp, | 111 kZero_StencilOp, |
109 kZero_StencilOp, | 112 kZero_StencilOp, |
110 // We know our rect will hit pixels outside the clip and the user bi
ts will be 0 | 113 // We know our rect will hit pixels outside the clip and the user bi
ts will be 0 |
111 // outside the clip. So we can't just fill where the user bits are 0
. We also need to | 114 // 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. | 115 // check that the clip bit is set. |
113 kEqualIfInClip_StencilFunc, | 116 kEqualIfInClip_StencilFunc, |
114 0xffff, | 117 0xffff, |
115 0x0000, | 118 0x0000, |
116 0xffff); | 119 0xffff); |
117 | 120 |
118 drawState->setStencil(kInvertedStencilPass); | 121 drawState->setStencil(kInvertedStencilPass); |
119 | 122 |
120 // fake inverse with a stencil and cover | 123 // fake inverse with a stencil and cover |
121 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE))
; | 124 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE,
viewMatrix)); |
122 target->stencilPath(drawState, pp, p, convert_skpath_filltype(path.getFi
llType())); | 125 target->stencilPath(drawState, pp, p, convert_skpath_filltype(path.getFi
llType())); |
123 | 126 |
124 SkMatrix invert = SkMatrix::I(); | 127 SkMatrix invert = SkMatrix::I(); |
125 GrDrawState::AutoViewMatrixRestore avmr; | |
126 SkRect bounds = SkRect::MakeLTRB(0, 0, | 128 SkRect bounds = SkRect::MakeLTRB(0, 0, |
127 SkIntToScalar(drawState->getRenderTarge
t()->width()), | 129 SkIntToScalar(drawState->getRenderTarge
t()->width()), |
128 SkIntToScalar(drawState->getRenderTarge
t()->height())); | 130 SkIntToScalar(drawState->getRenderTarge
t()->height())); |
129 SkMatrix vmi; | 131 SkMatrix vmi; |
130 // mapRect through persp matrix may not be correct | 132 // mapRect through persp matrix may not be correct |
131 if (!drawState->getViewMatrix().hasPerspective() && drawState->getViewIn
verse(&vmi)) { | 133 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { |
132 vmi.mapRect(&bounds); | 134 vmi.mapRect(&bounds); |
133 // theoretically could set bloat = 0, instead leave it because of ma
trix inversion | 135 // theoretically could set bloat = 0, instead leave it because of ma
trix inversion |
134 // precision. | 136 // precision. |
135 SkScalar bloat = drawState->getViewMatrix().getMaxScale() * SK_Scala
rHalf; | 137 SkScalar bloat = viewMatrix.getMaxScale() * SK_ScalarHalf; |
136 bounds.outset(bloat, bloat); | 138 bounds.outset(bloat, bloat); |
137 } else { | 139 } else { |
138 if (!drawState->getViewMatrix().invert(&invert)) { | 140 if (!viewMatrix.invert(&invert)) { |
139 return false; | 141 return false; |
140 } | 142 } |
141 avmr.setIdentity(drawState); | |
142 } | 143 } |
143 target->drawRect(drawState, color, bounds, NULL, &invert); | 144 const SkMatrix& viewM = viewMatrix.hasPerspective() ? SkMatrix::I() : vi
ewMatrix; |
| 145 target->drawRect(drawState, color, viewM, bounds, NULL, &invert); |
144 } else { | 146 } else { |
145 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, | 147 GR_STATIC_CONST_SAME_STENCIL(kStencilPass, |
146 kZero_StencilOp, | 148 kZero_StencilOp, |
147 kZero_StencilOp, | 149 kZero_StencilOp, |
148 kNotEqual_StencilFunc, | 150 kNotEqual_StencilFunc, |
149 0xffff, | 151 0xffff, |
150 0x0000, | 152 0x0000, |
151 0xffff); | 153 0xffff); |
152 | 154 |
153 drawState->setStencil(kStencilPass); | 155 drawState->setStencil(kStencilPass); |
154 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(color)); | 156 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(color, viewMatr
ix)); |
155 target->drawPath(drawState, pp, p, convert_skpath_filltype(path.getFillT
ype())); | 157 target->drawPath(drawState, pp, p, convert_skpath_filltype(path.getFillT
ype())); |
156 } | 158 } |
157 | 159 |
158 drawState->stencil()->setDisabled(); | 160 drawState->stencil()->setDisabled(); |
159 return true; | 161 return true; |
160 } | 162 } |
OLD | NEW |