| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #ifndef GrPathRenderer_DEFINED | 9 #ifndef GrPathRenderer_DEFINED |
| 10 #define GrPathRenderer_DEFINED | 10 #define GrPathRenderer_DEFINED |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 GrPathRendererChain::kNoSupport_StencilSupport; | 70 GrPathRendererChain::kNoSupport_StencilSupport; |
| 71 static const StencilSupport kStencilOnly_StencilSupport = | 71 static const StencilSupport kStencilOnly_StencilSupport = |
| 72 GrPathRendererChain::kStencilOnly_StencilSupport; | 72 GrPathRendererChain::kStencilOnly_StencilSupport; |
| 73 static const StencilSupport kNoRestriction_StencilSupport = | 73 static const StencilSupport kNoRestriction_StencilSupport = |
| 74 GrPathRendererChain::kNoRestriction_StencilSupport; | 74 GrPathRendererChain::kNoRestriction_StencilSupport; |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * This function is to get the stencil support for a particular path. The pa
th's fill must | 77 * This function is to get the stencil support for a particular path. The pa
th's fill must |
| 78 * not be an inverse type. | 78 * not be an inverse type. |
| 79 * | 79 * |
| 80 * @param target target that the path will be rendered to | |
| 81 * @param path the path that will be drawn | 80 * @param path the path that will be drawn |
| 82 * @param stroke the stroke information (width, join, cap). | 81 * @param stroke the stroke information (width, join, cap). |
| 83 */ | 82 */ |
| 84 StencilSupport getStencilSupport(const GrDrawTarget* target, | 83 StencilSupport getStencilSupport(const SkPath& path, const GrStrokeInfo& str
oke) const { |
| 85 const GrPipelineBuilder* pipelineBuilder, | |
| 86 const SkPath& path, | |
| 87 const GrStrokeInfo& stroke) const { | |
| 88 SkASSERT(!path.isInverseFillType()); | 84 SkASSERT(!path.isInverseFillType()); |
| 89 return this->onGetStencilSupport(target, pipelineBuilder, path, stroke); | 85 return this->onGetStencilSupport(path, stroke); |
| 90 } | 86 } |
| 91 | 87 |
| 92 /** Args to canDrawPath() | 88 /** Args to canDrawPath() |
| 93 * | 89 * |
| 94 * fTarget The target that the path will be rendered to | 90 * fShaderCaps The shader caps |
| 95 * fPipelineBuilder The pipelineBuilder | 91 * fPipelineBuilder The pipelineBuilder |
| 96 * fViewMatrix The viewMatrix | 92 * fViewMatrix The viewMatrix |
| 97 * fPath The path to draw | 93 * fPath The path to draw |
| 98 * fStroke The stroke information (width, join, cap) | 94 * fStroke The stroke information (width, join, cap) |
| 99 * fAntiAlias True if anti-aliasing is required. | 95 * fAntiAlias True if anti-aliasing is required. |
| 100 */ | 96 */ |
| 101 struct CanDrawPathArgs { | 97 struct CanDrawPathArgs { |
| 102 const GrDrawTarget* fTarget; | 98 const GrShaderCaps* fShaderCaps; |
| 103 const GrPipelineBuilder* fPipelineBuilder; | 99 const GrPipelineBuilder* fPipelineBuilder;// only used by GrStencilAn
dCoverPathRenderer |
| 104 const SkMatrix* fViewMatrix; | 100 const SkMatrix* fViewMatrix; |
| 105 const SkPath* fPath; | 101 const SkPath* fPath; |
| 106 const GrStrokeInfo* fStroke; | 102 const GrStrokeInfo* fStroke; |
| 107 bool fAntiAlias; | 103 bool fAntiAlias; |
| 104 |
| 105 void validate() const { |
| 106 SkASSERT(fShaderCaps); |
| 107 SkASSERT(fPipelineBuilder); |
| 108 SkASSERT(fViewMatrix); |
| 109 SkASSERT(fPath); |
| 110 SkASSERT(fStroke); |
| 111 SkASSERT(!fPath->isEmpty()); |
| 112 } |
| 108 }; | 113 }; |
| 109 | 114 |
| 110 /** | 115 /** |
| 111 * Returns true if this path renderer is able to render the path. Returning
false allows the | 116 * Returns true if this path renderer is able to render the path. Returning
false allows the |
| 112 * caller to fallback to another path renderer This function is called when
searching for a path | 117 * caller to fallback to another path renderer This function is called when
searching for a path |
| 113 * renderer capable of rendering a path. | 118 * renderer capable of rendering a path. |
| 114 * | 119 * |
| 115 * @return true if the path can be drawn by this object, false otherwise. | 120 * @return true if the path can be drawn by this object, false otherwise. |
| 116 */ | 121 */ |
| 117 bool canDrawPath(const CanDrawPathArgs& args) const { | 122 bool canDrawPath(const CanDrawPathArgs& args) const { |
| 118 SkASSERT(args.fTarget); | 123 SkDEBUGCODE(args.validate();) |
| 119 SkASSERT(args.fPipelineBuilder); | |
| 120 SkASSERT(args.fViewMatrix); | |
| 121 SkASSERT(args.fPath); | |
| 122 SkASSERT(args.fStroke); | |
| 123 SkASSERT(!args.fPath->isEmpty()); | |
| 124 return this->onCanDrawPath(args); | 124 return this->onCanDrawPath(args); |
| 125 } | 125 } |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * Args to drawPath() | 128 * Args to drawPath() |
| 129 * | 129 * |
| 130 * fTarget The target that the path will be rendered to | 130 * fTarget The target that the path will be rendered to |
| 131 * fResourceProvider The resource provider for creating gpu resources t
o render the path | 131 * fResourceProvider The resource provider for creating gpu resources t
o render the path |
| 132 * fPipelineBuilder The pipelineBuilder | 132 * fPipelineBuilder The pipelineBuilder |
| 133 * fViewMatrix The viewMatrix | 133 * fViewMatrix The viewMatrix |
| 134 * fPath the path to draw. | 134 * fPath the path to draw. |
| 135 * fStroke the stroke information (width, join, cap) | 135 * fStroke the stroke information (width, join, cap) |
| 136 * fAntiAlias true if anti-aliasing is required. | 136 * fAntiAlias true if anti-aliasing is required. |
| 137 */ | 137 */ |
| 138 struct DrawPathArgs { | 138 struct DrawPathArgs { |
| 139 GrDrawTarget* fTarget; | 139 GrDrawTarget* fTarget; |
| 140 GrResourceProvider* fResourceProvider; | 140 GrResourceProvider* fResourceProvider; |
| 141 GrPipelineBuilder* fPipelineBuilder; | 141 GrPipelineBuilder* fPipelineBuilder; |
| 142 GrColor fColor; | 142 GrColor fColor; |
| 143 const SkMatrix* fViewMatrix; | 143 const SkMatrix* fViewMatrix; |
| 144 const SkPath* fPath; | 144 const SkPath* fPath; |
| 145 const GrStrokeInfo* fStroke; | 145 const GrStrokeInfo* fStroke; |
| 146 bool fAntiAlias; | 146 bool fAntiAlias; |
| 147 |
| 148 void validate() const { |
| 149 SkASSERT(fTarget); |
| 150 SkASSERT(fResourceProvider); |
| 151 SkASSERT(fPipelineBuilder); |
| 152 SkASSERT(fViewMatrix); |
| 153 SkASSERT(fPath); |
| 154 SkASSERT(fStroke); |
| 155 SkASSERT(!fPath->isEmpty()); |
| 156 } |
| 147 }; | 157 }; |
| 148 | 158 |
| 149 /** | 159 /** |
| 150 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then | 160 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then |
| 151 * the subclass must respect the stencil settings of the GrPipelineBuilder. | 161 * the subclass must respect the stencil settings of the GrPipelineBuilder. |
| 152 */ | 162 */ |
| 153 bool drawPath(const DrawPathArgs& args) { | 163 bool drawPath(const DrawPathArgs& args) { |
| 154 SkASSERT(args.fTarget); | 164 SkDEBUGCODE(args.validate();) |
| 155 SkASSERT(args.fPipelineBuilder); | |
| 156 SkASSERT(args.fViewMatrix); | |
| 157 SkASSERT(args.fPath); | |
| 158 SkASSERT(args.fStroke); | |
| 159 | |
| 160 SkASSERT(!args.fPath->isEmpty()); | |
| 161 #ifdef SK_DEBUG | 165 #ifdef SK_DEBUG |
| 162 CanDrawPathArgs canArgs; | 166 CanDrawPathArgs canArgs; |
| 163 canArgs.fTarget = args.fTarget; | 167 canArgs.fShaderCaps = args.fTarget->caps()->shaderCaps(); |
| 164 canArgs.fPipelineBuilder = args.fPipelineBuilder; | 168 canArgs.fPipelineBuilder = args.fPipelineBuilder; |
| 165 canArgs.fViewMatrix = args.fViewMatrix; | 169 canArgs.fViewMatrix = args.fViewMatrix; |
| 166 canArgs.fPath = args.fPath; | 170 canArgs.fPath = args.fPath; |
| 167 canArgs.fStroke = args.fStroke; | 171 canArgs.fStroke = args.fStroke; |
| 168 canArgs.fAntiAlias = args.fAntiAlias; | 172 canArgs.fAntiAlias = args.fAntiAlias; |
| 169 SkASSERT(this->canDrawPath(canArgs)); | 173 SkASSERT(this->canDrawPath(canArgs)); |
| 170 SkASSERT(args.fPipelineBuilder->getStencil().isDisabled() || | 174 SkASSERT(args.fPipelineBuilder->getStencil().isDisabled() || |
| 171 kNoRestriction_StencilSupport == this->getStencilSupport(args.f
Target, | 175 kNoRestriction_StencilSupport == this->getStencilSupport(*args.
fPath, |
| 172 args.f
PipelineBuilder, | |
| 173 *args.
fPath, | |
| 174 *args.
fStroke)); | 176 *args.
fStroke)); |
| 175 #endif | 177 #endif |
| 176 return this->onDrawPath(args); | 178 return this->onDrawPath(args); |
| 177 } | 179 } |
| 178 | 180 |
| 179 /* Args to stencilPath(). | 181 /* Args to stencilPath(). |
| 180 * | 182 * |
| 181 * fTarget The target that the path will be rendered to. | 183 * fTarget The target that the path will be rendered to. |
| 184 * fResourceProvider The resource provider for creating gpu resources t
o render the path |
| 182 * fPipelineBuilder The pipeline builder. | 185 * fPipelineBuilder The pipeline builder. |
| 183 * fViewMatrix Matrix applied to the path. | 186 * fViewMatrix Matrix applied to the path. |
| 184 * fPath The path to draw. | 187 * fPath The path to draw. |
| 185 * fStroke The stroke information (width, join, cap) | 188 * fStroke The stroke information (width, join, cap) |
| 186 */ | 189 */ |
| 187 struct StencilPathArgs { | 190 struct StencilPathArgs { |
| 188 GrDrawTarget* fTarget; | 191 GrDrawTarget* fTarget; |
| 192 GrResourceProvider* fResourceProvider; |
| 189 GrPipelineBuilder* fPipelineBuilder; | 193 GrPipelineBuilder* fPipelineBuilder; |
| 190 GrResourceProvider* fResourceProvider; | |
| 191 const SkMatrix* fViewMatrix; | 194 const SkMatrix* fViewMatrix; |
| 192 const SkPath* fPath; | 195 const SkPath* fPath; |
| 193 const GrStrokeInfo* fStroke; | 196 const GrStrokeInfo* fStroke; |
| 197 |
| 198 void validate() const { |
| 199 SkASSERT(fTarget); |
| 200 SkASSERT(fResourceProvider); |
| 201 SkASSERT(fPipelineBuilder); |
| 202 SkASSERT(fViewMatrix); |
| 203 SkASSERT(fPath); |
| 204 SkASSERT(fStroke); |
| 205 SkASSERT(!fPath->isEmpty()); |
| 206 } |
| 194 }; | 207 }; |
| 195 | 208 |
| 196 /** | 209 /** |
| 197 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already | 210 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already |
| 198 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. | 211 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. |
| 199 * | 212 * |
| 200 */ | 213 */ |
| 201 void stencilPath(const StencilPathArgs& args) { | 214 void stencilPath(const StencilPathArgs& args) { |
| 202 SkASSERT(args.fTarget); | 215 SkDEBUGCODE(args.validate();) |
| 203 SkASSERT(args.fPipelineBuilder); | 216 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fPat
h, *args.fStroke)); |
| 204 SkASSERT(args.fResourceProvider); | 217 |
| 205 SkASSERT(args.fViewMatrix); | |
| 206 SkASSERT(args.fPath); | |
| 207 SkASSERT(args.fStroke); | |
| 208 SkASSERT(!args.fPath->isEmpty()); | |
| 209 SkASSERT(kNoSupport_StencilSupport != | |
| 210 this->getStencilSupport(args.fTarget, args.fPipelineBuilder, *a
rgs.fPath, | |
| 211 *args.fStroke)); | |
| 212 this->onStencilPath(args); | 218 this->onStencilPath(args); |
| 213 } | 219 } |
| 214 | 220 |
| 215 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. | 221 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. |
| 216 // If we can, we draw lots faster (raster device does this same test). | 222 // If we can, we draw lots faster (raster device does this same test). |
| 217 static bool IsStrokeHairlineOrEquivalent(const GrStrokeInfo& stroke, const S
kMatrix& matrix, | 223 static bool IsStrokeHairlineOrEquivalent(const GrStrokeInfo& stroke, const S
kMatrix& matrix, |
| 218 SkScalar* outCoverage) { | 224 SkScalar* outCoverage) { |
| 219 if (stroke.isDashed()) { | 225 if (stroke.isDashed()) { |
| 220 return false; | 226 return false; |
| 221 } | 227 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 243 const GrSurface* device, | 249 const GrSurface* device, |
| 244 const SkMatrix& matrix, | 250 const SkMatrix& matrix, |
| 245 SkRect* bounds) { | 251 SkRect* bounds) { |
| 246 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds
); | 252 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds
); |
| 247 } | 253 } |
| 248 | 254 |
| 249 private: | 255 private: |
| 250 /** | 256 /** |
| 251 * Subclass overrides if it has any limitations of stenciling support. | 257 * Subclass overrides if it has any limitations of stenciling support. |
| 252 */ | 258 */ |
| 253 virtual StencilSupport onGetStencilSupport(const GrDrawTarget*, | 259 virtual StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo
&) const { |
| 254 const GrPipelineBuilder*, | |
| 255 const SkPath&, | |
| 256 const GrStrokeInfo&) const { | |
| 257 return kNoRestriction_StencilSupport; | 260 return kNoRestriction_StencilSupport; |
| 258 } | 261 } |
| 259 | 262 |
| 260 /** | 263 /** |
| 261 * Subclass implementation of drawPath() | 264 * Subclass implementation of drawPath() |
| 262 */ | 265 */ |
| 263 virtual bool onDrawPath(const DrawPathArgs& args) = 0; | 266 virtual bool onDrawPath(const DrawPathArgs& args) = 0; |
| 264 | 267 |
| 265 /** | 268 /** |
| 266 * Subclass implementation of canDrawPath() | 269 * Subclass implementation of canDrawPath() |
| (...skipping 24 matching lines...) Expand all Loading... |
| 291 drawArgs.fStroke = args.fStroke; | 294 drawArgs.fStroke = args.fStroke; |
| 292 drawArgs.fAntiAlias = false; | 295 drawArgs.fAntiAlias = false; |
| 293 this->drawPath(drawArgs); | 296 this->drawPath(drawArgs); |
| 294 } | 297 } |
| 295 | 298 |
| 296 | 299 |
| 297 typedef SkRefCnt INHERITED; | 300 typedef SkRefCnt INHERITED; |
| 298 }; | 301 }; |
| 299 | 302 |
| 300 #endif | 303 #endif |
| OLD | NEW |