| 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 27 matching lines...) Expand all  Loading... | 
| 38         return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (resourceProvider)); | 38         return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (resourceProvider)); | 
| 39     } else { | 39     } else { | 
| 40         return NULL; | 40         return NULL; | 
| 41     } | 41     } | 
| 42 } | 42 } | 
| 43 | 43 | 
| 44 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrResourceProvider*
      resourceProvider) | 44 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrResourceProvider*
      resourceProvider) | 
| 45     : fResourceProvider(resourceProvider) { | 45     : fResourceProvider(resourceProvider) { | 
| 46 } | 46 } | 
| 47 | 47 | 
| 48 bool GrStencilAndCoverPathRenderer::canDrawPath(const GrDrawTarget* target, | 48 bool GrStencilAndCoverPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c
     onst { | 
| 49                                                 const GrPipelineBuilder* pipelin
     eBuilder, | 49     if (args.fStroke->isHairlineStyle()) { | 
| 50                                                 const SkMatrix& viewMatrix, |  | 
| 51                                                 const SkPath& path, |  | 
| 52                                                 const GrStrokeInfo& stroke, |  | 
| 53                                                 bool antiAlias) const { |  | 
| 54     if (stroke.isHairlineStyle()) { |  | 
| 55         return false; | 50         return false; | 
| 56     } | 51     } | 
| 57     if (!pipelineBuilder->getStencil().isDisabled()) { | 52     if (!args.fPipelineBuilder->getStencil().isDisabled()) { | 
| 58         return false; | 53         return false; | 
| 59     } | 54     } | 
| 60     if (antiAlias) { | 55     if (args.fAntiAlias) { | 
| 61         return pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled()
     ; | 56         return args.fPipelineBuilder->getRenderTarget()->isStencilBufferMultisam
     pled(); | 
| 62     } else { | 57     } else { | 
| 63         return true; // doesn't do per-path AA, relies on the target having MSAA | 58         return true; // doesn't do per-path AA, relies on the target having MSAA | 
| 64     } | 59     } | 
| 65 } | 60 } | 
| 66 | 61 | 
| 67 GrPathRenderer::StencilSupport | 62 GrPathRenderer::StencilSupport | 
| 68 GrStencilAndCoverPathRenderer::onGetStencilSupport(const GrDrawTarget*, | 63 GrStencilAndCoverPathRenderer::onGetStencilSupport(const GrDrawTarget*, | 
| 69                                                    const GrPipelineBuilder*, | 64                                                    const GrPipelineBuilder*, | 
| 70                                                    const SkPath&, | 65                                                    const SkPath&, | 
| 71                                                    const GrStrokeInfo&) const { | 66                                                    const GrStrokeInfo&) const { | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 83         path.reset(resourceProvider->createPath(skPath, stroke)); | 78         path.reset(resourceProvider->createPath(skPath, stroke)); | 
| 84         if (!isVolatile) { | 79         if (!isVolatile) { | 
| 85             resourceProvider->assignUniqueKeyToResource(key, path); | 80             resourceProvider->assignUniqueKeyToResource(key, path); | 
| 86         } | 81         } | 
| 87     } else { | 82     } else { | 
| 88         SkASSERT(path->isEqualTo(skPath, stroke)); | 83         SkASSERT(path->isEqualTo(skPath, stroke)); | 
| 89     } | 84     } | 
| 90     return path.detach(); | 85     return path.detach(); | 
| 91 } | 86 } | 
| 92 | 87 | 
| 93 void GrStencilAndCoverPathRenderer::onStencilPath(GrDrawTarget* target, | 88 void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) { | 
| 94                                                   GrPipelineBuilder* pipelineBui
     lder, | 89     SkASSERT(!args.fPath->isInverseFillType()); | 
| 95                                                   const SkMatrix& viewMatrix, | 90     SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE, *arg
     s.fViewMatrix)); | 
