未验证 提交 a9a53d40 编写于 作者: C Chinmay Garde 提交者: GitHub

Use the non-thread-hostile FontProviderSyncPtr for font resolution. (#5105)

上级 e11905c6
......@@ -108,13 +108,18 @@ void ApplicationRunner::SetupICU() {
}
void ApplicationRunner::SetupGlobalFonts() {
fonts::FontProviderPtr font_provider(
host_context_->ConnectToEnvironmentService<fonts::FontProvider>());
auto font_manager =
sk_make_sp<txt::FuchsiaFontManager>(std::move(font_provider));
blink::FontCollection::ForProcess()
.GetFontCollection()
->SetDefaultFontManager(std::move(font_manager));
// Fuchsia does not have per application (shell) fonts. Instead, all fonts
// must be obtained from the font provider.
auto process_font_collection =
blink::FontCollection::ForProcess().GetFontCollection();
// Connect to the system font provider.
fonts::FontProviderSyncPtr sync_font_provider;
host_context_->ConnectToEnvironmentService(sync_font_provider.NewRequest());
// Set the default font manager.
process_font_collection->SetDefaultFontManager(
sk_make_sp<txt::FuchsiaFontManager>(std::move(sync_font_provider)));
}
void ApplicationRunner::FireTerminationCallbackIfNecessary() {
......
......@@ -54,7 +54,7 @@ fonts::FontSlant ToFontSlant(SkFontStyle::Slant slant) {
} // anonymous namespace
FuchsiaFontManager::FuchsiaFontManager(fonts::FontProviderPtr provider)
FuchsiaFontManager::FuchsiaFontManager(fonts::FontProviderSyncPtr provider)
: font_provider_(std::move(provider)) {}
FuchsiaFontManager::~FuchsiaFontManager() = default;
......@@ -97,12 +97,7 @@ SkTypeface* FuchsiaFontManager::onMatchFamilyStyle(
request.slant = ToFontSlant(style.slant());
fonts::FontResponsePtr response;
font_provider_->GetFont(
std::move(request),
[&response](fonts::FontResponsePtr r) { response = std::move(r); });
font_provider_.WaitForResponse();
if (!response) {
if (!font_provider_->GetFont(std::move(request), &response)) {
FXL_DLOG(ERROR) << "Unable to contact the font provider. Did you run "
"Flutter in an environment that has a font manager?";
return nullptr;
......
......@@ -17,8 +17,8 @@
#ifndef TXT_FUCHSIA_FONT_MANAGER_H_
#define TXT_FUCHSIA_FONT_MANAGER_H_
#include <memory>
#include <fuchsia/cpp/fonts.h>
#include <memory>
#include "lib/fxl/macros.h"
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/core/SkTypeface.h"
......@@ -28,7 +28,7 @@ namespace txt {
class FuchsiaFontManager final : public SkFontMgr {
public:
FuchsiaFontManager(fonts::FontProviderPtr provider);
FuchsiaFontManager(fonts::FontProviderSyncPtr provider);
~FuchsiaFontManager() override;
......@@ -81,7 +81,7 @@ class FuchsiaFontManager final : public SkFontMgr {
FXL_DISALLOW_COPY_AND_ASSIGN(FuchsiaFontManager);
private:
mutable fonts::FontProviderPtr font_provider_;
mutable fonts::FontProviderSyncPtr font_provider_;
};
} // namespace txt
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册