Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dom/include/dom/dom_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class DomNode : public std::enable_shared_from_this<DomNode> {
DomNode(uint32_t id, uint32_t pid, int32_t index, std::string tag_name, std::string view_name,
std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<HippyValue>>> style_map,
std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<HippyValue>>> dom_ext_map,
std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type);
std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type, void* layout_config);

DomNode(uint32_t id, uint32_t pid, std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type);
DomNode(uint32_t id, uint32_t pid, std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type, void* layout_config);
DomNode();
virtual ~DomNode();

Expand Down
4 changes: 3 additions & 1 deletion dom/include/dom/layout_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ enum LayoutEngineType {
};

void InitLayoutConsts(LayoutEngineType type);
std::shared_ptr<LayoutNode> CreateLayoutNode(LayoutEngineType type);
std::shared_ptr<LayoutNode> CreateLayoutNode(LayoutEngineType type, void* layout_config);
void* CreateLayoutConfig(LayoutEngineType type);
void DestroyLayoutConfig(LayoutEngineType type, void* config);

} // namespace dom
} // namespace hippy
18 changes: 12 additions & 6 deletions dom/include/dom/root_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ class RootNode : public DomNode {
using EventCallback = std::function<void(const std::shared_ptr<DomEvent>&)>;
using EventCallBackRunner = std::function<void(const std::shared_ptr<DomEvent>&)>;

RootNode(uint32_t id, LayoutEngineType layout_engine_type = LayoutEngineDefault);
RootNode(uint32_t id, LayoutEngineType layout_engine_type = LayoutEngineDefault, void* layout_config = nullptr);
RootNode();
~RootNode();

inline std::weak_ptr<DomManager> GetDomManager() { return dom_manager_; }
inline void SetDomManager(std::weak_ptr<DomManager> dom_manager) {
Expand All @@ -89,7 +90,7 @@ class RootNode : public DomNode {
virtual void AddEventListener(const std::string& name, uint64_t listener_id, bool use_capture,
const EventCallback& cb) override;
virtual void RemoveEventListener(const std::string& name, uint64_t listener_id) override;

std::map<uint32_t, std::vector<ListenerOp>> &EventListenerOps() { return event_listener_ops_; }

void ReleaseResources();
Expand Down Expand Up @@ -122,9 +123,11 @@ class RootNode : public DomNode {
}

std::vector<std::weak_ptr<DomNode>> GetAllTextNodes();

LayoutEngineType GetLayoutEngineType() { return layout_engine_type_; }


void* GetLayoutConfig() { return layout_config_; }

void SetVSyncEventNeedSource(VSyncEventNeedSource source) { vSyncEventNeedSourceBits_ |= source; }
void UnsetVSyncEventNeedSource(VSyncEventNeedSource source) { vSyncEventNeedSourceBits_ &= (~source); }
bool HasVSyncEventNeedSource() { return vSyncEventNeedSourceBits_ != 0; }
Expand Down Expand Up @@ -160,9 +163,12 @@ class RootNode : public DomNode {
std::unique_ptr<DomNodeStyleDiffer> style_differ_;

bool disable_set_root_size_ { false };

LayoutEngineType layout_engine_type_ = LayoutEngineDefault;


// 布局引擎配置结构优先存在RootNode里,避免存在全局static区
void* layout_config_ = nullptr;

int32_t vSyncEventNeedSourceBits_ = 0;

static footstone::utils::PersistentObjectMap<uint32_t, std::shared_ptr<RootNode>> persistent_map_;
Expand Down
6 changes: 3 additions & 3 deletions dom/include/dom/taitank_layout_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace taitank;

class TaitankLayoutNode : public LayoutNode, public std::enable_shared_from_this<TaitankLayoutNode> {
public:
TaitankLayoutNode();
TaitankLayoutNode(TaitankConfig* layout_config);

TaitankLayoutNode(TaitankNodeRef engine_node_);

Expand Down Expand Up @@ -380,7 +380,7 @@ class TaitankLayoutNode : public LayoutNode, public std::enable_shared_from_this
/**
* @brief 分配节点
*/
void Allocate();
void Allocate(TaitankConfig* layout_config);

/**
* @brief 释放节点
Expand All @@ -397,7 +397,7 @@ class TaitankLayoutNode : public LayoutNode, public std::enable_shared_from_this


void InitLayoutConstsTaitank();
std::shared_ptr<LayoutNode> CreateLayoutNodeTaitank();
std::shared_ptr<LayoutNode> CreateLayoutNodeTaitank(TaitankConfig* layout_config);

} // namespace dom
} // namespace hippy
10 changes: 5 additions & 5 deletions dom/src/dom/dom_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ using HippyValueObjectType = footstone::value::HippyValue::HippyValueObjectType;
DomNode::DomNode(uint32_t id, uint32_t pid, int32_t index, std::string tag_name, std::string view_name,
std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<HippyValue>>> style_map,
std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<HippyValue>>> dom_ext_map,
std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type)
std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type, void* layout_config)
: id_(id),
pid_(pid),
index_(index),
Expand All @@ -76,13 +76,13 @@ DomNode::DomNode(uint32_t id, uint32_t pid, int32_t index, std::string tag_name,
current_callback_id_(0),
func_cb_map_(nullptr),
event_listener_map_(nullptr) {
layout_node_ = hippy::dom::CreateLayoutNode(layout_engine_type);
layout_node_ = hippy::dom::CreateLayoutNode(layout_engine_type, layout_config);
}

DomNode::DomNode(uint32_t id, uint32_t pid, std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type)
: DomNode(id, pid, 0, "", "", nullptr, nullptr, std::move(weak_root_node), layout_engine_type) {}
DomNode::DomNode(uint32_t id, uint32_t pid, std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type, void* layout_config)
: DomNode(id, pid, 0, "", "", nullptr, nullptr, std::move(weak_root_node), layout_engine_type, layout_config) {}

DomNode::DomNode() : DomNode(0, 0, {}, LayoutEngineDefault) {}
DomNode::DomNode() : DomNode(0, 0, {}, LayoutEngineDefault, nullptr) {}

DomNode::~DomNode() = default;

Expand Down
37 changes: 34 additions & 3 deletions dom/src/dom/layout_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,47 @@ void InitLayoutConsts(LayoutEngineType type) {
#endif
}

std::shared_ptr<LayoutNode> CreateLayoutNode(LayoutEngineType type) {
std::shared_ptr<LayoutNode> CreateLayoutNode(LayoutEngineType type, void* layout_config) {
#if defined(LAYOUT_ENGINE_YOGA)
return CreateLayoutNodeYoga();
#elif defined(LAYOUT_ENGINE_TAITANK)
return CreateLayoutNodeTaitank();
return CreateLayoutNodeTaitank((TaitankConfig*)layout_config);
#elif defined(LAYOUT_ENGINE_YOGA_AND_TAITANK)
if (type == LayoutEngineYoga) {
return CreateLayoutNodeYoga();
} else {
return CreateLayoutNodeTaitank();
return CreateLayoutNodeTaitank((TaitankConfig*)layout_config);
}
#endif
}

void* CreateLayoutConfig(LayoutEngineType type) {
#if defined(LAYOUT_ENGINE_YOGA)
return nullptr;
#elif defined(LAYOUT_ENGINE_TAITANK)
return new TaitankConfig();
#elif defined(LAYOUT_ENGINE_YOGA_AND_TAITANK)
if (type == LayoutEngineYoga) {
return nullptr;
} else {
return new TaitankConfig();
}
#endif
}

void DestroyLayoutConfig(LayoutEngineType type, void* config) {
if (!config) {
return;
}
#if defined(LAYOUT_ENGINE_YOGA)
#elif defined(LAYOUT_ENGINE_TAITANK)
TaitankConfig *p = (TaitankConfig*)config;
delete p;
#elif defined(LAYOUT_ENGINE_YOGA_AND_TAITANK)
if (type == LayoutEngineYoga) {
} else {
TaitankConfig *p = (TaitankConfig*)config;
delete p;
}
#endif
}
Expand Down
9 changes: 8 additions & 1 deletion dom/src/dom/root_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ bool DomNodeStyleDiffer::Calculate(const std::shared_ptr<hippy::dom::RootNode>&
return true;
}

RootNode::RootNode(uint32_t id, LayoutEngineType layout_engine_type) : DomNode(id, 0, 0, "", "", nullptr, nullptr, {}, layout_engine_type) {
RootNode::RootNode(uint32_t id, LayoutEngineType layout_engine_type, void* layout_config)
: DomNode(id, 0, 0, "", "", nullptr, nullptr, {}
, layout_engine_type, layout_config) {
layout_engine_type_ = layout_engine_type;
layout_config_ = layout_config;
InitLayoutConsts(layout_engine_type);
SetRenderInfo({id, 0, 0});
animation_manager_ = std::make_shared<AnimationManager>();
Expand All @@ -113,6 +116,10 @@ RootNode::RootNode(uint32_t id, LayoutEngineType layout_engine_type) : DomNode(i

RootNode::RootNode() : RootNode(0) {}

RootNode::~RootNode() {
DestroyLayoutConfig(layout_engine_type_, layout_config_);
}

void RootNode::AddEventListener(const std::string& name, uint64_t listener_id, bool use_capture,
const EventCallback& cb) {
DomNode::AddEventListener(name, listener_id, use_capture, cb);
Expand Down
38 changes: 24 additions & 14 deletions dom/src/dom/taitank_layout_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ class TaitankLayoutConsts {
const std::map<std::string, OverflowType> kOverflowMap = {{"visible", OverflowType::OVERFLOW_VISIBLE},
{"hidden", OverflowType::OVERFLOW_HIDDEN},
{"scroll", OverflowType::OVERFLOW_SCROLL}};

const std::map<std::string, FlexDirection> kFlexDirectionMap = {
{"row", FlexDirection::FLEX_DIRECTION_ROW},
{"row-reverse", FlexDirection::FLEX_DIRECTION_ROW_REVERSE},
{"column", FlexDirection::FLEX_DIRECTION_COLUMN},
{"column-reverse", FlexDirection::FLEX_DIRECTION_COLUNM_REVERSE}};

const std::map<std::string, FlexWrapMode> kWrapModeMap = {{"nowrap", FlexWrapMode::FLEX_NO_WRAP},
{"wrap", FlexWrapMode::FLEX_WRAP},
{"wrap-reverse", FlexWrapMode::FLEX_WRAP_REVERSE}};

const std::map<std::string, FlexAlign> kJustifyMap = {{"flex-start", FlexAlign::FLEX_ALIGN_START},
{"center", FlexAlign::FLEX_ALIGN_CENTER},
{"flex-end", FlexAlign::FLEX_ALIGN_END},
{"space-between", FlexAlign::FLEX_ALIGN_SPACE_BETWEEN},
{"space-around", FlexAlign::FLEX_ALIGN_SPACE_AROUND},
{"space-evenly", FlexAlign::FLEX_ALIGN_SPACE_EVENLY}};

const std::map<std::string, FlexAlign> kAlignMap = {{"auto", FlexAlign::FLEX_ALIGN_AUTO},
{"flex-start", FlexAlign::FLEX_ALIGN_START},
{"center", FlexAlign::FLEX_ALIGN_CENTER},
Expand All @@ -61,39 +61,39 @@ class TaitankLayoutConsts {
{"baseline", FlexAlign::FLEX_ALIGN_BASE_LINE},
{"space-between", FlexAlign::FLEX_ALIGN_SPACE_BETWEEN},
{"space-around", FlexAlign::FLEX_ALIGN_SPACE_AROUND}};

const std::map<std::string, CSSDirection> kMarginMap = {{kMargin, CSSDirection::CSS_ALL},
{kMarginVertical, CSSDirection::CSS_VERTICAL},
{kMarginHorizontal, CSSDirection::CSS_HORIZONTAL},
{kMarginLeft, CSSDirection::CSS_LEFT},
{kMarginRight, CSSDirection::CSS_RIGHT},
{kMarginTop, CSSDirection::CSS_TOP},
{kMarginBottom, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, CSSDirection> kPaddingMap = {{kPadding, CSSDirection::CSS_ALL},
{kPaddingVertical, CSSDirection::CSS_VERTICAL},
{kPaddingHorizontal, CSSDirection::CSS_HORIZONTAL},
{kPaddingLeft, CSSDirection::CSS_LEFT},
{kPaddingRight, CSSDirection::CSS_RIGHT},
{kPaddingTop, CSSDirection::CSS_TOP},
{kPaddingBottom, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, CSSDirection> kPositionMap = {{kLeft, CSSDirection::CSS_LEFT},
{kRight, CSSDirection::CSS_RIGHT},
{kTop, CSSDirection::CSS_TOP},
{kBottom, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, CSSDirection> kBorderMap = {{kBorderWidth, CSSDirection::CSS_ALL},
{kBorderLeftWidth, CSSDirection::CSS_LEFT},
{kBorderTopWidth, CSSDirection::CSS_TOP},
{kBorderRightWidth, CSSDirection::CSS_RIGHT},
{kBorderBottomWidth, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, PositionType> kPositionTypeMap = {{"relative", PositionType::POSITION_TYPE_RELATIVE},
{"absolute", PositionType::POSITION_TYPE_ABSOLUTE}};

const std::map<std::string, DisplayType> kDisplayTypeMap = {{"none", DisplayType::DISPLAY_TYPE_NONE}};

const std::map<std::string, TaitankDirection> kDirectionMap = {
{"inherit", DIRECTION_INHERIT}, {"ltr", DIRECTION_LTR}, {"rtl", DIRECTION_RTL}};
};
Expand Down Expand Up @@ -210,7 +210,14 @@ static CSSDirection GetCSSDirectionFromEdge(Edge edge) {
}
}

TaitankLayoutNode::TaitankLayoutNode() { Allocate(); }
void SetGlobalScaleFactor(float scale_factor) {
auto global_config = ConfigGetDefault();
if (global_config) {
global_config->SetScaleFactor(scale_factor);
}
}

TaitankLayoutNode::TaitankLayoutNode(TaitankConfig* layout_config) { Allocate(layout_config); }

TaitankLayoutNode::TaitankLayoutNode(TaitankNodeRef engine_node_) : engine_node_(engine_node_) {}

Expand Down Expand Up @@ -651,6 +658,7 @@ void TaitankLayoutNode::SetScaleFactor(float sacle_factor) {
if (config) {
config->SetScaleFactor(sacle_factor);
}
SetGlobalScaleFactor(sacle_factor);
}

void TaitankLayoutNode::SetMaxWidth(float max_width) {
Expand Down Expand Up @@ -818,7 +826,9 @@ void TaitankLayoutNode::SetOverflow(OverflowType overflow_type) {
engine_node_->MarkAsDirty();
}

void TaitankLayoutNode::Allocate() { engine_node_ = new TaitankNode(); }
void TaitankLayoutNode::Allocate(TaitankConfig* layout_config) {
engine_node_ = layout_config ? new TaitankNode(layout_config) : new TaitankNode();
}

void TaitankLayoutNode::Deallocate() {
if (engine_node_ == nullptr) return;
Expand All @@ -832,7 +842,7 @@ void InitLayoutConstsTaitank() {
}
}

std::shared_ptr<LayoutNode> CreateLayoutNodeTaitank() { return std::make_shared<TaitankLayoutNode>(); }
std::shared_ptr<LayoutNode> CreateLayoutNodeTaitank(TaitankConfig* layout_config) { return std::make_shared<TaitankLayoutNode>(layout_config); }

} // namespace dom
} // namespace hippy
9 changes: 6 additions & 3 deletions driver/js/src/modules/scene_builder_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ CreateNode(const std::shared_ptr<Ctx> &context,
style,
ext,
scope->GetRootNode(),
layout_type);
layout_type,
root_node ? root_node->GetLayoutConfig() : nullptr);
return std::make_tuple(true, "", dom_node);
}

Expand Down Expand Up @@ -506,7 +507,8 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
std::get<2>(id_tuple),
std::get<2>(pid_tuple),
scope->GetRootNode(),
layout_type),
layout_type,
root_node ? root_node->GetLayoutConfig() : nullptr),
std::get<2>(ref_info_tuple),
nullptr));
}
Expand Down Expand Up @@ -556,7 +558,8 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
std::get<2>(id_tuple),
std::get<2>(pid_tuple),
scope->GetRootNode(),
layout_type),
layout_type,
root_node ? root_node->GetLayoutConfig() : nullptr),
nullptr, nullptr));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ void CreateRoot(JNIEnv* j_env,
jint j_root_id,
jfloat j_density) {
auto root_id = footstone::check::checked_numeric_cast<jint, uint32_t>(j_root_id);
auto root_node = std::make_shared<hippy::RootNode>(root_id);
auto layout_config = CreateLayoutConfig(LayoutEngineDefault);
auto root_node = std::make_shared<hippy::RootNode>(root_id, LayoutEngineDefault, layout_config);
auto layout = root_node->GetLayoutNode();
layout->SetScaleFactor(static_cast<float>(j_density));
auto& persistent_map = RootNode::PersistentMap();
Expand Down
Loading