renamed YogaNodeJNI to YogaNodeJNIBase

Summary:
Renamed class from YogaNodeJNI to YogaNodeJNIBase.
This change set is for adding experiment for layout outputs batching using a float array where we will have two separate classes which will override how layout outputs are transferred to java YogaNode object.

We needed two separate classes because having everything in one class was causing memory issues as both the individual fields for width, height etc. and float array for batching needs to be present in code.

Reviewed By: davidaurelio

Differential Revision: D14368069

fbshipit-source-id: 0e98e28c8c7a9788345ccb92b2cd0f2cd4a53525
This commit is contained in:
Sidharth Guglani
2019-03-20 07:47:01 -07:00
committed by Facebook Github Bot
parent f793ba2d6b
commit f039835249
4 changed files with 24 additions and 24 deletions

View File

@@ -10,11 +10,11 @@ import javax.annotation.Nullable;
public abstract class YogaNode {
public static YogaNode create() {
return new YogaNodeJNI();
return new YogaNodeJNIBase();
}
public static YogaNode create(YogaConfig config) {
return new YogaNodeJNI(config);
return new YogaNodeJNIBase(config);
}
public abstract void reset();

View File

@@ -13,7 +13,7 @@ import java.util.List;
import javax.annotation.Nullable;
@DoNotStrip
public class YogaNodeJNI extends YogaNode {
public class YogaNodeJNIBase extends YogaNode {
static {
SoLoader.loadLibrary("yoga");
@@ -24,8 +24,8 @@ public class YogaNodeJNI extends YogaNode {
*/
static native int jni_YGNodeGetInstanceCount();
private YogaNodeJNI mOwner;
@Nullable private List<YogaNodeJNI> mChildren;
private YogaNodeJNIBase mOwner;
@Nullable private List<YogaNodeJNIBase> mChildren;
private YogaMeasureFunction mMeasureFunction;
private YogaBaselineFunction mBaselineFunction;
private long mNativePointer;
@@ -75,7 +75,7 @@ public class YogaNodeJNI extends YogaNode {
@DoNotStrip private boolean mDoesLegacyStretchFlagAffectsLayout = false;
private native long jni_YGNodeNew();
public YogaNodeJNI() {
public YogaNodeJNIBase() {
mNativePointer = jni_YGNodeNew();
if (mNativePointer == 0) {
throw new IllegalStateException("Failed to allocate native memory");
@@ -83,7 +83,7 @@ public class YogaNodeJNI extends YogaNode {
}
private native long jni_YGNodeNewWithConfig(long configPointer);
public YogaNodeJNI(YogaConfig config) {
public YogaNodeJNIBase(YogaConfig config) {
mNativePointer = jni_YGNodeNewWithConfig(config.mNativePointer);
if (mNativePointer == 0) {
throw new IllegalStateException("Failed to allocate native memory");
@@ -144,7 +144,7 @@ public class YogaNodeJNI extends YogaNode {
return mChildren == null ? 0 : mChildren.size();
}
public YogaNodeJNI getChildAt(int i) {
public YogaNodeJNIBase getChildAt(int i) {
if (mChildren == null) {
throw new IllegalStateException("YogaNode does not have children");
}
@@ -154,7 +154,7 @@ public class YogaNodeJNI extends YogaNode {
private static native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
public void addChildAt(YogaNode c, int i) {
YogaNodeJNI child = (YogaNodeJNI) c;
YogaNodeJNIBase child = (YogaNodeJNIBase) c;
if (child.mOwner != null) {
throw new IllegalStateException("Child already has a parent, it must be removed first.");
}
@@ -187,12 +187,12 @@ public class YogaNodeJNI extends YogaNode {
}
private static native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
public YogaNodeJNI removeChildAt(int i) {
public YogaNodeJNIBase removeChildAt(int i) {
if (mChildren == null) {
throw new IllegalStateException(
"Trying to remove a child of a YogaNode that does not have children");
}
final YogaNodeJNI child = mChildren.remove(i);
final YogaNodeJNIBase child = mChildren.remove(i);
child.mOwner = null;
jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
return child;
@@ -207,14 +207,14 @@ public class YogaNodeJNI extends YogaNode {
* {@link YogaNode} is shared between two or more YogaTrees.
*/
@Nullable
public YogaNodeJNI getOwner() {
public YogaNodeJNIBase getOwner() {
return mOwner;
}
/** @deprecated Use #getOwner() instead. This will be removed in the next version. */
@Deprecated
@Nullable
public YogaNodeJNI getParent() {
public YogaNodeJNIBase getParent() {
return getOwner();
}
@@ -222,21 +222,21 @@ public class YogaNodeJNI extends YogaNode {
return mChildren == null ? -1 : mChildren.indexOf(child);
}
private static native void jni_YGNodeCalculateLayout(long nativePointer, float width, float height, long[] nativePointers, YogaNodeJNI[] nodes);
private static native void jni_YGNodeCalculateLayout(long nativePointer, float width, float height, long[] nativePointers, YogaNodeJNIBase[] nodes);
public void calculateLayout(float width, float height) {
long[] nativePointers = null;
YogaNodeJNI[] nodes = null;
YogaNodeJNIBase[] nodes = null;
ArrayList<YogaNodeJNI> n = new ArrayList<>();
ArrayList<YogaNodeJNIBase> n = new ArrayList<>();
n.add(this);
for (int i = 0; i < n.size(); ++i) {
List<YogaNodeJNI> children = n.get(i).mChildren;
List<YogaNodeJNIBase> children = n.get(i).mChildren;
if (children != null) {
n.addAll(children);
}
}
nodes = n.toArray(new YogaNodeJNI[n.size()]);
nodes = n.toArray(new YogaNodeJNIBase[n.size()]);
nativePointers = new long[nodes.length];
for (int i = 0; i < nodes.length; ++i) {
nativePointers[i] = nodes[i].mNativePointer;
@@ -268,7 +268,7 @@ public class YogaNodeJNI extends YogaNode {
private static native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
@Override
public void copyStyle(YogaNode srcNode) {
jni_YGNodeCopyStyle(mNativePointer, ((YogaNodeJNI) srcNode).mNativePointer);
jni_YGNodeCopyStyle(mNativePointer, ((YogaNodeJNIBase) srcNode).mNativePointer);
}
public void markLayoutSeen() {
@@ -748,7 +748,7 @@ public class YogaNodeJNI extends YogaNode {
* @return the nativePointer of the newNode {@linl YogaNode}
*/
@DoNotStrip
private final long replaceChild(YogaNodeJNI newNode, int childIndex) {
private final long replaceChild(YogaNodeJNIBase newNode, int childIndex) {
if (mChildren == null) {
throw new IllegalStateException("Cannot replace child. YogaNode does not have children");
}

View File

@@ -8,7 +8,7 @@
#include <yoga/YGValue.h>
struct JYogaNode : public facebook::jni::JavaClass<JYogaNode> {
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNI;";
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNIBase;";
jfloat baseline(jfloat width, jfloat height);
jlong measure(jfloat width, jint widthMode, jfloat height, jint heightMode);

View File

@@ -30,9 +30,9 @@ public class YogaNodeTest {
@Test
public void testInit() {
final int refCount = YogaNodeJNI.jni_YGNodeGetInstanceCount();
final int refCount = YogaNodeJNIBase.jni_YGNodeGetInstanceCount();
final YogaNode node = createNode();
assertEquals(refCount + 1, YogaNodeJNI.jni_YGNodeGetInstanceCount());
assertEquals(refCount + 1, YogaNodeJNIBase.jni_YGNodeGetInstanceCount());
}
@Test
@@ -253,7 +253,7 @@ public class YogaNodeTest {
root_child0_child0_child0.setFlexShrink(1);
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertFalse(((YogaNodeJNI) root).getDoesLegacyStretchFlagAffectsLayout());
assertFalse(((YogaNodeJNIBase) root).getDoesLegacyStretchFlagAffectsLayout());
}
@Test