From 1718f9b935222b019c7226186700e8f36ba49549 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Fri, 18 May 2018 17:04:36 -0700 Subject: [PATCH] Break the FXL from flutter/assets. (flutter/engine#5316) --- engine/src/flutter/assets/asset_manager.cc | 3 +- engine/src/flutter/assets/asset_manager.h | 13 +++---- engine/src/flutter/assets/asset_resolver.h | 4 +- .../flutter/assets/directory_asset_bundle.cc | 4 +- .../flutter/assets/directory_asset_bundle.h | 6 +-- engine/src/flutter/shell/common/engine.cc | 2 +- engine/src/flutter/shell/common/engine.h | 4 +- .../shell/common/isolate_configuration.cc | 9 +++-- .../shell/common/isolate_configuration.h | 2 +- .../flutter/shell/common/run_configuration.cc | 8 ++-- .../flutter/shell/common/run_configuration.h | 6 +-- engine/src/flutter/shell/common/shell.cc | 23 ++++++++--- .../platform/android/android_shell_holder.cc | 38 +++++++++---------- .../platform/android/android_shell_holder.h | 2 +- .../android/platform_view_android_jni.cc | 6 +-- .../src/flutter/shell/testing/tester_main.cc | 2 +- 16 files changed, 71 insertions(+), 61 deletions(-) diff --git a/engine/src/flutter/assets/asset_manager.cc b/engine/src/flutter/assets/asset_manager.cc index cdbe007a5a..d7da9aeb87 100644 --- a/engine/src/flutter/assets/asset_manager.cc +++ b/engine/src/flutter/assets/asset_manager.cc @@ -6,7 +6,6 @@ #include "flutter/assets/directory_asset_bundle.h" #include "flutter/glue/trace_event.h" -#include "lib/fxl/files/path.h" #ifdef ERROR #undef ERROR @@ -46,7 +45,7 @@ bool AssetManager::GetAsBuffer(const std::string& asset_name, return true; } } - FXL_DLOG(WARNING) << "Could not find asset: " << asset_name; + FML_DLOG(WARNING) << "Could not find asset: " << asset_name; return false; } diff --git a/engine/src/flutter/assets/asset_manager.h b/engine/src/flutter/assets/asset_manager.h index fc7f3ef052..2389ea8705 100644 --- a/engine/src/flutter/assets/asset_manager.h +++ b/engine/src/flutter/assets/asset_manager.h @@ -10,14 +10,13 @@ #include #include "flutter/assets/asset_resolver.h" -#include "lib/fxl/files/unique_fd.h" -#include "lib/fxl/macros.h" -#include "lib/fxl/memory/ref_counted.h" +#include "flutter/fml/macros.h" +#include "flutter/fml/memory/ref_counted.h" namespace blink { class AssetManager final : public AssetResolver, - public fxl::RefCountedThreadSafe { + public fml::RefCountedThreadSafe { public: void PushFront(std::unique_ptr resolver); @@ -37,9 +36,9 @@ class AssetManager final : public AssetResolver, ~AssetManager(); - FXL_DISALLOW_COPY_AND_ASSIGN(AssetManager); - FRIEND_MAKE_REF_COUNTED(AssetManager); - FRIEND_REF_COUNTED_THREAD_SAFE(AssetManager); + FML_DISALLOW_COPY_AND_ASSIGN(AssetManager); + FML_FRIEND_MAKE_REF_COUNTED(AssetManager); + FML_FRIEND_REF_COUNTED_THREAD_SAFE(AssetManager); }; } // namespace blink diff --git a/engine/src/flutter/assets/asset_resolver.h b/engine/src/flutter/assets/asset_resolver.h index 6cfe27961a..1d70791c6c 100644 --- a/engine/src/flutter/assets/asset_resolver.h +++ b/engine/src/flutter/assets/asset_resolver.h @@ -8,7 +8,7 @@ #include #include -#include "lib/fxl/macros.h" +#include "flutter/fml/macros.h" namespace blink { @@ -24,7 +24,7 @@ class AssetResolver { std::vector* data) const = 0; private: - FXL_DISALLOW_COPY_AND_ASSIGN(AssetResolver); + FML_DISALLOW_COPY_AND_ASSIGN(AssetResolver); }; } // namespace blink diff --git a/engine/src/flutter/assets/directory_asset_bundle.cc b/engine/src/flutter/assets/directory_asset_bundle.cc index 8e5d4df2ab..732161589d 100644 --- a/engine/src/flutter/assets/directory_asset_bundle.cc +++ b/engine/src/flutter/assets/directory_asset_bundle.cc @@ -6,9 +6,9 @@ #include +#include "flutter/fml/eintr_wrapper.h" #include "flutter/fml/file.h" #include "flutter/fml/mapping.h" -#include "lib/fxl/files/eintr_wrapper.h" namespace blink { @@ -35,7 +35,7 @@ bool DirectoryAssetBundle::GetAsBuffer(const std::string& asset_name, } if (!is_valid_) { - FXL_DLOG(WARNING) << "Asset bundle was not valid."; + FML_DLOG(WARNING) << "Asset bundle was not valid."; return false; } diff --git a/engine/src/flutter/assets/directory_asset_bundle.h b/engine/src/flutter/assets/directory_asset_bundle.h index b594e1357f..c3f231e0ae 100644 --- a/engine/src/flutter/assets/directory_asset_bundle.h +++ b/engine/src/flutter/assets/directory_asset_bundle.h @@ -6,9 +6,9 @@ #define FLUTTER_ASSETS_DIRECTORY_ASSET_BUNDLE_H_ #include "flutter/assets/asset_resolver.h" +#include "flutter/fml/macros.h" +#include "flutter/fml/memory/ref_counted.h" #include "flutter/fml/unique_fd.h" -#include "lib/fxl/macros.h" -#include "lib/fxl/memory/ref_counted.h" namespace blink { @@ -31,7 +31,7 @@ class DirectoryAssetBundle : public AssetResolver { bool GetAsBuffer(const std::string& asset_name, std::vector* data) const override; - FXL_DISALLOW_COPY_AND_ASSIGN(DirectoryAssetBundle); + FML_DISALLOW_COPY_AND_ASSIGN(DirectoryAssetBundle); }; } // namespace blink diff --git a/engine/src/flutter/shell/common/engine.cc b/engine/src/flutter/shell/common/engine.cc index 4958e7445e..175ebd54e9 100644 --- a/engine/src/flutter/shell/common/engine.cc +++ b/engine/src/flutter/shell/common/engine.cc @@ -70,7 +70,7 @@ fml::WeakPtr Engine::GetWeakPtr() const { } bool Engine::UpdateAssetManager( - fxl::RefPtr new_asset_manager) { + fml::RefPtr new_asset_manager) { if (asset_manager_ == new_asset_manager) { return false; } diff --git a/engine/src/flutter/shell/common/engine.h b/engine/src/flutter/shell/common/engine.h index edb1915a87..65e907759f 100644 --- a/engine/src/flutter/shell/common/engine.h +++ b/engine/src/flutter/shell/common/engine.h @@ -61,7 +61,7 @@ class Engine final : public blink::RuntimeDelegate { FXL_WARN_UNUSED_RESULT bool Restart(RunConfiguration configuration); - bool UpdateAssetManager(fxl::RefPtr asset_manager); + bool UpdateAssetManager(fml::RefPtr asset_manager); void BeginFrame(fxl::TimePoint frame_time); @@ -105,7 +105,7 @@ class Engine final : public blink::RuntimeDelegate { tonic::DartErrorHandleType load_script_error_; std::string initial_route_; blink::ViewportMetrics viewport_metrics_; - fxl::RefPtr asset_manager_; + fml::RefPtr asset_manager_; bool activity_running_; bool have_surface_; fml::WeakPtrFactory weak_factory_; diff --git a/engine/src/flutter/shell/common/isolate_configuration.cc b/engine/src/flutter/shell/common/isolate_configuration.cc index eaf89b6ce3..c971740568 100644 --- a/engine/src/flutter/shell/common/isolate_configuration.cc +++ b/engine/src/flutter/shell/common/isolate_configuration.cc @@ -92,7 +92,7 @@ class KernelListIsolateConfiguration final : public IsolateConfiguration { public: KernelListIsolateConfiguration( std::vector> kernel_pieces) - : kernel_pieces_(std::move(kernel_pieces)) {} + : kernel_pieces_(std::move(kernel_pieces)) {} // |shell::IsolateConfiguration| bool DoPrepareIsolate(blink::DartIsolate& isolate) override { @@ -119,7 +119,7 @@ class KernelListIsolateConfiguration final : public IsolateConfiguration { std::unique_ptr IsolateConfiguration::InferFromSettings( const blink::Settings& settings, - fxl::RefPtr asset_manager) { + fml::RefPtr asset_manager) { // Running in AOT mode. if (blink::DartVM::IsRunningPrecompiledCode()) { return CreateForPrecompiledCode(); @@ -174,8 +174,9 @@ std::unique_ptr IsolateConfiguration::InferFromSettings( piece_path_end++; } - std::string piece_path(reinterpret_cast(&kernel_list[piece_path_start]), - piece_path_end - piece_path_start); + std::string piece_path( + reinterpret_cast(&kernel_list[piece_path_start]), + piece_path_end - piece_path_start); std::vector piece; if (!asset_manager->GetAsBuffer(piece_path, &piece)) { FXL_LOG(ERROR) << "Failed to load: " << piece_path; diff --git a/engine/src/flutter/shell/common/isolate_configuration.h b/engine/src/flutter/shell/common/isolate_configuration.h index 67494407bb..a0b9ebe2fa 100644 --- a/engine/src/flutter/shell/common/isolate_configuration.h +++ b/engine/src/flutter/shell/common/isolate_configuration.h @@ -22,7 +22,7 @@ class IsolateConfiguration { public: static std::unique_ptr InferFromSettings( const blink::Settings& settings, - fxl::RefPtr asset_manager); + fml::RefPtr asset_manager); static std::unique_ptr CreateForPrecompiledCode(); diff --git a/engine/src/flutter/shell/common/run_configuration.cc b/engine/src/flutter/shell/common/run_configuration.cc index 8a2080ed79..eb315f25e8 100644 --- a/engine/src/flutter/shell/common/run_configuration.cc +++ b/engine/src/flutter/shell/common/run_configuration.cc @@ -14,7 +14,7 @@ namespace shell { RunConfiguration RunConfiguration::InferFromSettings( const blink::Settings& settings) { - auto asset_manager = fxl::MakeRefCounted(); + auto asset_manager = fml::MakeRefCounted(); asset_manager->PushBack(std::make_unique( fml::Duplicate(settings.assets_dir))); @@ -30,11 +30,11 @@ RunConfiguration RunConfiguration::InferFromSettings( RunConfiguration::RunConfiguration( std::unique_ptr configuration) : RunConfiguration(std::move(configuration), - fxl::MakeRefCounted()) {} + fml::MakeRefCounted()) {} RunConfiguration::RunConfiguration( std::unique_ptr configuration, - fxl::RefPtr asset_manager) + fml::RefPtr asset_manager) : isolate_configuration_(std::move(configuration)), asset_manager_(std::move(asset_manager)) {} @@ -60,7 +60,7 @@ void RunConfiguration::SetEntrypoint(std::string entrypoint) { entrypoint_ = std::move(entrypoint); } -fxl::RefPtr RunConfiguration::GetAssetManager() const { +fml::RefPtr RunConfiguration::GetAssetManager() const { return asset_manager_; } diff --git a/engine/src/flutter/shell/common/run_configuration.h b/engine/src/flutter/shell/common/run_configuration.h index 59aa075666..5d45d2a26b 100644 --- a/engine/src/flutter/shell/common/run_configuration.h +++ b/engine/src/flutter/shell/common/run_configuration.h @@ -25,7 +25,7 @@ class RunConfiguration { RunConfiguration(std::unique_ptr configuration); RunConfiguration(std::unique_ptr configuration, - fxl::RefPtr asset_manager); + fml::RefPtr asset_manager); RunConfiguration(RunConfiguration&&); @@ -37,7 +37,7 @@ class RunConfiguration { void SetEntrypoint(std::string entrypoint); - fxl::RefPtr GetAssetManager() const; + fml::RefPtr GetAssetManager() const; const std::string& GetEntrypoint() const; @@ -45,7 +45,7 @@ class RunConfiguration { private: std::unique_ptr isolate_configuration_; - fxl::RefPtr asset_manager_; + fml::RefPtr asset_manager_; std::string entrypoint_ = "main"; FXL_DISALLOW_COPY_AND_ASSIGN(RunConfiguration); diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index 8f096d9a70..5d02f8fd19 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -13,6 +13,8 @@ #include "flutter/assets/directory_asset_bundle.h" #include "flutter/fml/file.h" #include "flutter/fml/icu_util.h" +#include "flutter/fml/log_settings.h" +#include "flutter/fml/logging.h" #include "flutter/fml/message_loop.h" #include "flutter/glue/trace_event.h" #include "flutter/runtime/dart_vm.h" @@ -166,10 +168,21 @@ static void PerformInitializationTasks(const blink::Settings& settings) { 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); + // TODO(chinmaygarde): There are currently two loggers till the transition + // away from FXL is ongoing. Remove FXL when done. + { + fxl::LogSettings log_settings; + log_settings.min_log_level = + settings.verbose_logging ? fxl::LOG_INFO : fxl::LOG_ERROR; + fxl::SetLogSettings(log_settings); + } + + { + fml::LogSettings log_settings; + log_settings.min_log_level = + settings.verbose_logging ? fml::LOG_INFO : fml::LOG_ERROR; + fml::SetLogSettings(log_settings); + } if (settings.trace_skia) { InitSkiaEventTracer(settings.trace_skia); @@ -909,7 +922,7 @@ bool Shell::OnServiceProtocolSetAssetBundlePath( auto& allocator = response.GetAllocator(); response.SetObject(); - auto asset_manager = fxl::MakeRefCounted(); + auto asset_manager = fml::MakeRefCounted(); asset_manager->PushFront(std::make_unique( fml::OpenFile(params.at("assetDirectory").ToString().c_str(), diff --git a/engine/src/flutter/shell/platform/android/android_shell_holder.cc b/engine/src/flutter/shell/platform/android/android_shell_holder.cc index 15bfdc6ad4..2414e018ed 100644 --- a/engine/src/flutter/shell/platform/android/android_shell_holder.cc +++ b/engine/src/flutter/shell/platform/android/android_shell_holder.cc @@ -84,25 +84,23 @@ AndroidShellHolder::AndroidShellHolder( is_valid_ = shell_ != nullptr; if (is_valid_) { - task_runners.GetGPUTaskRunner()->PostTask( - []() { - // Android describes -8 as "most important display threads, for - // compositing the screen and retrieving input events". Conservatively - // set the GPU thread to slightly lower priority than it. - if (::setpriority(PRIO_PROCESS, gettid(), -5) != 0) { - // Defensive fallback. Depending on the OEM, it may not be possible - // to set priority to -5. - if (::setpriority(PRIO_PROCESS, gettid(), -2) != 0) { - FXL_LOG(ERROR) << "Failed to set GPU task runner priority"; - } - } - }); - task_runners.GetUITaskRunner()->PostTask( - []() { - if (::setpriority(PRIO_PROCESS, gettid(), -1) != 0) { - FXL_LOG(ERROR) << "Failed to set UI task runner priority"; - } - }); + task_runners.GetGPUTaskRunner()->PostTask([]() { + // Android describes -8 as "most important display threads, for + // compositing the screen and retrieving input events". Conservatively + // set the GPU thread to slightly lower priority than it. + if (::setpriority(PRIO_PROCESS, gettid(), -5) != 0) { + // Defensive fallback. Depending on the OEM, it may not be possible + // to set priority to -5. + if (::setpriority(PRIO_PROCESS, gettid(), -2) != 0) { + FXL_LOG(ERROR) << "Failed to set GPU task runner priority"; + } + } + }); + task_runners.GetUITaskRunner()->PostTask([]() { + if (::setpriority(PRIO_PROCESS, gettid(), -1) != 0) { + FXL_LOG(ERROR) << "Failed to set UI task runner priority"; + } + }); } } @@ -184,7 +182,7 @@ fml::WeakPtr AndroidShellHolder::GetPlatformView() { } void AndroidShellHolder::UpdateAssetManager( - fxl::RefPtr asset_manager) { + fml::RefPtr asset_manager) { if (!IsValid() || !asset_manager) { return; } diff --git a/engine/src/flutter/shell/platform/android/android_shell_holder.h b/engine/src/flutter/shell/platform/android/android_shell_holder.h index 4bf42a776d..0163d4bbdc 100644 --- a/engine/src/flutter/shell/platform/android/android_shell_holder.h +++ b/engine/src/flutter/shell/platform/android/android_shell_holder.h @@ -41,7 +41,7 @@ class AndroidShellHolder { Rasterizer::Screenshot Screenshot(Rasterizer::ScreenshotType type, bool base64_encode); - void UpdateAssetManager(fxl::RefPtr asset_manager); + void UpdateAssetManager(fml::RefPtr asset_manager); private: const blink::Settings settings_; diff --git a/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc b/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc index 9c16ebdd30..20748b09aa 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc @@ -201,7 +201,7 @@ static void RunBundleAndSnapshot( jstring jEntrypoint, jboolean /* reuse runtime controller (unused) */, jobject jAssetManager) { - auto asset_manager = fxl::MakeRefCounted(); + auto asset_manager = fml::MakeRefCounted(); const auto bundlepath = fml::jni::JavaStringToString(env, jbundlepath); @@ -253,7 +253,7 @@ static void RunBundleAndSource(JNIEnv* env, jstring jBundlePath, jstring main, jstring packages) { - auto asset_manager = fxl::MakeRefCounted(); + auto asset_manager = fml::MakeRefCounted(); const auto bundlepath = fml::jni::JavaStringToString(env, jBundlePath); @@ -304,7 +304,7 @@ void SetAssetBundlePathOnUI(JNIEnv* env, return; } - auto asset_manager = fxl::MakeRefCounted(); + auto asset_manager = fml::MakeRefCounted(); asset_manager->PushBack(std::move(directory_asset_bundle)); ANDROID_SHELL_HOLDER->UpdateAssetManager(std::move(asset_manager)); diff --git a/engine/src/flutter/shell/testing/tester_main.cc b/engine/src/flutter/shell/testing/tester_main.cc index 5258d80a86..099774f614 100644 --- a/engine/src/flutter/shell/testing/tester_main.cc +++ b/engine/src/flutter/shell/testing/tester_main.cc @@ -156,7 +156,7 @@ int RunTester(const blink::Settings& settings, bool run_forever) { return EXIT_FAILURE; } - auto asset_manager = fxl::MakeRefCounted(); + auto asset_manager = fml::MakeRefCounted(); asset_manager->PushBack(std::make_unique( fml::Duplicate(settings.assets_dir))); asset_manager->PushBack(