Remove legacy layout diffing

Summary:
This removes some unused flags which will cause Yoga to layout every tree twice, then diffing the tree, reporting whether the whole tree is different. This is too expensive to run outside of local experimentation, but we have more nuanced ways to implement the `YGNodeLayoutAffectedByQuirk` I am wanting to add.

Changelog: [Internal]

Reviewed By: lunaleaps

Differential Revision: D42406917

fbshipit-source-id: b415ed02768f6b59de3a6fa90c60c750d56fd4b0
This commit is contained in:
Nick Gerleman
2023-01-19 06:38:45 -08:00
committed by Facebook GitHub Bot
parent cac197f5a6
commit 9e1bcd8557
13 changed files with 1 additions and 364 deletions

View File

@@ -25,14 +25,6 @@ public abstract class YogaConfig {
*/ */
public abstract void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour); public abstract void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour);
/**
* If this flag is set then yoga would diff the layout without legacy flag and would set a bool in
* YogaNode(mDoesLegacyStretchFlagAffectsLayout) with true if the layouts were different and false
* if not
*/
public abstract void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
public abstract void setLogger(YogaLogger logger); public abstract void setLogger(YogaLogger logger);
public abstract YogaLogger getLogger(); public abstract YogaLogger getLogger();

View File

@@ -52,17 +52,6 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviourJNI(mNativePointer, useLegacyStretchBehaviour); YogaNative.jni_YGConfigSetUseLegacyStretchBehaviourJNI(mNativePointer, useLegacyStretchBehaviour);
} }
/**
* If this flag is set then yoga would diff the layout without legacy flag and would set a bool in
* YogaNode(mDoesLegacyStretchFlagAffectsLayout) with true if the layouts were different and false
* if not
*/
public void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour) {
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI(
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
}
public void setLogger(YogaLogger logger) { public void setLogger(YogaLogger logger) {
mLogger = logger; mLogger = logger;
YogaNative.jni_YGConfigSetLoggerJNI(mNativePointer, logger); YogaNative.jni_YGConfigSetLoggerJNI(mNativePointer, logger);

View File

@@ -25,7 +25,6 @@ public class YogaNative {
static native void jni_YGConfigSetPrintTreeFlagJNI(long nativePointer, boolean enable); static native void jni_YGConfigSetPrintTreeFlagJNI(long nativePointer, boolean enable);
static native void jni_YGConfigSetPointScaleFactorJNI(long nativePointer, float pixelsInPoint); static native void jni_YGConfigSetPointScaleFactorJNI(long nativePointer, float pixelsInPoint);
static native void jni_YGConfigSetUseLegacyStretchBehaviourJNI(long nativePointer, boolean useLegacyStretchBehaviour); static native void jni_YGConfigSetUseLegacyStretchBehaviourJNI(long nativePointer, boolean useLegacyStretchBehaviour);
static native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI(long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
static native void jni_YGConfigSetLoggerJNI(long nativePointer, YogaLogger logger); static native void jni_YGConfigSetLoggerJNI(long nativePointer, YogaLogger logger);
// YGNode related // YGNode related

View File

@@ -19,7 +19,6 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
private static final byte MARGIN = 1; private static final byte MARGIN = 1;
private static final byte PADDING = 2; private static final byte PADDING = 2;
private static final byte BORDER = 4; private static final byte BORDER = 4;
private static final byte DOES_LEGACY_STRETCH_BEHAVIOUR = 8;
private static final byte HAS_NEW_LAYOUT = 16; private static final byte HAS_NEW_LAYOUT = 16;
private static final byte LAYOUT_EDGE_SET_FLAG_INDEX = 0; private static final byte LAYOUT_EDGE_SET_FLAG_INDEX = 0;
@@ -606,12 +605,6 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
return arr != null ? arr[LAYOUT_HEIGHT_INDEX] : 0; return arr != null ? arr[LAYOUT_HEIGHT_INDEX] : 0;
} }
public boolean getDoesLegacyStretchFlagAffectsLayout() {
return arr != null
&& (((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & DOES_LEGACY_STRETCH_BEHAVIOUR)
== DOES_LEGACY_STRETCH_BEHAVIOUR);
}
@Override @Override
public float getLayoutMargin(YogaEdge edge) { public float getLayoutMargin(YogaEdge edge) {
if (arr != null && ((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & MARGIN) == MARGIN) { if (arr != null && ((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & MARGIN) == MARGIN) {

View File

@@ -17,7 +17,6 @@ const short int LAYOUT_BORDER_START_INDEX = 14;
namespace { namespace {
const int DOES_LEGACY_STRETCH_BEHAVIOUR = 8;
const int HAS_NEW_LAYOUT = 16; const int HAS_NEW_LAYOUT = 16;
union YGNodeContext { union YGNodeContext {

View File

@@ -57,15 +57,6 @@ static void jni_YGConfigSetExperimentalFeatureEnabledJNI(
config, static_cast<YGExperimentalFeature>(feature), enabled); config, static_cast<YGExperimentalFeature>(feature), enabled);
} }
static void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI(
JNIEnv* env,
jobject obj,
jlong nativePointer,
jboolean enabled) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(config, enabled);
}
static void jni_YGConfigSetUseWebDefaultsJNI( static void jni_YGConfigSetUseWebDefaultsJNI(
JNIEnv* env, JNIEnv* env,
jobject obj, jobject obj,
@@ -294,9 +285,6 @@ static void YGTransferLayoutOutputsRecursive(
int fieldFlags = edgesSet.get(); int fieldFlags = edgesSet.get();
fieldFlags |= HAS_NEW_LAYOUT; fieldFlags |= HAS_NEW_LAYOUT;
if (YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root)) {
fieldFlags |= DOES_LEGACY_STRETCH_BEHAVIOUR;
}
const int arrSize = 6 + (marginFieldSet ? 4 : 0) + (paddingFieldSet ? 4 : 0) + const int arrSize = 6 + (marginFieldSet ? 4 : 0) + (paddingFieldSet ? 4 : 0) +
(borderFieldSet ? 4 : 0); (borderFieldSet ? 4 : 0);
@@ -776,9 +764,6 @@ static JNINativeMethod methods[] = {
{"jni_YGConfigSetUseLegacyStretchBehaviourJNI", {"jni_YGConfigSetUseLegacyStretchBehaviourJNI",
"(JZ)V", "(JZ)V",
(void*) jni_YGConfigSetUseLegacyStretchBehaviourJNI}, (void*) jni_YGConfigSetUseLegacyStretchBehaviourJNI},
{"jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI",
"(JZ)V",
(void*) jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI},
{"jni_YGConfigSetLoggerJNI", {"jni_YGConfigSetLoggerJNI",
"(JLcom/facebook/yoga/YogaLogger;)V", "(JLcom/facebook/yoga/YogaLogger;)V",
(void*) jni_YGConfigSetLoggerJNI}, (void*) jni_YGConfigSetLoggerJNI},

View File

@@ -233,29 +233,6 @@ public class YogaNodeTest {
} }
} }
@Test
public void testFlagShouldDiffLayoutWithoutLegacyStretchBehaviour() throws Exception {
YogaConfig config = YogaConfigFactory.create();
config.setShouldDiffLayoutWithoutLegacyStretchBehaviour(true);
config.setUseLegacyStretchBehaviour(true);
YogaNode root = createNode(config);
root.setWidth(500);
root.setHeight(500);
YogaNode root_child0 = createNode(config);
root_child0.setAlignItems(YogaAlign.FLEX_START);
root.addChildAt(root_child0, 0);
YogaNode root_child0_child0 = createNode(config);
root_child0_child0.setFlexGrow(1);
root_child0_child0.setFlexShrink(1);
root_child0.addChildAt(root_child0_child0, 0);
YogaNode root_child0_child0_child0 = createNode(config);
root_child0_child0_child0.setFlexGrow(1);
root_child0_child0_child0.setFlexShrink(1);
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertTrue(((YogaNodeJNIBase) root).getDoesLegacyStretchFlagAffectsLayout());
}
@Test @Test
public void initiallyHasNewLayout() { public void initiallyHasNewLayout() {
YogaNode root = createNode(); YogaNode root = createNode();
@@ -315,7 +292,6 @@ public class YogaNodeTest {
@Test @Test
public void testResetApiShouldResetAllLayoutOutputs() { public void testResetApiShouldResetAllLayoutOutputs() {
YogaConfig config = YogaConfigFactory.create(); YogaConfig config = YogaConfigFactory.create();
config.setShouldDiffLayoutWithoutLegacyStretchBehaviour(true);
config.setUseLegacyStretchBehaviour(true); config.setUseLegacyStretchBehaviour(true);
YogaNode node = createNode(config); YogaNode node = createNode(config);
node.setWidth(100); node.setWidth(100);
@@ -371,7 +347,6 @@ public class YogaNodeTest {
assertTrue(node.hasNewLayout()); assertTrue(node.hasNewLayout());
assertFalse(node.isMeasureDefined()); assertFalse(node.isMeasureDefined());
assertFalse(node.isBaselineDefined()); assertFalse(node.isBaselineDefined());
assertFalse(((YogaNodeJNIBase) node).getDoesLegacyStretchFlagAffectsLayout());
assertEquals(null, node.getData()); assertEquals(null, node.getData());
} }

View File

@@ -1,93 +0,0 @@
/*
* 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 <gtest/gtest.h>
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
#include "util/TestUtil.h"
using facebook::yoga::test::TestUtil;
TEST(YogaTest, assert_layout_trees_are_same) {
TestUtil::startCountingNodes();
YGConfig* config = YGConfigNew();
YGConfigSetUseLegacyStretchBehaviour(config, true);
const YGNodeRef root1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root1, 500);
YGNodeStyleSetHeight(root1, 500);
const YGNodeRef root1_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetAlignItems(root1_child0, YGAlignFlexStart);
YGNodeInsertChild(root1, root1_child0, 0);
const YGNodeRef root1_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root1_child0_child0, 1);
YGNodeStyleSetFlexShrink(root1_child0_child0, 1);
YGNodeInsertChild(root1_child0, root1_child0_child0, 0);
const YGNodeRef root1_child0_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root1_child0_child0_child0, 1);
YGNodeStyleSetFlexShrink(root1_child0_child0_child0, 1);
YGNodeInsertChild(root1_child0_child0, root1_child0_child0_child0, 0);
const int32_t cal1_configInstanceCount = YGConfigGetInstanceCount();
const int32_t cal1_nodeInstanceCount = TestUtil::nodeCount();
YGNodeCalculateLayout(root1, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGConfigGetInstanceCount(), cal1_configInstanceCount);
ASSERT_EQ(TestUtil::nodeCount(), cal1_nodeInstanceCount);
const YGNodeRef root2 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root2, 500);
YGNodeStyleSetHeight(root2, 500);
const YGNodeRef root2_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetAlignItems(root2_child0, YGAlignFlexStart);
YGNodeInsertChild(root2, root2_child0, 0);
const YGNodeRef root2_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root2_child0_child0, 1);
YGNodeStyleSetFlexShrink(root2_child0_child0, 1);
YGNodeInsertChild(root2_child0, root2_child0_child0, 0);
const YGNodeRef root2_child0_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root2_child0_child0_child0, 1);
YGNodeStyleSetFlexShrink(root2_child0_child0_child0, 1);
YGNodeInsertChild(root2_child0_child0, root2_child0_child0_child0, 0);
const int32_t cal2_configInstanceCount = YGConfigGetInstanceCount();
const int32_t cal2_nodeInstanceCount = TestUtil::nodeCount();
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGConfigGetInstanceCount(), cal2_configInstanceCount);
ASSERT_EQ(TestUtil::nodeCount(), cal2_nodeInstanceCount);
ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root1));
ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root2));
ASSERT_TRUE(root1->isLayoutTreeEqualToNode(*root2));
YGNodeStyleSetAlignItems(root2, YGAlignFlexEnd);
const int32_t cal3_configInstanceCount = YGConfigGetInstanceCount();
const int32_t cal3_nodeInstanceCount = TestUtil::nodeCount();
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGConfigGetInstanceCount(), cal3_configInstanceCount);
ASSERT_EQ(TestUtil::stopCountingNodes(), cal3_nodeInstanceCount);
ASSERT_FALSE(root1->isLayoutTreeEqualToNode(*root2));
YGNodeFreeRecursive(root1);
YGNodeFreeRecursive(root2);
YGConfigFree(config);
}

View File

@@ -22,12 +22,8 @@ struct YGLayout {
private: private:
static constexpr size_t directionOffset = 0; static constexpr size_t directionOffset = 0;
static constexpr size_t didUseLegacyFlagOffset =
directionOffset + facebook::yoga::detail::bitWidthFn<YGDirection>();
static constexpr size_t doesLegacyStretchFlagAffectsLayoutOffset =
didUseLegacyFlagOffset + 1;
static constexpr size_t hadOverflowOffset = static constexpr size_t hadOverflowOffset =
doesLegacyStretchFlagAffectsLayoutOffset + 1; directionOffset + facebook::yoga::detail::bitWidthFn<YGDirection>();
uint8_t flags = 0; uint8_t flags = 0;
public: public:
@@ -56,25 +52,6 @@ public:
flags, directionOffset, direction); flags, directionOffset, direction);
} }
bool didUseLegacyFlag() const {
return facebook::yoga::detail::getBooleanData(
flags, didUseLegacyFlagOffset);
}
void setDidUseLegacyFlag(bool val) {
facebook::yoga::detail::setBooleanData(flags, didUseLegacyFlagOffset, val);
}
bool doesLegacyStretchFlagAffectsLayout() const {
return facebook::yoga::detail::getBooleanData(
flags, doesLegacyStretchFlagAffectsLayoutOffset);
}
void setDoesLegacyStretchFlagAffectsLayout(bool val) {
facebook::yoga::detail::setBooleanData(
flags, doesLegacyStretchFlagAffectsLayoutOffset, val);
}
bool hadOverflow() const { bool hadOverflow() const {
return facebook::yoga::detail::getBooleanData(flags, hadOverflowOffset); return facebook::yoga::detail::getBooleanData(flags, hadOverflowOffset);
} }

View File

@@ -560,53 +560,6 @@ YGFloatOptional YGNode::getTrailingPaddingAndBorder(
YGFloatOptional(getTrailingBorder(axis)); YGFloatOptional(getTrailingBorder(axis));
} }
bool YGNode::didUseLegacyFlag() {
bool didUseLegacyFlag = layout_.didUseLegacyFlag();
if (didUseLegacyFlag) {
return true;
}
for (const auto& child : children_) {
if (child->layout_.didUseLegacyFlag()) {
didUseLegacyFlag = true;
break;
}
}
return didUseLegacyFlag;
}
void YGNode::setLayoutDoesLegacyFlagAffectsLayout(
bool doesLegacyFlagAffectsLayout) {
layout_.setDoesLegacyStretchFlagAffectsLayout(doesLegacyFlagAffectsLayout);
}
void YGNode::setLayoutDidUseLegacyFlag(bool didUseLegacyFlag) {
layout_.setDidUseLegacyFlag(didUseLegacyFlag);
}
bool YGNode::isLayoutTreeEqualToNode(const YGNode& node) const {
if (children_.size() != node.children_.size()) {
return false;
}
if (layout_ != node.layout_) {
return false;
}
if (children_.size() == 0) {
return true;
}
bool isLayoutTreeEqual = true;
YGNodeRef otherNodeChildren = nullptr;
for (std::vector<YGNodeRef>::size_type i = 0; i < children_.size(); ++i) {
otherNodeChildren = node.children_[i];
isLayoutTreeEqual =
children_[i]->isLayoutTreeEqualToNode(*otherNodeChildren);
if (!isLayoutTreeEqual) {
return false;
}
}
return isLayoutTreeEqual;
}
void YGNode::reset() { void YGNode::reset() {
YGAssertWithNode( YGAssertWithNode(
this, this,

View File

@@ -327,8 +327,6 @@ public:
const float mainSize, const float mainSize,
const float crossSize, const float crossSize,
const float ownerWidth); const float ownerWidth);
void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout);
void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag);
void markDirtyAndPropogateDownwards(); void markDirtyAndPropogateDownwards();
// Other methods // Other methods
@@ -351,8 +349,6 @@ public:
float resolveFlexGrow() const; float resolveFlexGrow() const;
float resolveFlexShrink() const; float resolveFlexShrink() const;
bool isNodeFlexible(); bool isNodeFlexible();
bool didUseLegacyFlag();
bool isLayoutTreeEqualToNode(const YGNode& node) const;
void reset(); void reset();
}; };

View File

@@ -180,10 +180,6 @@ YOGA_EXPORT bool YGNodeIsDirty(YGNodeRef node) {
return node->isDirty(); return node->isDirty();
} }
YOGA_EXPORT bool YGNodeLayoutGetDidUseLegacyFlag(const YGNodeRef node) {
return node->didUseLegacyFlag();
}
YOGA_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants( YOGA_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants(
const YGNodeRef node) { const YGNodeRef node) {
return node->markDirtyAndPropogateDownwards(); return node->markDirtyAndPropogateDownwards();
@@ -220,32 +216,6 @@ YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNode) {
return node; return node;
} }
static YGConfigRef YGConfigClone(const YGConfig& oldConfig) {
const YGConfigRef config = new YGConfig(oldConfig);
YGAssert(config != nullptr, "Could not allocate memory for config");
gConfigInstanceCount++;
return config;
}
static YGNodeRef YGNodeDeepClone(YGNodeRef oldNode) {
auto config = YGConfigClone(*oldNode->getConfig());
auto node = new YGNode{*oldNode, config};
node->setOwner(nullptr);
Event::publish<Event::NodeAllocation>(node, {node->getConfig()});
YGVector vec = YGVector();
vec.reserve(oldNode->getChildren().size());
YGNodeRef childNode = nullptr;
for (auto* item : oldNode->getChildren()) {
childNode = YGNodeDeepClone(item);
childNode->setOwner(node);
vec.push_back(childNode);
}
node->setChildren(vec);
return node;
}
YOGA_EXPORT void YGNodeFree(const YGNodeRef node) { YOGA_EXPORT void YGNodeFree(const YGNodeRef node) {
if (YGNodeRef owner = node->getOwner()) { if (YGNodeRef owner = node->getOwner()) {
owner->removeChild(node); owner->removeChild(node);
@@ -263,17 +233,6 @@ YOGA_EXPORT void YGNodeFree(const YGNodeRef node) {
delete node; delete node;
} }
static void YGConfigFreeRecursive(const YGNodeRef root) {
if (root->getConfig() != nullptr) {
gConfigInstanceCount--;
delete root->getConfig();
}
// Delete configs recursively for childrens
for (auto* child : root->getChildren()) {
YGConfigFreeRecursive(child);
}
}
YOGA_EXPORT void YGNodeFreeRecursiveWithCleanupFunc( YOGA_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
const YGNodeRef root, const YGNodeRef root,
YGNodeCleanupFunc cleanup) { YGNodeCleanupFunc cleanup) {
@@ -993,11 +952,6 @@ YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin);
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border); YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border);
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding); YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding);
YOGA_EXPORT bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(
const YGNodeRef node) {
return node->getLayout().doesLegacyStretchFlagAffectsLayout();
}
std::atomic<uint32_t> gCurrentGenerationCount(0); std::atomic<uint32_t> gCurrentGenerationCount(0);
bool YGLayoutNodeInternal( bool YGLayoutNodeInternal(
@@ -3051,9 +3005,6 @@ static void YGNodelayoutImpl(
collectedFlexItemsValues.sizeConsumedOnCurrentLine; collectedFlexItemsValues.sizeConsumedOnCurrentLine;
} }
if (node->getConfig()->useLegacyStretchBehaviour) {
node->setLayoutDidUseLegacyFlag(true);
}
sizeBasedOnContent = !node->getConfig()->useLegacyStretchBehaviour; sizeBasedOnContent = !node->getConfig()->useLegacyStretchBehaviour;
} }
} }
@@ -4205,13 +4156,6 @@ static void YGRoundToPixelGrid(
} }
} }
static void unsetUseLegacyFlagRecursively(YGNodeRef node) {
node->getConfig()->useLegacyStretchBehaviour = false;
for (auto child : node->getChildren()) {
unsetUseLegacyFlagRecursively(child);
}
}
YOGA_EXPORT void YGNodeCalculateLayoutWithContext( YOGA_EXPORT void YGNodeCalculateLayoutWithContext(
const YGNodeRef node, const YGNodeRef node,
const float ownerWidth, const float ownerWidth,
@@ -4297,67 +4241,6 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext(
} }
Event::publish<Event::LayoutPassEnd>(node, {layoutContext, &markerData}); Event::publish<Event::LayoutPassEnd>(node, {layoutContext, &markerData});
// We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we
// aren't sure whether client's of yoga have gotten rid off this flag or not.
// So logging this in YGLayout would help to find out the call sites depending
// on this flag. This check would be removed once we are sure no one is
// dependent on this flag anymore. The flag
// `shouldDiffLayoutWithoutLegacyStretchBehaviour` in YGConfig will help to
// run experiments.
if (node->getConfig()->shouldDiffLayoutWithoutLegacyStretchBehaviour &&
node->didUseLegacyFlag()) {
const YGNodeRef nodeWithoutLegacyFlag = YGNodeDeepClone(node);
nodeWithoutLegacyFlag->resolveDimension();
// Recursively mark nodes as dirty
nodeWithoutLegacyFlag->markDirtyAndPropogateDownwards();
gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed);
// Rerun the layout, and calculate the diff
unsetUseLegacyFlagRecursively(nodeWithoutLegacyFlag);
LayoutData layoutMarkerData = {};
if (YGLayoutNodeInternal(
nodeWithoutLegacyFlag,
width,
height,
ownerDirection,
widthMeasureMode,
heightMeasureMode,
ownerWidth,
ownerHeight,
true,
LayoutPassReason::kInitial,
nodeWithoutLegacyFlag->getConfig(),
layoutMarkerData,
layoutContext,
0, // tree root
gCurrentGenerationCount.load(std::memory_order_relaxed))) {
nodeWithoutLegacyFlag->setPosition(
nodeWithoutLegacyFlag->getLayout().direction(),
ownerWidth,
ownerHeight,
ownerWidth);
YGRoundToPixelGrid(
nodeWithoutLegacyFlag,
nodeWithoutLegacyFlag->getConfig()->pointScaleFactor,
0.0f,
0.0f);
// Set whether the two layouts are different or not.
auto neededLegacyStretchBehaviour =
!nodeWithoutLegacyFlag->isLayoutTreeEqualToNode(*node);
node->setLayoutDoesLegacyFlagAffectsLayout(neededLegacyStretchBehaviour);
#ifdef DEBUG
if (nodeWithoutLegacyFlag->getConfig()->printTree) {
YGNodePrint(
nodeWithoutLegacyFlag,
(YGPrintOptions) (YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle));
}
#endif
}
YGConfigFreeRecursive(nodeWithoutLegacyFlag);
YGNodeFreeRecursive(nodeWithoutLegacyFlag);
}
} }
YOGA_EXPORT void YGNodeCalculateLayout( YOGA_EXPORT void YGNodeCalculateLayout(
@@ -4381,12 +4264,6 @@ YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
} }
} }
YOGA_EXPORT void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
const YGConfigRef config,
const bool shouldDiffLayout) {
config->shouldDiffLayoutWithoutLegacyStretchBehaviour = shouldDiffLayout;
}
void YGAssert(const bool condition, const char* message) { void YGAssert(const bool condition, const char* message) {
if (!condition) { if (!condition) {
Log::log(YGNodeRef{nullptr}, YGLogLevelFatal, nullptr, "%s\n", message); Log::log(YGNodeRef{nullptr}, YGLogLevelFatal, nullptr, "%s\n", message);

View File

@@ -147,7 +147,6 @@ WIN_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout);
YGNodeType YGNodeGetNodeType(YGNodeRef node); YGNodeType YGNodeGetNodeType(YGNodeRef node);
void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType); void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType);
WIN_EXPORT bool YGNodeIsDirty(YGNodeRef node); WIN_EXPORT bool YGNodeIsDirty(YGNodeRef node);
bool YGNodeLayoutGetDidUseLegacyFlag(YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction); WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction);
WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node); WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node);
@@ -290,7 +289,6 @@ WIN_EXPORT float YGNodeLayoutGetWidth(YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetHeight(YGNodeRef node); WIN_EXPORT float YGNodeLayoutGetHeight(YGNodeRef node);
WIN_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeRef node); WIN_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeRef node);
WIN_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeRef node); WIN_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeRef node);
bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(YGNodeRef node);
// Get the computed values for these nodes after performing layout. If they were // Get the computed values for these nodes after performing layout. If they were
// set using point values then the returned value will be the same as // set using point values then the returned value will be the same as
@@ -315,9 +313,6 @@ WIN_EXPORT void YGAssertWithConfig(
WIN_EXPORT void YGConfigSetPointScaleFactor( WIN_EXPORT void YGConfigSetPointScaleFactor(
YGConfigRef config, YGConfigRef config,
float pixelsInPoint); float pixelsInPoint);
void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
YGConfigRef config,
bool shouldDiffLayout);
// Yoga previously had an error where containers would take the maximum space // Yoga previously had an error where containers would take the maximum space
// possible instead of the minimum like they are supposed to. In practice this // possible instead of the minimum like they are supposed to. In practice this