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 <android/log.h>
9 #include <jni.h>
10 
11 #define REGISTER_NATIVES(class_name)                     \
12 extern int register_androidkit_##class_name(JNIEnv*);    \
13 if (auto rc = register_androidkit_##class_name(env)) {   \
14     __android_log_print(ANDROID_LOG_ERROR, "AndroidKit", \
15         "Failed to load natives: " #class_name);         \
16     return rc;                                           \
17 }
18 
19 
JNI_OnLoad(JavaVM * vm,void * reserved)20 JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
21     JNIEnv* env;
22     if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
23         return JNI_ERR;
24     }
25 
26     REGISTER_NATIVES(Canvas)
27     REGISTER_NATIVES(Matrix)
28     REGISTER_NATIVES(Paint)
29     REGISTER_NATIVES(RuntimeShaderBuilder)
30     REGISTER_NATIVES(Shader)
31     REGISTER_NATIVES(Surface)
32 
33     return JNI_VERSION_1_6;
34 }
35