| 96                                                   const SkPath& path, | 91     SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fPath, *args.fSt
     roke)); | 
| 97                                                   const GrStrokeInfo& stroke) { | 92     args.fTarget->stencilPath(*args.fPipelineBuilder, pp, p, | 
| 98     SkASSERT(!path.isInverseFillType()); | 93                               convert_skpath_filltype(args.fPath->getFillType())
     ); | 
| 99     SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE, view
     Matrix)); |  | 
| 100     SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, stroke)); |  | 
| 101     target->stencilPath(*pipelineBuilder, pp, p, convert_skpath_filltype(path.ge
     tFillType())); |  | 
| 102 } | 94 } | 
| 103 | 95 | 
| 104 bool GrStencilAndCoverPathRenderer::onDrawPath(GrDrawTarget* target, | 96 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { | 
| 105                                                GrPipelineBuilder* pipelineBuilde
     r, | 97     SkASSERT(!args.fStroke->isHairlineStyle()); | 
| 106                                                GrColor color, | 98     const SkPath& path = *args.fPath; | 
| 107                                                const SkMatrix& viewMatrix, | 99     GrPipelineBuilder* pipelineBuilder = args.fPipelineBuilder; | 
| 108                                                const SkPath& path, | 100     const SkMatrix& viewMatrix = *args.fViewMatrix; | 
| 109                                                const GrStrokeInfo& stroke, | 101 | 
| 110                                                bool antiAlias) { |  | 
| 111     SkASSERT(!stroke.isHairlineStyle()); |  | 
| 112     SkASSERT(pipelineBuilder->getStencil().isDisabled()); | 102     SkASSERT(pipelineBuilder->getStencil().isDisabled()); | 
| 113 | 103 | 
| 114     if (antiAlias) { | 104     if (args.fAntiAlias) { | 
| 115         SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled
     ()); | 105         SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled
     ()); | 
| 116         pipelineBuilder->enableState(GrPipelineBuilder::kHWAntialias_Flag); | 106         pipelineBuilder->enableState(GrPipelineBuilder::kHWAntialias_Flag); | 
| 117     } | 107     } | 
| 118 | 108 | 
| 119     SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, stroke)); | 109     SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, *args.fStroke)); | 
| 120 | 110 | 
| 121     if (path.isInverseFillType()) { | 111     if (path.isInverseFillType()) { | 
| 122         GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, | 112         GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, | 
| 123             kZero_StencilOp, | 113             kZero_StencilOp, | 
| 124             kZero_StencilOp, | 114             kZero_StencilOp, | 
| 125             // We know our rect will hit pixels outside the clip and the user bi
     ts will be 0 | 115             // We know our rect will hit pixels outside the clip and the user bi
     ts will be 0 | 
| 126             // outside the clip. So we can't just fill where the user bits are 0
     . We also need to | 116             // outside the clip. So we can't just fill where the user bits are 0
     . We also need to | 
| 127             // check that the clip bit is set. | 117             // check that the clip bit is set. | 
| 128             kEqualIfInClip_StencilFunc, | 118             kEqualIfInClip_StencilFunc, | 
| 129             0xffff, | 119             0xffff, | 
| 130             0x0000, | 120             0x0000, | 
| 131             0xffff); | 121             0xffff); | 
| 132 | 122 | 
| 133         pipelineBuilder->setStencil(kInvertedStencilPass); | 123         pipelineBuilder->setStencil(kInvertedStencilPass); | 
| 134 | 124 | 
| 135         // fake inverse with a stencil and cover | 125         // fake inverse with a stencil and cover | 
| 136         SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE, 
     viewMatrix)); | 126         SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(GrColor_WHITE, 
     viewMatrix)); | 
