/* * Copyright 2019 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "include/core/SkCanvas.h" #include "include/core/SkTypes.h" #include "include/utils/SkRandom.h" #include "modules/particles/include/SkParticleDrawable.h" #include "modules/particles/include/SkParticleEffect.h" #include "modules/particles/include/SkParticleSerialization.h" #include #include #include using namespace emscripten; EMSCRIPTEN_BINDINGS(Particles) { class_("SkParticleEffect") .smart_ptr>("sk_sp") .function("draw", &SkParticleEffect::draw, allow_raw_pointers()) .function("start", select_overload(&SkParticleEffect::start)) .function("update", select_overload(&SkParticleEffect::update)); function("MakeParticles", optional_override([](std::string json)->sk_sp { static bool didInit = false; if (!didInit) { REGISTER_REFLECTED(SkReflected); SkParticleBinding::RegisterBindingTypes(); SkParticleDrawable::RegisterDrawableTypes(); didInit = true; } SkRandom r; sk_sp params(new SkParticleEffectParams()); skjson::DOM dom(json.c_str(), json.length()); SkFromJsonVisitor fromJson(dom.root()); params->visitFields(&fromJson); return sk_sp(new SkParticleEffect(std::move(params), r)); })); constant("particles", true); }