Flutter Engine
The Flutter Engine
Classes | Macros | Typedefs | Functions | Variables
pathkit_wasm_bindings.cpp File Reference
#include "include/core/SkCubicMap.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkPathUtils.h"
#include "include/core/SkRect.h"
#include "include/core/SkString.h"
#include "include/core/SkStrokeRec.h"
#include "include/effects/SkDashPathEffect.h"
#include "include/effects/SkTrimPathEffect.h"
#include "include/pathops/SkPathOps.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/utils/SkParsePath.h"
#include "src/base/SkFloatBits.h"
#include "src/core/SkPaintDefaults.h"
#include "src/core/SkPathPriv.h"
#include <emscripten.h>
#include <emscripten/bind.h>

Go to the source code of this file.

Classes

struct  StrokeOpts
 
struct  SimpleMatrix
 

Macros

#define CHECK_NUM_ARGS(n)
 

Typedefs

using SkPathOrNull = emscripten::val
 
using JSString = emscripten::val
 
using JSArray = emscripten::val
 

Functions

JSArray EMSCRIPTEN_KEEPALIVE ToCmds (const SkPath &path)
 
SkPathOrNull EMSCRIPTEN_KEEPALIVE FromCmds (uintptr_t cptr, int numCmds)
 
SkPath EMSCRIPTEN_KEEPALIVE NewPath ()
 
SkPath EMSCRIPTEN_KEEPALIVE CopyPath (const SkPath &a)
 
bool EMSCRIPTEN_KEEPALIVE Equals (const SkPath &a, const SkPath &b)
 
