Граф коммитов

371 Коммитов

Автор SHA1 Сообщение Дата
David Aurelio 0e1d4ecbb7 Make `==` operator for `YGStyle` free function
Summary:
@public

Makes it work nicely with gtest.

Also allows rhs *and* lhs to offer `operator(YGStyle)()`.

Reviewed By: SidharthGuglani

Differential Revision: D13942573

fbshipit-source-id: ff8b3a9aa6f05ca1b0572eb97d0ad23b09d77871
2019-02-04 10:24:50 -08:00
David Aurelio 5184f0d7a3 User-defined literals for `YGValue`
Summary:
@public

Adds `_pt` and `_percent` user defined literals to create `YGValue` instances.

This allows to create `YGValue`s in the following form:

```
use namespace facebook::yoga::literals;

auto a = 123_pt; // == YGValue{123.0f, YGUnitPoint}
auto b = -12.5_percent; // == YGValue{-12.5f, YGUnitPercent}
```

Reviewed By: SidharthGuglani

Differential Revision: D13942100

fbshipit-source-id: ce1e2f9431c3e2a99c6e11896a712539cc535e0d
2019-02-04 10:24:50 -08:00
David Aurelio e2bd70afff Marker for baseline callbacks
Summary:
@public

Wraps baseline callbacks with a marker.

Reviewed By: SidharthGuglani

Differential Revision: D13896861

fbshipit-source-id: 848ec697977a0a68b9943f1159f6562d54724f89
2019-02-01 03:34:39 -08:00
David Aurelio d2b2316722 Marker for measure callbacks
Summary:
@public

Wraps measure callbacks with a marker.

Reviewed By: SidharthGuglani

Differential Revision: D13896745

