Stateful PathRenderer implementation

https://codereview.chromium.org/23926019/



git-svn-id: http://skia.googlecode.com/svn/trunk@13384 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2014-02-10 16:46:23 +00:00
parent 0888b7534c
commit 3e0c64ad1e
17 changed files with 229 additions and 201 deletions

View File

@ -854,7 +854,8 @@ public:
const SkStrokeRec& stroke, const SkStrokeRec& stroke,
const GrDrawTarget* target, const GrDrawTarget* target,
bool allowSW, bool allowSW,
GrPathRendererChain::DrawType drawType = GrPathRendererChain::kColor_DrawType, GrPathRendererChain::DrawType drawType,
SkPath::FillType fillType,
GrPathRendererChain::StencilSupport* stencilSupport = NULL); GrPathRendererChain::StencilSupport* stencilSupport = NULL);

View File

@ -8,6 +8,7 @@
#ifndef GrPathRendererChain_DEFINED #ifndef GrPathRendererChain_DEFINED
#define GrPathRendererChain_DEFINED #define GrPathRendererChain_DEFINED
#include "SkPath.h"
#include "SkRefCnt.h" #include "SkRefCnt.h"
#include "SkTArray.h" #include "SkTArray.h"
@ -59,6 +60,7 @@ public:
const SkStrokeRec& rec, const SkStrokeRec& rec,
const GrDrawTarget* target, const GrDrawTarget* target,
DrawType drawType, DrawType drawType,
SkPath::FillType fillType,
StencilSupport* stencilSupport); StencilSupport* stencilSupport);
private: private:

View File

@ -605,12 +605,11 @@ GrEffectRef* QuadEdgeEffect::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
bool GrAAConvexPathRenderer::canDrawPath(const SkPath& path, bool GrAAConvexPathRenderer::canDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
const GrDrawTarget* target, const GrDrawTarget* target,
bool antiAlias) const { bool antiAlias) const {
return (target->caps()->shaderDerivativeSupport() && antiAlias && return (target->caps()->shaderDerivativeSupport() && antiAlias &&
stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex()); stroke.isFillStyle() && !this->path().isInverseFillType() && this->path().isConvex());
} }
namespace { namespace {
@ -623,12 +622,11 @@ extern const GrVertexAttrib gPathAttribs[] = {
}; };
bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath, bool GrAAConvexPathRenderer::onDrawPath(const SkStrokeRec&,
const SkStrokeRec&,
GrDrawTarget* target, GrDrawTarget* target,
bool antiAlias) { bool antiAlias) {
const SkPath* path = &origPath; const SkPath* path = &this->path();
if (path->isEmpty()) { if (path->isEmpty()) {
return true; return true;
} }
@ -645,7 +643,7 @@ bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath,
// segment representation. // segment representation.
SkPath tmpPath; SkPath tmpPath;
if (viewMatrix.hasPerspective()) { if (viewMatrix.hasPerspective()) {
origPath.transform(viewMatrix, &tmpPath); this->path().transform(viewMatrix, &tmpPath);
path = &tmpPath; path = &tmpPath;
viewMatrix = SkMatrix::I(); viewMatrix = SkMatrix::I();
} }

View File

@ -13,14 +13,15 @@ class GrAAConvexPathRenderer : public GrPathRenderer {
public: public:
GrAAConvexPathRenderer(); GrAAConvexPathRenderer();
virtual bool canDrawPath(const SkPath& path, virtual bool canDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
const GrDrawTarget* target, const GrDrawTarget* target,
bool antiAlias) const SK_OVERRIDE; bool antiAlias) const SK_OVERRIDE;
protected: protected:
virtual bool onDrawPath(const SkPath& path, virtual bool onDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
GrDrawTarget* target, GrDrawTarget* target,
bool antiAlias) SK_OVERRIDE; bool antiAlias) SK_OVERRIDE;
private:
typedef GrPathRenderer INHERITED;
}; };

View File

