Commit Graph

678 Commits

Author SHA1 Message Date
Emil Sjolander
46823878a5 BREAKING - Make first parameter of measure and print functions CSSNodeRef instead of just context
Summary: To perform some JNI optimizations for java we need a reference to the node in the measure function. This updates the API to provide the whole node as input instead of just the context.

Reviewed By: javache

Differential Revision: D4081544

fbshipit-source-id: d49679025cea027cf7b8482898de0a01fe0f9d40
2016-10-27 10:52:57 -07:00
Emil Sjolander
b59ce09109 BREAKING - Change measure() api to remove need for MeasureOutput allocation
Summary: This is an API breaking change done to allow us to avoid an allocation during measurement. Instead we do the same trick as is done when passing measure results to C, we path them into a long.

Reviewed By: splhack

Differential Revision: D4081037

fbshipit-source-id: 28adbcdd160cbd3f59a0fdd4b9f1200ae18678f1
2016-10-27 10:52:57 -07:00
Emil Sjolander
c34299edc9 Reset java state in jni reset method
Summary: This state was never reset when we switched to doing reset in C instead of re-allocating.

Differential Revision: D4081049

fbshipit-source-id: 0b9ad70339ad906ad5219ad2679329cfe2fd7abc
2016-10-26 07:37:47 -07:00
Kazuki Sakamoto
1ba81d9ec7 Prevent GC and avoid new
Summary:
- Prevent the GC from collecting MeasureInternal in order to call managed MeasureFunction properly from unmanaged
  - TestMeasureFuncWithDestructor will fail without the fix
- Avoid new as C implementation

Reviewed By: emilsjolander

Differential Revision: D4080765

fbshipit-source-id: d58fa18f6f74012aeda5dd15dfa7ceb0b64584d0
2016-10-26 06:52:41 -07:00
Emil Sjolander
d6d817c142 Dont go down through JNI to figure out that no margin/padding/border/position was set
Summary: Many layout systems query the padding after calculation to as it is needs to be propagated to the underlying view system on the platform. However most nodes have no padding set on them so going 4-6 times through JNI layer to figure this out is a waste of time.

Differential Revision: D4080909

fbshipit-source-id: 7eb1885c615191055aa21e3435c6fbc652b883ae
2016-10-26 03:07:42 -07:00
Scott Wolchok
01c2ac3369 Don't preallocate child lists
Summary: There is no reason to malloc a list of 4 child pointers for every CSS node eagerly. Instead, we malloc the list (preserving the default size of 4) when we try to put stuff in it.

Reviewed By: emilsjolander

Differential Revision: D4078012

fbshipit-source-id: 7cdcab03ec4067550a5fee5e1baea14344f3a8f9
2016-10-25 17:22:47 -07:00
Emil Sjolander
0cc1b83569 Remove nanosleep from benchmark measure and increase loop count
Summary: sleeping in the measure function was done to ensure we were not regressing in double measure calls. This was before we have CSSLayoutMeasureCacheTest though. Let's switch over benchmark to purely benchmark the algorithm and not simulate measure time.

Reviewed By: swolchok

Differential Revision: D4078186

