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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ struct Settings {
///
/// This is currently only used by iOS.
bool enable_embedder_api = false;

/// Enable support for isolates that run on the platform thread.
///
/// This is used by the runOnPlatformThread API.
bool enable_platform_isolates = false;
};

} // namespace flutter
Expand Down
8 changes: 8 additions & 0 deletions lib/ui/dart_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ void DartUI::InitForIsolate(const Settings& settings) {
}
}

if (settings.enable_platform_isolates) {
result =
Dart_SetField(dart_ui, ToDart("_platformIsolatesEnabled"), Dart_True());
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
}

result = Dart_SetField(dart_ui, ToDart("_implicitViewId"),
Dart_NewInteger(kFlutterImplicitViewId));
if (Dart_IsError(result)) {
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/natives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,8 @@ bool _impellerEnabled = false;
// determine the current implicit view, if any.
@pragma('vm:entry-point')
int? _implicitViewId;

// Used internally to indicate whether isolates running on the platform thread
// are enabled.
@pragma('vm:entry-point')
bool _platformIsolatesEnabled = false;
4 changes: 4 additions & 0 deletions lib/ui/platform_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ part of dart.ui;
///
/// This API is currently experimental.
Future<R> runOnPlatformThread<R>(FutureOr<R> Function() computation) {
if (!_platformIsolatesEnabled) {
throw UnsupportedError(
'Platform thread isolates are not supported by this platform.');
}
if (isRunningOnPlatformThread) {
return Future<R>(computation);
}
Expand Down
3 changes: 3 additions & 0 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
}
}

settings.enable_platform_isolates =
command_line.HasOption(FlagForSwitch(Switch::EnablePlatformIsolates));

return settings;
}

Expand Down
3 changes: 3 additions & 0 deletions shell/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ DEF_SWITCH(
DEF_SWITCH(EnableEmbedderAPI,
"enable-embedder-api",
"Enable the embedder api. Defaults to false. iOS only.")
DEF_SWITCH(EnablePlatformIsolates,
"enable-platform-isolates",
"Enable support for isolates that run on the platform thread.")
DEF_SWITCHES_END

void PrintUsage(const std::string& executable_name);
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/android/flutter_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ void FlutterMain::Init(JNIEnv* env,
static_cast<int>(message.size()), message.c_str());
};

settings.enable_platform_isolates = true;

#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
// There are no ownership concerns here as all mappings are owned by the
// embedder and not the engine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ static BOOL DoesHardwareSupportWideGamut() {
syslog(LOG_ALERT, "%.*s", (int)log.size(), log.c_str());
};

settings.enable_platform_isolates = true;

// The command line arguments may not always be complete. If they aren't, attempt to fill in
// defaults.

Expand Down
1 change: 1 addition & 0 deletions shell/platform/embedder/tests/embedder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3057,6 +3057,7 @@ TEST_F(EmbedderTest, PlatformThreadIsolatesWithCustomPlatformTaskRunner) {
builder.SetSoftwareRendererConfig();
builder.SetPlatformTaskRunner(&task_runner_description);
builder.SetDartEntrypoint("invokePlatformThreadIsolate");
builder.AddCommandLineArgument("--enable-platform-isolates");
engine = builder.LaunchEngine();
ASSERT_TRUE(engine.is_valid());
});
Expand Down
1 change: 1 addition & 0 deletions shell/testing/tester_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ int main(int argc, char* argv[]) {
}

settings.leak_vm = false;
settings.enable_platform_isolates = true;

if (settings.icu_data_path.empty()) {
settings.icu_data_path = "icudtl.dat";
Expand Down