[native assets] Consume NativeAssetsManifest.json (flutter/engine#56727)

This PR introduces a `NativeAssetsManifest.json` next to the `AssetManifest.json` and `FontManifest.json`. This removes the need for embedding the native assets mapping inside the kernel file and will enable decoupling native assets building and bundling from the kernel compilation in flutter tools. This will then allow us to remove dry-run from the build hook protocol.

(It also means all isolate groups will have the same native assets. However, since Flutter does not support `Isolate.spawnUri` from kernel files anyways, this is not a regression.)

This manifest is parsed eagerly on startup by the engine in a manner similar to how the font manifest is parsed. The manifest contents need to be available in the callback for resolving assets, which does not have access to the engine. Therefore the parsed manifest is `NativeAssetsManager` stored in the `IsolateGroupData`. The engine passes it in on isolate group creation, and the FFI callbacks access it from the isolate group data.

Issue:

* https://github.com/flutter/flutter/issues/154425

Related PRs:

* https://dart-review.googlesource.com/c/sdk/+/388161

Follow up work:

* This PR does not yet remove the engine callbacks registered via the dart_api that rely on kernel embedding. If we were to do that in this PR, it would require a manual roll of the engine into flutter/flutter with the PR that switches flutter_tools to emit the native assets manifest instead of embedding in kernel, and a manual roll into g3 to switch emitting a manifest instead of embedding in kernel. A TODO is left in the code for those callbacks to be removed.

## Testing

Most of this PR cannot be tested in isolation. The code in this PR is heavily exercised in the follow up flutter_tools PR which creates the `NativeAssetsManifest.json` and removes the embedding of native assets in kernel files.

* This PR adds a unit test for parsing the JSON manifest.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
Daco Harkes
2024-11-21 19:01:46 +01:00
committed by GitHub
parent 47ba585ccf
commit 09e3b52bdf
21 changed files with 439 additions and 50 deletions

View File

@@ -183,6 +183,7 @@ group("unittests") {
# Compile all unittests targets if enabled.
if (enable_unittests) {
public_deps += [
"//flutter/assets:assets_unittests",
"//flutter/display_list:display_list_rendertests",
"//flutter/display_list:display_list_unittests",
"//flutter/flow:flow_unittests",

View File

@@ -243,6 +243,7 @@ $ ./run_tests.py --variant=host_debug_unopt_arm64 --type=engine
| Name | run_tests.py type | Description |
| ---------------------------------------- | ------------------- | --------------------------------------------------------------- |
| accessibility_unittests | engine | |
| assets_unittests | engine | |
| client_wrapper_glfw_unittests | engine | |
| client_wrapper_unittests | engine | |
| common_cpp_core_unittests | engine | |

View File

@@ -2,6 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//flutter/common/config.gni")
import("//flutter/testing/testing.gni")
if (is_fuchsia) {
import("//flutter/tools/fuchsia/gn-sdk/src/gn_configs.gni")
}
source_set("assets") {
sources = [
"asset_manager.cc",
@@ -9,12 +16,43 @@ source_set("assets") {
"asset_resolver.h",
"directory_asset_bundle.cc",
"directory_asset_bundle.h",
"native_assets.cc",
"native_assets.h",
]
deps = [
"//flutter/common",
"//flutter/fml",
"//flutter/third_party/rapidjson",
]
public_configs = [ "//flutter:config" ]
}
test_fixtures("assets_fixtures") {
fixtures = []
}
if (enable_unittests) {
executable("assets_unittests") {
testonly = true
sources = [ "native_assets_unittests.cc" ]
deps = [
":assets",
":assets_fixtures",
"//flutter/testing",
]
if (!defined(defines)) {
defines = []
}
# This is needed for //flutter/third_party/googletest for linking zircon
# symbols.
if (is_fuchsia) {
libs = [ "${fuchsia_arch_root}/sysroot/lib/libzircon.so" ]
}
}
}

View File

@@ -0,0 +1,136 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "assets/native_assets.h"
#include "flutter/fml/build_config.h"
#include "rapidjson/document.h"
namespace flutter {
#if defined(FML_ARCH_CPU_ARMEL)
#define kTargetArchitectureName "arm"
#elif defined(FML_ARCH_CPU_ARM64)
#define kTargetArchitectureName "arm64"
#elif defined(FML_ARCH_CPU_X86)
#define kTargetArchitectureName "ia32"
#elif defined(FML_ARCH_CPU_X86_64)
#define kTargetArchitectureName "x64"
#else
#error Target architecture detection failed.
#endif
#if defined(FML_OS_ANDROID)
#define kTargetOperatingSystemName "android"
#elif defined(OS_FUCHSIA)
#define kTargetOperatingSystemName "fuchsia"
#elif defined(FML_OS_LINUX)
#define kTargetOperatingSystemName "linux"
#elif defined(FML_OS_IOS) || defined(FML_OS_IOS_SIMULATOR)
#define kTargetOperatingSystemName "ios"
#elif defined(FML_OS_MACOSX)
#define kTargetOperatingSystemName "macos"
#elif defined(FML_OS_WIN)
#define kTargetOperatingSystemName "windows"
#else
#error Target operating system detection failed.
#endif
#define kTarget kTargetOperatingSystemName "_" kTargetArchitectureName
void NativeAssetsManager::RegisterNativeAssets(const uint8_t* manifest,
size_t manifest_size) {
parsed_mapping_.clear();
rapidjson::Document document;
static_assert(sizeof(decltype(document)::Ch) == sizeof(uint8_t), "");
document.Parse(reinterpret_cast<const decltype(document)::Ch*>(manifest),
manifest_size);
if (document.HasParseError()) {
FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed.";
return;
}
if (!document.IsObject()) {
FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed.";
return;
}
auto native_assets = document.FindMember("native-assets");
if (native_assets == document.MemberEnd() ||
!native_assets->value.IsObject()) {
FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed.";
return;
}
auto mapping = native_assets->value.FindMember(kTarget);
if (mapping == native_assets->value.MemberEnd() ||
!mapping->value.IsObject()) {
FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed.";
return;
}
for (auto entry = mapping->value.MemberBegin();
entry != mapping->value.MemberEnd(); entry++) {
std::vector<std::string> parsed_path;
entry->name.GetString();
auto& value = entry->value;
if (!value.IsArray()) {
FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed.";
continue;
}
for (const auto& element : value.GetArray()) {
if (!element.IsString()) {
FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed.";
continue;
}
parsed_path.push_back(element.GetString());
}
parsed_mapping_[entry->name.GetString()] = std::move(parsed_path);
}
}
void NativeAssetsManager::RegisterNativeAssets(
const std::shared_ptr<AssetManager>& asset_manager) {
std::unique_ptr<fml::Mapping> manifest_mapping =
asset_manager->GetAsMapping("NativeAssetsManifest.json");
if (manifest_mapping == nullptr) {
FML_DLOG(WARNING)
<< "Could not find NativeAssetsManifest.json in the asset store.";
return;
}
RegisterNativeAssets(manifest_mapping->GetMapping(),
manifest_mapping->GetSize());
}
std::vector<std::string> NativeAssetsManager::LookupNativeAsset(
std::string_view asset_id) {
// Cpp17 does not support unordered_map lookup with std::string_view on a
// std::string key.
std::string as_string = std::string(asset_id);
if (parsed_mapping_.find(as_string) == parsed_mapping_.end()) {
return std::vector<std::string>();
}
return parsed_mapping_[as_string];
}
std::string NativeAssetsManager::AvailableNativeAssets() {
if (parsed_mapping_.empty()) {
return std::string("No available native assets.");
}
std::string result;
result.append("Available native assets: ");
bool first = true;
for (const auto& n : parsed_mapping_) {
if (first) {
first = false;
} else {
result.append(", ");
}
result.append(n.first);
}
result.append(".");
return result;
}
} // namespace flutter

View File

@@ -0,0 +1,54 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_ASSETS_NATIVE_ASSETS_H_
#define FLUTTER_ASSETS_NATIVE_ASSETS_H_
#include <memory>
#include <vector>
#include "flutter/assets/asset_manager.h"
namespace flutter {
// Parses the `NativeAssetsManifest.json` and provides a way to look up assets
// and the available assets for the callbacks that are registered to the Dart VM
// via the dart_api.h.
//
// The engine eagerly populates a native assets manager on startup. This native
// assets manager is stored in the `IsolateGroupData` so it can be accessed on
// the native assets callbacks registered in `InitDartFFIForIsolateGroup`.
class NativeAssetsManager {
public:
NativeAssetsManager() = default;
~NativeAssetsManager() = default;
// Reads the `NativeAssetsManifest.json` bundled in the Flutter application.
void RegisterNativeAssets(const uint8_t* manifest, size_t manifest_size);
void RegisterNativeAssets(const std::shared_ptr<AssetManager>& asset_manager);
// Looks up the asset path for [asset_id].
//
// The asset path consists of a type, and an optional path. For example:
// `["system", "libsqlite3.so"]`.
std::vector<std::string> LookupNativeAsset(std::string_view asset_id);
// Lists the available asset ids.
//
// Used when a user tries to look up an asset with an ID that does not exist
// to report the list of available asset ids.
std::string AvailableNativeAssets();
private:
std::unordered_map<std::string, std::vector<std::string>> parsed_mapping_;
NativeAssetsManager(const NativeAssetsManager&) = delete;
NativeAssetsManager(NativeAssetsManager&&) = delete;
NativeAssetsManager& operator=(const NativeAssetsManager&) = delete;
NativeAssetsManager& operator=(NativeAssetsManager&&) = delete;
};
} // namespace flutter
#endif // FLUTTER_ASSETS_NATIVE_ASSETS_H_

View File

@@ -0,0 +1,90 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/assets/native_assets.h"
#include "gtest/gtest.h"
namespace flutter {
namespace testing {
// Manifest containing all hosts on which this test is run.
// In practise, a manifest will only contain a single OS.
// A manifest might contain multiple architectures if the OS supports
// multi-arch apps.
const char* kTestManifest = R"({
"format-version": [
1,
0,
0
],
"native-assets": {
"linux_arm64": {
"package:my_package/my_package_bindings_generated.dart": [
"absolute",
"libmy_package.so"
]
},
"linux_x64": {
"package:my_package/my_package_bindings_generated.dart": [
"absolute",
"libmy_package.so"
]
},
"macos_arm64": {
"package:my_package/my_package_bindings_generated.dart": [
"absolute",
"my_package.framework/my_package"
]
},
"macos_x64": {
"package:my_package/my_package_bindings_generated.dart": [
"absolute",
"my_package.framework/my_package"
]
},
"windows_x64": {
"package:my_package/my_package_bindings_generated.dart": [
"absolute",
"my_package.dll"
]
}
}
})";
TEST(NativeAssetsManagerTest, NoAvailableAssets) {
NativeAssetsManager manager;
std::string available_assets = manager.AvailableNativeAssets();
ASSERT_EQ(available_assets, "No available native assets.");
}
TEST(NativeAssetsManagerTest, NativeAssetsManifestParsing) {
NativeAssetsManager manager;
manager.RegisterNativeAssets(reinterpret_cast<const uint8_t*>(kTestManifest),
strlen(kTestManifest));
std::string available_assets = manager.AvailableNativeAssets();
ASSERT_EQ(available_assets,
"Available native assets: "
"package:my_package/my_package_bindings_generated.dart.");
std::vector<std::string> existing_asset = manager.LookupNativeAsset(
"package:my_package/my_package_bindings_generated.dart");
ASSERT_EQ(existing_asset.size(), 2u);
ASSERT_EQ(existing_asset[0], "absolute");
#if defined(FML_OS_MACOSX)
ASSERT_EQ(existing_asset[1], "my_package.framework/my_package");
#elif defined(FML_OS_LINUX)
ASSERT_EQ(existing_asset[1], "libmy_package.so");
#elif defined(FML_OS_WIN)
ASSERT_EQ(existing_asset[1], "my_package.dll");
#endif
std::vector<std::string> non_existing_asset =
manager.LookupNativeAsset("non_existing_asset");
ASSERT_EQ(non_existing_asset.size(), 0u);
}
} // namespace testing
} // namespace flutter

View File

@@ -24,6 +24,7 @@
../../../flutter/Doxyfile
../../../flutter/README.md
../../../flutter/analysis_options.yaml
../../../flutter/assets/native_assets_unittests.cc
../../../flutter/build
../../../flutter/build_overrides
../../../flutter/buildtools

View File

@@ -42477,6 +42477,8 @@ ORIGIN: ../../../flutter/assets/asset_manager.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/assets/asset_resolver.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/assets/directory_asset_bundle.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/assets/directory_asset_bundle.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/assets/native_assets.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/assets/native_assets.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/benchmarking/benchmarking.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/benchmarking/benchmarking.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/benchmarking/library.cc + ../../../flutter/LICENSE
@@ -45369,6 +45371,8 @@ FILE: ../../../flutter/assets/asset_manager.h
FILE: ../../../flutter/assets/asset_resolver.h
FILE: ../../../flutter/assets/directory_asset_bundle.cc
FILE: ../../../flutter/assets/directory_asset_bundle.h
FILE: ../../../flutter/assets/native_assets.cc
FILE: ../../../flutter/assets/native_assets.h
FILE: ../../../flutter/benchmarking/benchmarking.cc
FILE: ../../../flutter/benchmarking/benchmarking.h
FILE: ../../../flutter/benchmarking/library.cc

View File

@@ -5,7 +5,6 @@
#include "flutter/runtime/dart_isolate.h"
#include <cstdlib>
#include <tuple>
#include <utility>
#include "flutter/fml/logging.h"
@@ -14,14 +13,13 @@
#include "flutter/lib/io/dart_io.h"
#include "flutter/lib/ui/dart_runtime_hooks.h"
#include "flutter/lib/ui/dart_ui.h"
#include "flutter/lib/ui/window/platform_isolate.h"
#include "flutter/runtime/dart_isolate_group_data.h"
#include "flutter/runtime/dart_plugin_registrant.h"
#include "flutter/runtime/dart_service_isolate.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/runtime/dart_vm_lifecycle.h"
#include "flutter/runtime/isolate_configuration.h"
#include "flutter/runtime/runtime_controller.h"
#include "flutter/runtime/platform_isolate_manager.h"
#include "fml/message_loop_task_queues.h"
#include "fml/task_source.h"
#include "fml/time/time_point.h"
@@ -33,7 +31,6 @@
#include "third_party/tonic/dart_class_provider.h"
#include "third_party/tonic/dart_message_handler.h"
#include "third_party/tonic/dart_state.h"
#include "third_party/tonic/file_loader/file_loader.h"
#include "third_party/tonic/logging/dart_invoke.h"
#include "third_party/tonic/scopes/dart_api_scope.h"
#include "third_party/tonic/scopes/dart_isolate_scope.h"
@@ -100,7 +97,8 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
const std::vector<std::string>& dart_entrypoint_args,
std::unique_ptr<IsolateConfiguration> isolate_configuration,
const UIDartState::Context& context,
const DartIsolate* spawning_isolate) {
const DartIsolate* spawning_isolate,
std::shared_ptr<NativeAssetsManager> native_assets_manager) {
if (!isolate_snapshot) {
FML_LOG(ERROR) << "Invalid isolate snapshot.";
return {};
@@ -122,7 +120,8 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
isolate_create_callback, //
isolate_shutdown_callback, //
context, //
spawning_isolate //
spawning_isolate, //
std::move(native_assets_manager) //
)
.lock();
@@ -196,7 +195,8 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
const fml::closure& isolate_create_callback,
const fml::closure& isolate_shutdown_callback,
const UIDartState::Context& context,
const DartIsolate* spawning_isolate) {
const DartIsolate* spawning_isolate,
std::shared_ptr<NativeAssetsManager> native_assets_manager) {
TRACE_EVENT0("flutter", "DartIsolate::CreateRootIsolate");
// Only needed if this is the main isolate for the group.
@@ -247,7 +247,8 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
context.advisory_script_entrypoint, // advisory entrypoint
nullptr, // child isolate preparer
isolate_create_callback, // isolate create callback
isolate_shutdown_callback // isolate shutdown callback
isolate_shutdown_callback, // isolate shutdown callback
std::move(native_assets_manager) //
)));
isolate_maker = [](std::shared_ptr<DartIsolateGroupData>*
isolate_group_data,
@@ -1181,15 +1182,73 @@ static void* NativeAssetsDlopenRelative(const char* path, char** error) {
error);
}
static void* NativeAssetsDlopen(const char* asset_id, char** error) {
auto* isolate_group_data =
static_cast<std::shared_ptr<DartIsolateGroupData>*>(
Dart_CurrentIsolateGroupData());
auto native_assets_manager = (*isolate_group_data)->GetNativeAssetsManager();
if (native_assets_manager == nullptr) {
return nullptr;
}
std::vector<std::string> asset_path =
native_assets_manager->LookupNativeAsset(asset_id);
if (asset_path.size() == 0) {
// The asset id was not in the mapping.
return nullptr;
}
auto& path_type = asset_path[0];
std::string path;
static constexpr const char* kAbsolute = "absolute";
static constexpr const char* kExecutable = "executable";
static constexpr const char* kProcess = "process";
static constexpr const char* kRelative = "relative";
static constexpr const char* kSystem = "system";
if (path_type == kAbsolute || path_type == kRelative ||
path_type == kSystem) {
path = asset_path[1];
}
if (path_type == kAbsolute) {
return dart::bin::NativeAssets::DlopenAbsolute(path.c_str(), error);
} else if (path_type == kRelative) {
return NativeAssetsDlopenRelative(path.c_str(), error);
} else if (path_type == kSystem) {
return dart::bin::NativeAssets::DlopenSystem(path.c_str(), error);
} else if (path_type == kProcess) {
return dart::bin::NativeAssets::DlopenProcess(error);
} else if (path_type == kExecutable) {
return dart::bin::NativeAssets::DlopenExecutable(error);
}
return nullptr;
}
static char* NativeAssetsAvailableAssets() {
auto* isolate_group_data =
static_cast<std::shared_ptr<DartIsolateGroupData>*>(
Dart_CurrentIsolateGroupData());
auto native_assets_manager = (*isolate_group_data)->GetNativeAssetsManager();
FML_DCHECK(native_assets_manager != nullptr);
auto available_assets = native_assets_manager->AvailableNativeAssets();
auto* result = fml::strdup(available_assets.c_str());
return result;
}
static void InitDartFFIForIsolateGroup() {
NativeAssetsApi native_assets;
memset(&native_assets, 0, sizeof(native_assets));
// TODO(dacoharkes): Remove after flutter_tools stops kernel embedding.
native_assets.dlopen_absolute = &dart::bin::NativeAssets::DlopenAbsolute;
native_assets.dlopen_relative = &NativeAssetsDlopenRelative;
native_assets.dlopen_system = &dart::bin::NativeAssets::DlopenSystem;
native_assets.dlopen_executable = &dart::bin::NativeAssets::DlopenExecutable;
native_assets.dlopen_process = &dart::bin::NativeAssets::DlopenProcess;
// TODO(dacoharkes): End todo.
native_assets.dlsym = &dart::bin::NativeAssets::Dlsym;
native_assets.dlopen = &NativeAssetsDlopen;
native_assets.available_assets = &NativeAssetsAvailableAssets;
Dart_InitializeNativeAssetsResolver(&native_assets);
};