void ApplyArcTo (SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
 
void ApplyClose (SkPath &p)
 
void ApplyConicTo (SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w)
 
void ApplyCubicTo (SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
 
void ApplyLineTo (SkPath &p, SkScalar x, SkScalar y)
 
void ApplyMoveTo (SkPath &p, SkScalar x, SkScalar y)
 
void ApplyQuadTo (SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
 
bool EMSCRIPTEN_KEEPALIVE IsEmpty (const SkPath &path)
 
JSString EMSCRIPTEN_KEEPALIVE ToSVGString (const SkPath &path)
 
SkPathOrNull EMSCRIPTEN_KEEPALIVE FromSVGString (std::string str)
 
bool EMSCRIPTEN_KEEPALIVE ApplySimplify (SkPath &path)
 
bool EMSCRIPTEN_KEEPALIVE ApplyAsWinding (SkPath &path)
 
bool EMSCRIPTEN_KEEPALIVE ApplyPathOp (SkPath &pathOne, const SkPath &pathTwo, SkPathOp op)
 
SkPathOrNull EMSCRIPTEN_KEEPALIVE MakeFromOp (const SkPath &pathOne, const SkPath &pathTwo, SkPathOp op)
 
SkPathOrNull EMSCRIPTEN_KEEPALIVE ResolveBuilder (SkOpBuilder &builder)
 
void EMSCRIPTEN_KEEPALIVE ToCanvas (const SkPath &path, emscripten::val ctx)
 
emscripten::val EMSCRIPTEN_KEEPALIVE ToPath2D (const SkPath &path)
 
void ApplyAddRect (SkPath &path, SkScalar x, SkScalar y, SkScalar width, SkScalar height)
 
void ApplyAddArc (SkPath &path, SkScalar x, SkScalar y, SkScalar radius, SkScalar startAngle, SkScalar endAngle, bool ccw)
 
void ApplyEllipse (SkPath &path, SkScalar x, SkScalar y, SkScalar radiusX, SkScalar radiusY, SkScalar rotation, SkScalar startAngle, SkScalar endAngle, bool ccw)
 
void ApplyAddPath (SkPath &orig, const SkPath &newPath, SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
 
void ApplyReverseAddPath (SkPath &orig, const SkPath &newPath)
 
JSString GetFillTypeString (const SkPath &path)
 
bool ApplyDash (SkPath &path, SkScalar on, SkScalar off, SkScalar phase)
 
bool ApplyTrim (SkPath &path, SkScalar startT, SkScalar stopT, bool isComplement)
 
bool ApplyStroke (SkPath &path, StrokeOpts opts)
 
SkMatrix toSkMatrix (const SimpleMatrix &sm)
 
void ApplyTransform (SkPath &orig, const SimpleMatrix &sm)
 
void ApplyTransform (SkPath &orig, SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
 
float SkBits2FloatUnsigned (uint32_t floatAsBits)
 
 EMSCRIPTEN_BINDINGS (skia)
 

Variables

static const int MOVE = 0
 
static const int LINE = 1
 
static const int QUAD = 2
 
static const int CONIC = 3
 
static const int CUBIC = 4
 
static const int CLOSE = 5
 
emscripten::val JSPath2D = emscripten::val::global("Path2D")
 

Macro Definition Documentation

◆ CHECK_NUM_ARGS

#define CHECK_NUM_ARGS (   n)
Value:
if ((i + n) > numCmds) { \
SkDebugf("Not enough args to match the verbs. Saw %d commands\n", numCmds); \
return emscripten::val::null(); \
}

Typedef Documentation

◆ JSArray

using JSArray = emscripten::val

Definition at line 45 of file pathkit_wasm_bindings.cpp.

◆ JSString

using JSString = emscripten::val

Definition at line 44 of file pathkit_wasm_bindings.cpp.

◆ SkPathOrNull

using SkPathOrNull = emscripten::val

Definition at line 42 of file pathkit_wasm_bindings.cpp.

Function Documentation

◆ ApplyAddArc()

void ApplyAddArc ( SkPath path,
SkScalar  x,
SkScalar  y,
SkScalar  radius,
SkScalar  startAngle,
SkScalar  endAngle,
bool  ccw 
)

Definition at line 320 of file pathkit_wasm_bindings.cpp.

321 {
322 SkPath temp;
323 SkRect bounds = SkRect::MakeLTRB(x-radius, y-radius, x+radius, y+radius);
324 const auto sweep = SkRadiansToDegrees(endAngle - startAngle) - 360 * ccw;
326 path.addPath(temp, SkPath::kExtend_AddPathMode);
327}
#define SkRadiansToDegrees(radians)
Definition: SkScalar.h:78
Definition: SkPath.h:59
SkPath & addArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle)
Definition: SkPath.cpp:1439
@ kExtend_AddPathMode
Definition: SkPath.h:1293
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkScalar startAngle
Definition: SkRecords.h:250
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

◆ ApplyAddPath()

void ApplyAddPath ( SkPath orig,
const SkPath newPath,
SkScalar  scaleX,
SkScalar  skewX,
SkScalar  transX,
SkScalar  skewY,
SkScalar  scaleY,
SkScalar  transY,
SkScalar  pers0,
SkScalar  pers1,
SkScalar  pers2 
)

Definition at line 344 of file pathkit_wasm_bindings.cpp.

347 {
348 SkMatrix m = SkMatrix::MakeAll(scaleX, skewX , transX,
349 skewY , scaleY, transY,
350 pers0 , pers1 , pers2);
351 orig.addPath(newPath, m);
352}
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Definition: SkMatrix.h:179
SkPath & addPath(const SkPath &src, SkScalar dx, SkScalar dy, AddPathMode mode=kAppend_AddPathMode)
Definition: SkPath.cpp:1506

◆ ApplyAddRect()

void ApplyAddRect ( SkPath path,
SkScalar  x,
SkScalar  y,
SkScalar  width,
SkScalar  height 
)

Definition at line 316 of file pathkit_wasm_bindings.cpp.

316 {
317 path.addRect(x, y, x+width, y+height);
318}
int32_t height
int32_t width

◆ ApplyArcTo()

void ApplyArcTo ( SkPath p,
SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2,
SkScalar  radius 
)

Definition at line 176 of file pathkit_wasm_bindings.cpp.

177 {
178 p.arcTo(x1, y1, x2, y2, radius);
179}

◆ ApplyAsWinding()

bool EMSCRIPTEN_KEEPALIVE ApplyAsWinding ( SkPath path)

Definition at line 242 of file pathkit_wasm_bindings.cpp.

242 {
243 return AsWinding(path, &path);
244}
bool SK_API AsWinding(const SkPath &path, SkPath *result)

◆ ApplyClose()

void ApplyClose ( SkPath p)

Definition at line 181 of file pathkit_wasm_bindings.cpp.

181 {
182 p.close();
183}

◆ ApplyConicTo()

void ApplyConicTo ( SkPath p,
SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2,
SkScalar  w 
)

Definition at line 185 of file pathkit_wasm_bindings.cpp.

186 {
187 p.conicTo(x1, y1, x2, y2, w);
188}
SkScalar w

◆ ApplyCubicTo()

void ApplyCubicTo ( SkPath p,
SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2,
SkScalar  x3,
SkScalar  y3 
)

Definition at line 190 of file pathkit_wasm_bindings.cpp.

191 {
192 p.cubicTo(x1, y1, x2, y2, x3, y3);
193}

◆ ApplyDash()

bool ApplyDash ( SkPath path,
SkScalar  on,
SkScalar  off,
SkScalar  phase 
)

Definition at line 374 of file pathkit_wasm_bindings.cpp.

374 {
375 SkScalar intervals[] = { on, off };
376 auto pe = SkDashPathEffect::Make(intervals, 2, phase);
377 if (!pe) {
378 SkDebugf("Invalid args to dash()\n");
379 return false;
380 }
381 SkStrokeRec rec(SkStrokeRec::InitStyle::kHairline_InitStyle);
382 if (pe->filterPath(&path, path, &rec, nullptr)) {
383 return true;
384 }
385 SkDebugf("Could not make dashed path\n");
386 return false;
387}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
float SkScalar
Definition: extension.cpp:12

◆ ApplyEllipse()

void ApplyEllipse ( SkPath path,
SkScalar  x,
SkScalar  y,
SkScalar  radiusX,
SkScalar  radiusY,
SkScalar  rotation,
SkScalar  startAngle,
SkScalar  endAngle,
bool  ccw 
)

Definition at line 329 of file pathkit_wasm_bindings.cpp.

330 {
331 // This is easiest to do by making a new path and then extending the current path
332 // (this properly catches the cases of if there's a moveTo before this call or not).
333 SkRect bounds = SkRect::MakeLTRB(x-radiusX, y-radiusY, x+radiusX, y+radiusY);
334 SkPath temp;
335 const auto sweep = SkRadiansToDegrees(endAngle - startAngle) - (360 * ccw);
337
338 SkMatrix m;
339 m.setRotate(SkRadiansToDegrees(rotation), x, y);
340 path.addPath(temp, m, SkPath::kExtend_AddPathMode);
341}

◆ ApplyLineTo()

void ApplyLineTo ( SkPath p,
SkScalar  x,
SkScalar  y 
)

Definition at line 195 of file pathkit_wasm_bindings.cpp.

195 {
196 p.lineTo(x, y);
197}

◆ ApplyMoveTo()

void ApplyMoveTo ( SkPath p,
SkScalar  x,
SkScalar  y 
)

Definition at line 199 of file pathkit_wasm_bindings.cpp.

199 {
200 p.moveTo(x, y);
201}

◆ ApplyPathOp()

bool EMSCRIPTEN_KEEPALIVE ApplyPathOp ( SkPath pathOne,
const SkPath pathTwo,
SkPathOp  op 
)

Definition at line 246 of file pathkit_wasm_bindings.cpp.

246 {
247 return Op(pathOne, pathTwo, op, &pathOne);
248}

◆ ApplyQuadTo()

void ApplyQuadTo ( SkPath p,
SkScalar  x1,
SkScalar  y1,
SkScalar  x2,
SkScalar  y2 
)

Definition at line 203 of file pathkit_wasm_bindings.cpp.

203 {
204 p.quadTo(x1, y1, x2, y2);
205}

◆ ApplyReverseAddPath()

void ApplyReverseAddPath ( SkPath orig,
const SkPath newPath 
)

Definition at line 354 of file pathkit_wasm_bindings.cpp.

354 {
355 orig.reverseAddPath(newPath);
356}
SkPath & reverseAddPath(const SkPath &src)
Definition: SkPath.cpp:1633

◆ ApplySimplify()

bool EMSCRIPTEN_KEEPALIVE ApplySimplify ( SkPath path)

Definition at line 238 of file pathkit_wasm_bindings.cpp.

238 {
239 return Simplify(path, &path);
240}
bool SK_API Simplify(const SkPath &path, SkPath *result)

◆ ApplyStroke()

bool ApplyStroke ( SkPath path,
StrokeOpts  opts 
)

Definition at line 415 of file pathkit_wasm_bindings.cpp.

415 {
416 SkPaint p;
417 p.setStyle(SkPaint::kStroke_Style);
418 p.setStrokeCap(opts.cap);
419 p.setStrokeJoin(opts.join);
420 p.setStrokeWidth(opts.width);
421 p.setStrokeMiter(opts.miter_limit);
422 // Default to 1.0 if 0 (or an invalid negative number)
423 if (opts.res_scale <= 0) {
424 opts.res_scale = 1.0;
425 }
426 return skpathutils::FillPathWithPaint(path, p, &path, nullptr, opts.res_scale);
427}
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
Definition: SkPathUtils.cpp:23
SkPaint::Join join
SkPaint::Cap cap

◆ ApplyTransform() [1/2]

void ApplyTransform ( SkPath orig,
const SimpleMatrix sm 
)

Definition at line 445 of file pathkit_wasm_bindings.cpp.

445 {
446 orig.transform(toSkMatrix(sm));
447}
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkPath.cpp:1711
SkMatrix toSkMatrix(const SimpleMatrix &sm)

◆ ApplyTransform() [2/2]

void ApplyTransform ( SkPath orig,
SkScalar  scaleX,
SkScalar  skewX,
SkScalar  transX,
SkScalar  skewY,
SkScalar  scaleY,
SkScalar  transY,
SkScalar  pers0,
SkScalar  pers1,
SkScalar  pers2 
)

Definition at line 449 of file pathkit_wasm_bindings.cpp.

452 {
453 SkMatrix m = SkMatrix::MakeAll(scaleX, skewX , transX,
454 skewY , scaleY, transY,
455 pers0 , pers1 , pers2);
456 orig.transform(m);
457}

◆ ApplyTrim()

bool ApplyTrim ( SkPath path,
SkScalar  startT,
SkScalar  stopT,
bool  isComplement 
)

Definition at line 389 of file pathkit_wasm_bindings.cpp.

389 {
391 auto pe = SkTrimPathEffect::Make(startT, stopT, mode);
392 if (!pe) {
393 SkDebugf("Invalid args to trim(): startT and stopT must be in [0,1]\n");
394 return false;
395 }
396 SkStrokeRec rec(SkStrokeRec::InitStyle::kHairline_InitStyle);
397 if (pe->filterPath(&path, path, &rec, nullptr)) {
398 return true;
399 }
400 SkDebugf("Could not trim path\n");
401 return false;
402}
static sk_sp< SkPathEffect > Make(SkScalar startT, SkScalar stopT, Mode=Mode::kNormal)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228

◆ CopyPath()

SkPath EMSCRIPTEN_KEEPALIVE CopyPath ( const SkPath a)

Definition at line 157 of file pathkit_wasm_bindings.cpp.

157 {
158 SkPath copy(a);
159 return copy;
160}
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
Definition: SkSwizzler.cpp:31
struct MyStruct a[10]

◆ EMSCRIPTEN_BINDINGS()

EMSCRIPTEN_BINDINGS ( skia  )

Definition at line 487 of file pathkit_wasm_bindings.cpp.

487 {
488 class_<SkPath>("SkPath")
489 .constructor<>()
490 .constructor<const SkPath&>()
491
492 // Path2D API
493 .function("_addPath", &ApplyAddPath)
494 .function("_reverseAddPath", &ApplyReverseAddPath)
495 // 3 additional overloads of addPath are handled in JS bindings
496 .function("_arc", &ApplyAddArc)
497 .function("_arcTo", &ApplyArcTo)
498 //"bezierCurveTo" alias handled in JS bindings
499 .function("_close", &ApplyClose)
500 //"closePath" alias handled in JS bindings
501 .function("_conicTo", &ApplyConicTo)
502 .function("_cubicTo", &ApplyCubicTo)
503
504 .function("_ellipse", &ApplyEllipse)
505 .function("_lineTo", &ApplyLineTo)
506 .function("_moveTo", &ApplyMoveTo)
507 // "quadraticCurveTo" alias handled in JS bindings
508 .function("_quadTo", &ApplyQuadTo)
509 .function("_rect", &ApplyAddRect)
510 .function("_isEmpty", &IsEmpty)
511
512 // Extra features
513 .function("setFillType", select_overload<void(SkPathFillType)>(&SkPath::setFillType))
514 .function("getFillType", &SkPath::getFillType)
515 .function("getFillTypeString", &GetFillTypeString)
516 .function("getBounds", &SkPath::getBounds)
517 .function("computeTightBounds", &SkPath::computeTightBounds)
518 .function("equals", &Equals)
519 .function("copy", &CopyPath)
520
521 // PathEffects
522 .function("_dash", &ApplyDash)
523 .function("_trim", &ApplyTrim)
524 .function("_stroke", &ApplyStroke)
525
526 // Matrix
527 .function("_transform", select_overload<void(SkPath& orig, const SimpleMatrix& sm)>(&ApplyTransform))
528 .function("_transform", select_overload<void(SkPath& orig, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar)>(&ApplyTransform))
529
530 // PathOps
531 .function("_simplify", &ApplySimplify)
532 .function("_asWinding", &ApplyAsWinding)
533 .function("_op", &ApplyPathOp)
534
535 // Exporting
536 .function("toCmds", &ToCmds)
537 .function("toPath2D", &ToPath2D)
538 .function("toCanvas", &ToCanvas)
539 .function("toSVGString", &ToSVGString)
540
541#ifdef PATHKIT_TESTING
542 .function("dump", select_overload<void() const>(&SkPath::dump))
543 .function("dumpHex", select_overload<void() const>(&SkPath::dumpHex))
544#endif
545 ;
546
547 class_<SkOpBuilder>("SkOpBuilder")
548 .constructor<>()
549
550 .function("add", &SkOpBuilder::add)
551 .function("make", &ResolveBuilder)
552 .function("resolve", &ResolveBuilder);
553
554 // Without these function() bindings, the function would be exposed but oblivious to
555 // our types (e.g. SkPath)
556
557 // Import
558 function("FromSVGString", &FromSVGString);
559 function("NewPath", &NewPath);
560 function("NewPath", &CopyPath);
561 // FromCmds is defined in helper.js to make use of TypedArrays transparent.
562 function("_FromCmds", &FromCmds);
563 // Path2D is opaque, so we can't read in from it.
564
565 // PathOps
566 function("MakeFromOp", &MakeFromOp);
567
568 enum_<SkPathOp>("PathOp")
569 .value("DIFFERENCE", SkPathOp::kDifference_SkPathOp)
570 .value("INTERSECT", SkPathOp::kIntersect_SkPathOp)
571 .value("UNION", SkPathOp::kUnion_SkPathOp)
572 .value("XOR", SkPathOp::kXOR_SkPathOp)
573 .value("REVERSE_DIFFERENCE", SkPathOp::kReverseDifference_SkPathOp);
574
575 enum_<SkPathFillType>("FillType")
576 .value("WINDING", SkPathFillType::kWinding)
577 .value("EVENODD", SkPathFillType::kEvenOdd)
578 .value("INVERSE_WINDING", SkPathFillType::kInverseWinding)
579 .value("INVERSE_EVENODD", SkPathFillType::kInverseEvenOdd);
580
581 constant("MOVE_VERB", MOVE);
582 constant("LINE_VERB", LINE);
583 constant("QUAD_VERB", QUAD);
584 constant("CONIC_VERB", CONIC);
585 constant("CUBIC_VERB", CUBIC);
586 constant("CLOSE_VERB", CLOSE);
587
588 // A value object is much simpler than a class - it is returned as a JS
589 // object and does not require delete().
590 // https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/embind.html#value-types
591 value_object<SkRect>("SkRect")
592 .field("fLeft", &SkRect::fLeft)
593 .field("fTop", &SkRect::fTop)
594 .field("fRight", &SkRect::fRight)
595 .field("fBottom", &SkRect::fBottom);
596
597 function("LTRBRect", &SkRect::MakeLTRB);
598
599 // Stroke
600 enum_<SkPaint::Join>("StrokeJoin")
601 .value("MITER", SkPaint::Join::kMiter_Join)
602 .value("ROUND", SkPaint::Join::kRound_Join)
603 .value("BEVEL", SkPaint::Join::kBevel_Join);
604
605 enum_<SkPaint::Cap>("StrokeCap")
606 .value("BUTT", SkPaint::Cap::kButt_Cap)
607 .value("ROUND", SkPaint::Cap::kRound_Cap)
608 .value("SQUARE", SkPaint::Cap::kSquare_Cap);
609
610 value_object<StrokeOpts>("StrokeOpts")
611 .field("width", &StrokeOpts::width)
612 .field("miter_limit", &StrokeOpts::miter_limit)
613 .field("res_scale", &StrokeOpts::res_scale)
614 .field("join", &StrokeOpts::join)
615 .field("cap", &StrokeOpts::cap);
616
617 // Matrix
618 // Allows clients to supply a 1D array of 9 elements and the bindings
619 // will automatically turn it into a 3x3 2D matrix.
620 // e.g. path.transform([0,1,2,3,4,5,6,7,8])
621 // This is likely simpler for the client than exposing SkMatrix
622 // directly and requiring them to do a lot of .delete().
623 value_array<SimpleMatrix>("SkMatrix")
624 .element(&SimpleMatrix::scaleX)
625 .element(&SimpleMatrix::skewX)
626 .element(&SimpleMatrix::transX)
627
628 .element(&SimpleMatrix::skewY)
629 .element(&SimpleMatrix::scaleY)
630 .element(&SimpleMatrix::transY)
631
632 .element(&SimpleMatrix::pers0)
633 .element(&SimpleMatrix::pers1)
634 .element(&SimpleMatrix::pers2);
635
636 value_array<SkPoint>("SkPoint")
637 .element(&SkPoint::fX)
638 .element(&SkPoint::fY);
639
640 // Not intended for external clients to call directly.
641 // See helper.js for the client-facing implementation.
642 class_<SkCubicMap>("_SkCubicMap")
643 .constructor<SkPoint, SkPoint>()
644
645 .function("computeYFromX", &SkCubicMap::computeYFromX)
646 .function("computePtFromT", &SkCubicMap::computeFromT);
647
648
649 // Test Utils
650 function("SkBits2FloatUnsigned", &SkBits2FloatUnsigned);
651}
@ kReverseDifference_SkPathOp
subtract the first path from the op path
Definition: SkPathOps.h:27
@ kDifference_SkPathOp
subtract the op path from the first path
Definition: SkPathOps.h:23
@ kIntersect_SkPathOp
intersect the two paths
Definition: SkPathOps.h:24
@ kUnion_SkPathOp
union (inclusive-or) the two paths
Definition: SkPathOps.h:25
@ kXOR_SkPathOp
exclusive-or the two paths
Definition: SkPathOps.h:26
SkPathFillType
Definition: SkPathTypes.h:11
float computeYFromX(float x) const
Definition: SkCubicMap.cpp:61
SkPoint computeFromT(float t) const
Definition: SkCubicMap.cpp:108
void add(const SkPath &path, SkPathOp _operator)
SkPathFillType getFillType() const
Definition: SkPath.h:230
void setFillType(SkPathFillType ft)
Definition: SkPath.h:235
SkRect computeTightBounds() const
Definition: SkPath.cpp:3446
void dump() const
Definition: SkPath.h:1734
const SkRect & getBounds() const
Definition: SkPath.cpp:430
void dumpHex() const
Definition: SkPath.h:1735
Dart_NativeFunction function
Definition: fuchsia.cc:51
SkPathOrNull EMSCRIPTEN_KEEPALIVE FromSVGString(std::string str)
bool EMSCRIPTEN_KEEPALIVE ApplySimplify(SkPath &path)
bool ApplyStroke(SkPath &path, StrokeOpts opts)
bool EMSCRIPTEN_KEEPALIVE ApplyAsWinding(SkPath &path)
static const int CLOSE
JSString EMSCRIPTEN_KEEPALIVE ToSVGString(const SkPath &path)
void ApplyReverseAddPath(SkPath &orig, const SkPath &newPath)
void ApplyClose(SkPath &p)
float SkBits2FloatUnsigned(uint32_t floatAsBits)
bool EMSCRIPTEN_KEEPALIVE ApplyPathOp(SkPath &pathOne, const SkPath &pathTwo, SkPathOp op)
SkPath EMSCRIPTEN_KEEPALIVE CopyPath(const SkPath &a)
JSArray EMSCRIPTEN_KEEPALIVE ToCmds(const SkPath &path)
void ApplyCubicTo(SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
void ApplyMoveTo(SkPath &p, SkScalar x, SkScalar y)
static const int QUAD
void ApplyArcTo(SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
void ApplyEllipse(SkPath &path, SkScalar x, SkScalar y, SkScalar radiusX, SkScalar radiusY, SkScalar rotation, SkScalar startAngle, SkScalar endAngle, bool ccw)
void ApplyConicTo(SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w)
bool EMSCRIPTEN_KEEPALIVE IsEmpty(const SkPath &path)
static const int CUBIC
SkPathOrNull EMSCRIPTEN_KEEPALIVE MakeFromOp(const SkPath &pathOne, const SkPath &pathTwo, SkPathOp op)
bool ApplyDash(SkPath &path, SkScalar on, SkScalar off, SkScalar phase)
JSString GetFillTypeString(const SkPath &path)
static const int MOVE
static const int LINE
void ApplyTransform(SkPath &orig, const SimpleMatrix &sm)
bool EMSCRIPTEN_KEEPALIVE Equals(const SkPath &a, const SkPath &b)
emscripten::val EMSCRIPTEN_KEEPALIVE ToPath2D(const SkPath &path)
SkPathOrNull EMSCRIPTEN_KEEPALIVE ResolveBuilder(SkOpBuilder &builder)
void EMSCRIPTEN_KEEPALIVE ToCanvas(const SkPath &path, emscripten::val ctx)
SkPathOrNull EMSCRIPTEN_KEEPALIVE FromCmds(uintptr_t cptr, int numCmds)
void ApplyQuadTo(SkPath &p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
void ApplyAddArc(SkPath &path, SkScalar x, SkScalar y, SkScalar radius, SkScalar startAngle, SkScalar endAngle, bool ccw)
bool ApplyTrim(SkPath &path, SkScalar startT, SkScalar stopT, bool isComplement)
static const int CONIC
void ApplyAddRect(SkPath &path, SkScalar x, SkScalar y, SkScalar width, SkScalar height)
void ApplyAddPath(SkPath &orig, const SkPath &newPath, SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
SkPath EMSCRIPTEN_KEEPALIVE NewPath()
void ApplyLineTo(SkPath &p, SkScalar x, SkScalar y)
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ Equals()

bool EMSCRIPTEN_KEEPALIVE Equals ( const SkPath a,
const SkPath b 
)

Definition at line 162 of file pathkit_wasm_bindings.cpp.

162 {
163 return a == b;
164}
static bool b

◆ FromCmds()

SkPathOrNull EMSCRIPTEN_KEEPALIVE FromCmds ( uintptr_t  cptr,
int  numCmds 
)

Definition at line 95 of file pathkit_wasm_bindings.cpp.

95 {
96 const auto* cmds = reinterpret_cast<const float*>(cptr);
98 float x1, y1, x2, y2, x3, y3;
99
100 // if there are not enough arguments, bail with the path we've constructed so far.
101 #define CHECK_NUM_ARGS(n) \
102 if ((i + n) > numCmds) { \
103 SkDebugf("Not enough args to match the verbs. Saw %d commands\n", numCmds); \
104 return emscripten::val::null(); \
105 }
106
107 for(int i = 0; i < numCmds;){
108 switch (sk_float_floor2int(cmds[i++])) {
109 case MOVE:
111 x1 = cmds[i++]; y1 = cmds[i++];
112 path.moveTo(x1, y1);
113 break;
114 case LINE:
116 x1 = cmds[i++]; y1 = cmds[i++];
117 path.lineTo(x1, y1);
118 break;
119 case QUAD:
121 x1 = cmds[i++]; y1 = cmds[i++];
122 x2 = cmds[i++]; y2 = cmds[i++];
123 path.quadTo(x1, y1, x2, y2);
124 break;
125 case CONIC:
127 x1 = cmds[i++]; y1 = cmds[i++];
128 x2 = cmds[i++]; y2 = cmds[i++];
129 x3 = cmds[i++]; // weight
130 path.conicTo(x1, y1, x2, y2, x3);
131 break;
132 case CUBIC:
134 x1 = cmds[i++]; y1 = cmds[i++];
135 x2 = cmds[i++]; y2 = cmds[i++];
136 x3 = cmds[i++]; y3 = cmds[i++];
137 path.cubicTo(x1, y1, x2, y2, x3, y3);
138 break;
139 case CLOSE:
140 path.close();
141 break;
142 default:
143 SkDebugf(" path: UNKNOWN command %f, aborting dump...\n", cmds[i-1]);
144 return emscripten::val::null();
145 }
146 }
147
148 #undef CHECK_NUM_ARGS
149
150 return emscripten::val(path);
151}
#define sk_float_floor2int(x)
static void dump(const float m[20], SkYUVColorSpace cs, bool rgb2yuv)
Definition: SkYUVMath.cpp:629
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By default
Definition: switches.h:183
list command
Definition: valgrind.py:24
#define CHECK_NUM_ARGS(n)

◆ FromSVGString()

SkPathOrNull EMSCRIPTEN_KEEPALIVE FromSVGString ( std::string  str)

Definition at line 226 of file pathkit_wasm_bindings.cpp.

226 {
227 SkPath path;
228 if (SkParsePath::FromSVGString(str.c_str(), &path)) {
229 return emscripten::val(path);
230 }
231 return emscripten::val::null();
232}
static bool FromSVGString(const char str[], SkPath *)

◆ GetFillTypeString()

JSString GetFillTypeString ( const SkPath path)

Definition at line 359 of file pathkit_wasm_bindings.cpp.

359 {
360 if (path.getFillType() == SkPathFillType::kWinding) {
361 return emscripten::val("nonzero");
362 } else if (path.getFillType() == SkPathFillType::kEvenOdd) {
363 return emscripten::val("evenodd");
364 } else {
365 SkDebugf("warning: can't translate inverted filltype to HTML Canvas\n");
366 return emscripten::val("nonzero"); //Use default
367 }
368}

◆ IsEmpty()

bool EMSCRIPTEN_KEEPALIVE IsEmpty ( const SkPath path)

Definition at line 207 of file pathkit_wasm_bindings.cpp.

207 {
208 return path.isEmpty();
209}

◆ MakeFromOp()

SkPathOrNull EMSCRIPTEN_KEEPALIVE MakeFromOp ( const SkPath pathOne,
const SkPath pathTwo,
SkPathOp  op 
)

Definition at line 250 of file pathkit_wasm_bindings.cpp.

250 {
251 SkPath out;
252 if (Op(pathOne, pathTwo, op, &out)) {
253 return emscripten::val(out);
254 }
255 return emscripten::val::null();
256}

◆ NewPath()

SkPath EMSCRIPTEN_KEEPALIVE NewPath ( )

Definition at line 153 of file pathkit_wasm_bindings.cpp.

153 {
154 return SkPath();
155}

◆ ResolveBuilder()

SkPathOrNull EMSCRIPTEN_KEEPALIVE ResolveBuilder ( SkOpBuilder builder)

Definition at line 258 of file pathkit_wasm_bindings.cpp.

258 {
259 SkPath path;
260 if (builder.resolve(&path)) {
261 return emscripten::val(path);
262 }
263 return emscripten::val::null();
264}

◆ SkBits2FloatUnsigned()

float SkBits2FloatUnsigned ( uint32_t  floatAsBits)

Definition at line 468 of file pathkit_wasm_bindings.cpp.

468 {
469 return SkBits2Float((int32_t) floatAsBits);
470}
static float SkBits2Float(uint32_t bits)
Definition: SkFloatBits.h:48

◆ ToCanvas()

void EMSCRIPTEN_KEEPALIVE ToCanvas ( const SkPath path,
emscripten::val  ctx 
)

Definition at line 270 of file pathkit_wasm_bindings.cpp.

270 {
271 SkPath::Iter iter(path, false);
272 SkPoint pts[4];
273 SkPath::Verb verb;
274 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
275 switch (verb) {
277 ctx.call<void>("moveTo", pts[0].x(), pts[0].y());
278 break;
280 ctx.call<void>("lineTo", pts[1].x(), pts[1].y());
281 break;
283 ctx.call<void>("quadraticCurveTo", pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
284 break;
286 SkPoint quads[5];
287 // approximate with 2^1=2 quads.
288 SkPath::ConvertConicToQuads(pts[0], pts[1], pts[2], iter.conicWeight(), quads, 1);
289 ctx.call<void>("quadraticCurveTo", quads[1].x(), quads[1].y(), quads[2].x(), quads[2].y());
290 ctx.call<void>("quadraticCurveTo", quads[3].x(), quads[3].y(), quads[4].x(), quads[4].y());
291 break;
293 ctx.call<void>("bezierCurveTo", pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y(),
294 pts[3].x(), pts[3].y());
295 break;
297 ctx.call<void>("closePath");
298 break;
300 break;
301 }
302 }
303}
static int ConvertConicToQuads(const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, SkScalar w, SkPoint pts[], int pow2)
Definition: SkPath.cpp:3238
@ kClose_Verb
Definition: SkPath.h:1471
@ kMove_Verb
Definition: SkPath.h:1466
@ kConic_Verb
Definition: SkPath.h:1469
@ kDone_Verb
Definition: SkPath.h:1472
@ kCubic_Verb
Definition: SkPath.h:1470
@ kQuad_Verb
Definition: SkPath.h:1468
@ kLine_Verb
Definition: SkPath.h:1467
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181

◆ ToCmds()

JSArray EMSCRIPTEN_KEEPALIVE ToCmds ( const SkPath path)

Definition at line 51 of file pathkit_wasm_bindings.cpp.

51 {
52 JSArray cmds = emscripten::val::array();
53 for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
54 JSArray cmd = emscripten::val::array();
55 switch (verb) {
57 cmd.call<void>("push", MOVE, pts[0].x(), pts[0].y());
58 break;
60 cmd.call<void>("push", LINE, pts[1].x(), pts[1].y());
61 break;
63 cmd.call<void>("push", QUAD, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
64 break;
66 cmd.call<void>("push", CONIC,
67 pts[1].x(), pts[1].y(),
68 pts[2].x(), pts[2].y(), *w);
69 break;
71 cmd.call<void>("push", CUBIC,
72 pts[1].x(), pts[1].y(),
73 pts[2].x(), pts[2].y(),
74 pts[3].x(), pts[3].y());
75 break;
77 cmd.call<void>("push", CLOSE);
78 break;
79 }
80 cmds.call<void>("push", cmd);
81 }
82 return cmds;
83}
@ kClose
SkPath::RawIter returns 0 points.
@ kCubic
SkPath::RawIter returns 4 points.
@ kConic
SkPath::RawIter returns 3 points + 1 weight.
@ kQuad
SkPath::RawIter returns 3 points.
@ kMove
SkPath::RawIter returns 1 point.
@ kLine
SkPath::RawIter returns 2 points.
emscripten::val JSArray
Definition: WasmCommon.h:27

◆ ToPath2D()

emscripten::val EMSCRIPTEN_KEEPALIVE ToPath2D ( const SkPath path)

Definition at line 307 of file pathkit_wasm_bindings.cpp.

307 {
308 emscripten::val retVal = JSPath2D.new_();
309 ToCanvas(path, retVal);
310 return retVal;
311}
emscripten::val JSPath2D

◆ toSkMatrix()

SkMatrix toSkMatrix ( const SimpleMatrix sm)

Definition at line 439 of file pathkit_wasm_bindings.cpp.

439 {
440 return SkMatrix::MakeAll(sm.scaleX, sm.skewX , sm.transX,
441 sm.skewY , sm.scaleY, sm.transY,
442 sm.pers0 , sm.pers1 , sm.pers2);
443}

◆ ToSVGString()

JSString EMSCRIPTEN_KEEPALIVE ToSVGString ( const SkPath path)

Definition at line 217 of file pathkit_wasm_bindings.cpp.

217 {
218 // Wrapping it in val automatically turns it into a JS string.
219 // Not too sure on performance implications, but is is simpler than
220 // returning a raw pointer to const char * and then using
221 // UTF8ToString() on the calling side.
222 return emscripten::val(SkParsePath::ToSVGString(path).c_str());
223}
static SkString ToSVGString(const SkPath &, PathEncoding=PathEncoding::Absolute)

Variable Documentation

◆ CLOSE

const int CLOSE = 5
static

Definition at line 36 of file pathkit_wasm_bindings.cpp.

◆ CONIC

const int CONIC = 3
static

Definition at line 34 of file pathkit_wasm_bindings.cpp.

◆ CUBIC

const int CUBIC = 4
static

Definition at line 35 of file pathkit_wasm_bindings.cpp.

◆ JSPath2D

emscripten::val JSPath2D = emscripten::val::global("Path2D")

Definition at line 305 of file pathkit_wasm_bindings.cpp.

◆ LINE

const int LINE = 1
static

Definition at line 32 of file pathkit_wasm_bindings.cpp.

◆ MOVE

const int MOVE = 0
static

Definition at line 31 of file pathkit_wasm_bindings.cpp.

◆ QUAD

const int QUAD = 2
static

Definition at line 33 of file pathkit_wasm_bindings.cpp.