Read/apply settings that apply process wide before creating any shell components. (flutter/engine#5203)

This commit is contained in:
Chinmay Garde
2018-05-08 11:56:31 -07:00
committed by GitHub
parent 5c02bf571f
commit 47d04deb99

View File

@@ -155,11 +155,47 @@ static void RecordStartupTimestamp() {
}
}
// Though there can be multiple shells, some settings apply to all components in
// the process. These have to be setup before the shell or any of its
// sub-components can be initialized. In a perfect world, this would be empty.
// TODO(chinmaygarde): The unfortunate side effect of this call is that settings
// that cause shell initialization failures will still lead to some of their
// settings being applied.
static void PerformInitializationTasks(const blink::Settings& settings) {
static std::once_flag gShellSettingsInitialization = {};
std::call_once(gShellSettingsInitialization, [&settings] {
RecordStartupTimestamp();
fxl::LogSettings log_settings;
log_settings.min_log_level =
settings.verbose_logging ? fxl::LOG_INFO : fxl::LOG_ERROR;
fxl::SetLogSettings(log_settings);
if (settings.trace_skia) {
InitSkiaEventTracer(settings.trace_skia);
}
if (!settings.skia_deterministic_rendering_on_cpu) {
SkGraphics::Init();
} else {
FXL_DLOG(INFO) << "Skia deterministic rendering is enabled.";
}
if (settings.icu_data_path.size() != 0) {
fml::icu::InitializeICU(settings.icu_data_path);
} else {
FXL_DLOG(WARNING) << "Skipping ICU initialization in the shell.";
}
});
}
std::unique_ptr<Shell> Shell::Create(
blink::TaskRunners task_runners,
blink::Settings settings,
Shell::CreateCallback<PlatformView> on_create_platform_view,
Shell::CreateCallback<Rasterizer> on_create_rasterizer) {
PerformInitializationTasks(settings);
auto vm = blink::DartVM::ForProcess(settings);
FXL_CHECK(vm) << "Must be able to initialize the VM.";
return Shell::Create(std::move(task_runners), //
@@ -176,12 +212,7 @@ std::unique_ptr<Shell> Shell::Create(
fxl::RefPtr<blink::DartSnapshot> isolate_snapshot,
Shell::CreateCallback<PlatformView> on_create_platform_view,
Shell::CreateCallback<Rasterizer> on_create_rasterizer) {
RecordStartupTimestamp();
fxl::LogSettings log_settings;
log_settings.min_log_level =
settings.verbose_logging ? fxl::LOG_INFO : fxl::LOG_ERROR;
fxl::SetLogSettings(log_settings);
PerformInitializationTasks(settings);
if (!task_runners.IsValid() || !on_create_platform_view ||
!on_create_rasterizer) {
@@ -219,22 +250,6 @@ Shell::Shell(blink::TaskRunners task_runners, blink::Settings settings)
FXL_DCHECK(task_runners_.IsValid());
FXL_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
if (settings_.icu_data_path.size() != 0) {
fml::icu::InitializeICU(settings_.icu_data_path);
} else {
FXL_DLOG(WARNING) << "Skipping ICU initialization in the shell.";
}
if (settings_.trace_skia) {
InitSkiaEventTracer(settings_.trace_skia);
}
if (!settings_.skia_deterministic_rendering_on_cpu) {
SkGraphics::Init();
} else {
FXL_DLOG(INFO) << "Skia deterministic rendering is enabled.";
}
// Install service protocol handlers.
service_protocol_handlers_[blink::ServiceProtocol::kScreenshotExtensionName