fbshipit-source-id: e1c16806b3c8714e223e1cfcb6c43846f8f6bbb2
2016-10-25 16:23:04 -07:00
Lukas Wöhrl
c8d77b2aae Remove children from the end to prevent copying over
Summary:
This PR leads to removing the children from the end. [So we don't have the overhead of copying them to the front](dcaef7ecb0/CSSLayout/CSSNodeList.c (L62)).
Closes https://github.com/facebook/css-layout/pull/233

Reviewed By: emilsjolander

Differential Revision: D4075905

Pulled By: splhack

fbshipit-source-id: d8b460badb01bfc6ea647004c799395b9cab9e7c
2016-10-25 12:22:48 -07:00
Emil Sjolander
01507044b3 Suggest the compiler to inline smaller functions
Summary: Suggest the compiler inline some functions. Shows ~15% performance benefit on android compiling with gcc.

Reviewed By: gkassabli

Differential Revision: D4074580

fbshipit-source-id: 69b63fadf2011cb688af58f09d67c2cb711a0e20
2016-10-25 10:37:45 -07:00
Kazuki Sakamoto
2168d68007 Update CSSNodeFree for C#, Java and Objective-C
Summary:
- Update CSSNodeFree to unlink parent and children for C#, Java and Objective-C bindings finalizer.
- [C#] Fix build (Fix #232)
- [C#] Add Clear API for convenience as CSSNodeFreeRecursive.
- [C#] Revise and add unit tests

Reviewed By: emilsjolander

Differential Revision: D4069655

fbshipit-source-id: 1fd764059784d7968af38b6aaf7fb6f70fdee8ee
2016-10-25 07:52:39 -07:00
Emil Sjolander
4d0e657653 Fix bug in canUseCachedMeasurement causing unneeded double measure
Summary: canUseCachedMeasurement function was not handling CSSMeasureModeAtMost correctly so a bunch of measurements that could have been reused were not. When a previous measurement used AtMost and the new one as an AtMost with a smaller constraint but still bigger than the previous computed size it should be OK to re-use the previously computed size.

Reviewed By: gkassabli

Differential Revision: D4071621

fbshipit-source-id: 19d87d939051ddf8ee2e1c6e60efee22d173bbb9
2016-10-25 07:37:59 -07:00
Kazuki Sakamoto
4452c7be5c Remove no longer needed Spacing.cs
Summary: - Remove no longer needed Spacing.cs

Reviewed By: emilsjolander

Differential Revision: D4073539

fbshipit-source-id: 916cf85119c6bac3d516de5396ea3ba7b0af1475
2016-10-25 07:08:00 -07:00
Emil Sjolander
15f5c4cea5 Reduce duplicate function calls
Summary: Remove duplicate functions calls. Using instruments I could see a 5% perf increase from this change.

Reviewed By: gkassabli

Differential Revision: D4068140

fbshipit-source-id: 91261afb73e1c5e23c2cfc84df6ecc5c844a4e78
2016-10-24 12:37:49 -07:00
Emil Sjolander
97fef59f96 Dont hold strong reference to java objects creating a cycle
Summary: Use weak reference to avoid cycle

Reviewed By: splhack

Differential Revision: D4064773

fbshipit-source-id: 4088fef5e088a8415747898ef17851e21ada5180
2016-10-24 12:37:49 -07:00
Emil Sjolander
e9b9973cae Dont create a spacing object for returning margin, padding, border, and position
Summary: The current implementation was made out of simplicity and to keep the same API as before. Now that the java version of csslayout is deprecated it is time to change the API to make the calls more efficient for the JNI version. This diff with reduce allocations as well as reduce the number of JNI calls done.

Differential Revision: D4050773

fbshipit-source-id: 3fd04c27f887a36875e455b5404a17154ac18f91
2016-10-24 10:37:51 -07:00
Emil Sjolander
69c374e74e Simplify memory model between managed and unmanaged memory
Summary: Instead of having different lifetimes for java and c memory we can can tie them together and make them much easier to manage. This also leads to automatically pooling native memory if pooling java memory.

Differential Revision: D4051454

fbshipit-source-id: 8f5d010be520b3d1c981a7f85e5e6d95773ea6c1
2016-10-24 10:37:51 -07:00
Emil Sjolander
4c57029a28 Remove flex shorthand getter because it doesnt make a lot of sense
Summary: It doesn't make sense to have a getter for the shorthand as it is the computed flexGrow and flexShrink values that you should care about.

Reviewed By: gkassabli

Differential Revision: D4064674

fbshipit-source-id: 69935b85042020b4e8c61a393c1be8f4d42a6674
2016-10-24 03:37:49 -07:00
Emil Sjolander
c28429efc8 Dont override flexShrink, flexGrow, and flexBasis with shorthand flex
Summary: when setting both flex and flexGrow then flexGrow should override flex even though flex was setter after.

Reviewed By: gkassabli

Differential Revision: D4064696

fbshipit-source-id: db2d4b8e60209f0a9eed6794a167b85e453be41c
2016-10-24 03:37:48 -07:00
Emil Sjolander
ab4ce535b9 Forward gLogger output to adb on android platforms
Summary: use android/log on android platforms

Reviewed By: splhack

Differential Revision: D4064619

fbshipit-source-id: de23e72844e25106d0db756064f5699959f45ed2
2016-10-23 11:07:43 -07:00
Emil Sjolander
7fee10691c Add test to assert default values
Summary: assert default values in test

Reviewed By: splhack

Differential Revision: D4064659

fbshipit-source-id: f7bf06232ebbbaa72c0202c5d9f15dd0d8005e22
2016-10-23 10:52:40 -07:00
Kazuki Sakamoto
4d964bdbc3 Update README
Summary:
- Update README for gentest
- Fix gentest.rb for the right working dir

Reviewed By: emilsjolander

Differential Revision: D4065863

fbshipit-source-id: 5c6bd9d18779c05c1de24c06a83b148889facb6b
2016-10-23 10:37:40 -07:00
Kazuki Sakamoto
ef538a45cd Add generated tests
Summary: - Add Java and C# test code generated by gentest

Reviewed By: emilsjolander

Differential Revision: D4065904

fbshipit-source-id: c0d489f37ee0a3132185636812057dc95725d59a
2016-10-23 10:37:39 -07:00
Kazuki Sakamoto
dc5e613285 gentest for Java and C#
Summary:
- Revise scripts to generate Java and C# unittests using the same HTML fixtures as well as C for code coverage.
- Add wrap_column test workaround in gentest.js.
- Add checkDefaultValues for sanity check of the CSSLayout default values by test-template.html
- Add `align-content: flex-start;` in default div to align with CSSLayout default

    $ cd csharp/gentest
    $ ruby gentest.rb

- macOS example for C#

    $ cd csharp/tests/Facebook.CSSLayout
    $ clang -DCSS_ASSERT_FAIL_ENABLED -Wall -Wextra -dynamiclib -o libCSSLayout.dylib -g -I../../.. ../../../CSSLayout/*.c ../../CSSLayout/CSSInterop.cpp
    $ mcs -debug -t:library -r:nunit.framework.dll -out:CSSLayoutTest.dll *.cs ../../../csharp/Facebook.CSSLayout/*cs
    $ mono64 --debug nunit-console.exe CSSLayoutTest.dll

Reviewed By: emilsjolander

Differential Revision: D4053777

fbshipit-source-id: 84450208015e65baf604987bd56c6a268598b545
2016-10-23 10:37:39 -07:00
mattpodwysocki
1488f822c3 Fix C# delegate calling conventions
Summary:
When using CSS-Layout in a C# UWP project in x86, by default the MSVC compiler defaults the delegate calling convention to cdecl, while .NET assumes that all delegates are declared using stdcall.  This causes a problem when invoking such as this error:

```
Run-Time Check Failure #0 - The value of ESP was not properly saved across
a function call.  This is usually a result of calling a function declared with one
calling convention with a function pointer declared with a different calling
convention.
```

This PR changes the calling convention in the C# code to reflect cdecl by using the `UnmanagedFunctionPointer` attribute and setting the calling convention to `CallingConvention.Cdecl`.

```csharp
 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  public delegate CSSSize CSSMeasureFunc(
        IntPtr context,
        float width,
        CSSMeasureMode widthMode,
        float height,
        CSSMeasureMode heightMode);
```

I have updated all calls as well to other functions.  I
Closes https://github.com/facebook/css-layout/pull/231

Reviewed By: emilsjolander

Differential Revision: D4063437

Pulled By: splhack

fbshipit-source-id: b1069a1b9f675d2623a64a1c5f3189292a18a646
2016-10-22 09:52:42 -07:00
Michael Lee
7673de823f Clean up the vm_args override and use_cxx_libraries instead
Summary: ryandm pointed out that `use_cxx_library` is necessary for fbcode overrides. And that's also true for fbandroid now.

Reviewed By: ryandm

Differential Revision: D4053192

fbshipit-source-id: 453e77df6f31b9bf6b2d221d7def8361e2966ff2
2016-10-20 15:22:39 -07:00
Dustin Shahidehpour
26bcc1e072 Remove view.isHidden optimization from sizing/layout.
Summary:
Originally, we thought that skipping the measurement of views that were hidden would be a nice optimiatzion. Upon further review, we saw that according to Apple's `UIView` documentation:

> A hidden view disappears from its window and does not receive input events. It remains in its superview’s list of subviews, however, and participates in autoresizing as usual.

So, to keep parity with common iOS layout APIs, we are going to size and layout views, even if they are hidden.

Reviewed By: emilsjolander

Differential Revision: D4051225

fbshipit-source-id: 0794cbad293a7de83d109dad2b3983d83845d145
2016-10-20 09:37:39 -07:00
Emil Sjolander
2e090cb1c8 Fixup format file for hopefully the last time in a while and re-format code
Summary: Fixup format file for hopefully the last time in a while and re-format code

Reviewed By: gkassabli

Differential Revision: D4044545

fbshipit-source-id: 60ebb73cfdd9dbc9b5fae62ddebf37e9b1e6eecf
2016-10-20 06:22:37 -07:00
Kazuki Sakamoto
daed6f5b8a Introduce CSSLayoutSetLogger to pass the print result to C# side
Summary:
- CSSLayoutSetLogger
  - Problem: Unity or other logging system can't use printf output
  - Solution: Add CSSLogger to pass CSSNodePrint result to UnityEngine.Debug.Log or other logging system via CSSLogger function for debugging purpose

Reviewed By: emilsjolander

Differential Revision: D4027044

fbshipit-source-id: 90e2e449260888770f71fa7ea790ca9764d91c44
2016-10-19 11:08:08 -07:00
Emil Sjolander
e4ad7d3c12 Change flex basis to override main axis size
Summary: Flex basis should override height/width. Not the other way around.

Reviewed By: gkassabli

Differential Revision: D4029374

fbshipit-source-id: bc3c72879f3937a50bf8a636b547adc7b9a4f5a7
2016-10-19 06:52:43 -07:00
Emil Sjolander
fa2ffc72a4 Use typedefs from header
Summary: Use typedefs from header for print and measure functions

Reviewed By: gkassabli

Differential Revision: D4036421

fbshipit-source-id: 01f15cb840363850970e6a60e661af06fd6ec9e0
2016-10-18 10:29:22 -07:00
Emil Sjolander
d1d9326fa4 Use switch instead of ifelse chain
Summary: easier to read

Reviewed By: gkassabli

Differential Revision: D4036445

fbshipit-source-id: 2159946f53507ff3d7505795e5baa5f820cdb65c
2016-10-18 10:07:46 -07:00
Emil Sjolander
9c3970dd75 Fix flex-shrink when shrinking to zero size
Summary: Fix flex-shrink when shrinking to zero size

Reviewed By: gkassabli

Differential Revision: D4036345

fbshipit-source-id: f6848d7a316a694426f761d5e51d972bd379d90e
2016-10-18 09:22:42 -07:00
Michael Lee
6152ca46c8 Tell the java wrapper to use the fbcode java
Summary:
The flag to use in fbandroid is `-Duses_native_libraries` passed in via `vm_args`

In `fbandroid/third-party/build-tools/java/java.sh` looks for this flag to override the default java with the fbcode runtime java.

Reviewed By: ryandm

Differential Revision: D4024857

fbshipit-source-id: 0ace0ee94fea32376a24004582556fa1d7d2e222
2016-10-18 08:07:45 -07:00
Emil Sjolander
9fb1b29f14 Remove default: usage to ensure compiler can help with missing cases
Summary: If we ever add more cases to an enum the compiler would not complain if we used default.

Reviewed By: gkassabli

Differential Revision: D4036440

fbshipit-source-id: f5ef4c8afff0f353de50681ad304878f90255fef
2016-10-18 06:52:51 -07:00
Emil Sjolander
82dafa75cf Move absolute layout calculation out into seperate function
Summary: Move absolute layout calculation out into seperate function

Reviewed By: gkassabli

Differential Revision: D4028329

fbshipit-source-id: 2903f66b028063cec0a6b3037ca7cb4d6552176d
2016-10-17 12:22:49 -07:00
Emil Sjolander
eb4f1cdc96 Fix justify content + min dimension when children overflow
Summary: Fix justify content + min dimension when children overflow

Reviewed By: gkassabli

Differential Revision: D4029442

fbshipit-source-id: d28ebd269c452c3359e16ecc5749a415da6e4d75
2016-10-17 08:07:48 -07:00
Emil Sjolander
501ed57784 Only look at computed style if key was not set inline
Summary: Prefer inline style to computed style as inline style should be the source of truth and computed style may differ

Reviewed By: gkassabli

Differential Revision: D4029373

fbshipit-source-id: 39ce9d577f295c2361dc384212d7467418c63c33
2016-10-17 06:37:45 -07:00
Emil Sjolander
bfb9b926b3 Move flex basis calculation out into seperate function
Summary: Move flex basis calculation out into seperate function

Reviewed By: gkassabli

Differential Revision: D4028328

fbshipit-source-id: 6d5f3bf1321077675eaa65408a70c9dc92a675be
2016-10-17 05:37:44 -07:00
Emil Sjolander
b21efa45e6 Fix justify content + min dimension usage in root
Summary: Min dimension was not respected when calculating justify content. This diff ensures that the min dimension is taken into account when at most measure spec is used.

Reviewed By: gkassabli, lucasr

Differential Revision: D4021443

fbshipit-source-id: 00f58c6078ac3076221e1148aacc34712786deb5
2016-10-17 04:23:55 -07:00
Dustin Shahidehpour
c619c0be5a Proper fix for broken android builds.
Summary: using `IS_THIS_FBOBJC` will break the tests in the open-source repo. This fixes Facebook builds and open source builds.

Reviewed By: WaseemTheDream, mzlee

Differential Revision: D4025580

fbshipit-source-id: 8280520a63134744fd24518aa6f45423aa0ecd03
2016-10-14 17:52:48 -07:00
Dustin Shahidehpour
63d3e8f3f3 Add uikit tests to Travis.
Summary: Now that we have some tests, lets run them.

Reviewed By: emilsjolander

Differential Revision: D4023765

fbshipit-source-id: 9f2fa723dc9a33f12c0470b782d6329b432546fa
2016-10-14 16:52:47 -07:00
Michael Lee
770fa6d254 Turn off the apple_test getting pulled into end-to-end tests
Summary: Gate it with `THIS_IS_FBOBJC` for now - the better solution is gating with fb_xplat_cxx_library and fb_xplat_cxx_test

Reviewed By: dshahidehpour

Differential Revision: D4024973

fbshipit-source-id: 2ce744fd67630b39b0498d0479a034d0b05c68ed
2016-10-14 16:22:55 -07:00
Dustin Shahidehpour
eedee80f25 Add Test to make sure associated objects live/die with lifetime of UIView.
Summary: Wrote some tests to make sure the associated objects we use for layout live and die with the objects. This was worthwhile because it made me realize UIView+CSSLayout wasn't enabled to ARC. As a result, my tests were failing because they weren't explicitly deallocing nodes.

Reviewed By: rnystrom

Differential Revision: D4023324

fbshipit-source-id: 5356cf4f0522582d75f83b5eb2193d9bc8d63aee
2016-10-14 14:52:57 -07:00
Dustin Shahidehpour
0254e3e97f Don't call sizeThatFits: if measure modes are exact.
Summary: `sizeThatFits:` can be expensive, this optimizes our measuring function so that we do not call it if we know that we are going to use the exact height and width that were passed-in.

Reviewed By: rnystrom

Differential Revision: D4023715

fbshipit-source-id: dc02703b50bafd168ffab62ed98a7f6342100cc9
2016-10-14 14:52:57 -07:00
Dustin Shahidehpour
05ba3a2565 Do not measure the view if it is hidden.
Summary: If views are hidden on screen, we don't want to bother including them in layout calculations.

Reviewed By: rnystrom

Differential Revision: D4022992

fbshipit-source-id: 2e93eb911f26223f305ef7ce788f86d050b83e4a
2016-10-14 14:37:43 -07:00
Dustin Shahidehpour
89440f630f Add Testing to uikit.
Summary: I'm going to make some changes, but first, I want to get testing setup.

Reviewed By: rnystrom

Differential Revision: D4022585

fbshipit-source-id: a48516faad0bcb1a9cf5610ab21da5ee099c6f16
2016-10-14 13:37:50 -07:00
Kazuki Sakamoto
832d07902e Modify unittest
Summary:
- Disable destructor tests in Unity Editor, seems GC is flaky.
- Use current native instance counts

Reviewed By: emilsjolander

Differential Revision: D4018951

fbshipit-source-id: a57f0e1fa5a46e7de0b88235124d437d20e4082b
2016-10-14 07:08:29 -07:00
Emil Sjolander
b45a7e3737 Don't assume a node with a measure function is a leaf node
Summary: Don't assume a node with a measure function is a leaf node

Reviewed By: gkassabli

Differential Revision: D4021096

fbshipit-source-id: 7e039239b1697a0ac42dce9f4b7e252a931bad7e
2016-10-14 04:37:53 -07:00
Emil Sjolander
14009ec470 Rename C test target to match pattern of other test targets
Summary: Rename C test target to match pattern of other test targets

Reviewed By: gkassabli

Differential Revision: D4014931

fbshipit-source-id: 2b4b831d6073214e8162a1d27b7478f3665a795f
2016-10-13 11:39:35 -07:00
Georgiy Kassabli
203e3dc9b8 Compatibility with Apple TVOS
Summary: This diff adds compatibility with Apple TVOS Buck build for CSSLayout library. Warning fixes are needed to ensure correct build

Reviewed By: emilsjolander

Differential Revision: D4001901

fbshipit-source-id: f095b4ac0ba91addb28d877b411ec27ecff4aad6
2016-10-13 10:52:44 -07:00