From e3453cbd20d00d685131a09d9141b1c70f0c5710 Mon Sep 17 00:00:00 2001 From: "sugoi@google.com" Date: Mon, 7 Jan 2013 14:26:40 +0000 Subject: This CL introduces a new path renderer. Here are the characteristics : - It uses the original path, before stroking - It supports traight lines only (no curves) - It supports butt or square caps only - It supports miter or bevel joins only - No AA support Support for these will be added step by step later on. A first pass at the benchmarks on my linux machine gave me these approximate speed improvements (running all bench with the option '--forceAA 0') : path_stroke_small_long_line 4X path_stroke_small_sawtooth 4X path_stroke_big_rect 4X path_stroke_small_rect 6X path_stroke_big_triangle 4X path_stroke_small_triangle 10X lines_1_BW 1.5X dashline_2_square 1.5X dashline_1_square 1.5X Also note that I can't submit this code until GrDrawTarget::isOpaque() is implemented, unless I just disable my renderer completely for now. BUG=chromium:135111 TEST=The following gms are affected and may require rebaselining : lineclosepath, linepath, strokes_poly Review URL: https://codereview.appspot.com/7026049 git-svn-id: http://skia.googlecode.com/svn/trunk@7047 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrAddPathRenderers_default.cpp | 6 ++++++ src/gpu/GrContext.cpp | 37 ++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/gpu/GrAddPathRenderers_default.cpp b/src/gpu/GrAddPathRenderers_default.cpp index 69be15a271..618bd3100b 100644 --- a/src/gpu/GrAddPathRenderers_default.cpp +++ b/src/gpu/GrAddPathRenderers_default.cpp @@ -10,8 +10,14 @@ #include "GrStencilAndCoverPathRenderer.h" #include "GrAAHairLinePathRenderer.h" #include "GrAAConvexPathRenderer.h" +#if GR_STROKE_PATH_RENDERING +#include "../../experimental/StrokePathRenderer/GrStrokePathRenderer.h" +#endif void GrPathRenderer::AddPathRenderers(GrContext* ctx, GrPathRendererChain* chain) { +#if GR_STROKE_PATH_RENDERING + chain->addPathRenderer(SkNEW(GrStrokePathRenderer))->unref(); +#endif if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(ctx)) { chain->addPathRenderer(pr)->unref(); } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 12fbeb6e31..5961aaf8ff 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -1063,24 +1063,15 @@ void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const SkStrok return; } - const SkPath* pathPtr = &path; - SkPath tmpPath; - SkStrokeRec strokeRec(stroke); - if (!strokeRec.isHairlineStyle()) { - if (strokeRec.applyToPath(&tmpPath, *pathPtr)) { - pathPtr = &tmpPath; - strokeRec.setFillStyle(); - } - } - SkRect ovalRect; - if (!pathPtr->isInverseFillType() && pathPtr->isOval(&ovalRect)) { - SkScalar width = strokeRec.isHairlineStyle() ? 0 : -SK_Scalar1; + if ((stroke.isHairlineStyle() || stroke.isFillStyle()) && !path.isInverseFillType() && + path.isOval(&ovalRect)) { + SkScalar width = stroke.isHairlineStyle() ? 0 : -SK_Scalar1; this->drawOval(paint, ovalRect, width); return; } - this->internalDrawPath(paint, *pathPtr, strokeRec); + this->internalDrawPath(paint, path, stroke); } void GrContext::internalDrawPath(const GrPaint& paint, const SkPath& path, const SkStrokeRec& stroke) { @@ -1109,7 +1100,23 @@ void GrContext::internalDrawPath(const GrPaint& paint, const SkPath& path, const GrPathRendererChain::DrawType type = prAA ? GrPathRendererChain::kColorAntiAlias_DrawType : GrPathRendererChain::kColor_DrawType; - GrPathRenderer* pr = this->getPathRenderer(path, stroke, target, true, type); + const SkPath* pathPtr = &path; + SkPath tmpPath; + SkStrokeRec strokeRec(stroke); + + // Try a 1st time without stroking the path and without allowing the SW renderer + GrPathRenderer* pr = this->getPathRenderer(*pathPtr, strokeRec, target, false, type); + + if ((NULL == pr) && !strokeRec.isHairlineStyle()) { + // It didn't work the 1st time, so try again with the stroked path + if (strokeRec.applyToPath(&tmpPath, *pathPtr)) { + pathPtr = &tmpPath; + strokeRec.setFillStyle(); + } + // This time, allow SW renderer + pr = this->getPathRenderer(*pathPtr, strokeRec, target, true, type); + } + if (NULL == pr) { #if GR_DEBUG GrPrintf("Unable to find path renderer compatible with path.\n"); @@ -1117,7 +1124,7 @@ void GrContext::internalDrawPath(const GrPaint& paint, const SkPath& path, const return; } - pr->drawPath(path, stroke, target, prAA); + pr->drawPath(*pathPtr, strokeRec, target, prAA); } //////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3