Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: src/core/SkEdge.h

Issue 2221103002: Analytic AntiAlias for Convex Shapes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make alpha computation cleaner and faster Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkEdge.h
diff --git a/src/core/SkEdge.h b/src/core/SkEdge.h
index 11669b4f7fb4056f0309022294a0bc8dc625fd1b..db1764671df18af041bb63d6a9e5354fe7771e74 100644
--- a/src/core/SkEdge.h
+++ b/src/core/SkEdge.h
@@ -130,5 +130,144 @@ int SkEdge::setLine(const SkPoint& p0, const SkPoint& p1, int shift) {
return 1;
}
+//////////////Analytic Edges////////////////////////////////
+
+struct SkAnalyticEdge {
+ enum Type {
+ kLine_Type,
+ kQuad_Type,
caryclark 2016/08/10 13:08:10 could you add a comment about how conic is support
liyuqian 2016/08/16 13:22:05 Done.
+ kCubic_Type
+ };
+
+ SkAnalyticEdge* fNext;
+ SkAnalyticEdge* fPrev;
+
+ SkFixed fX;
+ SkFixed fDX;
+ SkFixed fUpperX;
caryclark 2016/08/10 13:08:10 Could you add comments on what these fields mean a
liyuqian 2016/08/16 13:22:05 Done.
+ SkFixed fY;
+ SkFixed fUpperY;
+ SkFixed fLowerY;
+ SkFixed fDY; // abs of the inverse of fDX; may be SK_MaxS32 when fDX is close to 0
caryclark 2016/08/10 13:08:10 is this comment on the right line?
liyuqian 2016/08/16 13:22:05 Yes, I'm adding an extra newline to make it more c
+ // fDY is only used for blitting trapezoids
+ int8_t fCurveCount; // only used by kQuad(+) and kCubic(-)
+ uint8_t fCurveShift; // appled to all Dx/DDx/DDDx except for fCubicDShift exception
+ uint8_t fCubicDShift; // applied to fCDx and fCDy only in cubic
+ int8_t fWinding; // 1 or -1
+
+ static const int kDefaultAccuracy = 4; // default accuracy for snapping y
+
+ static inline SkFixed snapY(SkFixed y, int accuracy = kDefaultAccuracy) {
+ // We do ceiling to ensure that y is increasing
+ return SkFixedCeilToFixed(y << accuracy) >> accuracy;
+ }
+
+ static inline SkFixed snapX(SkFixed x, int accuracy = kDefaultAccuracy) {
+ return SkFixedRoundToFixed(x << accuracy) >> accuracy;
+ }
+
+ inline void goY(SkFixed y) {
+ if (y == fY + SK_Fixed1) {
+ fX = fX + fDX;
+ return;
+ } else if (y != fY) {
+ // Drop lower digits as our alpha only has 8 bits
+ // (fDX and y - fUpperY may be greater than SK_Fixed1)
+ fX = fUpperX + SkFixedMul_lowprec(fDX, y - fUpperY);
+ }
+ fY = y;
+ }
+
+ int setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip);
caryclark 2016/08/10 13:08:10 what does the return result mean? If it is always
liyuqian 2016/08/16 13:22:05 I've changed it to bool. I don't know why the orig
+ // call this version if you know you don't have a clip
+ inline int setLine(const SkPoint& p0, const SkPoint& p1);
caryclark 2016/08/10 13:08:10 ditto
liyuqian 2016/08/16 13:22:05 Done.
+ inline int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by);
+ void chopLineWithClip(const SkIRect& clip);
+
+ inline bool intersectsClip(const SkIRect& clip) const {
+ SkASSERT(SkFixedFloorToInt(fUpperY) < clip.fBottom);
+ return SkFixedCeilToInt(fLowerY) > clip.fTop;
+ }
+
+#ifdef SK_DEBUG
+ void dump() const {
+ SkDebugf("edge: upperY:%d lowerY:%d y:%g x:%g dx:%g w:%d\n",
+ fUpperY, fLowerY, SkFixedToFloat(fY), SkFixedToFloat(fX),
+ SkFixedToFloat(fDX), fWinding);
+ }
+
+ void validate() const {
+ SkASSERT(fPrev && fNext);
+ SkASSERT(fPrev->fNext == this);
+ SkASSERT(fNext->fPrev == this);
+
+ SkASSERT(fUpperY < fLowerY);
+ SkASSERT(SkAbs32(fWinding) == 1);
+ }
+#endif
+};
+
+struct SkAnalyticQuadraticEdge : public SkAnalyticEdge {
+ SkFixed fQx, fQy;
+ SkFixed fQDx, fQDy;
+ SkFixed fQDDx, fQDDy;
+ SkFixed fQLastX, fQLastY;
+
+ // snap y to integer points in the middle of the curve to accelerate AAA path filling
+ SkFixed fSnappedX, fSnappedY;
+
+ int setQuadratic(const SkPoint pts[3]);
+ int updateQuadratic();
+};
+
+struct SkAnalyticCubicEdge : public SkAnalyticEdge {
+ SkFixed fCx, fCy;
+ SkFixed fCDx, fCDy;
+ SkFixed fCDDx, fCDDy;
+ SkFixed fCDDDx, fCDDDy;
+ SkFixed fCLastX, fCLastY;
+
+ int setCubic(const SkPoint pts[4]);
+ int updateCubic();
+};
+
+int SkAnalyticEdge::setLine(const SkPoint& p0, const SkPoint& p1) {
+ SkFixed x0, y0, x1, y1;
+
+ x0 = SkScalarToFixed(p0.fX);
+ y0 = snapY(SkScalarToFixed(p0.fY));
+ x1 = SkScalarToFixed(p1.fX);
+ y1 = snapY(SkScalarToFixed(p1.fY));
+
+ int winding = 1;
+
+ if (y0 > y1) {
+ SkTSwap(x0, x1);
+ SkTSwap(y0, y1);
+ winding = -1;
+ }
+
+ // are we a zero-height line?
+ if (y0 == y1) {
+ return 0;
+ }
+
+ SkFixed slope = SkFixedDiv(x1 - x0, y1 - y0);
+
+ fX = x0;
+ fDX = slope;
+ fUpperX = x0;
+ fY = y0;
+ fUpperY = y0;
+ fLowerY = y1;
+ fDY = x1 - x0 != 0 ? SkAbs32(SkFixedDiv(y1 - y0, x1 - x0)) : SK_MaxS32;
caryclark 2016/08/10 13:08:10 x1 == x0 ?
liyuqian 2016/08/16 13:22:05 Done.
+ fCurveCount = 0;
+ fWinding = SkToS8(winding);
+ fCurveShift = 0;
+ return 1;
+}
+
+////////////////////////////////////////////////////////////
+
#endif

Powered by Google App Engine
This is Rietveld 408576698