Update canvaskit to use the new path iterator

Change-Id: I248396f7c0d176f846e0b87a5fed5b7e20063aa2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/287598
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Chris Dalton 2020-05-04 12:59:49 -06:00 committed by Skia Commit-Bot
parent 690b4c4644
commit f03781b6a9
2 changed files with 20 additions and 46 deletions

View File

@ -49,6 +49,7 @@
#include "include/utils/SkShadowUtils.h"
#include "modules/skshaper/include/SkShaper.h"
#include "src/core/SkFontMgrPriv.h"
#include "src/core/SkPathPriv.h"
#include "src/core/SkResourceCache.h"
#include "src/sksl/SkSLCompiler.h"
@ -367,51 +368,37 @@ static const int CONIC = 3;
static const int CUBIC = 4;
static const int CLOSE = 5;
template <typename VisitFunc>
void VisitPath(const SkPath& p, VisitFunc&& f) {
SkPath::RawIter iter(p);
SkPoint pts[4];
SkPath::Verb verb;
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
f(verb, pts, iter);
}
}
JSArray ToCmds(const SkPath& path) {
JSArray cmds = emscripten::val::array();
VisitPath(path, [&cmds](SkPath::Verb verb, const SkPoint pts[4], SkPath::RawIter iter) {
for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
JSArray cmd = emscripten::val::array();
switch (verb) {
case SkPath::kMove_Verb:
case SkPathVerb::kMove:
cmd.call<void>("push", MOVE, pts[0].x(), pts[0].y());
break;
case SkPath::kLine_Verb:
case SkPathVerb::kLine:
cmd.call<void>("push", LINE, pts[1].x(), pts[1].y());
break;
case SkPath::kQuad_Verb:
case SkPathVerb::kQuad:
cmd.call<void>("push", QUAD, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
break;
case SkPath::kConic_Verb:
case SkPathVerb::kConic:
cmd.call<void>("push", CONIC,
pts[1].x(), pts[1].y(),
pts[2].x(), pts[2].y(), iter.conicWeight());
pts[2].x(), pts[2].y(), *w);
break;
case SkPath::kCubic_Verb:
case SkPathVerb::kCubic:
cmd.call<void>("push", CUBIC,
pts[1].x(), pts[1].y(),
pts[2].x(), pts[2].y(),
pts[3].x(), pts[3].y());
break;
case SkPath::kClose_Verb:
case SkPathVerb::kClose:
cmd.call<void>("push", CLOSE);
break;
case SkPath::kDone_Verb:
SkASSERT(false);
break;
}
cmds.call<void>("push", cmd);
});
}
return cmds;
}

View File

@ -19,6 +19,7 @@
#include "include/private/SkFloatingPoint.h"
#include "include/utils/SkParsePath.h"
#include "src/core/SkPaintDefaults.h"
#include "src/core/SkPathPriv.h"
#include <emscripten/emscripten.h>
#include <emscripten/bind.h>
@ -44,51 +45,37 @@ using JSArray = emscripten::val;
// Creating/Exporting Paths with cmd arrays
// =================================================================================
template <typename VisitFunc>
void VisitPath(const SkPath& p, VisitFunc&& f) {
SkPath::RawIter iter(p);
SkPoint pts[4];
SkPath::Verb verb;
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
f(verb, pts, iter);
}
}
JSArray EMSCRIPTEN_KEEPALIVE ToCmds(const SkPath& path) {
JSArray cmds = emscripten::val::array();
VisitPath(path, [&cmds](SkPath::Verb verb, const SkPoint pts[4], SkPath::RawIter iter) {
for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
JSArray cmd = emscripten::val::array();
switch (verb) {
case SkPath::kMove_Verb:
case SkPathVerb::kMove:
cmd.call<void>("push", MOVE, pts[0].x(), pts[0].y());
break;
case SkPath::kLine_Verb:
case SkPathVerb::kLine:
cmd.call<void>("push", LINE, pts[1].x(), pts[1].y());
break;
case SkPath::kQuad_Verb:
case SkPathVerb::kQuad:
cmd.call<void>("push", QUAD, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
break;
case SkPath::kConic_Verb:
case SkPathVerb::kConic:
cmd.call<void>("push", CONIC,
pts[1].x(), pts[1].y(),
pts[2].x(), pts[2].y(), iter.conicWeight());
pts[2].x(), pts[2].y(), *w);
break;
case SkPath::kCubic_Verb:
case SkPathVerb::kCubic:
cmd.call<void>("push", CUBIC,
pts[1].x(), pts[1].y(),
pts[2].x(), pts[2].y(),
pts[3].x(), pts[3].y());
break;
case SkPath::kClose_Verb:
case SkPathVerb::kClose:
cmd.call<void>("push", CLOSE);
break;
case SkPath::kDone_Verb:
SkASSERT(false);
break;
}
cmds.call<void>("push", cmd);
});
}
return cmds;
}