Index: src/gpu/GrPathRenderer.h |
=================================================================== |
--- src/gpu/GrPathRenderer.h (revision 13379) |
+++ src/gpu/GrPathRenderer.h (working copy) |
@@ -74,70 +74,108 @@ |
GrPathRendererChain::kNoRestriction_StencilSupport; |
/** |
- * This function is to get the stencil support for a particular path. The path's fill must |
+ * This function is to get the stencil support for the current path. The path's fill must |
* not be an inverse type. |
* |
+ * @param stroke the stroke information (width, join, cap). |
* @param target target that the path will be rendered to |
- * @param path the path that will be drawn |
- * @param stroke the stroke information (width, join, cap). |
*/ |
- StencilSupport getStencilSupport(const SkPath& path, |
- const SkStrokeRec& stroke, |
+ StencilSupport getStencilSupport(const SkStrokeRec& stroke, |
const GrDrawTarget* target) const { |
- SkASSERT(!path.isInverseFillType()); |
- return this->onGetStencilSupport(path, stroke, target); |
+ SkASSERT(!fPath.isInverseFillType()); |
+ return this->onGetStencilSupport(stroke, target); |
} |
+ // Set the path and fill type the path renderer is to use. |
+ // 'fillType' is included as a parameter b.c. we often want to draw |
+ // inverse filled paths normally filled. |
+ void setPath(const SkPath& path, SkPath::FillType fillType) { |
+ SkASSERT(fPath.isEmpty()); |
+ fPath = path; |
+ fPath.setFillType(fillType); |
+ } |
+ |
+ void resetPath() { |
+ fPath.reset(); |
+ } |
+ |
/** |
- * Returns true if this path renderer is able to render the path. Returning false allows the |
- * caller to fallback to another path renderer This function is called when searching for a path |
- * renderer capable of rendering a path. |
+ * Returns true if this path renderer is able to render the current path. Returning false |
+ * allows the caller to fallback to another path renderer This function is called when |
+ * searching for a path renderer capable of rendering a path. |
* |
- * @param path The path to draw |
* @param stroke The stroke information (width, join, cap) |
* @param target The target that the path will be rendered to |
* @param antiAlias True if anti-aliasing is required. |
* |
* @return true if the path can be drawn by this object, false otherwise. |
*/ |
- virtual bool canDrawPath(const SkPath& path, |
- const SkStrokeRec& rec, |
+ virtual bool canDrawPath(const SkStrokeRec& stroke, |
const GrDrawTarget* target, |
bool antiAlias) const = 0; |
/** |
- * Draws the path into the draw target. If getStencilSupport() would return kNoRestriction then |
- * the subclass must respect the stencil settings of the target's draw state. |
+ * Draws the current path into the draw target. If getStencilSupport() would return |
+ * kNoRestriction then the subclass must respect the stencil settings of the |
+ * target's draw state. |
* |
- * @param path the path to draw. |
* @param stroke the stroke information (width, join, cap) |
* @param target target that the path will be rendered to |
* @param antiAlias true if anti-aliasing is required. |
*/ |
- bool drawPath(const SkPath& path, |
- const SkStrokeRec& stroke, |
+ bool drawPath(const SkStrokeRec& stroke, |
GrDrawTarget* target, |
bool antiAlias) { |
- SkASSERT(!path.isEmpty()); |
- SkASSERT(this->canDrawPath(path, stroke, target, antiAlias)); |
+ SkASSERT(!fPath.isEmpty()); |
+ SkASSERT(this->canDrawPath(stroke, target, antiAlias)); |
SkASSERT(target->drawState()->getStencil().isDisabled() || |
- kNoRestriction_StencilSupport == this->getStencilSupport(path, stroke, target)); |
- return this->onDrawPath(path, stroke, target, antiAlias); |
+ kNoRestriction_StencilSupport == this->getStencilSupport(stroke, target)); |
+ return this->onDrawPath(stroke, target, antiAlias); |
} |
/** |
- * Draws the path to the stencil buffer. Assume the writable stencil bits are already |
- * initialized to zero. The pixels inside the path will have non-zero stencil values afterwards. |
+ * Draws the current path to the stencil buffer. Assume the writable stencil bits are already |
+ * initialized to zero. The pixels inside the path will have non-zero stencil values |
+ * afterwards. |
* |
- * @param path the path to draw. |
* @param stroke the stroke information (width, join, cap) |
* @param target target that the path will be rendered to |
*/ |
- void stencilPath(const SkPath& path, const SkStrokeRec& stroke, GrDrawTarget* target) { |
- SkASSERT(!path.isEmpty()); |
- SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(path, stroke, target)); |
- this->onStencilPath(path, stroke, target); |
+ void stencilPath(const SkStrokeRec& stroke, GrDrawTarget* target) { |
+ SkASSERT(!fPath.isEmpty()); |
+ SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(stroke, target)); |
+ this->onStencilPath(stroke, target); |
} |
+ class AutoClearPath : ::SkNoncopyable { |
+ public: |
+ AutoClearPath(GrPathRenderer* renderer) : fRenderer(renderer) {} |
+ AutoClearPath() : fRenderer(NULL) {} |
+ ~AutoClearPath() { |
+ this->reset(); |
+ } |
+ |
+ GrPathRenderer* renderer() { |
+ return fRenderer; |
+ } |
+ |
+ void set(GrPathRenderer* renderer) { |
+ this->reset(); |
+ fRenderer = renderer; |
+ } |
+ |
+ GrPathRenderer* operator->() { return fRenderer; } |
+ |
+ private: |
+ void reset() { |
+ if (NULL != fRenderer) { |
+ fRenderer->resetPath(); |
+ } |
+ fRenderer = NULL; |
+ } |
+ |
+ GrPathRenderer* fRenderer; |
+ }; |
+ |
// Helper for determining if we can treat a thin stroke as a hairline w/ coverage. |
// If we can, we draw lots faster (raster device does this same test). |
static bool IsStrokeHairlineOrEquivalent(const SkStrokeRec& stroke, const SkMatrix& matrix, |
@@ -153,11 +191,14 @@ |
} |
protected: |
+ const SkPath& path() const { |
+ return fPath; |
+ } |
+ |
/** |
* Subclass overrides if it has any limitations of stenciling support. |
*/ |
- virtual StencilSupport onGetStencilSupport(const SkPath&, |
- const SkStrokeRec&, |
+ virtual StencilSupport onGetStencilSupport(const SkStrokeRec&, |
const GrDrawTarget*) const { |
return kNoRestriction_StencilSupport; |
} |
@@ -165,8 +206,7 @@ |
/** |
* Subclass implementation of drawPath() |
*/ |
- virtual bool onDrawPath(const SkPath& path, |
- const SkStrokeRec& stroke, |
+ virtual bool onDrawPath(const SkStrokeRec& stroke, |
GrDrawTarget* target, |
bool antiAlias) = 0; |
@@ -174,7 +214,7 @@ |
* Subclass implementation of stencilPath(). Subclass must override iff it ever returns |
* kStencilOnly in onGetStencilSupport(). |
*/ |
- virtual void onStencilPath(const SkPath& path, const SkStrokeRec& stroke, GrDrawTarget* target) { |
+ virtual void onStencilPath(const SkStrokeRec& stroke, GrDrawTarget* target) { |
GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRInit); |
GrDrawState* drawState = target->drawState(); |
GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil, |
@@ -186,7 +226,7 @@ |
0xffff); |
drawState->setStencil(kIncrementStencil); |
drawState->enableState(GrDrawState::kNoColorWrites_StateBit); |
- this->drawPath(path, stroke, target, false); |
+ this->drawPath(stroke, target, false); |
} |
// Helper for getting the device bounds of a path. Inverse filled paths will have bounds set |
@@ -206,6 +246,7 @@ |
} |
private: |
+ SkPath fPath; |
typedef SkRefCnt INHERITED; |
}; |