Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
skottie_bindings.cpp File Reference
#include "include/codec/SkCodec.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkImage.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkOnce.h"
#include "modules/canvaskit/WasmCommon.h"
#include "modules/skottie/include/Skottie.h"
#include "modules/skottie/include/SkottieProperty.h"
#include "modules/skottie/include/SlotManager.h"
#include "modules/skottie/utils/SkottieUtils.h"
#include "modules/skottie/utils/TextEditor.h"
#include "modules/skparagraph/include/Paragraph.h"
#include "modules/skresources/include/SkResources.h"
#include "modules/sksg/include/SkSGInvalidationController.h"
#include "modules/skshaper/utils/FactoryHelpers.h"
#include "modules/skunicode/include/SkUnicode.h"
#include "src/base/SkUTF.h"
#include "src/ports/SkTypeface_FreeType.h"
#include "tools/skui/InputState.h"
#include "tools/skui/ModifierKey.h"
#include <string>
#include <vector>
#include <emscripten.h>
#include <emscripten/bind.h>
#include "include/ports/SkFontMgr_empty.h"

Go to the source code of this file.

Functions

 EMSCRIPTEN_BINDINGS (Skottie)
 

Function Documentation

◆ EMSCRIPTEN_BINDINGS()

EMSCRIPTEN_BINDINGS ( Skottie  )

Definition at line 656 of file skottie_bindings.cpp.

