}
void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path,
- const SkStrokeRec& stroke) {
+ const SkStrokeRec& origStroke) {
SkASSERT(!path.isEmpty());
// An Assumption here is that path renderer would use some form of tweaking
GrPathRendererChain::kColor_DrawType;
const SkPath* pathPtr = &path;
- SkPath tmpPath;
- SkStrokeRec strokeRec(stroke);
+ SkTLazy<SkPath> tmpPath;
+ SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke);
// Try a 1st time without stroking the path and without allowing the SW renderer
- GrPathRenderer* pr = this->getPathRenderer(*pathPtr, strokeRec, target, false, type);
+ GrPathRenderer* pr = this->getPathRenderer(*pathPtr, *stroke, target, false, type);
if (NULL == pr) {
- if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(strokeRec, this->getMatrix(), NULL)) {
+ if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, this->getMatrix(), NULL)) {
// It didn't work the 1st time, so try again with the stroked path
- if (strokeRec.applyToPath(&tmpPath, *pathPtr)) {
- pathPtr = &tmpPath;
- strokeRec.setFillStyle();
+ if (stroke->applyToPath(tmpPath.init(), *pathPtr)) {
+ pathPtr = tmpPath.get();
+ stroke.writable()->setFillStyle();
if (pathPtr->isEmpty()) {
return;
}
}
// This time, allow SW renderer
- pr = this->getPathRenderer(*pathPtr, strokeRec, target, true, type);
+ pr = this->getPathRenderer(*pathPtr, *stroke, target, true, type);
}
if (NULL == pr) {
return;
}
- pr->drawPath(*pathPtr, strokeRec, target, useCoverageAA);
+ pr->drawPath(*pathPtr, *stroke, target, useCoverageAA);
}
////////////////////////////////////////////////////////////////////////////////
// where the original path can in fact be modified in place (even though
// its parameter type is const).
SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath);
- SkPath tmpPath, effectPath;
+ SkTLazy<SkPath> tmpPath;
+ SkTLazy<SkPath> effectPath;
if (prePathMatrix) {
SkPath* result = pathPtr;
if (!pathIsMutable) {
- result = &tmpPath;
+ result = tmpPath.init();
pathIsMutable = true;
}
// should I push prePathMatrix on our MV stack temporarily, instead
SkStrokeRec stroke(paint);
SkPathEffect* pathEffect = paint.getPathEffect();
const SkRect* cullRect = NULL; // TODO: what is our bounds?
- if (pathEffect && pathEffect->filterPath(&effectPath, *pathPtr, &stroke,
+ if (pathEffect && pathEffect->filterPath(effectPath.init(), *pathPtr, &stroke,
cullRect)) {
- pathPtr = &effectPath;
+ pathPtr = effectPath.get();
+ pathIsMutable = true;
}
if (paint.getMaskFilter()) {
if (!stroke.isHairlineStyle()) {
- if (stroke.applyToPath(&tmpPath, *pathPtr)) {
- pathPtr = &tmpPath;
+ SkPath* strokedPath = pathIsMutable ? pathPtr : tmpPath.init();
+ if (stroke.applyToPath(strokedPath, *pathPtr)) {
+ pathPtr = strokedPath;
pathIsMutable = true;
stroke.setFillStyle();
}
}
// avoid possibly allocating a new path in transform if we can
- SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath;
+ SkPath* devPathPtr = pathIsMutable ? pathPtr : tmpPath.init();
// transform the path into device space
pathPtr->transform(fContext->getMatrix(), devPathPtr);