From 47d04deb9913de5553bf67e0f7f29a5015ac7989 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 8 May 2018 11:56:31 -0700 Subject: [PATCH] Read/apply settings that apply process wide before creating any shell components. (flutter/engine#5203) --- engine/src/flutter/shell/common/shell.cc | 59 +++++++++++++++--------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index e508926a98..3359290f21 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -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::Create( blink::TaskRunners task_runners, blink::Settings settings, Shell::CreateCallback on_create_platform_view, Shell::CreateCallback 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::Create( fxl::RefPtr isolate_snapshot, Shell::CreateCallback on_create_platform_view, Shell::CreateCallback 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