remove useBatchingForLayoutOutputs config param and start using batching for layout outputs
Summary: Removes config param useBatchingForLayoutOutputs and now we are using batching of layout outputs as float array while passing data from c++ to java Reviewed By: davidaurelio Differential Revision: D16221483 fbshipit-source-id: 326c668d4dfd13b2cf031f98a84bfa50b1440513
This commit is contained in:
committed by
Facebook Github Bot
parent
296982a29e
commit
838fc3f019
@@ -11,7 +11,6 @@ import com.facebook.soloader.SoLoader;
|
|||||||
public class YogaConfig {
|
public class YogaConfig {
|
||||||
|
|
||||||
public static int SPACING_TYPE = 1;
|
public static int SPACING_TYPE = 1;
|
||||||
public static boolean useBatchingForLayoutOutputs = false;
|
|
||||||
|
|
||||||
long mNativePointer;
|
long mNativePointer;
|
||||||
private YogaLogger mLogger;
|
private YogaLogger mLogger;
|
||||||
|
@@ -28,8 +28,8 @@ public class YogaNative {
|
|||||||
|
|
||||||
|
|
||||||
// YGNode related
|
// YGNode related
|
||||||
static native long jni_YGNodeNew(boolean useBatchingForLayoutOutputs);
|
static native long jni_YGNodeNew();
|
||||||
static native long jni_YGNodeNewWithConfig(long configPointer, boolean useBatchingForLayoutOutputs);
|
static native long jni_YGNodeNewWithConfig(long configPointer);
|
||||||
static native void jni_YGNodeFree(long nativePointer);
|
static native void jni_YGNodeFree(long nativePointer);
|
||||||
static native void jni_YGNodeReset(long nativePointer);
|
static native void jni_YGNodeReset(long nativePointer);
|
||||||
static native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
|
static native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
|
||||||
|
@@ -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 YogaConfig.useBatchingForLayoutOutputs ? new YogaNodeJNIBatching() : new YogaNodeJNI();
|
return new YogaNodeJNIBatching();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static YogaNode create(YogaConfig config) {
|
public static YogaNode create(YogaConfig config) {
|
||||||
return YogaConfig.useBatchingForLayoutOutputs ? new YogaNodeJNIBatching(config) : new YogaNodeJNI(config);
|
return new YogaNodeJNIBatching(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void reset();
|
public abstract void reset();
|
||||||
|
@@ -22,14 +22,14 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
|
|||||||
@Nullable private Object mData;
|
@Nullable private Object mData;
|
||||||
|
|
||||||
public YogaNodeJNIBase() {
|
public YogaNodeJNIBase() {
|
||||||
mNativePointer = YogaNative.jni_YGNodeNew(YogaConfig.useBatchingForLayoutOutputs);
|
mNativePointer = YogaNative.jni_YGNodeNew();
|
||||||
if (mNativePointer == 0) {
|
if (mNativePointer == 0) {
|
||||||
throw new IllegalStateException("Failed to allocate native memory");
|
throw new IllegalStateException("Failed to allocate native memory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public YogaNodeJNIBase(YogaConfig config) {
|
public YogaNodeJNIBase(YogaConfig config) {
|
||||||
mNativePointer = YogaNative.jni_YGNodeNewWithConfig(config.mNativePointer, YogaConfig.useBatchingForLayoutOutputs);
|
mNativePointer = YogaNative.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");
|
||||||
}
|
}
|
||||||
|
@@ -73,8 +73,6 @@ const short int LAYOUT_MARGIN_START_INDEX = 6;
|
|||||||
const short int LAYOUT_PADDING_START_INDEX = 10;
|
const short int LAYOUT_PADDING_START_INDEX = 10;
|
||||||
const short int LAYOUT_BORDER_START_INDEX = 14;
|
const short int LAYOUT_BORDER_START_INDEX = 14;
|
||||||
|
|
||||||
bool useBatchingForLayoutOutputs;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
union YGNodeContext {
|
union YGNodeContext {
|
||||||
@@ -165,142 +163,57 @@ static void YGTransferLayoutOutputsRecursive(
|
|||||||
|
|
||||||
auto edgesSet = YGNodeEdges{root};
|
auto edgesSet = YGNodeEdges{root};
|
||||||
|
|
||||||
if (useBatchingForLayoutOutputs) {
|
bool marginFieldSet = edgesSet.has(YGNodeEdges::MARGIN);
|
||||||
bool marginFieldSet = edgesSet.has(YGNodeEdges::MARGIN);
|
bool paddingFieldSet = edgesSet.has(YGNodeEdges::PADDING);
|
||||||
bool paddingFieldSet = edgesSet.has(YGNodeEdges::PADDING);
|
bool borderFieldSet = edgesSet.has(YGNodeEdges::BORDER);
|
||||||
bool borderFieldSet = edgesSet.has(YGNodeEdges::BORDER);
|
|
||||||
|
|
||||||
int fieldFlags = edgesSet.get();
|
int fieldFlags = edgesSet.get();
|
||||||
fieldFlags |= HAS_NEW_LAYOUT;
|
fieldFlags |= HAS_NEW_LAYOUT;
|
||||||
if (YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root)) {
|
if (YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root)) {
|
||||||
fieldFlags |= DOES_LEGACY_STRETCH_BEHAVIOUR;
|
fieldFlags |= DOES_LEGACY_STRETCH_BEHAVIOUR;
|
||||||
}
|
|
||||||
|
|
||||||
const int arrSize = 6 + (marginFieldSet ? 4 : 0) +
|
|
||||||
(paddingFieldSet ? 4 : 0) + (borderFieldSet ? 4 : 0);
|
|
||||||
float arr[18];
|
|
||||||
arr[LAYOUT_EDGE_SET_FLAG_INDEX] = fieldFlags;
|
|
||||||
arr[LAYOUT_WIDTH_INDEX] = YGNodeLayoutGetWidth(root);
|
|
||||||
arr[LAYOUT_HEIGHT_INDEX] = YGNodeLayoutGetHeight(root);
|
|
||||||
arr[LAYOUT_LEFT_INDEX] = YGNodeLayoutGetLeft(root);
|
|
||||||
arr[LAYOUT_TOP_INDEX] = YGNodeLayoutGetTop(root);
|
|
||||||
arr[LAYOUT_DIRECTION_INDEX] =
|
|
||||||
static_cast<jint>(YGNodeLayoutGetDirection(root));
|
|
||||||
if (marginFieldSet) {
|
|
||||||
arr[LAYOUT_MARGIN_START_INDEX] = YGNodeLayoutGetMargin(root, YGEdgeLeft);
|
|
||||||
arr[LAYOUT_MARGIN_START_INDEX + 1] =
|
|
||||||
YGNodeLayoutGetMargin(root, YGEdgeTop);
|
|
||||||
arr[LAYOUT_MARGIN_START_INDEX + 2] =
|
|
||||||
YGNodeLayoutGetMargin(root, YGEdgeRight);
|
|
||||||
arr[LAYOUT_MARGIN_START_INDEX + 3] =
|
|
||||||
YGNodeLayoutGetMargin(root, YGEdgeBottom);
|
|
||||||
}
|
|
||||||
if (paddingFieldSet) {
|
|
||||||
int paddingStartIndex =
|
|
||||||
LAYOUT_PADDING_START_INDEX - (marginFieldSet ? 0 : 4);
|
|
||||||
arr[paddingStartIndex] = YGNodeLayoutGetPadding(root, YGEdgeLeft);
|
|
||||||
arr[paddingStartIndex + 1] = YGNodeLayoutGetPadding(root, YGEdgeTop);
|
|
||||||
arr[paddingStartIndex + 2] = YGNodeLayoutGetPadding(root, YGEdgeRight);
|
|
||||||
arr[paddingStartIndex + 3] = YGNodeLayoutGetPadding(root, YGEdgeBottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (borderFieldSet) {
|
|
||||||
int borderStartIndex = LAYOUT_BORDER_START_INDEX -
|
|
||||||
(marginFieldSet ? 0 : 4) - (paddingFieldSet ? 0 : 4);
|
|
||||||
arr[borderStartIndex] = YGNodeLayoutGetBorder(root, YGEdgeLeft);
|
|
||||||
arr[borderStartIndex + 1] = YGNodeLayoutGetBorder(root, YGEdgeTop);
|
|
||||||
arr[borderStartIndex + 2] = YGNodeLayoutGetBorder(root, YGEdgeRight);
|
|
||||||
arr[borderStartIndex + 3] = YGNodeLayoutGetBorder(root, YGEdgeBottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
static auto arrField = obj->getClass()->getField<jfloatArray>("arr");
|
|
||||||
local_ref<jfloatArray> arrFinal = make_float_array(arrSize);
|
|
||||||
arrFinal->setRegion(0, arrSize, arr);
|
|
||||||
obj->setFieldValue<jfloatArray>(arrField, arrFinal.get());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
|
|
||||||
static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
|
|
||||||
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
|
|
||||||
static auto topField = obj->getClass()->getField<jfloat>("mTop");
|
|
||||||
|
|
||||||
static auto marginLeftField =
|
|
||||||
obj->getClass()->getField<jfloat>("mMarginLeft");
|
|
||||||
static auto marginTopField =
|
|
||||||
obj->getClass()->getField<jfloat>("mMarginTop");
|
|
||||||
static auto marginRightField =
|
|
||||||
obj->getClass()->getField<jfloat>("mMarginRight");
|
|
||||||
static auto marginBottomField =
|
|
||||||
obj->getClass()->getField<jfloat>("mMarginBottom");
|
|
||||||
|
|
||||||
static auto paddingLeftField =
|
|
||||||
obj->getClass()->getField<jfloat>("mPaddingLeft");
|
|
||||||
static auto paddingTopField =
|
|
||||||
obj->getClass()->getField<jfloat>("mPaddingTop");
|
|
||||||
static auto paddingRightField =
|
|
||||||
obj->getClass()->getField<jfloat>("mPaddingRight");
|
|
||||||
static auto paddingBottomField =
|
|
||||||
obj->getClass()->getField<jfloat>("mPaddingBottom");
|
|
||||||
|
|
||||||
static auto borderLeftField =
|
|
||||||
obj->getClass()->getField<jfloat>("mBorderLeft");
|
|
||||||
static auto borderTopField =
|
|
||||||
obj->getClass()->getField<jfloat>("mBorderTop");
|
|
||||||
static auto borderRightField =
|
|
||||||
obj->getClass()->getField<jfloat>("mBorderRight");
|
|
||||||
static auto borderBottomField =
|
|
||||||
obj->getClass()->getField<jfloat>("mBorderBottom");
|
|
||||||
|
|
||||||
static auto hasNewLayoutField =
|
|
||||||
obj->getClass()->getField<jboolean>("mHasNewLayout");
|
|
||||||
static auto doesLegacyStretchBehaviour =
|
|
||||||
obj->getClass()->getField<jboolean>(
|
|
||||||
"mDoesLegacyStretchFlagAffectsLayout");
|
|
||||||
|
|
||||||
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
|
|
||||||
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
|
|
||||||
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
|
|
||||||
obj->setFieldValue(topField, YGNodeLayoutGetTop(root));
|
|
||||||
obj->setFieldValue<jboolean>(
|
|
||||||
doesLegacyStretchBehaviour,
|
|
||||||
YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root));
|
|
||||||
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
|
|
||||||
YGTransferLayoutDirection(root, obj);
|
|
||||||
|
|
||||||
if (edgesSet.has(YGNodeEdges::MARGIN)) {
|
|
||||||
obj->setFieldValue(
|
|
||||||
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
|
||||||
obj->setFieldValue(
|
|
||||||
marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
|
|
||||||
obj->setFieldValue(
|
|
||||||
marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
|
||||||
obj->setFieldValue(
|
|
||||||
marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (edgesSet.has(YGNodeEdges::PADDING)) {
|
|
||||||
obj->setFieldValue(
|
|
||||||
paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
|
|
||||||
obj->setFieldValue(
|
|
||||||
paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
|
|
||||||
obj->setFieldValue(
|
|
||||||
paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
|
|
||||||
obj->setFieldValue(
|
|
||||||
paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (edgesSet.has(YGNodeEdges::BORDER)) {
|
|
||||||
obj->setFieldValue(
|
|
||||||
borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
|
|
||||||
obj->setFieldValue(
|
|
||||||
borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
|
|
||||||
obj->setFieldValue(
|
|
||||||
borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
|
|
||||||
obj->setFieldValue(
|
|
||||||
borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int arrSize = 6 + (marginFieldSet ? 4 : 0) + (paddingFieldSet ? 4 : 0) +
|
||||||
|
(borderFieldSet ? 4 : 0);
|
||||||
|
float arr[18];
|
||||||
|
arr[LAYOUT_EDGE_SET_FLAG_INDEX] = fieldFlags;
|
||||||
|
arr[LAYOUT_WIDTH_INDEX] = YGNodeLayoutGetWidth(root);
|
||||||
|
arr[LAYOUT_HEIGHT_INDEX] = YGNodeLayoutGetHeight(root);
|
||||||
|
arr[LAYOUT_LEFT_INDEX] = YGNodeLayoutGetLeft(root);
|
||||||
|
arr[LAYOUT_TOP_INDEX] = YGNodeLayoutGetTop(root);
|
||||||
|
arr[LAYOUT_DIRECTION_INDEX] =
|
||||||
|
static_cast<jint>(YGNodeLayoutGetDirection(root));
|
||||||
|
if (marginFieldSet) {
|
||||||
|
arr[LAYOUT_MARGIN_START_INDEX] = YGNodeLayoutGetMargin(root, YGEdgeLeft);
|
||||||
|
arr[LAYOUT_MARGIN_START_INDEX + 1] = YGNodeLayoutGetMargin(root, YGEdgeTop);
|
||||||
|
arr[LAYOUT_MARGIN_START_INDEX + 2] =
|
||||||
|
YGNodeLayoutGetMargin(root, YGEdgeRight);
|
||||||
|
arr[LAYOUT_MARGIN_START_INDEX + 3] =
|
||||||
|
YGNodeLayoutGetMargin(root, YGEdgeBottom);
|
||||||
|
}
|
||||||
|
if (paddingFieldSet) {
|
||||||
|
int paddingStartIndex =
|
||||||
|
LAYOUT_PADDING_START_INDEX - (marginFieldSet ? 0 : 4);
|
||||||
|
arr[paddingStartIndex] = YGNodeLayoutGetPadding(root, YGEdgeLeft);
|
||||||
|
arr[paddingStartIndex + 1] = YGNodeLayoutGetPadding(root, YGEdgeTop);
|
||||||
|
arr[paddingStartIndex + 2] = YGNodeLayoutGetPadding(root, YGEdgeRight);
|
||||||
|
arr[paddingStartIndex + 3] = YGNodeLayoutGetPadding(root, YGEdgeBottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (borderFieldSet) {
|
||||||
|
int borderStartIndex = LAYOUT_BORDER_START_INDEX -
|
||||||
|
(marginFieldSet ? 0 : 4) - (paddingFieldSet ? 0 : 4);
|
||||||
|
arr[borderStartIndex] = YGNodeLayoutGetBorder(root, YGEdgeLeft);
|
||||||
|
arr[borderStartIndex + 1] = YGNodeLayoutGetBorder(root, YGEdgeTop);
|
||||||
|
arr[borderStartIndex + 2] = YGNodeLayoutGetBorder(root, YGEdgeRight);
|
||||||
|
arr[borderStartIndex + 3] = YGNodeLayoutGetBorder(root, YGEdgeBottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
static auto arrField = obj->getClass()->getField<jfloatArray>("arr");
|
||||||
|
local_ref<jfloatArray> arrFinal = make_float_array(arrSize);
|
||||||
|
arrFinal->setRegion(0, arrSize, arr);
|
||||||
|
obj->setFieldValue<jfloatArray>(arrField, arrFinal.get());
|
||||||
|
|
||||||
root->setHasNewLayout(false);
|
root->setHasNewLayout(false);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
||||||
@@ -410,21 +323,16 @@ static int YGJNILogFunc(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
jlong jni_YGNodeNew(alias_ref<jobject> thiz, jboolean useBatching) {
|
jlong jni_YGNodeNew(alias_ref<jobject> thiz) {
|
||||||
const YGNodeRef node = YGNodeNew();
|
const YGNodeRef node = YGNodeNew();
|
||||||
node->setContext(YGNodeContext{}.asVoidPtr);
|
node->setContext(YGNodeContext{}.asVoidPtr);
|
||||||
node->setPrintFunc(YGPrint);
|
node->setPrintFunc(YGPrint);
|
||||||
useBatchingForLayoutOutputs = useBatching;
|
|
||||||
return reinterpret_cast<jlong>(node);
|
return reinterpret_cast<jlong>(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
jlong jni_YGNodeNewWithConfig(
|
jlong jni_YGNodeNewWithConfig(alias_ref<jclass>, jlong configPointer) {
|
||||||
alias_ref<jclass>,
|
|
||||||
jlong configPointer,
|
|
||||||
jboolean useBatching) {
|
|
||||||
const YGNodeRef node = YGNodeNewWithConfig(_jlong2YGConfigRef(configPointer));
|
const YGNodeRef node = YGNodeNewWithConfig(_jlong2YGConfigRef(configPointer));
|
||||||
node->setContext(YGNodeContext{}.asVoidPtr);
|
node->setContext(YGNodeContext{}.asVoidPtr);
|
||||||
useBatchingForLayoutOutputs = useBatching;
|
|
||||||
return reinterpret_cast<jlong>(node);
|
return reinterpret_cast<jlong>(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user