add third party: yoga 1.18.0
This commit is contained in:
87
doric-Qt/doric/yoga/event/event.cpp
Normal file
87
doric-Qt/doric/yoga/event/event.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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 "event.h"
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace facebook {
|
||||
namespace yoga {
|
||||
|
||||
const char* LayoutPassReasonToString(const LayoutPassReason value) {
|
||||
switch (value) {
|
||||
case LayoutPassReason::kInitial:
|
||||
return "initial";
|
||||
case LayoutPassReason::kAbsLayout:
|
||||
return "abs_layout";
|
||||
case LayoutPassReason::kStretch:
|
||||
return "stretch";
|
||||
case LayoutPassReason::kMultilineStretch:
|
||||
return "multiline_stretch";
|
||||
case LayoutPassReason::kFlexLayout:
|
||||
return "flex_layout";
|
||||
case LayoutPassReason::kMeasureChild:
|
||||
return "measure";
|
||||
case LayoutPassReason::kAbsMeasureChild:
|
||||
return "abs_measure";
|
||||
case LayoutPassReason::kFlexMeasure:
|
||||
return "flex_measure";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct Node {
|
||||
std::function<Event::Subscriber> subscriber = nullptr;
|
||||
Node* next = nullptr;
|
||||
|
||||
Node(std::function<Event::Subscriber>&& subscriber)
|
||||
: subscriber{std::move(subscriber)} {}
|
||||
};
|
||||
|
||||
std::atomic<Node*> subscribers{nullptr};
|
||||
|
||||
Node* push(Node* newHead) {
|
||||
Node* oldHead;
|
||||
do {
|
||||
oldHead = subscribers.load(std::memory_order_relaxed);
|
||||
if (newHead != nullptr) {
|
||||
newHead->next = oldHead;
|
||||
}
|
||||
} while (!subscribers.compare_exchange_weak(
|
||||
oldHead, newHead, std::memory_order_release, std::memory_order_relaxed));
|
||||
return oldHead;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void Event::reset() {
|
||||
auto head = push(nullptr);
|
||||
while (head != nullptr) {
|
||||
auto current = head;
|
||||
head = head->next;
|
||||
delete current;
|
||||
}
|
||||
}
|
||||
|
||||
void Event::subscribe(std::function<Subscriber>&& subscriber) {
|
||||
push(new Node{std::move(subscriber)});
|
||||
}
|
||||
|
||||
void Event::publish(const YGNode& node, Type eventType, const Data& eventData) {
|
||||
for (auto subscriber = subscribers.load(std::memory_order_relaxed);
|
||||
subscriber != nullptr;
|
||||
subscriber = subscriber->next) {
|
||||
subscriber->subscriber(node, eventType, eventData);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace yoga
|
||||
} // namespace facebook
|
145
doric-Qt/doric/yoga/event/event.h
Normal file
145
doric-Qt/doric/yoga/event/event.h
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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 <functional>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <yoga/YGEnums.h>
|
||||
|
||||
struct YGConfig;
|
||||
struct YGNode;
|
||||
|
||||
namespace facebook {
|
||||
namespace yoga {
|
||||
|
||||
enum struct LayoutType : int {
|
||||
kLayout = 0,
|
||||
kMeasure = 1,
|
||||
kCachedLayout = 2,
|
||||
kCachedMeasure = 3
|
||||
};
|
||||
|
||||
enum struct LayoutPassReason : int {
|
||||
kInitial = 0,
|
||||
kAbsLayout = 1,
|
||||
kStretch = 2,
|
||||
kMultilineStretch = 3,
|
||||
kFlexLayout = 4,
|
||||
kMeasureChild = 5,
|
||||
kAbsMeasureChild = 6,
|
||||
kFlexMeasure = 7,
|
||||
COUNT
|
||||
};
|
||||
|
||||
struct LayoutData {
|
||||
int layouts;
|
||||
int measures;
|
||||
int maxMeasureCache;
|
||||
int cachedLayouts;
|
||||
int cachedMeasures;
|
||||
int measureCallbacks;
|
||||
std::array<int, static_cast<uint8_t>(LayoutPassReason::COUNT)>
|
||||
measureCallbackReasonsCount;
|
||||
};
|
||||
|
||||
const char* LayoutPassReasonToString(const LayoutPassReason value);
|
||||
|
||||
struct YOGA_EXPORT Event {
|
||||
enum Type {
|
||||
NodeAllocation,
|
||||
NodeDeallocation,
|
||||
NodeLayout,
|
||||
LayoutPassStart,
|
||||
LayoutPassEnd,
|
||||
MeasureCallbackStart,
|
||||
MeasureCallbackEnd,
|
||||
NodeBaselineStart,
|
||||
NodeBaselineEnd,
|
||||
};
|
||||
class Data;
|
||||
using Subscriber = void(const YGNode&, Type, Data);
|
||||
using Subscribers = std::vector<std::function<Subscriber>>;
|
||||
|
||||
template <Type E>
|
||||
struct TypedData {};
|
||||
|
||||
class Data {
|
||||
const void* data_;
|
||||
|
||||
public:
|
||||
template <Type E>
|
||||
Data(const TypedData<E>& data) : data_{&data} {}
|
||||
|
||||
template <Type E>
|
||||
const TypedData<E>& get() const {
|
||||
return *static_cast<const TypedData<E>*>(data_);
|
||||
};
|
||||
};
|
||||
|
||||
static void reset();
|
||||
|
||||
static void subscribe(std::function<Subscriber>&& subscriber);
|
||||
|
||||
template <Type E>
|
||||
static void publish(const YGNode& node, const TypedData<E>& eventData = {}) {
|
||||
#ifdef YG_ENABLE_EVENTS
|
||||
publish(node, E, Data{eventData});
|
||||
#endif
|
||||
}
|
||||
|
||||
template <Type E>
|
||||
static void publish(const YGNode* node, const TypedData<E>& eventData = {}) {
|
||||
publish<E>(*node, eventData);
|
||||
}
|
||||
|
||||
private:
|
||||
static void publish(const YGNode&, Type, const Data&);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Event::TypedData<Event::NodeAllocation> {
|
||||
YGConfig* config;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Event::TypedData<Event::NodeDeallocation> {
|
||||
YGConfig* config;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Event::TypedData<Event::LayoutPassStart> {
|
||||
void* layoutContext;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Event::TypedData<Event::LayoutPassEnd> {
|
||||
void* layoutContext;
|
||||
LayoutData* layoutData;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Event::TypedData<Event::MeasureCallbackEnd> {
|
||||
void* layoutContext;
|
||||
float width;
|
||||
YGMeasureMode widthMeasureMode;
|
||||
float height;
|
||||
YGMeasureMode heightMeasureMode;
|
||||
float measuredWidth;
|
||||
float measuredHeight;
|
||||
const LayoutPassReason reason;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Event::TypedData<Event::NodeLayout> {
|
||||
LayoutType layoutType;
|
||||
void* layoutContext;
|
||||
};
|
||||
|
||||
} // namespace yoga
|
||||
} // namespace facebook
|
Reference in New Issue
Block a user