Pass reason for measure pass along with measurecallbackend event (#566)

Summary:
Pull Request resolved: https://github.com/facebook/litho/pull/566

Pull Request resolved: https://github.com/facebook/react-native/pull/25702

Pass reason for each measure callback to the flipper plugin

Reviewed By: davidaurelio

Differential Revision: D16221771

fbshipit-source-id: 2e72e1ebb3c7e633d189e7a7a81d655ac9531e51
This commit is contained in:
Sidharth Guglani
2019-07-18 05:17:52 -07:00
committed by Facebook Github Bot
parent 5e40e4b682
commit e6dfe04388
5 changed files with 98 additions and 19 deletions

View File

@@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on) set(CMAKE_VERBOSE_MAKEFILE on)
file(GLOB yogacore_SRC yoga/*.cpp) file(GLOB_RECURSE yogacore_SRC yoga/*.cpp)
add_library(yogacore STATIC ${yogacore_SRC}) add_library(yogacore STATIC ${yogacore_SRC})
target_link_libraries(yogacore android log) target_link_libraries(yogacore android log)

View File

@@ -0,0 +1,40 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
package com.facebook.yoga;
public enum LayoutPassReason {
INITIAL(0),
MEASURE(1),
ABS_MEASURE(2),
FLEX(3),
ABS_LAYOUT(4),
STRETCH(5),
MULTILINE_STRETCH(6);
private final int mIntValue;
LayoutPassReason(int intValue) {
mIntValue = intValue;
}
public int intValue() {
return mIntValue;
}
public static LayoutPassReason fromInt(int value) {
switch (value) {
case 0: return INITIAL;
case 1: return MEASURE;
case 2: return ABS_MEASURE;
case 3: return FLEX;
case 4: return ABS_LAYOUT;
case 5: return STRETCH;
case 6: return MULTILINE_STRETCH;
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -938,7 +938,7 @@ bool YGLayoutNodeInternal(
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const bool performLayout, const bool performLayout,
const char* reason, const LayoutPassReason reason,
const YGConfigRef config, const YGConfigRef config,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext, void* const layoutContext,
@@ -1364,7 +1364,7 @@ static void YGNodeComputeFlexBasisForChild(
ownerWidth, ownerWidth,
ownerHeight, ownerHeight,
false, false,
"measure", kMeasureChild,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext, layoutContext,
@@ -1492,7 +1492,7 @@ static void YGNodeAbsoluteLayoutChild(
childWidth, childWidth,
childHeight, childHeight,
false, false,
"abs-measure", kAbsMeasureChild,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext, layoutContext,
@@ -1514,7 +1514,7 @@ static void YGNodeAbsoluteLayoutChild(
childWidth, childWidth,
childHeight, childHeight,
true, true,
"abs-layout", kAbsLayout,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext, layoutContext,
@@ -1588,7 +1588,8 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext) { void* const layoutContext,
const LayoutPassReason reason) {
YGAssertWithNode( YGAssertWithNode(
node, node,
node->hasMeasureFunc(), node->hasMeasureFunc(),
@@ -1652,7 +1653,8 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
innerHeight, innerHeight,
heightMeasureMode, heightMeasureMode,
measuredSize.width, measuredSize.width,
measuredSize.height}); measuredSize.height,
reason});
node->setLayoutMeasuredDimension( node->setLayoutMeasuredDimension(
YGNodeBoundAxis( YGNodeBoundAxis(
@@ -2185,7 +2187,7 @@ static float YGDistributeFreeSpaceSecondPass(
availableInnerWidth, availableInnerWidth,
availableInnerHeight, availableInnerHeight,
performLayout && !requiresStretchLayout, performLayout && !requiresStretchLayout,
"flex", kFlex,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext, layoutContext,
@@ -2653,7 +2655,8 @@ static void YGNodelayoutImpl(
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext, void* const layoutContext,
const uint32_t depth, const uint32_t depth,
const uint32_t generationCount) { const uint32_t generationCount,
const LayoutPassReason reason) {
YGAssertWithNode( YGAssertWithNode(
node, node,
YGFloatIsUndefined(availableWidth) YGFloatIsUndefined(availableWidth)
@@ -2722,7 +2725,8 @@ static void YGNodelayoutImpl(
ownerWidth, ownerWidth,
ownerHeight, ownerHeight,
layoutMarkerData, layoutMarkerData,
layoutContext); layoutContext,
reason);
return; return;
} }
@@ -3117,7 +3121,7 @@ static void YGNodelayoutImpl(
availableInnerWidth, availableInnerWidth,
availableInnerHeight, availableInnerHeight,
true, true,
"stretch", kStretch,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext, layoutContext,
@@ -3327,7 +3331,7 @@ static void YGNodelayoutImpl(
availableInnerWidth, availableInnerWidth,
availableInnerHeight, availableInnerHeight,
true, true,
"multiline-stretch", kMultilineStretch,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext, layoutContext,
@@ -3704,7 +3708,7 @@ bool YGLayoutNodeInternal(
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const bool performLayout, const bool performLayout,
const char* reason, const LayoutPassReason reason,
const YGConfigRef config, const YGConfigRef config,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext, void* const layoutContext,
@@ -3831,7 +3835,7 @@ bool YGLayoutNodeInternal(
availableHeight, availableHeight,
cachedResults->computedWidth, cachedResults->computedWidth,
cachedResults->computedHeight, cachedResults->computedHeight,
reason); LayoutPassReason(reason));
} }
} else { } else {
if (gPrintChanges) { if (gPrintChanges) {
@@ -3853,7 +3857,7 @@ bool YGLayoutNodeInternal(
YGMeasureModeName(heightMeasureMode, performLayout), YGMeasureModeName(heightMeasureMode, performLayout),
availableWidth, availableWidth,
availableHeight, availableHeight,
reason); LayoutPassToString(reason));
} }
YGNodelayoutImpl( YGNodelayoutImpl(
@@ -3870,7 +3874,8 @@ bool YGLayoutNodeInternal(
layoutMarkerData, layoutMarkerData,
layoutContext, layoutContext,
depth, depth,
generationCount); generationCount,
reason);
if (gPrintChanges) { if (gPrintChanges) {
Log::log( Log::log(
@@ -3891,7 +3896,7 @@ bool YGLayoutNodeInternal(
YGMeasureModeName(heightMeasureMode, performLayout), YGMeasureModeName(heightMeasureMode, performLayout),
layout->measuredDimensions[YGDimensionWidth], layout->measuredDimensions[YGDimensionWidth],
layout->measuredDimensions[YGDimensionHeight], layout->measuredDimensions[YGDimensionHeight],
reason); LayoutPassToString(reason));
} }
layout->lastOwnerDirection = ownerDirection; layout->lastOwnerDirection = ownerDirection;
@@ -4121,7 +4126,7 @@ void YGNodeCalculateLayoutWithContext(
ownerWidth, ownerWidth,
ownerHeight, ownerHeight,
true, true,
"initial", kInitial,
node->getConfig(), node->getConfig(),
markerData, markerData,
layoutContext, layoutContext,
@@ -4171,7 +4176,7 @@ void YGNodeCalculateLayoutWithContext(
ownerWidth, ownerWidth,
ownerHeight, ownerHeight,
true, true,
"initial", kInitial,
nodeWithoutLegacyFlag->getConfig(), nodeWithoutLegacyFlag->getConfig(),
layoutMarkerData, layoutMarkerData,
layoutContext, layoutContext,

View File

@@ -12,6 +12,27 @@
namespace facebook { namespace facebook {
namespace yoga { namespace yoga {
const char* LayoutPassToString(const LayoutPassReason value) {
switch (value) {
case kInitial:
return "initial";
case kMeasureChild:
return "measure";
case kAbsMeasureChild:
return "abs_measure";
case kFlex:
return "flex";
case kAbsLayout:
return "abs_layout";
case kStretch:
return "stretch";
case kMultilineStretch:
return "multiline_stretch";
default:
return "unknown";
}
}
namespace { namespace {
struct Node { struct Node {

View File

@@ -32,6 +32,18 @@ struct LayoutData {
int measureCallbacks; int measureCallbacks;
}; };
enum LayoutPassReason : int {
kInitial = 0,
kMeasureChild = 1,
kAbsMeasureChild = 2,
kFlex = 3,
kAbsLayout = 4,
kStretch = 5,
kMultilineStretch = 6
};
const char* LayoutPassToString(const LayoutPassReason value);
struct Event { struct Event {
enum Type { enum Type {
NodeAllocation, NodeAllocation,
@@ -114,6 +126,7 @@ struct Event::TypedData<Event::MeasureCallbackEnd> {
YGMeasureMode heightMeasureMode; YGMeasureMode heightMeasureMode;
float measuredWidth; float measuredWidth;
float measuredHeight; float measuredHeight;
const LayoutPassReason reason;
}; };
template <> template <>