Skip to content

Commit

Permalink
renamed YogaNodeJNI to YogaNodeJNIBase
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SidharthGuglani-zz authored and facebook-github-bot committed Mar 20, 2019
1 parent 84feec2 commit 80743eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import javax.annotation.Nullable;

@DoNotStrip
public class YogaNodeJNI extends YogaNode {
public class YogaNodeJNIBase extends YogaNode {

static {
SoLoader.loadLibrary("yoga");
Expand All @@ -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;
Expand Down Expand Up @@ -75,15 +75,15 @@ 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");
}
}

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");
Expand Down Expand Up @@ -144,7 +144,7 @@ public int getChildCount() {
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");
}
Expand All @@ -154,7 +154,7 @@ public YogaNodeJNI getChildAt(int i) {
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.");
}
Expand Down Expand Up @@ -187,12 +187,12 @@ private void clearChildren() {
}

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;
Expand All @@ -207,36 +207,36 @@ public YogaNodeJNI removeChildAt(int i) {
* {@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();
}

public int indexOf(YogaNode 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) {
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;
Expand Down Expand Up @@ -268,7 +268,7 @@ public boolean isDirty() {
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() {
Expand Down Expand Up @@ -748,7 +748,7 @@ public void setStyleInputs(float[] styleInputsArray, int size) {
* @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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 80743eb

Please sign in to comment.