fbshipit-source-id: d6e14fe93f666b06516be1aef7f8e1bfe45440a7
2019-02-01 03:34:39 -08:00
Eric Rozell dfcbf9729f Adds fixes for react-native-windows UWP (#848)
Summary:
Specifically, updates the UWP .vcxproj for MSBuild and also exposes the UseLegacyStretchBehaviour API for use with react-native-windows.
Pull Request resolved: https://github.com/facebook/yoga/pull/848

Reviewed By: SidharthGuglani

Differential Revision: D13848609

Pulled By: davidaurelio

fbshipit-source-id: eab046ff3c47e49706f515e209d8aaf750c2198f
2019-01-31 09:35:10 -08:00
David Aurelio c16fadb7c3 Track how much measure cache entries are used
Summary:
@public

Adds the maximum number of measure cache entries in use to the metrics for `YGMarkerLayout`

Reviewed By: SidharthGuglani

Differential Revision: D13844731

fbshipit-source-id: fa66dbf1b7a1799494f72ecc17dfaef04d0b56e4
2019-01-29 15:54:19 -08:00
David Aurelio f506019e8b count cache hits
Summary:
@public

Adds cache hit counts to layout stats.

Reviewed By: SidharthGuglani

Differential Revision: D13844022

fbshipit-source-id: 906b4ec5fe3314287911cee2c37d77c4aac76455
2019-01-29 11:41:36 -08:00
David Aurelio 0dafa0de6b Layout marker metadata
Summary:
@public

Adds marker meta data to `YGMarkerLayout`: the number of measures, and the numbers of layouts for all nodes in the tree.

Reviewed By: SidharthGuglani

Differential Revision: D13838975

fbshipit-source-id: d575c26a3d5a4f0b66834eb6bedecadc3f3ca265
2019-01-29 11:41:36 -08:00
David Aurelio fc6a4b6dbb Pass layout marker data along
Summary:
pubic

Passes layout marker data through the recursive calls of the layout algorithm, in order to allow for collecting metrics.

Reviewed By: SidharthGuglani

Differential Revision: D13819444

fbshipit-source-id: cdca04964fba6a03ca3eeaca4d169107019ba457
2019-01-29 11:41:36 -08:00
David Aurelio c723029242 Introduce first marker
Summary: @public Adds a marker section for a complete layout pass

Reviewed By: SidharthGuglani

Differential Revision: D13819447

fbshipit-source-id: 21a80f0fe3d325d804a968508761d115c50d3dc1
2019-01-29 11:41:36 -08:00
David Aurelio f1a3137b41 Add `MarkerSection`
Summary:
@public

Adds a class for triggering markers.

This calls `startMarker()` on construction, and `endMarker()` on destruction, thus being usable like a "scope guard": the object is instantiated, and automatically destroyed when going out of scope.

Reviewed By: SidharthGuglani

Differential Revision: D13817589

fbshipit-source-id: fd88884af970c1c0933d9ca6843f3f8f5d28b9e6
2019-01-29 11:41:36 -08:00
David Aurelio 52d9f2627b Remove unused constexpr
Summary:
@public

Removes unused constexpr variables from YGStyle. Not polluting the global namespace is a good thing.

Reviewed By: SidharthGuglani

Differential Revision: D13816817

fbshipit-source-id: e4c27a8f2de466ccb759bbe52cdaea6fe451b961
2019-01-29 04:11:25 -08:00
David Aurelio 43601f1a17 Add function to set marker callbacks
Summary:
@public

Adds a function to allow to configure markers. The function is declared in `YGMarker.h`

Reviewed By: SidharthGuglani

Differential Revision: D13819111

fbshipit-source-id: f9158b3d4e5727da4e151c84b523c7c7e8158620
2019-01-29 03:51:37 -08:00
David Aurelio 1db55803f1 Add `YGMarkerLayout`
Summary: @public adds a first `YGMarker`, and the accompanying data type.

Reviewed By: SidharthGuglani

Differential Revision: D13817588

fbshipit-source-id: 6007eb09d19cf4021989bad5b5e880adb16364a0
2019-01-29 03:51:37 -08:00
David Aurelio e804124e6f Rename `YGMarkerType` to `YGMarker`
Summary:
@public

this will lead to nicer enum member names.

Reviewed By: SidharthGuglani

Differential Revision: D13817587

fbshipit-source-id: 85355328f7977b4fb29a9474532f2d578a3cbf79
2019-01-29 03:51:36 -08:00
David Aurelio f4def0062c Delete functionality for shared childen
Summary:
@public

Removes `YGNodeInsertSharedChild` / `addSharedChildAt`.

This functionality is unused, and can cause memory leaks.

Reviewed By: SidharthGuglani

Differential Revision: D13711105

fbshipit-source-id: 86206c05393b3f1a497e6b046006f94ead88c6ce
2019-01-24 06:31:00 -08:00
Eduardo Roman cfbb2278a0 guard against INF values in CompactValue
Summary:
After this diff D13403925 that got rid of `-ffast-math` we started to have a very odd behavior on Yoga when using release builds.

After digging a while we found that certain set of conditions on O2 and O3 optimization levels was causing Origami to set some `INFINITE` values on Yoga.

We found the root of the problem and fix it on Origami side. But I'm wondering if guarding agains `INFINITE` on Yoga side would be good too. Since now Yoga it's not using `-ffast-math` anymore, and I think infinite is not a a valid value anywhere on Yoga side, it seems to support the reason to guard against it.

I'm happy to abandon this diff if you guys think this is not a good solution.

Reviewed By: davidaurelio

Differential Revision: D13679319

fbshipit-source-id: 061448fea9d1a8496362ff07dc46b546e7f1ffa3
2019-01-16 12:27:49 -08:00
David Aurelio 3cfe8d59bc Reflow comments
Summary:
@public

Repeated application and alternation of Clang Format rules has lead to unfortunate block comment formatting.

Here, we reflow comments

Reviewed By: SidharthGuglani

Differential Revision: D13677242

fbshipit-source-id: 3f1f5e38693eb15e9705f24fd363fc1618c78974
2019-01-16 08:47:15 -08:00
David Aurelio 53a28ee180 Fix URLs to CSS spec in comments
Summary:
@public

These URLs probably have been changed when CSSLayout was renamed to Yoga by search & replacing

Reviewed By: SidharthGuglani

Differential Revision: D13690829

fbshipit-source-id: 44dbd8fe256fc286006d164390609a7c3de6c4e6
2019-01-16 08:47:15 -08:00
David Aurelio 7406276a5b Remove enum count macros
Summary:
@public
Removes all `YG...Count` macros for enums and replaces them with `facebook::yoga::enums::count<YG...>()`.
This removes the need to manually maintain enum counts.

Same as D13597449, working around a defect in clang < 3.9

Reviewed By: amir-shalem

Differential Revision: D13634622

fbshipit-source-id: 344dc70e167b0caf746fe396cedd200f54e52219
2019-01-11 03:11:58 -08:00
Amir Shalem 1feda5e5c8 Revert D13597449: [Yoga][cleanup] Remove enum count macros
Differential Revision:
D13597449

Original commit changeset: edcee225ada4

fbshipit-source-id: 1afc24833c8657a8a198bc4529d98c8f605b7fbd
2019-01-10 23:51:29 -08:00
David Aurelio 35a136801c Remove enum count macros
Summary:
@public
Removes all `YG...Count` macros for enums and replaces them with `facebook::yoga::enums::count<YG...>()`.
This removes the need to manually maintain enum counts.

Reviewed By: shergin

Differential Revision: D13597449

fbshipit-source-id: edcee225ada4058e94f3a727246763e3cc45873d
2019-01-10 07:56:15 -08:00
Marko Novakovic 65194534f6 Using ENUM_BITFIELDS_NOT_SUPPORTED for enum bitfields
Reviewed By: davidaurelio

Differential Revision: D13556160

fbshipit-source-id: e6d373a4e1dd702509b5d63606c08fae9cdb5498
2019-01-08 16:22:29 -08:00
David Aurelio 2a1faec1ca Remove repetition in `YGEnums.h`
Summary:
@public

Wraps enum definition in a single macro.

Down the line, this will allow us to add more functionality:
- Replace manual counts with `yoga::enums::count<YG...>()`
- `yoga::enums::max<YG...>()`
- A bitfield implementation with known memory layout using `max<>()`

Reviewed By: SidharthGuglani

Differential Revision: D13597259

fbshipit-source-id: 543a11a53090bedf1474d00328565ed57d059e23
2019-01-08 12:51:43 -08:00
David Aurelio 3e24710155 Apply clang-format rules
Summary:
@public

Formats Yoga's source according to our clang-format configuration

Reviewed By: SidharthGuglani

Differential Revision: D13596650

fbshipit-source-id: c3722d4eafd63b7596a8b1e85c0197e9d2d6cb7d
2019-01-08 12:51:43 -08:00
David Aurelio d8fcb7f165 Use bitfields for `YGLayout` and `YGNode`
Summary:
@public

Further heap size reductions by using bitfields in `YGLayout` and `YGNode`.

Reviewed By: SidharthGuglani

Differential Revision: D13466325

fbshipit-source-id: ddcef0a1b3822e7449fe485d99c920d54139c893
2018-12-18 08:15:09 -08:00
David Aurelio ac94e54f5a Switch storage in `YGStyle` to `CompactValue`
Summary:
@public

Switches the storage in `facebook::yoga::detail::Values` from `YGValue` to `facebook::yoga::detail::CompactValue`.
This cuts heap size for arrays of values in half.

Reviewed By: SidharthGuglani

Differential Revision: D13465586

fbshipit-source-id: 49a4d6d29a73bdd44843b1f3c57bf746050c94d6
2018-12-18 08:15:09 -08:00
David Aurelio 0eeb94e948 Remove cast from `detail::Values` to `std::array<YGValue`
Summary:
@public

When switching to `CompactValue`, casting edges or dimensions to `std::array<YGValue, ...>` will do actual work.
In order to avoid that from happening implicitely, we remove the casting operator.

Reviewed By: SidharthGuglani

Differential Revision: D13464292

fbshipit-source-id: 217065b001a63cfa8adde715063682c583007a4d
2018-12-14 09:23:13 -08:00
David Aurelio dac59586ed Encapsulate arrays of `YGValue` within `YGStyle`
Summary:
@public

Enforce more encapsulation of arrays of `YGValue` in `YGSty;e`.
This will allow us to use `CompactValue` in `YGStyle` while (mostly) retaining API compatibility.

Reviewed By: SidharthGuglani

Differential Revision: D13452042

fbshipit-source-id: 382b1c7245c4bea4280126ab1413e7e931b62eaa
2018-12-14 09:23:13 -08:00
David Aurelio 94dd6025d3 Introduce `CompactValue`
Summary:
@public

`CompactValue` represents a `YGValue` in 32bits instead of 64. This comes at the cost of a range limitation, as one exponent bit is borrowed for the unit.

*Undefined* and *Auto* have no magnitude, and are represented as *NaN* values.

The data structure is meant to be used as a field type on `YGStyle` to save memory.

This is header-only for efficient inlining.

Reviewed By: jackerghan, aCorrado

Differential Revision: D13187211

fbshipit-source-id: 16e3ffad592e38e2493e4f7c8b952d372e449846
2018-12-14 09:23:13 -08:00
David Aurelio d0485b2f04 Don't use `default` in exhaustive switch
Summary:
@public
removes the `default` case from an already exhaustive switch.

Reviewed By: SidharthGuglani

Differential Revision: D13451869

fbshipit-source-id: 32727330c7fce013963f5c83c95a73b230d5c938
2018-12-13 10:42:51 -08:00
David Aurelio a816c0321c Don't pass `std::string` by pointer
Summary:
@public

Pass strings by mutable ref rather than pointer.

Reviewed By: SidharthGuglani

Differential Revision: D13439613

fbshipit-source-id: ea889abe0fe8ec44ae02f13c1d9a10c0dbfdbcf1
2018-12-13 07:16:46 -08:00
David Aurelio 206705892f Use bitfields for enum members of `YGStyle`
Summary:
@public

Puts all enum fields of `YGStyle` into bitfields. This saves 36 bytes (> 3%) per node.

Reviewed By: SidharthGuglani

Differential Revision: D13439606

fbshipit-source-id: b60a5444762041bc6f8cc5e04757034cb6893b30
2018-12-13 07:16:46 -08:00
David Aurelio bb1b80b763 Remove templates for setting/getting style properties
Summary:
@public

Replaces the `StyleProp` template with a simple setter macro / inlined getter code.

The template was introduced to replace more extensive macros that would generate function signatures, too.
Here, we keep the spirit of that change by only generating function bodies.

Reviewed By: SidharthGuglani

Differential Revision: D13439612

fbshipit-source-id: 36f6a86917d035be6891cb736d1f288d8e02f5cf
2018-12-13 07:16:46 -08:00
David Aurelio 05d90c3013 `YGNodeBoundAxisWithinMinAndMax` accepts `YGFloatOptional`
Summary:
@public

Saves some calls to `.unwrap()`

Reviewed By: SidharthGuglani

Differential Revision: D13439600

fbshipit-source-id: ce0f6bad9a0709e9d64e23d8349bc2423b9b2ad4
2018-12-13 07:16:46 -08:00
David Aurelio 3e3972628c Remove unnecessary `static` keyword
Summary:
@public

Header-declared inline functions shouldn’t be decleared `static`

Reviewed By: SidharthGuglani

Differential Revision: D13439607

fbshipit-source-id: 89555bb19a3fff6e29ca4afc10fe15fecca8fa17
2018-12-13 07:16:46 -08:00
David Aurelio 41c326ee9f Get rid of `static_cast` in `YGResolveValue`
Summary:
@public

Removes `static_cast` from `YGResolveValue`

Reviewed By: SidharthGuglani

Differential Revision: D13439605

fbshipit-source-id: 8736541c8e1d43fd698d368cb4f3211ffd929364
2018-12-13 07:16:46 -08:00
David Aurelio a56b67fa9b Inline `YGFloatOptional` completely
Summary:
@public
`YGFLoatOptional` only contains trivial functionality. Make it header-only.

Reviewed By: SidharthGuglani

Differential Revision: D13439609

fbshipit-source-id: 3f3c6c3a15e05ac55da2af30eb629f786ecb90a9
2018-12-13 07:16:45 -08:00
David Aurelio 688b3195c3 Pass `YGFloatOptional` by value, not reference
Summary:
@public

`YGFloatOptional` is a 32bit type now, and can be passed by value efficiently.

Reviewed By: SidharthGuglani

Differential Revision: D13439603

fbshipit-source-id: e12539ad5b3cccbd5bc27869866ca66c023b24a7
2018-12-13 07:16:45 -08:00
David Aurelio ada4831580 Eliminate `YGFloatOptional::getValue()`
Summary:
@public

Replace `YGFloatOptional::getValue()` with `YGFloatOptional::unwrap()`.

`YGFloatOptional::getValue()` has the unfortunate property of calling `std::exit` if the wrapped value is undefined.

Here, we eliminate the method, and just call `.unwrap()` everywhere.

Reviewed By: shergin

Differential Revision: D13439608

fbshipit-source-id: 5ae82b170537d0a10c301412567a7a66fd50bab4
2018-12-13 07:16:45 -08:00
David Aurelio 110c1c260f Remove `YGUnwrapFloatOptional`
Summary:
Replaces `YGUnwrapFloatOptional` with `YGFloatOptional::unwrap`.

This leads to more idiomatic C++, and to less function call nesting, thus increasing readability.

Reviewed By: SidharthGuglani

Differential Revision: D13439604

fbshipit-source-id: 33b43c08d725c253c359959e7cbbd83fd6bd9ba4
2018-12-13 07:16:45 -08:00
David Aurelio f90c2fb3f6 Store `YGFloatOptional` in 32 bits
Summary:
@public

After removing `-ffast-math`, `NaN` can again be used to represent `undefined`. That allows us to remove the additional flag from `YGFloatOptional`, and reduce memory usage.

Reviewed By: SidharthGuglani

Differential Revision: D13439611

fbshipit-source-id: 93e90f72f0415edb228b4e7d145e1fae35cc6b43
2018-12-13 07:16:45 -08:00
David Aurelio 2d6a10028f Add tests for `YGFloatOptional`
Summary:
@public

Adds tests for `YGFloatOptional`, to ease refactorings.

Reviewed By: SidharthGuglani

Differential Revision: D13439610

fbshipit-source-id: e29da7f85ccedc46520b59f6c893bad521d35417
2018-12-13 07:16:45 -08:00
David Aurelio 568472231f Make equality operator for `YGValue` inlineable
Summary:
@public

Makes `operator==` for `YGValue` an inline function.

Reviewed By: SidharthGuglani

Differential Revision: D13439601

fbshipit-source-id: c5dd1f35c40f0ffa8224ee2f40ac7cc3cd8e3cf9
2018-12-13 07:16:45 -08:00
David Aurelio b5c66a3fbe Move out `YGValue`
Summary:
@public

Creates a single header file for `YGValue`. This is in preparation of a more compact representation of `YGValue` within `YGStyle`.

Also fixes the incorrect definition of NAN.

Reviewed By: SidharthGuglani

Differential Revision: D13439602

fbshipit-source-id: 68eef2c391b6c9810f3c995b86fff7204ebe6511
2018-12-13 07:16:45 -08:00
David Aurelio 6f70d4c0ac Roll back `-ffast-math`
Summary:
@public

`-ffast-math` does not have measurable performance benefits.

By using `NaN` for *undefined* values again, we can squeeze `YGFloatOptional` into 32 bits.
This will also enable us to store `YGValue` (or a variant of it) in 32 bits.

Reviewed By: astreet

Differential Revision: D13403925

fbshipit-source-id: b13d026bf556f24ab4699e65fb450af13a70961b
2018-12-13 07:16:45 -08:00
David Aurelio 1decf879f8 Back out "[yoga][PR] Fix aspect ratio when stretching with main axis margin"
Summary: Original commit changeset: 6970e6072e79

Reviewed By: mdvacca

Differential Revision: D13437552

fbshipit-source-id: 65a55d716da6b6582e38efa906d3f540e58418bf
2018-12-12 16:20:45 -08:00
Emil Sjölander ee6b0d6658 Fix aspect ratio when stretching with main axis margin (#834)
Summary:
I've noticed that when a child's size is determined by `align-items: stretch` in combination with `aspect-ratio` its size is wrongly calculated to account for margin in the main axis when there is more than enough space.

See playground: https://goo.gl/tgW6cD

I've yet to figure out exactly how to solve this but i've started by writing a failing test when can be seen in the first commit here.

I assumed I had found the bug here https://github.com/facebook/yoga/blob/master/yoga/Yoga.cpp#L1838 where margin is being subtracted from the desired width even though the measure mode tells it to measure to exactly that size. However, if we don't remove this margin from the available width then 15 tests fail (including the one I just added) not quite figured out why yet. I'm also a bit confused at to why this would only happen for nodes with `aspect-ratio` and not for nodes where an explicit height and width is set.
Pull Request resolved: https://github.com/facebook/yoga/pull/834

Reviewed By: astreet

Differential Revision: D13223579

Pulled By: davidaurelio

fbshipit-source-id: 6970e6072e79f3bb6f9097355ab6e441441bfd88
2018-12-10 09:23:01 -08:00
David Aurelio 90f582ffb9 Back out Stack D13119110..D13236159
Summary: backout, causes failures

Reviewed By: adityasharat

Differential Revision: D13376210

fbshipit-source-id: 1fa8823f2dce601c47738f34ddb2674288197e79
2018-12-07 13:01:28 -08:00
David Aurelio 8f6521aacf Don't pass `std::string` by pointer
Summary:
@public

Pass strings by mutable ref rather than pointer.

Reviewed By: SidharthGuglani

Differential Revision: D13236159

fbshipit-source-id: 04fd35e8a9e106ba8cdd71cfab31e8d90edaac9e
2018-12-06 07:38:44 -08:00