| 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" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { | 89 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { |
| 90 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), | 90 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), |
| 91 "GrStencilAndCoverPathRenderer::onDrawPath"); | 91 "GrStencilAndCoverPathRenderer::onDrawPath"); |
| 92 SkASSERT(!args.fPaint->isAntiAlias() || args.fDrawContext->isStencilBufferMu
ltisampled()); | 92 SkASSERT(!args.fPaint->isAntiAlias() || args.fDrawContext->isStencilBufferMu
ltisampled()); |
| 93 SkASSERT(!args.fShape->style().strokeRec().isHairlineStyle()); | 93 SkASSERT(!args.fShape->style().strokeRec().isHairlineStyle()); |
| 94 | 94 |
| 95 const SkMatrix& viewMatrix = *args.fViewMatrix; | 95 const SkMatrix& viewMatrix = *args.fViewMatrix; |
| 96 | 96 |
| 97 SkPath path; | |
| 98 args.fShape->asPath(&path); | |
| 99 | 97 |
| 100 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fShape)); | 98 SkAutoTUnref<GrPath> path(get_gr_path(fResourceProvider, *args.fShape)); |
| 101 | 99 |
| 102 if (path.isInverseFillType()) { | 100 if (args.fShape->inverseFilled()) { |
| 103 SkMatrix invert = SkMatrix::I(); | 101 SkMatrix invert = SkMatrix::I(); |
| 104 SkRect bounds = | 102 SkRect bounds = |
| 105 SkRect::MakeLTRB(0, 0, | 103 SkRect::MakeLTRB(0, 0, |
| 106 SkIntToScalar(args.fDrawContext->width()), | 104 SkIntToScalar(args.fDrawContext->width()), |
| 107 SkIntToScalar(args.fDrawContext->height())); | 105 SkIntToScalar(args.fDrawContext->height())); |
| 108 SkMatrix vmi; | 106 SkMatrix vmi; |
| 109 // mapRect through persp matrix may not be correct | 107 // mapRect through persp matrix may not be correct |
| 110 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { | 108 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { |
| 111 vmi.mapRect(&bounds); | 109 vmi.mapRect(&bounds); |
| 112 // theoretically could set bloat = 0, instead leave it because of ma
trix inversion | 110 // theoretically could set bloat = 0, instead leave it because of ma
trix inversion |
| 113 // precision. | 111 // precision. |
| 114 SkScalar bloat = viewMatrix.getMaxScale() * SK_ScalarHalf; | 112 SkScalar bloat = viewMatrix.getMaxScale() * SK_ScalarHalf; |
| 115 bounds.outset(bloat, bloat); | 113 bounds.outset(bloat, bloat); |
| 116 } else { | 114 } else { |
| 117 if (!viewMatrix.invert(&invert)) { | 115 if (!viewMatrix.invert(&invert)) { |
| 118 return false; | 116 return false; |
| 119 } | 117 } |
| 120 } | 118 } |
| 121 const SkMatrix& viewM = viewMatrix.hasPerspective() ? SkMatrix::I() : vi
ewMatrix; | 119 const SkMatrix& viewM = viewMatrix.hasPerspective() ? SkMatrix::I() : vi
ewMatrix; |
| 122 | 120 |
| 123 SkAutoTUnref<GrDrawBatch> coverBatch( | 121 SkAutoTUnref<GrDrawBatch> coverBatch( |
| 124 GrRectBatchFactory::CreateNonAAFill(args.fPaint->getColor(), vie
wM, bounds, | 122 GrRectBatchFactory::CreateNonAAFill(args.fPaint->getColor(), vie
wM, bounds, |
| 125 nullptr, &invert)); | 123 nullptr, &invert)); |
| 126 | 124 |
| 127 // fake inverse with a stencil and cover | 125 // fake inverse with a stencil and cover |
| 128 args.fDrawContext->drawContextPriv().stencilPath(*args.fClip, args.fPain
t->isAntiAlias(), | 126 args.fDrawContext->drawContextPriv().stencilPath(*args.fClip, args.fPain
t->isAntiAlias(), |
| 129 viewMatrix, p); | 127 viewMatrix, path); |
| 130 | 128 |
| 131 { | 129 { |
| 132 static constexpr GrUserStencilSettings kInvertedCoverPass( | 130 static constexpr GrUserStencilSettings kInvertedCoverPass( |
| 133 GrUserStencilSettings::StaticInit< | 131 GrUserStencilSettings::StaticInit< |
| 134 0x0000, | 132 0x0000, |
| 135 // We know our rect will hit pixels outside the clip and the
user bits will | 133 // We know our rect will hit pixels outside the clip and the
user bits will |
| 136 // be 0 outside the clip. So we can't just fill where the us
er bits are 0. We | 134 // be 0 outside the clip. So we can't just fill where the us
er bits are 0. We |
| 137 // also need to check that the clip bit is set. | 135 // also need to check that the clip bit is set. |
| 138 GrUserStencilTest::kEqualIfInClip, | 136 GrUserStencilTest::kEqualIfInClip, |
| 139 0xffff, | 137 0xffff, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 153 static constexpr GrUserStencilSettings kCoverPass( | 151 static constexpr GrUserStencilSettings kCoverPass( |
| 154 GrUserStencilSettings::StaticInit< | 152 GrUserStencilSettings::StaticInit< |
| 155 0x0000, | 153 0x0000, |
| 156 GrUserStencilTest::kNotEqual, | 154 GrUserStencilTest::kNotEqual, |
| 157 0xffff, | 155 0xffff, |
| 158 GrUserStencilOp::kZero, | 156 GrUserStencilOp::kZero, |
| 159 GrUserStencilOp::kKeep, | 157 GrUserStencilOp::kKeep, |
| 160 0xffff>() | 158 0xffff>() |
| 161 ); | 159 ); |
| 162 | 160 |
| 163 SkAutoTUnref<GrDrawBatch> batch( | 161 SkAutoTUnref<GrDrawBatch> batch(GrDrawPathBatch::Create(viewMatrix, args
.fPaint->getColor(), |
| 164 GrDrawPathBatch::Create(viewMatrix, args.fPaint->getColor(), p->
getFillType(), p)); | 162 path)); |
| 165 | 163 |
| 166 GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fPaint->isAntiAlias
()); | 164 GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fPaint->isAntiAlias
()); |
| 167 pipelineBuilder.setUserStencil(&kCoverPass); | 165 pipelineBuilder.setUserStencil(&kCoverPass); |
| 168 if (args.fAntiAlias) { | 166 if (args.fAntiAlias) { |
| 169 SkASSERT(args.fDrawContext->isStencilBufferMultisampled()); | 167 SkASSERT(args.fDrawContext->isStencilBufferMultisampled()); |
| 170 pipelineBuilder.enableState(GrPipelineBuilder::kHWAntialias_Flag); | 168 pipelineBuilder.enableState(GrPipelineBuilder::kHWAntialias_Flag); |
| 171 } | 169 } |
| 172 | 170 |
| 173 args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); | 171 args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); |
| 174 } | 172 } |
| 175 | 173 |
| 176 return true; | 174 return true; |
| 177 } | 175 } |
| OLD | NEW |