2020-03-25 16:50:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <emscripten.h>
|
|
|
|
#include <emscripten/bind.h>
|
2020-04-01 20:46:16 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2020-05-27 20:59:16 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2020-05-29 16:51:08 +00:00
|
|
|
#include "tools/skui/InputState.h"
|
|
|
|
#include "tools/skui/ModifierKey.h"
|
2020-05-27 23:31:12 +00:00
|
|
|
#include "tools/viewer/SKPSlide.h"
|
2020-03-25 16:50:35 +00:00
|
|
|
#include "tools/viewer/SampleSlide.h"
|
2020-05-28 20:04:53 +00:00
|
|
|
#include "tools/viewer/SvgSlide.h"
|
2020-05-27 20:59:16 +00:00
|
|
|
#include <GLES3/gl3.h>
|
2020-03-25 16:50:35 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace emscripten;
|
|
|
|
|
2020-05-29 16:51:08 +00:00
|
|
|
static sk_sp<Slide> MakeSlide(std::string name) {
|
2020-05-29 08:10:37 +00:00
|
|
|
if (name == "PathText") {
|
|
|
|
extern Sample* MakePathTextSample();
|
|
|
|
return sk_make_sp<SampleSlide>(MakePathTextSample);
|
2020-05-27 20:59:16 +00:00
|
|
|
}
|
2020-05-29 16:51:08 +00:00
|
|
|
if (name == "TessellatedWedge") {
|
|
|
|
extern Sample* MakeTessellatedWedgeSample();
|
|
|
|
return sk_make_sp<SampleSlide>(MakeTessellatedWedgeSample);
|
|
|
|
}
|
2020-05-27 20:59:16 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-05-29 16:51:08 +00:00
|
|
|
static sk_sp<Slide> MakeSkpSlide(std::string name, std::string skpData) {
|
2020-05-27 23:31:12 +00:00
|
|
|
auto stream = std::make_unique<SkMemoryStream>(skpData.data(), skpData.size(),
|
|
|
|
/*copyData=*/true);
|
|
|
|
return sk_make_sp<SKPSlide>(SkString(name.c_str()), std::move(stream));
|
|
|
|
}
|
|
|
|
|
2020-05-29 16:51:08 +00:00
|
|
|
static sk_sp<Slide> MakeSvgSlide(std::string name, std::string svgText) {
|
2020-05-28 20:04:53 +00:00
|
|
|
auto stream = std::make_unique<SkMemoryStream>(svgText.data(), svgText.size(),
|
|
|
|
/*copyData=*/true);
|
|
|
|
return sk_make_sp<SvgSlide>(SkString(name.c_str()), std::move(stream));
|
|
|
|
}
|
|
|
|
|
2020-03-25 16:50:35 +00:00
|
|
|
EMSCRIPTEN_BINDINGS(Viewer) {
|
2020-05-27 20:59:16 +00:00
|
|
|
function("MakeSlide", &MakeSlide);
|
2020-05-27 23:31:12 +00:00
|
|
|
function("MakeSkpSlide", &MakeSkpSlide);
|
2020-05-28 20:04:53 +00:00
|
|
|
function("MakeSvgSlide", &MakeSvgSlide);
|
2020-03-25 16:50:35 +00:00
|
|
|
class_<Slide>("Slide")
|
|
|
|
.smart_ptr<sk_sp<Slide>>("sk_sp<Slide>")
|
|
|
|
.function("load", &Slide::load)
|
|
|
|
.function("animate", &Slide::animate)
|
|
|
|
.function("draw", optional_override([](Slide& self, SkCanvas& canvas) {
|
|
|
|
self.draw(&canvas);
|
2020-05-29 16:51:08 +00:00
|
|
|
}))
|
|
|
|
.function("onChar", &Slide::onChar)
|
|
|
|
.function("onMouse", &Slide::onMouse);
|
|
|
|
enum_<skui::InputState>("InputState")
|
|
|
|
.value("Down", skui::InputState::kDown)
|
|
|
|
.value("Up", skui::InputState::kUp)
|
|
|
|
.value("Move", skui::InputState::kMove)
|
|
|
|
.value("Right", skui::InputState::kRight)
|
|
|
|
.value("Left", skui::InputState::kLeft);
|
|
|
|
enum_<skui::ModifierKey>("ModifierKey")
|
|
|
|
.value("None", skui::ModifierKey::kNone)
|
|
|
|
.value("Shift", skui::ModifierKey::kShift)
|
|
|
|
.value("Control", skui::ModifierKey::kControl)
|
|
|
|
.value("Option", skui::ModifierKey::kOption)
|
|
|
|
.value("Command", skui::ModifierKey::kCommand)
|
|
|
|
.value("FirstPress", skui::ModifierKey::kFirstPress);
|
2020-03-25 16:50:35 +00:00
|
|
|
}
|