Skip to content

Commit f4f8631

Browse files
committed
fix(core): android layout config avoid static for some overflowed scene
1 parent 9d23aa5 commit f4f8631

File tree

10 files changed

+99
-39
lines changed

10 files changed

+99
-39
lines changed

dom/include/dom/dom_node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ class DomNode : public std::enable_shared_from_this<DomNode> {
9595
DomNode(uint32_t id, uint32_t pid, int32_t index, std::string tag_name, std::string view_name,
9696
std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<HippyValue>>> style_map,
9797
std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<HippyValue>>> dom_ext_map,
98-
std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type);
98+
std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type, void* layout_config);
9999

100-
DomNode(uint32_t id, uint32_t pid, std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type);
100+
DomNode(uint32_t id, uint32_t pid, std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type, void* layout_config);
101101
DomNode();
102102
virtual ~DomNode();
103103

dom/include/dom/layout_node.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ enum LayoutEngineType {
138138
};
139139

140140
void InitLayoutConsts(LayoutEngineType type);
141-
std::shared_ptr<LayoutNode> CreateLayoutNode(LayoutEngineType type);
141+
std::shared_ptr<LayoutNode> CreateLayoutNode(LayoutEngineType type, void* layout_config);
142+
void* CreateLayoutConfig(LayoutEngineType type);
143+
void DestroyLayoutConfig(LayoutEngineType type, void* config);
142144

143145
} // namespace dom
144146
} // namespace hippy

