| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #ifndef GrPathRenderer_DEFINED | 8 #ifndef GrPathRenderer_DEFINED |
| 9 #define GrPathRenderer_DEFINED | 9 #define GrPathRenderer_DEFINED |
| 10 | 10 |
| 11 #include "GrDrawContext.h" | 11 #include "GrDrawContext.h" |
| 12 #include "GrPaint.h" | 12 #include "GrPaint.h" |
| 13 #include "GrResourceProvider.h" | 13 #include "GrResourceProvider.h" |
| 14 #include "GrStyle.h" | 14 #include "GrShape.h" |
| 15 | 15 |
| 16 #include "SkDrawProcs.h" | 16 #include "SkDrawProcs.h" |
| 17 #include "SkTArray.h" | 17 #include "SkTArray.h" |
| 18 | 18 |
| 19 class SkPath; | 19 class SkPath; |
| 20 class GrFixedClip; | 20 class GrFixedClip; |
| 21 struct GrPoint; | 21 struct GrPoint; |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Base class for drawing paths into a GrDrawTarget. | 24 * Base class for drawing paths into a GrDrawTarget. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 53 enum StencilSupport { | 53 enum StencilSupport { |
| 54 kNoSupport_StencilSupport, | 54 kNoSupport_StencilSupport, |
| 55 kStencilOnly_StencilSupport, | 55 kStencilOnly_StencilSupport, |
| 56 kNoRestriction_StencilSupport, | 56 kNoRestriction_StencilSupport, |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * This function is to get the stencil support for a particular path. The pa
th's fill must | 60 * This function is to get the stencil support for a particular path. The pa
th's fill must |
| 61 * not be an inverse type. The path will always be filled and not stroked. | 61 * not be an inverse type. The path will always be filled and not stroked. |
| 62 * | 62 * |
| 63 * @param path the path that will be drawn | 63 * @param shape the shape that will be drawn. Must be simple fill styled a
nd non-inverse |
| 64 * filled. |
| 64 */ | 65 */ |
| 65 StencilSupport getStencilSupport(const SkPath& path) const { | 66 StencilSupport getStencilSupport(const GrShape& shape) const { |
| 67 SkDEBUGCODE(SkPath path;) |
| 68 SkDEBUGCODE(shape.asPath(&path);) |
| 69 SkASSERT(shape.style().isSimpleFill()); |
| 66 SkASSERT(!path.isInverseFillType()); | 70 SkASSERT(!path.isInverseFillType()); |
| 67 return this->onGetStencilSupport(path); | 71 return this->onGetStencilSupport(shape); |
| 68 } | 72 } |
| 69 | 73 |
| 70 /** Args to canDrawPath() | 74 /** Args to canDrawPath() |
| 71 * | 75 * |
| 72 * fShaderCaps The shader caps | 76 * fShaderCaps The shader caps |
| 73 * fPipelineBuilder The pipelineBuilder | 77 * fPipelineBuilder The pipelineBuilder |
| 74 * fViewMatrix The viewMatrix | 78 * fViewMatrix The viewMatrix |
| 75 * fPath The path to draw | 79 * fShape The shape to draw |
| 76 * fStyle The styling info (path effect, stroking info) | |
| 77 * fAntiAlias True if anti-aliasing is required. | 80 * fAntiAlias True if anti-aliasing is required. |
| 78 */ | 81 */ |
| 79 struct CanDrawPathArgs { | 82 struct CanDrawPathArgs { |
| 80 const GrShaderCaps* fShaderCaps; | 83 const GrShaderCaps* fShaderCaps; |
| 81 const SkMatrix* fViewMatrix; | 84 const SkMatrix* fViewMatrix; |
| 82 const SkPath* fPath; | 85 const GrShape* fShape; |
| 83 const GrStyle* fStyle; | |
| 84 bool fAntiAlias; | 86 bool fAntiAlias; |
| 85 | 87 |
| 86 // These next two are only used by GrStencilAndCoverPathRenderer | 88 // These next two are only used by GrStencilAndCoverPathRenderer |
| 87 bool fHasUserStencilSettings; | 89 bool fHasUserStencilSettings; |
| 88 bool fIsStencilBufferMSAA; | 90 bool fIsStencilBufferMSAA; |
| 89 | 91 |
| 92 #ifdef SK_DEBUG |
| 90 void validate() const { | 93 void validate() const { |
| 91 SkASSERT(fShaderCaps); | 94 SkASSERT(fShaderCaps); |
| 92 SkASSERT(fViewMatrix); | 95 SkASSERT(fViewMatrix); |
| 93 SkASSERT(fPath); | 96 SkASSERT(fShape); |
| 94 SkASSERT(fStyle); | |
| 95 SkASSERT(!fPath->isEmpty()); | |
| 96 } | 97 } |
| 98 #endif |
| 97 }; | 99 }; |
| 98 | 100 |
| 99 /** | 101 /** |
| 100 * Returns true if this path renderer is able to render the path. Returning
false allows the | 102 * Returns true if this path renderer is able to render the path. Returning
false allows the |
| 101 * caller to fallback to another path renderer This function is called when
searching for a path | 103 * caller to fallback to another path renderer This function is called when
searching for a path |
| 102 * renderer capable of rendering a path. | 104 * renderer capable of rendering a path. |
| 103 * | 105 * |
| 104 * @return true if the path can be drawn by this object, false otherwise. | 106 * @return true if the path can be drawn by this object, false otherwise. |
| 105 */ | 107 */ |
| 106 bool canDrawPath(const CanDrawPathArgs& args) const { | 108 bool canDrawPath(const CanDrawPathArgs& args) const { |
| 107 SkDEBUGCODE(args.validate();) | 109 SkDEBUGCODE(args.validate();) |
| 108 return this->onCanDrawPath(args); | 110 return this->onCanDrawPath(args); |
| 109 } | 111 } |
| 110 | 112 |
| 111 /** | 113 /** |
| 112 * Args to drawPath() | 114 * Args to drawPath() |
| 113 * | 115 * |
| 114 * fTarget The target that the path will be rendered to | 116 * fTarget The target that the path will be rendered to |
| 115 * fResourceProvider The resource provider for creating gpu resources t
o render the path | 117 * fResourceProvider The resource provider for creating gpu resources t
o render the path |
| 116 * fPipelineBuilder The pipelineBuilder | 118 * fPipelineBuilder The pipelineBuilder |
| 117 * fClip The clip | 119 * fClip The clip |
| 118 * fColor Color to render with | 120 * fColor Color to render with |
| 119 * fViewMatrix The viewMatrix | 121 * fViewMatrix The viewMatrix |
| 120 * fPath the path to draw. | 122 * fShape The shape to draw |
| 121 * fStyle the style information (path effect, stroke info) | |
| 122 * fAntiAlias true if anti-aliasing is required. | 123 * fAntiAlias true if anti-aliasing is required. |
| 123 * fGammaCorrect true if gamma-correct rendering is to be used. | 124 * fGammaCorrect true if gamma-correct rendering is to be used. |
| 124 */ | 125 */ |
| 125 struct DrawPathArgs { | 126 struct DrawPathArgs { |
| 126 GrResourceProvider* fResourceProvider; | 127 GrResourceProvider* fResourceProvider; |
| 127 const GrPaint* fPaint; | 128 const GrPaint* fPaint; |
| 128 const GrUserStencilSettings*fUserStencilSettings; | 129 const GrUserStencilSettings*fUserStencilSettings; |
| 129 | 130 |
| 130 GrDrawContext* fDrawContext; | 131 GrDrawContext* fDrawContext; |
| 131 const GrClip* fClip; | 132 const GrClip* fClip; |
| 132 GrColor fColor; | 133 GrColor fColor; |
| 133 const SkMatrix* fViewMatrix; | 134 const SkMatrix* fViewMatrix; |
| 134 const SkPath* fPath; | 135 const GrShape* fShape; |
| 135 const GrStyle* fStyle; | |
| 136 bool fAntiAlias; | 136 bool fAntiAlias; |
| 137 bool fGammaCorrect; | 137 bool fGammaCorrect; |
| 138 | 138 #ifdef SK_DEBUG |
| 139 void validate() const { | 139 void validate() const { |
| 140 SkASSERT(fResourceProvider); | 140 SkASSERT(fResourceProvider); |
| 141 SkASSERT(fPaint); | 141 SkASSERT(fPaint); |
| 142 SkASSERT(fUserStencilSettings); | 142 SkASSERT(fUserStencilSettings); |
| 143 SkASSERT(fDrawContext); | 143 SkASSERT(fDrawContext); |
| 144 SkASSERT(fClip); | 144 SkASSERT(fClip); |
| 145 SkASSERT(fViewMatrix); | 145 SkASSERT(fViewMatrix); |
| 146 SkASSERT(fPath); | 146 SkASSERT(fShape); |
| 147 SkASSERT(fStyle); | |
| 148 SkASSERT(!fPath->isEmpty()); | |
| 149 } | 147 } |
| 148 #endif |
| 150 }; | 149 }; |
| 151 | 150 |
| 152 /** | 151 /** |
| 153 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then | 152 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then |
| 154 * the subclass must respect the stencil settings of the GrPipelineBuilder. | 153 * the subclass must respect the stencil settings of the GrPipelineBuilder. |
| 155 */ | 154 */ |
| 156 bool drawPath(const DrawPathArgs& args) { | 155 bool drawPath(const DrawPathArgs& args) { |
| 157 SkDEBUGCODE(args.validate();) | 156 SkDEBUGCODE(args.validate();) |
| 158 #ifdef SK_DEBUG | 157 #ifdef SK_DEBUG |
| 159 CanDrawPathArgs canArgs; | 158 CanDrawPathArgs canArgs; |
| 160 canArgs.fShaderCaps = args.fResourceProvider->caps()->shaderCaps(); | 159 canArgs.fShaderCaps = args.fResourceProvider->caps()->shaderCaps(); |
| 161 canArgs.fViewMatrix = args.fViewMatrix; | 160 canArgs.fViewMatrix = args.fViewMatrix; |
| 162 canArgs.fPath = args.fPath; | 161 canArgs.fShape = args.fShape; |
| 163 canArgs.fStyle = args.fStyle; | |
| 164 canArgs.fAntiAlias = args.fAntiAlias; | 162 canArgs.fAntiAlias = args.fAntiAlias; |
| 165 | 163 |
| 166 canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused()
; | 164 canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused()
; |
| 167 canArgs.fIsStencilBufferMSAA = args.fDrawContext->isStencilBufferMultisa
mpled(); | 165 canArgs.fIsStencilBufferMSAA = args.fDrawContext->isStencilBufferMultisa
mpled(); |
| 168 SkASSERT(this->canDrawPath(canArgs)); | 166 SkASSERT(this->canDrawPath(canArgs)); |
| 169 if (!args.fUserStencilSettings->isUnused()) { | 167 if (!args.fUserStencilSettings->isUnused()) { |
| 170 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*a
rgs.fPath)); | 168 SkPath path; |
| 171 SkASSERT(args.fStyle->isSimpleFill()); | 169 args.fShape->asPath(&path); |
| 170 SkASSERT(args.fShape->style().isSimpleFill()); |
| 171 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*a
rgs.fShape)); |
| 172 } | 172 } |
| 173 #endif | 173 #endif |
| 174 return this->onDrawPath(args); | 174 return this->onDrawPath(args); |
| 175 } | 175 } |
| 176 | 176 |
| 177 /* Args to stencilPath(). | 177 /* Args to stencilPath(). |
| 178 * | 178 * |
| 179 * fResourceProvider The resource provider for creating gpu resources t
o render the path | 179 * fResourceProvider The resource provider for creating gpu resources t
o render the path |
| 180 * fDrawContext The target of the draws | 180 * fDrawContext The target of the draws |
| 181 * fViewMatrix Matrix applied to the path. | 181 * fViewMatrix Matrix applied to the path. |
| 182 * fPath The path to draw. | 182 * fPath The path to draw. |
| 183 * fIsAA Is the path to be drawn AA (only set when MSAA is
available) | 183 * fIsAA Is the path to be drawn AA (only set when MSAA is
available) |
| 184 */ | 184 */ |
| 185 struct StencilPathArgs { | 185 struct StencilPathArgs { |
| 186 GrResourceProvider* fResourceProvider; | 186 GrResourceProvider* fResourceProvider; |
| 187 GrDrawContext* fDrawContext; | 187 GrDrawContext* fDrawContext; |
| 188 const GrFixedClip* fClip; | 188 const GrFixedClip* fClip; |
| 189 const SkMatrix* fViewMatrix; | 189 const SkMatrix* fViewMatrix; |
| 190 const SkPath* fPath; | |
| 191 bool fIsAA; | 190 bool fIsAA; |
| 191 const GrShape* fShape; |
| 192 | 192 |
| 193 #ifdef SK_DEBUG |
| 193 void validate() const { | 194 void validate() const { |
| 194 SkASSERT(fResourceProvider); | 195 SkASSERT(fResourceProvider); |
| 195 SkASSERT(fDrawContext); | 196 SkASSERT(fDrawContext); |
| 196 SkASSERT(fViewMatrix); | 197 SkASSERT(fViewMatrix); |
| 197 SkASSERT(fPath); | 198 SkASSERT(fShape); |
| 198 SkASSERT(!fPath->isEmpty()); | 199 SkASSERT(fShape->style().isSimpleFill()) |
| 200 SkPath path; |
| 201 fShape->asPath(&path); |
| 202 SkASSERT(!path.isInverseFillType()); |
| 199 } | 203 } |
| 204 #endif |
| 200 }; | 205 }; |
| 201 | 206 |
| 202 /** | 207 /** |
| 203 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already | 208 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already |
| 204 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. | 209 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. |
| 205 */ | 210 */ |
| 206 void stencilPath(const StencilPathArgs& args) { | 211 void stencilPath(const StencilPathArgs& args) { |
| 207 SkDEBUGCODE(args.validate();) | 212 SkDEBUGCODE(args.validate();) |
| 208 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fPat
h)); | 213 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fSha
pe)); |
| 209 this->onStencilPath(args); | 214 this->onStencilPath(args); |
| 210 } | 215 } |
| 211 | 216 |
| 212 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. | 217 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. |
| 213 // If we can, we draw lots faster (raster device does this same test). | 218 // If we can, we draw lots faster (raster device does this same test). |
| 214 static bool IsStrokeHairlineOrEquivalent(const GrStyle& style, const SkMatri
x& matrix, | 219 static bool IsStrokeHairlineOrEquivalent(const GrStyle& style, const SkMatri
x& matrix, |
| 215 SkScalar* outCoverage) { | 220 SkScalar* outCoverage) { |
| 216 if (style.pathEffect()) { | 221 if (style.pathEffect()) { |
| 217 return false; | 222 return false; |
| 218 } | 223 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 233 static void GetPathDevBounds(const SkPath& path, | 238 static void GetPathDevBounds(const SkPath& path, |
| 234 int devW, | 239 int devW, |
| 235 int devH, | 240 int devH, |
| 236 const SkMatrix& matrix, | 241 const SkMatrix& matrix, |
| 237 SkRect* bounds); | 242 SkRect* bounds); |
| 238 | 243 |
| 239 private: | 244 private: |
| 240 /** | 245 /** |
| 241 * Subclass overrides if it has any limitations of stenciling support. | 246 * Subclass overrides if it has any limitations of stenciling support. |
| 242 */ | 247 */ |
| 243 virtual StencilSupport onGetStencilSupport(const SkPath&) const { | 248 virtual StencilSupport onGetStencilSupport(const GrShape&) const { |
| 244 return kNoRestriction_StencilSupport; | 249 return kNoRestriction_StencilSupport; |
| 245 } | 250 } |
| 246 | 251 |
| 247 /** | 252 /** |
| 248 * Subclass implementation of drawPath() | 253 * Subclass implementation of drawPath() |
| 249 */ | 254 */ |
| 250 virtual bool onDrawPath(const DrawPathArgs& args) = 0; | 255 virtual bool onDrawPath(const DrawPathArgs& args) = 0; |
| 251 | 256 |
| 252 /** | 257 /** |
| 253 * Subclass implementation of canDrawPath() | 258 * Subclass implementation of canDrawPath() |
| (...skipping 17 matching lines...) Expand all Loading... |
| 271 | 276 |
| 272 GrPaint paint; | 277 GrPaint paint; |
| 273 | 278 |
| 274 DrawPathArgs drawArgs; | 279 DrawPathArgs drawArgs; |
| 275 drawArgs.fResourceProvider = args.fResourceProvider; | 280 drawArgs.fResourceProvider = args.fResourceProvider; |
| 276 drawArgs.fPaint = &paint; | 281 drawArgs.fPaint = &paint; |
| 277 drawArgs.fUserStencilSettings = &kIncrementStencil; | 282 drawArgs.fUserStencilSettings = &kIncrementStencil; |
| 278 drawArgs.fDrawContext = args.fDrawContext; | 283 drawArgs.fDrawContext = args.fDrawContext; |
| 279 drawArgs.fColor = GrColor_WHITE; | 284 drawArgs.fColor = GrColor_WHITE; |
| 280 drawArgs.fViewMatrix = args.fViewMatrix; | 285 drawArgs.fViewMatrix = args.fViewMatrix; |
| 281 drawArgs.fPath = args.fPath; | 286 drawArgs.fShape = args.fShape; |
| 282 drawArgs.fStyle = &GrStyle::SimpleFill(); | |
| 283 drawArgs.fAntiAlias = false; // In this case the MSAA handles the AA so
we want to draw BW | 287 drawArgs.fAntiAlias = false; // In this case the MSAA handles the AA so
we want to draw BW |
| 284 drawArgs.fGammaCorrect = false; | 288 drawArgs.fGammaCorrect = false; |
| 285 this->drawPath(drawArgs); | 289 this->drawPath(drawArgs); |
| 286 } | 290 } |
| 287 | 291 |
| 288 typedef SkRefCnt INHERITED; | 292 typedef SkRefCnt INHERITED; |
| 289 }; | 293 }; |
| 290 | 294 |
| 291 #endif | 295 #endif |
| OLD | NEW |