10#include <fuchsia/fonts/cpp/fidl.h>
11#include <lib/zx/vmar.h>
14#include <unordered_map>
38 struct ReleaseSkDataContext {
43 static void ReleaseSkData(
const void*
buffer,
void* context);
44 void OnBufferDeleted(
int bufferId);
47 std::unordered_map<int, SkData*> fBuffers SK_GUARDED_BY(fMutex);
51 const fuchsia::mem::Buffer&
buffer) {
54 auto iter = fBuffers.find(bufferId);
55 if (iter != fBuffers.end()) {
61 uintptr_t mapped_addr = 0;
63 zx::vmar::root_self()->map(ZX_VM_PERM_READ, 0,
buffer.vmo, 0,
size, &mapped_addr);
64 if (status != ZX_OK)
return nullptr;
66 auto context =
new ReleaseSkDataContext{
sk_ref_sp(
this), bufferId};
68 reinterpret_cast<void*
>(mapped_addr),
size, ReleaseSkData, context);
71 fBuffers[bufferId] =
data.get();
75void SkFuchsiaFontDataCache::OnBufferDeleted(
int bufferId) {
76 zx_vaddr_t unmap_addr;
80 auto it = fBuffers.find(bufferId);
82 unmap_addr =
reinterpret_cast<zx_vaddr_t
>(it->second->data());
83 unmap_size = it->second->size();
87 zx::vmar::root_self()->unmap(unmap_addr, unmap_size);
91void SkFuchsiaFontDataCache::ReleaseSkData(
const void*
buffer,
void* context) {
92 auto releaseSkDataContext =
reinterpret_cast<ReleaseSkDataContext*
>(context);
93 releaseSkDataContext->fCache->OnBufferDeleted(releaseSkDataContext->fBufferId);
94 delete releaseSkDataContext;
100 return fuchsia::fonts::Slant::OBLIQUE;
102 return fuchsia::fonts::Slant::ITALIC;
105 return fuchsia::fonts::Slant::UPRIGHT;
111 case fuchsia::fonts::Slant::OBLIQUE:
113 case fuchsia::fonts::Slant::ITALIC:
115 case fuchsia::fonts::Slant::UPRIGHT:
123 case SkFontStyle::Width::kUltraCondensed_Width:
124 return fuchsia::fonts::Width::ULTRA_CONDENSED;
125 case SkFontStyle::Width::kExtraCondensed_Width:
126 return fuchsia::fonts::Width::EXTRA_CONDENSED;
127 case SkFontStyle::Width::kCondensed_Width:
128 return fuchsia::fonts::Width::CONDENSED;
129 case SkFontStyle::Width::kSemiCondensed_Width:
130 return fuchsia::fonts::Width::SEMI_CONDENSED;
131 case SkFontStyle::Width::kNormal_Width:
132 return fuchsia::fonts::Width::NORMAL;
133 case SkFontStyle::Width::kSemiExpanded_Width:
134 return fuchsia::fonts::Width::SEMI_EXPANDED;
135 case SkFontStyle::Width::kExpanded_Width:
136 return fuchsia::fonts::Width::EXPANDED;
137 case SkFontStyle::Width::kExtraExpanded_Width:
138 return fuchsia::fonts::Width::EXTRA_EXPANDED;
139 case SkFontStyle::Width::kUltraExpanded_Width:
140 return fuchsia::fonts::Width::ULTRA_EXPANDED;
148 if (skWidth < SkFontStyle::Width::kUltraCondensed_Width ||
149 skWidth > SkFontStyle::Width::kUltraExpanded_Width) {
159 case fuchsia::fonts::Width::ULTRA_CONDENSED:
160 return SkFontStyle::Width::kUltraCondensed_Width;
161 case fuchsia::fonts::Width::EXTRA_CONDENSED:
162 return SkFontStyle::Width::kExtraCondensed_Width;
163 case fuchsia::fonts::Width::CONDENSED:
164 return SkFontStyle::Width::kCondensed_Width;
165 case fuchsia::fonts::Width::SEMI_CONDENSED:
166 return SkFontStyle::Width::kSemiCondensed_Width;
167 case fuchsia::fonts::Width::NORMAL:
168 return SkFontStyle::Width::kNormal_Width;
169 case fuchsia::fonts::Width::SEMI_EXPANDED:
170 return SkFontStyle::Width::kSemiExpanded_Width;
171 case fuchsia::fonts::Width::EXPANDED:
172 return SkFontStyle::Width::kExpanded_Width;
173 case fuchsia::fonts::Width::EXTRA_EXPANDED:
174 return SkFontStyle::Width::kExtraExpanded_Width;
175 case fuchsia::fonts::Width::ULTRA_EXPANDED:
176 return SkFontStyle::Width::kUltraExpanded_Width;
181 fuchsia::fonts::Style2 fuchsiaStyle;
184 fuchsia::fonts::Width fuchsiaWidth = fuchsia::fonts::Width::NORMAL;
186 fuchsiaStyle.set_width(fuchsiaWidth);
196 {
"sans", fuchsia::fonts::GenericFontFamily::SANS_SERIF},
197 {
"sans-serif", fuchsia::fonts::GenericFontFamily::SANS_SERIF},
198 {
"mono", fuchsia::fonts::GenericFontFamily::MONOSPACE},
199 {
"monospace", fuchsia::fonts::GenericFontFamily::MONOSPACE},
200 {
"cursive", fuchsia::fonts::GenericFontFamily::CURSIVE},
201 {
"fantasy", fuchsia::fonts::GenericFontFamily::FANTASY},
202 {
"system-ui", fuchsia::fonts::GenericFontFamily::SYSTEM_UI},
203 {
"emoji", fuchsia::fonts::GenericFontFamily::EMOJI},
204 {
"math", fuchsia::fonts::GenericFontFamily::MATH},
205 {
"fangsong", fuchsia::fonts::GenericFontFamily::FANGSONG}};
209 fuchsia::fonts::GenericFontFamily* outGenericFamily) {
210 if (!
name)
return false;
212 if (strcasecmp(genericFamily.fName,
name) == 0) {
213 *outGenericFamily = genericFamily.fGenericFontFamily;
256 args.getCollectionIndex(),
269 auto fontData = std::make_unique<SkFontData>(
270 std::move(
stream),
args.getCollectionIndex(),
args.getPalette().index,
271 axisValues.
get(), axisDefinitions.
size(),
272 args.getPalette().overrides,
args.getPalette().overrideCount);
273 return sk_make_sp<SkTypeface_Fuchsia>(std::move(fontData), style, isFixedPitch,
name,
id);
294 const char* bcp47[],
int bcp47Count,
298 int ttcIndex)
const override;
309 bool allow_fallback,
bool exact_style_match)
const;
313 mutable fuchsia::fonts::ProviderSyncPtr fFontProvider;
317 mutable SkMutex fCacheMutex;
324 std::vector<SkFontStyle> styles)
325 : fFontManager(font_manager), fFamilyName(familyName), fStyles(styles) {}
329 int count()
override {
return fStyles.size(); }
332 SkASSERT(index >= 0 && index <
static_cast<int>(fStyles.size()));
333 if (style) *style = fStyles[index];
336 if (styleName) styleName->
reset();
340 SkASSERT(index >= 0 && index <
static_cast<int>(fStyles.size()));
342 if (fTypefaces.empty()) fTypefaces.resize(fStyles.size());
344 if (!fTypefaces[index]) {
345 fTypefaces[index] = fFontManager->FetchTypeface(
346 fFamilyName.c_str(), fStyles[index],
nullptr,
351 return fTypefaces[index];
360 std::string fFamilyName;
361 std::vector<SkFontStyle> fStyles;
362 std::vector<sk_sp<SkTypeface>> fTypefaces;
386 fuchsia::fonts::FamilyName typedFamilyName;
387 typedFamilyName.name = familyName;
389 fuchsia::fonts::FontFamilyInfo familyInfo;
390 int result = fFontProvider->GetFontFamilyInfo(typedFamilyName, &familyInfo);
391 if (
result != ZX_OK || !familyInfo.has_styles() || familyInfo.styles().empty())
return nullptr;
393 std::vector<SkFontStyle> styles;
394 for (
auto& style : familyInfo.styles()) {
405 return FetchTypeface(familyName, style,
nullptr, 0, 0,
411 const char* bcp47[],
int bcp47Count,
414 return FetchTypeface(familyName, style, bcp47, bcp47Count,
character,
423 int ttcIndex)
const {
445 bool exact_style_match)
const {
446 fuchsia::fonts::TypefaceQuery query;
449 if (bcp47Count > 0) {
450 std::vector<fuchsia::intl::LocaleId> languages{};
451 for (
int i = 0;
i < bcp47Count;
i++) {
452 fuchsia::intl::LocaleId localeId;
453 localeId.id = bcp47[
i];
454 languages.push_back(localeId);
456 query.set_languages(std::move(languages));
460 query.set_code_points({
static_cast<uint32_t
>(
character)});
465 fuchsia::fonts::GenericFontFamily genericFontFamily =
466 fuchsia::fonts::GenericFontFamily::SANS_SERIF;
468 if (!familyName || *familyName ==
'\0' || isGenericFontFamily) {
469 if (isGenericFontFamily) {
470 query.set_fallback_family(genericFontFamily);
472 allow_fallback =
true;
474 fuchsia::fonts::FamilyName typedFamilyName{};
475 typedFamilyName.name = familyName;
476 query.set_family(typedFamilyName);
479 fuchsia::fonts::TypefaceRequestFlags
flags{};
480 if (!allow_fallback)
flags |= fuchsia::fonts::TypefaceRequestFlags::EXACT_FAMILY;
481 if (exact_style_match)
flags |= fuchsia::fonts::TypefaceRequestFlags::EXACT_STYLE;
483 fuchsia::fonts::TypefaceRequest request;
484 request.set_query(std::move(query));
485 request.set_flags(
flags);
487 fuchsia::fonts::TypefaceResponse response;
488 int result = fFontProvider->GetTypeface(std::move(request), &response);
489 if (
result != ZX_OK)
return nullptr;
492 if (response.IsEmpty())
return nullptr;
494 return GetOrCreateTypeface(
TypefaceId{response.buffer_id(), response.font_index()},
502 return cachedFuchsiaTypeface->
id() == *
id;
506 const fuchsia::mem::Buffer&
buffer)
const {
510 if (cached)
return cached;
513 if (!
data)
return nullptr;
516 fTypefaceCache.add(
result);
521 return sk_make_sp<SkFontMgr_Fuchsia>(std::move(provider));
static bool FindByTypefaceId(SkTypeface *cachedTypeface, void *ctx)
constexpr struct @420 kGenericFontFamiliesByName[]
struct TypefaceId kNullTypefaceId
sk_sp< SkFontMgr > SkFontMgr_New_Fuchsia(fuchsia::fonts::ProviderSyncPtr provider)
SkFontStyle::Slant FuchsiaToSkSlant(fuchsia::fonts::Slant slant)
sk_sp< SkTypeface > CreateTypefaceFromSkStream(std::unique_ptr< SkStreamAsset > stream, const SkFontArguments &args, TypefaceId id)
fuchsia::fonts::GenericFontFamily fGenericFontFamily
bool GetGenericFontFamilyByName(const char *name, fuchsia::fonts::GenericFontFamily *outGenericFamily)
fuchsia::fonts::Slant SkToFuchsiaSlant(SkFontStyle::Slant slant)
sk_sp< SkTypeface > CreateTypefaceFromSkData(sk_sp< SkData > data, TypefaceId id)
fuchsia::fonts::Style2 SkToFuchsiaStyle(const SkFontStyle &style)
SkFontStyle::Width FuchsiaToSkWidth(fuchsia::fonts::Width width)
fuchsia::fonts::Width SkToFuchsiaWidth(SkFontStyle::Width width)
sk_sp< T > sk_make_sp(Args &&... args)
sk_sp< T > sk_ref_sp(T *obj)
static sk_sp< SkData > MakeWithProc(const void *ptr, size_t length, ReleaseProc proc, void *ctx)
~SkFontMgr_Fuchsia() override
friend class SkFontStyleSet_Fuchsia
sk_sp< SkFontStyleSet > onMatchFamily(const char familyName[]) const override
sk_sp< SkTypeface > onMakeFromStreamArgs(std::unique_ptr< SkStreamAsset >, const SkFontArguments &) const override
void onGetFamilyName(int index, SkString *familyName) const override
SkFontMgr_Fuchsia(fuchsia::fonts::ProviderSyncPtr provider)
sk_sp< SkTypeface > onMatchFamilyStyle(const char familyName[], const SkFontStyle &) const override
int onCountFamilies() const override
sk_sp< SkFontStyleSet > onCreateStyleSet(int index) const override
sk_sp< SkTypeface > onMakeFromStreamIndex(std::unique_ptr< SkStreamAsset >, int ttcIndex) const override
sk_sp< SkTypeface > onMakeFromData(sk_sp< SkData >, int ttcIndex) const override
sk_sp< SkTypeface > onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle &, const char *bcp47[], int bcp47Count, SkUnichar character) const override
sk_sp< SkTypeface > onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override
sk_sp< SkTypeface > onMakeFromFile(const char path[], int ttcIndex) const override
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, int ttcIndex=0) const
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
bool scanFace(SkStreamAsset *stream, int faceIndex, int *numInstances) const override
static void computeAxisValues(AxisDefinitions axisDefinitions, const SkFontArguments::VariationPosition position, SkFixed *axisValues, const SkString &name, SkFontStyle *style, const SkFontArguments::VariationPosition::Coordinate *currentPosition=nullptr)
bool scanInstance(SkStreamAsset *stream, int faceIndex, int instanceIndex, SkString *name, SkFontStyle *style, bool *isFixedPitch, AxisDefinitions *axes) const override
void getStyle(int index, SkFontStyle *style, SkString *styleName) override
SkFontStyleSet_Fuchsia(sk_sp< SkFontMgr_Fuchsia > font_manager, std::string familyName, std::vector< SkFontStyle > styles)
sk_sp< SkTypeface > matchStyle(const SkFontStyle &pattern) override
~SkFontStyleSet_Fuchsia() override=default
sk_sp< SkTypeface > createTypeface(int index) override
sk_sp< SkTypeface > matchStyleCSS3(const SkFontStyle &pattern)
sk_sp< SkData > GetOrCreateSkData(int bufferId, const fuchsia::mem::Buffer &buffer)
~SkFuchsiaFontDataCache()
SkFuchsiaFontDataCache()=default
SkTypeface_Fuchsia(std::unique_ptr< SkFontData > fontData, const SkFontStyle &style, bool isFixedPitch, const SkString familyName, TypefaceId id)
bool isFixedPitch() const
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_SWITCHES_START aot vmservice shared library name
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
bool operator==(TypefaceId &other) const
std::shared_ptr< const fml::Mapping > data