move yg node new and ygnode new with config
Summary: YGNode creation methods to vanilla JNI Reviewed By: amir-shalem Differential Revision: D17714230 fbshipit-source-id: 74e14e876ab7efc67771d92091c2a78f09072b83
This commit is contained in:
committed by
Facebook Github Bot
parent
34739ec652
commit
22a60e82b0
@@ -125,6 +125,9 @@ public class YogaNative {
|
|||||||
static native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI(long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
static native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI(long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||||
// static native void jni_YGConfigSetLoggerJNI(long nativePointer, Object logger);
|
// static native void jni_YGConfigSetLoggerJNI(long nativePointer, Object logger);
|
||||||
|
|
||||||
|
// YGNode related
|
||||||
|
static native long jni_YGNodeNewJNI();
|
||||||
|
static native long jni_YGNodeNewWithConfigJNI(long configPointer);
|
||||||
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);
|
||||||
|
@@ -5,6 +5,10 @@ public abstract class YogaNodeFactory {
|
|||||||
return new YogaNodeJNIFinalizer();
|
return new YogaNodeJNIFinalizer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static YogaNode create(boolean useVanillaJNI) {
|
||||||
|
return new YogaNodeJNIFinalizer(useVanillaJNI);
|
||||||
|
}
|
||||||
|
|
||||||
public static YogaNode create(YogaConfig config) {
|
public static YogaNode create(YogaConfig config) {
|
||||||
return new YogaNodeJNIFinalizer(config);
|
return new YogaNodeJNIFinalizer(config);
|
||||||
}
|
}
|
||||||
|
@@ -59,8 +59,12 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
|
|||||||
this(YogaNative.jni_YGNodeNew());
|
this(YogaNative.jni_YGNodeNew());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
YogaNodeJNIBase(boolean useVanillaJNI) {
|
||||||
|
this(useVanillaJNI ? YogaNative.jni_YGNodeNewJNI() : YogaNative.jni_YGNodeNew());
|
||||||
|
}
|
||||||
|
|
||||||
YogaNodeJNIBase(YogaConfig config) {
|
YogaNodeJNIBase(YogaConfig config) {
|
||||||
this(YogaNative.jni_YGNodeNewWithConfig(((YogaConfigJNIBase)config).mNativePointer));
|
this(config.useVanillaJNI() ? YogaNative.jni_YGNodeNewWithConfigJNI(((YogaConfigJNIBase)config).mNativePointer) : YogaNative.jni_YGNodeNewWithConfig(((YogaConfigJNIBase)config).mNativePointer));
|
||||||
this.useVanillaJNI = config.useVanillaJNI();
|
this.useVanillaJNI = config.useVanillaJNI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,6 +11,10 @@ public class YogaNodeJNIFinalizer extends YogaNodeJNIBase {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public YogaNodeJNIFinalizer(boolean useVanillaJNI) {
|
||||||
|
super(useVanillaJNI);
|
||||||
|
}
|
||||||
|
|
||||||
public YogaNodeJNIFinalizer(YogaConfig config) {
|
public YogaNodeJNIFinalizer(YogaConfig config) {
|
||||||
super(config);
|
super(config);
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "YGJTypesVanilla.h"
|
#include "YGJTypesVanilla.h"
|
||||||
#include <yoga/log.h>
|
#include <yoga/log.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace facebook::yoga::vanillajni;
|
using namespace facebook::yoga::vanillajni;
|
||||||
using facebook::yoga::detail::Log;
|
using facebook::yoga::detail::Log;
|
||||||
@@ -90,6 +91,18 @@ static void jni_YGConfigSetPointScaleFactorJNI(
|
|||||||
YGConfigSetPointScaleFactor(config, pixelsInPoint);
|
YGConfigSetPointScaleFactor(config, pixelsInPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void YGPrint(YGNodeRef node, void* layoutContext) {
|
||||||
|
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||||
|
// TODO cout << obj.get()->toString() << endl;
|
||||||
|
} else {
|
||||||
|
Log::log(
|
||||||
|
node,
|
||||||
|
YGLogLevelError,
|
||||||
|
nullptr,
|
||||||
|
"Java YGNode was GCed during layout calculation\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void jni_YGConfigSetUseLegacyStretchBehaviourJNI(
|
static void jni_YGConfigSetUseLegacyStretchBehaviourJNI(
|
||||||
JNIEnv* env,
|
JNIEnv* env,
|
||||||
jobject obj,
|
jobject obj,
|
||||||
@@ -99,6 +112,22 @@ static void jni_YGConfigSetUseLegacyStretchBehaviourJNI(
|
|||||||
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
|
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static jlong jni_YGNodeNewJNI(JNIEnv* env, jobject obj) {
|
||||||
|
const YGNodeRef node = YGNodeNew();
|
||||||
|
node->setContext(YGNodeContext{}.asVoidPtr);
|
||||||
|
node->setPrintFunc(YGPrint);
|
||||||
|
return reinterpret_cast<jlong>(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
static jlong jni_YGNodeNewWithConfigJNI(
|
||||||
|
JNIEnv* env,
|
||||||
|
jobject obj,
|
||||||
|
jlong configPointer) {
|
||||||
|
const YGNodeRef node = YGNodeNewWithConfig(_jlong2YGConfigRef(configPointer));
|
||||||
|
node->setContext(YGNodeContext{}.asVoidPtr);
|
||||||
|
return reinterpret_cast<jlong>(node);
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -558,6 +587,8 @@ static JNINativeMethod methods[] = {
|
|||||||
"(JZ)V",
|
"(JZ)V",
|
||||||
(void*) jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI},
|
(void*) jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI},
|
||||||
// {"jni_YGConfigSetLoggerJNI", "(JO)V", (void*) jni_YGConfigSetLoggerJNI},
|
// {"jni_YGConfigSetLoggerJNI", "(JO)V", (void*) jni_YGConfigSetLoggerJNI},
|
||||||
|
{"jni_YGNodeNewJNI", "()J", (void*) jni_YGNodeNewJNI},
|
||||||
|
{"jni_YGNodeNewWithConfigJNI", "(J)J", (void*) jni_YGNodeNewWithConfigJNI},
|
||||||
{"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