Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkottieAnimation.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc.
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 <jni.h>
9
12
13using namespace skottie;
14
15namespace {
16
17static jlong Animation_Create(JNIEnv* env, jobject, jstring jjson) {
18 const jetski::utils::CString cstr(env, jjson);
19
20 // TODO: more builder opts
21 auto animation = Animation::Builder().make(cstr, strlen(cstr));
22
23 return reinterpret_cast<jlong>(animation.release());
24}
25
26static void Animation_Release(JNIEnv, jobject, jlong native_animation) {
27 SkSafeUnref(reinterpret_cast<Animation*>(native_animation));
28}
29
30static jdouble Animation_GetDuration(JNIEnv, jobject, jlong native_animation) {
31 const auto* animation = reinterpret_cast<const Animation*>(native_animation);
32 return animation ? animation->duration() : 0;
33}
34
35static jdouble Animation_GetFrameCnt(JNIEnv, jobject, jlong native_animation) {
36 const auto* animation = reinterpret_cast<const Animation*>(native_animation);
37 return animation ? animation->outPoint() : 0;
38}
39
40static jfloat Animation_GetWidth(JNIEnv, jobject, jlong native_animation) {
41 const auto* animation = reinterpret_cast<const Animation*>(native_animation);
42 return animation ? animation->size().width() : 0;
43}
44
45static jfloat Animation_GetHeight(JNIEnv, jobject, jlong native_animation) {
46 const auto* animation = reinterpret_cast<const Animation*>(native_animation);
47 return animation ? animation->size().height() : 0;
48}
49
50static void Animation_SeekFrame(JNIEnv, jobject, jlong native_animation, jdouble frame) {
51 if (auto* animation = reinterpret_cast<Animation*>(native_animation)) {
52 animation->seekFrame(frame);
53 }
54}
55
56static void Animation_SeekTime(JNIEnv, jobject, jlong native_animation, jdouble t) {
57 if (auto* animation = reinterpret_cast<Animation*>(native_animation)) {
58 animation->seekFrameTime(t);
59 }
60}
61
62static void Animation_Render(JNIEnv, jobject, jlong native_animation, jlong native_canvas) {
63 const auto* animation = reinterpret_cast<const Animation*>(native_animation);
64 auto* canvas = reinterpret_cast<SkCanvas*>(native_canvas);
65 if (animation && canvas) {
66 animation->render(canvas);
67 }
68}
69
70} // namespace
71
73 static const JNINativeMethod methods[] = {
74 {"nCreate" , "(Ljava/lang/String;)J", reinterpret_cast<void*>(Animation_Create) },
75 {"nRelease" , "(J)V" , reinterpret_cast<void*>(Animation_Release) },
76
77 {"nGetDuration" , "(J)D" , reinterpret_cast<void*>(Animation_GetDuration)},
78 {"nGetFrameCount", "(J)D" , reinterpret_cast<void*>(Animation_GetFrameCnt)},
79 {"nGetWidth" , "(J)F" , reinterpret_cast<void*>(Animation_GetWidth) },
80 {"nGetHeight" , "(J)F" , reinterpret_cast<void*>(Animation_GetHeight) },
81
82 {"nSeekFrame" , "(JD)V" , reinterpret_cast<void*>(Animation_SeekFrame) },
83 {"nSeekTime" , "(JD)V" , reinterpret_cast<void*>(Animation_SeekTime) },
84 {"nRender" , "(JJ)V" , reinterpret_cast<void*>(Animation_Render) },
85 };
86
87 const auto clazz = env->FindClass("org/skia/jetski/SkottieAnimation");
88 return clazz
89 ? env->RegisterNatives(clazz, methods, std::size(methods))
90 : JNI_ERR;
91}
static void SkSafeUnref(T *obj)
Definition SkRefCnt.h:149
int register_jetski_SkottieAnimation(JNIEnv *env)
sk_sp< Animation > make(SkStream *)
Definition Skottie.cpp:349
const SkSize & size() const
Definition Skottie.h:286
double outPoint() const
Definition Skottie.h:283
double duration() const
Definition Skottie.h:268
double frame
Definition examples.cpp:31
Definition __init__.py:1
SkScalar width() const
Definition SkSize.h:76
SkScalar height() const
Definition SkSize.h:77