Revert D48710796: C++ Cleanup 2/N: Reorganize YGConfig

Differential Revision:
D48710796

Original commit changeset: d548553f7ce8

Original Phabricator Diff: D48710796

fbshipit-source-id: c8b2de245f3894f6a87c262ec70d313020aa228e
This commit is contained in:
Zhiyao Zhou
2023-08-29 23:27:25 -07:00
committed by Facebook GitHub Bot
parent ea7f61a3db
commit 13c5ce2234
10 changed files with 107 additions and 122 deletions

View File

@@ -19,8 +19,6 @@
// API and use that // API and use that
#include <yoga/YGNode.h> #include <yoga/YGNode.h>
using namespace facebook;
using namespace facebook::yoga;
using namespace facebook::yoga::vanillajni; using namespace facebook::yoga::vanillajni;
static inline ScopedLocalRef<jobject> YGNodeJobject( static inline ScopedLocalRef<jobject> YGNodeJobject(
@@ -196,7 +194,7 @@ static void jni_YGConfigSetLoggerJNI(
} }
*context = newGlobalRef(env, logger); *context = newGlobalRef(env, logger);
static_cast<yoga::Config*>(config)->setLogger(YGJNILogFunc); config->setLogger(YGJNILogFunc);
} else { } else {
if (context != nullptr) { if (context != nullptr) {
delete context; delete context;

View File

@@ -9,16 +9,14 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
#include <yoga/config/Config.h> #include <yoga/YGConfig.h>
#include <yoga/YGNode.h> #include <yoga/YGNode.h>
#include <functional> #include <functional>
#include <memory> #include <memory>
using namespace facebook;
struct ConfigCloningTest : public ::testing::Test { struct ConfigCloningTest : public ::testing::Test {
std::unique_ptr<yoga::Config, std::function<void(yoga::Config*)>> config; std::unique_ptr<YGConfig, std::function<void(YGConfig*)>> config;
void SetUp() override; void SetUp() override;
void TearDown() override; void TearDown() override;
@@ -58,7 +56,7 @@ TEST_F(ConfigCloningTest, can_clone_with_context) {
} }
void ConfigCloningTest::SetUp() { void ConfigCloningTest::SetUp() {
config = {static_cast<yoga::Config*>(YGConfigNew()), YGConfigFree}; config = {YGConfigNew(), YGConfigFree};
} }
void ConfigCloningTest::TearDown() { void ConfigCloningTest::TearDown() {

View File

@@ -5,129 +5,133 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#include <yoga/config/Config.h> #include "YGConfig.h"
using namespace facebook::yoga;
namespace facebook::yoga { namespace facebook::yoga {
bool configUpdateInvalidatesLayout(YGConfigRef a, YGConfigRef b) {
bool configUpdateInvalidatesLayout(Config* a, Config* b) {
return a->getErrata() != b->getErrata() || return a->getErrata() != b->getErrata() ||
a->getEnabledExperiments() != b->getEnabledExperiments() || a->getEnabledExperiments() != b->getEnabledExperiments() ||
a->getPointScaleFactor() != b->getPointScaleFactor() || a->getPointScaleFactor() != b->getPointScaleFactor() ||
a->useWebDefaults() != b->useWebDefaults(); a->useWebDefaults() != b->useWebDefaults();
} }
} // namespace facebook::yoga
Config::Config(YGLogger logger) : cloneNodeCallback_{nullptr} { YGConfig::YGConfig(YGLogger logger) : cloneNodeCallback_{nullptr} {
setLogger(logger); setLogger(logger);
} }
void Config::setUseWebDefaults(bool useWebDefaults) { void YGConfig::setUseWebDefaults(bool useWebDefaults) {
flags_.useWebDefaults = useWebDefaults; flags_.useWebDefaults = useWebDefaults;
} }
bool Config::useWebDefaults() const { bool YGConfig::useWebDefaults() const {
return flags_.useWebDefaults; return flags_.useWebDefaults;
} }
void Config::setShouldPrintTree(bool printTree) { void YGConfig::setShouldPrintTree(bool printTree) {
flags_.printTree = printTree; flags_.printTree = printTree;
} }
bool Config::shouldPrintTree() const { bool YGConfig::shouldPrintTree() const {
return flags_.printTree; return flags_.printTree;
} }
void Config::setExperimentalFeatureEnabled( void YGConfig::setExperimentalFeatureEnabled(
YGExperimentalFeature feature, YGExperimentalFeature feature,
bool enabled) { bool enabled) {
experimentalFeatures_.set(feature, enabled); experimentalFeatures_.set(feature, enabled);
} }
bool Config::isExperimentalFeatureEnabled(YGExperimentalFeature feature) const { bool YGConfig::isExperimentalFeatureEnabled(
YGExperimentalFeature feature) const {
return experimentalFeatures_.test(feature); return experimentalFeatures_.test(feature);
} }
ExperimentalFeatureSet Config::getEnabledExperiments() const { ExperimentalFeatureSet YGConfig::getEnabledExperiments() const {
return experimentalFeatures_; return experimentalFeatures_;
} }
void Config::setErrata(YGErrata errata) { void YGConfig::setErrata(YGErrata errata) {
errata_ = errata; errata_ = errata;
} }
void Config::addErrata(YGErrata errata) { void YGConfig::addErrata(YGErrata errata) {
errata_ |= errata; errata_ |= errata;
} }
void Config::removeErrata(YGErrata errata) { void YGConfig::removeErrata(YGErrata errata) {
errata_ &= (~errata); errata_ &= (~errata);
} }
YGErrata Config::getErrata() const { YGErrata YGConfig::getErrata() const {
return errata_; return errata_;
} }
bool Config::hasErrata(YGErrata errata) const { bool YGConfig::hasErrata(YGErrata errata) const {
return (errata_ & errata) != YGErrataNone; return (errata_ & errata) != YGErrataNone;
} }
void Config::setPointScaleFactor(float pointScaleFactor) { void YGConfig::setPointScaleFactor(float pointScaleFactor) {
pointScaleFactor_ = pointScaleFactor; pointScaleFactor_ = pointScaleFactor;
} }
float Config::getPointScaleFactor() const { float YGConfig::getPointScaleFactor() const {
return pointScaleFactor_; return pointScaleFactor_;
} }
void Config::setContext(void* context) { void YGConfig::setContext(void* context) {
context_ = context; context_ = context;
} }
void* Config::getContext() const { void* YGConfig::getContext() const {
return context_; return context_;
} }
void Config::setLogger(YGLogger logger) { void YGConfig::setLogger(YGLogger logger) {
logger_.noContext = logger; logger_.noContext = logger;
flags_.loggerUsesContext = false; flags_.loggerUsesContext = false;
} }
void Config::setLogger(LogWithContextFn logger) { void YGConfig::setLogger(LogWithContextFn logger) {
logger_.withContext = logger; logger_.withContext = logger;
flags_.loggerUsesContext = true; flags_.loggerUsesContext = true;
} }
void Config::setLogger(std::nullptr_t) { void YGConfig::setLogger(std::nullptr_t) {
setLogger(YGLogger{nullptr}); setLogger(YGLogger{nullptr});
} }
void Config::log( void YGConfig::log(
YGNodeRef node, YGConfig* config,
YGNode* node,
YGLogLevel logLevel, YGLogLevel logLevel,
void* logContext, void* logContext,
const char* format, const char* format,
va_list args) { va_list args) const {
if (flags_.loggerUsesContext) { if (flags_.loggerUsesContext) {
logger_.withContext(this, node, logLevel, logContext, format, args); logger_.withContext(config, node, logLevel, logContext, format, args);
} else { } else {
logger_.noContext(this, node, logLevel, format, args); logger_.noContext(config, node, logLevel, format, args);
} }
} }
void Config::setCloneNodeCallback(YGCloneNodeFunc cloneNode) { void YGConfig::setCloneNodeCallback(YGCloneNodeFunc cloneNode) {
cloneNodeCallback_.noContext = cloneNode; cloneNodeCallback_.noContext = cloneNode;
flags_.cloneNodeUsesContext = false; flags_.cloneNodeUsesContext = false;
} }
void Config::setCloneNodeCallback(CloneWithContextFn cloneNode) { void YGConfig::setCloneNodeCallback(CloneWithContextFn cloneNode) {
cloneNodeCallback_.withContext = cloneNode; cloneNodeCallback_.withContext = cloneNode;
flags_.cloneNodeUsesContext = true; flags_.cloneNodeUsesContext = true;
} }
void Config::setCloneNodeCallback(std::nullptr_t) { void YGConfig::setCloneNodeCallback(std::nullptr_t) {
setCloneNodeCallback(YGCloneNodeFunc{nullptr}); setCloneNodeCallback(YGCloneNodeFunc{nullptr});
} }
YGNodeRef Config::cloneNode( YGNodeRef YGConfig::cloneNode(
YGNodeRef node, YGNodeRef node,
YGNodeRef owner, YGNodeRef owner,
int childIndex, int childIndex,
@@ -143,5 +147,3 @@ YGNodeRef Config::cloneNode(
} }
return clone; return clone;
} }
} // namespace facebook::yoga

View File

@@ -12,16 +12,11 @@
#include <yoga/BitUtils.h> #include <yoga/BitUtils.h>
#include <yoga/Yoga-internal.h> #include <yoga/Yoga-internal.h>
// Tag struct used to form the opaque YGConfigRef for the public C API
struct YGConfig {};
namespace facebook::yoga { namespace facebook::yoga {
class Config;
// Whether moving a node from config "a" to config "b" should dirty previously // Whether moving a node from config "a" to config "b" should dirty previously
// calculated layout results. // calculated layout results.
bool configUpdateInvalidatesLayout(Config* a, Config* b); bool configUpdateInvalidatesLayout(YGConfigRef a, YGConfigRef b);
// Internal variants of log functions, currently used only by JNI bindings. // Internal variants of log functions, currently used only by JNI bindings.
// TODO: Reconcile this with the public API // TODO: Reconcile this with the public API
@@ -38,12 +33,13 @@ using CloneWithContextFn = YGNodeRef (*)(
int childIndex, int childIndex,
void* cloneContext); void* cloneContext);
using ExperimentalFeatureSet = detail::EnumBitset<YGExperimentalFeature>; using ExperimentalFeatureSet =
facebook::yoga::detail::EnumBitset<YGExperimentalFeature>;
#pragma pack(push) #pragma pack(push)
#pragma pack(1) #pragma pack(1)
// Packed structure of <32-bit options to miminize size per node. // Packed structure of <32-bit options to miminize size per node.
struct ConfigFlags { struct YGConfigFlags {
bool useWebDefaults : 1; bool useWebDefaults : 1;
bool printTree : 1; bool printTree : 1;
bool cloneNodeUsesContext : 1; bool cloneNodeUsesContext : 1;
@@ -51,9 +47,10 @@ struct ConfigFlags {
}; };
#pragma pack(pop) #pragma pack(pop)
class YOGA_EXPORT Config : public ::YGConfig { } // namespace facebook::yoga
public:
Config(YGLogger logger); struct YOGA_EXPORT YGConfig {
YGConfig(YGLogger logger);
void setUseWebDefaults(bool useWebDefaults); void setUseWebDefaults(bool useWebDefaults);
bool useWebDefaults() const; bool useWebDefaults() const;
@@ -65,7 +62,7 @@ public:
YGExperimentalFeature feature, YGExperimentalFeature feature,
bool enabled); bool enabled);
bool isExperimentalFeatureEnabled(YGExperimentalFeature feature) const; bool isExperimentalFeatureEnabled(YGExperimentalFeature feature) const;
ExperimentalFeatureSet getEnabledExperiments() const; facebook::yoga::ExperimentalFeatureSet getEnabledExperiments() const;
void setErrata(YGErrata errata); void setErrata(YGErrata errata);
void addErrata(YGErrata errata); void addErrata(YGErrata errata);
@@ -80,12 +77,12 @@ public:
void* getContext() const; void* getContext() const;
void setLogger(YGLogger logger); void setLogger(YGLogger logger);
void setLogger(LogWithContextFn logger); void setLogger(facebook::yoga::LogWithContextFn logger);
void setLogger(std::nullptr_t); void setLogger(std::nullptr_t);
void log(YGNodeRef, YGLogLevel, void*, const char*, va_list); void log(YGConfig*, YGNode*, YGLogLevel, void*, const char*, va_list) const;
void setCloneNodeCallback(YGCloneNodeFunc cloneNode); void setCloneNodeCallback(YGCloneNodeFunc cloneNode);
void setCloneNodeCallback(CloneWithContextFn cloneNode); void setCloneNodeCallback(facebook::yoga::CloneWithContextFn cloneNode);
void setCloneNodeCallback(std::nullptr_t); void setCloneNodeCallback(std::nullptr_t);
YGNodeRef cloneNode( YGNodeRef cloneNode(
YGNodeRef node, YGNodeRef node,
@@ -95,19 +92,17 @@ public:
private: private:
union { union {
CloneWithContextFn withContext; facebook::yoga::CloneWithContextFn withContext;
YGCloneNodeFunc noContext; YGCloneNodeFunc noContext;
} cloneNodeCallback_; } cloneNodeCallback_;
union { union {
LogWithContextFn withContext; facebook::yoga::LogWithContextFn withContext;
YGLogger noContext; YGLogger noContext;
} logger_; } logger_;
ConfigFlags flags_{}; facebook::yoga::YGConfigFlags flags_{};
ExperimentalFeatureSet experimentalFeatures_{}; facebook::yoga::ExperimentalFeatureSet experimentalFeatures_{};
YGErrata errata_ = YGErrataNone; YGErrata errata_ = YGErrataNone;
float pointScaleFactor_ = 1.0f; float pointScaleFactor_ = 1.0f;
void* context_ = nullptr; void* context_ = nullptr;
}; };
} // namespace facebook::yoga

View File

@@ -14,7 +14,7 @@ using namespace facebook;
using namespace facebook::yoga; using namespace facebook::yoga;
using facebook::yoga::CompactValue; using facebook::yoga::CompactValue;
YGNode::YGNode(yoga::Config* config) : config_{config} { YGNode::YGNode(const YGConfigRef config) : config_{config} {
YGAssert( YGAssert(
config != nullptr, "Attempting to construct YGNode with null config"); config != nullptr, "Attempting to construct YGNode with null config");
@@ -264,7 +264,7 @@ void YGNode::insertChild(YGNodeRef child, uint32_t index) {
children_.insert(children_.begin() + index, child); children_.insert(children_.begin() + index, child);
} }
void YGNode::setConfig(yoga::Config* config) { void YGNode::setConfig(YGConfigRef config) {
YGAssert(config != nullptr, "Attempting to set a null config on a YGNode"); YGAssert(config != nullptr, "Attempting to set a null config on a YGNode");
YGAssertWithConfig( YGAssertWithConfig(
config, config,

View File

@@ -9,13 +9,15 @@
#include <cstdint> #include <cstdint>
#include <stdio.h> #include <stdio.h>
#include <yoga/config/Config.h> #include "YGConfig.h"
#include "YGLayout.h" #include "YGLayout.h"
#include <yoga/Yoga-internal.h> #include <yoga/Yoga-internal.h>
#include <yoga/style/CompactValue.h> #include <yoga/style/CompactValue.h>
#include <yoga/style/Style.h> #include <yoga/style/Style.h>
YGConfigRef YGConfigGetDefault();
#pragma pack(push) #pragma pack(push)
#pragma pack(1) #pragma pack(1)
struct YGNodeFlags { struct YGNodeFlags {
@@ -56,7 +58,7 @@ private:
uint32_t lineIndex_ = 0; uint32_t lineIndex_ = 0;
YGNodeRef owner_ = nullptr; YGNodeRef owner_ = nullptr;
YGVector children_ = {}; YGVector children_ = {};
facebook::yoga::Config* config_; YGConfigRef config_;
std::array<YGValue, 2> resolvedDimensions_ = { std::array<YGValue, 2> resolvedDimensions_ = {
{YGValueUndefined, YGValueUndefined}}; {YGValueUndefined, YGValueUndefined}};
@@ -82,11 +84,8 @@ private:
using CompactValue = facebook::yoga::CompactValue; using CompactValue = facebook::yoga::CompactValue;
public: public:
YGNode() YGNode() : YGNode{YGConfigGetDefault()} { flags_.hasNewLayout = true; }
: YGNode{static_cast<facebook::yoga::Config*>(YGConfigGetDefault())} { explicit YGNode(const YGConfigRef config);
flags_.hasNewLayout = true;
}
explicit YGNode(facebook::yoga::Config* config);
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree ~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree
YGNode(YGNode&&); YGNode(YGNode&&);
@@ -167,7 +166,7 @@ public:
YGNodeRef getChild(uint32_t index) const { return children_.at(index); } YGNodeRef getChild(uint32_t index) const { return children_.at(index); }
facebook::yoga::Config* getConfig() const { return config_; } YGConfigRef getConfig() const { return config_; }
bool isDirty() const { return flags_.isDirty; } bool isDirty() const { return flags_.isDirty; }
@@ -291,7 +290,7 @@ public:
// TODO: rvalue override for setChildren // TODO: rvalue override for setChildren
void setConfig(facebook::yoga::Config* config); void setConfig(YGConfigRef config);
void setDirty(bool isDirty); void setDirty(bool isDirty);
void setLayoutLastOwnerDirection(YGDirection direction); void setLayoutLastOwnerDirection(YGDirection direction);

View File

@@ -20,7 +20,6 @@
#include <yoga/Yoga-internal.h> #include <yoga/Yoga-internal.h>
#include "event/event.h" #include "event/event.h"
using namespace facebook;
using namespace facebook::yoga; using namespace facebook::yoga;
using detail::Log; using detail::Log;
@@ -120,7 +119,7 @@ YOGA_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node) {
} }
YOGA_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config) { YOGA_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config) {
node->setConfig(static_cast<yoga::Config*>(config)); node->setConfig(config);
} }
YOGA_EXPORT bool YGNodeHasMeasureFunc(YGNodeRef node) { YOGA_EXPORT bool YGNodeHasMeasureFunc(YGNodeRef node) {
@@ -162,7 +161,7 @@ YOGA_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node) {
} }
YOGA_EXPORT void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) { YOGA_EXPORT void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) {
static_cast<yoga::Config*>(config)->setShouldPrintTree(enabled); config->setShouldPrintTree(enabled);
} }
YOGA_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) { YOGA_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) {
@@ -189,7 +188,7 @@ YOGA_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(
int32_t gConfigInstanceCount = 0; int32_t gConfigInstanceCount = 0;
YOGA_EXPORT WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { YOGA_EXPORT WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
const YGNodeRef node = new YGNode{static_cast<yoga::Config*>(config)}; const YGNodeRef node = new YGNode{config};
YGAssert(config != nullptr, "Tried to construct YGNode with null config"); YGAssert(config != nullptr, "Tried to construct YGNode with null config");
YGAssertWithConfig( YGAssertWithConfig(
config, node != nullptr, "Could not allocate memory for node"); config, node != nullptr, "Could not allocate memory for node");
@@ -273,19 +272,23 @@ YOGA_EXPORT int32_t YGConfigGetInstanceCount(void) {
YOGA_EXPORT YGConfigRef YGConfigNew(void) { YOGA_EXPORT YGConfigRef YGConfigNew(void) {
#ifdef ANDROID #ifdef ANDROID
const YGConfigRef config = new yoga::Config(YGAndroidLog); const YGConfigRef config = new YGConfig(YGAndroidLog);
#else #else
const YGConfigRef config = new yoga::Config(YGDefaultLog); const YGConfigRef config = new YGConfig(YGDefaultLog);
#endif #endif
gConfigInstanceCount++; gConfigInstanceCount++;
return config; return config;
} }
YOGA_EXPORT void YGConfigFree(const YGConfigRef config) { YOGA_EXPORT void YGConfigFree(const YGConfigRef config) {
delete static_cast<yoga::Config*>(config); delete config;
gConfigInstanceCount--; gConfigInstanceCount--;
} }
void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src) {
memcpy(dest, src, sizeof(YGConfig));
}
YOGA_EXPORT void YGNodeSetIsReferenceBaseline( YOGA_EXPORT void YGNodeSetIsReferenceBaseline(
YGNodeRef node, YGNodeRef node,
bool isReferenceBaseline) { bool isReferenceBaseline) {
@@ -3712,22 +3715,22 @@ YOGA_EXPORT bool YGNodeCanUseCachedMeasurement(
return false; return false;
} }
bool useRoundedComparison = bool useRoundedComparison =
config != nullptr && YGConfigGetPointScaleFactor(config) != 0; config != nullptr && config->getPointScaleFactor() != 0;
const float effectiveWidth = useRoundedComparison const float effectiveWidth = useRoundedComparison
? YGRoundValueToPixelGrid( ? YGRoundValueToPixelGrid(
width, YGConfigGetPointScaleFactor(config), false, false) width, config->getPointScaleFactor(), false, false)
: width; : width;
const float effectiveHeight = useRoundedComparison const float effectiveHeight = useRoundedComparison
? YGRoundValueToPixelGrid( ? YGRoundValueToPixelGrid(
height, YGConfigGetPointScaleFactor(config), false, false) height, config->getPointScaleFactor(), false, false)
: height; : height;
const float effectiveLastWidth = useRoundedComparison const float effectiveLastWidth = useRoundedComparison
? YGRoundValueToPixelGrid( ? YGRoundValueToPixelGrid(
lastWidth, YGConfigGetPointScaleFactor(config), false, false) lastWidth, config->getPointScaleFactor(), false, false)
: lastWidth; : lastWidth;
const float effectiveLastHeight = useRoundedComparison const float effectiveLastHeight = useRoundedComparison
? YGRoundValueToPixelGrid( ? YGRoundValueToPixelGrid(
lastHeight, YGConfigGetPointScaleFactor(config), false, false) lastHeight, config->getPointScaleFactor(), false, false)
: lastHeight; : lastHeight;
const bool hasSameWidthSpec = lastWidthMode == widthMode && const bool hasSameWidthSpec = lastWidthMode == widthMode &&
@@ -4054,14 +4057,14 @@ YOGA_EXPORT void YGConfigSetPointScaleFactor(
// We store points for Pixel as we will use it for rounding // We store points for Pixel as we will use it for rounding
if (pixelsInPoint == 0.0f) { if (pixelsInPoint == 0.0f) {
// Zero is used to skip rounding // Zero is used to skip rounding
static_cast<yoga::Config*>(config)->setPointScaleFactor(0.0f); config->setPointScaleFactor(0.0f);
} else { } else {
static_cast<yoga::Config*>(config)->setPointScaleFactor(pixelsInPoint); config->setPointScaleFactor(pixelsInPoint);
} }
} }
YOGA_EXPORT float YGConfigGetPointScaleFactor(const YGConfigRef config) { YOGA_EXPORT float YGConfigGetPointScaleFactor(const YGConfigRef config) {
return static_cast<yoga::Config*>(config)->getPointScaleFactor(); return config->getPointScaleFactor();
} }
static void YGRoundToPixelGrid( static void YGRoundToPixelGrid(
@@ -4236,12 +4239,12 @@ YOGA_EXPORT void YGNodeCalculateLayout(
YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) { YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
if (logger != nullptr) { if (logger != nullptr) {
static_cast<yoga::Config*>(config)->setLogger(logger); config->setLogger(logger);
} else { } else {
#ifdef ANDROID #ifdef ANDROID
static_cast<yoga::Config*>(config)->setLogger(&YGAndroidLog); config->setLogger(&YGAndroidLog);
#else #else
static_cast<yoga::Config*>(config)->setLogger(&YGDefaultLog); config->setLogger(&YGDefaultLog);
#endif #endif
} }
} }
@@ -4268,12 +4271,7 @@ void YGAssertWithConfig(
const bool condition, const bool condition,
const char* message) { const char* message) {
if (!condition) { if (!condition) {
Log::log( Log::log(config, YGLogLevelFatal, nullptr, "%s\n", message);
static_cast<yoga::Config*>(config),
YGLogLevelFatal,
nullptr,
"%s\n",
message);
throwLogicalErrorWithMessage(message); throwLogicalErrorWithMessage(message);
} }
} }
@@ -4282,61 +4280,58 @@ YOGA_EXPORT void YGConfigSetExperimentalFeatureEnabled(
const YGConfigRef config, const YGConfigRef config,
const YGExperimentalFeature feature, const YGExperimentalFeature feature,
const bool enabled) { const bool enabled) {
static_cast<yoga::Config*>(config)->setExperimentalFeatureEnabled( config->setExperimentalFeatureEnabled(feature, enabled);
feature, enabled);
} }
YOGA_EXPORT bool YGConfigIsExperimentalFeatureEnabled( YOGA_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
const YGConfigRef config, const YGConfigRef config,
const YGExperimentalFeature feature) { const YGExperimentalFeature feature) {
return static_cast<yoga::Config*>(config)->isExperimentalFeatureEnabled( return config->isExperimentalFeatureEnabled(feature);
feature);
} }
YOGA_EXPORT void YGConfigSetUseWebDefaults( YOGA_EXPORT void YGConfigSetUseWebDefaults(
const YGConfigRef config, const YGConfigRef config,
const bool enabled) { const bool enabled) {
static_cast<yoga::Config*>(config)->setUseWebDefaults(enabled); config->setUseWebDefaults(enabled);
} }
YOGA_EXPORT bool YGConfigGetUseLegacyStretchBehaviour( YOGA_EXPORT bool YGConfigGetUseLegacyStretchBehaviour(
const YGConfigRef config) { const YGConfigRef config) {
return static_cast<yoga::Config*>(config)->hasErrata( return config->hasErrata(YGErrataStretchFlexBasis);
YGErrataStretchFlexBasis);
} }
YOGA_EXPORT void YGConfigSetUseLegacyStretchBehaviour( YOGA_EXPORT void YGConfigSetUseLegacyStretchBehaviour(
const YGConfigRef config, const YGConfigRef config,
const bool useLegacyStretchBehaviour) { const bool useLegacyStretchBehaviour) {
if (useLegacyStretchBehaviour) { if (useLegacyStretchBehaviour) {
static_cast<yoga::Config*>(config)->addErrata(YGErrataStretchFlexBasis); config->addErrata(YGErrataStretchFlexBasis);
} else { } else {
static_cast<yoga::Config*>(config)->removeErrata(YGErrataStretchFlexBasis); config->removeErrata(YGErrataStretchFlexBasis);
} }
} }
bool YGConfigGetUseWebDefaults(const YGConfigRef config) { bool YGConfigGetUseWebDefaults(const YGConfigRef config) {
return static_cast<yoga::Config*>(config)->useWebDefaults(); return config->useWebDefaults();
} }
YOGA_EXPORT void YGConfigSetContext(const YGConfigRef config, void* context) { YOGA_EXPORT void YGConfigSetContext(const YGConfigRef config, void* context) {
static_cast<yoga::Config*>(config)->setContext(context); config->setContext(context);
} }
YOGA_EXPORT void* YGConfigGetContext(const YGConfigRef config) { YOGA_EXPORT void* YGConfigGetContext(const YGConfigRef config) {
return static_cast<yoga::Config*>(config)->getContext(); return config->getContext();
} }
YOGA_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata) { YOGA_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata) {
static_cast<yoga::Config*>(config)->setErrata(errata); config->setErrata(errata);
} }
YOGA_EXPORT YGErrata YGConfigGetErrata(YGConfigRef config) { YOGA_EXPORT YGErrata YGConfigGetErrata(YGConfigRef config) {
return static_cast<yoga::Config*>(config)->getErrata(); return config->getErrata();
} }
YOGA_EXPORT void YGConfigSetCloneNodeFunc( YOGA_EXPORT void YGConfigSetCloneNodeFunc(
const YGConfigRef config, const YGConfigRef config,
const YGCloneNodeFunc callback) { const YGCloneNodeFunc callback) {
static_cast<yoga::Config*>(config)->setCloneNodeCallback(callback); config->setCloneNodeCallback(callback);
} }

View File

@@ -343,6 +343,7 @@ void YGConfigSetUseLegacyStretchBehaviour(
// YGConfig // YGConfig
WIN_EXPORT YGConfigRef YGConfigNew(void); WIN_EXPORT YGConfigRef YGConfigNew(void);
WIN_EXPORT void YGConfigFree(YGConfigRef config); WIN_EXPORT void YGConfigFree(YGConfigRef config);
WIN_EXPORT void YGConfigCopy(YGConfigRef dest, YGConfigRef src);
WIN_EXPORT int32_t YGConfigGetInstanceCount(void); WIN_EXPORT int32_t YGConfigGetInstanceCount(void);
WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled( WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(

View File

@@ -8,7 +8,7 @@
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
#include "log.h" #include "log.h"
#include <yoga/config/Config.h> #include "YGConfig.h"
#include "YGNode.h" #include "YGNode.h"
namespace facebook::yoga::detail { namespace facebook::yoga::detail {
@@ -16,16 +16,14 @@ namespace facebook::yoga::detail {
namespace { namespace {
void vlog( void vlog(
yoga::Config* config, YGConfig* config,
YGNode* node, YGNode* node,
YGLogLevel level, YGLogLevel level,
void* context, void* context,
const char* format, const char* format,
va_list args) { va_list args) {
yoga::Config* logConfig = config != nullptr YGConfig* logConfig = config != nullptr ? config : YGConfigGetDefault();
? config logConfig->log(logConfig, node, level, context, format, args);
: static_cast<yoga::Config*>(YGConfigGetDefault());
logConfig->log(node, level, context, format, args);
} }
} // namespace } // namespace
@@ -48,7 +46,7 @@ YOGA_EXPORT void Log::log(
} }
void Log::log( void Log::log(
yoga::Config* config, YGConfig* config,
YGLogLevel level, YGLogLevel level,
void* context, void* context,
const char* format, const char* format,

View File

@@ -8,7 +8,6 @@
#pragma once #pragma once
#include <yoga/YGEnums.h> #include <yoga/YGEnums.h>
#include <yoga/config/Config.h>
struct YGNode; struct YGNode;
struct YGConfig; struct YGConfig;
@@ -24,7 +23,7 @@ struct Log {
...) noexcept; ...) noexcept;
static void log( static void log(
yoga::Config* config, YGConfig* config,
YGLogLevel level, YGLogLevel level,
void*, void*,
const char* format, const char* format,