@ -826,8 +826,7 @@ bool GrAAHairLinePathRenderer::createBezierGeom(
return true; return true;
} }
bool GrAAHairLinePathRenderer::canDrawPath(const SkPath& path, bool GrAAHairLinePathRenderer::canDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
const GrDrawTarget* target, const GrDrawTarget* target,
bool antiAlias) const { bool antiAlias) const {
if (!antiAlias) { if (!antiAlias) {
@ -840,7 +839,7 @@ bool GrAAHairLinePathRenderer::canDrawPath(const SkPath& path,
return false; return false;
} }
if (SkPath::kLine_SegmentMask == path.getSegmentMasks() || if (SkPath::kLine_SegmentMask == this->path().getSegmentMasks() ||
target->caps()->shaderDerivativeSupport()) { target->caps()->shaderDerivativeSupport()) {
return true; return true;
} }
@ -884,8 +883,7 @@ bool check_bounds(GrDrawState* drawState, const SkRect& devBounds, void* vertice
return true; return true;
} }
bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path, bool GrAAHairLinePathRenderer::onDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
GrDrawTarget* target, GrDrawTarget* target,
bool antiAlias) { bool antiAlias) {
GrDrawState* drawState = target->drawState(); GrDrawState* drawState = target->drawState();
@ -910,7 +908,7 @@ bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
PREALLOC_PTARRAY(128) conics; PREALLOC_PTARRAY(128) conics;
IntArray qSubdivs; IntArray qSubdivs;
FloatArray cWeights; FloatArray cWeights;
quadCnt = generate_lines_and_quads(path, drawState->getViewMatrix(), devClipBounds, quadCnt = generate_lines_and_quads(this->path(), drawState->getViewMatrix(), devClipBounds,
&lines, &quads, &conics, &qSubdivs, &cWeights); &lines, &quads, &conics, &qSubdivs, &cWeights);
lineCnt = lines.count() / 2; lineCnt = lines.count() / 2;
conicCnt = conics.count() / 3; conicCnt = conics.count() / 3;
@ -920,7 +918,7 @@ bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
GrDrawTarget::AutoReleaseGeometry arg; GrDrawTarget::AutoReleaseGeometry arg;
SkRect devBounds; SkRect devBounds;
if (!this->createLineGeom(path, if (!this->createLineGeom(this->path(),
target, target,
lines, lines,
lineCnt, lineCnt,
@ -966,7 +964,7 @@ bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
GrDrawTarget::AutoReleaseGeometry arg; GrDrawTarget::AutoReleaseGeometry arg;
SkRect devBounds; SkRect devBounds;
if (!this->createBezierGeom(path, if (!this->createBezierGeom(this->path(),
target, target,
quads, quads,
quadCnt, quadCnt,

View File

@ -17,8 +17,7 @@ public:
static GrPathRenderer* Create(GrContext* context); static GrPathRenderer* Create(GrContext* context);
virtual bool canDrawPath(const SkPath& path, virtual bool canDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
const GrDrawTarget* target, const GrDrawTarget* target,
bool antiAlias) const SK_OVERRIDE; bool antiAlias) const SK_OVERRIDE;
@ -27,8 +26,7 @@ public:
typedef SkTArray<float, true> FloatArray; typedef SkTArray<float, true> FloatArray;
protected: protected:
virtual bool onDrawPath(const SkPath& path, virtual bool onDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
GrDrawTarget* target, GrDrawTarget* target,
bool antiAlias) SK_OVERRIDE; bool antiAlias) SK_OVERRIDE;

View File

@ -30,12 +30,11 @@ typedef SkClipStack::Element Element;
using namespace GrReducedClip; using namespace GrReducedClip;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace {
// set up the draw state to enable the aa clipping mask. Besides setting up the // set up the draw state to enable the aa clipping mask. Besides setting up the
// stage matrix this also alters the vertex layout // stage matrix this also alters the vertex layout
void setup_drawstate_aaclip(GrGpu* gpu, static void setup_drawstate_aaclip(GrGpu* gpu,
GrTexture* result, GrTexture* result,
const SkIRect &devBound) { const SkIRect &devBound) {
GrDrawState* drawState = gpu->drawState(); GrDrawState* drawState = gpu->drawState();
SkASSERT(drawState); SkASSERT(drawState);
@ -59,24 +58,21 @@ void setup_drawstate_aaclip(GrGpu* gpu,
kPosition_GrCoordSet))->unref(); kPosition_GrCoordSet))->unref();
} }
bool path_needs_SW_renderer(GrContext* context, static bool path_needs_SW_renderer(GrContext* context,
GrGpu* gpu, GrGpu* gpu,
const SkPath& origPath, const SkPath& origPath,
const SkStrokeRec& stroke, const SkStrokeRec& stroke,
bool doAA) { bool doAA) {
// the gpu alpha mask will draw the inverse paths as non-inverse to a temp buffer
SkTCopyOnFirstWrite<SkPath> path(origPath);
if (path->isInverseFillType()) {
path.writable()->toggleInverseFillType();
}
// last (false) parameter disallows use of the SW path renderer
GrPathRendererChain::DrawType type = doAA ? GrPathRendererChain::DrawType type = doAA ?
GrPathRendererChain::kColorAntiAlias_DrawType : GrPathRendererChain::kColorAntiAlias_DrawType :
GrPathRendererChain::kColor_DrawType; GrPathRendererChain::kColor_DrawType;
// the gpu alpha mask will draw the inverse paths as non-inverse to a temp buffer
SkPath::FillType fillType = SkPath::ConvertToNonInverseFillType(origPath.getFillType());
return NULL == context->getPathRenderer(*path, stroke, gpu, false, type); // the 'false' parameter disallows use of the SW path renderer
} GrPathRenderer::AutoClearPath acp(context->getPathRenderer(origPath, stroke, gpu,
false, type, fillType));
return NULL == acp.renderer();
} }
/* /*
@ -313,9 +309,20 @@ void setup_boolean_blendcoeffs(GrDrawState* drawState, SkRegion::Op op) {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool GrClipMaskManager::drawFilledPath(GrTexture* target,
GrPathRenderer* pathRenderer,
bool isAA) {
GrDrawState* drawState = fGpu->drawState();
drawState->setRenderTarget(target->asRenderTarget());
SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
pathRenderer->drawPath(stroke, fGpu, isAA);
return true;
}
bool GrClipMaskManager::drawElement(GrTexture* target, bool GrClipMaskManager::drawElement(GrTexture* target,
const SkClipStack::Element* element, const SkClipStack::Element* element) {
GrPathRenderer* pr) {
GrDrawState* drawState = fGpu->drawState(); GrDrawState* drawState = fGpu->drawState();
drawState->setRenderTarget(target->asRenderTarget()); drawState->setRenderTarget(target->asRenderTarget());
@ -336,21 +343,19 @@ bool GrClipMaskManager::drawElement(GrTexture* target,
} }
return true; return true;
case Element::kPath_Type: { case Element::kPath_Type: {
SkTCopyOnFirstWrite<SkPath> path(element->getPath());
if (path->isInverseFillType()) {
path.writable()->toggleInverseFillType();
}
SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
if (NULL == pr) { GrPathRendererChain::DrawType type;
GrPathRendererChain::DrawType type; type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_DrawType :
type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_DrawType : GrPathRendererChain::kColor_DrawType;
GrPathRendererChain::kColor_DrawType; SkPath::FillType fillType = element->getPath().getFillType();
pr = this->getContext()->getPathRenderer(*path, stroke, fGpu, false, type); GrPathRenderer::AutoClearPath acp(this->getContext()->getPathRenderer(
} element->getPath(),
if (NULL == pr) { stroke, fGpu, false, type,
SkPath::ConvertToNonInverseFillType(fillType)));
if (NULL == acp.renderer()) {
return false; return false;
} }
pr->drawPath(element->getPath(), stroke, fGpu, element->isAA()); acp->drawPath(stroke, fGpu, element->isAA());
break; break;
} }
default: default:
@ -363,7 +368,7 @@ bool GrClipMaskManager::drawElement(GrTexture* target,
bool GrClipMaskManager::canStencilAndDrawElement(GrTexture* target, bool GrClipMaskManager::canStencilAndDrawElement(GrTexture* target,
const SkClipStack::Element* element, const SkClipStack::Element* element,
GrPathRenderer** pr) { GrPathRenderer::AutoClearPath* acp) {
GrDrawState* drawState = fGpu->drawState(); GrDrawState* drawState = fGpu->drawState();
drawState->setRenderTarget(target->asRenderTarget()); drawState->setRenderTarget(target->asRenderTarget());
@ -371,16 +376,15 @@ bool GrClipMaskManager::canStencilAndDrawElement(GrTexture* target,
case Element::kRect_Type: case Element::kRect_Type:
return true; return true;
case Element::kPath_Type: { case Element::kPath_Type: {
SkTCopyOnFirstWrite<SkPath> path(element->getPath());
if (path->isInverseFillType()) {
path.writable()->toggleInverseFillType();
}
SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
GrPathRendererChain::DrawType type = element->isAA() ? GrPathRendererChain::DrawType type = element->isAA() ?
GrPathRendererChain::kStencilAndColorAntiAlias_DrawType : GrPathRendererChain::kStencilAndColorAntiAlias_DrawType :
GrPathRendererChain::kStencilAndColor_DrawType; GrPathRendererChain::kStencilAndColor_DrawType;
*pr = this->getContext()->getPathRenderer(*path, stroke, fGpu, false, type); SkPath::FillType fillType = element->getPath().getFillType();
return NULL != *pr; acp->set(this->getContext()->getPathRenderer(element->getPath(),
stroke, fGpu, false, type,
SkPath::ConvertToNonInverseFillType(fillType)));
return NULL != acp->renderer();
} }
default: default:
// something is wrong if we're trying to draw an empty element. // something is wrong if we're trying to draw an empty element.
@ -525,8 +529,8 @@ GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID,
bool invert = element->isInverseFilled(); bool invert = element->isInverseFilled();
if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) { if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) {
GrPathRenderer* pr = NULL; GrPathRenderer::AutoClearPath acp;
bool useTemp = !this->canStencilAndDrawElement(result, element, &pr); bool useTemp = !this->canStencilAndDrawElement(result, element, &acp);
GrTexture* dst; GrTexture* dst;
// This is the bounds of the clip element in the space of the alpha-mask. The temporary // This is the bounds of the clip element in the space of the alpha-mask. The temporary
// mask buffer can be substantially larger than the actually clip stack element. We // mask buffer can be substantially larger than the actually clip stack element. We
@ -573,9 +577,13 @@ GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID,
drawState->setAlpha(invert ? 0x00 : 0xff); drawState->setAlpha(invert ? 0x00 : 0xff);
if (!this->drawElement(dst, element, pr)) { if (NULL != acp.renderer()) {
fAACache.reset(); this->drawFilledPath(dst, acp.renderer(), element->isAA());
return NULL; } else {
if (!this->drawElement(dst, element)) {
fAACache.reset();
return NULL;
}
} }
if (useTemp) { if (useTemp) {
@ -601,7 +609,7 @@ GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID,
drawState->disableStencil(); drawState->disableStencil();
} }
} else { } else {
// all the remaining ops can just be directly draw into the accumulation buffer // all the remaining ops can just be directly drawn into the accumulation buffer
drawState->setAlpha(0xff); drawState->setAlpha(0xff);
setup_boolean_blendcoeffs(drawState, op); setup_boolean_blendcoeffs(drawState, op);
this->drawElement(result, element); this->drawElement(result, element);
@ -687,25 +695,22 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
SkRegion::Op op = element->getOp(); SkRegion::Op op = element->getOp();
GrPathRenderer* pr = NULL; GrPathRenderer::AutoClearPath acp;
SkTCopyOnFirstWrite<SkPath> clipPath;
if (Element::kRect_Type == element->getType()) { if (Element::kRect_Type == element->getType()) {
stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
fillInverted = false; fillInverted = false;
} else { } else {
SkASSERT(Element::kPath_Type == element->getType()); SkASSERT(Element::kPath_Type == element->getType());
clipPath.init(element->getPath()); fillInverted = element->getPath().isInverseFillType();
fillInverted = clipPath->isInverseFillType(); SkPath::FillType fill = element->getPath().getFillType();
if (fillInverted) { acp.set(this->getContext()->getPathRenderer(element->getPath(),
clipPath.writable()->toggleInverseFillType();
}
pr = this->getContext()->getPathRenderer(*clipPath,
stroke, stroke,
fGpu, fGpu,
false, false,
GrPathRendererChain::kStencilOnly_DrawType, GrPathRendererChain::kStencilOnly_DrawType,
&stencilSupport); SkPath::ConvertToNonInverseFillType(fill),
if (NULL == pr) { &stencilSupport));
if (NULL == acp.renderer()) {
return false; return false;
} }
} }
@ -741,12 +746,12 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
fGpu->drawSimpleRect(element->getRect(), NULL); fGpu->drawSimpleRect(element->getRect(), NULL);
} else { } else {
SkASSERT(Element::kPath_Type == element->getType()); SkASSERT(Element::kPath_Type == element->getType());
if (!clipPath->isEmpty()) { if (NULL != acp.renderer()) {
if (canRenderDirectToStencil) { if (canRenderDirectToStencil) {
*drawState->stencil() = gDrawToStencil; *drawState->stencil() = gDrawToStencil;
pr->drawPath(*clipPath, stroke, fGpu, false); acp->drawPath(stroke, fGpu, false);
} else { } else {
pr->stencilPath(*clipPath, stroke, fGpu); acp->stencilPath(stroke, fGpu);
} }
} }
} }
@ -764,7 +769,7 @@ bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID,
} else { } else {
SkASSERT(Element::kPath_Type == element->getType()); SkASSERT(Element::kPath_Type == element->getType());
SET_RANDOM_COLOR SET_RANDOM_COLOR
pr->drawPath(*clipPath, stroke, fGpu, false); acp->drawPath(stroke, fGpu, false);
} }
} else { } else {
SET_RANDOM_COLOR SET_RANDOM_COLOR

View File

@ -11,6 +11,7 @@
#include "GrClipMaskCache.h" #include "GrClipMaskCache.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawState.h" #include "GrDrawState.h"
#include "GrPathRenderer.h"
#include "GrReducedClip.h" #include "GrReducedClip.h"
#include "GrStencil.h" #include "GrStencil.h"
#include "GrTexture.h" #include "GrTexture.h"
@ -130,15 +131,18 @@ private:
bool useSWOnlyPath(const GrReducedClip::ElementList& elements); bool useSWOnlyPath(const GrReducedClip::ElementList& elements);
// Draws a filled clip path into the target alpha mask
bool drawFilledPath(GrTexture* target, GrPathRenderer* pathRenderer, bool isAA);
// Draws a clip element into the target alpha mask. The caller should have already setup the // Draws a clip element into the target alpha mask. The caller should have already setup the
// desired blend operation. Optionally if the caller already selected a path renderer it can // desired blend operation.
// be passed. Otherwise the function will select one if the element is a path. bool drawElement(GrTexture* target, const SkClipStack::Element* element);
bool drawElement(GrTexture* target, const SkClipStack::Element*, GrPathRenderer* = NULL);
// Determines whether it is possible to draw the element to both the stencil buffer and the // Determines whether it is possible to draw the element to both the stencil buffer and the
// alpha mask simultaneously. If so and the element is a path a compatible path renderer is // alpha mask simultaneously. If so and the element is a path a compatible path renderer is
// also returned. // also returned.
bool canStencilAndDrawElement(GrTexture* target, const SkClipStack::Element*, GrPathRenderer**); bool canStencilAndDrawElement(GrTexture* target, const SkClipStack::Element*,
GrPathRenderer::AutoClearPath* pr);
void mergeMask(GrTexture* dstMask, void mergeMask(GrTexture* dstMask,
GrTexture* srcMask, GrTexture* srcMask,

View File

@ -1148,16 +1148,18 @@ void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath&
GrPathRendererChain::DrawType type = GrPathRendererChain::DrawType type =
useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType :
GrPathRendererChain::kColor_DrawType; GrPathRendererChain::kColor_DrawType;
const SkPath* pathPtr = &path; const SkPath* pathPtr = &path;
SkTLazy<SkPath> tmpPath; SkTLazy<SkPath> tmpPath;
SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke); SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke);
// Try a 1st time without stroking the path and without allowing the SW renderer // Try a 1st time without stroking the path and without allowing the SW renderer
GrPathRenderer* pr = this->getPathRenderer(*pathPtr, *stroke, target, false, type); GrPathRenderer::AutoClearPath acp(this->getPathRenderer(*pathPtr, *stroke,
target, false, type,
pathPtr->getFillType()));
if (NULL == pr) { if (NULL == acp.renderer()) {
if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, this->getMatrix(), NULL)) { if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, this->getMatrix(), NULL)) {
// It didn't work the 1st time, so try again with the stroked path // It didn't work the 1st time, so try again with the stroked path
if (stroke->applyToPath(tmpPath.init(), *pathPtr)) { if (stroke->applyToPath(tmpPath.init(), *pathPtr)) {
@ -1170,17 +1172,18 @@ void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath&
} }
// This time, allow SW renderer // This time, allow SW renderer
pr = this->getPathRenderer(*pathPtr, *stroke, target, true, type); acp.set(this->getPathRenderer(*pathPtr, *stroke, target, true, type,
pathPtr->getFillType()));
} }
if (NULL == pr) { if (NULL == acp.renderer()) {
#ifdef SK_DEBUG #ifdef SK_DEBUG
GrPrintf("Unable to find path renderer compatible with path.\n"); GrPrintf("Unable to find path renderer compatible with path.\n");
#endif #endif
return; return;
} }
pr->drawPath(*pathPtr, *stroke, target, useCoverageAA); acp->drawPath(*stroke, target, useCoverageAA);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1676,6 +1679,7 @@ GrPathRenderer* GrContext::getPathRenderer(const SkPath& path,
const GrDrawTarget* target, const GrDrawTarget* target,
bool allowSW, bool allowSW,
GrPathRendererChain::DrawType drawType, GrPathRendererChain::DrawType drawType,
SkPath::FillType fillType,
GrPathRendererChain::StencilSupport* stencilSupport) { GrPathRendererChain::StencilSupport* stencilSupport) {
if (NULL == fPathRendererChain) { if (NULL == fPathRendererChain) {
@ -1686,6 +1690,7 @@ GrPathRenderer* GrContext::getPathRenderer(const SkPath& path,
stroke, stroke,
target, target,
drawType, drawType,
fillType,
stencilSupport); stencilSupport);
if (NULL == pr && allowSW) { if (NULL == pr && allowSW) {
@ -1693,6 +1698,7 @@ GrPathRenderer* GrContext::getPathRenderer(const SkPath& path,
fSoftwarePathRenderer = SkNEW_ARGS(GrSoftwarePathRenderer, (this)); fSoftwarePathRenderer = SkNEW_ARGS(GrSoftwarePathRenderer, (this));
} }
pr = fSoftwarePathRenderer; pr = fSoftwarePathRenderer;
pr->setPath(path, fillType);
} }
return pr; return pr;

View File

@ -163,10 +163,9 @@ static inline bool single_pass_path(const SkPath& path, const SkStrokeRec& strok
} }
GrPathRenderer::StencilSupport GrDefaultPathRenderer::onGetStencilSupport( GrPathRenderer::StencilSupport GrDefaultPathRenderer::onGetStencilSupport(
const SkPath& path,
const SkStrokeRec& stroke, const SkStrokeRec& stroke,
const GrDrawTarget*) const { const GrDrawTarget*) const {
if (single_pass_path(path, stroke)) { if (single_pass_path(this->path(), stroke)) {
return GrPathRenderer::kNoRestriction_StencilSupport; return GrPathRenderer::kNoRestriction_StencilSupport;
} else { } else {
return GrPathRenderer::kStencilOnly_StencilSupport; return GrPathRenderer::kStencilOnly_StencilSupport;
@ -325,8 +324,7 @@ FINISHED:
return true; return true;
} }
bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path, bool GrDefaultPathRenderer::internalDrawPath(const SkStrokeRec& origStroke,
const SkStrokeRec& origStroke,
GrDrawTarget* target, GrDrawTarget* target,
bool stencilOnly) { bool stencilOnly) {
@ -346,13 +344,13 @@ bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
} }
SkScalar tol = SK_Scalar1; SkScalar tol = SK_Scalar1;
tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, path.getBounds()); tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, this->path().getBounds());
int vertexCnt; int vertexCnt;
int indexCnt; int indexCnt;
GrPrimitiveType primType; GrPrimitiveType primType;
GrDrawTarget::AutoReleaseGeometry arg; GrDrawTarget::AutoReleaseGeometry arg;
if (!this->createGeom(path, if (!this->createGeom(this->path(),
*stroke, *stroke,
tol, tol,
target, target,
@ -386,7 +384,7 @@ bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
lastPassIsBounds = false; lastPassIsBounds = false;
drawFace[0] = GrDrawState::kBoth_DrawFace; drawFace[0] = GrDrawState::kBoth_DrawFace;
} else { } else {
if (single_pass_path(path, *stroke)) { if (single_pass_path(this->path(), *stroke)) {
passCount = 1; passCount = 1;
if (stencilOnly) { if (stencilOnly) {
passes[0] = &gDirectToStencil; passes[0] = &gDirectToStencil;
@ -396,7 +394,7 @@ bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
drawFace[0] = GrDrawState::kBoth_DrawFace; drawFace[0] = GrDrawState::kBoth_DrawFace;
lastPassIsBounds = false; lastPassIsBounds = false;
} else { } else {
switch (path.getFillType()) { switch (this->path().getFillType()) {
case SkPath::kInverseEvenOdd_FillType: case SkPath::kInverseEvenOdd_FillType:
reverse = true; reverse = true;
// fallthrough // fallthrough
@ -463,7 +461,7 @@ bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
} }
SkRect devBounds; SkRect devBounds;
GetPathDevBounds(path, drawState->getRenderTarget(), viewM, &devBounds); GetPathDevBounds(this->path(), drawState->getRenderTarget(), viewM, &devBounds);
for (int p = 0; p < passCount; ++p) { for (int p = 0; p < passCount; ++p) {
drawState->setDrawFace(drawFace[p]); drawState->setDrawFace(drawFace[p]);
@ -490,7 +488,7 @@ bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
avmr.setIdentity(drawState); avmr.setIdentity(drawState);
} }
} else { } else {
bounds = path.getBounds(); bounds = this->path().getBounds();
} }
GrDrawTarget::AutoGeometryAndStatePush agasp(target, GrDrawTarget::kPreserve_ASRInit); GrDrawTarget::AutoGeometryAndStatePush agasp(target, GrDrawTarget::kPreserve_ASRInit);
target->drawSimpleRect(bounds, NULL); target->drawSimpleRect(bounds, NULL);
@ -509,8 +507,7 @@ bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path,
return true; return true;
} }
bool GrDefaultPathRenderer::canDrawPath(const SkPath& path, bool GrDefaultPathRenderer::canDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
const GrDrawTarget* target, const GrDrawTarget* target,
bool antiAlias) const { bool antiAlias) const {
// this class can draw any path with any fill but doesn't do any anti-aliasing. // this class can draw any path with any fill but doesn't do any anti-aliasing.
@ -520,20 +517,15 @@ bool GrDefaultPathRenderer::canDrawPath(const SkPath& path,
IsStrokeHairlineOrEquivalent(stroke, target->getDrawState().getViewMatrix(), NULL)); IsStrokeHairlineOrEquivalent(stroke, target->getDrawState().getViewMatrix(), NULL));
} }
bool GrDefaultPathRenderer::onDrawPath(const SkPath& path, bool GrDefaultPathRenderer::onDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
GrDrawTarget* target, GrDrawTarget* target,
bool antiAlias) { bool antiAlias) {
return this->internalDrawPath(path, return this->internalDrawPath(stroke, target, false);
stroke,
target,
false);
} }
void GrDefaultPathRenderer::onStencilPath(const SkPath& path, void GrDefaultPathRenderer::onStencilPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
GrDrawTarget* target) { GrDrawTarget* target) {
SkASSERT(SkPath::kInverseEvenOdd_FillType != path.getFillType()); SkASSERT(SkPath::kInverseEvenOdd_FillType != this->path().getFillType());
SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); SkASSERT(SkPath::kInverseWinding_FillType != this->path().getFillType());
this->internalDrawPath(path, stroke, target, true); this->internalDrawPath(stroke, target, true);
} }

View File

@ -19,28 +19,23 @@ class SK_API GrDefaultPathRenderer : public GrPathRenderer {
public: public:
GrDefaultPathRenderer(bool separateStencilSupport, bool stencilWrapOpsSupport); GrDefaultPathRenderer(bool separateStencilSupport, bool stencilWrapOpsSupport);
virtual bool canDrawPath(const SkPath&, virtual bool canDrawPath(const SkStrokeRec&,
const SkStrokeRec&,
const GrDrawTarget*, const GrDrawTarget*,
bool antiAlias) const SK_OVERRIDE; bool antiAlias) const SK_OVERRIDE;
private: private:
virtual StencilSupport onGetStencilSupport(const SkPath&, virtual StencilSupport onGetStencilSupport(const SkStrokeRec&,
const SkStrokeRec&,
const GrDrawTarget*) const SK_OVERRIDE; const GrDrawTarget*) const SK_OVERRIDE;
virtual bool onDrawPath(const SkPath&, virtual bool onDrawPath(const SkStrokeRec&,
const SkStrokeRec&,
GrDrawTarget*, GrDrawTarget*,
bool antiAlias) SK_OVERRIDE; bool antiAlias) SK_OVERRIDE;
virtual void onStencilPath(const SkPath&, virtual void onStencilPath(const SkStrokeRec&,
const SkStrokeRec&,
GrDrawTarget*) SK_OVERRIDE; GrDrawTarget*) SK_OVERRIDE;
bool internalDrawPath(const SkPath&, bool internalDrawPath(const SkStrokeRec&,
const SkStrokeRec&,
GrDrawTarget*, GrDrawTarget*,
bool stencilOnly); bool stencilOnly);

View File

@ -74,70 +74,108 @@ public:
GrPathRendererChain::kNoRestriction_StencilSupport; 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. * 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 stroke the stroke information (width, join, cap).
* @param target target that the path will be rendered to
*/ */
StencilSupport getStencilSupport(const SkPath& path, StencilSupport getStencilSupport(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
const GrDrawTarget* target) const { const GrDrawTarget* target) const {
SkASSERT(!path.isInverseFillType()); SkASSERT(!fPath.isInverseFillType());
return this->onGetStencilSupport(path, stroke, target); 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 * Returns true if this path renderer is able to render the current path. Returning false
* caller to fallback to another path renderer This function is called when searching for a path * allows the caller to fallback to another path renderer This function is called when
* renderer capable of rendering a path. * 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 stroke The stroke information (width, join, cap)
* @param target The target that the path will be rendered to * @param target The target that the path will be rendered to
* @param antiAlias True if anti-aliasing is required. * @param antiAlias True if anti-aliasing is required.
* *
* @return true if the path can be drawn by this object, false otherwise. * @return true if the path can be drawn by this object, false otherwise.
*/ */
virtual bool canDrawPath(const SkPath& path, virtual bool canDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& rec,
const GrDrawTarget* target, const GrDrawTarget* target,
bool antiAlias) const = 0; bool antiAlias) const = 0;
/** /**
* Draws the path into the draw target. If getStencilSupport() would return kNoRestriction then * Draws the current path into the draw target. If getStencilSupport() would return
* the subclass must respect the stencil settings of the target's draw state. * 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 stroke the stroke information (width, join, cap)
* @param target target that the path will be rendered to * @param target target that the path will be rendered to
* @param antiAlias true if anti-aliasing is required. * @param antiAlias true if anti-aliasing is required.
*/ */
bool drawPath(const SkPath& path, bool drawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
GrDrawTarget* target, GrDrawTarget* target,
bool antiAlias) { bool antiAlias) {
SkASSERT(!path.isEmpty()); SkASSERT(!fPath.isEmpty());
SkASSERT(this->canDrawPath(path, stroke, target, antiAlias)); SkASSERT(this->canDrawPath(stroke, target, antiAlias));
SkASSERT(target->drawState()->getStencil().isDisabled() || SkASSERT(target->drawState()->getStencil().isDisabled() ||
kNoRestriction_StencilSupport == this->getStencilSupport(path, stroke, target)); kNoRestriction_StencilSupport == this->getStencilSupport(stroke, target));
return this->onDrawPath(path, stroke, target, antiAlias); return this->onDrawPath(stroke, target, antiAlias);
} }
/** /**
* Draws the path to the stencil buffer. Assume the writable stencil bits are already * 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. * 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 stroke the stroke information (width, join, cap)
* @param target target that the path will be rendered to * @param target target that the path will be rendered to
*/ */
void stencilPath(const SkPath& path, const SkStrokeRec& stroke, GrDrawTarget* target) { void stencilPath(const SkStrokeRec& stroke, GrDrawTarget* target) {
SkASSERT(!path.isEmpty()); SkASSERT(!fPath.isEmpty());
SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(path, stroke, target)); SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(stroke, target));
this->onStencilPath(path, 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. // 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). // If we can, we draw lots faster (raster device does this same test).
static bool IsStrokeHairlineOrEquivalent(const SkStrokeRec& stroke, const SkMatrix& matrix, static bool IsStrokeHairlineOrEquivalent(const SkStrokeRec& stroke, const SkMatrix& matrix,
@ -153,11 +191,14 @@ public:
} }
protected: protected:
const SkPath& path() const {
return fPath;
}
/** /**
* Subclass overrides if it has any limitations of stenciling support. * Subclass overrides if it has any limitations of stenciling support.
*/ */
virtual StencilSupport onGetStencilSupport(const SkPath&, virtual StencilSupport onGetStencilSupport(const SkStrokeRec&,
const SkStrokeRec&,
const GrDrawTarget*) const { const GrDrawTarget*) const {
return kNoRestriction_StencilSupport; return kNoRestriction_StencilSupport;
} }
@ -165,8 +206,7 @@ protected:
/** /**
* Subclass implementation of drawPath() * Subclass implementation of drawPath()
*/ */
virtual bool onDrawPath(const SkPath& path, virtual bool onDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
GrDrawTarget* target, GrDrawTarget* target,
bool antiAlias) = 0; bool antiAlias) = 0;
@ -174,7 +214,7 @@ protected:
* Subclass implementation of stencilPath(). Subclass must override iff it ever returns * Subclass implementation of stencilPath(). Subclass must override iff it ever returns
* kStencilOnly in onGetStencilSupport(). * 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); GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRInit);
GrDrawState* drawState = target->drawState(); GrDrawState* drawState = target->drawState();
GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil, GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil,
@ -186,7 +226,7 @@ protected:
0xffff); 0xffff);
drawState->setStencil(kIncrementStencil); drawState->setStencil(kIncrementStencil);
drawState->enableState(GrDrawState::kNoColorWrites_StateBit); 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 // Helper for getting the device bounds of a path. Inverse filled paths will have bounds set
@ -206,6 +246,7 @@ protected:
} }
private: private:
SkPath fPath;
typedef SkRefCnt INHERITED; typedef SkRefCnt INHERITED;
}; };

