diff options
author | 2013-01-30 12:50:38 +0000 | |
---|---|---|
committer | 2013-01-30 12:50:38 +0000 | |
commit | 86adc0d414496185972a7191aca904e9e7223d7d (patch) | |
tree | cc4d65451f9de8a6a8bd8c4da289920b66924a58 /experimental | |
parent | 2a772e14c5c637e1daff0d7ddc81559330feb8e2 (diff) |
shape ops work in progress
git-svn-id: http://skia.googlecode.com/svn/trunk@7459 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/Intersection/CubicIntersection_Test.cpp | 2 | ||||
-rw-r--r-- | experimental/Intersection/EdgeWalker_Test.h | 3 | ||||
-rw-r--r-- | experimental/Intersection/EdgeWalker_TestUtility.cpp | 56 | ||||
-rw-r--r-- | experimental/Intersection/Simplify.cpp | 16 |
4 files changed, 54 insertions, 23 deletions
diff --git a/experimental/Intersection/CubicIntersection_Test.cpp b/experimental/Intersection/CubicIntersection_Test.cpp index 738a0dc401..d6816e3400 100644 --- a/experimental/Intersection/CubicIntersection_Test.cpp +++ b/experimental/Intersection/CubicIntersection_Test.cpp @@ -57,7 +57,7 @@ void CubicIntersection_Test() { } } -#define ONE_OFF_DEBUG 1 +#define ONE_OFF_DEBUG 0 static void oneOff(const Cubic& cubic1, const Cubic& cubic2) { SkTDArray<Quadratic> quads1; diff --git a/experimental/Intersection/EdgeWalker_Test.h b/experimental/Intersection/EdgeWalker_Test.h index 205051ebae..8799b35ffb 100644 --- a/experimental/Intersection/EdgeWalker_Test.h +++ b/experimental/Intersection/EdgeWalker_Test.h @@ -13,7 +13,8 @@ struct State4; //extern int comparePaths(const SkPath& one, const SkPath& two); extern int comparePaths(const SkPath& one, const SkPath& two, SkBitmap& bitmap); -extern int comparePaths(const SkPath& one, const SkPath& two, SkBitmap& bitmap, +extern int comparePaths(const SkPath& one, const SkPath& scaledOne, const SkPath& two, + const SkPath& scaledTwo, SkBitmap& bitmap, const SkPath& a, const SkPath& b, const ShapeOp shapeOp); extern void comparePathsTiny(const SkPath& one, const SkPath& two); extern bool drawAsciiPaths(const SkPath& one, const SkPath& two, diff --git a/experimental/Intersection/EdgeWalker_TestUtility.cpp b/experimental/Intersection/EdgeWalker_TestUtility.cpp index f0af4f4346..ae5632e17d 100644 --- a/experimental/Intersection/EdgeWalker_TestUtility.cpp +++ b/experimental/Intersection/EdgeWalker_TestUtility.cpp @@ -104,15 +104,10 @@ void showPath(const SkPath& path, const char* str) { showPathContour(iter); } -static int pathsDrawTheSame(const SkPath& one, const SkPath& two, - SkBitmap& bits, SkPath& scaledOne, SkPath& scaledTwo, int& error2x2) { const int bitWidth = 64; const int bitHeight = 64; - if (bits.width() == 0) { - bits.setConfig(SkBitmap::kARGB_8888_Config, bitWidth * 2, bitHeight); - bits.allocPixels(); - } +static void scaleMatrix(const SkPath& one, const SkPath& two, SkMatrix& scale) { SkRect larger = one.getBounds(); larger.join(two.getBounds()); SkScalar largerWidth = larger.width(); @@ -125,17 +120,21 @@ static int pathsDrawTheSame(const SkPath& one, const SkPath& two, } SkScalar hScale = (bitWidth - 2) / largerWidth; SkScalar vScale = (bitHeight - 2) / largerHeight; - SkMatrix scale; scale.reset(); scale.preScale(hScale, vScale); - one.transform(scale, &scaledOne); - two.transform(scale, &scaledTwo); - const SkRect& bounds1 = scaledOne.getBounds(); +} +static int pathsDrawTheSame(SkBitmap& bits, const SkPath& scaledOne, const SkPath& scaledTwo, + int& error2x2) { + if (bits.width() == 0) { + bits.setConfig(SkBitmap::kARGB_8888_Config, bitWidth * 2, bitHeight); + bits.allocPixels(); + } SkCanvas canvas(bits); canvas.drawColor(SK_ColorWHITE); SkPaint paint; canvas.save(); + const SkRect& bounds1 = scaledOne.getBounds(); canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1); canvas.drawPath(scaledOne, paint); canvas.restore(); @@ -167,6 +166,15 @@ static int pathsDrawTheSame(const SkPath& one, const SkPath& two, return errors; } +static int pathsDrawTheSame(const SkPath& one, const SkPath& two, SkBitmap& bits, SkPath& scaledOne, + SkPath& scaledTwo, int& error2x2) { + SkMatrix scale; + scaleMatrix(one, two, scale); + one.transform(scale, &scaledOne); + two.transform(scale, &scaledTwo); + return pathsDrawTheSame(bits, scaledOne, scaledTwo, error2x2); +} + bool drawAsciiPaths(const SkPath& one, const SkPath& two, bool drawPaths) { if (!drawPaths) { return true; @@ -252,11 +260,11 @@ static void showShapeOpPath(const SkPath& one, const SkPath& two, const SkPath& drawAsciiPaths(scaledOne, scaledTwo, true); } -int comparePaths(const SkPath& one, const SkPath& two, SkBitmap& bitmap, - const SkPath& a, const SkPath& b, const ShapeOp shapeOp) { +int comparePaths(const SkPath& one, const SkPath& scaledOne, const SkPath& two, + const SkPath& scaledTwo, + SkBitmap& bitmap, const SkPath& a, const SkPath& b, const ShapeOp shapeOp) { int errors2x2; - SkPath scaledOne, scaledTwo; - int errors = pathsDrawTheSame(one, two, bitmap, scaledOne, scaledTwo, errors2x2); + int errors = pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); if (errors2x2 == 0) { return 0; } @@ -359,15 +367,31 @@ bool testSimplifyx(const SkPath& path) { bool testShapeOp(const SkPath& a, const SkPath& b, const ShapeOp shapeOp) { SkPath out; operate(a, b, shapeOp, out); - SkPath pathOut; + SkPath pathOut, scaledPathOut; SkRegion rgnA, rgnB, openClip, rgnOut; openClip.setRect(-16000, -16000, 16000, 16000); rgnA.setPath(a, openClip); rgnB.setPath(b, openClip); rgnOut.op(rgnA, rgnB, (SkRegion::Op) shapeOp); rgnOut.getBoundaryPath(&pathOut); + + SkMatrix scale; + scaleMatrix(a, b, scale); + SkRegion scaledRgnA, scaledRgnB, scaledRgnOut; + SkPath scaledA, scaledB; + scaledA.addPath(a, scale); + scaledA.setFillType(a.getFillType()); + scaledB.addPath(b, scale); + scaledB.setFillType(b.getFillType()); + scaledRgnA.setPath(scaledA, openClip); + scaledRgnB.setPath(scaledB, openClip); + scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); + scaledRgnOut.getBoundaryPath(&scaledPathOut); SkBitmap bitmap; - int result = comparePaths(pathOut, out, bitmap, a, b, shapeOp); + SkPath scaledOut; + scaledOut.addPath(out, scale); + scaledOut.setFillType(out.getFillType()); + int result = comparePaths(pathOut, scaledPathOut, out, scaledOut, bitmap, a, b, shapeOp); if (result && gPathStrAssert) { SkASSERT(0); } diff --git a/experimental/Intersection/Simplify.cpp b/experimental/Intersection/Simplify.cpp index ad3767a33e..9b4ebc4481 100644 --- a/experimental/Intersection/Simplify.cpp +++ b/experimental/Intersection/Simplify.cpp @@ -31,7 +31,7 @@ int gDebugMaxWindValue = SK_MaxS32; #define APPROXIMATE_CUBICS 1 #define DEBUG_UNUSED 0 // set to expose unused functions -#define FORCE_RELEASE 0 // set force release to 1 for multiple thread -- no debugging +#define FORCE_RELEASE 1 // set force release to 1 for multiple thread -- no debugging #if FORCE_RELEASE || defined SK_RELEASE @@ -601,6 +601,7 @@ public: return cmp < 0; } // at this point, the initial tangent line is coincident + // see if edges curl away from each other if (fSide * rh.fSide <= 0 && (!approximately_zero(fSide) || !approximately_zero(rh.fSide))) { // FIXME: running demo will trigger this assertion @@ -767,18 +768,20 @@ public: fTangent1.quadEndPoints(fQ, 0, 1); #if 1 // FIXME: try enabling this and see if a) it's called and b) does it break anything if (dx() == 0 && dy() == 0) { - SkDebugf("*** %s quad is line\n"); + SkDebugf("*** %s quad is line\n", __FUNCTION__); fTangent1.quadEndPoints(fQ); } #endif fSide = -fTangent1.pointDistance(fQ[2]); // not normalized -- compare sign only break; - case SkPath::kCubic_Verb: + case SkPath::kCubic_Verb: { Cubic c; + int nextC = 2; CubicSubDivideHD(fPts, startT, endT, c); fTangent1.cubicEndPoints(c, 0, 1); if (dx() == 0 && dy() == 0) { fTangent1.cubicEndPoints(c, 0, 2); + nextC = 3; #if 1 // FIXME: try enabling this and see if a) it's called and b) does it break anything if (dx() == 0 && dy() == 0) { SkDebugf("*** %s cubic is line\n"); @@ -786,8 +789,11 @@ public: } #endif } - fSide = -fTangent1.pointDistance(c[2]); // not normalized -- compare sign only - break; + fSide = -fTangent1.pointDistance(c[nextC]); // not normalized -- compare sign only + if (nextC == 2 && approximately_zero(fSide)) { + fSide = -fTangent1.pointDistance(c[3]); + } + } break; default: SkASSERT(0); } |