diff options
author | stephana <stephana@google.com> | 2016-10-04 09:56:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-04 09:56:08 -0700 |
commit | d36baa7a4a5ae3cc94cc4a45379f55658f80c0a6 (patch) | |
tree | d70c97848f983c8f8d6bac4e120784fbc47221c5 /src/core/SkEdgeBuilder.cpp | |
parent | 7795822807478143120c33228b68d2ab3918af2c (diff) |
Revert of Analytic AntiAlias for Convex Shapes (patchset #14 id:260001 of https://codereview.chromium.org/2221103002/ )
Reason for revert:
Breaks iOS build.
Original issue's description:
> Implement AnalyticAA for convex shapes.
>
> Design doc: go/analyticAA
>
> A performance test can be found here: https://docs.google.com/a/google.com/spreadsheets/d/1n9LSjFzrQzx0hovFddWey0GSMXNRjl1oFuSypMlHWZk/edit?usp=sharing
>
> Our best case is filling big triangles, which according to our experiment has ~2.9x speedup. Our worst case is filling small ovals/circles, which has a ~1.06x slowdown.
>
> To see how our new algorithm changes the DM images, see: https://x20web.corp.google.com/~liyuqian/dmdiff/index.html
> The most significant changes are in convexpaths and analytic_antialias_convex
>
> BUG=skia:
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2221103002
>
> Committed: https://skia.googlesource.com/skia/+/7795822807478143120c33228b68d2ab3918af2c
TBR=reed@google.com,caryclark@google.com,liyuqian@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review-Url: https://codereview.chromium.org/2388213003
Diffstat (limited to 'src/core/SkEdgeBuilder.cpp')
-rw-r--r-- | src/core/SkEdgeBuilder.cpp | 185 |
1 files changed, 36 insertions, 149 deletions
diff --git a/src/core/SkEdgeBuilder.cpp b/src/core/SkEdgeBuilder.cpp index 1a160882d4..af68e0ff65 100644 --- a/src/core/SkEdgeBuilder.cpp +++ b/src/core/SkEdgeBuilder.cpp @@ -7,7 +7,6 @@ #include "SkEdgeBuilder.h" #include "SkPath.h" #include "SkEdge.h" -#include "SkAnalyticEdge.h" #include "SkEdgeClipper.h" #include "SkLineClipper.h" #include "SkGeometry.h" @@ -63,135 +62,45 @@ SkEdgeBuilder::Combine SkEdgeBuilder::CombineVertical(const SkEdge* edge, SkEdge return kNo_Combine; } -SkEdgeBuilder::Combine SkEdgeBuilder::CombineVertical( - const SkAnalyticEdge* edge, SkAnalyticEdge* last) { - SkASSERT(fAnalyticAA); - if (last->fCurveCount || last->fDX || edge->fX != last->fX) { - return kNo_Combine; - } - if (edge->fWinding == last->fWinding) { - if (edge->fLowerY == last->fUpperY) { - last->fUpperY = edge->fUpperY; - last->fY = last->fUpperY; - return kPartial_Combine; - } - if (edge->fUpperY == last->fLowerY) { - last->fLowerY = edge->fLowerY; - return kPartial_Combine; - } - return kNo_Combine; - } - if (edge->fUpperY == last->fUpperY) { - if (edge->fLowerY == last->fLowerY) { - return kTotal_Combine; - } - if (edge->fLowerY < last->fLowerY) { - last->fUpperY = edge->fLowerY; - last->fY = last->fUpperY; - return kPartial_Combine; - } - last->fUpperY = last->fLowerY; - last->fY = last->fUpperY; - last->fLowerY = edge->fLowerY; - last->fWinding = edge->fWinding; - return kPartial_Combine; - } - if (edge->fLowerY == last->fLowerY) { - if (edge->fUpperY > last->fUpperY) { - last->fLowerY = edge->fUpperY; - return kPartial_Combine; - } - last->fLowerY = last->fUpperY; - last->fUpperY = edge->fUpperY; - last->fY = last->fUpperY; - last->fWinding = edge->fWinding; - return kPartial_Combine; - } - return kNo_Combine; -} - -bool SkEdgeBuilder::vertical_line(const SkEdge* edge) { - return !edge->fDX && !edge->fCurveCount; -} - -bool SkEdgeBuilder::vertical_line(const SkAnalyticEdge* edge) { - SkASSERT(fAnalyticAA); +static bool vertical_line(const SkEdge* edge) { return !edge->fDX && !edge->fCurveCount; } void SkEdgeBuilder::addLine(const SkPoint pts[]) { - if (fAnalyticAA) { - SkAnalyticEdge* edge = typedAllocThrow<SkAnalyticEdge>(fAlloc); - if (edge->setLine(pts[0], pts[1])) { - if (vertical_line(edge) && fList.count()) { - Combine combine = CombineVertical(edge, (SkAnalyticEdge*)*(fList.end() - 1)); - if (kNo_Combine != combine) { - if (kTotal_Combine == combine) { - fList.pop(); - } - goto unallocate_analytic_edge; + SkEdge* edge = typedAllocThrow<SkEdge>(fAlloc); + if (edge->setLine(pts[0], pts[1], fShiftUp)) { + if (vertical_line(edge) && fList.count()) { + Combine combine = CombineVertical(edge, *(fList.end() - 1)); + if (kNo_Combine != combine) { + if (kTotal_Combine == combine) { + fList.pop(); } + goto unallocate_edge; } - fList.push(edge); - } else { -unallocate_analytic_edge: - ; - // TODO: unallocate edge from storage... } + fList.push(edge); } else { - SkEdge* edge = typedAllocThrow<SkEdge>(fAlloc); - if (edge->setLine(pts[0], pts[1], fShiftUp)) { - if (vertical_line(edge) && fList.count()) { - Combine combine = CombineVertical(edge, (SkEdge*)*(fList.end() - 1)); - if (kNo_Combine != combine) { - if (kTotal_Combine == combine) { - fList.pop(); - } - goto unallocate_edge; - } - } - fList.push(edge); - } else { unallocate_edge: - ; - // TODO: unallocate edge from storage... - } + ; + // TODO: unallocate edge from storage... } } void SkEdgeBuilder::addQuad(const SkPoint pts[]) { - if (fAnalyticAA) { - SkAnalyticQuadraticEdge* edge = typedAllocThrow<SkAnalyticQuadraticEdge>(fAlloc); - if (edge->setQuadratic(pts)) { - fList.push(edge); - } else { - // TODO: unallocate edge from storage... - } + SkQuadraticEdge* edge = typedAllocThrow<SkQuadraticEdge>(fAlloc); + if (edge->setQuadratic(pts, fShiftUp)) { + fList.push(edge); } else { - SkQuadraticEdge* edge = typedAllocThrow<SkQuadraticEdge>(fAlloc); - if (edge->setQuadratic(pts, fShiftUp)) { - fList.push(edge); - } else { - // TODO: unallocate edge from storage... - } + // TODO: unallocate edge from storage... } } void SkEdgeBuilder::addCubic(const SkPoint pts[]) { - if (fAnalyticAA) { - SkAnalyticCubicEdge* edge = typedAllocThrow<SkAnalyticCubicEdge>(fAlloc); - if (edge->setCubic(pts)) { - fList.push(edge); - } else { - // TODO: unallocate edge from storage... - } + SkCubicEdge* edge = typedAllocThrow<SkCubicEdge>(fAlloc); + if (edge->setCubic(pts, fShiftUp)) { + fList.push(edge); } else { - SkCubicEdge* edge = typedAllocThrow<SkCubicEdge>(fAlloc); - if (edge->setCubic(pts, fShiftUp)) { - fList.push(edge); - } else { - // TODO: unallocate edge from storage... - } + // TODO: unallocate edge from storage... } } @@ -226,14 +135,7 @@ static void setShiftedClip(SkRect* dst, const SkIRect& src, int shift) { } SkEdgeBuilder::Combine SkEdgeBuilder::checkVertical(const SkEdge* edge, SkEdge** edgePtr) { - return !vertical_line(edge) || edgePtr <= (SkEdge**)fEdgeList ? kNo_Combine : - CombineVertical(edge, edgePtr[-1]); -} - -SkEdgeBuilder::Combine SkEdgeBuilder::checkVertical(const SkAnalyticEdge* edge, - SkAnalyticEdge** edgePtr) { - SkASSERT(fAnalyticAA); - return !vertical_line(edge) || edgePtr <= (SkAnalyticEdge**)fEdgeList ? kNo_Combine : + return !vertical_line(edge) || edgePtr <= fEdgeList ? kNo_Combine : CombineVertical(edge, edgePtr[-1]); } @@ -250,16 +152,15 @@ int SkEdgeBuilder::buildPoly(const SkPath& path, const SkIRect* iclip, int shift // segments. maxEdgeCount *= SkLineClipper::kMaxClippedLineSegments; } - size_t edgeSize = fAnalyticAA ? sizeof(SkAnalyticEdge) : sizeof(SkEdge); - size_t maxEdgeSize = maxEdgeCount * edgeSize; - size_t maxEdgePtrSize = maxEdgeCount * sizeof(char*); + size_t maxEdgeSize = maxEdgeCount * sizeof(SkEdge); + size_t maxEdgePtrSize = maxEdgeCount * sizeof(SkEdge*); // lets store the edges and their pointers in the same block char* storage = (char*)fAlloc.allocThrow(maxEdgeSize + maxEdgePtrSize); - char* edge = (char*)storage; - char** edgePtr = (char**)(storage + maxEdgeSize); + SkEdge* edge = reinterpret_cast<SkEdge*>(storage); + SkEdge** edgePtr = reinterpret_cast<SkEdge**>(storage + maxEdgeSize); // Record the beginning of our pointers, so we can return them to the caller - fEdgeList = (void**)edgePtr; + fEdgeList = edgePtr; if (iclip) { SkRect clip; @@ -277,16 +178,10 @@ int SkEdgeBuilder::buildPoly(const SkPath& path, const SkIRect* iclip, int shift int lineCount = SkLineClipper::ClipLine(pts, clip, lines, canCullToTheRight); SkASSERT(lineCount <= SkLineClipper::kMaxClippedLineSegments); for (int i = 0; i < lineCount; i++) { - bool setLineResult = fAnalyticAA ? - ((SkAnalyticEdge*)edge)->setLine(lines[i], lines[i + 1]) : - ((SkEdge*)edge)->setLine(lines[i], lines[i + 1], shiftUp); - if (setLineResult) { - Combine combine = fAnalyticAA ? - checkVertical((SkAnalyticEdge*)edge, (SkAnalyticEdge**)edgePtr) : - checkVertical((SkEdge*)edge, (SkEdge**)edgePtr); + if (edge->setLine(lines[i], lines[i + 1], shiftUp)) { + Combine combine = checkVertical(edge, edgePtr); if (kNo_Combine == combine) { - *edgePtr++ = edge; - edge += edgeSize; + *edgePtr++ = edge++; } else if (kTotal_Combine == combine) { --edgePtr; } @@ -307,23 +202,16 @@ int SkEdgeBuilder::buildPoly(const SkPath& path, const SkIRect* iclip, int shift // we ignore these, and just get the whole segment from // the corresponding line/quad/cubic verbs break; - case SkPath::kLine_Verb: { - bool setLineResult = fAnalyticAA ? - ((SkAnalyticEdge*)edge)->setLine(pts[0], pts[1]) : - ((SkEdge*)edge)->setLine(pts[0], pts[1], shiftUp); - if (setLineResult) { - Combine combine = fAnalyticAA ? - checkVertical((SkAnalyticEdge*)edge, (SkAnalyticEdge**)edgePtr) : - checkVertical((SkEdge*)edge, (SkEdge**)edgePtr); + case SkPath::kLine_Verb: + if (edge->setLine(pts[0], pts[1], shiftUp)) { + Combine combine = checkVertical(edge, edgePtr); if (kNo_Combine == combine) { - *edgePtr++ = edge; - edge += edgeSize; + *edgePtr++ = edge++; } else if (kTotal_Combine == combine) { --edgePtr; } } break; - } default: SkDEBUGFAIL("unexpected verb"); break; @@ -331,8 +219,8 @@ int SkEdgeBuilder::buildPoly(const SkPath& path, const SkIRect* iclip, int shift } } SkASSERT((char*)edge <= (char*)fEdgeList); - SkASSERT(edgePtr - (char**)fEdgeList <= maxEdgeCount); - return SkToInt(edgePtr - (char**)fEdgeList); + SkASSERT(edgePtr - fEdgeList <= maxEdgeCount); + return SkToInt(edgePtr - fEdgeList); } static void handle_quad(SkEdgeBuilder* builder, const SkPoint pts[3]) { @@ -344,11 +232,10 @@ static void handle_quad(SkEdgeBuilder* builder, const SkPoint pts[3]) { } int SkEdgeBuilder::build(const SkPath& path, const SkIRect* iclip, int shiftUp, - bool canCullToTheRight, bool analyticAA) { + bool canCullToTheRight) { fAlloc.reset(); fList.reset(); fShiftUp = shiftUp; - fAnalyticAA = analyticAA; if (SkPath::kLine_SegmentMask == path.getSegmentMasks()) { return this->buildPoly(path, iclip, shiftUp, canCullToTheRight); |