| 137         target->stencilPath(*pipelineBuilder, pp, p, convert_skpath_filltype(pat
     h.getFillType())); | 127         args.fTarget->stencilPath(*pipelineBuilder, pp, p, | 
|  | 128                                   convert_skpath_filltype(path.getFillType())); | 
| 138 | 129 | 
| 139         SkMatrix invert = SkMatrix::I(); | 130         SkMatrix invert = SkMatrix::I(); | 
| 140         SkRect bounds = | 131         SkRect bounds = | 
| 141             SkRect::MakeLTRB(0, 0, SkIntToScalar(pipelineBuilder->getRenderTarge
     t()->width()), | 132             SkRect::MakeLTRB(0, 0, SkIntToScalar(pipelineBuilder->getRenderTarge
     t()->width()), | 
| 142                              SkIntToScalar(pipelineBuilder->getRenderTarget()->h
     eight())); | 133                              SkIntToScalar(pipelineBuilder->getRenderTarget()->h
     eight())); | 
| 143         SkMatrix vmi; | 134         SkMatrix vmi; | 
| 144         // mapRect through persp matrix may not be correct | 135         // mapRect through persp matrix may not be correct | 
| 145         if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { | 136         if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { | 
| 146             vmi.mapRect(&bounds); | 137             vmi.mapRect(&bounds); | 
| 147             // theoretically could set bloat = 0, instead leave it because of ma
     trix inversion | 138             // theoretically could set bloat = 0, instead leave it because of ma
     trix inversion | 
| 148             // precision. | 139             // precision. | 
| 149             SkScalar bloat = viewMatrix.getMaxScale() * SK_ScalarHalf; | 140             SkScalar bloat = viewMatrix.getMaxScale() * SK_ScalarHalf; | 
| 150             bounds.outset(bloat, bloat); | 141             bounds.outset(bloat, bloat); | 
| 151         } else { | 142         } else { | 
| 152             if (!viewMatrix.invert(&invert)) { | 143             if (!viewMatrix.invert(&invert)) { | 
| 153                 return false; | 144                 return false; | 
| 154             } | 145             } | 
| 155         } | 146         } | 
| 156         const SkMatrix& viewM = viewMatrix.hasPerspective() ? SkMatrix::I() : vi
     ewMatrix; | 147         const SkMatrix& viewM = viewMatrix.hasPerspective() ? SkMatrix::I() : vi
     ewMatrix; | 
| 157         target->drawBWRect(*pipelineBuilder, color, viewM, bounds, NULL, &invert
     ); | 148         args.fTarget->drawBWRect(*pipelineBuilder, args.fColor, viewM, bounds, N
     ULL, &invert); | 
| 158     } else { | 149     } else { | 
| 159         GR_STATIC_CONST_SAME_STENCIL(kStencilPass, | 150         GR_STATIC_CONST_SAME_STENCIL(kStencilPass, | 
| 160             kZero_StencilOp, | 151             kZero_StencilOp, | 
| 161             kZero_StencilOp, | 152             kZero_StencilOp, | 
| 162             kNotEqual_StencilFunc, | 153             kNotEqual_StencilFunc, | 
| 163             0xffff, | 154             0xffff, | 
| 164             0x0000, | 155             0x0000, | 
| 165             0xffff); | 156             0xffff); | 
| 166 | 157 | 
| 167         pipelineBuilder->setStencil(kStencilPass); | 158         pipelineBuilder->setStencil(kStencilPass); | 
| 168         SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(color, viewMatr
     ix)); | 159         SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(args.fColor, vi
     ewMatrix)); | 
| 169         target->drawPath(*pipelineBuilder, pp, p, convert_skpath_filltype(path.g
     etFillType())); | 160         args.fTarget->drawPath(*pipelineBuilder, pp, p, | 
|  | 161                                convert_skpath_filltype(path.getFillType())); | 
| 170     } | 162     } | 
| 171 | 163 | 
| 172     pipelineBuilder->stencil()->setDisabled(); | 164     pipelineBuilder->stencil()->setDisabled(); | 
| 173     return true; | 165     return true; | 
| 174 } | 166 } | 
| OLD | NEW | 
|---|