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,29 +9,39 @@
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 YGJustifyContentTest {
@Parameterized.Parameters(name = "{0}")
public static Iterable<TestParametrization.NodeFactory> nodeFactories() {
return TestParametrization.nodeFactories();
}
@Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory;
@Test
public void test_justify_content_row_flex_start() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -85,21 +95,21 @@ public class YGJustifyContentTest {
public void test_justify_content_row_flex_end() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setJustifyContent(YogaJustify.FLEX_END);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -153,21 +163,21 @@ public class YGJustifyContentTest {
public void test_justify_content_row_center() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setJustifyContent(YogaJustify.CENTER);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -221,21 +231,21 @@ public class YGJustifyContentTest {
public void test_justify_content_row_space_between() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setJustifyContent(YogaJustify.SPACE_BETWEEN);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -289,21 +299,21 @@ public class YGJustifyContentTest {
public void test_justify_content_row_space_around() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setJustifyContent(YogaJustify.SPACE_AROUND);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -357,19 +367,19 @@ public class YGJustifyContentTest {
public void test_justify_content_column_flex_start() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -423,20 +433,20 @@ public class YGJustifyContentTest {
public void test_justify_content_column_flex_end() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setJustifyContent(YogaJustify.FLEX_END);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -490,20 +500,20 @@ public class YGJustifyContentTest {
public void test_justify_content_column_center() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -557,20 +567,20 @@ public class YGJustifyContentTest {
public void test_justify_content_column_space_between() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setJustifyContent(YogaJustify.SPACE_BETWEEN);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -624,20 +634,20 @@ public class YGJustifyContentTest {
public void test_justify_content_column_space_around() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setJustifyContent(YogaJustify.SPACE_AROUND);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -691,13 +701,13 @@ public class YGJustifyContentTest {
public void test_justify_content_row_min_width_and_margin() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setJustifyContent(YogaJustify.CENTER);
root.setMargin(YogaEdge.LEFT, 100f);
root.setMinWidth(50f);
final YogaNode root_child0 = new YogaNode(config);
final YogaNode root_child0 = createNode(config);
root_child0.setWidth(20f);
root_child0.setHeight(20f);
root.addChildAt(root_child0, 0);
@@ -732,14 +742,14 @@ public class YGJustifyContentTest {
public void test_justify_content_row_max_width_and_margin() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setJustifyContent(YogaJustify.CENTER);
root.setMargin(YogaEdge.LEFT, 100f);
root.setWidth(100f);
root.setMaxWidth(80f);
final YogaNode root_child0 = new YogaNode(config);
final YogaNode root_child0 = createNode(config);
root_child0.setWidth(20f);
root_child0.setHeight(20f);
root.addChildAt(root_child0, 0);
@@ -774,12 +784,12 @@ public class YGJustifyContentTest {
public void test_justify_content_column_min_height_and_margin() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setMargin(YogaEdge.TOP, 100f);
root.setMinHeight(50f);
final YogaNode root_child0 = new YogaNode(config);
final YogaNode root_child0 = createNode(config);
root_child0.setWidth(20f);
root_child0.setHeight(20f);
root.addChildAt(root_child0, 0);
@@ -814,13 +824,13 @@ public class YGJustifyContentTest {
public void test_justify_content_colunn_max_height_and_margin() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setMargin(YogaEdge.TOP, 100f);
root.setHeight(100f);
root.setMaxHeight(80f);
final YogaNode root_child0 = new YogaNode(config);
final YogaNode root_child0 = createNode(config);
root_child0.setWidth(20f);
root_child0.setHeight(20f);
root.addChildAt(root_child0, 0);
@@ -855,20 +865,20 @@ public class YGJustifyContentTest {
public void test_justify_content_column_space_evenly() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setJustifyContent(YogaJustify.SPACE_EVENLY);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -922,21 +932,21 @@ public class YGJustifyContentTest {
public void test_justify_content_row_space_evenly() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setJustifyContent(YogaJustify.SPACE_EVENLY);
root.setWidth(102f);
root.setHeight(102f);
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);
@@ -986,4 +996,7 @@ public class YGJustifyContentTest {
assertEquals(10f, root_child2.getLayoutHeight(), 0.0f);
}
private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config);
}
}