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
This commit is contained in:
committed by
Facebook Github Bot
parent
b4b009c2d8
commit
cbea5d44b8
@@ -32,6 +32,9 @@ struct MarkerTest : public ::testing::Test {
|
|||||||
struct EndData {
|
struct EndData {
|
||||||
Data data;
|
Data data;
|
||||||
void* cookie;
|
void* cookie;
|
||||||
|
union {
|
||||||
|
YGMarkerLayoutData layout;
|
||||||
|
} markerData;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
@@ -43,6 +46,7 @@ struct MarkerTest : public ::testing::Test {
|
|||||||
static void endMarker(YGMarker, YGNodeRef, YGMarkerData, void*);
|
static void endMarker(YGMarker, YGNodeRef, YGMarkerData, void*);
|
||||||
static uniquePtr<YGConfig> makeConfig();
|
static uniquePtr<YGConfig> makeConfig();
|
||||||
static uniquePtr<YGNode> makeNode(uniquePtr<YGConfig>&);
|
static uniquePtr<YGNode> makeNode(uniquePtr<YGConfig>&);
|
||||||
|
static uniquePtr<YGNode> makeNode(uniquePtr<YGConfig>&, uniquePtr<YGNode>&);
|
||||||
|
|
||||||
void SetUp() override;
|
void SetUp() override;
|
||||||
};
|
};
|
||||||
@@ -95,6 +99,28 @@ TEST_F(MarkerTest, layout_marker) {
|
|||||||
ASSERT_EQ(markerCookie.start.node, root.get());
|
ASSERT_EQ(markerCookie.start.node, root.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(MarkerTest, layout_marker_counts_single_node_layout) {
|
||||||
|
auto config = makeConfig();
|
||||||
|
auto root = makeNode(config);
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root.get(), YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_EQ(markerCookie.end.markerData.layout.layouts, 1);
|
||||||
|
ASSERT_EQ(markerCookie.end.markerData.layout.measures, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(MarkerTest, layout_marker_counts_multi_node_layout) {
|
||||||
|
auto config = makeConfig();
|
||||||
|
auto root = makeNode(config);
|
||||||
|
auto childA = makeNode(config, root);
|
||||||
|
auto childB = makeNode(config, root);
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root.get(), YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_EQ(markerCookie.end.markerData.layout.layouts, 3);
|
||||||
|
ASSERT_EQ(markerCookie.end.markerData.layout.measures, 4);
|
||||||
|
}
|
||||||
|
|
||||||
void* MarkerTest::startMarker(
|
void* MarkerTest::startMarker(
|
||||||
YGMarker marker,
|
YGMarker marker,
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
@@ -108,7 +134,12 @@ void MarkerTest::endMarker(
|
|||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGMarkerData data,
|
YGMarkerData data,
|
||||||
void* id) {
|
void* id) {
|
||||||
markerCookie.end = {{marker, node, data}, id};
|
markerCookie.end = {{marker, node, data}, id, {}};
|
||||||
|
switch (marker) {
|
||||||
|
case YGMarkerLayout:
|
||||||
|
markerCookie.end.markerData.layout = *marker::data<YGMarkerLayout>(data);
|
||||||
|
break;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
uniquePtr<YGConfig> MarkerTest::makeConfig() {
|
uniquePtr<YGConfig> MarkerTest::makeConfig() {
|
||||||
@@ -122,6 +153,14 @@ uniquePtr<YGNode> MarkerTest::makeNode(uniquePtr<YGConfig>& config) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uniquePtr<YGNode> MarkerTest::makeNode(
|
||||||
|
uniquePtr<YGConfig>& config,
|
||||||
|
uniquePtr<YGNode>& owner) {
|
||||||
|
auto n = makeNode(config);
|
||||||
|
YGNodeInsertChild(owner.get(), n.get(), YGNodeGetChildCount(owner.get()));
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
void MarkerTest::SetUp() {
|
void MarkerTest::SetUp() {
|
||||||
markerCookie = {};
|
markerCookie = {};
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,8 @@ typedef YG_ENUM_BEGIN(YGMarker){
|
|||||||
} YG_ENUM_END(YGMarker);
|
} YG_ENUM_END(YGMarker);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int unused;
|
int layouts;
|
||||||
|
int measures;
|
||||||
} YGMarkerLayoutData;
|
} YGMarkerLayoutData;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
@@ -54,6 +55,15 @@ struct MarkerData<YGMarkerLayout> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
template <YGMarker M>
|
||||||
|
typename detail::MarkerData<M>::type* data(YGMarkerData) = delete;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline YGMarkerLayoutData* data<YGMarkerLayout>(YGMarkerData d) {
|
||||||
|
return d.layout;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace marker
|
} // namespace marker
|
||||||
} // namespace yoga
|
} // namespace yoga
|
||||||
} // namespace facebook
|
} // namespace facebook
|
||||||
|
@@ -2685,6 +2685,8 @@ static void YGNodelayoutImpl(
|
|||||||
"availableHeight is indefinite so heightMeasureMode must be "
|
"availableHeight is indefinite so heightMeasureMode must be "
|
||||||
"YGMeasureModeUndefined");
|
"YGMeasureModeUndefined");
|
||||||
|
|
||||||
|
(performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1;
|
||||||
|
|
||||||
// Set the resolved resolution in the node's layout.
|
// Set the resolved resolution in the node's layout.
|
||||||
const YGDirection direction = node->resolveDirection(ownerDirection);
|
const YGDirection direction = node->resolveDirection(ownerDirection);
|
||||||
node->setLayoutDirection(direction);
|
node->setLayoutDirection(direction);
|
||||||
|
Reference in New Issue
Block a user