move config jni methods to vanilla jni

Summary: Move yoga node config related jni methods to vanilla jni

Reviewed By: amir-shalem

Differential Revision: D17684821

fbshipit-source-id: 31a667b3ad67501aaef83a132971e4e0826cacd4
This commit is contained in:
Sidharth Guglani
2019-10-08 14:23:57 -07:00
committed by Facebook Github Bot
parent 34b68cf1d2
commit ee73f556b4
6 changed files with 143 additions and 14 deletions

View File

@@ -38,7 +38,5 @@ public abstract class YogaConfig {
abstract long getNativePointer();
public abstract void setUseVanillaJNI(boolean useVanillaJNI);
public abstract boolean useVanillaJNI();
}

View File

@@ -4,4 +4,8 @@ public abstract class YogaConfigFactory {
public static YogaConfig create() {
return new YogaConfigJNIFinalizer();
}
public static YogaConfig create(boolean useVanillaJNI) {
return new YogaConfigJNIFinalizer(useVanillaJNI);
}
}

View File

@@ -23,19 +23,36 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
this(YogaNative.jni_YGConfigNew());
}
YogaConfigJNIBase(boolean useVanillaJNI) {
this(useVanillaJNI ? YogaNative.jni_YGConfigNewJNI() : YogaNative.jni_YGConfigNew());
this.useVanillaJNI = useVanillaJNI;
}
public void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI(mNativePointer, feature.intValue(), enabled);
else
YogaNative.jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
}
public void setUseWebDefaults(boolean useWebDefaults) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetUseWebDefaultsJNI(mNativePointer, useWebDefaults);
else
YogaNative.jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
}
public void setPrintTreeFlag(boolean enable) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetPrintTreeFlagJNI(mNativePointer, enable);
else
YogaNative.jni_YGConfigSetPrintTreeFlag(mNativePointer, enable);
}
public void setPointScaleFactor(float pixelsInPoint) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetPointScaleFactorJNI(mNativePointer, pixelsInPoint);
else
YogaNative.jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
}
@@ -45,6 +62,9 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
* Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour.
*/
public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviourJNI(mNativePointer, useLegacyStretchBehaviour);
else
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
}
@@ -55,6 +75,10 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
*/
public void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI(
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
else
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
}
@@ -72,11 +96,6 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
return mNativePointer;
}
@Override
public void setUseVanillaJNI(boolean useVanillaJNI) {
this.useVanillaJNI = useVanillaJNI;
}
@Override
public boolean useVanillaJNI() {
return this.useVanillaJNI;

View File

@@ -11,6 +11,10 @@ public class YogaConfigJNIFinalizer extends YogaConfigJNIBase {
super();
}
public YogaConfigJNIFinalizer(boolean useVanillaJNI) {
super(useVanillaJNI);
}
@Override
protected void finalize() throws Throwable {
try {

View File

@@ -114,6 +114,17 @@ public class YogaNative {
// JNI methods that use Vanilla JNI
// YGConfig related
static native long jni_YGConfigNewJNI();
// static native void jni_YGConfigFreeJNI(long nativePointer);
static native void jni_YGConfigSetExperimentalFeatureEnabledJNI(long nativePointer, int feature, boolean enabled);
static native void jni_YGConfigSetUseWebDefaultsJNI(long nativePointer, boolean useWebDefaults);
static native void jni_YGConfigSetPrintTreeFlagJNI(long nativePointer, boolean enable);
static native void jni_YGConfigSetPointScaleFactorJNI(long nativePointer, float pixelsInPoint);
static native void jni_YGConfigSetUseLegacyStretchBehaviourJNI(long nativePointer, boolean useLegacyStretchBehaviour);
static native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI(long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
// static native void jni_YGConfigSetLoggerJNI(long nativePointer, Object logger);
static native void jni_YGNodeFreeJNI(long nativePointer);
static native void jni_YGNodeResetJNI(long nativePointer);
static native void jni_YGNodeInsertChildJNI(long nativePointer, long childPointer, int index);

View File

@@ -14,6 +14,78 @@ static inline YGNodeRef _jlong2YGNodeRef(jlong addr) {
return reinterpret_cast<YGNodeRef>(static_cast<intptr_t>(addr));
}
static inline YGConfigRef _jlong2YGConfigRef(jlong addr) {
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
}
static jlong jni_YGConfigNewJNI(JNIEnv* env, jobject obj) {
return reinterpret_cast<jlong>(YGConfigNew());
}
// void jni_YGConfigFreeJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
// const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
// // unique_ptr will destruct the underlying global_ref, if present.
// auto context = std::unique_ptr<global_ref<JYogaLogger>>{
// static_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config))};
// YGConfigFree(config);
// }
static void jni_YGConfigSetExperimentalFeatureEnabledJNI(
JNIEnv* env,
jobject obj,
jlong nativePointer,
jint feature,
jboolean enabled) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetExperimentalFeatureEnabled(
config, static_cast<YGExperimentalFeature>(feature), enabled);
}
static void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI(
JNIEnv* env,
jobject obj,
jlong nativePointer,
jboolean enabled) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(config, enabled);
}
static void jni_YGConfigSetUseWebDefaultsJNI(
JNIEnv* env,
jobject obj,
jlong nativePointer,
jboolean useWebDefaults) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetUseWebDefaults(config, useWebDefaults);
}
static void jni_YGConfigSetPrintTreeFlagJNI(
JNIEnv* env,
jobject obj,
jlong nativePointer,
jboolean enable) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetPrintTreeFlag(config, enable);
}
static void jni_YGConfigSetPointScaleFactorJNI(
JNIEnv* env,
jobject obj,
jlong nativePointer,
jfloat pixelsInPoint) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetPointScaleFactor(config, pixelsInPoint);
}
static void jni_YGConfigSetUseLegacyStretchBehaviourJNI(
JNIEnv* env,
jobject obj,
jlong nativePointer,
jboolean useLegacyStretchBehaviour) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
}
static void jni_YGNodeFreeJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
if (nativePointer == 0) {
return;
@@ -347,6 +419,27 @@ void registerNativeMethods(
}
static JNINativeMethod methods[] = {
{"jni_YGConfigNewJNI", "()J", (void*) jni_YGConfigNewJNI},
// {"jni_YGConfigFreeJNI", "(J)V", (void*) jni_YGConfigFreeJNI},
{"jni_YGConfigSetExperimentalFeatureEnabledJNI",
"(JIZ)V",
(void*) jni_YGConfigSetExperimentalFeatureEnabledJNI},
{"jni_YGConfigSetUseWebDefaultsJNI",
"(JZ)V",
(void*) jni_YGConfigSetUseWebDefaultsJNI},
{"jni_YGConfigSetPrintTreeFlagJNI",
"(JZ)V",
(void*) jni_YGConfigSetPrintTreeFlagJNI},
{"jni_YGConfigSetPointScaleFactorJNI",
"(JF)V",
(void*) jni_YGConfigSetPointScaleFactorJNI},
{"jni_YGConfigSetUseLegacyStretchBehaviourJNI",
"(JZ)V",
(void*) jni_YGConfigSetUseLegacyStretchBehaviourJNI},
{"jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI",
"(JZ)V",
(void*) jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI},
// {"jni_YGConfigSetLoggerJNI", "(JO)V", (void*) jni_YGConfigSetLoggerJNI},
{"jni_YGNodeFreeJNI", "(J)V", (void*) jni_YGNodeFreeJNI},
{"jni_YGNodeResetJNI", "(J)V", (void*) jni_YGNodeResetJNI},
{"jni_YGNodeInsertChildJNI", "(JJI)V", (void*) jni_YGNodeInsertChildJNI},