aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrPathRenderer.h
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-10 16:46:23 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-10 16:46:23 +0000
commit3e0c64ad1e5e12aca2907a1384ee7dc3d39d5148 (patch)
treef52833d3ae2b671a3b0dfa890b912fc5611bb7cb /src/gpu/GrPathRenderer.h
parent0888b7534c4b3b1cb17ac428881334e1169c3d9f (diff)
Stateful PathRenderer implementation
Diffstat (limited to 'src/gpu/GrPathRenderer.h')
-rw-r--r--src/gpu/GrPathRenderer.h111
1 files changed, 76 insertions, 35 deletions
diff --git a/src/gpu/GrPathRenderer.h b/src/gpu/GrPathRenderer.h
index 88665c1d42..692cefc7f1 100644
--- a/src/gpu/GrPathRenderer.h
+++ b/src/gpu/GrPathRenderer.h
@@ -74,70 +74,108 @@ public:
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 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).
+ * @param target target that the path will be rendered to
*/
- 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 @@ public:
}
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 @@ protected:
/**
* 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 @@ protected:
* 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 @@ protected:
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 @@ protected:
}
private:
+ SkPath fPath;
typedef SkRefCnt INHERITED;
};