From 87aca7ed74a4e6bd82d16ecff4a87c1c89b83b8e Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Thu, 18 Jul 2019 05:17:52 -0700 Subject: [PATCH] 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 --- .../com/facebook/yoga/LayoutPassReason.java | 40 ++++++++++++++++++ ReactCommon/yoga/Android.mk | 1 + ReactCommon/yoga/BUCK | 4 +- ReactCommon/yoga/yoga/Yoga.cpp | 41 +++++++++++-------- ReactCommon/yoga/yoga/event/event.cpp | 21 ++++++++++ ReactCommon/yoga/yoga/event/event.h | 13 ++++++ 6 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 ReactAndroid/src/main/java/com/facebook/yoga/LayoutPassReason.java diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/LayoutPassReason.java b/ReactAndroid/src/main/java/com/facebook/yoga/LayoutPassReason.java new file mode 100644 index 00000000000..dc72ad4ffb2 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/yoga/LayoutPassReason.java @@ -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); + } + } +} diff --git a/ReactCommon/yoga/Android.mk b/ReactCommon/yoga/Android.mk index f1cd07fc953..d4ec34f9b32 100644 --- a/ReactCommon/yoga/Android.mk +++ b/ReactCommon/yoga/Android.mk @@ -10,6 +10,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := yogacore LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/yoga/*.cpp) +LOCAL_SRC_FILES += $(wildcard $(LOCAL_PATH)/yoga/*/*.cpp) LOCAL_C_INCLUDES := $(LOCAL_PATH) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) diff --git a/ReactCommon/yoga/BUCK b/ReactCommon/yoga/BUCK index 49ac7854aec..13e624f86b7 100644 --- a/ReactCommon/yoga/BUCK +++ b/ReactCommon/yoga/BUCK @@ -2,9 +2,9 @@ load("//tools/build_defs/oss:rn_defs.bzl", "cxx_library") cxx_library( name = "yoga", - srcs = glob(["yoga/*.cpp"]), + srcs = glob(["yoga/**/*.cpp"]), header_namespace = "", - exported_headers = glob(["yoga/*.h"]), + exported_headers = glob(["yoga/**/*.h"]), compiler_flags = [ "-fno-omit-frame-pointer", "-fexceptions", diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index caffe000cdb..dae5bb411d9 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -938,7 +938,7 @@ bool YGLayoutNodeInternal( const float ownerWidth, const float ownerHeight, const bool performLayout, - const char* reason, + const LayoutPassReason reason, const YGConfigRef config, LayoutData& layoutMarkerData, void* const layoutContext, @@ -1364,7 +1364,7 @@ static void YGNodeComputeFlexBasisForChild( ownerWidth, ownerHeight, false, - "measure", + kMeasureChild, config, layoutMarkerData, layoutContext, @@ -1492,7 +1492,7 @@ static void YGNodeAbsoluteLayoutChild( childWidth, childHeight, false, - "abs-measure", + kAbsMeasureChild, config, layoutMarkerData, layoutContext, @@ -1514,7 +1514,7 @@ static void YGNodeAbsoluteLayoutChild( childWidth, childHeight, true, - "abs-layout", + kAbsLayout, config, layoutMarkerData, layoutContext, @@ -1588,7 +1588,8 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( const float ownerWidth, const float ownerHeight, LayoutData& layoutMarkerData, - void* const layoutContext) { + void* const layoutContext, + const LayoutPassReason reason) { YGAssertWithNode( node, node->hasMeasureFunc(), @@ -1652,7 +1653,8 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( innerHeight, heightMeasureMode, measuredSize.width, - measuredSize.height}); + measuredSize.height, + reason}); node->setLayoutMeasuredDimension( YGNodeBoundAxis( @@ -2185,7 +2187,7 @@ static float YGDistributeFreeSpaceSecondPass( availableInnerWidth, availableInnerHeight, performLayout && !requiresStretchLayout, - "flex", + kFlex, config, layoutMarkerData, layoutContext, @@ -2653,7 +2655,8 @@ static void YGNodelayoutImpl( LayoutData& layoutMarkerData, void* const layoutContext, const uint32_t depth, - const uint32_t generationCount) { + const uint32_t generationCount, + const LayoutPassReason reason) { YGAssertWithNode( node, YGFloatIsUndefined(availableWidth) @@ -2722,7 +2725,8 @@ static void YGNodelayoutImpl( ownerWidth, ownerHeight, layoutMarkerData, - layoutContext); + layoutContext, + reason); return; } @@ -3117,7 +3121,7 @@ static void YGNodelayoutImpl( availableInnerWidth, availableInnerHeight, true, - "stretch", + kStretch, config, layoutMarkerData, layoutContext, @@ -3327,7 +3331,7 @@ static void YGNodelayoutImpl( availableInnerWidth, availableInnerHeight, true, - "multiline-stretch", + kMultilineStretch, config, layoutMarkerData, layoutContext, @@ -3704,7 +3708,7 @@ bool YGLayoutNodeInternal( const float ownerWidth, const float ownerHeight, const bool performLayout, - const char* reason, + const LayoutPassReason reason, const YGConfigRef config, LayoutData& layoutMarkerData, void* const layoutContext, @@ -3831,7 +3835,7 @@ bool YGLayoutNodeInternal( availableHeight, cachedResults->computedWidth, cachedResults->computedHeight, - reason); + LayoutPassReason(reason)); } } else { if (gPrintChanges) { @@ -3853,7 +3857,7 @@ bool YGLayoutNodeInternal( YGMeasureModeName(heightMeasureMode, performLayout), availableWidth, availableHeight, - reason); + LayoutPassToString(reason)); } YGNodelayoutImpl( @@ -3870,7 +3874,8 @@ bool YGLayoutNodeInternal( layoutMarkerData, layoutContext, depth, - generationCount); + generationCount, + reason); if (gPrintChanges) { Log::log( @@ -3891,7 +3896,7 @@ bool YGLayoutNodeInternal( YGMeasureModeName(heightMeasureMode, performLayout), layout->measuredDimensions[YGDimensionWidth], layout->measuredDimensions[YGDimensionHeight], - reason); + LayoutPassToString(reason)); } layout->lastOwnerDirection = ownerDirection; @@ -4121,7 +4126,7 @@ void YGNodeCalculateLayoutWithContext( ownerWidth, ownerHeight, true, - "initial", + kInitial, node->getConfig(), markerData, layoutContext, @@ -4171,7 +4176,7 @@ void YGNodeCalculateLayoutWithContext( ownerWidth, ownerHeight, true, - "initial", + kInitial, nodeWithoutLegacyFlag->getConfig(), layoutMarkerData, layoutContext, diff --git a/ReactCommon/yoga/yoga/event/event.cpp b/ReactCommon/yoga/yoga/event/event.cpp index 9fc00120935..86031476c21 100644 --- a/ReactCommon/yoga/yoga/event/event.cpp +++ b/ReactCommon/yoga/yoga/event/event.cpp @@ -12,6 +12,27 @@ namespace facebook { 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 { struct Node { diff --git a/ReactCommon/yoga/yoga/event/event.h b/ReactCommon/yoga/yoga/event/event.h index dc49cefc422..8e6bc97238b 100644 --- a/ReactCommon/yoga/yoga/event/event.h +++ b/ReactCommon/yoga/yoga/event/event.h @@ -32,6 +32,18 @@ struct LayoutData { 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 { enum Type { NodeAllocation, @@ -114,6 +126,7 @@ struct Event::TypedData { YGMeasureMode heightMeasureMode; float measuredWidth; float measuredHeight; + const LayoutPassReason reason; }; template <>