Make native method binding configurable

Summary:
Moves binding of native methods into a separate native method that can be parameterized.

This will be used to experiment with JNI-related technology.

Reviewed By: priteshrnandgaonkar

Differential Revision: D9943870

fbshipit-source-id: 661f15537d5bbf7a3eef7717e3d99fed2de23904
This commit is contained in:
David Aurelio 2018-09-25 15:44:40 -07:00 коммит произвёл Facebook Github Bot
Родитель 201f2f189f
Коммит ee6c1ecef0
4 изменённых файлов: 134 добавлений и 100 удалений

Просмотреть файл

@ -16,7 +16,7 @@ public class YogaConfig {
public static int SPACING_TYPE = 1;
static {
SoLoader.loadLibrary("yoga");
YogaJNI.init();
}
long mNativePointer;

Просмотреть файл

@ -0,0 +1,26 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.soloader.SoLoader;
public class YogaJNI {
// set before loading any other Yoga code
public static boolean useFastCall = false;
private static native void jni_bindNativeMethods(boolean useFastCall);
static boolean init() {
if (SoLoader.loadLibrary("yoga")) {
jni_bindNativeMethods(useFastCall);
return true;
}
return false;
}
}

Просмотреть файл

@ -18,7 +18,7 @@ import javax.annotation.Nullable;
public class YogaNode implements Cloneable {
static {
SoLoader.loadLibrary("yoga");
YogaJNI.init();
}
/**

Просмотреть файл

@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
@ -674,8 +674,7 @@ jint jni_YGNodeGetInstanceCount(alias_ref<jclass> clazz) {
#define YGMakeNativeMethod(name) makeNativeMethod(#name, name)
jint JNI_OnLoad(JavaVM* vm, void*) {
return initialize(vm, [] {
void jni_bindNativeMethods(alias_ref<jclass>, jboolean) {
registerNatives(
"com/facebook/yoga/YogaNode",
{
@ -776,5 +775,14 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
YGMakeNativeMethod(
jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour),
});
}
jint JNI_OnLoad(JavaVM* vm, void*) {
return initialize(vm, [] {
registerNatives(
"com/facebook/yoga/YogaJNI",
{
YGMakeNativeMethod(jni_bindNativeMethods),
});
});
}