Commit Graph

1840 Commits

Author SHA1 Message Date
David Aurelio
59d680f4e9 Upgrade fbjni
Summary:
Upgrades Yoga’s copy of *fbjni* to the latest version.

This will enable us

- to move from `finalize()` to `PhantomReference` to deallocate native memory, with the potential of making GC more efficient.
- to remove the internal dependency to *libfb,* allowing apps without an own dependency to ship less code

Reviewed By: passy

Differential Revision: D16220924

fbshipit-source-id: e8233fe2b5403946ff51f43cb6def558ded52fda
2019-07-17 06:57:18 -07:00
Amir Shalem
be305b5d0f Rename fbjni shared library name to the standard soname
Summary:
Before we can upgrade to latest fbjni, we need to make sure our shared libraries are named the same.

Currently when we compile libfbjni it is named as `liblib_fb_fbjni.so`, where as the regular fbjni is expected to be named as `libfbjni.so`

Reviewed By: davidaurelio

Differential Revision: D16250801

fbshipit-source-id: 9a7f0f803d7e525985b40a49edcc0e660e9025f5
2019-07-17 03:35:31 -07:00
Sidharth Guglani
d676d917e3 moved all yoga node jni batching code to YogaNodeJNIBase and removed subclasses
Summary: Removed classes YogaNodeJNI and YogaNodeJNIBatching and all the logic have been moved to base class

Reviewed By: davidaurelio

Differential Revision: D16221484

fbshipit-source-id: 830819f5bc6010291b8bc0c6d90897cea991909f
2019-07-15 11:16:38 -07:00
Sidharth Guglani
838fc3f019 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
2019-07-15 11:16:38 -07:00
David Aurelio
296982a29e Enable events in OSS
Summary:
- Events are our new approach to instrumentation, and keeping debug code out of the core library
- This has run internally at FB for some time now
- Enabling for OSS, too, to make Java tests pass

Reviewed By: SidharthGuglani

Differential Revision: D16202541

fbshipit-source-id: c13f5270f04bba59f9f0a06d9c793da92b73d4ff
2019-07-12 01:43:49 -07:00
David Aurelio
1d0668692b Make tests runnable with Buck/OSS again
Summary:
Fixes test execution for open source:

- adds hamcrest jar and dependency, as required by buck (to not throw `"Unable to locate hamcrest on the classpath. Please add as a test dependency."`)
- enables events for OSS, to make tests pass

Reviewed By: SidharthGuglani

Differential Revision: D16202542

fbshipit-source-id: a56069de162f739b3b989961b5dc00f3d37f5849
2019-07-12 01:43:48 -07:00
Sidharth Guglani
39e512f691 Add tests for measure and baseline events
Summary: Add tests for measure and baseline events , same as we had in InstrumentationTests for marker based approach

Reviewed By: davidaurelio

Differential Revision: D16074402

fbshipit-source-id: 8b11cd6468420428701fd5be5c57700cbd913d23
2019-07-10 08:50:44 -07:00
Sidharth Guglani
0f250490d4 add baseline start and baseline end events
Summary: Adds Baseline start and end events to be handled later for instrumentation

Reviewed By: davidaurelio

Differential Revision: D16048790

fbshipit-source-id: 8409dbb633168753a7bf8fab20bc6551d113ddd6
2019-07-10 08:50:43 -07:00
Sidharth Guglani
eeae39d707 move YGMarkerLayout to event based system
Summary: Using layoutPassStart and LayoutPassEnd events instead of YGMarkerLayout for instrumentation

Reviewed By: davidaurelio

Differential Revision: D16048789

fbshipit-source-id: 041a35bc2cb1b7281ca83cf9d35041b4011cfeb9
2019-07-10 08:50:42 -07:00
Sidharth Guglani
ce517689ff add tests for layoutPassStart and layoutPassEnd
Summary: Add tests for layout pass start and end , same as what we had in InstrumentationTests for marker based approach

Reviewed By: davidaurelio

Differential Revision: D16073121

