Refactor: Group together externally-managed UIDartState. (flutter/engine#26247)
Group together externally-managed UIDartState. It's a frequent pattern to enable access to shell resources from the framework via UIDartState. These handles are passed through several other objects, where they lay mostly dormant. This refactor just aims to ease maintenance of this state. UIDartState is essentially just an easy to extend bus for dropping off the shell kids in UIDartState, with constructors/operators that remove the need for providing a full initializer lists in unittests.
This commit is contained in:
@@ -24,43 +24,50 @@ using tonic::ToDart;
|
||||
|
||||
namespace flutter {
|
||||
|
||||
UIDartState::UIDartState(
|
||||
TaskRunners task_runners,
|
||||
TaskObserverAdd add_callback,
|
||||
TaskObserverRemove remove_callback,
|
||||
UIDartState::Context::Context(const TaskRunners& task_runners)
|
||||
: task_runners(task_runners) {}
|
||||
|
||||
UIDartState::Context::Context(
|
||||
const TaskRunners& task_runners,
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> skia_unref_queue,
|
||||
fml::RefPtr<SkiaUnrefQueue> unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker)
|
||||
: task_runners(task_runners),
|
||||
snapshot_delegate(snapshot_delegate),
|
||||
hint_freed_delegate(hint_freed_delegate),
|
||||
io_manager(io_manager),
|
||||
unref_queue(unref_queue),
|
||||
image_decoder(image_decoder),
|
||||
image_generator_registry(image_generator_registry),
|
||||
advisory_script_uri(advisory_script_uri),
|
||||
advisory_script_entrypoint(advisory_script_entrypoint),
|
||||
volatile_path_tracker(volatile_path_tracker) {}
|
||||
|
||||
UIDartState::UIDartState(
|
||||
TaskObserverAdd add_callback,
|
||||
TaskObserverRemove remove_callback,
|
||||
std::string logger_prefix,
|
||||
UnhandledExceptionCallback unhandled_exception_callback,
|
||||
LogMessageCallback log_message_callback,
|
||||
std::shared_ptr<IsolateNameServer> isolate_name_server,
|
||||
bool is_root_isolate,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
|
||||
bool enable_skparagraph)
|
||||
: task_runners_(std::move(task_runners)),
|
||||
add_callback_(std::move(add_callback)),
|
||||
bool enable_skparagraph,
|
||||
const UIDartState::Context& context)
|
||||
: add_callback_(std::move(add_callback)),
|
||||
remove_callback_(std::move(remove_callback)),
|
||||
snapshot_delegate_(std::move(snapshot_delegate)),
|
||||
hint_freed_delegate_(std::move(hint_freed_delegate)),
|
||||
io_manager_(std::move(io_manager)),
|
||||
skia_unref_queue_(std::move(skia_unref_queue)),
|
||||
image_decoder_(std::move(image_decoder)),
|
||||
image_generator_registry_(std::move(image_generator_registry)),
|
||||
volatile_path_tracker_(std::move(volatile_path_tracker)),
|
||||
advisory_script_uri_(std::move(advisory_script_uri)),
|
||||
advisory_script_entrypoint_(std::move(advisory_script_entrypoint)),
|
||||
logger_prefix_(std::move(logger_prefix)),
|
||||
is_root_isolate_(is_root_isolate),
|
||||
unhandled_exception_callback_(unhandled_exception_callback),
|
||||
log_message_callback_(log_message_callback),
|
||||
isolate_name_server_(std::move(isolate_name_server)),
|
||||
enable_skparagraph_(enable_skparagraph) {
|
||||
enable_skparagraph_(enable_skparagraph),
|
||||
context_(std::move(context)) {
|
||||
AddOrRemoveTaskObserver(true /* add */);
|
||||
}
|
||||
|
||||
@@ -69,19 +76,19 @@ UIDartState::~UIDartState() {
|
||||
}
|
||||
|
||||
const std::string& UIDartState::GetAdvisoryScriptURI() const {
|
||||
return advisory_script_uri_;
|
||||
return context_.advisory_script_uri;
|
||||
}
|
||||
|
||||
const std::string& UIDartState::GetAdvisoryScriptEntrypoint() const {
|
||||
return advisory_script_entrypoint_;
|
||||
return context_.advisory_script_entrypoint;
|
||||
}
|
||||
|
||||
void UIDartState::DidSetIsolate() {
|
||||
main_port_ = Dart_GetMainPortId();
|
||||
std::ostringstream debug_name;
|
||||
// main.dart$main-1234
|
||||
debug_name << advisory_script_uri_ << "$" << advisory_script_entrypoint_
|
||||
<< "-" << main_port_;
|
||||
debug_name << context_.advisory_script_uri << "$"
|
||||
<< context_.advisory_script_entrypoint << "-" << main_port_;
|
||||
SetDebugName(debug_name.str());
|
||||
}
|
||||
|
||||
@@ -114,20 +121,20 @@ void UIDartState::SetPlatformConfiguration(
|
||||
}
|
||||
|
||||
const TaskRunners& UIDartState::GetTaskRunners() const {
|
||||
return task_runners_;
|
||||
return context_.task_runners;
|
||||
}
|
||||
|
||||
fml::WeakPtr<IOManager> UIDartState::GetIOManager() const {
|
||||
return io_manager_;
|
||||
return context_.io_manager;
|
||||
}
|
||||
|
||||
fml::RefPtr<flutter::SkiaUnrefQueue> UIDartState::GetSkiaUnrefQueue() const {
|
||||
return skia_unref_queue_;
|
||||
return context_.unref_queue;
|
||||
}
|
||||
|
||||
std::shared_ptr<VolatilePathTracker> UIDartState::GetVolatilePathTracker()
|
||||
const {
|
||||
return volatile_path_tracker_;
|
||||
return context_.volatile_path_tracker;
|
||||
}
|
||||
|
||||
void UIDartState::ScheduleMicrotask(Dart_Handle closure) {
|
||||
@@ -143,7 +150,7 @@ void UIDartState::FlushMicrotasksNow() {
|
||||
}
|
||||
|
||||
void UIDartState::AddOrRemoveTaskObserver(bool add) {
|
||||
auto task_runner = task_runners_.GetUITaskRunner();
|
||||
auto task_runner = context_.task_runners.GetUITaskRunner();
|
||||
if (!task_runner) {
|
||||
// This may happen in case the isolate has no thread affinity (for example,
|
||||
// the service isolate).
|
||||
@@ -159,27 +166,27 @@ void UIDartState::AddOrRemoveTaskObserver(bool add) {
|
||||
}
|
||||
|
||||
fml::WeakPtr<SnapshotDelegate> UIDartState::GetSnapshotDelegate() const {
|
||||
return snapshot_delegate_;
|
||||
return context_.snapshot_delegate;
|
||||
}
|
||||
|
||||
fml::WeakPtr<HintFreedDelegate> UIDartState::GetHintFreedDelegate() const {
|
||||
return hint_freed_delegate_;
|
||||
return context_.hint_freed_delegate;
|
||||
}
|
||||
|
||||
fml::WeakPtr<GrDirectContext> UIDartState::GetResourceContext() const {
|
||||
if (!io_manager_) {
|
||||
if (!context_.io_manager) {
|
||||
return {};
|
||||
}
|
||||
return io_manager_->GetResourceContext();
|
||||
return context_.io_manager->GetResourceContext();
|
||||
}
|
||||
|
||||
fml::WeakPtr<ImageDecoder> UIDartState::GetImageDecoder() const {
|
||||
return image_decoder_;
|
||||
return context_.image_decoder;
|
||||
}
|
||||
|
||||
fml::WeakPtr<ImageGeneratorRegistry> UIDartState::GetImageGeneratorRegistry()
|
||||
const {
|
||||
return image_generator_registry_;
|
||||
return context_.image_generator_registry;
|
||||
}
|
||||
|
||||
std::shared_ptr<IsolateNameServer> UIDartState::GetIsolateNameServer() const {
|
||||
|
||||
@@ -36,6 +36,67 @@ class UIDartState : public tonic::DartState {
|
||||
public:
|
||||
static UIDartState* Current();
|
||||
|
||||
/// @brief The subset of state which is owned by the shell or engine
|
||||
/// and passed through the RuntimeController into DartIsolates.
|
||||
/// If a shell-owned resource needs to be exposed to the framework via
|
||||
/// UIDartState, a pointer to the resource can be added to this
|
||||
/// struct with appropriate default construction.
|
||||
struct Context {
|
||||
Context(const TaskRunners& task_runners);
|
||||
|
||||
Context(const TaskRunners& task_runners,
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker);
|
||||
|
||||
/// The task runners used by the shell hosting this runtime controller. This
|
||||
/// may be used by the isolate to scheduled asynchronous texture uploads or
|
||||
/// post tasks to the platform task runner.
|
||||
const TaskRunners task_runners;
|
||||
|
||||
/// The snapshot delegate used by the
|
||||
/// isolate to gather raster snapshots
|
||||
/// of Flutter view hierarchies.
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate;
|
||||
|
||||
/// The delegate used by the isolate to hint the Dart VM when additional
|
||||
/// memory may be freed if a GC ran at the next NotifyIdle.
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate;
|
||||
|
||||
/// The IO manager used by the isolate for asynchronous texture uploads.
|
||||
fml::WeakPtr<IOManager> io_manager;
|
||||
|
||||
/// The unref queue used by the isolate to collect resources that may
|
||||
/// reference resources on the GPU.
|
||||
fml::RefPtr<SkiaUnrefQueue> unref_queue;
|
||||
|
||||
/// The image decoder.
|
||||
fml::WeakPtr<ImageDecoder> image_decoder;
|
||||
|
||||
/// Cascading registry of image generator builders. Given compressed image
|
||||
/// bytes as input, this is used to find and create image generators, which
|
||||
/// can then be used for image decoding.
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry;
|
||||
|
||||
/// The advisory script URI (only used for debugging). This does not affect
|
||||
/// the code being run in the isolate in any way.
|
||||
std::string advisory_script_uri;
|
||||
|
||||
/// The advisory script entrypoint (only used for debugging). This does not
|
||||
/// affect the code being run in the isolate in any way. The isolate must be
|
||||
/// transitioned to the running state explicitly by the caller.
|
||||
std::string advisory_script_entrypoint;
|
||||
|
||||
/// Cache for tracking path volatility.
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker;
|
||||
};
|
||||
|
||||
Dart_Port main_port() const { return main_port_; }
|
||||
// Root isolate of the VM application
|
||||
bool IsRootIsolate() const { return is_root_isolate_; }
|
||||
@@ -102,24 +163,15 @@ class UIDartState : public tonic::DartState {
|
||||
};
|
||||
|
||||
protected:
|
||||
UIDartState(TaskRunners task_runners,
|
||||
TaskObserverAdd add_callback,
|
||||
UIDartState(TaskObserverAdd add_callback,
|
||||
TaskObserverRemove remove_callback,
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> skia_unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
std::string logger_prefix,
|
||||
UnhandledExceptionCallback unhandled_exception_callback,
|
||||
LogMessageCallback log_message_callback,
|
||||
std::shared_ptr<IsolateNameServer> isolate_name_server,
|
||||
bool is_root_isolate_,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
|
||||
bool enable_skparagraph);
|
||||
bool enable_skparagraph,
|
||||
const UIDartState::Context& context);
|
||||
|
||||
~UIDartState() override;
|
||||
|
||||
@@ -133,18 +185,8 @@ class UIDartState : public tonic::DartState {
|
||||
private:
|
||||
void DidSetIsolate() override;
|
||||
|
||||
const TaskRunners task_runners_;
|
||||
const TaskObserverAdd add_callback_;
|
||||
const TaskObserverRemove remove_callback_;
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate_;
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate_;
|
||||
fml::WeakPtr<IOManager> io_manager_;
|
||||
fml::RefPtr<SkiaUnrefQueue> skia_unref_queue_;
|
||||
fml::WeakPtr<ImageDecoder> image_decoder_;
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry_;
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker_;
|
||||
const std::string advisory_script_uri_;
|
||||
const std::string advisory_script_entrypoint_;
|
||||
const std::string logger_prefix_;
|
||||
Dart_Port main_port_ = ILLEGAL_PORT;
|
||||
const bool is_root_isolate_;
|
||||
@@ -155,6 +197,7 @@ class UIDartState : public tonic::DartState {
|
||||
LogMessageCallback log_message_callback_;
|
||||
const std::shared_ptr<IsolateNameServer> isolate_name_server_;
|
||||
const bool enable_skparagraph_;
|
||||
UIDartState::Context context_;
|
||||
|
||||
void AddOrRemoveTaskObserver(bool add);
|
||||
};
|
||||
|
||||
@@ -92,35 +92,40 @@ std::weak_ptr<DartIsolate> DartIsolate::SpawnIsolate(
|
||||
std::optional<std::string> dart_entrypoint_library,
|
||||
std::unique_ptr<IsolateConfiguration> isolate_configration) const {
|
||||
return CreateRunningRootIsolate(
|
||||
settings, GetIsolateGroupData().GetIsolateSnapshot(), GetTaskRunners(),
|
||||
std::move(platform_configuration), snapshot_delegate, hint_freed_delegate,
|
||||
GetIOManager(), GetSkiaUnrefQueue(), GetImageDecoder(),
|
||||
GetImageGeneratorRegistry(), advisory_script_uri,
|
||||
advisory_script_entrypoint, flags, isolate_create_callback,
|
||||
isolate_shutdown_callback, dart_entrypoint, dart_entrypoint_library,
|
||||
std::move(isolate_configration), GetVolatilePathTracker(), this);
|
||||
settings, //
|
||||
GetIsolateGroupData().GetIsolateSnapshot(), //
|
||||
std::move(platform_configuration), //
|
||||
flags, //
|
||||
isolate_create_callback, //
|
||||
isolate_shutdown_callback, //
|
||||
dart_entrypoint, //
|
||||
dart_entrypoint_library, //
|
||||
std::move(isolate_configration), //
|
||||
UIDartState::Context{GetTaskRunners(), //
|
||||
snapshot_delegate, //
|
||||
hint_freed_delegate, //
|
||||
GetIOManager(), //
|
||||
GetSkiaUnrefQueue(), //
|
||||
GetImageDecoder(), //
|
||||
GetImageGeneratorRegistry(), //
|
||||
advisory_script_uri, //
|
||||
advisory_script_entrypoint, //
|
||||
GetVolatilePathTracker()}, //
|
||||
this //
|
||||
);
|
||||
}
|
||||
|
||||
std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
|
||||
const Settings& settings,
|
||||
fml::RefPtr<const DartSnapshot> isolate_snapshot,
|
||||
TaskRunners task_runners,
|
||||
std::unique_ptr<PlatformConfiguration> platform_configuration,
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> skia_unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
Flags isolate_flags,
|
||||
const fml::closure& isolate_create_callback,
|
||||
const fml::closure& isolate_shutdown_callback,
|
||||
std::optional<std::string> dart_entrypoint,
|
||||
std::optional<std::string> dart_entrypoint_library,
|
||||
std::unique_ptr<IsolateConfiguration> isolate_configration,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
|
||||
const UIDartState::Context& context,
|
||||
const DartIsolate* spawning_isolate) {
|
||||
if (!isolate_snapshot) {
|
||||
FML_LOG(ERROR) << "Invalid isolate snapshot.";
|
||||
@@ -137,20 +142,11 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
|
||||
|
||||
auto isolate = CreateRootIsolate(settings, //
|
||||
isolate_snapshot, //
|
||||
task_runners, //
|
||||
std::move(platform_configuration), //
|
||||
snapshot_delegate, //
|
||||
hint_freed_delegate, //
|
||||
io_manager, //
|
||||
skia_unref_queue, //
|
||||
image_decoder, //
|
||||
image_generator_registry, //
|
||||
advisory_script_uri, //
|
||||
advisory_script_entrypoint, //
|
||||
isolate_flags, //
|
||||
isolate_create_callback, //
|
||||
isolate_shutdown_callback, //
|
||||
std::move(volatile_path_tracker), //
|
||||
context, //
|
||||
spawning_isolate //
|
||||
)
|
||||
.lock();
|
||||
@@ -217,20 +213,11 @@ void DartIsolate::SpawnIsolateShutdownCallback(
|
||||
std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
|
||||
const Settings& settings,
|
||||
fml::RefPtr<const DartSnapshot> isolate_snapshot,
|
||||
TaskRunners task_runners,
|
||||
std::unique_ptr<PlatformConfiguration> platform_configuration,
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
Flags flags,
|
||||
const fml::closure& isolate_create_callback,
|
||||
const fml::closure& isolate_shutdown_callback,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
|
||||
const UIDartState::Context& context,
|
||||
const DartIsolate* spawning_isolate) {
|
||||
TRACE_EVENT0("flutter", "DartIsolate::CreateRootIsolate");
|
||||
|
||||
@@ -239,29 +226,20 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
|
||||
auto isolate_group_data =
|
||||
std::make_unique<std::shared_ptr<DartIsolateGroupData>>(
|
||||
std::shared_ptr<DartIsolateGroupData>(new DartIsolateGroupData(
|
||||
settings, // settings
|
||||
std::move(isolate_snapshot), // isolate snapshot
|
||||
advisory_script_uri, // advisory URI
|
||||
advisory_script_entrypoint, // advisory entrypoint
|
||||
nullptr, // child isolate preparer
|
||||
isolate_create_callback, // isolate create callback
|
||||
isolate_shutdown_callback // isolate shutdown callback
|
||||
settings, // settings
|
||||
std::move(isolate_snapshot), // isolate snapshot
|
||||
context.advisory_script_uri, // advisory URI
|
||||
context.advisory_script_entrypoint, // advisory entrypoint
|
||||
nullptr, // child isolate preparer
|
||||
isolate_create_callback, // isolate create callback
|
||||
isolate_shutdown_callback // isolate shutdown callback
|
||||
)));
|
||||
|
||||
auto isolate_data = std::make_unique<std::shared_ptr<DartIsolate>>(
|
||||
std::shared_ptr<DartIsolate>(new DartIsolate(
|
||||
settings, // settings
|
||||
task_runners, // task runners
|
||||
std::move(snapshot_delegate), // snapshot delegate
|
||||
std::move(hint_freed_delegate), // hint freed delegate
|
||||
std::move(io_manager), // IO manager
|
||||
std::move(unref_queue), // Skia unref queue
|
||||
std::move(image_decoder), // Image Decoder
|
||||
std::move(image_generator_registry), // Image generator registry
|
||||
advisory_script_uri, // advisory URI
|
||||
advisory_script_entrypoint, // advisory entrypoint
|
||||
true, // is_root_isolate
|
||||
std::move(volatile_path_tracker) // volatile path tracker
|
||||
settings, // settings
|
||||
true, // is_root_isolate
|
||||
std::move(context) // context
|
||||
)));
|
||||
|
||||
DartErrorString error;
|
||||
@@ -322,37 +300,18 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRootIsolate(
|
||||
return (*root_isolate_data)->GetWeakIsolatePtr();
|
||||
}
|
||||
|
||||
DartIsolate::DartIsolate(
|
||||
const Settings& settings,
|
||||
TaskRunners task_runners,
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
bool is_root_isolate,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker)
|
||||
: UIDartState(std::move(task_runners),
|
||||
settings.task_observer_add,
|
||||
DartIsolate::DartIsolate(const Settings& settings,
|
||||
bool is_root_isolate,
|
||||
const UIDartState::Context& context)
|
||||
: UIDartState(settings.task_observer_add,
|
||||
settings.task_observer_remove,
|
||||
std::move(snapshot_delegate),
|
||||
std::move(hint_freed_delegate),
|
||||
std::move(io_manager),
|
||||
std::move(unref_queue),
|
||||
std::move(image_decoder),
|
||||
std::move(image_generator_registry),
|
||||
advisory_script_uri,
|
||||
advisory_script_entrypoint,
|
||||
settings.log_tag,
|
||||
settings.unhandled_exception_callback,
|
||||
settings.log_message_callback,
|
||||
DartVMRef::GetIsolateNameServer(),
|
||||
is_root_isolate,
|
||||
std::move(volatile_path_tracker),
|
||||
settings.enable_skparagraph),
|
||||
settings.enable_skparagraph,
|
||||
std::move(context)),
|
||||
may_insecurely_connect_to_all_domains_(
|
||||
settings.may_insecurely_connect_to_all_domains),
|
||||
domain_network_policy_(settings.domain_network_policy) {
|
||||
@@ -852,9 +811,6 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TaskRunners null_task_runners("io.flutter." DART_VM_SERVICE_ISOLATE_NAME,
|
||||
nullptr, nullptr, nullptr, nullptr);
|
||||
|
||||
flags->load_vmservice_library = true;
|
||||
|
||||
#if (FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_DEBUG)
|
||||
@@ -865,25 +821,19 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate(
|
||||
vm_data->GetIsolateSnapshot()->IsNullSafetyEnabled(nullptr);
|
||||
#endif
|
||||
|
||||
UIDartState::Context context(
|
||||
TaskRunners("io.flutter." DART_VM_SERVICE_ISOLATE_NAME, nullptr, nullptr,
|
||||
nullptr, nullptr));
|
||||
context.advisory_script_uri = DART_VM_SERVICE_ISOLATE_NAME;
|
||||
context.advisory_script_entrypoint = DART_VM_SERVICE_ISOLATE_NAME;
|
||||
std::weak_ptr<DartIsolate> weak_service_isolate =
|
||||
DartIsolate::CreateRootIsolate(
|
||||
vm_data->GetSettings(), // settings
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
null_task_runners, // task runners
|
||||
nullptr, // platform_configuration
|
||||
{}, // snapshot delegate
|
||||
{}, // Hint freed delegate
|
||||
{}, // IO Manager
|
||||
{}, // Skia unref queue
|
||||
{}, // Image Decoder
|
||||
{}, // Image generator registry
|
||||
DART_VM_SERVICE_ISOLATE_NAME, // script uri
|
||||
DART_VM_SERVICE_ISOLATE_NAME, // script entrypoint
|
||||
DartIsolate::Flags{flags}, // flags
|
||||
nullptr, // isolate create callback
|
||||
nullptr, // isolate shutdown callback
|
||||
nullptr // volatile path tracker
|
||||
);
|
||||
DartIsolate::CreateRootIsolate(vm_data->GetSettings(), //
|
||||
vm_data->GetIsolateSnapshot(), //
|
||||
nullptr, //
|
||||
DartIsolate::Flags{flags}, //
|
||||
nullptr, //
|
||||
nullptr, //
|
||||
context); //
|
||||
|
||||
std::shared_ptr<DartIsolate> service_isolate = weak_service_isolate.lock();
|
||||
if (!service_isolate) {
|
||||
@@ -990,20 +940,14 @@ Dart_Isolate DartIsolate::DartIsolateGroupCreateCallback(
|
||||
/* ui= */ nullptr,
|
||||
/* io= */ nullptr);
|
||||
|
||||
UIDartState::Context context(null_task_runners);
|
||||
context.advisory_script_uri = advisory_script_uri;
|
||||
context.advisory_script_entrypoint = advisory_script_entrypoint;
|
||||
auto isolate_data = std::make_unique<std::shared_ptr<DartIsolate>>(
|
||||
std::shared_ptr<DartIsolate>(new DartIsolate(
|
||||
(*isolate_group_data)->GetSettings(), // settings
|
||||
null_task_runners, // task_runners
|
||||
fml::WeakPtr<SnapshotDelegate>{}, // snapshot_delegate
|
||||
fml::WeakPtr<HintFreedDelegate>{}, // hint_freed_delegate
|
||||
fml::WeakPtr<IOManager>{}, // io_manager
|
||||
fml::RefPtr<SkiaUnrefQueue>{}, // unref_queue
|
||||
fml::WeakPtr<ImageDecoder>{}, // image_decoder
|
||||
fml::WeakPtr<ImageGeneratorRegistry>{}, // image_generator_registry
|
||||
advisory_script_uri, // advisory_script_uri
|
||||
advisory_script_entrypoint, // advisory_script_entrypoint
|
||||
false, // is_root_isolate
|
||||
nullptr))); // volatile path tracker
|
||||
std::shared_ptr<DartIsolate>(
|
||||
new DartIsolate((*isolate_group_data)->GetSettings(), // settings
|
||||
false, // is_root_isolate
|
||||
context))); // context
|
||||
|
||||
Dart_Isolate vm_isolate = CreateDartIsolateGroup(
|
||||
std::move(isolate_group_data), std::move(isolate_data), flags, error,
|
||||
@@ -1048,21 +992,15 @@ bool DartIsolate::DartIsolateInitializeCallback(void** child_callback_data,
|
||||
/* ui= */ nullptr,
|
||||
/* io= */ nullptr);
|
||||
|
||||
UIDartState::Context context(null_task_runners);
|
||||
context.advisory_script_uri = (*isolate_group_data)->GetAdvisoryScriptURI();
|
||||
context.advisory_script_entrypoint =
|
||||
(*isolate_group_data)->GetAdvisoryScriptEntrypoint();
|
||||
auto embedder_isolate = std::make_unique<std::shared_ptr<DartIsolate>>(
|
||||
std::shared_ptr<DartIsolate>(new DartIsolate(
|
||||
(*isolate_group_data)->GetSettings(), // settings
|
||||
null_task_runners, // task_runners
|
||||
fml::WeakPtr<SnapshotDelegate>{}, // snapshot_delegate
|
||||
fml::WeakPtr<HintFreedDelegate>{}, // hint_freed_delegate
|
||||
fml::WeakPtr<IOManager>{}, // io_manager
|
||||
fml::RefPtr<SkiaUnrefQueue>{}, // unref_queue
|
||||
fml::WeakPtr<ImageDecoder>{}, // image_decoder
|
||||
fml::WeakPtr<ImageGeneratorRegistry>{}, // image_generator_registry
|
||||
(*isolate_group_data)->GetAdvisoryScriptURI(), // advisory_script_uri
|
||||
(*isolate_group_data)
|
||||
->GetAdvisoryScriptEntrypoint(), // advisory_script_entrypoint
|
||||
false, // is_root_isolate
|
||||
nullptr))); // volatile path tracker
|
||||
std::shared_ptr<DartIsolate>(
|
||||
new DartIsolate((*isolate_group_data)->GetSettings(), // settings
|
||||
false, // is_root_isolate
|
||||
context))); // context
|
||||
|
||||
// root isolate should have been created via CreateRootIsolate
|
||||
if (!InitializeIsolate(*embedder_isolate, isolate, error)) {
|
||||
|
||||
@@ -161,57 +161,34 @@ class DartIsolate : public UIDartState {
|
||||
///
|
||||
/// @param[in] settings The settings used to create the
|
||||
/// isolate.
|
||||
/// @param[in] isolate_snapshot The isolate snapshot. This is
|
||||
/// usually obtained from the
|
||||
/// DartVMData associated with the
|
||||
/// running Dart VM instance.
|
||||
/// @param[in] task_runners The task runners used by the
|
||||
/// isolate. Via UI bindings, the
|
||||
/// isolate will use the IO task
|
||||
/// runner to scheduled texture
|
||||
/// decompression jobs and post tasks
|
||||
/// back to the UI task runner.
|
||||
/// @param[in] window The weak pointer to the window
|
||||
/// associated with this root isolate.
|
||||
/// @param[in] io_manager The i/o manager.
|
||||
/// @param[in] unref_queue The Skia unref queue.
|
||||
/// @param[in] image_decoder The image decoder.
|
||||
/// @param[in] image_generator_registry Cascading registry of image
|
||||
/// generator builders. Given
|
||||
/// compressed image bytes as input,
|
||||
/// this is used to find and create
|
||||
/// image generators, which can then
|
||||
/// be used for image decoding.
|
||||
/// @param[in] advisory_script_uri The advisory script uri. This is
|
||||
/// only used in instrumentation.
|
||||
/// @param[in] advisory_script_entrypoint The advisory script entrypoint.
|
||||
/// This is only used in
|
||||
/// instrumentation. Notably, this is
|
||||
/// NOT the main entrypoint of Dart
|
||||
/// code in the isolate. That is
|
||||
/// specified when making one of the
|
||||
/// `Run` calls.
|
||||
/// @param[in] platform_configuration The platform configuration for
|
||||
/// handling communication with the
|
||||
/// framework.
|
||||
/// @param[in] flags The Dart isolate flags for this
|
||||
/// isolate instance.
|
||||
/// @param[in] dart_entrypoint The name of the dart entrypoint
|
||||
/// function to invoke.
|
||||
/// @param[in] dart_entrypoint_library The name of the dart library
|
||||
/// containing the entrypoint.
|
||||
/// @param[in] isolate_configuration The isolate configuration used to
|
||||
/// configure the isolate before
|
||||
/// invoking the entrypoint.
|
||||
/// @param[in] isolate_create_callback The isolate create callback. This
|
||||
/// will be called when the before the
|
||||
/// main Dart entrypoint is invoked in
|
||||
/// the root isolate. The isolate is
|
||||
/// already in the running state at
|
||||
/// this point and an isolate scope is
|
||||
/// current. This callback is made for
|
||||
/// all isolate launches (including
|
||||
/// the children of the root isolate).
|
||||
/// current.
|
||||
/// @param[in] isolate_shutdown_callback The isolate shutdown callback.
|
||||
/// This will be called before the
|
||||
/// isolate is about to transition
|
||||
/// into the Shutdown phase. The
|
||||
/// isolate is still running at this
|
||||
/// point and an isolate scope is
|
||||
/// current. This callback is made
|
||||
/// for all isolate shutdowns
|
||||
/// (including the children of the
|
||||
/// root isolate).
|
||||
/// current.
|
||||
/// @param[in] context Engine-owned state which is
|
||||
/// accessed by the root dart isolate.
|
||||
/// @param[in] spawning_isolate The isolate that is spawning the
|
||||
/// new isolate. See also
|
||||
/// DartIsolate::SpawnIsolate.
|
||||
@@ -224,23 +201,14 @@ class DartIsolate : public UIDartState {
|
||||
static std::weak_ptr<DartIsolate> CreateRunningRootIsolate(
|
||||
const Settings& settings,
|
||||
fml::RefPtr<const DartSnapshot> isolate_snapshot,
|
||||
TaskRunners task_runners,
|
||||
std::unique_ptr<PlatformConfiguration> platform_configuration,
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> skia_unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
Flags flags,
|
||||
const fml::closure& isolate_create_callback,
|
||||
const fml::closure& isolate_shutdown_callback,
|
||||
std::optional<std::string> dart_entrypoint,
|
||||
std::optional<std::string> dart_entrypoint_library,
|
||||
std::unique_ptr<IsolateConfiguration> isolate_configration,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
|
||||
const UIDartState::Context& context,
|
||||
const DartIsolate* spawning_isolate = nullptr);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -460,34 +428,16 @@ class DartIsolate : public UIDartState {
|
||||
static std::weak_ptr<DartIsolate> CreateRootIsolate(
|
||||
const Settings& settings,
|
||||
fml::RefPtr<const DartSnapshot> isolate_snapshot,
|
||||
TaskRunners task_runners,
|
||||
std::unique_ptr<PlatformConfiguration> platform_configuration,
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> skia_unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
Flags flags,
|
||||
const fml::closure& isolate_create_callback,
|
||||
const fml::closure& isolate_shutdown_callback,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
|
||||
const UIDartState::Context& context,
|
||||
const DartIsolate* spawning_isolate = nullptr);
|
||||
|
||||
DartIsolate(const Settings& settings,
|
||||
TaskRunners task_runners,
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
bool is_root_isolate,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker);
|
||||
const UIDartState::Context& context);
|
||||
|
||||
[[nodiscard]] bool Initialize(Dart_Isolate isolate);
|
||||
|
||||
|
||||
@@ -51,26 +51,20 @@ TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) {
|
||||
auto isolate_configuration =
|
||||
IsolateConfiguration::InferFromSettings(settings);
|
||||
|
||||
UIDartState::Context context(std::move(task_runners));
|
||||
context.advisory_script_uri = "main.dart";
|
||||
context.advisory_script_entrypoint = "main";
|
||||
auto weak_isolate = DartIsolate::CreateRunningRootIsolate(
|
||||
vm_data->GetSettings(), // settings
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
std::move(task_runners), // task runners
|
||||
nullptr, // window
|
||||
{}, // snapshot delegate
|
||||
{}, // hint freed delegate
|
||||
{}, // io manager
|
||||
{}, // unref queue
|
||||
{}, // image decoder
|
||||
{}, // image generator registry
|
||||
"main.dart", // advisory uri
|
||||
"main", // advisory entrypoint,
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
std::nullopt, // dart entrypoint library
|
||||
std::move(isolate_configuration), // isolate configuration
|
||||
nullptr // Volatile path tracker
|
||||
std::move(context) // engine context
|
||||
);
|
||||
auto root_isolate = weak_isolate.lock();
|
||||
ASSERT_TRUE(root_isolate);
|
||||
@@ -95,26 +89,20 @@ TEST_F(DartIsolateTest, SpawnIsolate) {
|
||||
auto isolate_configuration =
|
||||
IsolateConfiguration::InferFromSettings(settings);
|
||||
|
||||
UIDartState::Context context(std::move(task_runners));
|
||||
context.advisory_script_uri = "main.dart";
|
||||
context.advisory_script_entrypoint = "main";
|
||||
auto weak_isolate = DartIsolate::CreateRunningRootIsolate(
|
||||
vm_data->GetSettings(), // settings
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
std::move(task_runners), // task runners
|
||||
nullptr, // window
|
||||
{}, // snapshot delegate
|
||||
{}, // hint freed delegate
|
||||
{}, // io manager
|
||||
{}, // unref queue
|
||||
{}, // image decoder
|
||||
{}, // image generator registry
|
||||
"main.dart", // advisory uri
|
||||
"main", // advisory entrypoint,
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
std::nullopt, // dart entrypoint library
|
||||
std::move(isolate_configuration), // isolate configuration
|
||||
nullptr // Volatile path tracker
|
||||
std::move(context) // engine context
|
||||
);
|
||||
auto root_isolate = weak_isolate.lock();
|
||||
ASSERT_TRUE(root_isolate);
|
||||
@@ -174,26 +162,21 @@ TEST_F(DartIsolateTest, IsolateShutdownCallbackIsInIsolateScope) {
|
||||
);
|
||||
auto isolate_configuration =
|
||||
IsolateConfiguration::InferFromSettings(settings);
|
||||
|
||||
UIDartState::Context context(std::move(task_runners));
|
||||
context.advisory_script_uri = "main.dart";
|
||||
context.advisory_script_entrypoint = "main";
|
||||
auto weak_isolate = DartIsolate::CreateRunningRootIsolate(
|
||||
vm_data->GetSettings(), // settings
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
std::move(task_runners), // task runners
|
||||
nullptr, // window
|
||||
{}, // snapshot delegate
|
||||
{}, // hint freed delegate
|
||||
{}, // io manager
|
||||
{}, // unref queue
|
||||
{}, // image decoder
|
||||
{}, // image generator registry
|
||||
"main.dart", // advisory uri
|
||||
"main", // advisory entrypoint
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
std::nullopt, // dart entrypoint library
|
||||
std::move(isolate_configuration), // isolate configuration
|
||||
nullptr // Volatile path tracker
|
||||
std::move(context) // engine context
|
||||
);
|
||||
auto root_isolate = weak_isolate.lock();
|
||||
ASSERT_TRUE(root_isolate);
|
||||
@@ -434,27 +417,23 @@ TEST_F(DartIsolateTest, CanCreateServiceIsolate) {
|
||||
|
||||
auto isolate_configuration =
|
||||
IsolateConfiguration::InferFromSettings(settings);
|
||||
|
||||
UIDartState::Context context(std::move(task_runners));
|
||||
context.advisory_script_uri = "main.dart";
|
||||
context.advisory_script_entrypoint = "main";
|
||||
auto weak_isolate = DartIsolate::CreateRunningRootIsolate(
|
||||
vm_data->GetSettings(), // settings
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
std::move(task_runners), // task runners
|
||||
nullptr, // window
|
||||
{}, // snapshot delegate
|
||||
{}, // hint freed delegate
|
||||
{}, // io manager
|
||||
{}, // unref queue
|
||||
{}, // image decoder
|
||||
{}, // image generator registry
|
||||
"main.dart", // advisory uri
|
||||
"main", // advisory entrypoint,
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
std::nullopt, // dart entrypoint library
|
||||
std::move(isolate_configuration), // isolate configuration
|
||||
nullptr // Volatile path tracker
|
||||
std::move(context) // engine context
|
||||
);
|
||||
|
||||
auto root_isolate = weak_isolate.lock();
|
||||
ASSERT_TRUE(root_isolate);
|
||||
ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::Running);
|
||||
@@ -536,27 +515,23 @@ TEST_F(DartIsolateTest, InvalidLoadingUnitFails) {
|
||||
);
|
||||
auto isolate_configuration =
|
||||
IsolateConfiguration::InferFromSettings(settings);
|
||||
|
||||
UIDartState::Context context(std::move(task_runners));
|
||||
context.advisory_script_uri = "main.dart";
|
||||
context.advisory_script_entrypoint = "main";
|
||||
auto weak_isolate = DartIsolate::CreateRunningRootIsolate(
|
||||
vm_data->GetSettings(), // settings
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
std::move(task_runners), // task runners
|
||||
nullptr, // window
|
||||
{}, // snapshot delegate
|
||||
{}, // hint freed delegate
|
||||
{}, // io manager
|
||||
{}, // unref queue
|
||||
{}, // image decoder
|
||||
{}, // image generator registry
|
||||
"main.dart", // advisory uri
|
||||
"main", // advisory entrypoint
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
std::nullopt, // dart entrypoint library
|
||||
std::move(isolate_configuration), // isolate configuration
|
||||
nullptr // volatile path tracker
|
||||
std::move(context) // engine context
|
||||
);
|
||||
|
||||
auto root_isolate = weak_isolate.lock();
|
||||
ASSERT_TRUE(root_isolate);
|
||||
ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::Running);
|
||||
|
||||
@@ -55,27 +55,21 @@ static std::shared_ptr<DartIsolate> CreateAndRunRootIsolate(
|
||||
auto isolate_configuration =
|
||||
IsolateConfiguration::InferFromSettings(settings);
|
||||
|
||||
UIDartState::Context context(runners);
|
||||
context.advisory_script_uri = "main.dart";
|
||||
context.advisory_script_entrypoint = entrypoint.c_str();
|
||||
auto isolate =
|
||||
DartIsolate::CreateRunningRootIsolate(
|
||||
vm.GetSettings(), // settings
|
||||
vm.GetIsolateSnapshot(), // isolate_snapshot
|
||||
runners, // task_runners
|
||||
{}, // window
|
||||
{}, // snapshot_delegate
|
||||
{}, // hint_freed_delegate
|
||||
{}, // io_manager
|
||||
{}, // unref_queue
|
||||
{}, // image_decoder
|
||||
{}, // image_generator_registry
|
||||
"main.dart", // advisory_script_uri
|
||||
entrypoint.c_str(), // advisory_script_entrypoint
|
||||
{}, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback,
|
||||
entrypoint, // dart entrypoint
|
||||
std::nullopt, // dart entrypoint library
|
||||
std::move(isolate_configuration), // isolate configuration
|
||||
nullptr // Volatile path tracker
|
||||
std::move(context) // engine context
|
||||
)
|
||||
.lock();
|
||||
|
||||
|
||||
@@ -17,63 +17,48 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
RuntimeController::RuntimeController(RuntimeDelegate& client,
|
||||
TaskRunners p_task_runners)
|
||||
: client_(client), vm_(nullptr), task_runners_(p_task_runners) {}
|
||||
RuntimeController::RuntimeController(RuntimeDelegate& p_client,
|
||||
TaskRunners task_runners)
|
||||
: client_(p_client), vm_(nullptr), context_(task_runners) {}
|
||||
|
||||
RuntimeController::RuntimeController(
|
||||
RuntimeDelegate& p_client,
|
||||
DartVM* p_vm,
|
||||
fml::RefPtr<const DartSnapshot> p_isolate_snapshot,
|
||||
TaskRunners p_task_runners,
|
||||
fml::WeakPtr<SnapshotDelegate> p_snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> p_hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> p_io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> p_unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> p_image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> p_image_generator_registry,
|
||||
std::string p_advisory_script_uri,
|
||||
std::string p_advisory_script_entrypoint,
|
||||
const std::function<void(int64_t)>& idle_notification_callback,
|
||||
const std::function<void(int64_t)>& p_idle_notification_callback,
|
||||
const PlatformData& p_platform_data,
|
||||
const fml::closure& p_isolate_create_callback,
|
||||
const fml::closure& p_isolate_shutdown_callback,
|
||||
std::shared_ptr<const fml::Mapping> p_persistent_isolate_data,
|
||||
std::shared_ptr<VolatilePathTracker> p_volatile_path_tracker)
|
||||
const UIDartState::Context& p_context)
|
||||
: client_(p_client),
|
||||
vm_(p_vm),
|
||||
isolate_snapshot_(std::move(p_isolate_snapshot)),
|
||||
task_runners_(p_task_runners),
|
||||
snapshot_delegate_(p_snapshot_delegate),
|
||||
hint_freed_delegate_(p_hint_freed_delegate),
|
||||
io_manager_(p_io_manager),
|
||||
unref_queue_(p_unref_queue),
|
||||
image_decoder_(p_image_decoder),
|
||||
image_generator_registry_(p_image_generator_registry),
|
||||
advisory_script_uri_(p_advisory_script_uri),
|
||||
advisory_script_entrypoint_(p_advisory_script_entrypoint),
|
||||
idle_notification_callback_(idle_notification_callback),
|
||||
isolate_snapshot_(p_isolate_snapshot),
|
||||
idle_notification_callback_(p_idle_notification_callback),
|
||||
platform_data_(std::move(p_platform_data)),
|
||||
isolate_create_callback_(p_isolate_create_callback),
|
||||
isolate_shutdown_callback_(p_isolate_shutdown_callback),
|
||||
persistent_isolate_data_(std::move(p_persistent_isolate_data)),
|
||||
volatile_path_tracker_(std::move(p_volatile_path_tracker)) {}
|
||||
context_(p_context) {}
|
||||
|
||||
std::unique_ptr<RuntimeController> RuntimeController::Spawn(
|
||||
RuntimeDelegate& client,
|
||||
RuntimeDelegate& p_client,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
const std::function<void(int64_t)>& idle_notification_callback,
|
||||
const fml::closure& isolate_create_callback,
|
||||
const fml::closure& isolate_shutdown_callback,
|
||||
std::shared_ptr<const fml::Mapping> persistent_isolate_data) const {
|
||||
auto result = std::make_unique<RuntimeController>(
|
||||
client, vm_, isolate_snapshot_, task_runners_, snapshot_delegate_,
|
||||
hint_freed_delegate_, io_manager_, unref_queue_, image_decoder_,
|
||||
image_generator_registry_, advisory_script_uri,
|
||||
advisory_script_entrypoint, idle_notification_callback, platform_data_,
|
||||
isolate_create_callback, isolate_shutdown_callback,
|
||||
persistent_isolate_data, volatile_path_tracker_);
|
||||
const std::function<void(int64_t)>& p_idle_notification_callback,
|
||||
const fml::closure& p_isolate_create_callback,
|
||||
const fml::closure& p_isolate_shutdown_callback,
|
||||
std::shared_ptr<const fml::Mapping> p_persistent_isolate_data) const {
|
||||
auto result =
|
||||
std::make_unique<RuntimeController>(p_client, //
|
||||
vm_, //
|
||||
isolate_snapshot_, //
|
||||
p_idle_notification_callback, //
|
||||
platform_data_, //
|
||||
p_isolate_create_callback, //
|
||||
p_isolate_shutdown_callback, //
|
||||
p_persistent_isolate_data, //
|
||||
context_); //
|
||||
result->spawning_isolate_ = root_isolate_;
|
||||
return result;
|
||||
}
|
||||
@@ -100,26 +85,16 @@ bool RuntimeController::IsRootIsolateRunning() {
|
||||
}
|
||||
|
||||
std::unique_ptr<RuntimeController> RuntimeController::Clone() const {
|
||||
return std::unique_ptr<RuntimeController>(new RuntimeController(
|
||||
client_, //
|
||||
vm_, //
|
||||
isolate_snapshot_, //
|
||||
task_runners_, //
|
||||
snapshot_delegate_, //
|
||||
hint_freed_delegate_, //
|
||||
io_manager_, //
|
||||
unref_queue_, //
|
||||
image_decoder_, //
|
||||
image_generator_registry_, //
|
||||
advisory_script_uri_, //
|
||||
advisory_script_entrypoint_, //
|
||||
idle_notification_callback_, //
|
||||
platform_data_, //
|
||||
isolate_create_callback_, //
|
||||
isolate_shutdown_callback_, //
|
||||
persistent_isolate_data_, //
|
||||
volatile_path_tracker_ //
|
||||
));
|
||||
return std::make_unique<RuntimeController>(client_, //
|
||||
vm_, //
|
||||
isolate_snapshot_, //
|
||||
idle_notification_callback_, //
|
||||
platform_data_, //
|
||||
isolate_create_callback_, //
|
||||
isolate_shutdown_callback_, //
|
||||
persistent_isolate_data_, //
|
||||
context_ //
|
||||
);
|
||||
}
|
||||
|
||||
bool RuntimeController::FlushRuntimeStateToIsolate() {
|
||||
@@ -394,25 +369,15 @@ bool RuntimeController::LaunchRootIsolate(
|
||||
DartIsolate::CreateRunningRootIsolate(
|
||||
settings, //
|
||||
isolate_snapshot_, //
|
||||
task_runners_, //
|
||||
std::make_unique<PlatformConfiguration>(this), //
|
||||
snapshot_delegate_, //
|
||||
hint_freed_delegate_, //
|
||||
io_manager_, //
|
||||
unref_queue_, //
|
||||
image_decoder_, //
|
||||
image_generator_registry_, //
|
||||
advisory_script_uri_, //
|
||||
advisory_script_entrypoint_, //
|
||||
DartIsolate::Flags{}, //
|
||||
isolate_create_callback_, //
|
||||
isolate_shutdown_callback_, //
|
||||
dart_entrypoint, //
|
||||
dart_entrypoint_library, //
|
||||
std::move(isolate_configuration), //
|
||||
volatile_path_tracker_, //
|
||||
spawning_isolate_.lock().get() //
|
||||
)
|
||||
context_, //
|
||||
spawning_isolate_.lock().get()) //
|
||||
.lock();
|
||||
|
||||
if (!strong_root_isolate) {
|
||||
|
||||
@@ -55,50 +55,6 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
/// collected before the VM is
|
||||
/// destroyed (this order is
|
||||
/// guaranteed by the shell).
|
||||
/// @param[in] isolate_snapshot The isolate snapshot used to start
|
||||
/// the root isolate managed by this
|
||||
/// runtime controller. The isolate
|
||||
/// must be transitioned into the
|
||||
/// running phase manually by the
|
||||
/// caller.
|
||||
/// @param[in] task_runners The task runners used by the shell
|
||||
/// hosting this runtime controller.
|
||||
/// This may be used by the isolate to
|
||||
/// scheduled asynchronous texture
|
||||
/// uploads or post tasks to the
|
||||
/// platform task runner.
|
||||
/// @param[in] snapshot_delegate The snapshot delegate used by the
|
||||
/// isolate to gather raster snapshots
|
||||
/// of Flutter view hierarchies.
|
||||
/// @param[in] hint_freed_delegate The delegate used by the isolate
|
||||
/// to hint the Dart VM when
|
||||
/// additional memory may be freed
|
||||
/// if a GC ran at the next
|
||||
/// NotifyIdle.
|
||||
/// @param[in] io_manager The IO manager used by the isolate
|
||||
/// for asynchronous texture uploads.
|
||||
/// @param[in] unref_queue The unref queue used by the
|
||||
/// isolate to collect resources that
|
||||
/// may reference resources on the
|
||||
/// GPU.
|
||||
/// @param[in] image_decoder The image decoder.
|
||||
/// @param[in] image_generator_registry Cascading registry of image
|
||||
/// generator builders. Given
|
||||
/// compressed image bytes as input,
|
||||
/// this is used to find and create
|
||||
/// image generators, which can then
|
||||
/// be used for image decoding.
|
||||
/// @param[in] advisory_script_uri The advisory script URI (only used
|
||||
/// for debugging). This does not
|
||||
/// affect the code being run in the
|
||||
/// isolate in any way.
|
||||
/// @param[in] advisory_script_entrypoint The advisory script entrypoint
|
||||
/// (only used for debugging). This
|
||||
/// does not affect the code being run
|
||||
/// in the isolate in any way. The
|
||||
/// isolate must be transitioned to
|
||||
/// the running state explicitly by
|
||||
/// the caller.
|
||||
/// @param[in] idle_notification_callback The idle notification callback.
|
||||
/// This allows callers to run native
|
||||
/// code in isolate scope when the VM
|
||||
@@ -118,28 +74,19 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
/// @param[in] persistent_isolate_data Unstructured persistent read-only
|
||||
/// data that the root isolate can
|
||||
/// access in a synchronous manner.
|
||||
/// @param[in] volatile_path_tracker Cache for tracking path
|
||||
/// volatility.
|
||||
/// @param[in] context Engine-owned state which is
|
||||
/// accessed by the root dart isolate.
|
||||
///
|
||||
RuntimeController(
|
||||
RuntimeDelegate& client,
|
||||
RuntimeDelegate& p_client,
|
||||
DartVM* vm,
|
||||
fml::RefPtr<const DartSnapshot> isolate_snapshot,
|
||||
TaskRunners task_runners,
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate,
|
||||
fml::WeakPtr<IOManager> io_manager,
|
||||
fml::RefPtr<SkiaUnrefQueue> unref_queue,
|
||||
fml::WeakPtr<ImageDecoder> image_decoder,
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
fml::RefPtr<const DartSnapshot> p_isolate_snapshot,
|
||||
const std::function<void(int64_t)>& idle_notification_callback,
|
||||
const PlatformData& platform_data,
|
||||
const fml::closure& isolate_create_callback,
|
||||
const fml::closure& isolate_shutdown_callback,
|
||||
std::shared_ptr<const fml::Mapping> persistent_isolate_data,
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker);
|
||||
std::shared_ptr<const fml::Mapping> p_persistent_isolate_data,
|
||||
const UIDartState::Context& context);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Create a RuntimeController that shares as many resources as
|
||||
@@ -149,7 +96,7 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
/// @see RuntimeController::RuntimeController
|
||||
///
|
||||
std::unique_ptr<RuntimeController> Spawn(
|
||||
RuntimeDelegate& client,
|
||||
RuntimeDelegate& p_client,
|
||||
std::string advisory_script_uri,
|
||||
std::string advisory_script_entrypoint,
|
||||
const std::function<void(int64_t)>& idle_notification_callback,
|
||||
@@ -589,7 +536,9 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
|
||||
// |PlatformConfigurationClient|
|
||||
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
|
||||
const fml::WeakPtr<IOManager>& GetIOManager() const { return io_manager_; }
|
||||
const fml::WeakPtr<IOManager>& GetIOManager() const {
|
||||
return context_.io_manager;
|
||||
}
|
||||
|
||||
virtual DartVM* GetDartVM() const { return vm_; }
|
||||
|
||||
@@ -600,16 +549,16 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
const PlatformData& GetPlatformData() const { return platform_data_; }
|
||||
|
||||
const fml::RefPtr<SkiaUnrefQueue>& GetSkiaUnrefQueue() const {
|
||||
return unref_queue_;
|
||||
return context_.unref_queue;
|
||||
}
|
||||
|
||||
const fml::WeakPtr<SnapshotDelegate>& GetSnapshotDelegate() const {
|
||||
return snapshot_delegate_;
|
||||
return context_.snapshot_delegate;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Constructor for Mocks.
|
||||
RuntimeController(RuntimeDelegate& client, TaskRunners p_task_runners);
|
||||
RuntimeController(RuntimeDelegate& p_client, TaskRunners task_runners);
|
||||
|
||||
private:
|
||||
struct Locale {
|
||||
@@ -629,15 +578,6 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
RuntimeDelegate& client_;
|
||||
DartVM* const vm_;
|
||||
fml::RefPtr<const DartSnapshot> isolate_snapshot_;
|
||||
TaskRunners task_runners_;
|
||||
fml::WeakPtr<SnapshotDelegate> snapshot_delegate_;
|
||||
fml::WeakPtr<HintFreedDelegate> hint_freed_delegate_;
|
||||
fml::WeakPtr<IOManager> io_manager_;
|
||||
fml::RefPtr<SkiaUnrefQueue> unref_queue_;
|
||||
fml::WeakPtr<ImageDecoder> image_decoder_;
|
||||
fml::WeakPtr<ImageGeneratorRegistry> image_generator_registry_;
|
||||
std::string advisory_script_uri_;
|
||||
std::string advisory_script_entrypoint_;
|
||||
std::function<void(int64_t)> idle_notification_callback_;
|
||||
PlatformData platform_data_;
|
||||
std::weak_ptr<DartIsolate> root_isolate_;
|
||||
@@ -646,7 +586,7 @@ class RuntimeController : public PlatformConfigurationClient {
|
||||
const fml::closure isolate_create_callback_;
|
||||
const fml::closure isolate_shutdown_callback_;
|
||||
std::shared_ptr<const fml::Mapping> persistent_isolate_data_;
|
||||
std::shared_ptr<VolatilePathTracker> volatile_path_tracker_;
|
||||
UIDartState::Context context_;
|
||||
|
||||
PlatformConfiguration* GetPlatformConfigurationIfAvailable();
|
||||
|
||||
|
||||
@@ -87,25 +87,26 @@ Engine::Engine(Delegate& delegate,
|
||||
std::make_shared<FontCollection>(),
|
||||
nullptr) {
|
||||
runtime_controller_ = std::make_unique<RuntimeController>(
|
||||
*this, // runtime delegate
|
||||
&vm, // VM
|
||||
std::move(isolate_snapshot), // isolate snapshot
|
||||
task_runners_, // task runners
|
||||
std::move(snapshot_delegate), // snapshot delegate
|
||||
GetWeakPtr(), // hint freed delegate
|
||||
std::move(io_manager), // io manager
|
||||
std::move(unref_queue), // Skia unref queue
|
||||
image_decoder_.GetWeakPtr(), // image decoder
|
||||
image_generator_registry_.GetWeakPtr(), // image generator registry
|
||||
settings_.advisory_script_uri, // advisory script uri
|
||||
settings_.advisory_script_entrypoint, // advisory script entrypoint
|
||||
settings_.idle_notification_callback, // idle notification callback
|
||||
platform_data, // platform data
|
||||
settings_.isolate_create_callback, // isolate create callback
|
||||
settings_.isolate_shutdown_callback, // isolate shutdown callback
|
||||
settings_.persistent_isolate_data, // persistent isolate data
|
||||
std::move(volatile_path_tracker) // volatile path tracker
|
||||
);
|
||||
*this, // runtime delegate
|
||||
&vm, // VM
|
||||
std::move(isolate_snapshot), // isolate snapshot
|
||||
settings_.idle_notification_callback, // idle notification callback
|
||||
platform_data, // platform data
|
||||
settings_.isolate_create_callback, // isolate create callback
|
||||
settings_.isolate_shutdown_callback, // isolate shutdown callback
|
||||
settings_.persistent_isolate_data, // persistent isolate data
|
||||
UIDartState::Context{
|
||||
task_runners_, // task runners
|
||||
std::move(snapshot_delegate), // snapshot delegate
|
||||
GetWeakPtr(), // hint freed delegate
|
||||
std::move(io_manager), // io manager
|
||||
std::move(unref_queue), // Skia unref queue
|
||||
image_decoder_.GetWeakPtr(), // image decoder
|
||||
image_generator_registry_.GetWeakPtr(), // image generator registry
|
||||
settings_.advisory_script_uri, // advisory script uri
|
||||
settings_.advisory_script_entrypoint, // advisory script entrypoint
|
||||
std::move(volatile_path_tracker), // volatile path tracker
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<Engine> Engine::Spawn(
|
||||
|
||||
@@ -119,27 +119,23 @@ std::unique_ptr<AutoIsolateShutdown> RunDartCodeInIsolateOnUITaskRunner(
|
||||
auto isolate_configuration =
|
||||
IsolateConfiguration::InferFromSettings(settings);
|
||||
|
||||
UIDartState::Context context(std::move(task_runners));
|
||||
context.io_manager = io_manager;
|
||||
context.advisory_script_uri = "main.dart";
|
||||
context.advisory_script_entrypoint = entrypoint.c_str();
|
||||
|
||||
auto isolate =
|
||||
DartIsolate::CreateRunningRootIsolate(
|
||||
settings, // settings
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
std::move(task_runners), // task runners
|
||||
nullptr, // window
|
||||
{}, // snapshot delegate
|
||||
{}, // hint freed delegate
|
||||
io_manager, // io manager
|
||||
{}, // unref queue
|
||||
{}, // image decoder
|
||||
{}, // image generator registry
|
||||
"main.dart", // advisory uri
|
||||
entrypoint.c_str(), // advisory entrypoint
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
entrypoint, // entrypoint
|
||||
std::nullopt, // library
|
||||
std::move(isolate_configuration), // isolate configuration
|
||||
std::move(volatile_path_tracker) // volatile path tracker
|
||||
context // engine context
|
||||
)
|
||||
.lock();
|
||||
|
||||
|
||||
@@ -27,26 +27,21 @@ TEST_F(DartState, IsShuttingDown) {
|
||||
);
|
||||
auto isolate_configuration =
|
||||
IsolateConfiguration::InferFromSettings(settings);
|
||||
|
||||
UIDartState::Context context(std::move(task_runners));
|
||||
context.advisory_script_uri = "main.dart";
|
||||
context.advisory_script_entrypoint = "main";
|
||||
auto weak_isolate = DartIsolate::CreateRunningRootIsolate(
|
||||
vm_data->GetSettings(), // settings
|
||||
vm_data->GetIsolateSnapshot(), // isolate snapshot
|
||||
std::move(task_runners), // task runners
|
||||
nullptr, // window
|
||||
{}, // snapshot delegate
|
||||
{}, // hint freed delegate
|
||||
{}, // io manager
|
||||
{}, // unref queue
|
||||
{}, // image decoder
|
||||
{}, // image generator registry
|
||||
"main.dart", // advisory uri
|
||||
"main", // advisory entrypoint
|
||||
nullptr, // platform configuration
|
||||
DartIsolate::Flags{}, // flags
|
||||
settings.isolate_create_callback, // isolate create callback
|
||||
settings.isolate_shutdown_callback, // isolate shutdown callback
|
||||
"main", // dart entrypoint
|
||||
std::nullopt, // dart entrypoint library
|
||||
std::move(isolate_configuration), // isolate configuration
|
||||
nullptr // Volatile path tracker
|
||||
std::move(context) // engine context
|
||||
);
|
||||
auto root_isolate = weak_isolate.lock();
|
||||
ASSERT_TRUE(root_isolate);
|
||||
|
||||
Reference in New Issue
Block a user