diff --git a/assets/directory_asset_bundle.h b/assets/directory_asset_bundle.h index 75843ea4cd685..7c1466d737218 100644 --- a/assets/directory_asset_bundle.h +++ b/assets/directory_asset_bundle.h @@ -9,10 +9,12 @@ #include #include "lib/fxl/macros.h" +#include "lib/fxl/memory/ref_counted.h" namespace blink { -class DirectoryAssetBundle { +class DirectoryAssetBundle + : public fxl::RefCountedThreadSafe { public: explicit DirectoryAssetBundle(std::string directory); ~DirectoryAssetBundle(); diff --git a/lib/ui/text/font_collection.cc b/lib/ui/text/font_collection.cc index d61e8177dbb73..cc47fe061368a 100644 --- a/lib/ui/text/font_collection.cc +++ b/lib/ui/text/font_collection.cc @@ -34,14 +34,15 @@ std::shared_ptr FontCollection::GetFontCollection() const { return collection_; } -void FontCollection::RegisterFontsFromAssetStore( - fxl::RefPtr asset_store) { - if (!asset_store) { +void FontCollection::RegisterFontsFromDirectoryAssetBundle( + fxl::RefPtr directory_asset_bundle) { + if (!directory_asset_bundle) { return; } std::vector 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; } @@ -91,7 +92,8 @@ void FontCollection::RegisterFontsFromAssetStore( // TODO: Handle weights and styles. std::vector 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 = diff --git a/lib/ui/text/font_collection.h b/lib/ui/text/font_collection.h index 54eada44da981..e99d6ef9227d8 100644 --- a/lib/ui/text/font_collection.h +++ b/lib/ui/text/font_collection.h @@ -7,7 +7,7 @@ #include #include -#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" @@ -21,8 +21,8 @@ class FontCollection { std::shared_ptr GetFontCollection() const; - void RegisterFontsFromAssetStore( - fxl::RefPtr asset_store); + void RegisterFontsFromDirectoryAssetBundle( + fxl::RefPtr directory_asset_bundle); void RegisterTestFonts(); diff --git a/runtime/asset_font_selector.cc b/runtime/asset_font_selector.cc index 46921ca88e55a..eaa86e3ab9308 100644 --- a/runtime/asset_font_selector.cc +++ b/runtime/asset_font_selector.cc @@ -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" @@ -80,15 +80,17 @@ struct FontMatcher { } // namespace -void AssetFontSelector::Install(fxl::RefPtr asset_store) { +void AssetFontSelector::Install( + fxl::RefPtr directory_asset_bundle) { RefPtr 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 asset_store) - : asset_store_(std::move(asset_store)) {} +AssetFontSelector::AssetFontSelector( + fxl::RefPtr directory_asset_bundle) + : directory_asset_bundle_(std::move(directory_asset_bundle)) {} AssetFontSelector::~AssetFontSelector() {} @@ -106,7 +108,8 @@ AssetFontSelector::FlutterFontAttributes::~FlutterFontAttributes() {} void AssetFontSelector::parseFontManifest() { std::vector font_manifest_data; - if (!asset_store_->GetAsBuffer(kFontManifestAssetPath, &font_manifest_data)) + if (!directory_asset_bundle_->GetAsBuffer(kFontManifestAssetPath, + &font_manifest_data)) return; rapidjson::Document document; @@ -222,7 +225,8 @@ sk_sp AssetFontSelector::getTypefaceAsset( } std::unique_ptr 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; } diff --git a/runtime/asset_font_selector.h b/runtime/asset_font_selector.h index a016c0dc64fb7..ad6144071e370 100644 --- a/runtime/asset_font_selector.h +++ b/runtime/asset_font_selector.h @@ -8,7 +8,7 @@ #include #include -#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" @@ -16,14 +16,14 @@ 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 asset_store); + static void Install(fxl::RefPtr directory_asset_bundle); PassRefPtr getFontData(const FontDescription& font_description, const AtomicString& family_name) override; @@ -39,14 +39,15 @@ class AssetFontSelector : public FontSelector { private: struct TypefaceAsset; - explicit AssetFontSelector(fxl::RefPtr asset_store); + explicit AssetFontSelector( + fxl::RefPtr directory_asset_bundle); void parseFontManifest(); sk_sp getTypefaceAsset(const FontDescription& font_description, const AtomicString& family_name); - fxl::RefPtr asset_store_; + fxl::RefPtr directory_asset_bundle_; HashMap> font_family_map_; diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 44b7e22cc2ee7..dcbd225f846a8 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -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) { @@ -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(path); + fxl::MakeRefCounted(path); flx_path = files::GetDirectoryName(path) + "/app.flx"; } else if (S_ISREG(stat_result.st_mode)) { flx_path = path; @@ -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_); } } } diff --git a/shell/common/engine.h b/shell/common/engine.h index 907940d2e027f..099eaa62e8c37 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -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 asset_store_; - std::unique_ptr directory_asset_bundle_; + fxl::RefPtr directory_asset_bundle_; // TODO(eseidel): This should move into an AnimatorStateMachine. bool activity_running_; bool have_surface_;