Maintain a FontCollection for each engine instance instead of a process-wide singleton (flutter/engine#5521)
This commit is contained in:
@@ -96,7 +96,6 @@ source_set("ui") {
|
||||
"$flutter_root/fml",
|
||||
"$flutter_root/glue",
|
||||
"$flutter_root/runtime:test_font",
|
||||
"$flutter_root/third_party/txt",
|
||||
"//third_party/dart/runtime/bin:embedded_dart_io",
|
||||
"//third_party/rapidjson",
|
||||
"//third_party/skia",
|
||||
@@ -107,4 +106,6 @@ source_set("ui") {
|
||||
if (is_fuchsia) {
|
||||
deps += [ "//topaz/public/dart-pkg/zircon" ]
|
||||
}
|
||||
|
||||
public_deps = ["$flutter_root/third_party/txt"]
|
||||
}
|
||||
|
||||
@@ -16,13 +16,6 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
FontCollection& FontCollection::ForProcess() {
|
||||
static std::once_flag once = {};
|
||||
static FontCollection* gCollection = nullptr;
|
||||
std::call_once(once, []() { gCollection = new FontCollection(); });
|
||||
return *gCollection;
|
||||
}
|
||||
|
||||
FontCollection::FontCollection()
|
||||
: collection_(std::make_shared<txt::FontCollection>()) {
|
||||
collection_->SetDefaultFontManager(SkFontMgr::RefDefault());
|
||||
|
||||
@@ -17,7 +17,9 @@ namespace blink {
|
||||
|
||||
class FontCollection {
|
||||
public:
|
||||
static FontCollection& ForProcess();
|
||||
FontCollection();
|
||||
|
||||
~FontCollection();
|
||||
|
||||
std::shared_ptr<txt::FontCollection> GetFontCollection() const;
|
||||
|
||||
@@ -28,10 +30,6 @@ class FontCollection {
|
||||
private:
|
||||
std::shared_ptr<txt::FontCollection> collection_;
|
||||
|
||||
FontCollection();
|
||||
|
||||
~FontCollection();
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(FontCollection);
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "flutter/common/task_runners.h"
|
||||
#include "flutter/lib/ui/text/font_collection.h"
|
||||
#include "flutter/lib/ui/ui_dart_state.h"
|
||||
#include "flutter/lib/ui/window/window.h"
|
||||
#include "flutter/third_party/txt/src/txt/font_style.h"
|
||||
#include "flutter/third_party/txt/src/txt/font_weight.h"
|
||||
#include "flutter/third_party/txt/src/txt/paragraph_style.h"
|
||||
@@ -110,8 +111,8 @@ fxl::RefPtr<ParagraphBuilder> ParagraphBuilder::create(
|
||||
double lineHeight,
|
||||
const std::u16string& ellipsis,
|
||||
const std::string& locale) {
|
||||
return fxl::MakeRefCounted<ParagraphBuilder>(
|
||||
encoded, fontFamily, fontSize, lineHeight, ellipsis, locale);
|
||||
return fxl::MakeRefCounted<ParagraphBuilder>(encoded, fontFamily, fontSize,
|
||||
lineHeight, ellipsis, locale);
|
||||
}
|
||||
|
||||
ParagraphBuilder::ParagraphBuilder(tonic::Int32List& encoded,
|
||||
@@ -155,8 +156,10 @@ ParagraphBuilder::ParagraphBuilder(tonic::Int32List& encoded,
|
||||
style.locale = locale;
|
||||
}
|
||||
|
||||
FontCollection& font_collection =
|
||||
UIDartState::Current()->window()->client()->GetFontCollection();
|
||||
m_paragraphBuilder = std::make_unique<txt::ParagraphBuilder>(
|
||||
style, blink::FontCollection::ForProcess().GetFontCollection());
|
||||
style, font_collection.GetFontCollection());
|
||||
} // namespace blink
|
||||
|
||||
ParagraphBuilder::~ParagraphBuilder() = default;
|
||||
@@ -207,8 +210,7 @@ void ParagraphBuilder::pushStyle(tonic::Int32List& encoded,
|
||||
static_cast<txt::FontWeight>(encoded[tsFontWeightIndex]);
|
||||
|
||||
if (mask & tsFontStyleMask)
|
||||
style.font_style =
|
||||
static_cast<txt::FontStyle>(encoded[tsFontStyleIndex]);
|
||||
style.font_style = static_cast<txt::FontStyle>(encoded[tsFontStyleIndex]);
|
||||
|
||||
if (mask & tsFontFamilyMask)
|
||||
style.font_family = fontFamily;
|
||||
|
||||
@@ -20,6 +20,7 @@ class DartLibraryNatives;
|
||||
} // namespace tonic
|
||||
|
||||
namespace blink {
|
||||
class FontCollection;
|
||||
class Scene;
|
||||
|
||||
Dart_Handle ToByteData(const std::vector<uint8_t>& buffer);
|
||||
@@ -31,6 +32,7 @@ class WindowClient {
|
||||
virtual void Render(Scene* scene) = 0;
|
||||
virtual void UpdateSemantics(SemanticsUpdate* update) = 0;
|
||||
virtual void HandlePlatformMessage(fxl::RefPtr<PlatformMessage> message) = 0;
|
||||
virtual FontCollection& GetFontCollection() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~WindowClient();
|
||||
|
||||
@@ -249,6 +249,10 @@ void RuntimeController::HandlePlatformMessage(
|
||||
client_.HandlePlatformMessage(std::move(message));
|
||||
}
|
||||
|
||||
FontCollection& RuntimeController::GetFontCollection() {
|
||||
return client_.GetFontCollection();
|
||||
}
|
||||
|
||||
Dart_Port RuntimeController::GetMainPort() {
|
||||
return root_isolate_ ? root_isolate_->main_port() : ILLEGAL_PORT;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "flutter/common/task_runners.h"
|
||||
#include "flutter/flow/layers/layer_tree.h"
|
||||
#include "flutter/lib/ui/ui_dart_state.h"
|
||||
#include "flutter/lib/ui/text/font_collection.h"
|
||||
#include "flutter/lib/ui/window/pointer_data_packet.h"
|
||||
#include "flutter/lib/ui/window/window.h"
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
@@ -124,6 +125,9 @@ class RuntimeController final : public WindowClient {
|
||||
// |blink::WindowClient|
|
||||
void HandlePlatformMessage(fxl::RefPtr<PlatformMessage> message) override;
|
||||
|
||||
// |blink::WindowClient|
|
||||
FontCollection& GetFontCollection() override;
|
||||
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "flutter/flow/layers/layer_tree.h"
|
||||
#include "flutter/lib/ui/semantics/semantics_node.h"
|
||||
#include "flutter/lib/ui/text/font_collection.h"
|
||||
#include "flutter/lib/ui/window/platform_message.h"
|
||||
#include "third_party/dart/runtime/include/dart_api.h"
|
||||
|
||||
@@ -27,6 +28,8 @@ class RuntimeDelegate {
|
||||
|
||||
virtual void HandlePlatformMessage(fxl::RefPtr<PlatformMessage> message) = 0;
|
||||
|
||||
virtual FontCollection& GetFontCollection() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~RuntimeDelegate();
|
||||
};
|
||||
|
||||
@@ -100,7 +100,6 @@ source_set("common") {
|
||||
"$flutter_root/lib/ui",
|
||||
"$flutter_root/runtime",
|
||||
"$flutter_root/synchronization",
|
||||
"$flutter_root/third_party/txt",
|
||||
"//garnet/public/lib/fxl",
|
||||
"//third_party/dart/runtime:dart_api",
|
||||
"//third_party/rapidjson",
|
||||
@@ -109,6 +108,7 @@ source_set("common") {
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"$flutter_root/third_party/txt",
|
||||
"//topaz/lib/tonic",
|
||||
]
|
||||
|
||||
|
||||
@@ -87,9 +87,9 @@ bool Engine::UpdateAssetManager(
|
||||
|
||||
// Using libTXT as the text engine.
|
||||
if (settings_.use_test_fonts) {
|
||||
blink::FontCollection::ForProcess().RegisterTestFonts();
|
||||
font_collection_.RegisterTestFonts();
|
||||
} else {
|
||||
blink::FontCollection::ForProcess().RegisterFonts(*asset_manager_.get());
|
||||
font_collection_.RegisterFonts(*asset_manager_.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -377,6 +377,10 @@ void Engine::HandlePlatformMessage(
|
||||
}
|
||||
}
|
||||
|
||||
blink::FontCollection& Engine::GetFontCollection() {
|
||||
return font_collection_;
|
||||
}
|
||||
|
||||
void Engine::HandleAssetPlatformMessage(
|
||||
fxl::RefPtr<blink::PlatformMessage> message) {
|
||||
fxl::RefPtr<blink::PlatformMessageResponse> response = message->response();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "flutter/assets/asset_manager.h"
|
||||
#include "flutter/common/task_runners.h"
|
||||
#include "flutter/lib/ui/semantics/semantics_node.h"
|
||||
#include "flutter/lib/ui/text/font_collection.h"
|
||||
#include "flutter/lib/ui/window/platform_message.h"
|
||||
#include "flutter/lib/ui/window/viewport_metrics.h"
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
@@ -109,6 +110,7 @@ class Engine final : public blink::RuntimeDelegate {
|
||||
fml::RefPtr<blink::AssetManager> asset_manager_;
|
||||
bool activity_running_;
|
||||
bool have_surface_;
|
||||
blink::FontCollection font_collection_;
|
||||
fml::WeakPtrFactory<Engine> weak_factory_;
|
||||
|
||||
// |blink::RuntimeDelegate|
|
||||
@@ -124,6 +126,9 @@ class Engine final : public blink::RuntimeDelegate {
|
||||
void HandlePlatformMessage(
|
||||
fxl::RefPtr<blink::PlatformMessage> message) override;
|
||||
|
||||
// |blink::RuntimeDelegate|
|
||||
blink::FontCollection& GetFontCollection() override;
|
||||
|
||||
void StopAnimator();
|
||||
|
||||
void StartAnimatorIfPossible();
|
||||
|
||||
Reference in New Issue
Block a user