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:
committed by
Facebook Github Bot
parent
34b68cf1d2
commit
ee73f556b4
@@ -38,7 +38,5 @@ public abstract class YogaConfig {
|
|||||||
|
|
||||||
abstract long getNativePointer();
|
abstract long getNativePointer();
|
||||||
|
|
||||||
public abstract void setUseVanillaJNI(boolean useVanillaJNI);
|
|
||||||
|
|
||||||
public abstract boolean useVanillaJNI();
|
public abstract boolean useVanillaJNI();
|
||||||
}
|
}
|
||||||
|
@@ -4,4 +4,8 @@ public abstract class YogaConfigFactory {
|
|||||||
public static YogaConfig create() {
|
public static YogaConfig create() {
|
||||||
return new YogaConfigJNIFinalizer();
|
return new YogaConfigJNIFinalizer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static YogaConfig create(boolean useVanillaJNI) {
|
||||||
|
return new YogaConfigJNIFinalizer(useVanillaJNI);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,20 +23,37 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
|
|||||||
this(YogaNative.jni_YGConfigNew());
|
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) {
|
public void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled) {
|
||||||
YogaNative.jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
|
if (useVanillaJNI)
|
||||||
|
YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI(mNativePointer, feature.intValue(), enabled);
|
||||||
|
else
|
||||||
|
YogaNative.jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseWebDefaults(boolean useWebDefaults) {
|
public void setUseWebDefaults(boolean useWebDefaults) {
|
||||||
YogaNative.jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
|
if (useVanillaJNI)
|
||||||
|
YogaNative.jni_YGConfigSetUseWebDefaultsJNI(mNativePointer, useWebDefaults);
|
||||||
|
else
|
||||||
|
YogaNative.jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrintTreeFlag(boolean enable) {
|
public void setPrintTreeFlag(boolean enable) {
|
||||||
YogaNative.jni_YGConfigSetPrintTreeFlag(mNativePointer, enable);
|
if (useVanillaJNI)
|
||||||
|
YogaNative.jni_YGConfigSetPrintTreeFlagJNI(mNativePointer, enable);
|
||||||
|
else
|
||||||
|
YogaNative.jni_YGConfigSetPrintTreeFlag(mNativePointer, enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPointScaleFactor(float pixelsInPoint) {
|
public void setPointScaleFactor(float pixelsInPoint) {
|
||||||
YogaNative.jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
|
if (useVanillaJNI)
|
||||||
|
YogaNative.jni_YGConfigSetPointScaleFactorJNI(mNativePointer, pixelsInPoint);
|
||||||
|
else
|
||||||
|
YogaNative.jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +62,10 @@ 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.
|
* Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour.
|
||||||
*/
|
*/
|
||||||
public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) {
|
public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) {
|
||||||
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
if (useVanillaJNI)
|
||||||
|
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviourJNI(mNativePointer, useLegacyStretchBehaviour);
|
||||||
|
else
|
||||||
|
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,8 +75,12 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
|
|||||||
*/
|
*/
|
||||||
public void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
public void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||||
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour) {
|
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour) {
|
||||||
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
if (useVanillaJNI)
|
||||||
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI(
|
||||||
|
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||||
|
else
|
||||||
|
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||||
|
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLogger(YogaLogger logger) {
|
public void setLogger(YogaLogger logger) {
|
||||||
@@ -72,11 +96,6 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
|
|||||||
return mNativePointer;
|
return mNativePointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUseVanillaJNI(boolean useVanillaJNI) {
|
|
||||||
this.useVanillaJNI = useVanillaJNI;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean useVanillaJNI() {
|
public boolean useVanillaJNI() {
|
||||||
return this.useVanillaJNI;
|
return this.useVanillaJNI;
|
||||||
|
@@ -11,6 +11,10 @@ public class YogaConfigJNIFinalizer extends YogaConfigJNIBase {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public YogaConfigJNIFinalizer(boolean useVanillaJNI) {
|
||||||
|
super(useVanillaJNI);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
try {
|
try {
|
||||||
|
@@ -114,6 +114,17 @@ public class YogaNative {
|
|||||||
|
|
||||||
|
|
||||||
// JNI methods that use Vanilla JNI
|
// 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_YGNodeFreeJNI(long nativePointer);
|
||||||
static native void jni_YGNodeResetJNI(long nativePointer);
|
static native void jni_YGNodeResetJNI(long nativePointer);
|
||||||
static native void jni_YGNodeInsertChildJNI(long nativePointer, long childPointer, int index);
|
static native void jni_YGNodeInsertChildJNI(long nativePointer, long childPointer, int index);
|
||||||
|
@@ -14,6 +14,78 @@ static inline YGNodeRef _jlong2YGNodeRef(jlong addr) {
|
|||||||
return reinterpret_cast<YGNodeRef>(static_cast<intptr_t>(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) {
|
static void jni_YGNodeFreeJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
|
||||||
if (nativePointer == 0) {
|
if (nativePointer == 0) {
|
||||||
return;
|
return;
|
||||||
@@ -347,6 +419,27 @@ void registerNativeMethods(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod methods[] = {
|
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_YGNodeFreeJNI", "(J)V", (void*) jni_YGNodeFreeJNI},
|
||||||
{"jni_YGNodeResetJNI", "(J)V", (void*) jni_YGNodeResetJNI},
|
{"jni_YGNodeResetJNI", "(J)V", (void*) jni_YGNodeResetJNI},
|
||||||
{"jni_YGNodeInsertChildJNI", "(JJI)V", (void*) jni_YGNodeInsertChildJNI},
|
{"jni_YGNodeInsertChildJNI", "(JJI)V", (void*) jni_YGNodeInsertChildJNI},
|
||||||
|
Reference in New Issue
Block a user