move YGMarkerLayout to event based system
Summary: Using layoutPassStart and LayoutPassEnd events instead of YGMarkerLayout for instrumentation Reviewed By: davidaurelio Differential Revision: D16048789 fbshipit-source-id: 041a35bc2cb1b7281ca83cf9d35041b4011cfeb9
This commit is contained in:
committed by
Facebook Github Bot
parent
ce517689ff
commit
eeae39d707
@@ -67,136 +67,6 @@ struct MarkerTest : public ::testing::Test {
|
||||
uniquePtr<YGConfig> config;
|
||||
};
|
||||
|
||||
TEST_F(MarkerTest, marker_start_works) {
|
||||
auto root = makeNode();
|
||||
|
||||
decltype(MarkerSection<YGMarkerLayout>::data)* dataAddress;
|
||||
{
|
||||
MarkerSection<YGMarkerLayout> marker{root.get()};
|
||||
dataAddress = &marker.data;
|
||||
}
|
||||
|
||||
auto& markerCookie = findLastMarker(YGMarkerLayout);
|
||||
|
||||
ASSERT_EQ(markerCookie.start.marker, YGMarkerLayout)
|
||||
<< "wrong marker type passed to `startMarker`";
|
||||
ASSERT_EQ(markerCookie.start.node, root.get())
|
||||
<< "wrong node pointer passed to `startMarker`";
|
||||
ASSERT_EQ(markerCookie.start.markerData.layout, dataAddress)
|
||||
<< "wrong pointer to marker data passed to `startMarker`";
|
||||
}
|
||||
|
||||
TEST_F(MarkerTest, marker_end_works) {
|
||||
auto root = makeNode();
|
||||
|
||||
{ MarkerSection<YGMarkerLayout> marker{root.get()}; }
|
||||
|
||||
auto& markerCookie = findLastMarker(YGMarkerLayout);
|
||||
|
||||
ASSERT_EQ(markerCookie.end.data.marker, markerCookie.start.marker)
|
||||
<< "marker type passed to `endMarker` differs from type passed to "
|
||||
"`startMarker`";
|
||||
ASSERT_EQ(markerCookie.end.data.node, markerCookie.start.node)
|
||||
<< "node passed to `endMarker` differs from node passed to `startMarker`";
|
||||
ASSERT_EQ(
|
||||
markerCookie.end.data.markerData.layout,
|
||||
markerCookie.start.markerData.layout)
|
||||
<< "marker data pointer passed to `endMarker` differs from pointer "
|
||||
"passed to `startMarker`";
|
||||
ASSERT_EQ(markerCookie.end.cookie, &markerCookie)
|
||||
<< "pointer returned by `startMarker` was not passed to `endMarker`";
|
||||
}
|
||||
|
||||
TEST_F(MarkerTest, layout_marker) {
|
||||
auto root = makeNode();
|
||||
|
||||
calculateLayout(root);
|
||||
|
||||
auto& markerCookie = findLastMarker(YGMarkerLayout);
|
||||
|
||||
ASSERT_EQ(markerCookie.start.marker, YGMarkerLayout);
|
||||
ASSERT_EQ(markerCookie.start.node, root.get());
|
||||
}
|
||||
|
||||
TEST_F(MarkerTest, layout_marker_counts_single_node_layout) {
|
||||
auto root = makeNode();
|
||||
|
||||
calculateLayout(root);
|
||||
|
||||
auto& markerCookie = findLastMarker(YGMarkerLayout);
|
||||
|
||||
ASSERT_EQ(
|
||||
markerCookie.end.markerData.layout,
|
||||
(YGMarkerLayoutData{.layouts = 1, .measures = 0, .maxMeasureCache = 1}));
|
||||
}
|
||||
|
||||
TEST_F(MarkerTest, layout_marker_counts_multi_node_layout) {
|
||||
auto root = makeNode();
|
||||
auto childA = addChild(root);
|
||||
auto childB = addChild(root);
|
||||
|
||||
calculateLayout(root);
|
||||
|
||||
auto& markerCookie = findLastMarker(YGMarkerLayout);
|
||||
|
||||
ASSERT_EQ(
|
||||
markerCookie.end.markerData.layout,
|
||||
(YGMarkerLayoutData{.layouts = 3, .measures = 4, .maxMeasureCache = 3}));
|
||||
}
|
||||
|
||||
TEST_F(MarkerTest, layout_marker_counts_cache_hits_single_node_layout) {
|
||||
auto root = makeNode();
|
||||
calculateLayout(root);
|
||||
|
||||
calculateLayout(root);
|
||||
|
||||
auto& markerCookie = findLastMarker(YGMarkerLayout);
|
||||
|
||||
ASSERT_EQ(
|
||||
markerCookie.end.markerData.layout,
|
||||
(YGMarkerLayoutData{.layouts = 0,
|
||||
.measures = 0,
|
||||
.cachedLayouts = 1,
|
||||
.cachedMeasures = 0}));
|
||||
}
|
||||
|
||||
TEST_F(MarkerTest, layout_marker_counts_cache_hits_multi_node_layout) {
|
||||
auto root = makeNode();
|
||||
auto childA = addChild(root);
|
||||
auto childB = addChild(root);
|
||||
calculateLayout(root, 987, 654);
|
||||
calculateLayout(root, 123, 456);
|
||||
|
||||
calculateLayout(root, 987, 654);
|
||||
|
||||
auto& markerCookie = findLastMarker(YGMarkerLayout);
|
||||
|
||||
ASSERT_EQ(
|
||||
markerCookie.end.markerData.layout,
|
||||
(YGMarkerLayoutData{.layouts = 3,
|
||||
.measures = 0,
|
||||
.maxMeasureCache = 5,
|
||||
.cachedLayouts = 0,
|
||||
.cachedMeasures = 4}));
|
||||
}
|
||||
|
||||
TEST_F(MarkerTest, layout_marker_has_max_measure_cache) {
|
||||
auto root = makeNode();
|
||||
auto a = addChild(root);
|
||||
auto b = addChild(root);
|
||||
YGNodeStyleSetFlexBasis(a.get(), 10.0f);
|
||||
|
||||
for (auto s : {20, 30, 40}) {
|
||||
calculateLayout(root, s, s);
|
||||
}
|
||||
|
||||
auto& markerCookie = findLastMarker(YGMarkerLayout);
|
||||
|
||||
ASSERT_EQ(
|
||||
markerCookie.end.markerData.layout,
|
||||
(YGMarkerLayoutData{.layouts = 3, .measures = 3, .maxMeasureCache = 7}));
|
||||
}
|
||||
|
||||
TEST_F(MarkerTest, measure_functions_get_wrapped) {
|
||||
auto root = makeNode();
|
||||
YGNodeSetMeasureFunc(
|
||||
@@ -244,9 +114,6 @@ void MarkerTest::endMarker(
|
||||
auto cookie = static_cast<MarkerCookie*>(id);
|
||||
cookie->end = {{marker, node, data}, id, {}};
|
||||
switch (marker) {
|
||||
case YGMarkerLayout:
|
||||
cookie->end.markerData.layout = *marker::data<YGMarkerLayout>(data);
|
||||
break;
|
||||
case YGMarkerMeasure:
|
||||
case YGMarkerBaselineFn:
|
||||
break;
|
||||
@@ -275,8 +142,6 @@ namespace {
|
||||
|
||||
const char* markerTypeName(YGMarker type) {
|
||||
switch (type) {
|
||||
case YGMarkerLayout:
|
||||
return "YGMarkerLayout";
|
||||
case YGMarkerMeasure:
|
||||
return "YGMarkerMeasure";
|
||||
case YGMarkerBaselineFn:
|
||||
|
@@ -14,7 +14,6 @@ typedef struct YGNode* YGNodeRef;
|
||||
typedef struct YGConfig* YGConfigRef;
|
||||
|
||||
typedef YG_ENUM_BEGIN(YGMarker){
|
||||
YGMarkerLayout,
|
||||
YGMarkerMeasure,
|
||||
YGMarkerBaselineFn,
|
||||
} YG_ENUM_END(YGMarker);
|
||||
@@ -33,7 +32,6 @@ typedef struct {
|
||||
} YGMarkerNoData;
|
||||
|
||||
typedef union {
|
||||
YGMarkerLayoutData* layout;
|
||||
YGMarkerNoData* noData;
|
||||
} YGMarkerData;
|
||||
|
||||
@@ -60,12 +58,6 @@ namespace detail {
|
||||
template <YGMarker M>
|
||||
struct MarkerData;
|
||||
|
||||
template <>
|
||||
struct MarkerData<YGMarkerLayout> {
|
||||
using type = YGMarkerLayoutData;
|
||||
static type*& get(YGMarkerData& d) { return d.layout; }
|
||||
};
|
||||
|
||||
struct NoMarkerData {
|
||||
using type = YGMarkerNoData;
|
||||
static type*& get(YGMarkerData& d) { return d.noData; }
|
||||
|
@@ -4063,7 +4063,7 @@ void YGNodeCalculateLayoutWithContext(
|
||||
void* layoutContext) {
|
||||
|
||||
Event::publish<Event::LayoutPassStart>(node, {layoutContext});
|
||||
marker::MarkerSection<YGMarkerLayout> marker{node};
|
||||
YGMarkerLayoutData markerData = {};
|
||||
|
||||
// Increment the generation count. This will force the recursive routine to
|
||||
// visit all dirty nodes at least once. Subsequent visits will be skipped if
|
||||
@@ -4122,7 +4122,7 @@ void YGNodeCalculateLayoutWithContext(
|
||||
true,
|
||||
"initial",
|
||||
node->getConfig(),
|
||||
marker.data,
|
||||
markerData,
|
||||
layoutContext,
|
||||
0, // tree root
|
||||
gCurrentGenerationCount)) {
|
||||
@@ -4141,8 +4141,7 @@ void YGNodeCalculateLayoutWithContext(
|
||||
#endif
|
||||
}
|
||||
|
||||
marker.end();
|
||||
Event::publish<Event::LayoutPassEnd>(node, {layoutContext, &marker.data});
|
||||
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.
|
||||
@@ -4160,7 +4159,7 @@ void YGNodeCalculateLayoutWithContext(
|
||||
gCurrentGenerationCount++;
|
||||
// Rerun the layout, and calculate the diff
|
||||
unsetUseLegacyFlagRecursively(nodeWithoutLegacyFlag);
|
||||
YGMarkerLayoutData layoutMarkerData;
|
||||
YGMarkerLayoutData layoutMarkerData = {};
|
||||
if (YGLayoutNodeInternal(
|
||||
nodeWithoutLegacyFlag,
|
||||
width,
|
||||
|
Reference in New Issue
Block a user