Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/directory_asset_bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include <vector>

#include "lib/fxl/macros.h"
#include "lib/fxl/memory/ref_counted.h"

namespace blink {

class DirectoryAssetBundle {
class DirectoryAssetBundle
: public fxl::RefCountedThreadSafe<DirectoryAssetBundle> {
public:
explicit DirectoryAssetBundle(std::string directory);
~DirectoryAssetBundle();
Expand Down
12 changes: 7 additions & 5 deletions lib/ui/text/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ std::shared_ptr<txt::FontCollection> FontCollection::GetFontCollection() const {
return collection_;
}

void FontCollection::RegisterFontsFromAssetStore(
fxl::RefPtr<blink::ZipAssetStore> asset_store) {
if (!asset_store) {
void FontCollection::RegisterFontsFromDirectoryAssetBundle(
fxl::RefPtr<blink::DirectoryAssetBundle> directory_asset_bundle) {
if (!directory_asset_bundle) {
return;
}

std::vector<uint8_t> manifest_data;
if (!asset_store->GetAsBuffer("FontManifest.json", &manifest_data)) {
if (!directory_asset_bundle->GetAsBuffer("FontManifest.json",
&manifest_data)) {
FXL_DLOG(WARNING) << "Could not find the font manifest in the asset store.";
return;
}
Expand Down Expand Up @@ -91,7 +92,8 @@ void FontCollection::RegisterFontsFromAssetStore(

// TODO: Handle weights and styles.
std::vector<uint8_t> font_data;
if (asset_store->GetAsBuffer(font_asset->value.GetString(), &font_data)) {
if (directory_asset_bundle->GetAsBuffer(font_asset->value.GetString(),
&font_data)) {
// The data must be copied because it needs to be moved into the
// typeface as a stream.
auto data =
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/text/font_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <memory>
#include <vector>
#include "flutter/assets/zip_asset_store.h"
#include "flutter/assets/directory_asset_bundle.h"
#include "lib/fxl/macros.h"
#include "lib/fxl/memory/ref_ptr.h"
#include "txt/asset_data_provider.h"
Expand All @@ -21,8 +21,8 @@ class FontCollection {

std::shared_ptr<txt::FontCollection> GetFontCollection() const;

void RegisterFontsFromAssetStore(
fxl::RefPtr<blink::ZipAssetStore> asset_store);
void RegisterFontsFromDirectoryAssetBundle(
fxl::RefPtr<blink::DirectoryAssetBundle> directory_asset_bundle);

void RegisterTestFonts();

Expand Down
18 changes: 11 additions & 7 deletions runtime/asset_font_selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "flutter/runtime/asset_font_selector.h"

#include "flutter/assets/zip_asset_store.h"
#include "flutter/assets/directory_asset_bundle.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/sky/engine/platform/fonts/FontData.h"
#include "flutter/sky/engine/platform/fonts/FontFaceCreationParams.h"
Expand Down Expand Up @@ -80,15 +80,17 @@ struct FontMatcher {

} // namespace

void AssetFontSelector::Install(fxl::RefPtr<ZipAssetStore> asset_store) {
void AssetFontSelector::Install(
fxl::RefPtr<DirectoryAssetBundle> directory_asset_bundle) {
RefPtr<AssetFontSelector> font_selector =
adoptRef(new AssetFontSelector(std::move(asset_store)));
adoptRef(new AssetFontSelector(std::move(directory_asset_bundle)));
font_selector->parseFontManifest();
UIDartState::Current()->set_font_selector(font_selector);
}

AssetFontSelector::AssetFontSelector(fxl::RefPtr<ZipAssetStore> asset_store)
: asset_store_(std::move(asset_store)) {}
AssetFontSelector::AssetFontSelector(
fxl::RefPtr<DirectoryAssetBundle> directory_asset_bundle)
: directory_asset_bundle_(std::move(directory_asset_bundle)) {}

AssetFontSelector::~AssetFontSelector() {}

Expand All @@ -106,7 +108,8 @@ AssetFontSelector::FlutterFontAttributes::~FlutterFontAttributes() {}

void AssetFontSelector::parseFontManifest() {
std::vector<uint8_t> font_manifest_data;
if (!asset_store_->GetAsBuffer(kFontManifestAssetPath, &font_manifest_data))
if (!directory_asset_bundle_->GetAsBuffer(kFontManifestAssetPath,
&font_manifest_data))
return;

rapidjson::Document document;
Expand Down Expand Up @@ -222,7 +225,8 @@ sk_sp<SkTypeface> AssetFontSelector::getTypefaceAsset(
}

std::unique_ptr<TypefaceAsset> typeface_asset(new TypefaceAsset);
if (!asset_store_->GetAsBuffer(asset_path, &typeface_asset->data)) {
if (!directory_asset_bundle_->GetAsBuffer(asset_path,
&typeface_asset->data)) {
typeface_cache_.insert(std::make_pair(asset_path, nullptr));
return nullptr;
}
Expand Down
11 changes: 6 additions & 5 deletions runtime/asset_font_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
#include <unordered_map>
#include <vector>

#include "flutter/assets/zip_asset_store.h"
#include "flutter/assets/directory_asset_bundle.h"
#include "flutter/sky/engine/platform/fonts/FontCacheKey.h"
#include "flutter/sky/engine/platform/fonts/FontSelector.h"
#include "flutter/sky/engine/platform/fonts/SimpleFontData.h"

namespace blink {

// A FontSelector implementation that resolves custon font names to assets
// loaded from the FLX.
// loaded from the asset directory.
class AssetFontSelector : public FontSelector {
public:
struct FlutterFontAttributes;

~AssetFontSelector() override;

static void Install(fxl::RefPtr<ZipAssetStore> asset_store);
static void Install(fxl::RefPtr<DirectoryAssetBundle> directory_asset_bundle);

PassRefPtr<FontData> getFontData(const FontDescription& font_description,
const AtomicString& family_name) override;
Expand All @@ -39,14 +39,15 @@ class AssetFontSelector : public FontSelector {
private:
struct TypefaceAsset;

explicit AssetFontSelector(fxl::RefPtr<ZipAssetStore> asset_store);
explicit AssetFontSelector(
fxl::RefPtr<DirectoryAssetBundle> directory_asset_bundle);

void parseFontManifest();

sk_sp<SkTypeface> getTypefaceAsset(const FontDescription& font_description,
const AtomicString& family_name);

fxl::RefPtr<ZipAssetStore> asset_store_;
fxl::RefPtr<DirectoryAssetBundle> directory_asset_bundle_;

HashMap<AtomicString, std::vector<FlutterFontAttributes>> font_family_map_;

Expand Down
13 changes: 6 additions & 7 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,7 @@ void Engine::SetSemanticsEnabled(bool enabled) {
void Engine::ConfigureAssetBundle(const std::string& path) {
struct stat stat_result = {};

directory_asset_bundle_.reset();
// TODO(abarth): We should reset asset_store_ as well, but that might break
// TODO(abarth): We should reset directory_asset_bundle_, but that might break
// custom font loading in hot reload.

if (::stat(path.c_str(), &stat_result) != 0) {
Expand All @@ -590,7 +589,7 @@ void Engine::ConfigureAssetBundle(const std::string& path) {
std::string flx_path;
if (S_ISDIR(stat_result.st_mode)) {
directory_asset_bundle_ =
std::make_unique<blink::DirectoryAssetBundle>(path);
fxl::MakeRefCounted<blink::DirectoryAssetBundle>(path);
flx_path = files::GetDirectoryName(path) + "/app.flx";
} else if (S_ISREG(stat_result.st_mode)) {
flx_path = path;
Expand Down Expand Up @@ -622,11 +621,11 @@ void Engine::DidCreateMainIsolate(Dart_Isolate isolate) {
blink::TestFontSelector::Install();
if (!blink::Settings::Get().using_blink)
blink::FontCollection::ForProcess().RegisterTestFonts();
} else if (asset_store_) {
blink::AssetFontSelector::Install(asset_store_);
} else if (directory_asset_bundle_) {
blink::AssetFontSelector::Install(directory_asset_bundle_);
if (!blink::Settings::Get().using_blink) {
blink::FontCollection::ForProcess().RegisterFontsFromAssetStore(
asset_store_);
blink::FontCollection::ForProcess().RegisterFontsFromDirectoryAssetBundle(
directory_asset_bundle_);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Engine : public blink::RuntimeDelegate {
bool semantics_enabled_ = false;
// TODO(zarah): Remove usage of asset_store_ once app.flx is removed.
fxl::RefPtr<blink::ZipAssetStore> asset_store_;
std::unique_ptr<blink::DirectoryAssetBundle> directory_asset_bundle_;
fxl::RefPtr<blink::DirectoryAssetBundle> directory_asset_bundle_;
// TODO(eseidel): This should move into an AnimatorStateMachine.
bool activity_running_;
bool have_surface_;
Expand Down