656 {
657 // Animation things (may eventually go in own library)
658 class_<skottie::Animation>("Animation")
659 .smart_ptr<sk_sp<skottie::Animation>>("sk_sp<Animation>")
660 .function("version", optional_override([](skottie::Animation& self)->std::string {
661 return std::string(self.version().c_str());
662 }))
663 .function("_size", optional_override([](skottie::Animation& self,
664 WASMPointerF32 oPtr)->void {
665 SkSize* output = reinterpret_cast<SkSize*>(oPtr);
666 *output = self.size();
667 }))
668 .function("duration", &skottie::Animation::duration)
669 .function("fps" , &skottie::Animation::fps)
670 .function("seek", optional_override([](skottie::Animation& self, SkScalar t)->void {
671 self.seek(t);
672 }))
673 .function("seekFrame", optional_override([](skottie::Animation& self, double t)->void {
674 self.seekFrame(t);
675 }))
676 .function("_render", optional_override([](skottie::Animation& self, SkCanvas* canvas,
677 WASMPointerF32 fPtr)->void {
678 const SkRect* dst = reinterpret_cast<const SkRect*>(fPtr);
679 self.render(canvas, dst);
680 }), allow_raw_pointers());
681
682 function("MakeAnimation", optional_override([](std::string json)->sk_sp<skottie::Animation> {
683 return skottie::Animation::Make(json.c_str(), json.length());
684 }));
685 constant("skottie", true);
686
687 class_<ManagedAnimation>("ManagedAnimation")
688 .smart_ptr<sk_sp<ManagedAnimation>>("sk_sp<ManagedAnimation>")
689 .function("version" , &ManagedAnimation::version)
690 .function("_size", optional_override([](ManagedAnimation& self,
691 WASMPointerF32 oPtr)->void {
692 SkSize* output = reinterpret_cast<SkSize*>(oPtr);
693 *output = self.size();
694 }))
695 .function("duration" , &ManagedAnimation::duration)
696 .function("fps" , &ManagedAnimation::fps)
697 .function("_render", optional_override([](ManagedAnimation& self, SkCanvas* canvas,
698 WASMPointerF32 fPtr)->void {
699 const SkRect* dst = reinterpret_cast<const SkRect*>(fPtr);
700 self.render(canvas, dst);
701 }), allow_raw_pointers())
702 .function("_seek", optional_override([](ManagedAnimation& self, SkScalar t,
703 WASMPointerF32 fPtr) {
704 SkRect* damageRect = reinterpret_cast<SkRect*>(fPtr);
705 damageRect[0] = self.seek(t);
706 }))
707 .function("_seekFrame", optional_override([](ManagedAnimation& self, double frame,
708 WASMPointerF32 fPtr) {
709 SkRect* damageRect = reinterpret_cast<SkRect*>(fPtr);
710 damageRect[0] = self.seekFrame(frame);
711 }))
712 .function("seekFrame" , &ManagedAnimation::seekFrame)
713 .function("_setColor" , optional_override([](ManagedAnimation& self, const std::string& key, WASMPointerF32 cPtr) {
714 float* fourFloats = reinterpret_cast<float*>(cPtr);
715 SkColor4f color = { fourFloats[0], fourFloats[1], fourFloats[2], fourFloats[3] };
716 return self.setColor(key, color.toSkColor());
717 }))
718 .function("_setTransform" , optional_override([](ManagedAnimation& self,
719 const std::string& key,
720 WASMPointerF32 transformData) {
721 // transform value info is passed in as an array of 9 scalars in the following order:
722 // anchor xy, position xy, scalexy, rotation, skew, skew axis
723 auto transform = reinterpret_cast<SkScalar*>(transformData);
724 return self.setTransform(key, transform[0], transform[1], transform[2], transform[3],
725 transform[4], transform[5], transform[6], transform[7], transform[8]);
726 }))
727 .function("getMarkers" , &ManagedAnimation::getMarkers)
728 .function("getColorProps" , &ManagedAnimation::getColorProps)
729 .function("getOpacityProps" , &ManagedAnimation::getOpacityProps)
730 .function("setOpacity" , &ManagedAnimation::setOpacity)
731 .function("getTextProps" , &ManagedAnimation::getTextProps)
732 .function("setText" , &ManagedAnimation::setText)
733 .function("getTransformProps", &ManagedAnimation::getTransformProps)
734 .function("getSlotInfo" , &ManagedAnimation::getSlotInfo)
735 .function("_getColorSlot" , &ManagedAnimation::getColorSlot)
736 .function("_setColorSlot" , optional_override([](ManagedAnimation& self, const std::string& key, WASMPointerF32 cPtr) {
738 return self.setColorSlot(key, color.toSkColor());
739 }))
740 .function("_getVec2Slot" , &ManagedAnimation::getVec2Slot)
741 .function("_setVec2Slot" , optional_override([](ManagedAnimation& self, const std::string& key, WASMPointerF32 vPtr) {
742 float* twoFloats = reinterpret_cast<float*>(vPtr);
743 SkV2 vec2 = {twoFloats[0], twoFloats[1]};
744 return self.setVec2Slot(key, vec2);
745 }))
746 .function("getScalarSlot" , &ManagedAnimation::getScalarSlot)
747 .function("setScalarSlot" , &ManagedAnimation::setScalarSlot)
748 .function("attachEditor" , &ManagedAnimation::attachEditor)
749 .function("enableEditor" , &ManagedAnimation::enableEditor)
750 .function("dispatchEditorKey" , &ManagedAnimation::dispatchEditorKey)
751 .function("dispatchEditorPointer", &ManagedAnimation::dispatchEditorPointer)
752 .function("setEditorCursorWeight", &ManagedAnimation::setEditorCursorWeight)
753 .function("getTextSlot" , &ManagedAnimation::getTextSlot)
754 .function("_setTextSlot" , &ManagedAnimation::setTextSlot)
755 .function("setImageSlot" , &ManagedAnimation::setImageSlot);
756
757 function("_MakeManagedAnimation", optional_override([](std::string json,
758 size_t assetCount,
759 WASMPointerU32 nptr,
760 WASMPointerU32 dptr,
761 WASMPointerU32 sptr,
762 std::string prop_prefix,
763 emscripten::val soundMap,
764 emscripten::val logger)
766 const auto assetNames = reinterpret_cast<char** >(nptr);
767 const auto assetDatas = reinterpret_cast<uint8_t**>(dptr);
768 const auto assetSizes = reinterpret_cast<size_t* >(sptr);
769
770 SkottieAssetProvider::AssetVec assets;
771 assets.reserve(assetCount);
772
773 for (size_t i = 0; i < assetCount; i++) {
774 auto name = SkString(assetNames[i]);
775 auto bytes = SkData::MakeFromMalloc(assetDatas[i], assetSizes[i]);
776 assets.push_back(std::make_pair(std::move(name), std::move(bytes)));
777 }
778
779 // DataURIResourceProviderProxy needs codecs registered to try to process Base64 encoded
780 // images.
781 static SkOnce once;
782 once([] {
783#if defined(SK_CODEC_DECODES_PNG)
784 SkCodecs::Register(SkPngDecoder::Decoder());
785#endif
786#if defined(SK_CODEC_DECODES_JPEG)
787 SkCodecs::Register(SkJpegDecoder::Decoder());
788#endif
789#if defined(SK_CODEC_DECODES_GIF)
790 SkCodecs::Register(SkGifDecoder::Decoder());
791#endif
792#if defined(SK_CODEC_DECODES_WEBP)
793 SkCodecs::Register(SkWebpDecoder::Decoder());
794#endif
795 });
796
797 sk_sp<SkFontMgr> fontmgr;
798#if !defined(CK_NO_FONTS)
799 fontmgr = SkFontMgr_New_Custom_Empty();
800#endif
801
802 return ManagedAnimation::Make(json,
804 SkottieAssetProvider::Make(std::move(assets),
805 std::move(soundMap)),
807 std::move(fontmgr)),
808 prop_prefix, std::move(logger));
809 }));
810
811 enum_<skui::InputState>("InputState")
812 .value("Down", skui::InputState::kDown)
813 .value("Up", skui::InputState::kUp)
814 .value("Move", skui::InputState::kMove)
815 .value("Right", skui::InputState::kRight)
816 .value("Left", skui::InputState::kLeft);
817
818 enum_<skui::ModifierKey>("ModifierKey")
819 .value("None", skui::ModifierKey::kNone)
820 .value("Shift", skui::ModifierKey::kShift)
821 .value("Control", skui::ModifierKey::kControl)
822 .value("Option", skui::ModifierKey::kOption)
823 .value("Command", skui::ModifierKey::kCommand)
824 .value("FirstPress", skui::ModifierKey::kFirstPress);
825
826 enum_<skottie::Shaper::VAlign>("VerticalTextAlign")
827 .value("Top", skottie::Shaper::VAlign::kTop)
828 .value("TopBaseline", skottie::Shaper::VAlign::kTopBaseline)
829 .value("VisualTop", skottie::Shaper::VAlign::kVisualTop)
830 .value("VisualCenter", skottie::Shaper::VAlign::kVisualCenter)
831 .value("VisualBottom", skottie::Shaper::VAlign::kVisualBottom);
832
833 enum_<skottie::Shaper::ResizePolicy>("ResizePolicy")
836 .value("DownscaleToFit", skottie::Shaper::ResizePolicy::kDownscaleToFit);
837
838 value_object<SimpleSlottableTextProperty>("SlottableTextProperty")
839 .field("typeface", &SimpleSlottableTextProperty::typeface)
840 .field("text", &SimpleSlottableTextProperty::text)
841 .field("textSize", &SimpleSlottableTextProperty::textSize)
842 .field("minTextSize", &SimpleSlottableTextProperty::minTextSize)
843 .field("maxTextSize", &SimpleSlottableTextProperty::maxTextSize)
844 .field("strokeWidth", &SimpleSlottableTextProperty::strokeWidth)
845 .field("lineHeight", &SimpleSlottableTextProperty::lineHeight)
846 .field("lineShift", &SimpleSlottableTextProperty::lineShift)
847 .field("ascent", &SimpleSlottableTextProperty::ascent)
848 .field("maxLines", &SimpleSlottableTextProperty::maxLines)
849 .field("horizAlign", &SimpleSlottableTextProperty::horizAlign)
850 .field("vertAlign", &SimpleSlottableTextProperty::vertAlign)
851 .field("strokeJoin", &SimpleSlottableTextProperty::strokeJoin)
852 .field("direction", &SimpleSlottableTextProperty::direction)
853 .field("linebreak", &SimpleSlottableTextProperty::lineBreak)
854 .field("resize", &SimpleSlottableTextProperty::resize)
855 .field("_fillColorPtr", &SimpleSlottableTextProperty::fillColorPtr)
856 .field("_strokeColorPtr", &SimpleSlottableTextProperty::strokeColorPtr)
857 .field("_boundingBoxPtr", &SimpleSlottableTextProperty::boundingBoxPtr);
858
859 constant("managed_skottie", true);
860}
SkColor4f color
SK_API sk_sp< SkFontMgr > SkFontMgr_New_Custom_Empty()
uintptr_t WASMPointerU32
Definition WasmCommon.h:48
uintptr_t WASMPointerF32
Definition WasmCommon.h:44
SkColor4f ptrToSkColor4f(WASMPointerF32 cPtr)
static sk_sp< SkData > MakeFromMalloc(const void *data, size_t length)
Definition SkData.cpp:107
double fps() const
Definition Skottie.h:273
double duration() const
Definition Skottie.h:268
static sk_sp< Animation > Make(const char *data, size_t length)
Definition Skottie.cpp:534
static sk_sp< DataURIResourceProviderProxy > Make(sk_sp< ResourceProvider > rp, ImageDecodeStrategy=ImageDecodeStrategy::kLazyDecode, sk_sp< const SkFontMgr > fontMgr=nullptr)
double frame
Definition examples.cpp:31
float SkScalar
Definition extension.cpp:12
Dart_NativeFunction function
Definition fuchsia.cc:51
const char * name
Definition fuchsia.cc:50
constexpr SkCodecs::Decoder Decoder()
constexpr SkCodecs::Decoder Decoder()
constexpr SkCodecs::Decoder Decoder()
constexpr SkCodecs::Decoder Decoder()
dst
Definition cp.py:12
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
Definition SkM44.h:19