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:
committed by
Facebook Github Bot
parent
f793ba2d6b
commit
f039835249
@@ -10,11 +10,11 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
public abstract class YogaNode {
|
public abstract class YogaNode {
|
||||||
public static YogaNode create() {
|
public static YogaNode create() {
|
||||||
return new YogaNodeJNI();
|
return new YogaNodeJNIBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static YogaNode create(YogaConfig config) {
|
public static YogaNode create(YogaConfig config) {
|
||||||
return new YogaNodeJNI(config);
|
return new YogaNodeJNIBase(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void reset();
|
public abstract void reset();
|
||||||
|
@@ -13,7 +13,7 @@ import java.util.List;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
public class YogaNodeJNI extends YogaNode {
|
public class YogaNodeJNIBase extends YogaNode {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
SoLoader.loadLibrary("yoga");
|
SoLoader.loadLibrary("yoga");
|
||||||
@@ -24,8 +24,8 @@ public class YogaNodeJNI extends YogaNode {
|
|||||||
*/
|
*/
|
||||||
static native int jni_YGNodeGetInstanceCount();
|
static native int jni_YGNodeGetInstanceCount();
|
||||||
|
|
||||||
private YogaNodeJNI mOwner;
|
private YogaNodeJNIBase mOwner;
|
||||||
@Nullable private List<YogaNodeJNI> mChildren;
|
@Nullable private List<YogaNodeJNIBase> mChildren;
|
||||||
private YogaMeasureFunction mMeasureFunction;
|
private YogaMeasureFunction mMeasureFunction;
|
||||||
private YogaBaselineFunction mBaselineFunction;
|
private YogaBaselineFunction mBaselineFunction;
|
||||||
private long mNativePointer;
|
private long mNativePointer;
|
||||||
@@ -75,7 +75,7 @@ public class YogaNodeJNI extends YogaNode {
|
|||||||
@DoNotStrip private boolean mDoesLegacyStretchFlagAffectsLayout = false;
|
@DoNotStrip private boolean mDoesLegacyStretchFlagAffectsLayout = false;
|
||||||
|
|
||||||
private native long jni_YGNodeNew();
|
private native long jni_YGNodeNew();
|
||||||
public YogaNodeJNI() {
|
public YogaNodeJNIBase() {
|
||||||
mNativePointer = jni_YGNodeNew();
|
mNativePointer = jni_YGNodeNew();
|
||||||
if (mNativePointer == 0) {
|
if (mNativePointer == 0) {
|
||||||
throw new IllegalStateException("Failed to allocate native memory");
|
throw new IllegalStateException("Failed to allocate native memory");
|
||||||
@@ -83,7 +83,7 @@ public class YogaNodeJNI extends YogaNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private native long jni_YGNodeNewWithConfig(long configPointer);
|
private native long jni_YGNodeNewWithConfig(long configPointer);
|
||||||
public YogaNodeJNI(YogaConfig config) {
|
public YogaNodeJNIBase(YogaConfig config) {
|
||||||
mNativePointer = jni_YGNodeNewWithConfig(config.mNativePointer);
|
mNativePointer = jni_YGNodeNewWithConfig(config.mNativePointer);
|
||||||
if (mNativePointer == 0) {
|
if (mNativePointer == 0) {
|
||||||
throw new IllegalStateException("Failed to allocate native memory");
|
throw new IllegalStateException("Failed to allocate native memory");
|
||||||
@@ -144,7 +144,7 @@ public class YogaNodeJNI extends YogaNode {
|
|||||||
return mChildren == null ? 0 : mChildren.size();
|
return mChildren == null ? 0 : mChildren.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public YogaNodeJNI getChildAt(int i) {
|
public YogaNodeJNIBase getChildAt(int i) {
|
||||||
if (mChildren == null) {
|
if (mChildren == null) {
|
||||||
throw new IllegalStateException("YogaNode does not have children");
|
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);
|
private static native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
|
||||||
|
|
||||||
public void addChildAt(YogaNode c, int i) {
|
public void addChildAt(YogaNode c, int i) {
|
||||||
YogaNodeJNI child = (YogaNodeJNI) c;
|
YogaNodeJNIBase child = (YogaNodeJNIBase) c;
|
||||||
if (child.mOwner != null) {
|
if (child.mOwner != null) {
|
||||||
throw new IllegalStateException("Child already has a parent, it must be removed first.");
|
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);
|
private static native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
|
||||||
public YogaNodeJNI removeChildAt(int i) {
|
public YogaNodeJNIBase removeChildAt(int i) {
|
||||||
if (mChildren == null) {
|
if (mChildren == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Trying to remove a child of a YogaNode that does not have children");
|
"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;
|
child.mOwner = null;
|
||||||
jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
|
jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
|
||||||
return child;
|
return child;
|
||||||
@@ -207,14 +207,14 @@ public class YogaNodeJNI extends YogaNode {
|
|||||||
* {@link YogaNode} is shared between two or more YogaTrees.
|
* {@link YogaNode} is shared between two or more YogaTrees.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public YogaNodeJNI getOwner() {
|
public YogaNodeJNIBase getOwner() {
|
||||||
return mOwner;
|
return mOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use #getOwner() instead. This will be removed in the next version. */
|
/** @deprecated Use #getOwner() instead. This will be removed in the next version. */
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Nullable
|
@Nullable
|
||||||
public YogaNodeJNI getParent() {
|
public YogaNodeJNIBase getParent() {
|
||||||
return getOwner();
|
return getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,21 +222,21 @@ public class YogaNodeJNI extends YogaNode {
|
|||||||
return mChildren == null ? -1 : mChildren.indexOf(child);
|
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) {
|
public void calculateLayout(float width, float height) {
|
||||||
long[] nativePointers = null;
|
long[] nativePointers = null;
|
||||||
YogaNodeJNI[] nodes = null;
|
YogaNodeJNIBase[] nodes = null;
|
||||||
|
|
||||||
ArrayList<YogaNodeJNI> n = new ArrayList<>();
|
ArrayList<YogaNodeJNIBase> n = new ArrayList<>();
|
||||||
n.add(this);
|
n.add(this);
|
||||||
for (int i = 0; i < n.size(); ++i) {
|
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) {
|
if (children != null) {
|
||||||
n.addAll(children);
|
n.addAll(children);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes = n.toArray(new YogaNodeJNI[n.size()]);
|
nodes = n.toArray(new YogaNodeJNIBase[n.size()]);
|
||||||
nativePointers = new long[nodes.length];
|
nativePointers = new long[nodes.length];
|
||||||
for (int i = 0; i < nodes.length; ++i) {
|
for (int i = 0; i < nodes.length; ++i) {
|
||||||
nativePointers[i] = nodes[i].mNativePointer;
|
nativePointers[i] = nodes[i].mNativePointer;
|
||||||
@@ -268,7 +268,7 @@ public class YogaNodeJNI extends YogaNode {
|
|||||||
private static native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
|
private static native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
|
||||||
@Override
|
@Override
|
||||||
public void copyStyle(YogaNode srcNode) {
|
public void copyStyle(YogaNode srcNode) {
|
||||||
jni_YGNodeCopyStyle(mNativePointer, ((YogaNodeJNI) srcNode).mNativePointer);
|
jni_YGNodeCopyStyle(mNativePointer, ((YogaNodeJNIBase) srcNode).mNativePointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markLayoutSeen() {
|
public void markLayoutSeen() {
|
||||||
@@ -748,7 +748,7 @@ public class YogaNodeJNI extends YogaNode {
|
|||||||
* @return the nativePointer of the newNode {@linl YogaNode}
|
* @return the nativePointer of the newNode {@linl YogaNode}
|
||||||
*/
|
*/
|
||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
private final long replaceChild(YogaNodeJNI newNode, int childIndex) {
|
private final long replaceChild(YogaNodeJNIBase newNode, int childIndex) {
|
||||||
if (mChildren == null) {
|
if (mChildren == null) {
|
||||||
throw new IllegalStateException("Cannot replace child. YogaNode does not have children");
|
throw new IllegalStateException("Cannot replace child. YogaNode does not have children");
|
||||||
}
|
}
|
@@ -8,7 +8,7 @@
|
|||||||
#include <yoga/YGValue.h>
|
#include <yoga/YGValue.h>
|
||||||
|
|
||||||
struct JYogaNode : public facebook::jni::JavaClass<JYogaNode> {
|
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);
|
jfloat baseline(jfloat width, jfloat height);
|
||||||
jlong measure(jfloat width, jint widthMode, jfloat height, jint heightMode);
|
jlong measure(jfloat width, jint widthMode, jfloat height, jint heightMode);
|
||||||
|
@@ -30,9 +30,9 @@ public class YogaNodeTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInit() {
|
public void testInit() {
|
||||||
final int refCount = YogaNodeJNI.jni_YGNodeGetInstanceCount();
|
final int refCount = YogaNodeJNIBase.jni_YGNodeGetInstanceCount();
|
||||||
final YogaNode node = createNode();
|
final YogaNode node = createNode();
|
||||||
assertEquals(refCount + 1, YogaNodeJNI.jni_YGNodeGetInstanceCount());
|
assertEquals(refCount + 1, YogaNodeJNIBase.jni_YGNodeGetInstanceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -253,7 +253,7 @@ public class YogaNodeTest {
|
|||||||
root_child0_child0_child0.setFlexShrink(1);
|
root_child0_child0_child0.setFlexShrink(1);
|
||||||
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
|
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
|
||||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
assertFalse(((YogaNodeJNI) root).getDoesLegacyStretchFlagAffectsLayout());
|
assertFalse(((YogaNodeJNIBase) root).getDoesLegacyStretchFlagAffectsLayout());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user