• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkCanvas.h"
9 #include "SkTypes.h"
10 #include "SkParticleAffector.h"
11 #include "SkParticleDrawable.h"
12 #include "SkParticleEffect.h"
13 #include "SkParticleSerialization.h"
14 #include "SkRandom.h"
15 
16 #include <string>
17 
18 #include <emscripten.h>
19 #include <emscripten/bind.h>
20 
21 using namespace emscripten;
22 
EMSCRIPTEN_BINDINGS(Particles)23 EMSCRIPTEN_BINDINGS(Particles) {
24     class_<SkParticleEffect>("SkParticleEffect")
25         .smart_ptr<sk_sp<SkParticleEffect>>("sk_sp<SkParticleEffect>")
26         .function("draw", &SkParticleEffect::draw, allow_raw_pointers())
27         .function("start", select_overload<void (double, bool)>(&SkParticleEffect::start))
28         .function("update", select_overload<void (double)>(&SkParticleEffect::update));
29 
30     function("MakeParticles", optional_override([](std::string json)->sk_sp<SkParticleEffect> {
31         static bool didInit = false;
32         if (!didInit) {
33             REGISTER_REFLECTED(SkReflected);
34             SkParticleAffector::RegisterAffectorTypes();
35             SkParticleDrawable::RegisterDrawableTypes();
36             didInit = true;
37         }
38         SkRandom r;
39         sk_sp<SkParticleEffectParams> params(new SkParticleEffectParams());
40         skjson::DOM dom(json.c_str(), json.length());
41         SkFromJsonVisitor fromJson(dom.root());
42         params->visitFields(&fromJson);
43         return sk_sp<SkParticleEffect>(new SkParticleEffect(std::move(params), r));
44     }));
45     constant("particles", true);
46 
47 }
48