Skip to content

Commit 032d6b9

Browse files
committed
Migrate choreographer-30fps to RegisterNatives.
1 parent 3e09643 commit 032d6b9

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

teapots/choreographer-30fps/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ android {
1919
path 'src/main/cpp/CMakeLists.txt'
2020
}
2121
}
22+
23+
buildFeatures {
24+
prefab true
25+
}
2226
}
2327

2428
dependencies {
29+
implementation project(":base")
2530
implementation libs.appcompat
2631
implementation libs.androidx.constraintlayout
2732
}

teapots/choreographer-30fps/src/main/cpp/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ cmake_minimum_required(VERSION 3.22.1)
1818
project(ChoreographerNativeActivity LANGUAGES C CXX)
1919

2020
include(AppLibrary)
21+
find_package(base CONFIG REQUIRED)
2122

2223
# build the ndk-helper library
2324
get_filename_component(commonDir ${CMAKE_CURRENT_SOURCE_DIR}/../../../../common ABSOLUTE)
@@ -40,6 +41,6 @@ set_target_properties(${PROJECT_NAME}
4041
# add lib dependencies
4142
target_link_libraries(${PROJECT_NAME}
4243
PRIVATE
44+
base::base
4345
NdkHelper
4446
)
45-

teapots/choreographer-30fps/src/main/cpp/ChoreographerNativeActivity.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <EGL/egl.h>
2121
#include <android/log.h>
2222
#include <android_native_app_glue.h>
23+
#include <base/macros.h>
2324
#include <dlfcn.h>
2425

2526
#include <condition_variable>
@@ -303,9 +304,7 @@ void Engine::SynchInCallback(jlong frameTimeInNanos) {
303304
}
304305
};
305306

306-
extern "C" JNIEXPORT void JNICALL
307-
Java_com_sample_choreographer_ChoreographerNativeActivity_choregrapherCallback(
308-
JNIEnv*, jobject, jlong frameTimeInNanos) {
307+
void ChoregrapherCallback(JNIEnv*, jobject, jlong frameTimeInNanos) {
309308
g_engine.SynchInCallback(frameTimeInNanos);
310309
}
311310

@@ -611,4 +610,25 @@ void android_main(android_app* state) {
611610
}
612611

613612
g_engine.TermDisplay();
614-
}
613+
}
614+
615+
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* _Nonnull vm,
616+
void* _Nullable) {
617+
JNIEnv* env;
618+
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
619+
return JNI_ERR;
620+
}
621+
622+
jclass c =
623+
env->FindClass("com/sample/choreographer/ChoreographerNativeActivity");
624+
if (c == nullptr) return JNI_ERR;
625+
626+
static const JNINativeMethod methods[] = {
627+
{"choregrapherCallback", "(J)V",
628+
reinterpret_cast<void*>(ChoregrapherCallback)},
629+
};
630+
int rc = env->RegisterNatives(c, methods, arraysize(methods));
631+
if (rc != JNI_OK) return rc;
632+
633+
return JNI_VERSION_1_6;
634+
}

0 commit comments

Comments
 (0)