View File

@@ -7,21 +7,16 @@
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <unordered_set>
#include "flutter/common/task_runners.h"
#include "assets/native_assets.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
#include "flutter/lib/ui/io_manager.h"
#include "flutter/lib/ui/snapshot_delegate.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/platform_configuration.h"
#include "flutter/runtime/dart_snapshot.h"
#include "flutter/runtime/isolate_configuration.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/tonic/dart_state.h"
namespace flutter {
@@ -221,7 +216,8 @@ class DartIsolate : public UIDartState {
const std::vector<std::string>& dart_entrypoint_args,
std::unique_ptr<IsolateConfiguration> isolate_configuration,
const UIDartState::Context& context,
const DartIsolate* spawning_isolate = nullptr);
const DartIsolate* spawning_isolate = nullptr,
std::shared_ptr<NativeAssetsManager> native_assets_manager = nullptr);
// |UIDartState|
~DartIsolate() override;
@@ -447,7 +443,8 @@ class DartIsolate : public UIDartState {
const fml::closure& isolate_create_callback,
const fml::closure& isolate_shutdown_callback,
const UIDartState::Context& context,
const DartIsolate* spawning_isolate = nullptr);
const DartIsolate* spawning_isolate = nullptr,
std::shared_ptr<NativeAssetsManager> native_assets_manager = nullptr);
DartIsolate(const Settings& settings,
bool is_root_isolate,

View File

@@ -17,14 +17,16 @@ DartIsolateGroupData::DartIsolateGroupData(
std::string advisory_script_entrypoint,
const ChildIsolatePreparer& child_isolate_preparer,
const fml::closure& isolate_create_callback,
const fml::closure& isolate_shutdown_callback)
const fml::closure& isolate_shutdown_callback,
std::shared_ptr<NativeAssetsManager> native_assets_manager)
: settings_(settings),
isolate_snapshot_(std::move(isolate_snapshot)),
advisory_script_uri_(std::move(advisory_script_uri)),
advisory_script_entrypoint_(std::move(advisory_script_entrypoint)),
child_isolate_preparer_(child_isolate_preparer),
isolate_create_callback_(isolate_create_callback),
isolate_shutdown_callback_(isolate_shutdown_callback) {
isolate_shutdown_callback_(isolate_shutdown_callback),
native_assets_manager_(std::move(native_assets_manager)) {
FML_DCHECK(isolate_snapshot_) << "Must contain a valid isolate snapshot.";
}
@@ -66,6 +68,11 @@ void DartIsolateGroupData::SetChildIsolatePreparer(
child_isolate_preparer_ = value;
}
std::shared_ptr<NativeAssetsManager>
DartIsolateGroupData::GetNativeAssetsManager() const {
return native_assets_manager_;
}
void DartIsolateGroupData::SetPlatformMessageHandler(
int64_t root_isolate_token,
std::weak_ptr<PlatformMessageHandler> handler) {

View File

@@ -9,6 +9,7 @@
#include <mutex>
#include <string>
#include "assets/native_assets.h"
#include "flutter/common/settings.h"
#include "flutter/fml/closure.h"
#include "flutter/fml/memory/ref_ptr.h"
@@ -30,13 +31,15 @@ using ChildIsolatePreparer = std::function<bool(DartIsolate*)>;
// group cleanup callback on any thread.
class DartIsolateGroupData : public PlatformMessageHandlerStorage {
public:
DartIsolateGroupData(const Settings& settings,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
const ChildIsolatePreparer& child_isolate_preparer,
const fml::closure& isolate_create_callback,
const fml::closure& isolate_shutdown_callback);
DartIsolateGroupData(
const Settings& settings,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
const ChildIsolatePreparer& child_isolate_preparer,
const fml::closure& isolate_create_callback,
const fml::closure& isolate_shutdown_callback,
std::shared_ptr<NativeAssetsManager> native_assets_manager = nullptr);
~DartIsolateGroupData();
@@ -56,6 +59,8 @@ class DartIsolateGroupData : public PlatformMessageHandlerStorage {
void SetChildIsolatePreparer(const ChildIsolatePreparer& value);
std::shared_ptr<NativeAssetsManager> GetNativeAssetsManager() const;
/// Adds a kernel buffer mapping to the kernels loaded for this isolate group.
void AddKernelBuffer(const std::shared_ptr<const fml::Mapping>& buffer);
@@ -82,6 +87,7 @@ class DartIsolateGroupData : public PlatformMessageHandlerStorage {
ChildIsolatePreparer child_isolate_preparer_;
const fml::closure isolate_create_callback_;
const fml::closure isolate_shutdown_callback_;
std::shared_ptr<NativeAssetsManager> native_assets_manager_;
std::map<int64_t, std::weak_ptr<PlatformMessageHandler>>
platform_message_handlers_;
mutable std::mutex platform_message_handlers_mutex_;

View File

@@ -6,7 +6,6 @@
#define FLUTTER_RUNTIME_DART_SNAPSHOT_H_
#include <memory>
#include <string>
#include "flutter/common/settings.h"
#include "flutter/fml/macros.h"

View File

@@ -7,14 +7,12 @@
#include <future>
#include <memory>
#include <string>
#include "flutter/assets/asset_manager.h"
#include "flutter/assets/asset_resolver.h"
#include "flutter/common/settings.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/runtime/dart_isolate.h"
namespace flutter {

View File

@@ -4,6 +4,7 @@
#include "flutter/runtime/dart_vm.h"
#include "flutter/runtime/dart_vm_lifecycle.h"
#include "flutter/runtime/isolate_configuration.h"
#include "flutter/runtime/platform_isolate_manager.h"
#include "flutter/testing/fixture_test.h"
#include "flutter/testing/testing.h"

View File

@@ -6,9 +6,7 @@
#include <utility>
#include "flutter/common/constants.h"
#include "flutter/common/settings.h"
#include "flutter/fml/message_loop.h"
#include "flutter/fml/trace_event.h"
#include "flutter/lib/ui/compositing/scene.h"
#include "flutter/lib/ui/ui_dart_state.h"
@@ -530,7 +528,8 @@ bool RuntimeController::LaunchRootIsolate(
std::optional<std::string> dart_entrypoint,
std::optional<std::string> dart_entrypoint_library,
const std::vector<std::string>& dart_entrypoint_args,
std::unique_ptr<IsolateConfiguration> isolate_configuration) {
std::unique_ptr<IsolateConfiguration> isolate_configuration,
std::shared_ptr<NativeAssetsManager> native_assets_manager) {
if (root_isolate_.lock()) {
FML_LOG(ERROR) << "Root isolate was already running.";
return false;
@@ -550,7 +549,8 @@ bool RuntimeController::LaunchRootIsolate(
dart_entrypoint_args, //
std::move(isolate_configuration), //
context_, //
spawning_isolate_.lock().get()) //
spawning_isolate_.lock().get(),
std::move(native_assets_manager)) //
.lock();
if (!strong_root_isolate) {

View File

@@ -8,9 +8,9 @@
#include <memory>
#include <vector>
#include "assets/native_assets.h"
#include "flutter/assets/asset_manager.h"
#include "flutter/common/task_runners.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
#include "flutter/lib/ui/io_manager.h"
@@ -23,8 +23,6 @@
#include "flutter/runtime/dart_vm.h"
#include "flutter/runtime/platform_data.h"
#include "flutter/runtime/platform_isolate_manager.h"
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
namespace flutter {
@@ -167,7 +165,8 @@ class RuntimeController : public PlatformConfigurationClient,
std::optional<std::string> dart_entrypoint,
std::optional<std::string> dart_entrypoint_library,
const std::vector<std::string>& dart_entrypoint_args,
std::unique_ptr<IsolateConfiguration> isolate_configuration);
std::unique_ptr<IsolateConfiguration> isolate_configuration,
std::shared_ptr<NativeAssetsManager> native_assets_manager);
//----------------------------------------------------------------------------
/// @brief Clone the runtime controller. Launching an isolate with a

View File

@@ -10,17 +10,12 @@
#include <utility>
#include <vector>
#include "flutter/assets/native_assets.h"
#include "flutter/common/settings.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/trace_event.h"
#include "flutter/lib/snapshot/snapshot.h"
#include "flutter/lib/ui/text/font_collection.h"
#include "flutter/shell/common/animator.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/shell.h"
#include "impeller/runtime_stage/runtime_stage.h"
#include "rapidjson/document.h"
#include "third_party/dart/runtime/include/dart_tools_api.h"
namespace flutter {
@@ -195,6 +190,11 @@ bool Engine::UpdateAssetManager(
font_collection_->RegisterTestFonts();
}
if (native_assets_manager_ == nullptr) {
native_assets_manager_ = std::make_shared<NativeAssetsManager>();
}
native_assets_manager_->RegisterNativeAssets(asset_manager_);
return true;
}
@@ -244,7 +244,8 @@ Engine::RunStatus Engine::Run(RunConfiguration configuration) {
configuration.GetEntrypoint(), //
configuration.GetEntrypointLibrary(), //
configuration.GetEntrypointArgs(), //
configuration.TakeIsolateConfiguration()) //
configuration.TakeIsolateConfiguration(), //
native_assets_manager_) //
) {
return RunStatus::Failure;
}

View File

@@ -25,11 +25,8 @@
#include "flutter/runtime/runtime_controller.h"
#include "flutter/runtime/runtime_delegate.h"
#include "flutter/shell/common/animator.h"
#include "flutter/shell/common/display_manager.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/pointer_data_dispatcher.h"
#include "flutter/shell/common/run_configuration.h"
#include "flutter/shell/common/shell_io_manager.h"
namespace flutter {
@@ -1055,6 +1052,7 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
std::string initial_route_;
std::shared_ptr<AssetManager> asset_manager_;
std::shared_ptr<FontCollection> font_collection_;
std::shared_ptr<NativeAssetsManager> native_assets_manager_;
const std::unique_ptr<ImageDecoder> image_decoder_;
ImageGeneratorRegistry image_generator_registry_;
TaskRunners task_runners_;

View File

@@ -5,11 +5,9 @@
#define FML_USED_ON_EMBEDDER
#include <algorithm>
#include <chrono>
#include <ctime>
#include <future>
#include <memory>
#include <strstream>
#include <thread>
#include <utility>
#include <vector>
@@ -30,7 +28,6 @@
#include "flutter/flow/layers/transform_layer.h"
#include "flutter/fml/backtrace.h"
#include "flutter/fml/command_line.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/message_loop.h"
#include "flutter/fml/synchronization/count_down_latch.h"
#include "flutter/fml/synchronization/waitable_event.h"
@@ -317,7 +314,8 @@ class ThreadCheckingAssetResolver : public AssetResolver {
// |AssetResolver|
std::unique_ptr<fml::Mapping> GetAsMapping(
const std::string& asset_name) const override {
if (asset_name == "FontManifest.json") {
if (asset_name == "FontManifest.json" ||
asset_name == "NativeAssetsManifest.json") {
// This file is loaded directly by the engine.
return nullptr;
}

View File

@@ -418,6 +418,7 @@ def run_cc_tests(build_dir, executable_filter, coverage, capture_core_dump):
return (name, flags, extra_env)
unittests = [
make_test('assets_unittests'),
make_test('client_wrapper_glfw_unittests'),
make_test('client_wrapper_unittests'),
make_test('common_cpp_core_unittests'),