diff options
author | egdaniel <egdaniel@google.com> | 2015-01-05 10:22:28 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-05 10:22:28 -0800 |
commit | af18a09d13611526c4217656c98947f9067cb07a (patch) | |
tree | fe9d4ffaaad14f1addca75bbecac4043d56c5a20 /src/gpu | |
parent | 91b0a3587342c48a1a6e1c4687686688737359da (diff) |
Add conic support to Default and AAConvex path redender.
This is achieved but chopping up conics into quads.
With this change conics should be ready to be used on the gpu side of things
BUG=skia:3258
Review URL: https://codereview.chromium.org/825443002
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrAAConvexPathRenderer.cpp | 13 | ||||
-rw-r--r-- | src/gpu/GrDefaultPathRenderer.cpp | 55 | ||||
-rw-r--r-- | src/gpu/GrPathUtils.cpp | 8 |
3 files changed, 56 insertions, 20 deletions
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp index ed6bc6365b..fcf38ef7e7 100644 --- a/src/gpu/GrAAConvexPathRenderer.cpp +++ b/src/gpu/GrAAConvexPathRenderer.cpp @@ -15,6 +15,7 @@ #include "GrInvariantOutput.h" #include "GrProcessor.h" #include "GrPathUtils.h" +#include "SkGeometry.h" #include "SkString.h" #include "SkStrokeRec.h" #include "SkTraceEvent.h" @@ -307,6 +308,18 @@ static bool get_segments(const SkPath& path, update_degenerate_test(°enerateData, pts[2]); add_quad_segment(pts, segments, devBounds); break; + case SkPath::kConic_Verb: { + m.mapPoints(pts, 3); + SkScalar weight = iter.conicWeight(); + SkAutoConicToQuads converter; + const SkPoint* quadPts = converter.computeQuads(pts, weight, 0.5f); + for (int i = 0; i < converter.countQuads(); ++i) { + update_degenerate_test(°enerateData, quadPts[2*i + 1]); + update_degenerate_test(°enerateData, quadPts[2*i + 2]); + add_quad_segment(quadPts + 2*i, segments, devBounds); + } + break; + } case SkPath::kCubic_Verb: { m.mapPoints(pts, 4); update_degenerate_test(°enerateData, pts[1]); diff --git a/src/gpu/GrDefaultPathRenderer.cpp b/src/gpu/GrDefaultPathRenderer.cpp index 79e9f154ae..af0404ae0e 100644 --- a/src/gpu/GrDefaultPathRenderer.cpp +++ b/src/gpu/GrDefaultPathRenderer.cpp @@ -11,12 +11,12 @@ #include "GrDefaultGeoProcFactory.h" #include "GrDrawState.h" #include "GrPathUtils.h" +#include "SkGeometry.h" #include "SkString.h" #include "SkStrokeRec.h" #include "SkTLazy.h" #include "SkTraceEvent.h" - GrDefaultPathRenderer::GrDefaultPathRenderer(bool separateStencilSupport, bool stencilWrapOpsSupport) : fSeparateStencil(separateStencilSupport) @@ -189,6 +189,24 @@ static inline void append_countour_edge_indices(bool hairLine, *((*indices)++) = edgeV0Idx + 1; } +static inline void add_quad(SkPoint** vert, const SkPoint* base, const SkPoint pts[], + SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol, bool indexed, + bool isHairline, uint16_t subpathIdxStart, uint16_t** idx) { + // first pt of quad is the pt we ended on in previous step + uint16_t firstQPtIdx = (uint16_t)(*vert - base) - 1; + uint16_t numPts = (uint16_t) + GrPathUtils::generateQuadraticPoints( + pts[0], pts[1], pts[2], + srcSpaceTolSqd, vert, + GrPathUtils::quadraticPointCount(pts, srcSpaceTol)); + if (indexed) { + for (uint16_t i = 0; i < numPts; ++i) { + append_countour_edge_indices(isHairline, subpathIdxStart, + firstQPtIdx + i, idx); + } + } +} + bool GrDefaultPathRenderer::createGeom(GrDrawTarget* target, GrDrawState* drawState, GrPrimitiveType* primType, @@ -256,9 +274,6 @@ bool GrDefaultPathRenderer::createGeom(GrDrawTarget* target, for (;;) { SkPath::Verb verb = iter.next(pts); switch (verb) { - case SkPath::kConic_Verb: - SkASSERT(0); - break; case SkPath::kMove_Verb: if (!first) { uint16_t currIdx = (uint16_t) (vert - base); @@ -276,22 +291,22 @@ bool GrDefaultPathRenderer::createGeom(GrDrawTarget* target, } *(vert++) = pts[1]; break; - case SkPath::kQuad_Verb: { - // first pt of quad is the pt we ended on in previous step - uint16_t firstQPtIdx = (uint16_t)(vert - base) - 1; - uint16_t numPts = (uint16_t) - GrPathUtils::generateQuadraticPoints( - pts[0], pts[1], pts[2], - srcSpaceTolSqd, &vert, - GrPathUtils::quadraticPointCount(pts, srcSpaceTol)); - if (indexed) { - for (uint16_t i = 0; i < numPts; ++i) { - append_countour_edge_indices(isHairline, subpathIdxStart, - firstQPtIdx + i, &idx); - } + case SkPath::kConic_Verb: { + SkScalar weight = iter.conicWeight(); + SkAutoConicToQuads converter; + // Converting in src-space, hance the finer tolerance (0.25) + // TODO: find a way to do this in dev-space so the tolerance means something + const SkPoint* quadPts = converter.computeQuads(pts, weight, 0.25f); + for (int i = 0; i < converter.countQuads(); ++i) { + add_quad(&vert, base, quadPts + i*2, srcSpaceTolSqd, srcSpaceTol, indexed, + isHairline, subpathIdxStart, &idx); } break; } + case SkPath::kQuad_Verb: + add_quad(&vert, base, pts, srcSpaceTolSqd, srcSpaceTol, indexed, + isHairline, subpathIdxStart, &idx); + break; case SkPath::kCubic_Verb: { // first pt of cubic is the pt we ended on in previous step uint16_t firstCPtIdx = (uint16_t)(vert - base) - 1; @@ -530,9 +545,9 @@ bool GrDefaultPathRenderer::canDrawPath(const GrDrawTarget* target, const SkStrokeRec& stroke, bool antiAlias) const { // this class can draw any path with any fill but doesn't do any anti-aliasing. - - return !antiAlias && !(SkPath::kConic_SegmentMask & path.getSegmentMasks()) && - (stroke.isFillStyle() || IsStrokeHairlineOrEquivalent(stroke, viewMatrix, NULL)); + return !antiAlias && (stroke.isFillStyle() || IsStrokeHairlineOrEquivalent(stroke, + viewMatrix, + NULL)); } bool GrDefaultPathRenderer::onDrawPath(GrDrawTarget* target, diff --git a/src/gpu/GrPathUtils.cpp b/src/gpu/GrPathUtils.cpp index 81dc103e02..8e7a01d091 100644 --- a/src/gpu/GrPathUtils.cpp +++ b/src/gpu/GrPathUtils.cpp @@ -166,6 +166,14 @@ int GrPathUtils::worstCasePointCount(const SkPath& path, int* subpaths, case SkPath::kLine_Verb: pointCount += 1; break; + case SkPath::kConic_Verb: { + SkScalar weight = iter.conicWeight(); + SkAutoConicToQuads converter; + const SkPoint* quadPts = converter.computeQuads(pts, weight, 0.25f); + for (int i = 0; i < converter.countQuads(); ++i) { + pointCount += quadraticPointCount(quadPts + 2*i, tol); + } + } case SkPath::kQuad_Verb: pointCount += quadraticPointCount(pts, tol); break; |