From f1cbc12c808e28ac4079b1009d2fba79eb2255fe Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 12 Sep 2023 19:08:28 -0700 Subject: [PATCH 1/3] Extract isBaselineLayout() Summary: Moves `isBaselineLayout` out of `CalculateLayout` into `Baseline.h`. This function is called by flex line justification code, which I have been looking at extracting. Differential Revision: D49177937 fbshipit-source-id: 31b42d1c249d258903b59ff8b88f83fe5151b95f --- yoga/algorithm/Baseline.cpp | 19 +++++++++++++++++++ yoga/algorithm/Baseline.h | 3 +++ yoga/algorithm/CalculateLayout.cpp | 19 ------------------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/yoga/algorithm/Baseline.cpp b/yoga/algorithm/Baseline.cpp index 5042074a1e..1cbfbd1883 100644 --- a/yoga/algorithm/Baseline.cpp +++ b/yoga/algorithm/Baseline.cpp @@ -62,4 +62,23 @@ float calculateBaseline(const yoga::Node* node, void* layoutContext) { return baseline + baselineChild->getLayout().position[YGEdgeTop]; } +bool isBaselineLayout(const yoga::Node* node) { + if (isColumn(node->getStyle().flexDirection())) { + return false; + } + if (node->getStyle().alignItems() == YGAlignBaseline) { + return true; + } + const auto childCount = node->getChildCount(); + for (size_t i = 0; i < childCount; i++) { + auto child = node->getChild(i); + if (child->getStyle().positionType() != YGPositionTypeAbsolute && + child->getStyle().alignSelf() == YGAlignBaseline) { + return true; + } + } + + return false; +} + } // namespace facebook::yoga diff --git a/yoga/algorithm/Baseline.h b/yoga/algorithm/Baseline.h index 2e6b015845..71fb3d520d 100644 --- a/yoga/algorithm/Baseline.h +++ b/yoga/algorithm/Baseline.h @@ -15,4 +15,7 @@ namespace facebook::yoga { // Calculate baseline represented as an offset from the top edge of the node. float calculateBaseline(const yoga::Node* node, void* layoutContext); +// Whether any of the children of this node participate in baseline alignment +bool isBaselineLayout(const yoga::Node* node); + } // namespace facebook::yoga diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index cbd75ee047..78766ede93 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -50,25 +50,6 @@ bool calculateLayoutInternal( const uint32_t depth, const uint32_t generationCount); -static bool isBaselineLayout(const yoga::Node* node) { - if (isColumn(node->getStyle().flexDirection())) { - return false; - } - if (node->getStyle().alignItems() == YGAlignBaseline) { - return true; - } - const auto childCount = node->getChildCount(); - for (size_t i = 0; i < childCount; i++) { - auto child = node->getChild(i); - if (child->getStyle().positionType() != YGPositionTypeAbsolute && - child->getStyle().alignSelf() == YGAlignBaseline) { - return true; - } - } - - return false; -} - static inline float dimensionWithMargin( const yoga::Node* const node, const YGFlexDirection axis, From cd419f440b2ec7e3f885db804f10a215021b13e9 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 12 Sep 2023 19:08:28 -0700 Subject: [PATCH 2/3] Remove JNI Binding usage of layoutContext Summary: To avoid keeping a per-node mapping on native Yoga nodes to Java nodes, a per-layout context was added, to be able to pass information from the start of the layout, to measure functions, log functions, etc. The way this was done was super invasive, and added quite a few private APIs used only by the JNI functions. This change removes the context-using functions from the JNI bindings in favor of it managing its own context. Next diff removes all the cruft. Differential Revision: D49179243 fbshipit-source-id: 9f0277187339cc4d123d339fd7580dcd82bcb8fb --- java/jni/LayoutContext.cpp | 34 +++++++++++++++++++++++ java/jni/LayoutContext.h | 29 ++++++++++++++++++++ java/jni/YGJNIVanilla.cpp | 56 ++++++++++++++++---------------------- java/jni/YGJTypesVanilla.h | 2 ++ 4 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 java/jni/LayoutContext.cpp create mode 100644 java/jni/LayoutContext.h diff --git a/java/jni/LayoutContext.cpp b/java/jni/LayoutContext.cpp new file mode 100644 index 0000000000..970812f84b --- /dev/null +++ b/java/jni/LayoutContext.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +#include "LayoutContext.h" + +namespace facebook::yoga::vanillajni { + +namespace { +std::stack& getContexts() { + static thread_local std::stack contexts; + return contexts; +} + +} // namespace + +LayoutContext::Provider::Provider(PtrJNodeMapVanilla* data) { + getContexts().push(data); +} + +LayoutContext::Provider::~Provider() { + getContexts().pop(); +} + +/*static*/ PtrJNodeMapVanilla* LayoutContext::getNodeMap() { + return getContexts().empty() ? nullptr : getContexts().top(); +} + +} // namespace facebook::yoga::vanillajni diff --git a/java/jni/LayoutContext.h b/java/jni/LayoutContext.h new file mode 100644 index 0000000000..476ee82217 --- /dev/null +++ b/java/jni/LayoutContext.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include "YGJTypesVanilla.h" + +namespace facebook::yoga::vanillajni { + +// TODO: This should not be exported or used outside of the JNI bindings +class YG_EXPORT LayoutContext { +public: + // Sets a context on the current thread for the duration of the Provider's + // lifetime. This context should be set during the layout process to allow + // layout callbacks to access context-data specific to the layout pass. + struct Provider { + explicit Provider(PtrJNodeMapVanilla* data); + ~Provider(); + }; + + static PtrJNodeMapVanilla* getNodeMap(); +}; + +} // namespace facebook::yoga::vanillajni diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index 86f740e1f5..747d937ba8 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -14,22 +14,17 @@ #include #include #include "YogaJniException.h" +#include "LayoutContext.h" #include #include -// TODO: Reconcile missing layoutContext functionality from callbacks in the C -// API and use that -#include - using namespace facebook; using namespace facebook::yoga; using namespace facebook::yoga::vanillajni; -static inline ScopedLocalRef YGNodeJobject( - YGNodeConstRef node, - void* layoutContext) { - return reinterpret_cast(layoutContext)->ref(node); +static inline ScopedLocalRef YGNodeJobject(YGNodeConstRef node) { + return LayoutContext::getNodeMap()->ref(node); } static inline YGNodeRef _jlong2YGNodeRef(jlong addr) { @@ -129,7 +124,6 @@ static int YGJNILogFunc( const YGConfigConstRef config, const YGNodeConstRef /*node*/, YGLogLevel level, - void* /*layoutContext*/, const char* format, va_list args) { va_list argsCopy; @@ -187,7 +181,7 @@ static void jni_YGConfigSetLoggerJNI( } *context = newGlobalRef(env, logger); - static_cast(config)->setLogger(YGJNILogFunc); + YGConfigSetLogger(config, YGJNILogFunc); } else { if (context != nullptr) { delete context; @@ -278,12 +272,11 @@ static void jni_YGNodeRemoveChildJNI( static void YGTransferLayoutOutputsRecursive( JNIEnv* env, jobject thiz, - YGNodeRef root, - void* layoutContext) { + YGNodeRef root) { if (!YGNodeGetHasNewLayout(root)) { return; } - auto obj = YGNodeJobject(root, layoutContext); + auto obj = YGNodeJobject(root); if (!obj) { return; } @@ -351,8 +344,7 @@ static void YGTransferLayoutOutputsRecursive( YGNodeSetHasNewLayout(root, false); for (size_t i = 0; i < YGNodeGetChildCount(root); i++) { - YGTransferLayoutOutputsRecursive( - env, thiz, YGNodeGetChild(root, i), layoutContext); + YGTransferLayoutOutputsRecursive(env, thiz, YGNodeGetChild(root, i)); } } @@ -366,21 +358,22 @@ static void jni_YGNodeCalculateLayoutJNI( jobjectArray javaNodes) { try { - void* layoutContext = nullptr; + PtrJNodeMapVanilla* layoutContext = nullptr; auto map = PtrJNodeMapVanilla{}; if (nativePointers) { map = PtrJNodeMapVanilla{nativePointers, javaNodes}; layoutContext = ↦ } + LayoutContext::Provider contextProvider(layoutContext); + const YGNodeRef root = _jlong2YGNodeRef(nativePointer); - YGNodeCalculateLayoutWithContext( + YGNodeCalculateLayout( root, static_cast(width), static_cast(height), - YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)), - layoutContext); - YGTransferLayoutOutputsRecursive(env, obj, root, layoutContext); + YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer))); + YGTransferLayoutOutputsRecursive(env, obj, root); } catch (const YogaJniException& jniException) { ScopedLocalRef throwable = jniException.getThrowable(); if (throwable.get()) { @@ -647,9 +640,8 @@ static YGSize YGJNIMeasureFunc( float width, YGMeasureMode widthMode, float height, - YGMeasureMode heightMode, - void* layoutContext) { - if (auto obj = YGNodeJobject(node, layoutContext)) { + YGMeasureMode heightMode) { + if (auto obj = YGNodeJobject(node)) { YGTransferLayoutDirection(node, obj.get()); JNIEnv* env = getCurrentEnv(); auto objectClass = facebook::yoga::vanillajni::make_local_ref( @@ -683,16 +675,13 @@ static void jni_YGNodeSetHasMeasureFuncJNI( jobject /*obj*/, jlong nativePointer, jboolean hasMeasureFunc) { - static_cast(_jlong2YGNodeRef(nativePointer)) - ->setMeasureFunc(hasMeasureFunc ? YGJNIMeasureFunc : nullptr); + YGNodeSetMeasureFunc( + _jlong2YGNodeRef(nativePointer), + hasMeasureFunc ? YGJNIMeasureFunc : nullptr); } -static float YGJNIBaselineFunc( - YGNodeConstRef node, - float width, - float height, - void* layoutContext) { - if (auto obj = YGNodeJobject(node, layoutContext)) { +static float YGJNIBaselineFunc(YGNodeConstRef node, float width, float height) { + if (auto obj = YGNodeJobject(node)) { JNIEnv* env = getCurrentEnv(); auto objectClass = facebook::yoga::vanillajni::make_local_ref( env, env->GetObjectClass(obj.get())); @@ -710,8 +699,9 @@ static void jni_YGNodeSetHasBaselineFuncJNI( jobject /*obj*/, jlong nativePointer, jboolean hasBaselineFunc) { - static_cast(_jlong2YGNodeRef(nativePointer)) - ->setBaselineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr); + YGNodeSetBaselineFunc( + _jlong2YGNodeRef(nativePointer), + hasBaselineFunc ? YGJNIBaselineFunc : nullptr); } static void jni_YGNodePrintJNI( diff --git a/java/jni/YGJTypesVanilla.h b/java/jni/YGJTypesVanilla.h index e5c44c0cf6..705e1eda6f 100644 --- a/java/jni/YGJTypesVanilla.h +++ b/java/jni/YGJTypesVanilla.h @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +#pragma once + #include #include From 0d3268dc3eaaa00391f614f67aecb7b69a6b2de4 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 12 Sep 2023 19:08:43 -0700 Subject: [PATCH 3/3] Remove layoutContext Drilling (#1376) Summary: X-link: https://github.com/facebook/react-native/pull/39401 Pull Request resolved: https://github.com/facebook/yoga/pull/1376 kill_with_fire_flamethrower Reviewed By: rshest Differential Revision: D49179244 fbshipit-source-id: 4f680ba32d0afb5b0a46621e39d5ad12e2bbbf04 --- tests/EventsTest.cpp | 3 +- tests/YGConfigTest.cpp | 14 +----- tests/YGNodeCallbackTest.cpp | 71 +------------------------- yoga/Yoga-internal.h | 7 --- yoga/Yoga.cpp | 16 ++---- yoga/algorithm/Baseline.cpp | 7 ++- yoga/algorithm/Baseline.h | 2 +- yoga/algorithm/CalculateLayout.cpp | 80 ++++++++---------------------- yoga/algorithm/CalculateLayout.h | 3 +- yoga/config/Config.cpp | 40 +++------------ yoga/config/Config.h | 35 ++----------- yoga/debug/AssertFatal.cpp | 6 +-- yoga/debug/Log.cpp | 18 ++----- yoga/debug/Log.h | 4 +- yoga/event/event.h | 8 --- yoga/node/Node.cpp | 61 +++++++---------------- yoga/node/Node.h | 78 ++++++----------------------- 17 files changed, 83 insertions(+), 370 deletions(-) diff --git a/tests/EventsTest.cpp b/tests/EventsTest.cpp index 7dcee28918..7aa8015df7 100644 --- a/tests/EventsTest.cpp +++ b/tests/EventsTest.cpp @@ -24,7 +24,6 @@ struct TypedEventTestData {}; template <> struct TypedEventTestData { - void* layoutContext; LayoutData layoutData; }; @@ -329,7 +328,7 @@ void EventTest::listen( case Event::LayoutPassEnd: { auto& eventData = data.get(); events.push_back(createArgs( - node, data, {eventData.layoutContext, *eventData.layoutData})); + node, data, {*eventData.layoutData})); break; } diff --git a/tests/YGConfigTest.cpp b/tests/YGConfigTest.cpp index 0a3e128a25..ced84a7069 100644 --- a/tests/YGConfigTest.cpp +++ b/tests/YGConfigTest.cpp @@ -33,7 +33,7 @@ TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) { config->setCloneNodeCallback(cloneNode); yoga::Node node{}, owner{}; - auto clone = config->cloneNode(&node, &owner, 0, nullptr); + auto clone = config->cloneNode(&node, &owner, 0); ASSERT_EQ(clone, &clonedNode); } @@ -44,22 +44,12 @@ TEST_F( config->setCloneNodeCallback(doNotClone); yoga::Node node{}, owner{}; - auto clone = config->cloneNode(&node, &owner, 0, nullptr); + auto clone = config->cloneNode(&node, &owner, 0); ASSERT_NE(clone, nullptr); YGNodeFree(clone); } -TEST_F(ConfigCloningTest, can_clone_with_context) { - config->setCloneNodeCallback( - [](YGNodeConstRef, YGNodeConstRef, size_t, void* context) { - return (YGNodeRef) context; - }); - - yoga::Node node{}, owner{}, clone{}; - ASSERT_EQ(config->cloneNode(&node, &owner, 0, &clone), &clone); -} - void ConfigCloningTest::SetUp() { config = {static_cast(YGConfigNew()), YGConfigFree}; } diff --git a/tests/YGNodeCallbackTest.cpp b/tests/YGNodeCallbackTest.cpp index e599af501b..4f68871c98 100644 --- a/tests/YGNodeCallbackTest.cpp +++ b/tests/YGNodeCallbackTest.cpp @@ -38,38 +38,7 @@ TEST(Node, measure_with_measure_fn) { }); ASSERT_EQ( - n.measure(23, YGMeasureModeExactly, 24, YGMeasureModeAtMost, nullptr), - (YGSize{23, 12})); -} - -TEST(Node, measure_with_context_measure_fn) { - auto n = Node{}; - n.setMeasureFunc([](YGNodeConstRef, - float, - YGMeasureMode, - float, - YGMeasureMode, - void* ctx) { return *(YGSize*) ctx; }); - - auto result = YGSize{123.4f, -56.7f}; - ASSERT_EQ( - n.measure(0, YGMeasureModeUndefined, 0, YGMeasureModeUndefined, &result), - result); -} - -TEST(Node, switching_measure_fn_types) { - auto n = Node{}; - n.setMeasureFunc( - [](YGNodeConstRef, float, YGMeasureMode, float, YGMeasureMode, void*) { - return YGSize{}; - }); - n.setMeasureFunc( - [](YGNodeConstRef, float w, YGMeasureMode wm, float h, YGMeasureMode hm) { - return YGSize{w * static_cast(wm), h / static_cast(hm)}; - }); - - ASSERT_EQ( - n.measure(23, YGMeasureModeExactly, 24, YGMeasureModeAtMost, nullptr), + n.measure(23, YGMeasureModeExactly, 24, YGMeasureModeAtMost), (YGSize{23, 12})); } @@ -84,17 +53,6 @@ TEST(Node, hasMeasureFunc_after_unset) { ASSERT_FALSE(n.hasMeasureFunc()); } -TEST(Node, hasMeasureFunc_after_unset_context) { - auto n = Node{}; - n.setMeasureFunc( - [](YGNodeConstRef, float, YGMeasureMode, float, YGMeasureMode, void*) { - return YGSize{}; - }); - - n.setMeasureFunc(nullptr); - ASSERT_FALSE(n.hasMeasureFunc()); -} - TEST(Node, hasBaselineFunc_initial) { auto n = Node{}; ASSERT_FALSE(n.hasBaselineFunc()); @@ -110,17 +68,7 @@ TEST(Node, baseline_with_baseline_fn) { auto n = Node{}; n.setBaselineFunc([](YGNodeConstRef, float w, float h) { return w + h; }); - ASSERT_EQ(n.baseline(1.25f, 2.5f, nullptr), 3.75f); -} - -TEST(Node, baseline_with_context_baseline_fn) { - auto n = Node{}; - n.setBaselineFunc([](YGNodeConstRef, float w, float h, void* ctx) { - return w + h + *(float*) ctx; - }); - - auto ctx = -10.0f; - ASSERT_EQ(n.baseline(1.25f, 2.5f, &ctx), -6.25f); + ASSERT_EQ(n.baseline(1.25f, 2.5f), 3.75f); } TEST(Node, hasBaselineFunc_after_unset) { @@ -130,18 +78,3 @@ TEST(Node, hasBaselineFunc_after_unset) { n.setBaselineFunc(nullptr); ASSERT_FALSE(n.hasBaselineFunc()); } - -TEST(Node, hasBaselineFunc_after_unset_context) { - auto n = Node{}; - n.setBaselineFunc([](YGNodeConstRef, float, float, void*) { return 0.0f; }); - - n.setMeasureFunc(nullptr); - ASSERT_FALSE(n.hasMeasureFunc()); -} - -TEST(Node, switching_baseline_fn_types) { - auto n = Node{}; - n.setBaselineFunc([](YGNodeConstRef, float, float, void*) { return 0.0f; }); - n.setBaselineFunc([](YGNodeConstRef, float, float) { return 1.0f; }); - ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f); -} diff --git a/yoga/Yoga-internal.h b/yoga/Yoga-internal.h index 5ad0dd6937..7c1caaa378 100644 --- a/yoga/Yoga-internal.h +++ b/yoga/Yoga-internal.h @@ -15,13 +15,6 @@ YG_EXTERN_C_BEGIN -YG_EXPORT void YGNodeCalculateLayoutWithContext( - YGNodeRef node, - float availableWidth, - float availableHeight, - YGDirection ownerDirection, - void* layoutContext); - // Deallocates a Yoga Node. Unlike YGNodeFree, does not remove the node from // its parent or children. YG_EXPORT void YGNodeDeallocate(YGNodeRef node); diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 5c5f6a8cca..c8eff1ece3 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -57,7 +57,7 @@ void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc) { } YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeConstRef node) { - return resolveRef(node)->getDirtied(); + return resolveRef(node)->getDirtiedFunc(); } void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc) { @@ -805,7 +805,7 @@ void YGNodePrint(const YGNodeConstRef nodeRef, const YGPrintOptions options) { const auto node = resolveRef(nodeRef); std::string str; yoga::nodeToString(str, node, options, 0); - yoga::log(node, YGLogLevelDebug, nullptr, str.c_str()); + yoga::log(node, YGLogLevelDebug, str.c_str()); } #endif @@ -927,16 +927,6 @@ void YGNodeCalculateLayout( const float ownerWidth, const float ownerHeight, const YGDirection ownerDirection) { - YGNodeCalculateLayoutWithContext( - node, ownerWidth, ownerHeight, ownerDirection, nullptr); -} - -void YGNodeCalculateLayoutWithContext( - const YGNodeRef node, - const float ownerWidth, - const float ownerHeight, - const YGDirection ownerDirection, - void* layoutContext) { yoga::calculateLayout( - resolveRef(node), ownerWidth, ownerHeight, ownerDirection, layoutContext); + resolveRef(node), ownerWidth, ownerHeight, ownerDirection); } diff --git a/yoga/algorithm/Baseline.cpp b/yoga/algorithm/Baseline.cpp index 1cbfbd1883..a3fd42c577 100644 --- a/yoga/algorithm/Baseline.cpp +++ b/yoga/algorithm/Baseline.cpp @@ -14,15 +14,14 @@ namespace facebook::yoga { -float calculateBaseline(const yoga::Node* node, void* layoutContext) { +float calculateBaseline(const yoga::Node* node) { if (node->hasBaselineFunc()) { Event::publish(node); const float baseline = node->baseline( node->getLayout().measuredDimensions[YGDimensionWidth], - node->getLayout().measuredDimensions[YGDimensionHeight], - layoutContext); + node->getLayout().measuredDimensions[YGDimensionHeight]); Event::publish(node); @@ -58,7 +57,7 @@ float calculateBaseline(const yoga::Node* node, void* layoutContext) { return node->getLayout().measuredDimensions[YGDimensionHeight]; } - const float baseline = calculateBaseline(baselineChild, layoutContext); + const float baseline = calculateBaseline(baselineChild); return baseline + baselineChild->getLayout().position[YGEdgeTop]; } diff --git a/yoga/algorithm/Baseline.h b/yoga/algorithm/Baseline.h index 71fb3d520d..c95ffd0f04 100644 --- a/yoga/algorithm/Baseline.h +++ b/yoga/algorithm/Baseline.h @@ -13,7 +13,7 @@ namespace facebook::yoga { // Calculate baseline represented as an offset from the top edge of the node. -float calculateBaseline(const yoga::Node* node, void* layoutContext); +float calculateBaseline(const yoga::Node* node); // Whether any of the children of this node participate in baseline alignment bool isBaselineLayout(const yoga::Node* node); diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index 78766ede93..c91b30391b 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -46,7 +46,6 @@ bool calculateLayoutInternal( const LayoutPassReason reason, const yoga::Config* const config, LayoutData& layoutMarkerData, - void* const layoutContext, const uint32_t depth, const uint32_t generationCount); @@ -134,7 +133,6 @@ static void computeFlexBasisForChild( const YGDirection direction, const yoga::Config* const config, LayoutData& layoutMarkerData, - void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { const YGFlexDirection mainAxis = @@ -309,7 +307,6 @@ static void computeFlexBasisForChild( LayoutPassReason::kMeasureChild, config, layoutMarkerData, - layoutContext, depth, generationCount); @@ -329,7 +326,6 @@ static void layoutAbsoluteChild( const YGDirection direction, const yoga::Config* const config, LayoutData& layoutMarkerData, - void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { const YGFlexDirection mainAxis = @@ -437,7 +433,6 @@ static void layoutAbsoluteChild( LayoutPassReason::kAbsMeasureChild, config, layoutMarkerData, - layoutContext, depth, generationCount); childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] + @@ -459,7 +454,6 @@ static void layoutAbsoluteChild( LayoutPassReason::kAbsLayout, config, layoutMarkerData, - layoutContext, depth, generationCount); @@ -564,7 +558,6 @@ static void measureNodeWithMeasureFunc( const float ownerWidth, const float ownerHeight, LayoutData& layoutMarkerData, - void* const layoutContext, const LayoutPassReason reason) { yoga::assertFatalWithNode( node, @@ -613,11 +606,7 @@ static void measureNodeWithMeasureFunc( // Measure the text under the current constraints. const YGSize measuredSize = node->measure( - innerWidth, - widthMeasureMode, - innerHeight, - heightMeasureMode, - layoutContext); + innerWidth, widthMeasureMode, innerHeight, heightMeasureMode); layoutMarkerData.measureCallbacks += 1; layoutMarkerData.measureCallbackReasonsCount[static_cast(reason)] += @@ -625,8 +614,7 @@ static void measureNodeWithMeasureFunc( Event::publish( node, - {layoutContext, - innerWidth, + {innerWidth, widthMeasureMode, innerHeight, heightMeasureMode, @@ -739,17 +727,15 @@ static bool measureNodeWithFixedSize( return false; } -static void zeroOutLayoutRecursively( - yoga::Node* const node, - void* layoutContext) { +static void zeroOutLayoutRecursively(yoga::Node* const node) { node->getLayout() = {}; node->setLayoutDimension(0, YGDimensionWidth); node->setLayoutDimension(0, YGDimensionHeight); node->setHasNewLayout(true); - node->cloneChildrenIfNeeded(layoutContext); + node->cloneChildrenIfNeeded(); for (const auto child : node->getChildren()) { - zeroOutLayoutRecursively(child, layoutContext); + zeroOutLayoutRecursively(child); } } @@ -795,7 +781,6 @@ static float computeFlexBasisForChildren( const yoga::Config* const config, bool performLayout, LayoutData& layoutMarkerData, - void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { float totalOuterFlexBasis = 0.0f; @@ -826,7 +811,7 @@ static float computeFlexBasisForChildren( for (auto child : children) { child->resolveDimension(); if (child->getStyle().display() == YGDisplayNone) { - zeroOutLayoutRecursively(child, layoutContext); + zeroOutLayoutRecursively(child); child->setHasNewLayout(true); child->setDirty(false); continue; @@ -861,7 +846,6 @@ static float computeFlexBasisForChildren( direction, config, layoutMarkerData, - layoutContext, depth, generationCount); } @@ -894,7 +878,6 @@ static float distributeFreeSpaceSecondPass( const bool performLayout, const yoga::Config* const config, LayoutData& layoutMarkerData, - void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { float childFlexBasis = 0; @@ -1059,7 +1042,6 @@ static float distributeFreeSpaceSecondPass( : LayoutPassReason::kFlexMeasure, config, layoutMarkerData, - layoutContext, depth, generationCount); node->setLayoutHadOverflow( @@ -1192,7 +1174,6 @@ static void resolveFlexibleLength( const bool performLayout, const yoga::Config* const config, LayoutData& layoutMarkerData, - void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { const float originalFreeSpace = flexLine.layout.remainingFreeSpace; @@ -1220,7 +1201,6 @@ static void resolveFlexibleLength( performLayout, config, layoutMarkerData, - layoutContext, depth, generationCount); @@ -1240,8 +1220,7 @@ static void YGJustifyMainAxis( const float availableInnerMainDim, const float availableInnerCrossDim, const float availableInnerWidth, - const bool performLayout, - void* const layoutContext) { + const bool performLayout) { const auto& style = node->getStyle(); const float leadingPaddingAndBorderMain = node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); @@ -1400,7 +1379,7 @@ static void YGJustifyMainAxis( if (isNodeBaselineLayout) { // If the child is baseline aligned then the cross dimension is // calculated by adding maxAscent and maxDescent from the baseline. - const float ascent = calculateBaseline(child, layoutContext) + + const float ascent = calculateBaseline(child) + child ->getLeadingMargin( YGFlexDirectionColumn, availableInnerWidth) @@ -1519,7 +1498,6 @@ static void calculateLayoutImpl( const bool performLayout, const yoga::Config* const config, LayoutData& layoutMarkerData, - void* const layoutContext, const uint32_t depth, const uint32_t generationCount, const LayoutPassReason reason) { @@ -1597,7 +1575,6 @@ static void calculateLayoutImpl( ownerWidth, ownerHeight, layoutMarkerData, - layoutContext, reason); return; } @@ -1631,7 +1608,7 @@ static void calculateLayoutImpl( // At this point we know we're going to perform work. Ensure that each child // has a mutable copy. - node->cloneChildrenIfNeeded(layoutContext); + node->cloneChildrenIfNeeded(); // Reset layout flags, as they could have changed. node->setLayoutHadOverflow(false); @@ -1699,7 +1676,6 @@ static void calculateLayoutImpl( config, performLayout, layoutMarkerData, - layoutContext, depth, generationCount); @@ -1838,7 +1814,6 @@ static void calculateLayoutImpl( performLayout, config, layoutMarkerData, - layoutContext, depth, generationCount); } @@ -1867,8 +1842,7 @@ static void calculateLayoutImpl( availableInnerMainDim, availableInnerCrossDim, availableInnerWidth, - performLayout, - layoutContext); + performLayout); float containerCrossAxis = availableInnerCrossDim; if (measureModeCrossDim == YGMeasureModeUndefined || @@ -2015,7 +1989,6 @@ static void calculateLayoutImpl( LayoutPassReason::kStretch, config, layoutMarkerData, - layoutContext, depth, generationCount); } @@ -2127,7 +2100,7 @@ static void calculateLayoutImpl( .unwrap()); } if (resolveChildAlignment(node, child) == YGAlignBaseline) { - const float ascent = calculateBaseline(child, layoutContext) + + const float ascent = calculateBaseline(child) + child ->getLeadingMargin( YGFlexDirectionColumn, availableInnerWidth) @@ -2233,7 +2206,6 @@ static void calculateLayoutImpl( LayoutPassReason::kMultilineStretch, config, layoutMarkerData, - layoutContext, depth, generationCount); } @@ -2243,7 +2215,7 @@ static void calculateLayoutImpl( case YGAlignBaseline: { child->setLayoutPosition( currentLead + maxAscentForCurrentLine - - calculateBaseline(child, layoutContext) + + calculateBaseline(child) + child ->getLeadingPosition( YGFlexDirectionColumn, availableInnerCrossDim) @@ -2384,7 +2356,6 @@ static void calculateLayoutImpl( direction, config, layoutMarkerData, - layoutContext, depth, generationCount); } @@ -2465,7 +2436,6 @@ bool calculateLayoutInternal( const LayoutPassReason reason, const yoga::Config* const config, LayoutData& layoutMarkerData, - void* const layoutContext, uint32_t depth, const uint32_t generationCount) { LayoutResults* layout = &node->getLayout(); @@ -2577,15 +2547,13 @@ bool calculateLayoutInternal( yoga::log( node, YGLogLevelVerbose, - nullptr, "%s%d.{[skipped] ", spacerWithLength(depth), depth); - node->print(layoutContext); + node->print(); yoga::log( node, YGLogLevelVerbose, - nullptr, "wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n", measureModeName(widthMeasureMode, performLayout), measureModeName(heightMeasureMode, performLayout), @@ -2600,16 +2568,14 @@ bool calculateLayoutInternal( yoga::log( node, YGLogLevelVerbose, - nullptr, "%s%d.{%s", spacerWithLength(depth), depth, needToVisitNode ? "*" : ""); - node->print(layoutContext); + node->print(); yoga::log( node, YGLogLevelVerbose, - nullptr, "wm: %s, hm: %s, aw: %f ah: %f %s\n", measureModeName(widthMeasureMode, performLayout), measureModeName(heightMeasureMode, performLayout), @@ -2630,7 +2596,6 @@ bool calculateLayoutInternal( performLayout, config, layoutMarkerData, - layoutContext, depth, generationCount, reason); @@ -2639,16 +2604,14 @@ bool calculateLayoutInternal( yoga::log( node, YGLogLevelVerbose, - nullptr, "%s%d.}%s", spacerWithLength(depth), depth, needToVisitNode ? "*" : ""); - node->print(layoutContext); + node->print(); yoga::log( node, YGLogLevelVerbose, - nullptr, "wm: %s, hm: %s, d: (%f, %f) %s\n", measureModeName(widthMeasureMode, performLayout), measureModeName(heightMeasureMode, performLayout), @@ -2668,8 +2631,7 @@ bool calculateLayoutInternal( if (layout->nextCachedMeasurementsIndex == LayoutResults::MaxCachedMeasurements) { if (gPrintChanges) { - yoga::log( - node, YGLogLevelVerbose, nullptr, "Out of cache entries!\n"); + yoga::log(node, YGLogLevelVerbose, "Out of cache entries!\n"); } layout->nextCachedMeasurementsIndex = 0; } @@ -2719,7 +2681,7 @@ bool calculateLayoutInternal( layoutType = cachedResults != nullptr ? LayoutType::kCachedMeasure : LayoutType::kMeasure; } - Event::publish(node, {layoutType, layoutContext}); + Event::publish(node, {layoutType}); return (needToVisitNode || cachedResults == nullptr); } @@ -2728,9 +2690,8 @@ void calculateLayout( yoga::Node* const node, const float ownerWidth, const float ownerHeight, - const YGDirection ownerDirection, - void* layoutContext) { - Event::publish(node, {layoutContext}); + const YGDirection ownerDirection) { + Event::publish(node); LayoutData markerData = {}; // Increment the generation count. This will force the recursive routine to @@ -2791,7 +2752,6 @@ void calculateLayout( LayoutPassReason::kInitial, node->getConfig(), markerData, - layoutContext, 0, // tree root gCurrentGenerationCount.load(std::memory_order_relaxed))) { node->setPosition( @@ -2808,7 +2768,7 @@ void calculateLayout( #endif } - Event::publish(node, {layoutContext, &markerData}); + Event::publish(node, {&markerData}); } } // namespace facebook::yoga diff --git a/yoga/algorithm/CalculateLayout.h b/yoga/algorithm/CalculateLayout.h index e12dcc0dda..b93dd5da37 100644 --- a/yoga/algorithm/CalculateLayout.h +++ b/yoga/algorithm/CalculateLayout.h @@ -16,7 +16,6 @@ void calculateLayout( yoga::Node* const node, const float ownerWidth, const float ownerHeight, - const YGDirection ownerDirection, - void* layoutContext); + const YGDirection ownerDirection); } // namespace facebook::yoga diff --git a/yoga/config/Config.cpp b/yoga/config/Config.cpp index f3b28ffae0..e86c76017b 100644 --- a/yoga/config/Config.cpp +++ b/yoga/config/Config.cpp @@ -91,56 +91,28 @@ void* Config::getContext() const { } void Config::setLogger(YGLogger logger) { - logger_.noContext = logger; - flags_.loggerUsesContext = false; -} - -void Config::setLogger(LogWithContextFn logger) { - logger_.withContext = logger; - flags_.loggerUsesContext = true; -} - -void Config::setLogger(std::nullptr_t) { - setLogger(YGLogger{nullptr}); + logger_ = logger; } void Config::log( const yoga::Node* node, YGLogLevel logLevel, - void* logContext, const char* format, va_list args) const { - if (flags_.loggerUsesContext) { - logger_.withContext(this, node, logLevel, logContext, format, args); - } else { - logger_.noContext(this, node, logLevel, format, args); - } + logger_(this, node, logLevel, format, args); } void Config::setCloneNodeCallback(YGCloneNodeFunc cloneNode) { - cloneNodeCallback_.noContext = cloneNode; - flags_.cloneNodeUsesContext = false; -} - -void Config::setCloneNodeCallback(CloneWithContextFn cloneNode) { - cloneNodeCallback_.withContext = cloneNode; - flags_.cloneNodeUsesContext = true; -} - -void Config::setCloneNodeCallback(std::nullptr_t) { - setCloneNodeCallback(YGCloneNodeFunc{nullptr}); + cloneNodeCallback_ = cloneNode; } YGNodeRef Config::cloneNode( YGNodeConstRef node, YGNodeConstRef owner, - size_t childIndex, - void* cloneContext) const { + size_t childIndex) const { YGNodeRef clone = nullptr; - if (cloneNodeCallback_.noContext != nullptr) { - clone = flags_.cloneNodeUsesContext - ? cloneNodeCallback_.withContext(node, owner, childIndex, cloneContext) - : cloneNodeCallback_.noContext(node, owner, childIndex); + if (cloneNodeCallback_ != nullptr) { + clone = cloneNodeCallback_(node, owner, childIndex); } if (clone == nullptr) { clone = YGNodeClone(node); diff --git a/yoga/config/Config.h b/yoga/config/Config.h index dfea29c588..67a0299f71 100644 --- a/yoga/config/Config.h +++ b/yoga/config/Config.h @@ -24,29 +24,12 @@ bool configUpdateInvalidatesLayout( const Config& oldConfig, const Config& newConfig); -// Internal variants of log functions, currently used only by JNI bindings. -// TODO: Reconcile this with the public API -using LogWithContextFn = int (*)( - YGConfigConstRef config, - YGNodeConstRef node, - YGLogLevel level, - void* context, - const char* format, - va_list args); -using CloneWithContextFn = YGNodeRef (*)( - YGNodeConstRef node, - YGNodeConstRef owner, - size_t childIndex, - void* cloneContext); - #pragma pack(push) #pragma pack(1) // Packed structure of <32-bit options to miminize size per node. struct ConfigFlags { bool useWebDefaults : 1; bool printTree : 1; - bool cloneNodeUsesContext : 1; - bool loggerUsesContext : 1; }; #pragma pack(pop) @@ -79,35 +62,23 @@ class YG_EXPORT Config : public ::YGConfig { void* getContext() const; void setLogger(YGLogger logger); - void setLogger(LogWithContextFn logger); - void setLogger(std::nullptr_t); void log( const yoga::Node* node, YGLogLevel logLevel, - void* logContext, const char* format, va_list args) const; void setCloneNodeCallback(YGCloneNodeFunc cloneNode); - void setCloneNodeCallback(CloneWithContextFn cloneNode); - void setCloneNodeCallback(std::nullptr_t); YGNodeRef cloneNode( YGNodeConstRef node, YGNodeConstRef owner, - size_t childIndex, - void* cloneContext) const; + size_t childIndex) const; static const Config& getDefault(); private: - union { - CloneWithContextFn withContext; - YGCloneNodeFunc noContext; - } cloneNodeCallback_; - union { - LogWithContextFn withContext; - YGLogger noContext; - } logger_; + YGCloneNodeFunc cloneNodeCallback_; + YGLogger logger_; ConfigFlags flags_{}; EnumBitset experimentalFeatures_{}; diff --git a/yoga/debug/AssertFatal.cpp b/yoga/debug/AssertFatal.cpp index bc85235a85..d83c8cc56e 100644 --- a/yoga/debug/AssertFatal.cpp +++ b/yoga/debug/AssertFatal.cpp @@ -22,7 +22,7 @@ namespace facebook::yoga { void assertFatal(const bool condition, const char* message) { if (!condition) { - yoga::log(YGLogLevelFatal, nullptr, "%s\n", message); + yoga::log(YGLogLevelFatal, "%s\n", message); fatalWithMessage(message); } } @@ -32,7 +32,7 @@ void assertFatalWithNode( const bool condition, const char* message) { if (!condition) { - yoga::log(node, YGLogLevelFatal, nullptr, "%s\n", message); + yoga::log(node, YGLogLevelFatal, "%s\n", message); fatalWithMessage(message); } } @@ -42,7 +42,7 @@ void assertFatalWithConfig( const bool condition, const char* message) { if (!condition) { - yoga::log(config, YGLogLevelFatal, nullptr, "%s\n", message); + yoga::log(config, YGLogLevelFatal, "%s\n", message); fatalWithMessage(message); } } diff --git a/yoga/debug/Log.cpp b/yoga/debug/Log.cpp index 675c1ebd4c..c16547ae34 100644 --- a/yoga/debug/Log.cpp +++ b/yoga/debug/Log.cpp @@ -19,51 +19,43 @@ void vlog( const yoga::Config* config, const yoga::Node* node, YGLogLevel level, - void* context, const char* format, va_list args) { if (config == nullptr) { getDefaultLogger()(nullptr, node, level, format, args); } else { - config->log(node, level, context, format, args); + config->log(node, level, format, args); } } } // namespace -void log(YGLogLevel level, void* context, const char* format, ...) noexcept { +void log(YGLogLevel level, const char* format, ...) noexcept { va_list args; va_start(args, format); - vlog(nullptr, nullptr, level, context, format, args); + vlog(nullptr, nullptr, level, format, args); va_end(args); } void log( const yoga::Node* node, YGLogLevel level, - void* context, const char* format, ...) noexcept { va_list args; va_start(args, format); vlog( - node == nullptr ? nullptr : node->getConfig(), - node, - level, - context, - format, - args); + node == nullptr ? nullptr : node->getConfig(), node, level, format, args); va_end(args); } void log( const yoga::Config* config, YGLogLevel level, - void* context, const char* format, ...) noexcept { va_list args; va_start(args, format); - vlog(config, nullptr, level, context, format, args); + vlog(config, nullptr, level, format, args); va_end(args); } diff --git a/yoga/debug/Log.h b/yoga/debug/Log.h index 54f10c4b04..a595eba824 100644 --- a/yoga/debug/Log.h +++ b/yoga/debug/Log.h @@ -15,19 +15,17 @@ namespace facebook::yoga { -void log(YGLogLevel level, void*, const char* format, ...) noexcept; +void log(YGLogLevel level, const char* format, ...) noexcept; void log( const yoga::Node* node, YGLogLevel level, - void*, const char* message, ...) noexcept; void log( const yoga::Config* config, YGLogLevel level, - void*, const char* format, ...) noexcept; diff --git a/yoga/event/event.h b/yoga/event/event.h index 3335954032..2969f26d02 100644 --- a/yoga/event/event.h +++ b/yoga/event/event.h @@ -103,20 +103,13 @@ struct Event::TypedData { YGConfigConstRef config; }; -template <> -struct Event::TypedData { - void* layoutContext; -}; - template <> struct Event::TypedData { - void* layoutContext; LayoutData* layoutData; }; template <> struct Event::TypedData { - void* layoutContext; float width; YGMeasureMode widthMeasureMode; float height; @@ -129,7 +122,6 @@ struct Event::TypedData { template <> struct Event::TypedData { LayoutType layoutType; - void* layoutContext; }; } // namespace facebook::yoga diff --git a/yoga/node/Node.cpp b/yoga/node/Node.cpp index ac6a5b88f7..da3438d2f3 100644 --- a/yoga/node/Node.cpp +++ b/yoga/node/Node.cpp @@ -32,10 +32,10 @@ Node::Node(const yoga::Config* config) : config_{config} { Node::Node(Node&& node) { context_ = node.context_; flags_ = node.flags_; - measure_ = node.measure_; - baseline_ = node.baseline_; - print_ = node.print_; - dirtied_ = node.dirtied_; + measureFunc_ = node.measureFunc_; + baselineFunc_ = node.baselineFunc_; + printFunc_ = node.printFunc_; + dirtiedFunc_ = node.dirtiedFunc_; style_ = node.style_; layout_ = node.layout_; lineIndex_ = node.lineIndex_; @@ -48,13 +48,9 @@ Node::Node(Node&& node) { } } -void Node::print(void* printContext) { - if (print_.noContext != nullptr) { - if (flags_.printUsesContext) { - print_.withContext(this, printContext); - } else { - print_.noContext(this); - } +void Node::print() { + if (printFunc_ != nullptr) { + printFunc_(this); } } @@ -217,25 +213,18 @@ YGSize Node::measure( float width, YGMeasureMode widthMode, float height, - YGMeasureMode heightMode, - void* layoutContext) { - return flags_.measureUsesContext - ? measure_.withContext( - this, width, widthMode, height, heightMode, layoutContext) - : measure_.noContext(this, width, widthMode, height, heightMode); + YGMeasureMode heightMode) { + return measureFunc_(this, width, widthMode, height, heightMode); } -float Node::baseline(float width, float height, void* layoutContext) const { - return flags_.baselineUsesContext - ? baseline_.withContext( - const_cast(this), width, height, layoutContext) - : baseline_.noContext(const_cast(this), width, height); +float Node::baseline(float width, float height) const { + return baselineFunc_(this, width, height); } // Setters -void Node::setMeasureFunc(decltype(Node::measure_) measureFunc) { - if (measureFunc.noContext == nullptr) { +void Node::setMeasureFunc(YGMeasureFunc measureFunc) { + if (measureFunc == nullptr) { // TODO: t18095186 Move nodeType to opt-in function and mark appropriate // places in Litho setNodeType(YGNodeTypeDefault); @@ -250,21 +239,7 @@ void Node::setMeasureFunc(decltype(Node::measure_) measureFunc) { setNodeType(YGNodeTypeText); } - measure_ = measureFunc; -} - -void Node::setMeasureFunc(YGMeasureFunc measureFunc) { - flags_.measureUsesContext = false; - decltype(Node::measure_) m; - m.noContext = measureFunc; - setMeasureFunc(m); -} - -void Node::setMeasureFunc(MeasureWithContextFn measureFunc) { - flags_.measureUsesContext = true; - decltype(Node::measure_) m; - m.withContext = measureFunc; - setMeasureFunc(m); + measureFunc_ = measureFunc; } void Node::replaceChild(Node* child, size_t index) { @@ -299,8 +274,8 @@ void Node::setDirty(bool isDirty) { return; } flags_.isDirty = isDirty; - if (isDirty && dirtied_) { - dirtied_(this); + if (isDirty && dirtiedFunc_) { + dirtiedFunc_(this); } } @@ -485,11 +460,11 @@ void Node::clearChildren() { // Other Methods -void Node::cloneChildrenIfNeeded(void* cloneContext) { +void Node::cloneChildrenIfNeeded() { size_t i = 0; for (Node*& child : children_) { if (child->getOwner() != this) { - child = resolveRef(config_->cloneNode(child, this, i, cloneContext)); + child = resolveRef(config_->cloneNode(child, this, i)); child->setOwner(this); } i += 1; diff --git a/yoga/node/Node.h b/yoga/node/Node.h index e749179122..37f18a5a70 100644 --- a/yoga/node/Node.h +++ b/yoga/node/Node.h @@ -30,42 +30,17 @@ struct NodeFlags { bool isReferenceBaseline : 1; bool isDirty : 1; uint32_t nodeType : 1; - bool measureUsesContext : 1; - bool baselineUsesContext : 1; - bool printUsesContext : 1; }; #pragma pack(pop) class YG_EXPORT Node : public ::YGNode { -public: - // Internal variants of callbacks, currently used only by JNI bindings. - // TODO: Reconcile this with the public API - using MeasureWithContextFn = YGSize (*)( - YGNodeConstRef, - float, - YGMeasureMode, - float, - YGMeasureMode, - void*); - using BaselineWithContextFn = float (*)(YGNodeConstRef, float, float, void*); - using PrintWithContextFn = void (*)(YGNodeConstRef, void*); - private: void* context_ = nullptr; NodeFlags flags_ = {}; - union { - YGMeasureFunc noContext; - MeasureWithContextFn withContext; - } measure_ = {nullptr}; - union { - YGBaselineFunc noContext; - BaselineWithContextFn withContext; - } baseline_ = {nullptr}; - union { - YGPrintFunc noContext; - PrintWithContextFn withContext; - } print_ = {nullptr}; - YGDirtiedFunc dirtied_ = nullptr; + YGMeasureFunc measureFunc_ = {nullptr}; + YGBaselineFunc baselineFunc_ = {nullptr}; + YGPrintFunc printFunc_ = {nullptr}; + YGDirtiedFunc dirtiedFunc_ = nullptr; Style style_ = {}; LayoutResults layout_ = {}; size_t lineIndex_ = 0; @@ -79,9 +54,6 @@ class YG_EXPORT Node : public ::YGNode { const YGFlexDirection axis, const float axisSize) const; - void setMeasureFunc(decltype(measure_)); - void setBaselineFunc(decltype(baseline_)); - void useWebDefaults() { style_.flexDirection() = YGFlexDirectionRow; style_.alignContent() = YGAlignStretch; @@ -112,7 +84,7 @@ class YG_EXPORT Node : public ::YGNode { // Getters void* getContext() const { return context_; } - void print(void*); + void print(); bool getHasNewLayout() const { return flags_.hasNewLayout; } @@ -120,19 +92,17 @@ class YG_EXPORT Node : public ::YGNode { return static_cast(flags_.nodeType); } - bool hasMeasureFunc() const noexcept { return measure_.noContext != nullptr; } + bool hasMeasureFunc() const noexcept { return measureFunc_ != nullptr; } - YGSize measure(float, YGMeasureMode, float, YGMeasureMode, void*); + YGSize measure(float, YGMeasureMode, float, YGMeasureMode); - bool hasBaselineFunc() const noexcept { - return baseline_.noContext != nullptr; - } + bool hasBaselineFunc() const noexcept { return baselineFunc_ != nullptr; } - float baseline(float width, float height, void* layoutContext) const; + float baseline(float width, float height) const; bool hasErrata(YGErrata errata) const { return config_->hasErrata(errata); } - YGDirtiedFunc getDirtied() const { return dirtied_; } + YGDirtiedFunc getDirtiedFunc() const { return dirtiedFunc_; } // For Performance reasons passing as reference. Style& getStyle() { return style_; } @@ -232,15 +202,7 @@ class YG_EXPORT Node : public ::YGNode { void setContext(void* context) { context_ = context; } - void setPrintFunc(YGPrintFunc printFunc) { - print_.noContext = printFunc; - flags_.printUsesContext = false; - } - void setPrintFunc(PrintWithContextFn printFunc) { - print_.withContext = printFunc; - flags_.printUsesContext = true; - } - void setPrintFunc(std::nullptr_t) { setPrintFunc(YGPrintFunc{nullptr}); } + void setPrintFunc(YGPrintFunc printFunc) { printFunc_ = printFunc; } void setHasNewLayout(bool hasNewLayout) { flags_.hasNewLayout = hasNewLayout; @@ -251,24 +213,12 @@ class YG_EXPORT Node : public ::YGNode { } void setMeasureFunc(YGMeasureFunc measureFunc); - void setMeasureFunc(MeasureWithContextFn); - void setMeasureFunc(std::nullptr_t) { - return setMeasureFunc(YGMeasureFunc{nullptr}); - } void setBaselineFunc(YGBaselineFunc baseLineFunc) { - flags_.baselineUsesContext = false; - baseline_.noContext = baseLineFunc; - } - void setBaselineFunc(BaselineWithContextFn baseLineFunc) { - flags_.baselineUsesContext = true; - baseline_.withContext = baseLineFunc; - } - void setBaselineFunc(std::nullptr_t) { - return setBaselineFunc(YGBaselineFunc{nullptr}); + baselineFunc_ = baseLineFunc; } - void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtied_ = dirtiedFunc; } + void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtiedFunc_ = dirtiedFunc; } void setStyle(const Style& style) { style_ = style; } @@ -325,7 +275,7 @@ class YG_EXPORT Node : public ::YGNode { bool removeChild(Node* child); void removeChild(size_t index); - void cloneChildrenIfNeeded(void*); + void cloneChildrenIfNeeded(); void markDirtyAndPropagate(); float resolveFlexGrow() const; float resolveFlexShrink() const;