fbshipit-source-id: 838f01cb2a41d2d2764ba7ce2f317147f737b287
2019-07-10 08:50:42 -07:00
Sidharth Guglani
9c82ba783f Adds typed event test data for test cases
Summary: We are now using custom TypedEventTestData for test cases as we need to copy some data passed from the yoga event system

Reviewed By: davidaurelio

Differential Revision: D16090931

fbshipit-source-id: 4d11bdbdd73b67172ad4bba4b294c71f1c24cc10
2019-07-10 08:50:41 -07:00
James Burnett
1c8e8d3aec Compile Issues with Recent GCC (#895)
Summary:
GCC 8.3.0 (and possibly all gcc 7+) identified several warnings for signed unsigned integer comparison. With `-Werror` enabled this broke compiling tests. I suspect the warning is related to google/googletest#683. This diff updates those `ASSERT_EQ` calls that attempt to compare signed and unsigned errors by specifically declaring the literals to be unsigned.

There is also an issue with Buck where it will not link to pthreads. facebook/buck#1443. Adding a `prebuilt_cxx_library` for pthread fixes that issue and the tests will compile and run.

Finally, there was a warning about a missing return after a switch in `InstrumentationTest.cpp`. I added a `return ""` as a default, but it might be better to throw something. Thoughts?
Pull Request resolved: https://github.com/facebook/yoga/pull/895

Reviewed By: davidaurelio

Differential Revision: D15393082

Pulled By: davidaurelio

fbshipit-source-id: 4f13ec2f016af39537c08fb591b188a6a0ed55ce
2019-07-04 19:08:18 -07:00
Uladzislau Paulovich
cc27d85110 Remove incorrect constexpr specifier in YGLayout (#25430)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/25430

Pull Request resolved: https://github.com/facebook/litho/pull/561

Pull Request resolved: https://github.com/facebook/yoga/pull/910

* According to C++ standard values which produce undefined behavior cannot be declared as `constexpr`.
* Expressions which evaluate to `nan, infinity, etc` are undefined behavior.

For more details you can checkout this Stackoverflow answer: https://stackoverflow.com/a/46373136

Reviewed By: davidaurelio

Differential Revision: D16055108

fbshipit-source-id: ee85ba63a714b18bfb8aa8c0770652e184454f74
2019-07-01 08:52:10 -07:00
David Aurelio
cd5324378d Move YG_ENABLE_EVENTS checks to event.h
Summary:
Instead of checking whether `YG_ENABLE_EVENTS` is defined for every publish, we simply wrap the body of the `publish` function macro that delegates to the method that actually publishes the event.

This way we get

1. easier to write code where we publish events
2. more type safety when editing, enabling editors/IDEs to show errors without knowing about `YG_ENABLE_EVENTS`

Reviewed By: SidharthGuglani

Differential Revision: D16049888

fbshipit-source-id: cbf362d6f7be5053c3f377125d303b7137d6a241
2019-06-28 09:58:57 -07:00
David Aurelio
c6ae314202 Stop recording measure callback duration
Summary: Removes time measurements for measure callbacks. This functionality should not be part of Yoga/core, and can now be done by event subscribers themselves, as we have two events per measure callback.

Reviewed By: SidharthGuglani

Differential Revision: D16049812

fbshipit-source-id: e16556f3854e42f4bada39a97a668e718719b22c
2019-06-28 09:58:57 -07:00
David Aurelio
73224c62b5 Publish two events for measure callbacks
Summary: Publishing two events will allow us to replace marker functionality completely with events. This also allows us to remove measuring time spent from Yoga itself.

Reviewed By: SidharthGuglani

Differential Revision: D16049810

fbshipit-source-id: 98628a92ed3c94d479e9fbcd53fac90c5f524087
2019-06-28 09:58:56 -07:00
David Aurelio
2c6a4485f5 Remove duplicate declaration of YGRoundValueToPixelGrid from Yoga-internal.h
Summary:
@public

Removes the declaration of `YGRoundValueToPixelGrid` from `Yoga-internal.h`, as it is already declared in `Yoga.h`. `Yoga.h` is included from `Yoga-internal.h`

Reviewed By: SidharthGuglani

Differential Revision: D16047832

fbshipit-source-id: 72d9d2510372c983eedacc5d7af406b9346f18e6
2019-06-28 05:17:06 -07:00
dattc2
cf005df828 make yoga threadsafe (#852)
Summary:
Continuing https://github.com/facebook/yoga/pull/791
nokia6686 is a former member of our team, so we are trying to pick up what he left and carry out the pull request.
# Solution
Improved from previous solution with jpap's suggestions.
2. Passing ```gDepth``` and ```gCurrentGenerationCount``` (renamed to **_depth_** and **_generationCount_** respectively) between function calls that stem from ```YGNodeCalculateLayout```.
In ```YGNodeCalculateLayout```, pass ```depth``` as value 0, to indicate the root depth.
Pull Request resolved: https://github.com/facebook/yoga/pull/852

Reviewed By: SidharthGuglani

Differential Revision: D15537450

Pulled By: davidaurelio

fbshipit-source-id: 338f51383591ba27702ebe759f6c47c2dede3530
2019-06-25 12:10:23 -07:00
Chris Hopman
f539d68049 Force ordering of :yoga/:yogaForDebug
Summary:
Due to testutil depending on :yoga, we are always linking against both
:yoga and :yogaForDebug in tests. This is only working right now due to luck in
how Buck orders the link line. Adding a dependency is silly but it enforces
that Buck maintain the ordering that we currently have even when it changes how
it does its traversal.

Reviewed By: philipjameson

Differential Revision: D15973581

fbshipit-source-id: 3d18aff578ee4d56175ce5efae52b56aeb2d9586
2019-06-24 17:10:45 -07:00
Sidharth Guglani
39996512fc pass cachedLayout and cachedMeasure measures to plugin
Summary: Passing whether layout cache or measure cache was used or not

Reviewed By: davidaurelio

Differential Revision: D15920937

fbshipit-source-id: a6728e7af07ea228a285f824fbdfddc8130c5990
2019-06-24 08:37:18 -07:00
Sidharth Guglani
2dc5a16d1f Move event NodeLayout to end of NodeLayout step
Summary:
Added event NodeLayoutEnd and this is being used now instead of NodeLayout
It will be used later to add more information about caches

Reviewed By: davidaurelio

Differential Revision: D15920935

fbshipit-source-id: c9f5e193bc8cc70d26ff5d84882d483c9b09f67d
2019-06-24 08:37:17 -07:00
David Aurelio
d667ebd66e Replace relative include
Summary: Replaces the relative include to `YGEnums.h` in `yoga/event/event.h` with `#include <yoga/YGEnums.h>

Reviewed By: SidharthGuglani

Differential Revision: D15778634

fbshipit-source-id: 2bceeb58f26c0d9d0df6c0e7ea20b8ddf68a1ee5
2019-06-21 04:11:36 -07:00
Sidharth Guglani
2b8217ce8d Send measure pass duration
Summary: Send measure callback duration time to yoga plugin

Reviewed By: davidaurelio

Differential Revision: D15917548

fbshipit-source-id: 2c947f14ddbc5932cedd0aab8622260478ec29a6
2019-06-21 02:38:57 -07:00
Stiopa Koltsov
9dac56e824 Migrate Yoga targets to raw_headers
Summary:
In "regular" header mode, Buck will symlink from `buck-out/` to the actual header file. This works fine with GCC and clang, but not with MSVC. Headers will be treated as different file, sidestepping `#pragma once` directives.

As a result, all kinds of symbols get declared twice, leading to compile errors.

Reviewed By: davidaurelio

Differential Revision: D15781947

fbshipit-source-id: a3b4e211b8b74b9ef44fc39471a3009b2cf47260
2019-06-15 12:07:14 -07:00
David Aurelio
a7e8aec3d9 Allow to end markers early
Summary:
Adds the ability to `MarkerSection` to end the marker before it goes out of scope.

This unlocks two scenarios:
- reuse the data associated with a marker after ending it.
- end markers in the middle of a function without adding arbitrary blocks.

Reviewed By: SidharthGuglani

Differential Revision: D15837840

fbshipit-source-id: c0afaeeabd169c65189b5028be54ea7dac3e3b84
2019-06-15 10:26:32 -07:00
David Aurelio
6b5bf570c8 Count the number measure callback invocations
Summary: Counts how many times measure callbacks have been invoked during a layout pass. This is made available via the marker and event APIs.

Reviewed By: SidharthGuglani

Differential Revision: D15836983

fbshipit-source-id: 3835bef94e497375821c9f2ad8209447b4f11518
2019-06-15 10:26:31 -07:00
Sidharth Guglani
a130ac2f9c pass measure callback data from c++ to java
Summary:
Passing Measure callback data - width, widthMeasureMode, height, heightMeasureMode, measuredWidth and measuredHeight along with NodeMeasure event
This data is then propagated to java layer in this diff

Reviewed By: davidaurelio

Differential Revision: D15697523

fbshipit-source-id: 615463da237175ff88abef3f6528b55333ccd915
2019-06-12 00:33:31 -07:00
David Aurelio
19fd066507 Pass layout context for Event::LayoutPassStart
Summary: Adds the layout context pointer when publishing `Event::LayoutPassStart`.

Reviewed By: SidharthGuglani

Differential Revision: D15754425

fbshipit-source-id: 6295ae1ebec9eab72a79c43bc1cb0e05a6d7ae68
2019-06-11 01:41:22 -07:00
David Aurelio
204e849218 rm YogaEventListener
Reviewed By: SidharthGuglani

Differential Revision: D15742456

fbshipit-source-id: b90a221e177e936e141c582500dccf0ac38027c2
2019-06-11 01:41:22 -07:00
Aditya Sharat
8ff13c922a Back out "[litho] Adds check to unset a YogaNode's parent during reconciliation."
Summary: Removes `unsetOwner` from Yoga. This was temporarily for patching a crash.

Reviewed By: colriot

Differential Revision: D15737613

fbshipit-source-id: 8ab93ecf7ffb913df6207fe5db47a8cc93eded2c
2019-06-10 06:57:05 -07:00
Sidharth Guglani
af219f8836 add node layout event and pass it java layer
Summary: Listen to NodeLayout event and passes this event callback to java layer along with the information whether layout or measure was done in this pass

Reviewed By: davidaurelio

Differential Revision: D15696021

fbshipit-source-id: 8c5ca69330a9baca26b77052d4965cc67fe97c75
2019-06-10 01:51:53 -07:00
Aditya Sharat
e33123f955 Adds check to unset a YogaNode's parent during reconciliation.
Summary: Adds check to unset a YogaNode's parent during reconciliation.

Reviewed By: davidaurelio

Differential Revision: D15714899

fbshipit-source-id: 6e2c2a28106574d062fec722c9a051acea87d0b6
2019-06-07 09:28:24 -07:00
Sidharth Guglani
755fa07b39 add node measure event and passing the callback to java layer
Summary: Adds measure event and its listener initial code structure

Reviewed By: davidaurelio

Differential Revision: D15600738

fbshipit-source-id: d15764e0b64edb170fcb15e0912ecce5f7e53595
2019-06-06 21:03:24 -07:00
Sidharth Guglani
2701d80078 passing layout context and getting local reference from it
Summary: We are passing layout context from yoga as event data for Layout Pass End event and it is being then used to get the local reference of node so that we can pass it as method parameter to java layer

Reviewed By: davidaurelio

Differential Revision: D15619640

fbshipit-source-id: 5f6c29d9e6acb73a8d87f8e0cb1577d35a271aeb
2019-06-06 21:03:24 -07:00
Sidharth Guglani
c393ed1381 moved PtrJNode map to YGJtypes.h and passing layout context as data in LayoutPassEnd Event
Summary: Move PtrJNodeMap to header file so that it can be accessed in events subscribers outside yoga

Reviewed By: davidaurelio

Differential Revision: D15619629

fbshipit-source-id: 1bf213efd38ec7bcac6a38070f21fa837c5f17da
2019-06-06 21:03:23 -07:00
Rain ⁣
a4bdd9cd9b standardize C-like MIT copyright headers throughout fbsource
Summary:
`/*` is the standard throughout open source code. For example, Firefox uses single /*: https://hg.mozilla.org/mozilla-central/file/21d22b2f541258d3d1cf96c7ba5ad73e96e616b5/gfx/ipc/CompositorWidgetVsyncObserver.cpp#l3

In addition, Rust considers `/**` to be a doc comment (similar to Javadoc) and having such a comment at the beginning of the file causes `rustc` to barf.

Note that some JavaScript tooling requires `/**`. This is OK since JavaScript files were not covered by the linter in the first place, but it would be good to have that tooling fixed too.

Reviewed By: zertosh

Differential Revision: D15640366

fbshipit-source-id: b4ed4599071516364d6109720750d6a43304c089
2019-06-06 19:44:16 -07:00
Joshua Gross
4a4325afb6 Revert D15602627: [yoga] moved PtrJNode map to YGJtypes.h and passing layout context as data in LayoutPassEnd Event
Differential Revision:
D15602627

Original commit changeset: bb5bd5bbf8dc

fbshipit-source-id: 5ae08826eb706c3794c36738cb9625f82b58641e
2019-06-03 19:57:53 -07:00
Joshua Gross
586eb6102a Revert D15602923: [yoga] passing layout context and getting local reference from it
Differential Revision:
D15602923

Original commit changeset: 54b25956af09

fbshipit-source-id: 8ce26a7f00d76bd5ade18f32ad14d943118a6f31
2019-06-03 19:57:53 -07:00
Sidharth Guglani
b1e6793460 passing layout context and getting local reference from it
Summary: We are passing layout context from yoga as event data for Layout Pass End event and it is being then used to get the local reference of node so that we can pass it as method parameter to java layer

Reviewed By: davidaurelio

Differential Revision: D15602923

fbshipit-source-id: 54b25956af098700cea25c4f7f8ffe0b9117432c
2019-06-03 16:01:51 -07:00
Sidharth Guglani
8b17459254 moved PtrJNode map to YGJtypes.h and passing layout context as data in LayoutPassEnd Event
Summary: Move PtrJNodeMap to header file so that it can be accessed in events subscribers outside yoga

Reviewed By: davidaurelio

Differential Revision: D15602627

fbshipit-source-id: bb5bd5bbf8dcb279f5f87a4fd7287909d4e895d8
2019-06-03 16:01:50 -07:00
David Aurelio
195c166efe Back out "[Yoga] Remove comparison to YGUndefined *and* 0.0f"
Summary: Original commit changeset: 13c8f24e1bc8

Reviewed By: fabiomassimo

Differential Revision: D15583502

fbshipit-source-id: efc6175f6c4925a383fea723195c073f49e2eff1
2019-05-31 15:56:50 -07:00
David Aurelio
0908d3a173 Data structure for exclusive writing
Summary:
Adds a data structure that holds a series of values that can be *borrowed* for exclusive writing.
That means, that only a single consumer can write to any value owned by the data structure.

In addition, the data structure exposes read access via iteration over all contained values.

A typical use case would be a counter with thread-local values that are accumulated by readers in other parts of a programm. The design carefully avoids the use of atomics or locks for reading and writing. This approach avoids cache flushes and bus sync between cores.

Borrowing and returning a value go through a central lock to guarantee the consistency of the underlying data structure.

Values are allocated in a `std::forward_list`, which typically should avoid two values in the same cache line -- in that case, writing to one value would still cause cache flushing on other cores. An alternative approach would be to allocate values continuously on cache line boundaries (with padding between them). We can still change the code if the current approach turns out to be too naive (non-deterministic).

Reviewed By: SidharthGuglani

Differential Revision: D15535018

fbshipit-source-id: 212ac88bba9682a4c9d4326b46de0ee2fb5d9a7e
2019-05-31 09:43:43 -07:00
David Aurelio
f304990656 Use atomic list for event subscribers
Summary:
Replace the *copy on write* vector with an atomic pointer to a linked list.

This allows to publish without locking a mutex, at the cost of the slower traversal of a linked list (a vector has better locality).

At the moment, the typical use case is to have one subscriber, meaning that the afforementioned slower traversal is not a problem.

Adding subscribers is implemented as atomic *compare and swap.*

Reviewed By: SidharthGuglani

Differential Revision: D15546964

fbshipit-source-id: 41bfa41f1ac6be5c9b6bf4288ea3271ee995877e
2019-05-31 01:26:42 -07:00
David Aurelio
cea3865c74 Deprecate YGNode::setConfig
Summary:
We want to phase out usage of config pointers on nodes. Setting configs is no longer needed, as a config is unly used during construction.

Here we deprecate the setter, as it is no longer working as it used to (e.g. changing `useWebDefaults` after a node is constructed).

Reviewed By: SidharthGuglani

Differential Revision: D15416474

fbshipit-source-id: a2cc06cad0c5148cecce056ece5f141b3defe9a9
2019-05-29 07:50:11 -07:00
David Aurelio
b74c0d4766 Remove comparison to YGUndefined *and* 0.0f
Summary: Removes a check introduced in D6969537, comparing `totalFlexGrowFactors` and `resolveFlexGrow` to both `0.0` *and* undefined.

Reviewed By: SidharthGuglani

Differential Revision: D15431425

fbshipit-source-id: 13c8f24e1bc8c49496097a6aa78e20ee5d3964a7
2019-05-22 09:44:36 -07:00
David Aurelio
54e863cef2 Remove YGNode::setAndPropogateUseLegacyFlag
Summary:
`YGNode::setAndPropogateUseLegacyFlag` was only used for debugging purposes.
Here, we replace it with a free function in `Yoga.cpp`.

Now that we have events, the diffing functionality should go into a separate debugging package and be implemented in terms of an event listener. Let's do that as soon as we can support multiple listeners.

Reviewed By: SidharthGuglani

Differential Revision: D15316863

fbshipit-source-id: db929eba7c2de8aa1550e362dd2c175929c0070e
2019-05-21 06:06:37 -07:00
David Aurelio
1938792517 YGNode: Field for web defaults
Summary:
In order to remove the config pointer from nodes, we have to keep track of whether the node is using web defaults.
This information fits into one bit that we can place in padding (i.e. no extra memory needed).

This allows us to get rid of config usage withing `YGNode` with some exceptions:

- `iterChildrenAfterCloningIfNeeded` -- this function will simply receive the configuration, or the cloning callback.
- `setAndPropogateUseLegacyFlag` -- will be removed in D15316863
- in `YGNode::reset` -- will go away utomatically once we remove the config pointer

Reviewed By: SidharthGuglani

Differential Revision: D15391536

fbshipit-source-id: 0fa0d0805c6862bd741fe4a7d9b637ed534f56a4
2019-05-20 10:51:38 -07:00
Sidharth Guglani
aa71dbb5bd mutex lock while accessing event subscribers vector for thread safety
Summary: Using Mutex lock_guard mechanism when writing to subscribers and when accessing them in publish to make a copy

Reviewed By: davidaurelio

Differential Revision: D15391679

fbshipit-source-id: 16713ff28ce1762a5ca4c48c152897a92417e80b
2019-05-19 23:34:41 -07:00
David Aurelio
8dc46c0a87 YGNode: one byte of private storage
Summary:
Adds one byte of private storage to `YGNode`, intended to be used by Yoga itself.

This is in previously unused alignment space, and won’t cause more memory to be allocated.

Reviewed By: SidharthGuglani

Differential Revision: D15296732

fbshipit-source-id: 3caf0a3cd506e4e324e51c31869c69be5781d476
2019-05-16 11:47:30 -07:00
David Aurelio
1180afed9c Fix style property bits
Summary: Style bits had overlap, because `dimensionBit` was set with an incorrect increment.

Reviewed By: SidharthGuglani

Differential Revision: D15335134

fbshipit-source-id: 370e1a73547d76b0e26bc6ab67acb96d33ddf180
2019-05-16 11:47:30 -07:00