Add YogaNodeProperties implementation based on ByteBuffer

Summary:
@public
Adds an implementation of `YogaNodeProperties` that accesses style and layout properties using a `ByteBuffer` rather than JNI calls.
We hope for a speed improvement.

This needs further cleanup after experimenting, e.g. to codegen the offsets.

Reviewed By: pasqualeanatriello

Differential Revision: D8911723

fbshipit-source-id: 3c24b57eb545155878896ebb5d64d4553eb6bedc
This commit is contained in:
David Aurelio
2018-07-30 09:30:51 -07:00
committed by Facebook Github Bot
parent b1821ab4cd
commit 3499e2e0ef
29 changed files with 2034 additions and 979 deletions

View File

@@ -9,27 +9,37 @@
package com.facebook.yoga;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class YGFlexDirectionTest {
@Parameterized.Parameters(name = "{0}")
public static Iterable<TestParametrization.NodeFactory> nodeFactories() {
return TestParametrization.nodeFactories();
}
@Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory;
@Test
public void test_flex_direction_column_no_height() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setWidth(100f);
final YogaNode root_child0 = new YogaNode(config);
final YogaNode root_child0 = createNode(config);
root_child0.setHeight(10f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
final YogaNode root_child1 = createNode(config);
root_child1.setHeight(10f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = new YogaNode(config);
final YogaNode root_child2 = createNode(config);
root_child2.setHeight(10f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
@@ -83,19 +93,19 @@ public class YGFlexDirectionTest {
public void test_flex_direction_row_no_width() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode(config);
final YogaNode root_child0 = createNode(config);
root_child0.setWidth(10f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
final YogaNode root_child1 = createNode(config);
root_child1.setWidth(10f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = new YogaNode(config);
final YogaNode root_child2 = createNode(config);
root_child2.setWidth(10f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
@@ -149,19 +159,19 @@ public class YGFlexDirectionTest {
public void test_flex_direction_column() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode(config);
final YogaNode root_child0 = createNode(config);
root_child0.setHeight(10f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
final YogaNode root_child1 = createNode(config);
root_child1.setHeight(10f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = new YogaNode(config);
final YogaNode root_child2 = createNode(config);
root_child2.setHeight(10f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
@@ -215,20 +225,20 @@ public class YGFlexDirectionTest {
public void test_flex_direction_row() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode(config);
final YogaNode root_child0 = createNode(config);
root_child0.setWidth(10f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
final YogaNode root_child1 = createNode(config);
root_child1.setWidth(10f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = new YogaNode(config);
final YogaNode root_child2 = createNode(config);
root_child2.setWidth(10f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
@@ -282,20 +292,20 @@ public class YGFlexDirectionTest {
public void test_flex_direction_column_reverse() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.COLUMN_REVERSE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode(config);
final YogaNode root_child0 = createNode(config);
root_child0.setHeight(10f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
final YogaNode root_child1 = createNode(config);
root_child1.setHeight(10f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = new YogaNode(config);
final YogaNode root_child2 = createNode(config);
root_child2.setHeight(10f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
@@ -349,20 +359,20 @@ public class YGFlexDirectionTest {
public void test_flex_direction_row_reverse() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW_REVERSE);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode(config);
final YogaNode root_child0 = createNode(config);
root_child0.setWidth(10f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
final YogaNode root_child1 = createNode(config);
root_child1.setWidth(10f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = new YogaNode(config);
final YogaNode root_child2 = createNode(config);
root_child2.setWidth(10f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
@@ -412,4 +422,7 @@ public class YGFlexDirectionTest {
assertEquals(100f, root_child2.getLayoutHeight(), 0.0f);
}
private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config);
}
}