From e6dfe043889c03e3a9407e1686e1024c6dfb9142 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 --- CMakeLists.txt | 2 +- java/com/facebook/yoga/LayoutPassReason.java | 40 +++++++++++++++++++ yoga/Yoga.cpp | 41 +++++++++++--------- yoga/event/event.cpp | 21 ++++++++++ yoga/event/event.h | 13 +++++++ 5 files changed, 98 insertions(+), 19 deletions(-) create mode 100644 java/com/facebook/yoga/LayoutPassReason.java diff --git a/CMakeLists.txt b/CMakeLists.txt index ed4eff5c..3ba4477e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.4.1) set(CMAKE_VERBOSE_MAKEFILE on) -file(GLOB yogacore_SRC yoga/*.cpp) +file(GLOB_RECURSE yogacore_SRC yoga/*.cpp) add_library(yogacore STATIC ${yogacore_SRC}) target_link_libraries(yogacore android log) diff --git a/java/com/facebook/yoga/LayoutPassReason.java b/java/com/facebook/yoga/LayoutPassReason.java new file mode 100644 index 00000000..dc72ad4f --- /dev/null +++ b/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/yoga/Yoga.cpp b/yoga/Yoga.cpp index caffe000..dae5bb41 100644 --- a/yoga/Yoga.cpp +++ b/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/yoga/event/event.cpp b/yoga/event/event.cpp index 9fc00120..86031476 100644 --- a/yoga/event/event.cpp +++ b/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/yoga/event/event.h b/yoga/event/event.h index dc49cefc..8e6bc972 100644 --- a/yoga/event/event.h +++ b/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 <>