Skip to content

Commit 8320939

Browse files
linxs0211jianliang00
authored andcommitted
[Optimize][Harmony] Enable global font collection by default
- Remove the Harmony runtime setting that toggled global font collection. - Always use the shared Harmony global font collection and global-family font key path. - Drop legacy system-font preload branches that were only needed when the setting was disabled. TEST: tools/env.sh ninja -C out/harmony_debug_profile_arm64 lynx/platform/harmony/lynx_harmony/src/main/cpp:cpp TEST: tools/env.sh ninja -C out/harmony_debug_profile_arm64 lynx/core/renderer/utils:lynx_env
1 parent 82cd294 commit 8320939

8 files changed

Lines changed: 17 additions & 56 deletions

File tree

core/renderer/utils/lynx_env.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,6 @@ bool LynxEnv::FixRadonTransitionPropertyRemoveBug() {
550550
return fix_radon_transition_property_remove_bug;
551551
}
552552

553-
bool LynxEnv::EnableGlobalFontCollection() {
554-
static bool enable_global_font_collection =
555-
GetBoolEnv(Key::ENABLE_GLOBAL_FONT_COLLECTION, true);
556-
return enable_global_font_collection;
557-
}
558-
559553
uint32_t LynxEnv::EnableGCOnceOnIdle() {
560554
static uint32_t cached_enable_gc_once_on_idle =
561555
static_cast<uint32_t>(GetLongEnv(Key::ENABLE_GC_ONCE_ON_IDLE, 0));

core/renderer/utils/lynx_env.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ class LYNX_EXPORT_FOR_DEVTOOL LynxEnv {
122122
FIX_OLD_FIXED_INSERT_SELF_USE_RENDER_PARENT,
123123
FIX_FIBER_REINSERT_DETACH_FROM_OLD_RENDER_PARENT,
124124
FIX_FILTER_DYNAMIC_UPDATE_BUG,
125-
ENABLE_GLOBAL_FONT_COLLECTION,
126125
ENABLE_GC_ONCE_ON_IDLE,
127126
ENABLE_CSS_INLINE_VARIABLES,
128127
ENABLE_OPTIMIZE_HAS_OPACITY,
@@ -293,8 +292,6 @@ class LYNX_EXPORT_FOR_DEVTOOL LynxEnv {
293292
"disable_list_callback_if_detached"},
294293
{Key::FIX_RADON_TRANSITION_PROPERTY_REMOVE_BUG,
295294
"fix_radon_transition_property_remove_bug"},
296-
{Key::ENABLE_GLOBAL_FONT_COLLECTION,
297-
"enable_global_font_collection"},
298295
{Key::ENABLE_GC_ONCE_ON_IDLE, "enable_gc_once_on_idle"},
299296
{Key::ENABLE_CSS_INLINE_VARIABLES, "enable_css_inline_variables"},
300297
{Key::ENABLE_OPTIMIZE_HAS_OPACITY, "enable_optimize_has_opacity"},
@@ -485,7 +482,6 @@ class LYNX_EXPORT_FOR_DEVTOOL LynxEnv {
485482
bool EnableDecoupledList();
486483
bool DisableListCallbackIfDetached();
487484
bool FixRadonTransitionPropertyRemoveBug();
488-
bool EnableGlobalFontCollection();
489485
uint32_t EnableGCOnceOnIdle();
490486
bool EnableCSSInlineVariables();
491487
bool EnableOptimizeHasOpacity();

platform/harmony/lynx_harmony/src/main/cpp/font/font_face_manager.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,8 @@ void FontFace::ParseAndAddSrc(const std::string& src) {
6262
}
6363

6464
std::string url = item.substr(start_pos, end_pos - start_pos + 1);
65-
// if enable global font collection,we need to use font_family+ur.hash to
66-
// make a unique key!
6765
std::string unique_key =
68-
LynxEnv::GetInstance().EnableGlobalFontCollection()
69-
? (font_family_ + std::to_string(std::hash<std::string>{}(url)))
70-
: font_family_;
66+
font_family_ + std::to_string(std::hash<std::string>{}(url));
7167
src_data_.emplace_back(
7268
FontSrcData{type, std::move(url), std::move(unique_key)});
7369
}

platform/harmony/lynx_harmony/src/main/cpp/font/font_face_manager.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ using FontResourceCallback =
7979
using FontPrefetchCallback = base::MoveOnlyClosure<void, int32_t, std::string>;
8080
class FontFaceManager : public std::enable_shared_from_this<FontFaceManager> {
8181
public:
82-
explicit FontFaceManager(ShadowNodeOwner* node_owner,
83-
bool enable_global_font_collection = false)
82+
explicit FontFaceManager(ShadowNodeOwner* node_owner)
8483
: node_owner_(node_owner),
8584
font_collection_(
8685
FontCollectionHarmony::MakeSharedFontCollectionHarmony()) {}

platform/harmony/lynx_harmony/src/main/cpp/lynx_template_renderer.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "core/shell/runtime/bts/lynx_bts_runtime_proxy_impl.h"
3636
#include "core/shell/runtime/common/module_delegate_impl.h"
3737
#include "platform/harmony/lynx_harmony/src/main/cpp/base/base_trace_backend.h"
38-
#include "platform/harmony/lynx_harmony/src/main/cpp/font/system_font_manager.h"
3938
#include "platform/harmony/lynx_harmony/src/main/cpp/lynx_white_board_harmony.h"
4039
#include "platform/harmony/lynx_harmony/src/main/cpp/ui/ui_new_image.h"
4140

@@ -693,13 +692,6 @@ napi_value LynxTemplateRenderer::InitGlobalEnv(napi_env env,
693692
OH_ResourceManager_InitNativeResourceManager(env, args[0]);
694693
});
695694

696-
// try to load system font
697-
if (!tasm::LynxEnv::GetInstance().EnableGlobalFontCollection()) {
698-
tasm::harmony::SystemFontManager::GetInstance().GetSystemFont(
699-
env, [](std::string font_family, std::string font_path) {
700-
LOGI("GetSystemFont when InitGlobalEnv!")
701-
});
702-
}
703695
return nullptr;
704696
}
705697

platform/harmony/lynx_harmony/src/main/cpp/shadow_node/base_text_shadow_node.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,15 @@ void BaseTextShadowNode::OnPropsUpdate(const std::string& name,
117117

118118
void BaseTextShadowNode::SetCustomFontFamiliesToStyle() {
119119
if (!raw_font_families_.empty() && style_.GetCustomFontFamilies().empty()) {
120-
std::vector<std::string> new_custom_families =
121-
context_->GetFontFaceManager()->GetCustomFamiliesFromRawVector(
122-
raw_font_families_);
123-
style_.SetCustomFontFamilyVector(std::move(new_custom_families));
120+
const auto font_manager =
121+
context_ ? context_->GetFontFaceManager() : nullptr;
122+
if (font_manager) {
123+
std::vector<std::string> new_custom_families =
124+
font_manager->GetCustomFamiliesFromRawVector(raw_font_families_);
125+
style_.SetCustomFontFamilyVector(std::move(new_custom_families));
126+
} else {
127+
style_.SetCustomFontFamilyVector(raw_font_families_);
128+
}
124129
}
125130
}
126131

@@ -141,8 +146,6 @@ void BaseTextShadowNode::UpdateInheritedTextStyle(
141146
} else {
142147
style_.SetCustomFontFamilyVector({});
143148
}
144-
} else if (!LynxEnv::GetInstance().EnableGlobalFontCollection()) {
145-
style_.SetCustomFontFamilyVector(effective_raw_font_families);
146149
} else {
147150
const auto font_manager =
148151
context_ ? context_->GetFontFaceManager() : nullptr;
@@ -201,13 +204,7 @@ void BaseTextShadowNode::AppendToParagraph(ParagraphBuilderHarmony& builder,
201204
style_.UpdateTextPaint(width, height, context_->ScaledDensity());
202205

203206
// we need to set font families before PushTextStyle!
204-
if (!LynxEnv::GetInstance().EnableGlobalFontCollection()) {
205-
if (!raw_font_families_.empty()) {
206-
style_.SetCustomFontFamilyVector(raw_font_families_);
207-
}
208-
} else {
209-
SetCustomFontFamiliesToStyle();
210-
}
207+
SetCustomFontFamiliesToStyle();
211208

212209
builder.PushTextStyle(style_);
213210
OnAppendToParagraph(builder, width, height);

platform/harmony/lynx_harmony/src/main/cpp/shadow_node/shadow_node_owner.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ void LayoutVSyncProxy::SetLayoutTriggerCallback(base::closure callback) {
4343

4444
ShadowNodeOwner::ShadowNodeOwner()
4545
: text_measure_cache_(new TextMeasureCache),
46-
font_face_manager_(new FontFaceManager(
47-
this, LynxEnv::GetInstance().EnableGlobalFontCollection())) {}
46+
font_face_manager_(new FontFaceManager(this)) {}
4847

4948
// delete the reference to release the object in js.
5049
ShadowNodeOwner::~ShadowNodeOwner() = default;
@@ -81,11 +80,6 @@ void ShadowNodeOwner::SetContext(const std::shared_ptr<LynxContext>& context) {
8180
context_ = context;
8281

8382
font_face_manager_->SetLayoutTaskRunner(context->GetLayoutTaskRunner());
84-
if (!LynxEnv::GetInstance().EnableGlobalFontCollection()) {
85-
// ty to load system font when Init ShadowNodeOwner
86-
// FIXME(linxs): need to fetch system font when system font updated later
87-
font_face_manager_->TryFetchSystemFont(env_);
88-
}
8983
}
9084

9185
void ShadowNodeOwner::SetLayoutNodeManager(

platform/harmony/lynx_harmony/src/main/cpp/text/font_collection_harmony.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "base/include/log/logging.h"
2020
#include "core/base/harmony/harmony_function_loader.h"
2121
#include "core/base/threading/task_runner_manufactor.h"
22-
#include "core/renderer/utils/lynx_env.h"
2322

2423
namespace lynx {
2524
namespace tasm {
@@ -53,16 +52,10 @@ class FontCollectionHarmony
5352

5453
static std::shared_ptr<FontCollectionHarmony>
5554
MakeSharedFontCollectionHarmony() {
56-
bool enable_global_font_collection =
57-
LynxEnv::GetInstance().EnableGlobalFontCollection();
58-
if (enable_global_font_collection) {
59-
static std::shared_ptr<FontCollectionHarmony>
60-
gGlobalFontCollectionHarmony_ =
61-
std::make_shared<FontCollectionHarmony>(true);
62-
return gGlobalFontCollectionHarmony_;
63-
} else {
64-
return std::make_shared<FontCollectionHarmony>(false);
65-
}
55+
static std::shared_ptr<FontCollectionHarmony>
56+
gGlobalFontCollectionHarmony_ =
57+
std::make_shared<FontCollectionHarmony>(true);
58+
return gGlobalFontCollectionHarmony_;
6659
}
6760

6861
static OH_Drawing_FontCollection* GetGlobalFontCollection() {

0 commit comments

Comments
 (0)