void SkPathStroker::quad_to(const SkPoint pts[3], const SkVector& normalAB, const SkVector& unitNormalAB, SkVector* normalBC, SkVector* unitNormalBC, int subDivide) { if (!set_normal_unitnormal(pts[1], pts[2], fRadius, normalBC, unitNormalBC)) { // pts[1] nearly equals pts[2], so just draw a line to pts[2] this->line_to(pts[2], normalAB); *normalBC = normalAB; *unitNormalBC = unitNormalAB; return; } if (--subDivide >= 0 && normals_too_curvy(unitNormalAB, *unitNormalBC)) { SkPoint tmp[5]; SkVector norm, unit; SkChopQuadAtHalf(pts, tmp); this->quad_to(&tmp[0], normalAB, unitNormalAB, &norm, &unit, subDivide); this->quad_to(&tmp[2], norm, unit, normalBC, unitNormalBC, subDivide); } else { SkVector normalB, unitB; SkAssertResult(set_normal_unitnormal(pts[0], pts[2], fRadius, &normalB, &unitB)); fOuter.quadTo( pts[1].fX + normalB.fX, pts[1].fY + normalB.fY, pts[2].fX + normalBC->fX, pts[2].fY + normalBC->fY); fInner.quadTo( pts[1].fX - normalB.fX, pts[1].fY - normalB.fY, pts[2].fX - normalBC->fX, pts[2].fY - normalBC->fY); } }
// Need to exercise drawing an inverse-path whose bounds intersect the clip, // but whose edges do not (since its a quad which draws only in the bottom half // of its bounds). // In the debug build, we used to assert in this case, until it was fixed. // static void test_inversepathwithclip() { SkPath path; path.moveTo(0, 20); path.quadTo(10, 10, 20, 20); path.toggleInverseFillType(); SkPaint paint; auto surface(SkSurface::MakeRasterN32Premul(640, 480)); SkCanvas* canvas = surface->getCanvas(); canvas->save(); canvas->clipRect(SkRect::MakeWH(19, 11)); paint.setAntiAlias(false); canvas->drawPath(path, paint); paint.setAntiAlias(true); canvas->drawPath(path, paint); canvas->restore(); // Now do the test again, with the path flipped, so we only draw in the // top half of our bounds, and have the clip intersect our bounds at the // bottom. path.reset(); // preserves our filltype path.moveTo(0, 10); path.quadTo(10, 20, 20, 10); canvas->clipRect(SkRect::MakeXYWH(0, 19, 19, 11)); paint.setAntiAlias(false); canvas->drawPath(path, paint); paint.setAntiAlias(true); canvas->drawPath(path, paint); }
static void failOne(skiatest::Reporter* reporter, int index) { SkPath path; int i = (int) (index % nonFinitePtsCount); int f = (int) (index % finitePtsCount); int g = (int) ((f + 1) % finitePtsCount); switch (index % 13) { case 0: path.lineTo(nonFinitePts[i]); break; case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break; case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break; case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break; case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break; case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break; case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break; case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break; case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break; case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break; case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break; case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break; case 12: path.moveTo(nonFinitePts[i]); break; } SkPath result; result.setFillType(SkPath::kWinding_FillType); bool success = Simplify(path, &result); REPORTER_ASSERT(reporter, !success); REPORTER_ASSERT(reporter, result.isEmpty()); REPORTER_ASSERT(reporter, result.getFillType() == SkPath::kWinding_FillType); reporter->bumpTestCount(); }
static void fuzz763_1(skiatest::Reporter* reporter, const char* filename) { SkPath path; path.setFillType((SkPath::FillType) 0); path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 path.cubicTo(SkBits2Float(0xbcb63000), SkBits2Float(0xb6b6b6b7), SkBits2Float(0x38b6b6b6), SkBits2Float(0xafb63a5a), SkBits2Float(0xca000087), SkBits2Float(0xe93ae9e9)); // -0.0222397f, -5.44529e-06f, 8.71247e-05f, -3.31471e-10f, -2.09719e+06f, -1.41228e+25f path.quadTo(SkBits2Float(0xb6007fb6), SkBits2Float(0xb69fb6b6), SkBits2Float(0xe9e964b6), SkBits2Float(0xe9e9e9e9)); // -1.91478e-06f, -4.75984e-06f, -3.52694e+25f, -3.5348e+25f path.quadTo(SkBits2Float(0xb6b6b8b7), SkBits2Float(0xb60000b6), SkBits2Float(0xb6b6b6b6), SkBits2Float(0xe9e92064)); // -5.44553e-06f, -1.90739e-06f, -5.44529e-06f, -3.52291e+25f path.quadTo(SkBits2Float(0x000200e9), SkBits2Float(0xe9e9d100), SkBits2Float(0xe93ae9e9), SkBits2Float(0xe964b6e9)); // 1.83997e-40f, -3.53333e+25f, -1.41228e+25f, -1.72812e+25f path.quadTo(SkBits2Float(0x40b6e9e9), SkBits2Float(0xe9b60000), SkBits2Float(0x00b6b8e9), SkBits2Float(0xe9000001)); // 5.71605f, -2.75031e+25f, 1.67804e-38f, -9.67141e+24f path.quadTo(SkBits2Float(0xe9d3b6b2), SkBits2Float(0x40404540), SkBits2Float(0x803d4043), SkBits2Float(0xe9e9e9ff)); // -3.19933e+25f, 3.00423f, -5.62502e-39f, -3.53481e+25f path.cubicTo(SkBits2Float(0x00000000), SkBits2Float(0xe8b3b6b6), SkBits2Float(0xe90a0003), SkBits2Float(0x4040403c), SkBits2Float(0x803d4040), SkBits2Float(0xe9e80900)); // 0, -6.78939e+24f, -1.0427e+25f, 3.00392f, -5.62501e-39f, -3.50642e+25f path.quadTo(SkBits2Float(0xe9e910e9), SkBits2Float(0xe9e93ae9), SkBits2Float(0x0000b6b6), SkBits2Float(0xb6b6aab6)); // -3.52199e+25f, -3.52447e+25f, 6.55443e-41f, -5.4439e-06f path.moveTo(SkBits2Float(0xe9e92064), SkBits2Float(0xe9e9d106)); // -3.52291e+25f, -3.53334e+25f path.quadTo(SkBits2Float(0xe9e93ae9), SkBits2Float(0x0000abb6), SkBits2Float(0xb6b6bdb6), SkBits2Float(0xe92064b6)); // -3.52447e+25f, 6.15983e-41f, -5.44611e-06f, -1.2119e+25f path.quadTo(SkBits2Float(0x0000e9e9), SkBits2Float(0xb6b6b6e9), SkBits2Float(0x05ffff05), SkBits2Float(0xe9ea06e9)); // 8.39112e-41f, -5.44532e-06f, 2.40738e-35f, -3.53652e+25f path.quadTo(SkBits2Float(0xe93ae9e9), SkBits2Float(0x02007fe9), SkBits2Float(0xb8b7b600), SkBits2Float(0xe9e9b6b6)); // -1.41228e+25f, 9.44066e-38f, -8.76002e-05f, -3.53178e+25f path.quadTo(SkBits2Float(0xe9e9e9b6), SkBits2Float(0xedb6b6b6), SkBits2Float(0x5a38a1b6), SkBits2Float(0xe93ae9e9)); // -3.53479e+25f, -7.06839e+27f, 1.29923e+16f, -1.41228e+25f path.quadTo(SkBits2Float(0x0000b6b6), SkBits2Float(0xb6b6b6b6), SkBits2Float(0xe9e9e9b6), SkBits2Float(0xe9e9e954)); // 6.55443e-41f, -5.44529e-06f, -3.53479e+25f, -3.53477e+25f path.quadTo(SkBits2Float(0xb6e9e93a), SkBits2Float(0x375837ff), SkBits2Float(0xceb6b6b6), SkBits2Float(0x0039e94f)); // -6.97109e-06f, 1.28876e-05f, -1.53271e+09f, 5.31832e-39f path.quadTo(SkBits2Float(0xe9e9e9e9), SkBits2Float(0xe9e6e9e9), SkBits2Float(0xb6b641b6), SkBits2Float(0xede9e9e9)); // -3.5348e+25f, -3.48947e+25f, -5.43167e-06f, -9.0491e+27f path.moveTo(SkBits2Float(0xb6b6e9e9), SkBits2Float(0xb6b60000)); // -5.45125e-06f, -5.42402e-06f path.moveTo(SkBits2Float(0xe9b6b6b6), SkBits2Float(0xe9b6b8e9)); // -2.76109e+25f, -2.76122e+25f path.close(); path.moveTo(SkBits2Float(0xe9b6b6b6), SkBits2Float(0xe9b6b8e9)); // -2.76109e+25f, -2.76122e+25f path.quadTo(SkBits2Float(0xe93ae9e9), SkBits2Float(0xe964b6e9), SkBits2Float(0x0000203a), SkBits2Float(0xb6000000)); // -1.41228e+25f, -1.72812e+25f, 1.15607e-41f, -1.90735e-06f path.moveTo(SkBits2Float(0x64b6b6b6), SkBits2Float(0xe9e9e900)); // 2.69638e+22f, -3.53475e+25f path.quadTo(SkBits2Float(0xb6b6b6e9), SkBits2Float(0xb6b6b6b6), SkBits2Float(0xe9e9b6ce), SkBits2Float(0xe9e93ae9)); // -5.44532e-06f, -5.44529e-06f, -3.53179e+25f, -3.52447e+25f testSimplifyFuzz(reporter, path, filename); }
void SkPathStroker::quad_to(const SkPoint pts[3], const SkVector& normalAB, const SkVector& unitNormalAB, SkVector* normalBC, SkVector* unitNormalBC, int subDivide) { if (!set_normal_unitnormal(pts[1], pts[2], fRadius, normalBC, unitNormalBC)) { // pts[1] nearly equals pts[2], so just draw a line to pts[2] this->line_to(pts[2], normalAB); *normalBC = normalAB; *unitNormalBC = unitNormalAB; return; } if (--subDivide >= 0 && normals_too_curvy(unitNormalAB, *unitNormalBC)) { SkPoint tmp[5]; SkVector norm, unit; SkChopQuadAtHalf(pts, tmp); this->quad_to(&tmp[0], normalAB, unitNormalAB, &norm, &unit, subDivide); this->quad_to(&tmp[2], norm, unit, normalBC, unitNormalBC, subDivide); } else { SkVector normalB; normalB = pts[2] - pts[0]; normalB.rotateCCW(); SkScalar dot = SkPoint::DotProduct(unitNormalAB, *unitNormalBC); SkAssertResult(normalB.setLength(SkScalarDiv(fRadius, SkScalarSqrt((SK_Scalar1 + dot)/2)))); fOuter.quadTo( pts[1].fX + normalB.fX, pts[1].fY + normalB.fY, pts[2].fX + normalBC->fX, pts[2].fY + normalBC->fY); fInner.quadTo( pts[1].fX - normalB.fX, pts[1].fY - normalB.fY, pts[2].fX - normalBC->fX, pts[2].fY - normalBC->fY); } }
static void fuzz763_2s(skiatest::Reporter* reporter, const char* filename) { SkPath path; path.setFillType((SkPath::FillType) 0); path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 path.cubicTo(SkBits2Float(0x76773011), SkBits2Float(0x5d66fe78), SkBits2Float(0xbbeeff66), SkBits2Float(0x637677a2), SkBits2Float(0x205266fe), SkBits2Float(0xec296fdf)); // 1.25339e+33f, 1.0403e+18f, -0.00729363f, 4.54652e+21f, 1.78218e-19f, -8.19347e+26f path.lineTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 path.close(); path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 path.quadTo(SkBits2Float(0xec4eecec), SkBits2Float(0x6e6f10ec), SkBits2Float(0xb6b6ecf7), SkBits2Float(0xb6b6b6b6)); // -1.00063e+27f, 1.84968e+28f, -5.45161e-06f, -5.44529e-06f path.moveTo(SkBits2Float(0x002032b8), SkBits2Float(0xecfeb6b6)); // 2.95693e-39f, -2.46344e+27f path.moveTo(SkBits2Float(0x73737300), SkBits2Float(0x73735273)); // 1.9288e+31f, 1.9278e+31f path.cubicTo(SkBits2Float(0x1616ece4), SkBits2Float(0xdf020018), SkBits2Float(0x77772965), SkBits2Float(0x1009db73), SkBits2Float(0x80ececec), SkBits2Float(0xf7ffffff)); // 1.21917e-25f, -9.36751e+18f, 5.01303e+33f, 2.71875e-29f, -2.17582e-38f, -1.03846e+34f path.lineTo(SkBits2Float(0x73737300), SkBits2Float(0x73735273)); // 1.9288e+31f, 1.9278e+31f path.close(); path.moveTo(SkBits2Float(0x73737300), SkBits2Float(0x73735273)); // 1.9288e+31f, 1.9278e+31f path.conicTo(SkBits2Float(0xec0700ec), SkBits2Float(0xecececec), SkBits2Float(0xececccec), SkBits2Float(0x772965ec), SkBits2Float(0x77777377)); // -6.52837e+26f, -2.2914e+27f, -2.29019e+27f, 3.4358e+33f, 5.0189e+33f path.moveTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.close(); path.moveTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.quadTo(SkBits2Float(0x29ec02ec), SkBits2Float(0x1009ecec), SkBits2Float(0x80ececec), SkBits2Float(0xf7ffffff)); // 1.0481e-13f, 2.7201e-29f, -2.17582e-38f, -1.03846e+34f path.lineTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.close(); path.moveTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.conicTo(SkBits2Float(0xff003aff), SkBits2Float(0xdbec2300), SkBits2Float(0xecececec), SkBits2Float(0x6fdf6052), SkBits2Float(0x41ecec29)); // -1.70448e+38f, -1.32933e+17f, -2.2914e+27f, 1.38263e+29f, 29.6153f path.lineTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.close(); path.moveTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.quadTo(SkBits2Float(0xecf76e6f), SkBits2Float(0xeccfddec), SkBits2Float(0xecececcc), SkBits2Float(0x66000066)); // -2.39301e+27f, -2.01037e+27f, -2.2914e+27f, 1.51118e+23f path.lineTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.close(); path.moveTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.cubicTo(SkBits2Float(0x772965df), SkBits2Float(0x77777377), SkBits2Float(0x77777876), SkBits2Float(0x665266fe), SkBits2Float(0xecececdf), SkBits2Float(0x0285806e)); // 3.4358e+33f, 5.0189e+33f, 5.0193e+33f, 2.48399e+23f, -2.2914e+27f, 1.96163e-37f path.lineTo(SkBits2Float(0xecececeb), SkBits2Float(0xecec0700)); // -2.2914e+27f, -2.28272e+27f path.lineTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.close(); path.moveTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.lineTo(SkBits2Float(0x65ecfaec), SkBits2Float(0xde777729)); // 1.39888e+23f, -4.45794e+18f path.conicTo(SkBits2Float(0x74777777), SkBits2Float(0x66fe7876), SkBits2Float(0xecdf6660), SkBits2Float(0x726eecec), SkBits2Float(0x29d610ec)); // 7.84253e+31f, 6.00852e+23f, -2.16059e+27f, 4.73241e+30f, 9.50644e-14f path.lineTo(SkBits2Float(0xfe817477), SkBits2Float(0xdf665266)); // -8.60376e+37f, -1.65964e+19f path.close(); path.moveTo(SkBits2Float(0xd0ecec10), SkBits2Float(0x6e6eecdb)); // -3.17991e+10f, 1.84859e+28f path.quadTo(SkBits2Float(0x003affec), SkBits2Float(0xec2300ef), SkBits2Float(0xecececdb), SkBits2Float(0xcfececec)); // 5.41827e-39f, -7.88237e+26f, -2.2914e+27f, -7.9499e+09f path.lineTo(SkBits2Float(0xd0ecec10), SkBits2Float(0x6e6eecdb)); // -3.17991e+10f, 1.84859e+28f path.close(); path.moveTo(SkBits2Float(0xd0ecec10), SkBits2Float(0x6e6eecdb)); // -3.17991e+10f, 1.84859e+28f path.quadTo(SkBits2Float(0xecccec80), SkBits2Float(0xfa66ecec), SkBits2Float(0x66fa0000), SkBits2Float(0x772965df)); // -1.9819e+27f, -2.99758e+35f, 5.90296e+23f, 3.4358e+33f path.moveTo(SkBits2Float(0x77777790), SkBits2Float(0x00807677)); // 5.01923e+33f, 1.17974e-38f path.close(); path.moveTo(SkBits2Float(0x77777790), SkBits2Float(0x00807677)); // 5.01923e+33f, 1.17974e-38f path.cubicTo(SkBits2Float(0xecececec), SkBits2Float(0xfe66eaec), SkBits2Float(0xecdf1452), SkBits2Float(0x806eecec), SkBits2Float(0x10ececec), SkBits2Float(0xec000000)); // -2.2914e+27f, -7.67356e+37f, -2.15749e+27f, -1.01869e-38f, 9.34506e-29f, -6.1897e+26f path.lineTo(SkBits2Float(0x77777790), SkBits2Float(0x00807677)); // 5.01923e+33f, 1.17974e-38f path.close(); path.moveTo(SkBits2Float(0x77777790), SkBits2Float(0x00807677)); // 5.01923e+33f, 1.17974e-38f path.cubicTo(SkBits2Float(0x52668062), SkBits2Float(0x2965df66), SkBits2Float(0x77777377), SkBits2Float(0x76777773), SkBits2Float(0x1697fe78), SkBits2Float(0xeebfff00)); // 2.47499e+11f, 5.1042e-14f, 5.0189e+33f, 1.2548e+33f, 2.4556e-25f, -2.971e+28f path.lineTo(SkBits2Float(0x77777790), SkBits2Float(0x00807677)); // 5.01923e+33f, 1.17974e-38f path.close(); testSimplifyFuzz(reporter, path, filename); }
static void PathOpsSimplifyFailTest(skiatest::Reporter* reporter) { for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) { SkPath path; int i = (int) (index % nonFinitePtsCount); int f = (int) (index % finitePtsCount); int g = (int) ((f + 1) % finitePtsCount); switch (index % 13) { case 0: path.lineTo(nonFinitePts[i]); break; case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break; case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break; case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break; case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break; case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break; case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break; case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break; case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break; case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break; case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break; case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break; case 12: path.moveTo(nonFinitePts[i]); break; } SkPath result; result.setFillType(SkPath::kWinding_FillType); bool success = Simplify(path, &result); REPORTER_ASSERT(reporter, !success); REPORTER_ASSERT(reporter, result.isEmpty()); REPORTER_ASSERT(reporter, result.getFillType() == SkPath::kWinding_FillType); reporter->bumpTestCount(); } if (sizeof(reporter) == 4) { return; } for (int index = 0; index < (int) (11 * finitePtsCount); ++index) { SkPath path; int f = (int) (index % finitePtsCount); int g = (int) ((f + 1) % finitePtsCount); switch (index % 11) { case 0: path.lineTo(finitePts[f]); break; case 1: path.quadTo(finitePts[f], finitePts[f]); break; case 2: path.quadTo(finitePts[f], finitePts[g]); break; case 3: path.quadTo(finitePts[g], finitePts[f]); break; case 4: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break; case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break; case 6: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break; case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break; case 8: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break; case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break; case 10: path.moveTo(finitePts[f]); break; } SkPath result; result.setFillType(SkPath::kWinding_FillType); bool success = Simplify(path, &result); REPORTER_ASSERT(reporter, success); REPORTER_ASSERT(reporter, result.getFillType() != SkPath::kWinding_FillType); reporter->bumpTestCount(); } }
static SkPath make_path() { SkPath path; int numOps = R(30); for (int i = 0; i < numOps; ++i) { switch (R(6)) { case 0: path.moveTo(make_scalar(), make_scalar()); break; case 1: path.lineTo(make_scalar(), make_scalar()); break; case 2: path.quadTo(make_scalar(), make_scalar(), make_scalar(), make_scalar()); break; case 3: path.conicTo(make_scalar(), make_scalar(), make_scalar(), make_scalar(), make_scalar()); break; case 4: path.cubicTo(make_scalar(), make_scalar(), make_scalar(), make_scalar(), make_scalar(), make_scalar()); break; case 5: default: path.arcTo(make_scalar(), make_scalar(), make_scalar(), make_scalar(), make_scalar()); break; } } path.close(); return path; }
void onDraw(SkCanvas* canvas) override { SkPath path; SkRandom rand; int scale = 300; for (int i = 0; i < 4; ++i) { // get the random values deterministically SkScalar randoms[12]; for (int index = 0; index < (int) SK_ARRAY_COUNT(randoms); ++index) { randoms[index] = rand.nextUScalar1(); } path.lineTo(randoms[0] * scale, randoms[1] * scale); path.quadTo(randoms[2] * scale, randoms[3] * scale, randoms[4] * scale, randoms[5] * scale); path.cubicTo(randoms[6] * scale, randoms[7] * scale, randoms[8] * scale, randoms[9] * scale, randoms[10] * scale, randoms[11] * scale); } path.setFillType(SkPath::kEvenOdd_FillType); path.offset(SkIntToScalar(20), SkIntToScalar(20)); test_hittest(canvas, path); canvas->translate(SkIntToScalar(scale), 0); path.setFillType(SkPath::kWinding_FillType); test_hittest(canvas, path); }
// A quad which generates a huge number of points (>2B) when uniformly // linearized. This should not hang or OOM. static SkPath create_path_29() { SkPath path; path.moveTo(10, 0); path.lineTo(0, 0); path.quadTo(10, 0, 0, 8315084722602508288); return path; }
static int quad_proc(const FT_Vector* pt0, const FT_Vector* pt1, void* ctx) { SkPath* path = (SkPath*)ctx; path->quadTo(SkFDot6ToScalar(pt0->x), -SkFDot6ToScalar(pt0->y), SkFDot6ToScalar(pt1->x), -SkFDot6ToScalar(pt1->y)); return 0; }
SkPath SubsetVerbs::getSubsetPath() const { SkPath result; result.setFillType(fPath.getFillType()); if (!fSelected.count()) { return result; } SkPath::RawIter iter(fPath); uint8_t verb; SkPoint pts[4]; int verbIndex = 0; bool addMoveTo = true; bool addLineTo = false; while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { bool enabled = SkPath::kLine_Verb <= verb && verb <= SkPath::kCubic_Verb ? fSelected[verbIndex++] : false; if (enabled) { if (addMoveTo) { result.moveTo(pts[0]); addMoveTo = false; } else if (addLineTo) { result.lineTo(pts[0]); addLineTo = false; } } switch (verb) { case SkPath::kMove_Verb: break; case SkPath::kLine_Verb: if (enabled) { result.lineTo(pts[1]); } break; case SkPath::kQuad_Verb: if (enabled) { result.quadTo(pts[1], pts[2]); } break; case SkPath::kConic_Verb: if (enabled) { result.conicTo(pts[1], pts[2], iter.conicWeight()); } break; case SkPath::kCubic_Verb: if (enabled) { result.cubicTo(pts[1], pts[2], pts[3]); } break; case SkPath::kClose_Verb: result.close(); addMoveTo = true; addLineTo = false; continue; default: SkDEBUGFAIL("bad verb"); return result; } addLineTo = !enabled; } return result; }
void SkTestFont::init(const SkScalar* pts, const unsigned char* verbs) { fPaths = new SkPath*[fCharCodesCount]; for (unsigned index = 0; index < fCharCodesCount; ++index) { SkPath* path = new SkPath; SkPath::Verb verb; while ((verb = (SkPath::Verb)*verbs++) != SkPath::kDone_Verb) { switch (verb) { case SkPath::kMove_Verb: path->moveTo(pts[0], pts[1]); pts += 2; break; case SkPath::kLine_Verb: path->lineTo(pts[0], pts[1]); pts += 2; break; case SkPath::kQuad_Verb: path->quadTo(pts[0], pts[1], pts[2], pts[3]); pts += 4; break; case SkPath::kCubic_Verb: path->cubicTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]); pts += 6; break; case SkPath::kClose_Verb: path->close(); break; default: SkDEBUGFAIL("bad verb"); return; } } // This should make SkPath::getBounds() queries threadsafe. path->updateBoundsCache(); fPaths[index] = path; } }
static void test_flattening(skiatest::Reporter* reporter) { SkPath p; static const SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(10), SkIntToScalar(10) }, { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) } }; p.moveTo(pts[0]); p.lineTo(pts[1]); p.quadTo(pts[2], pts[3]); p.cubicTo(pts[4], pts[5], pts[6]); SkWriter32 writer(100); p.flatten(writer); size_t size = writer.size(); SkAutoMalloc storage(size); writer.flatten(storage.get()); SkReader32 reader(storage.get(), size); SkPath p1; REPORTER_ASSERT(reporter, p1 != p); p1.unflatten(reader); REPORTER_ASSERT(reporter, p1 == p); }
static SkPoint AddMoveDegenQuadClose(SkPath& path, SkPoint& startPt) { SkPoint moveToPt = startPt + SkPoint::Make(0, 10*SK_Scalar1); path.moveTo(moveToPt); path.quadTo(moveToPt, moveToPt); path.close(); return moveToPt; }
static void testQuads() { SkPath path; path.moveTo(2,0); path.quadTo(1,1, 0,0); path.close(); test(path); }
static SkPoint AddMoveQuad(SkPath& path, SkPoint& startPt) { SkPoint moveToPt = startPt + SkPoint::Make(0, 10*SK_Scalar1); SkPoint midPt = moveToPt + SkPoint::Make(20*SK_Scalar1, 5*SK_Scalar1); SkPoint endPt = moveToPt + SkPoint::Make(40*SK_Scalar1, 0); path.moveTo(moveToPt); path.quadTo(midPt, endPt); return endPt; }
void onOnceBeforeDraw() override { { SkPath* bigQuad = &fPaths.push_back(); bigQuad->moveTo(0, 0); bigQuad->quadTo(kWidth/2, kHeight, kWidth, 0); } { SkPath* degenBigQuad = &fPaths.push_back(); SkScalar yPos = kHeight / 2 + 10; degenBigQuad->moveTo(0, yPos); degenBigQuad->quadTo(0, yPos, kWidth, yPos); } { SkPath* bigCubic = &fPaths.push_back(); bigCubic->moveTo(0, 0); bigCubic->cubicTo(0, kHeight, kWidth, kHeight, kWidth, 0); } { SkPath* degenBigCubic = &fPaths.push_back(); SkScalar yPos = kHeight / 2; degenBigCubic->moveTo(0, yPos); degenBigCubic->cubicTo(0, yPos, 0, yPos, kWidth, yPos); } { SkPath* bigConic = &fPaths.push_back(); bigConic->moveTo(0, 0); bigConic->conicTo(kWidth/2, kHeight, kWidth, 0, .5); } { SkPath* degenBigConic = &fPaths.push_back(); SkScalar yPos = kHeight / 2 - 10; degenBigConic->moveTo(0, yPos); degenBigConic->conicTo(0, yPos, kWidth, yPos, .5); } }
static void textonpath_slide(SkCanvas* canvas) { const char* text = "Displacement"; size_t len =strlen(text); SkPath path; path.moveTo(100, 300); path.quadTo(300, 100, 500, 300); path.offset(0, -100); SkPaint paint; paint.setAntiAlias(true); paint.setTextSize(40); paint.setStyle(SkPaint::kStroke_Style); canvas->drawPath(path, paint); paint.setStyle(SkPaint::kFill_Style); SkScalar x = 50; paint.setColor(0xFF008800); canvas->drawTextOnPathHV(text, len, path, x, paint.getTextSize()*2/3, paint); paint.setColor(SK_ColorRED); canvas->drawTextOnPathHV(text, len, path, x + 60, 0, paint); paint.setColor(SK_ColorBLUE); canvas->drawTextOnPathHV(text, len, path, x + 120, -paint.getTextSize()*2/3, paint); path.offset(0, 200); paint.setTextAlign(SkPaint::kRight_Align); text = "Matrices"; len = strlen(text); SkScalar pathLen = getpathlen(path); SkMatrix matrix; paint.setColor(SK_ColorBLACK); paint.setStyle(SkPaint::kStroke_Style); canvas->drawPath(path, paint); paint.setStyle(SkPaint::kFill_Style); paint.setTextSize(50); canvas->drawTextOnPath(text, len, path, NULL, paint); paint.setColor(SK_ColorRED); matrix.setScale(-SK_Scalar1, SK_Scalar1); matrix.postTranslate(pathLen, 0); canvas->drawTextOnPath(text, len, path, &matrix, paint); paint.setColor(SK_ColorBLUE); matrix.setScale(SK_Scalar1, -SK_Scalar1); canvas->drawTextOnPath(text, len, path, &matrix, paint); paint.setColor(0xFF008800); matrix.setScale(-SK_Scalar1, -SK_Scalar1); matrix.postTranslate(pathLen, 0); canvas->drawTextOnPath(text, len, path, &matrix, paint); }
SkPath SubsetContours::getSubsetPath() const { SkPath result; result.setFillType(fPath.getFillType()); if (!fSelected.count()) { return result; } SkPath::RawIter iter(fPath); uint8_t verb; SkPoint pts[4]; int contourCount = 0; bool enabled = fSelected[0]; bool addMoveTo = true; while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { if (enabled && addMoveTo) { result.moveTo(pts[0]); addMoveTo = false; } switch (verb) { case SkPath::kMove_Verb: break; case SkPath::kLine_Verb: if (enabled) { result.lineTo(pts[1]); } break; case SkPath::kQuad_Verb: if (enabled) { result.quadTo(pts[1], pts[2]); } break; case SkPath::kConic_Verb: if (enabled) { result.conicTo(pts[1], pts[2], iter.conicWeight()); } break; case SkPath::kCubic_Verb: if (enabled) { result.cubicTo(pts[1], pts[2], pts[3]); } break; case SkPath::kClose_Verb: if (enabled) { result.close(); } if (++contourCount >= fSelected.count()) { break; } enabled = fSelected[contourCount]; addMoveTo = true; continue; default: SkDEBUGFAIL("bad verb"); return result; } } return result; }
static void fuzz_x3(skiatest::Reporter* reporter, const char* filename) { SkPath path; path.setFillType(SkPath::kWinding_FillType); path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 path.cubicTo(SkBits2Float(0x92743420), SkBits2Float(0x74747474), SkBits2Float(0x0f747c74), SkBits2Float(0xff538565), SkBits2Float(0x74744374), SkBits2Float(0x20437474)); // -7.70571e-28f, 7.74708e+31f, 1.20541e-29f, -2.8116e+38f, 7.74102e+31f, 1.65557e-19f path.conicTo(SkBits2Float(0x7474926d), SkBits2Float(0x7c747474), SkBits2Float(0x00170f74), SkBits2Float(0x3a7410d7), SkBits2Float(0x3a3a3a3a)); // 7.7508e+31f, 5.07713e+36f, 2.11776e-39f, 0.000931037f, 0.000710401f path.quadTo(SkBits2Float(0x203a3a3a), SkBits2Float(0x7459f43a), SkBits2Float(0x74747474), SkBits2Float(0x2043ad6e)); // 1.57741e-19f, 6.90724e+31f, 7.74708e+31f, 1.65745e-19f path.conicTo(SkBits2Float(0x7474b374), SkBits2Float(0x74747474), SkBits2Float(0x0f747c74), SkBits2Float(0xff537065), SkBits2Float(0x74744374)); // 7.75488e+31f, 7.74708e+31f, 1.20541e-29f, -2.81051e+38f, 7.74102e+31f path.cubicTo(SkBits2Float(0x3a3a3a3a), SkBits2Float(0x3a2c103a), SkBits2Float(0x7474263a), SkBits2Float(0x74976507), SkBits2Float(0x000000ff), SkBits2Float(0x00000000)); // 0.000710401f, 0.00065637f, 7.7374e+31f, 9.59578e+31f, 3.57331e-43f, 0 testSimplifyFuzz(reporter, path, filename); }
void draw(SkCanvas* canvas) { SkPath path; path.moveTo(100, 100); path.quadTo(100, 20, 20, 100); SkMatrix matrix; matrix.setRotate(36, 100, 100); path.transform(matrix); SkPoint last; path.getLastPt(&last); SkDebugf("last point: %g, %g\n", last.fX, last.fY); }
/** * Called on a background thread. Here we can only modify fBackPaths. */ void runAnimationTask(double t, double dt, int w, int h) override { const float tsec = static_cast<float>(t); this->INHERITED::runAnimationTask(t, 0.5 * dt, w, h); for (int i = 0; i < kNumPaths; ++i) { const Glyph& glyph = fGlyphs[i]; const SkMatrix& backMatrix = fBackMatrices[i]; const Sk2f matrix[3] = { Sk2f(backMatrix.getScaleX(), backMatrix.getSkewY()), Sk2f(backMatrix.getSkewX(), backMatrix.getScaleY()), Sk2f(backMatrix.getTranslateX(), backMatrix.getTranslateY()) }; SkPath* backpath = &fBackPaths[i]; backpath->reset(); backpath->setFillType(SkPath::kEvenOdd_FillType); SkPath::RawIter iter(glyph.fPath); SkPath::Verb verb; SkPoint pts[4]; while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { switch (verb) { case SkPath::kMove_Verb: { SkPoint pt = fWaves.apply(tsec, matrix, pts[0]); backpath->moveTo(pt.x(), pt.y()); break; } case SkPath::kLine_Verb: { SkPoint endpt = fWaves.apply(tsec, matrix, pts[1]); backpath->lineTo(endpt.x(), endpt.y()); break; } case SkPath::kQuad_Verb: { SkPoint controlPt = fWaves.apply(tsec, matrix, pts[1]); SkPoint endpt = fWaves.apply(tsec, matrix, pts[2]); backpath->quadTo(controlPt.x(), controlPt.y(), endpt.x(), endpt.y()); break; } case SkPath::kClose_Verb: { backpath->close(); break; } case SkPath::kCubic_Verb: case SkPath::kConic_Verb: case SkPath::kDone_Verb: SK_ABORT("Unexpected path verb"); break; } } } }
// This used to assert in debug builds (and crash writing bad memory in release) // because we overflowed an intermediate value (B coefficient) setting up our // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow static void test_crbug_140803() { SkBitmap bm; bm.allocN32Pixels(2700, 30*1024); SkCanvas canvas(bm); SkPath path; path.moveTo(2762, 20); path.quadTo(11, 21702, 10, 21706); SkPaint paint; paint.setAntiAlias(true); canvas.drawPath(path, paint); }
void draw(SkCanvas* canvas) { SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kStroke_Style); SkPoint quadPts[] = {{20, 90}, {120, 10}, {220, 90}}; canvas->drawLine(quadPts[0], quadPts[1], paint); canvas->drawLine(quadPts[1], quadPts[2], paint); SkPath path; path.moveTo(quadPts[0]); path.quadTo(quadPts[1], quadPts[2]); paint.setStrokeWidth(3); canvas->drawPath(path, paint); }
// This used to assert in debug builds (and crash writing bad memory in release) // because we overflowed an intermediate value (B coefficient) setting up our // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow static void test_crbug_140803(skiatest::Reporter* reporter) { SkBitmap bm; bm.setConfig(SkBitmap::kARGB_8888_Config, 2700, 30*1024); bm.allocPixels(); SkCanvas canvas(bm); SkPath path; path.moveTo(2762, 20); path.quadTo(11, 21702, 10, 21706); SkPaint paint; paint.setAntiAlias(true); canvas.drawPath(path, paint); }
SkPath quadPath(SkPoint p1, SkPoint p2) { SkASSERT(p1.y() == p2.y()); SkPath path; path.moveTo(p1); path.lineTo(p2); SkPoint p3 = SkPoint::Make((p1.x() + p2.x()) / 2.0f, p1.y() * 0.7f); path.quadTo(p3, p1); return path; }
void draw(SkCanvas* canvas) { SkPaint paint; paint.setAntiAlias(true); SkPath path; path.moveTo(128, 20); path.rQuadTo(-6, 10, -7, 10); for (int i = 1; i < 32; i += 4) { path.rQuadTo(10 + i, 10 + i, 10 + i * 4, 10); path.rQuadTo(-10 - i, 10 + i, -10 - (i + 2) * 4, 10); } path.quadTo(92, 220, 128, 215); canvas->drawPath(path, paint); }
static void fuzz_drawPath(Fuzz* fuzz) { SkPaint p; init_paint(fuzz, &p); sk_sp<SkSurface> surface; init_surface(fuzz, &surface); // TODO(kjlubick): put the ability to fuzz a path in shared file, with // other common things (e.g. rects, lines) uint8_t i, j; fuzz->nextRange(&i, 0, 10); // set i to number of operations to perform SkPath path; SkScalar a, b, c, d, e, f; for (int k = 0; k < i; ++k) { fuzz->nextRange(&j, 0, 5); // set j to choose operation to perform switch (j) { case 0: fuzz->next(&a, &b); path.moveTo(a, b); break; case 1: fuzz->next(&a, &b); path.lineTo(a, b); break; case 2: fuzz->next(&a, &b, &c, &d); path.quadTo(a, b, c, d); break; case 3: fuzz->next(&a, &b, &c, &d, &e); path.conicTo(a, b, c, d, e); break; case 4: fuzz->next(&a, &b, &c, &d, &e, &f); path.cubicTo(a, b, c, d, e, f); break; case 5: fuzz->next(&a, &b, &c, &d, &e); path.arcTo(a, b, c, d, e); break; } } path.close(); SkCanvas* cnv = surface->getCanvas(); cnv->drawPath(path, p); bool bl; fuzz->next(&bl); cnv->clipPath(path, kIntersect_SkClipOp, bl); }
// quadApprox - makes an approximation, which we hope is faster static void quadApprox(SkPath &fPath, const SkPoint &p0, const SkPoint &p1, const SkPoint &p2) { //divide the cubic up into two cubics, then convert them into quadratics //define our points SkPoint c,j,k,l,m,n,o,p,q, mid; fPath.getLastPt(&c); midPt(j, p0, c); midPt(k, p0, p1); midPt(l, p1, p2); midPt(o, j, k); midPt(p, k, l); midPt(q, o, p); //compute the first half m.set(SkScalarHalf(3*j.fX - c.fX), SkScalarHalf(3*j.fY - c.fY)); n.set(SkScalarHalf(3*o.fX -q.fX), SkScalarHalf(3*o.fY - q.fY)); midPt(mid,m,n); fPath.quadTo(mid,q); c = q; //compute the second half m.set(SkScalarHalf(3*p.fX - c.fX), SkScalarHalf(3*p.fY - c.fY)); n.set(SkScalarHalf(3*l.fX -p2.fX),SkScalarHalf(3*l.fY -p2.fY)); midPt(mid,m,n); fPath.quadTo(mid,p2); }