Node -> Measure func map instead of vec (#1581)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1581 This is better than just trusting the order of the measure func call. Now each measure function I/O is associated with a node in the JSON. Reviewed By: NickGerleman Differential Revision: D53776790 fbshipit-source-id: 793cf2d9cbf6f663d24848af0af30aa297614eea
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b35456b93c
commit
c278713eb5
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <capture/NodeToString.h>
|
||||
|
||||
@@ -120,7 +121,26 @@ static YGValue borderFloatToYGValue(YGNodeRef node, YGEdge edge) {
|
||||
return YGValue{val, unit};
|
||||
}
|
||||
|
||||
static void serializeTreeImpl(json& j, YGNodeRef node, PrintOptions options) {
|
||||
static void serializeMeasureFuncResults(
|
||||
json& j,
|
||||
std::vector<SerializedMeasureFunc>& measureFuncs) {
|
||||
for (auto measureFunc : measureFuncs) {
|
||||
j["measure-funcs"].push_back(
|
||||
{{"width", measureFunc.inputWidth},
|
||||
{"width-mode", YGMeasureModeToString(measureFunc.widthMode)},
|
||||
{"height", measureFunc.inputHeight},
|
||||
{"height-mode", YGMeasureModeToString(measureFunc.heightMode)},
|
||||
{"output-width", measureFunc.outputWidth},
|
||||
{"output-height", measureFunc.outputHeight},
|
||||
{"duration-ns", measureFunc.durationNs}});
|
||||
}
|
||||
}
|
||||
|
||||
static void serializeTreeImpl(
|
||||
json& j,
|
||||
SerializedMeasureFuncMap& nodesToMeasureFuncs,
|
||||
YGNodeRef node,
|
||||
PrintOptions options) {
|
||||
if ((options & PrintOptions::Layout) == PrintOptions::Layout) {
|
||||
j["layout"]["width"] = YGNodeStyleGetWidth(node).value;
|
||||
j["layout"]["height"] = YGNodeStyleGetHeight(node).value;
|
||||
@@ -293,7 +313,12 @@ static void serializeTreeImpl(json& j, YGNodeRef node, PrintOptions options) {
|
||||
YGNodeGetAlwaysFormsContainingBlock(node),
|
||||
YGNodeGetAlwaysFormsContainingBlock(defaultNode.get()));
|
||||
if (YGNodeHasMeasureFunc(node)) {
|
||||
j["node"]["has-custom-measure"] = true;
|
||||
auto measureFuncIt = nodesToMeasureFuncs.find(node);
|
||||
if (measureFuncIt == nodesToMeasureFuncs.end()) {
|
||||
j["node"]["measure-funcs"];
|
||||
} else {
|
||||
serializeMeasureFuncResults(j["node"], measureFuncIt->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,13 +327,21 @@ static void serializeTreeImpl(json& j, YGNodeRef node, PrintOptions options) {
|
||||
childCount > 0) {
|
||||
for (size_t i = 0; i < childCount; i++) {
|
||||
j["children"].push_back({});
|
||||
serializeTreeImpl(j["children"][i], YGNodeGetChild(node, i), options);
|
||||
serializeTreeImpl(
|
||||
j["children"][i],
|
||||
nodesToMeasureFuncs,
|
||||
YGNodeGetChild(node, i),
|
||||
options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void serializeTree(json& j, YGNodeRef node, PrintOptions options) {
|
||||
serializeTreeImpl(j["tree"], node, options);
|
||||
void serializeTree(
|
||||
json& j,
|
||||
SerializedMeasureFuncMap& nodesToMeasureFuncs,
|
||||
YGNodeRef node,
|
||||
PrintOptions options) {
|
||||
serializeTreeImpl(j["tree"], nodesToMeasureFuncs, node, options);
|
||||
}
|
||||
|
||||
void serializeLayoutInputs(
|
||||
@@ -323,19 +356,4 @@ void serializeLayoutInputs(
|
||||
};
|
||||
}
|
||||
|
||||
void serializeMeasureFuncResults(
|
||||
json& j,
|
||||
std::vector<SerializedMeasureFunc>& measureFuncs) {
|
||||
for (auto measureFunc : measureFuncs) {
|
||||
j["measure-funcs"].push_back(
|
||||
{{"width", measureFunc.inputWidth},
|
||||
{"width-mode", YGMeasureModeToString(measureFunc.widthMode)},
|
||||
{"height", measureFunc.inputHeight},
|
||||
{"height-mode", YGMeasureModeToString(measureFunc.heightMode)},
|
||||
{"output-width", measureFunc.outputWidth},
|
||||
{"output-height", measureFunc.outputHeight},
|
||||
{"duration-ns", measureFunc.durationNs}});
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace facebook::yoga
|
||||
|
Reference in New Issue
Block a user