From 03119ba4f815bc2c2774a9349ca8278ab1695072 Mon Sep 17 00:00:00 2001 From: reed Date: Sun, 4 Jan 2015 20:24:42 -0800 Subject: [PATCH] enable conics gm BUG=skia: TBR= Review URL: https://codereview.chromium.org/835593002 --- gm/conicpaths.cpp | 61 +++++++++++++++--------------------------- gyp/gmslides.gypi | 2 +- src/pdf/SkPDFUtils.cpp | 27 ++++++++++++------- 3 files changed, 40 insertions(+), 50 deletions(-) diff --git a/gm/conicpaths.cpp b/gm/conicpaths.cpp index 96242faf5f..d04cd26359 100644 --- a/gm/conicpaths.cpp +++ b/gm/conicpaths.cpp @@ -17,14 +17,14 @@ protected: } SkISize onISize() SK_OVERRIDE { - return SkISize::Make(950, 1000); + return SkISize::Make(920, 960); } void onOnceBeforeDraw() SK_OVERRIDE { { const SkScalar w = SkScalarSqrt(2)/2; SkPath* conicCirlce = &fPaths.push_back(); - conicCirlce->moveTo(0, -0); + conicCirlce->moveTo(0, 0); conicCirlce->conicTo(0, 50, 50, 50, w); conicCirlce->rConicTo(50, 0, 50, -50, w); conicCirlce->rConicTo(0, -50, -50, -50, w); @@ -33,43 +33,43 @@ protected: } { SkPath* hyperbola = &fPaths.push_back(); - hyperbola->moveTo(0, -0); + hyperbola->moveTo(0, 0); hyperbola->conicTo(0, 100, 100, 100, 2); } { SkPath* thinHyperbola = &fPaths.push_back(); - thinHyperbola->moveTo(0, -0); + thinHyperbola->moveTo(0, 0); thinHyperbola->conicTo(100, 100, 5, 0, 2); } { SkPath* veryThinHyperbola = &fPaths.push_back(); - veryThinHyperbola->moveTo(0, -0); + veryThinHyperbola->moveTo(0, 0); veryThinHyperbola->conicTo(100, 100, 1, 0, 2); } { SkPath* closedHyperbola = &fPaths.push_back(); - closedHyperbola->moveTo(0, -0); + closedHyperbola->moveTo(0, 0); closedHyperbola->conicTo(100, 100, 0, 0, 2); } { // using 1 as weight defaults to using quadTo SkPath* nearParabola = &fPaths.push_back(); - nearParabola->moveTo(0, -0); + nearParabola->moveTo(0, 0); nearParabola->conicTo(0, 100, 100, 100, 0.999f); } { SkPath* thinEllipse = &fPaths.push_back(); - thinEllipse->moveTo(0, -0); + thinEllipse->moveTo(0, 0); thinEllipse->conicTo(100, 100, 5, 0, SK_ScalarHalf); } { SkPath* veryThinEllipse = &fPaths.push_back(); - veryThinEllipse->moveTo(0, -0); + veryThinEllipse->moveTo(0, 0); veryThinEllipse->conicTo(100, 100, 1, 0, SK_ScalarHalf); } { SkPath* closedEllipse = &fPaths.push_back(); - closedEllipse->moveTo(0, -0); + closedEllipse->moveTo(0, 0); closedEllipse->conicTo(100, 100, 0, 0, SK_ScalarHalf); } } @@ -77,58 +77,39 @@ protected: void onDraw(SkCanvas* canvas) SK_OVERRIDE { const SkAlpha kAlphaValue[] = { 0xFF, 0x40 }; - SkScalar maxH = 0; const SkScalar margin = 15; canvas->translate(margin, margin); - canvas->save(); - SkScalar x = margin; - int counter = 0; + SkPaint paint; for (int p = 0; p < fPaths.count(); ++p) { + canvas->save(); for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) { + paint.setARGB(kAlphaValue[a], 0, 0, 0); for (int aa = 0; aa < 2; ++aa) { + paint.setAntiAlias(SkToBool(aa)); for (int fh = 0; fh < 2; ++fh) { + paint.setStyle(fh ? SkPaint::kStroke_Style : SkPaint::kFill_Style); const SkRect& bounds = fPaths[p].getBounds(); - - SkPaint paint; - paint.setARGB(kAlphaValue[a], 0, 0, 0); - paint.setAntiAlias(SkToBool(aa)); - if (fh == 1) { - paint.setStyle(SkPaint::kStroke_Style); - paint.setStrokeWidth(0); - } else if (fh == 0) { - paint.setStyle(SkPaint::kFill_Style); - } canvas->save(); canvas->translate(-bounds.fLeft, -bounds.fTop); canvas->drawPath(fPaths[p], paint); canvas->restore(); - maxH = SkMaxScalar(maxH, bounds.height()); - - SkScalar dx = bounds.width() + margin; - x += dx; - canvas->translate(dx, 0); - - if (++counter == 8) { - counter = 0; - - canvas->restore(); - canvas->translate(0, maxH + margin); - canvas->save(); - maxH = 0; - x = margin; - } + canvas->translate(110, 0); } } } + canvas->restore(); + canvas->translate(0, 110); } canvas->restore(); } uint32_t onGetFlags() const SK_OVERRIDE { - return kSkipPDF_Flag; + // tiling w/ non-antialias paths can cause off-by-1-pixels differences which are + // unavoidable (chopping in floats -vs- stepping in scan-converter). + return kSkipTiled_Flag; } private: diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index 10b70f35b0..9350ddb29c 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -56,7 +56,7 @@ '../gm/complexclip2.cpp', '../gm/complexclip3.cpp', '../gm/composeshader.cpp', - #'../gm/conicpaths.cpp', + '../gm/conicpaths.cpp', '../gm/convexpaths.cpp', '../gm/convexpolyclip.cpp', '../gm/convexpolyeffect.cpp', diff --git a/src/pdf/SkPDFUtils.cpp b/src/pdf/SkPDFUtils.cpp index d034270e07..e488f7da06 100644 --- a/src/pdf/SkPDFUtils.cpp +++ b/src/pdf/SkPDFUtils.cpp @@ -95,6 +95,13 @@ void SkPDFUtils::AppendCubic(SkScalar ctl1X, SkScalar ctl1Y, content->writeText(cmd.c_str()); } +static void append_quad(const SkPoint quad[], SkWStream* content) { + SkPoint cubic[4]; + SkConvertQuadToCubic(quad, cubic); + SkPDFUtils::AppendCubic(cubic[1].fX, cubic[1].fY, cubic[2].fX, cubic[2].fY, + cubic[3].fX, cubic[3].fY, content); +} + // static void SkPDFUtils::AppendRectangle(const SkRect& rect, SkWStream* content) { // Skia has 0,0 at top left, pdf at bottom left. Do the right thing. @@ -130,9 +137,7 @@ void SkPDFUtils::EmitPath(const SkPath& path, SkPaint::Style paintStyle, SkDynamicMemoryWStream currentSegment; SkPoint args[4]; SkPath::Iter iter(path, false); - for (SkPath::Verb verb = iter.next(args); - verb != SkPath::kDone_Verb; - verb = iter.next(args)) { + for (SkPath::Verb verb = iter.next(args); verb != SkPath::kDone_Verb; verb = iter.next(args)) { // args gets all the points, even the implicit first point. switch (verb) { case SkPath::kMove_Verb: @@ -150,14 +155,18 @@ void SkPDFUtils::EmitPath(const SkPath& path, SkPaint::Style paintStyle, fillState = kNonSingleLine_SkipFillState; } break; - case SkPath::kQuad_Verb: { - SkPoint cubic[4]; - SkConvertQuadToCubic(args, cubic); - AppendCubic(cubic[1].fX, cubic[1].fY, cubic[2].fX, cubic[2].fY, - cubic[3].fX, cubic[3].fY, ¤tSegment); + case SkPath::kQuad_Verb: + append_quad(args, ¤tSegment); fillState = kNonSingleLine_SkipFillState; break; - } + case SkPath::kConic_Verb: { + const SkScalar tol = SK_Scalar1 / 4; + SkAutoConicToQuads converter; + const SkPoint* quads = converter.computeQuads(args, iter.conicWeight(), tol); + for (int i = 0; i < converter.countQuads(); ++i) { + append_quad(&quads[i * 2], ¤tSegment); + } + } break; case SkPath::kCubic_Verb: AppendCubic(args[1].fX, args[1].fY, args[2].fX, args[2].fY, args[3].fX, args[3].fY, ¤tSegment);