extend clipper for lines, for uniformity, and so curves can call itself with lines
authorMike Reed <reed@google.com>
Thu, 26 Jan 2017 19:21:26 +0000 (14:21 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 26 Jan 2017 19:57:47 +0000 (19:57 +0000)
BUG=skia:

Change-Id: Id8c1fba6fcd2496802d3d17afe3f5c91bf5dfc33
Reviewed-on: https://skia-review.googlesource.com/7621
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Mike Reed <reed@google.com>

src/core/SkEdgeBuilder.cpp
src/core/SkEdgeClipper.cpp
src/core/SkEdgeClipper.h

index 22ee9ed..22942f4 100644 (file)
@@ -377,14 +377,11 @@ int SkEdgeBuilder::build(const SkPath& path, const SkIRect* iclip, int shiftUp,
                     // we ignore these, and just get the whole segment from
                     // the corresponding line/quad/cubic verbs
                     break;
-                case SkPath::kLine_Verb: {
-                    SkPoint lines[SkLineClipper::kMaxPoints];
-                    int lineCount = SkLineClipper::ClipLine(pts, clip, lines, canCullToTheRight);
-                    for (int i = 0; i < lineCount; i++) {
-                        this->addLine(&lines[i]);
+                case SkPath::kLine_Verb:
+                    if (clipper.clipLine(pts[0], pts[1], clip)) {
+                        this->addClipper(&clipper);
                     }
                     break;
-                }
                 case SkPath::kQuad_Verb:
                     if (clipper.clipQuad(pts, clip)) {
                         this->addClipper(&clipper);
index b5ac27a..97d7169 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "SkEdgeClipper.h"
 #include "SkGeometry.h"
+#include "SkLineClipper.h"
 
 static bool quick_reject(const SkRect& bounds, const SkRect& clip) {
     return bounds.fTop >= clip.fBottom || bounds.fBottom <= clip.fTop;
@@ -42,6 +43,23 @@ static bool sort_increasing_Y(SkPoint dst[], const SkPoint src[], int count) {
     }
 }
 
+bool SkEdgeClipper::clipLine(SkPoint p0, SkPoint p1, const SkRect& clip) {
+    fCurrPoint = fPoints;
+    fCurrVerb = fVerbs;
+
+    SkPoint lines[SkLineClipper::kMaxPoints];
+    const SkPoint pts[] = { p0, p1 };
+    int lineCount = SkLineClipper::ClipLine(pts, clip, lines, fCanCullToTheRight);
+    for (int i = 0; i < lineCount; i++) {
+        this->appendLine(lines[i], lines[i + 1]);
+    }
+
+    *fCurrVerb = SkPath::kDone_Verb;
+    fCurrPoint = fPoints;
+    fCurrVerb = fVerbs;
+    return SkPath::kDone_Verb != fVerbs[0];
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 static bool chopMonoQuadAt(SkScalar c0, SkScalar c1, SkScalar c2,
@@ -407,6 +425,13 @@ bool SkEdgeClipper::clipCubic(const SkPoint srcPts[4], const SkRect& clip) {
 
 ///////////////////////////////////////////////////////////////////////////////
 
+void SkEdgeClipper::appendLine(SkPoint p0, SkPoint p1) {
+    *fCurrVerb++ = SkPath::kLine_Verb;
+    fCurrPoint[0] = p0;
+    fCurrPoint[1] = p1;
+    fCurrPoint += 2;
+}
+
 void SkEdgeClipper::appendVLine(SkScalar x, SkScalar y0, SkScalar y1,
                                 bool reverse) {
     *fCurrVerb++ = SkPath::kLine_Verb;
index e460c1c..b20c0a1 100644 (file)
@@ -18,6 +18,7 @@ class SkEdgeClipper {
 public:
     SkEdgeClipper(bool canCullToTheRight) : fCanCullToTheRight(canCullToTheRight) {}
 
+    bool clipLine(SkPoint p0, SkPoint p1, const SkRect& clip);
     bool clipQuad(const SkPoint pts[3], const SkRect& clip);
     bool clipCubic(const SkPoint pts[4], const SkRect& clip);
 
@@ -39,6 +40,7 @@ private:
 
     void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
     void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
+    void appendLine(SkPoint p0, SkPoint p1);
     void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
     void appendQuad(const SkPoint pts[3], bool reverse);
     void appendCubic(const SkPoint pts[4], bool reverse);