diff --git a/tests/EventsTest.cpp b/tests/EventsTest.cpp index bb86fe71..18128cc0 100644 --- a/tests/EventsTest.cpp +++ b/tests/EventsTest.cpp @@ -15,7 +15,6 @@ #include #include #include -#include namespace facebook { namespace yoga { @@ -27,7 +26,7 @@ struct TypedEventTestData {}; template <> struct TypedEventTestData { void* layoutContext; - YGMarkerLayoutData layoutData; + LayoutData layoutData; }; struct EventArgs { @@ -147,7 +146,7 @@ TEST_F(EventTest, layout_events_single_node) { ASSERT_EQ(events[3].node, root); ASSERT_EQ(events[3].type, Event::LayoutPassEnd); - YGMarkerLayoutData layoutData = + LayoutData layoutData = events[3].eventTestData().layoutData; ASSERT_EQ(layoutData.layouts, 1); @@ -170,7 +169,7 @@ TEST_F(EventTest, layout_events_counts_multi_node_layout) { ASSERT_EQ(events[11].node, root); ASSERT_EQ(events[11].type, Event::LayoutPassEnd); - YGMarkerLayoutData layoutData = + LayoutData layoutData = events[11].eventTestData().layoutData; ASSERT_EQ(layoutData.layouts, 3); @@ -191,7 +190,7 @@ TEST_F(EventTest, layout_events_counts_cache_hits_single_node_layout) { ASSERT_EQ(events[6].node, root); ASSERT_EQ(events[6].type, Event::LayoutPassEnd); - YGMarkerLayoutData layoutData = + LayoutData layoutData = events[6].eventTestData().layoutData; ASSERT_EQ(layoutData.layouts, 0); @@ -215,7 +214,7 @@ TEST_F(EventTest, layout_events_counts_cache_hits_multi_node_layout) { ASSERT_EQ(lastEvent().node, root); ASSERT_EQ(lastEvent().type, Event::LayoutPassEnd); - YGMarkerLayoutData layoutData = + LayoutData layoutData = lastEvent().eventTestData().layoutData; ASSERT_EQ(layoutData.layouts, 3); @@ -240,7 +239,7 @@ TEST_F(EventTest, layout_events_has_max_measure_cache) { ASSERT_EQ(lastEvent().node, root); ASSERT_EQ(lastEvent().type, Event::LayoutPassEnd); - YGMarkerLayoutData layoutData = + LayoutData layoutData = lastEvent().eventTestData().layoutData; ASSERT_EQ(layoutData.layouts, 3); diff --git a/tests/InstrumentationTest.cpp b/tests/InstrumentationTest.cpp deleted file mode 100644 index 62902e31..00000000 --- a/tests/InstrumentationTest.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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. - */ -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -bool operator==(const YGMarkerLayoutData&, const YGMarkerLayoutData&); -void PrintTo(const YGMarkerLayoutData, std::ostream*); - -namespace facebook { -namespace yoga { -namespace marker { -namespace test { - -template -using uniquePtr = std::unique_ptr>; - -struct MarkerTest : public ::testing::Test { - struct Data { - YGMarker marker; - YGNodeRef node; - YGMarkerData markerData; - }; - - struct EndData { - Data data; - void* cookie; - union { - YGMarkerLayoutData layout; - } markerData; - }; - - struct MarkerCookie { - Data start; - EndData end; - }; - - // std::deque will keep pointers stable on reallocation, whereas std::vector - // does not - static std::deque markerCookies; - - static void* startMarker(YGMarker, YGNodeRef, YGMarkerData); - static void endMarker(YGMarker, YGNodeRef, YGMarkerData, void*); - uniquePtr makeNode(); - uniquePtr addChild(uniquePtr& owner); - static void calculateLayout( - uniquePtr& node, - float width = YGUndefined, - float height = YGUndefined); - static MarkerCookie& findMarker(YGMarker); - static MarkerCookie& findLastMarker(YGMarker); - - void SetUp() override; - void TearDown() override; - uniquePtr config; -}; - -void* MarkerTest::startMarker( - YGMarker marker, - YGNodeRef node, - YGMarkerData data) { - markerCookies.emplace_back(); - MarkerCookie* cookie = &markerCookies.back(); - cookie->start = {marker, node, data}; - return cookie; -} - -void MarkerTest::endMarker( - YGMarker marker, - YGNodeRef node, - YGMarkerData data, - void* id) { - auto cookie = static_cast(id); - cookie->end = {{marker, node, data}, id, {}}; -} - -uniquePtr MarkerTest::makeNode() { - auto n = uniquePtr{YGNodeNewWithConfig(config.get()), &YGNodeFree}; - return n; -} - -uniquePtr MarkerTest::addChild(uniquePtr& owner) { - auto n = makeNode(); - YGNodeInsertChild(owner.get(), n.get(), YGNodeGetChildCount(owner.get())); - return n; -} - -void MarkerTest::calculateLayout( - uniquePtr& node, - float width, - float height) { - YGNodeCalculateLayout(node.get(), width, height, YGDirectionLTR); -} - -namespace { - -const char* markerTypeName(YGMarker type) { - return ""; -} - -template -MarkerTest::MarkerCookie& find(It begin, It end, YGMarker type) { - auto result = std::find_if(begin, end, [type](MarkerTest::MarkerCookie& c) { - return c.start.marker == type; - }); - if (result == end) { - throw std::runtime_error{std::string{"No marker recorded for type: "} + - markerTypeName(type)}; - } - return *result; -} - -} // namespace - -MarkerTest::MarkerCookie& MarkerTest::findMarker(YGMarker markerType) { - return find(markerCookies.begin(), markerCookies.end(), markerType); -} - -MarkerTest::MarkerCookie& MarkerTest::findLastMarker(YGMarker markerType) { - return find(markerCookies.rbegin(), markerCookies.rend(), markerType); -} - -void MarkerTest::SetUp() { - config = uniquePtr{YGConfigNew(), &YGConfigFree}; - YGConfigSetMarkerCallbacks(config.get(), {startMarker, endMarker}); -} - -void MarkerTest::TearDown() { - markerCookies.resize(0); -} - -decltype(MarkerTest::markerCookies) MarkerTest::markerCookies = {}; - -} // namespace test -} // namespace marker -} // namespace yoga -} // namespace facebook - -bool operator==(const YGMarkerLayoutData& lhs, const YGMarkerLayoutData& rhs) { - return lhs.layouts == rhs.layouts && lhs.measures == rhs.measures && - lhs.maxMeasureCache == rhs.maxMeasureCache && - lhs.cachedLayouts == rhs.cachedLayouts && - lhs.cachedMeasures == rhs.cachedMeasures; -} - -void PrintTo(const YGMarkerLayoutData data, std::ostream* os) { - *os << "YGMarkerLayoutData{ layouts = " << data.layouts - << ", measures = " << data.measures - << ", maxMeasureCache = " << data.maxMeasureCache - << ", cachedLayouts = " << data.cachedLayouts - << ", cachedMeasures = " << data.cachedMeasures << " }"; -} diff --git a/yoga/YGConfig.h b/yoga/YGConfig.h index aaf6d137..b1bce612 100644 --- a/yoga/YGConfig.h +++ b/yoga/YGConfig.h @@ -5,7 +5,6 @@ * file in the root directory of this source tree. */ #pragma once -#include "YGMarker.h" #include "Yoga-internal.h" #include "Yoga.h" @@ -44,7 +43,6 @@ public: std::array()> experimentalFeatures = {}; void* context = nullptr; - YGMarkerCallbacks markerCallbacks = {nullptr, nullptr}; YGConfig(YGLogger logger); void log(YGConfig*, YGNode*, YGLogLevel, void*, const char*, va_list); diff --git a/yoga/YGMarker.cpp b/yoga/YGMarker.cpp deleted file mode 100644 index e0758e23..00000000 --- a/yoga/YGMarker.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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. - */ -#include "YGMarker.h" -#include "YGConfig.h" - -void YGConfigSetMarkerCallbacks( - YGConfigRef config, - YGMarkerCallbacks markerCallbacks) { - config->markerCallbacks = markerCallbacks; -} diff --git a/yoga/YGMarker.h b/yoga/YGMarker.h deleted file mode 100644 index 025e246a..00000000 --- a/yoga/YGMarker.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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. - */ -#pragma once - -#include "YGMacros.h" - -YG_EXTERN_C_BEGIN - -typedef struct YGNode* YGNodeRef; -typedef struct YGConfig* YGConfigRef; - -typedef YG_ENUM_BEGIN(YGMarker) {} -YG_ENUM_END(YGMarker); - -typedef struct { - int layouts; - int measures; - int maxMeasureCache; - int cachedLayouts; - int cachedMeasures; - int measureCallbacks; -} YGMarkerLayoutData; - -typedef struct { - bool _unused; -} YGMarkerNoData; - -typedef union { - YGMarkerNoData* noData; -} YGMarkerData; - -typedef struct { - // accepts marker type, a node ref, and marker data (depends on marker type) - // can return a handle or id that Yoga will pass to endMarker - void* (*startMarker)(YGMarker, YGNodeRef, YGMarkerData); - // accepts marker type, a node ref, marker data, and marker id as returned by - // startMarker - void (*endMarker)(YGMarker, YGNodeRef, YGMarkerData, void* id); -} YGMarkerCallbacks; - -void YGConfigSetMarkerCallbacks(YGConfigRef, YGMarkerCallbacks); - -YG_EXTERN_C_END - -#ifdef __cplusplus - -namespace facebook { -namespace yoga { -namespace marker { -namespace detail { - -template -struct MarkerData; - -struct NoMarkerData { - using type = YGMarkerNoData; - static type*& get(YGMarkerData& d) { return d.noData; } -}; -} // namespace detail - -template -typename detail::MarkerData::type* data(YGMarkerData d) { - return detail::MarkerData::get(d); -} - -} // namespace marker -} // namespace yoga -} // namespace facebook - -#endif // __cplusplus diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index e3cc78bc..caffe000 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -15,7 +15,6 @@ #include "YGNodePrint.h" #include "Yoga-internal.h" #include "event/event.h" -#include "instrumentation.h" #ifdef _MSC_VER #include @@ -941,7 +940,7 @@ bool YGLayoutNodeInternal( const bool performLayout, const char* reason, const YGConfigRef config, - YGMarkerLayoutData& layoutMarkerData, + LayoutData& layoutMarkerData, void* const layoutContext, const uint32_t depth, const uint32_t generationCount); @@ -1191,7 +1190,7 @@ static void YGNodeComputeFlexBasisForChild( const YGMeasureMode heightMode, const YGDirection direction, const YGConfigRef config, - YGMarkerLayoutData& layoutMarkerData, + LayoutData& layoutMarkerData, void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { @@ -1387,7 +1386,7 @@ static void YGNodeAbsoluteLayoutChild( const float height, const YGDirection direction, const YGConfigRef config, - YGMarkerLayoutData& layoutMarkerData, + LayoutData& layoutMarkerData, void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { @@ -1588,7 +1587,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( const YGMeasureMode heightMeasureMode, const float ownerWidth, const float ownerHeight, - YGMarkerLayoutData& layoutMarkerData, + LayoutData& layoutMarkerData, void* const layoutContext) { YGAssertWithNode( node, @@ -1836,7 +1835,7 @@ static float YGNodeComputeFlexBasisForChildren( YGFlexDirection mainAxis, const YGConfigRef config, bool performLayout, - YGMarkerLayoutData& layoutMarkerData, + LayoutData& layoutMarkerData, void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { @@ -2020,7 +2019,7 @@ static float YGDistributeFreeSpaceSecondPass( const YGMeasureMode measureModeCrossDim, const bool performLayout, const YGConfigRef config, - YGMarkerLayoutData& layoutMarkerData, + LayoutData& layoutMarkerData, void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { @@ -2321,7 +2320,7 @@ static void YGResolveFlexibleLength( const YGMeasureMode measureModeCrossDim, const bool performLayout, const YGConfigRef config, - YGMarkerLayoutData& layoutMarkerData, + LayoutData& layoutMarkerData, void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { @@ -2651,7 +2650,7 @@ static void YGNodelayoutImpl( const float ownerHeight, const bool performLayout, const YGConfigRef config, - YGMarkerLayoutData& layoutMarkerData, + LayoutData& layoutMarkerData, void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { @@ -3707,7 +3706,7 @@ bool YGLayoutNodeInternal( const bool performLayout, const char* reason, const YGConfigRef config, - YGMarkerLayoutData& layoutMarkerData, + LayoutData& layoutMarkerData, void* const layoutContext, uint32_t depth, const uint32_t generationCount) { @@ -4065,7 +4064,7 @@ void YGNodeCalculateLayoutWithContext( void* layoutContext) { Event::publish(node, {layoutContext}); - YGMarkerLayoutData markerData = {}; + LayoutData 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 @@ -4161,7 +4160,7 @@ void YGNodeCalculateLayoutWithContext( gCurrentGenerationCount++; // Rerun the layout, and calculate the diff unsetUseLegacyFlagRecursively(nodeWithoutLegacyFlag); - YGMarkerLayoutData layoutMarkerData = {}; + LayoutData layoutMarkerData = {}; if (YGLayoutNodeInternal( nodeWithoutLegacyFlag, width, diff --git a/yoga/event/event.h b/yoga/event/event.h index 2043cc8c..dc49cefc 100644 --- a/yoga/event/event.h +++ b/yoga/event/event.h @@ -9,7 +9,6 @@ #include #include #include -#include struct YGConfig; struct YGNode; @@ -24,6 +23,15 @@ enum LayoutType : int { kCachedMeasure = 3 }; +struct LayoutData { + int layouts; + int measures; + int maxMeasureCache; + int cachedLayouts; + int cachedMeasures; + int measureCallbacks; +}; + struct Event { enum Type { NodeAllocation, @@ -94,7 +102,7 @@ struct Event::TypedData { template <> struct Event::TypedData { void* layoutContext; - YGMarkerLayoutData* layoutData; + LayoutData* layoutData; }; template <> diff --git a/yoga/instrumentation.h b/yoga/instrumentation.h deleted file mode 100644 index 369703a1..00000000 --- a/yoga/instrumentation.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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. - */ -#include "YGConfig.h" -#include "YGMarker.h" -#include "YGNode.h" - -namespace facebook { -namespace yoga { -namespace marker { - -template -class MarkerSection { -private: - using Data = detail::MarkerData; - -public: - MarkerSection(YGNodeRef node) : MarkerSection{node, node->getConfig()} {} - void end() { - if (endMarker_) { - endMarker_(MarkerType, node_, markerData(&data), userData_); - endMarker_ = nullptr; - } - } - ~MarkerSection() { end(); } - - typename Data::type data = {}; - - template - static Ret wrap( - YGNodeRef node, - Ret (YGNode::*method)(Args...), - Args... args) { - MarkerSection section{node}; - return (node->*method)(std::forward(args)...); - } - -private: - decltype(YGMarkerCallbacks{}.endMarker) endMarker_; - YGNodeRef node_; - void* userData_; - - MarkerSection(YGNodeRef node, YGConfigRef config) - : MarkerSection{node, config ? &config->markerCallbacks : nullptr} {} - MarkerSection(YGNodeRef node, YGMarkerCallbacks* callbacks) - : endMarker_{callbacks ? callbacks->endMarker : nullptr}, - node_{node}, - userData_{ - callbacks && callbacks->startMarker - ? callbacks->startMarker(MarkerType, node, markerData(&data)) - : nullptr} {} - - static YGMarkerData markerData(typename Data::type* d) { - YGMarkerData markerData = {}; - Data::get(markerData) = d; - return markerData; - } -}; - -} // namespace marker -} // namespace yoga -} // namespace facebook