dom/include/dom/root_node.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ class RootNode : public DomNode {
7676
using EventCallback = std::function<void(const std::shared_ptr<DomEvent>&)>;
7777
using EventCallBackRunner = std::function<void(const std::shared_ptr<DomEvent>&)>;
7878

79-
RootNode(uint32_t id, LayoutEngineType layout_engine_type = LayoutEngineDefault);
79+
RootNode(uint32_t id, LayoutEngineType layout_engine_type = LayoutEngineDefault, void* layout_config = nullptr);
8080
RootNode();
81+
~RootNode();
8182

8283
inline std::weak_ptr<DomManager> GetDomManager() { return dom_manager_; }
8384
inline void SetDomManager(std::weak_ptr<DomManager> dom_manager) {
@@ -89,7 +90,7 @@ class RootNode : public DomNode {
8990
virtual void AddEventListener(const std::string& name, uint64_t listener_id, bool use_capture,
9091
const EventCallback& cb) override;
9192
virtual void RemoveEventListener(const std::string& name, uint64_t listener_id) override;
92-
93+
9394
std::map<uint32_t, std::vector<ListenerOp>> &EventListenerOps() { return event_listener_ops_; }
9495

9596
void ReleaseResources();
@@ -122,9 +123,11 @@ class RootNode : public DomNode {
122123
}
123124

124125
std::vector<std::weak_ptr<DomNode>> GetAllTextNodes();
125-
126+
126127
LayoutEngineType GetLayoutEngineType() { return layout_engine_type_; }
127-
128+
129+
void* GetLayoutConfig() { return layout_config_; }
130+
128131
void SetVSyncEventNeedSource(VSyncEventNeedSource source) { vSyncEventNeedSourceBits_ |= source; }
129132
void UnsetVSyncEventNeedSource(VSyncEventNeedSource source) { vSyncEventNeedSourceBits_ &= (~source); }
130133
bool HasVSyncEventNeedSource() { return vSyncEventNeedSourceBits_ != 0; }
@@ -160,9 +163,12 @@ class RootNode : public DomNode {
160163
std::unique_ptr<DomNodeStyleDiffer> style_differ_;
161164

162165
bool disable_set_root_size_ { false };
163-
166+
164167
LayoutEngineType layout_engine_type_ = LayoutEngineDefault;
165-
168+
169+
// 布局引擎配置结构优先存在RootNode里,避免存在全局static区
170+
void* layout_config_ = nullptr;
171+
166172
int32_t vSyncEventNeedSourceBits_ = 0;
167173

168174
static footstone::utils::PersistentObjectMap<uint32_t, std::shared_ptr<RootNode>> persistent_map_;

dom/include/dom/taitank_layout_node.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ using namespace taitank;
3131

3232
class TaitankLayoutNode : public LayoutNode, public std::enable_shared_from_this<TaitankLayoutNode> {
3333
public:
34-
TaitankLayoutNode();
34+
TaitankLayoutNode(TaitankConfig* layout_config);
3535

3636
TaitankLayoutNode(TaitankNodeRef engine_node_);
3737

@@ -380,7 +380,7 @@ class TaitankLayoutNode : public LayoutNode, public std::enable_shared_from_this
380380
/**
381381
* @brief 分配节点
382382
*/
383-
void Allocate();
383+
void Allocate(TaitankConfig* layout_config);
384384

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

398398

399399
void InitLayoutConstsTaitank();
400-
std::shared_ptr<LayoutNode> CreateLayoutNodeTaitank();
400+
std::shared_ptr<LayoutNode> CreateLayoutNodeTaitank(TaitankConfig* layout_config);
401401

402402
} // namespace dom
403403
} // namespace hippy

dom/src/dom/dom_node.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ using HippyValueObjectType = footstone::value::HippyValue::HippyValueObjectType;
6363
DomNode::DomNode(uint32_t id, uint32_t pid, int32_t index, std::string tag_name, std::string view_name,
6464
std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<HippyValue>>> style_map,
6565
std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<HippyValue>>> dom_ext_map,
66-
std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type)
66+
std::weak_ptr<RootNode> weak_root_node, LayoutEngineType layout_engine_type, void* layout_config)
6767
: id_(id),
6868
pid_(pid),
6969
index_(index),
@@ -76,13 +76,13 @@ DomNode::DomNode(uint32_t id, uint32_t pid, int32_t index, std::string tag_name,
7676
current_callback_id_(0),
7777
func_cb_map_(nullptr),
7878
event_listener_map_(nullptr) {
79-
layout_node_ = hippy::dom::CreateLayoutNode(layout_engine_type);
79+
layout_node_ = hippy::dom::CreateLayoutNode(layout_engine_type, layout_config);
8080
}
8181

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

85-
DomNode::DomNode() : DomNode(0, 0, {}, LayoutEngineDefault) {}
85+
DomNode::DomNode() : DomNode(0, 0, {}, LayoutEngineDefault, nullptr) {}
8686

8787
DomNode::~DomNode() = default;
8888

dom/src/dom/layout_node.cc

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,47 @@ void InitLayoutConsts(LayoutEngineType type) {
4949
#endif
5050
}
5151

52-
std::shared_ptr<LayoutNode> CreateLayoutNode(LayoutEngineType type) {
52+
std::shared_ptr<LayoutNode> CreateLayoutNode(LayoutEngineType type, void* layout_config) {
5353
#if defined(LAYOUT_ENGINE_YOGA)
5454
return CreateLayoutNodeYoga();
5555
#elif defined(LAYOUT_ENGINE_TAITANK)
56-
return CreateLayoutNodeTaitank();
56+
return CreateLayoutNodeTaitank((TaitankConfig*)layout_config);
5757
#elif defined(LAYOUT_ENGINE_YOGA_AND_TAITANK)
5858
if (type == LayoutEngineYoga) {
5959
return CreateLayoutNodeYoga();
6060
} else {
61-
return CreateLayoutNodeTaitank();
61+
return CreateLayoutNodeTaitank((TaitankConfig*)layout_config);
62+
}
63+
#endif
64+
}
65+
66+
void* CreateLayoutConfig(LayoutEngineType type) {
67+
#if defined(LAYOUT_ENGINE_YOGA)
68+
return nullptr;
69+
#elif defined(LAYOUT_ENGINE_TAITANK)
70+
return new TaitankConfig();
71+
#elif defined(LAYOUT_ENGINE_YOGA_AND_TAITANK)
72+
if (type == LayoutEngineYoga) {
73+
return nullptr;
74+
} else {
75+
return new TaitankConfig();
76+
}
77+
#endif
78+
}
79+
80+
void DestroyLayoutConfig(LayoutEngineType type, void* config) {
81+
if (!config) {
82+
return;
83+
}
84+
#if defined(LAYOUT_ENGINE_YOGA)
85+
#elif defined(LAYOUT_ENGINE_TAITANK)
86+
TaitankConfig *p = (TaitankConfig*)config;
87+
delete p;
88+
#elif defined(LAYOUT_ENGINE_YOGA_AND_TAITANK)
89+
if (type == LayoutEngineYoga) {
90+
} else {
91+
TaitankConfig *p = (TaitankConfig*)config;
92+
delete p;
6293
}
6394
#endif
6495
}

dom/src/dom/root_node.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ bool DomNodeStyleDiffer::Calculate(const std::shared_ptr<hippy::dom::RootNode>&
102102
return true;
103103
}
104104

105-
RootNode::RootNode(uint32_t id, LayoutEngineType layout_engine_type) : DomNode(id, 0, 0, "", "", nullptr, nullptr, {}, layout_engine_type) {
105+
RootNode::RootNode(uint32_t id, LayoutEngineType layout_engine_type, void* layout_config)
106+
: DomNode(id, 0, 0, "", "", nullptr, nullptr, {}
107+
, layout_engine_type, layout_config) {
106108
layout_engine_type_ = layout_engine_type;
109+
layout_config_ = layout_config;
107110
InitLayoutConsts(layout_engine_type);
108111
SetRenderInfo({id, 0, 0});
109112
animation_manager_ = std::make_shared<AnimationManager>();
@@ -113,6 +116,10 @@ RootNode::RootNode(uint32_t id, LayoutEngineType layout_engine_type) : DomNode(i
113116

114117
RootNode::RootNode() : RootNode(0) {}
115118

119+
RootNode::~RootNode() {
120+
DestroyLayoutConfig(layout_engine_type_, layout_config_);
121+
}
122+
116123
void RootNode::AddEventListener(const std::string& name, uint64_t listener_id, bool use_capture,
117124
const EventCallback& cb) {
118125
DomNode::AddEventListener(name, listener_id, use_capture, cb);

dom/src/dom/taitank_layout_node.cc

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,24 @@ class TaitankLayoutConsts {
3535
const std::map<std::string, OverflowType> kOverflowMap = {{"visible", OverflowType::OVERFLOW_VISIBLE},
3636
{"hidden", OverflowType::OVERFLOW_HIDDEN},
3737
{"scroll", OverflowType::OVERFLOW_SCROLL}};
38-
38+
3939
const std::map<std::string, FlexDirection> kFlexDirectionMap = {
4040
{"row", FlexDirection::FLEX_DIRECTION_ROW},
4141
{"row-reverse", FlexDirection::FLEX_DIRECTION_ROW_REVERSE},
4242
{"column", FlexDirection::FLEX_DIRECTION_COLUMN},
4343
{"column-reverse", FlexDirection::FLEX_DIRECTION_COLUNM_REVERSE}};
44-
44+
4545
const std::map<std::string, FlexWrapMode> kWrapModeMap = {{"nowrap", FlexWrapMode::FLEX_NO_WRAP},
4646
{"wrap", FlexWrapMode::FLEX_WRAP},
4747
{"wrap-reverse", FlexWrapMode::FLEX_WRAP_REVERSE}};
48-
48+
4949
const std::map<std::string, FlexAlign> kJustifyMap = {{"flex-start", FlexAlign::FLEX_ALIGN_START},
5050
{"center", FlexAlign::FLEX_ALIGN_CENTER},
5151
{"flex-end", FlexAlign::FLEX_ALIGN_END},
5252
{"space-between", FlexAlign::FLEX_ALIGN_SPACE_BETWEEN},
5353
{"space-around", FlexAlign::FLEX_ALIGN_SPACE_AROUND},
5454
{"space-evenly", FlexAlign::FLEX_ALIGN_SPACE_EVENLY}};
55-
55+
5656
const std::map<std::string, FlexAlign> kAlignMap = {{"auto", FlexAlign::FLEX_ALIGN_AUTO},
5757
{"flex-start", FlexAlign::FLEX_ALIGN_START},
5858
{"center", FlexAlign::FLEX_ALIGN_CENTER},
@@ -61,39 +61,39 @@ class TaitankLayoutConsts {
6161
{"baseline", FlexAlign::FLEX_ALIGN_BASE_LINE},
6262
{"space-between", FlexAlign::FLEX_ALIGN_SPACE_BETWEEN},
6363
{"space-around", FlexAlign::FLEX_ALIGN_SPACE_AROUND}};
64-
64+
6565
const std::map<std::string, CSSDirection> kMarginMap = {{kMargin, CSSDirection::CSS_ALL},
6666
{kMarginVertical, CSSDirection::CSS_VERTICAL},
6767
{kMarginHorizontal, CSSDirection::CSS_HORIZONTAL},
6868
{kMarginLeft, CSSDirection::CSS_LEFT},
6969
{kMarginRight, CSSDirection::CSS_RIGHT},
7070
{kMarginTop, CSSDirection::CSS_TOP},
7171
{kMarginBottom, CSSDirection::CSS_BOTTOM}};
72-
72+
7373
const std::map<std::string, CSSDirection> kPaddingMap = {{kPadding, CSSDirection::CSS_ALL},
7474
{kPaddingVertical, CSSDirection::CSS_VERTICAL},
7575
{kPaddingHorizontal, CSSDirection::CSS_HORIZONTAL},
7676
{kPaddingLeft, CSSDirection::CSS_LEFT},
7777
{kPaddingRight, CSSDirection::CSS_RIGHT},
7878
{kPaddingTop, CSSDirection::CSS_TOP},
7979
{kPaddingBottom, CSSDirection::CSS_BOTTOM}};
80-
80+
8181
const std::map<std::string, CSSDirection> kPositionMap = {{kLeft, CSSDirection::CSS_LEFT},
8282
{kRight, CSSDirection::CSS_RIGHT},
8383
{kTop, CSSDirection::CSS_TOP},
8484
{kBottom, CSSDirection::CSS_BOTTOM}};
85-
85+
8686
const std::map<std::string, CSSDirection> kBorderMap = {{kBorderWidth, CSSDirection::CSS_ALL},
8787
{kBorderLeftWidth, CSSDirection::CSS_LEFT},
8888
{kBorderTopWidth, CSSDirection::CSS_TOP},
8989
{kBorderRightWidth, CSSDirection::CSS_RIGHT},
9090
{kBorderBottomWidth, CSSDirection::CSS_BOTTOM}};
91-
91+
9292
const std::map<std::string, PositionType> kPositionTypeMap = {{"relative", PositionType::POSITION_TYPE_RELATIVE},
9393
{"absolute", PositionType::POSITION_TYPE_ABSOLUTE}};
94-
94+
9595
const std::map<std::string, DisplayType> kDisplayTypeMap = {{"none", DisplayType::DISPLAY_TYPE_NONE}};
96-
96+
9797
const std::map<std::string, TaitankDirection> kDirectionMap = {
9898
{"inherit", DIRECTION_INHERIT}, {"ltr", DIRECTION_LTR}, {"rtl", DIRECTION_RTL}};
9999
};
@@ -210,7 +210,14 @@ static CSSDirection GetCSSDirectionFromEdge(Edge edge) {
210210
}
211211
}
212212

213-
TaitankLayoutNode::TaitankLayoutNode() { Allocate(); }
213+
void SetGlobalScaleFactor(float scale_factor) {
214+
auto global_config = ConfigGetDefault();
215+
if (global_config) {
216+
global_config->SetScaleFactor(scale_factor);
217+
}
218+
}
219+
220+
TaitankLayoutNode::TaitankLayoutNode(TaitankConfig* layout_config) { Allocate(layout_config); }
214221

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

@@ -651,6 +658,7 @@ void TaitankLayoutNode::SetScaleFactor(float sacle_factor) {
651658
if (config) {
652659
config->SetScaleFactor(sacle_factor);
653660
}
661+
SetGlobalScaleFactor(sacle_factor);
654662
}
655663

656664
void TaitankLayoutNode::SetMaxWidth(float max_width) {
@@ -818,7 +826,9 @@ void TaitankLayoutNode::SetOverflow(OverflowType overflow_type) {
818826
engine_node_->MarkAsDirty();
819827
}
820828

821-
void TaitankLayoutNode::Allocate() { engine_node_ = new TaitankNode(); }
829+
void TaitankLayoutNode::Allocate(TaitankConfig* layout_config) {
830+
engine_node_ = layout_config ? new TaitankNode(layout_config) : new TaitankNode();
831+
}
822832

823833
void TaitankLayoutNode::Deallocate() {
824834
if (engine_node_ == nullptr) return;
@@ -832,7 +842,7 @@ void InitLayoutConstsTaitank() {
832842
}
833843
}
834844

835-
std::shared_ptr<LayoutNode> CreateLayoutNodeTaitank() { return std::make_shared<TaitankLayoutNode>(); }
845+
std::shared_ptr<LayoutNode> CreateLayoutNodeTaitank(TaitankConfig* layout_config) { return std::make_shared<TaitankLayoutNode>(layout_config); }
836846

837847
} // namespace dom
838848
} // namespace hippy

driver/js/src/modules/scene_builder_module.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ CreateNode(const std::shared_ptr<Ctx> &context,
297297
style,
298298
ext,
299299
scope->GetRootNode(),
300-
layout_type);
300+
layout_type,
301+
root_node ? root_node->GetLayoutConfig() : nullptr);
301302
return std::make_tuple(true, "", dom_node);
302303
}
303304

@@ -506,7 +507,8 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
506507
std::get<2>(id_tuple),
507508
std::get<2>(pid_tuple),
508509
scope->GetRootNode(),
509-
layout_type),
510+
layout_type,
511+
root_node ? root_node->GetLayoutConfig() : nullptr),
510512
std::get<2>(ref_info_tuple),
511513
nullptr));
512514
}
@@ -556,7 +558,8 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
556558
std::get<2>(id_tuple),
557559
std::get<2>(pid_tuple),
558560
scope->GetRootNode(),
559-
layout_type),
561+
layout_type,
562+
root_node ? root_node->GetLayoutConfig() : nullptr),
560563
nullptr, nullptr));
561564
}
562565
}

framework/android/connector/dom/src/main/cpp/src/dom_jni.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ void CreateRoot(JNIEnv* j_env,
8686
jint j_root_id,
8787
jfloat j_density) {
8888
auto root_id = footstone::check::checked_numeric_cast<jint, uint32_t>(j_root_id);
89-
auto root_node = std::make_shared<hippy::RootNode>(root_id);
89+
auto layout_config = CreateLayoutConfig(LayoutEngineDefault);
90+
auto root_node = std::make_shared<hippy::RootNode>(root_id, LayoutEngineDefault, layout_config);
9091
auto layout = root_node->GetLayoutNode();
9192
layout->SetScaleFactor(static_cast<float>(j_density));
9293
auto& persistent_map = RootNode::PersistentMap();

0 commit comments

Comments
 (0)