skia2/modules/canvaskit/viewer_bindings.cpp
Adlai Holler 0ce2c54094 Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc6768.

Reason for revert: Fixed g3

Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeac.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac8.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94ede.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>

TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com


Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:59:11 +00:00

73 lines
2.7 KiB
C++

/*
* 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>
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "tools/skui/InputState.h"
#include "tools/skui/ModifierKey.h"
#include "tools/viewer/SKPSlide.h"
#include "tools/viewer/SampleSlide.h"
#include "tools/viewer/SvgSlide.h"
#include <GLES3/gl3.h>
#include <string>
using namespace emscripten;
static sk_sp<Slide> MakeSlide(std::string name) {
if (name == "PathText") {
extern Sample* MakePathTextSample();
return sk_make_sp<SampleSlide>(MakePathTextSample);
}
if (name == "TessellatedWedge") {
extern Sample* MakeTessellatedWedgeSample();
return sk_make_sp<SampleSlide>(MakeTessellatedWedgeSample);
}
return nullptr;
}
static sk_sp<Slide> MakeSkpSlide(std::string name, std::string skpData) {
auto stream = std::make_unique<SkMemoryStream>(skpData.data(), skpData.size(),
/*copyData=*/true);
return sk_make_sp<SKPSlide>(SkString(name.c_str()), std::move(stream));
}
static sk_sp<Slide> MakeSvgSlide(std::string name, std::string svgText) {
auto stream = std::make_unique<SkMemoryStream>(svgText.data(), svgText.size(),
/*copyData=*/true);
return sk_make_sp<SvgSlide>(SkString(name.c_str()), std::move(stream));
}
EMSCRIPTEN_BINDINGS(Viewer) {
function("MakeSlide", &MakeSlide);
function("MakeSkpSlide", &MakeSkpSlide);
function("MakeSvgSlide", &MakeSvgSlide);
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);
}))
.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);
}