View File

@ -35,6 +35,7 @@ GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path,
const SkStrokeRec& stroke, const SkStrokeRec& stroke,
const GrDrawTarget* target, const GrDrawTarget* target,
DrawType drawType, DrawType drawType,
SkPath::FillType fillType,
StencilSupport* stencilSupport) { StencilSupport* stencilSupport) {
if (!fInit) { if (!fInit) {
this->init(); this->init();
@ -56,12 +57,11 @@ GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path,
minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
} }
for (int i = 0; i < fChain.count(); ++i) { for (int i = 0; i < fChain.count(); ++i) {
if (fChain[i]->canDrawPath(path, stroke, target, antiAlias)) { fChain[i]->setPath(path, fillType);
if (fChain[i]->canDrawPath(stroke, target, antiAlias)) {
if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(path, GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(stroke,
stroke,
target); target);
if (support < minStencilSupport) { if (support < minStencilSupport) {
continue; continue;
@ -71,6 +71,7 @@ GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path,
} }
return fChain[i]; return fChain[i];
} }
fChain[i]->resetPath();
} }
return NULL; return NULL;
} }

View File

@ -11,8 +11,7 @@
#include "GrSWMaskHelper.h" #include "GrSWMaskHelper.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool GrSoftwarePathRenderer::canDrawPath(const SkPath&, bool GrSoftwarePathRenderer::canDrawPath(const SkStrokeRec&,
const SkStrokeRec&,
const GrDrawTarget*, const GrDrawTarget*,
bool antiAlias) const { bool antiAlias) const {
if (!antiAlias || NULL == fContext) { if (!antiAlias || NULL == fContext) {
@ -29,7 +28,6 @@ bool GrSoftwarePathRenderer::canDrawPath(const SkPath&,
} }
GrPathRenderer::StencilSupport GrSoftwarePathRenderer::onGetStencilSupport( GrPathRenderer::StencilSupport GrSoftwarePathRenderer::onGetStencilSupport(
const SkPath&,
const SkStrokeRec&, const SkStrokeRec&,
const GrDrawTarget*) const { const GrDrawTarget*) const {
return GrPathRenderer::kNoSupport_StencilSupport; return GrPathRenderer::kNoSupport_StencilSupport;
@ -113,8 +111,7 @@ void draw_around_inv_path(GrDrawTarget* target,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// return true on success; false on failure // return true on success; false on failure
bool GrSoftwarePathRenderer::onDrawPath(const SkPath& path, bool GrSoftwarePathRenderer::onDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
GrDrawTarget* target, GrDrawTarget* target,
bool antiAlias) { bool antiAlias) {
@ -127,16 +124,16 @@ bool GrSoftwarePathRenderer::onDrawPath(const SkPath& path,
SkMatrix vm = drawState->getViewMatrix(); SkMatrix vm = drawState->getViewMatrix();
SkIRect devPathBounds, devClipBounds; SkIRect devPathBounds, devClipBounds;
if (!get_path_and_clip_bounds(target, path, vm, if (!get_path_and_clip_bounds(target, this->path(), vm,
&devPathBounds, &devClipBounds)) { &devPathBounds, &devClipBounds)) {
if (path.isInverseFillType()) { if (this->path().isInverseFillType()) {
draw_around_inv_path(target, devClipBounds, devPathBounds); draw_around_inv_path(target, devClipBounds, devPathBounds);
} }
return true; return true;
} }
SkAutoTUnref<GrTexture> texture( SkAutoTUnref<GrTexture> texture(
GrSWMaskHelper::DrawPathMaskToTexture(fContext, path, stroke, GrSWMaskHelper::DrawPathMaskToTexture(fContext, this->path(), stroke,
devPathBounds, devPathBounds,
antiAlias, &vm)); antiAlias, &vm));
if (NULL == texture) { if (NULL == texture) {
@ -145,7 +142,7 @@ bool GrSoftwarePathRenderer::onDrawPath(const SkPath& path,
GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, devPathBounds); GrSWMaskHelper::DrawToTargetWithPathMask(texture, target, devPathBounds);
if (path.isInverseFillType()) { if (this->path().isInverseFillType()) {
draw_around_inv_path(target, devClipBounds, devPathBounds); draw_around_inv_path(target, devClipBounds, devPathBounds);
} }

View File

@ -24,17 +24,14 @@ public:
: fContext(context) { : fContext(context) {
} }
virtual bool canDrawPath(const SkPath&, virtual bool canDrawPath(const SkStrokeRec&,
const SkStrokeRec&,
const GrDrawTarget*, const GrDrawTarget*,
bool antiAlias) const SK_OVERRIDE; bool antiAlias) const SK_OVERRIDE;
protected: protected:
virtual StencilSupport onGetStencilSupport(const SkPath&, virtual StencilSupport onGetStencilSupport(const SkStrokeRec&,
const SkStrokeRec&,
const GrDrawTarget*) const SK_OVERRIDE; const GrDrawTarget*) const SK_OVERRIDE;
virtual bool onDrawPath(const SkPath&, virtual bool onDrawPath(const SkStrokeRec&,
const SkStrokeRec&,
GrDrawTarget*, GrDrawTarget*,
bool antiAlias) SK_OVERRIDE; bool antiAlias) SK_OVERRIDE;

View File

@ -34,8 +34,7 @@ GrStencilAndCoverPathRenderer::~GrStencilAndCoverPathRenderer() {
fGpu->unref(); fGpu->unref();
} }
bool GrStencilAndCoverPathRenderer::canDrawPath(const SkPath& path, bool GrStencilAndCoverPathRenderer::canDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
const GrDrawTarget* target, const GrDrawTarget* target,
bool antiAlias) const { bool antiAlias) const {
return !stroke.isHairlineStyle() && return !stroke.isHairlineStyle() &&
@ -45,22 +44,19 @@ bool GrStencilAndCoverPathRenderer::canDrawPath(const SkPath& path,
} }
GrPathRenderer::StencilSupport GrStencilAndCoverPathRenderer::onGetStencilSupport( GrPathRenderer::StencilSupport GrStencilAndCoverPathRenderer::onGetStencilSupport(
const SkPath&,
const SkStrokeRec& , const SkStrokeRec& ,
const GrDrawTarget*) const { const GrDrawTarget*) const {
return GrPathRenderer::kStencilOnly_StencilSupport; return GrPathRenderer::kStencilOnly_StencilSupport;
} }
void GrStencilAndCoverPathRenderer::onStencilPath(const SkPath& path, void GrStencilAndCoverPathRenderer::onStencilPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
GrDrawTarget* target) { GrDrawTarget* target) {
SkASSERT(!path.isInverseFillType()); SkASSERT(!this->path().isInverseFillType());
SkAutoTUnref<GrPath> p(fGpu->getContext()->createPath(path, stroke)); SkAutoTUnref<GrPath> p(fGpu->getContext()->createPath(this->path(), stroke));
target->stencilPath(p, path.getFillType()); target->stencilPath(p, this->path().getFillType());
} }
bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path, bool GrStencilAndCoverPathRenderer::onDrawPath(const SkStrokeRec& stroke,
const SkStrokeRec& stroke,
GrDrawTarget* target, GrDrawTarget* target,
bool antiAlias) { bool antiAlias) {
SkASSERT(!antiAlias); SkASSERT(!antiAlias);
@ -69,9 +65,9 @@ bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path,
GrDrawState* drawState = target->drawState(); GrDrawState* drawState = target->drawState();
SkASSERT(drawState->getStencil().isDisabled()); SkASSERT(drawState->getStencil().isDisabled());
SkAutoTUnref<GrPath> p(fGpu->getContext()->createPath(path, stroke)); SkAutoTUnref<GrPath> p(fGpu->getContext()->createPath(this->path(), stroke));
if (path.isInverseFillType()) { if (this->path().isInverseFillType()) {
GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass, GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass,
kZero_StencilOp, kZero_StencilOp,
kZero_StencilOp, kZero_StencilOp,
@ -96,7 +92,7 @@ bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path,
*drawState->stencil() = kStencilPass; *drawState->stencil() = kStencilPass;
} }
target->drawPath(p, path.getFillType()); target->drawPath(p, this->path().getFillType());
target->drawState()->stencil()->setDisabled(); target->drawState()->stencil()->setDisabled();
return true; return true;

View File

@ -25,23 +25,19 @@ public:
virtual ~GrStencilAndCoverPathRenderer(); virtual ~GrStencilAndCoverPathRenderer();
virtual bool canDrawPath(const SkPath&, virtual bool canDrawPath(const SkStrokeRec&,
const SkStrokeRec&,
const GrDrawTarget*, const GrDrawTarget*,
bool antiAlias) const SK_OVERRIDE; bool antiAlias) const SK_OVERRIDE;
protected: protected:
virtual StencilSupport onGetStencilSupport(const SkPath&, virtual StencilSupport onGetStencilSupport(const SkStrokeRec&,
const SkStrokeRec&,
const GrDrawTarget*) const SK_OVERRIDE; const GrDrawTarget*) const SK_OVERRIDE;
virtual bool onDrawPath(const SkPath&, virtual bool onDrawPath(const SkStrokeRec&,
const SkStrokeRec&,
GrDrawTarget*, GrDrawTarget*,
bool antiAlias) SK_OVERRIDE; bool antiAlias) SK_OVERRIDE;
virtual void onStencilPath(const SkPath&, virtual void onStencilPath(const SkStrokeRec&,
const SkStrokeRec&,
GrDrawTarget*) SK_OVERRIDE; GrDrawTarget*) SK_OVERRIDE;
private: private: