From 2c52994c64c9947d952df1c227e19da428faa79a Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 11 Aug 2022 19:57:54 -0700 Subject: [PATCH] [Windows] Migrate error logging to FML_LOG Migrates error logging from logging directly to stderr to using the FML_LOG macro with a specified log level. No additional tests since there is no semantic change to the logging (FML_LOG simply writes to stderr). --- .../platform/windows/angle_surface_manager.cc | 11 +++-- .../platform/windows/external_texture_d3d.cc | 4 +- .../windows/flutter_project_bundle.cc | 18 ++++---- shell/platform/windows/flutter_window.cc | 4 +- .../windows/flutter_windows_engine.cc | 46 +++++++++---------- .../flutter_windows_texture_registrar.cc | 8 ++-- .../windows/keyboard_key_channel_handler.cc | 5 +- .../platform/windows/keyboard_key_handler.cc | 7 ++- shell/platform/windows/keyboard_manager.cc | 9 ++-- shell/platform/windows/platform_handler.cc | 13 ++++-- shell/platform/windows/task_runner_window.cc | 5 +- 11 files changed, 66 insertions(+), 64 deletions(-) diff --git a/shell/platform/windows/angle_surface_manager.cc b/shell/platform/windows/angle_surface_manager.cc index 8f8daf02ddd54..95eb1d1224873 100644 --- a/shell/platform/windows/angle_surface_manager.cc +++ b/shell/platform/windows/angle_surface_manager.cc @@ -4,15 +4,16 @@ #include "flutter/shell/platform/windows/angle_surface_manager.h" -#include #include +#include "flutter/fml/logging.h" + // Logs an EGL error to stderr. This automatically calls eglGetError() // and logs the error code. static void LogEglError(std::string message) { EGLint error = eglGetError(); - std::cerr << "EGL: " << message << std::endl; - std::cerr << "EGL: eglGetError returned " << error << std::endl; + FML_LOG(ERROR) << "EGL: " << message; + FML_LOG(ERROR) << "EGL: eglGetError returned " << error; } namespace flutter { @@ -245,8 +246,8 @@ void AngleSurfaceManager::ResizeSurface(WindowsRenderTarget* render_target, ClearContext(); DestroySurface(); if (!CreateSurface(render_target, width, height)) { - std::cerr << "AngleSurfaceManager::ResizeSurface failed to create surface" - << std::endl; + FML_LOG(ERROR) + << "AngleSurfaceManager::ResizeSurface failed to create surface"; } } } diff --git a/shell/platform/windows/external_texture_d3d.cc b/shell/platform/windows/external_texture_d3d.cc index dfd4d1979daf4..cd8785d717c67 100644 --- a/shell/platform/windows/external_texture_d3d.cc +++ b/shell/platform/windows/external_texture_d3d.cc @@ -6,8 +6,8 @@ #include #include -#include +#include "flutter/fml/logging.h" #include "flutter/shell/platform/embedder/embedder_struct_macros.h" namespace flutter { @@ -107,7 +107,7 @@ bool ExternalTextureD3d::CreateOrUpdateTexture( if (egl_surface_ == EGL_NO_SURFACE || eglBindTexImage(surface_manager_->egl_display(), egl_surface_, EGL_BACK_BUFFER) == EGL_FALSE) { - std::cerr << "Binding D3D surface failed." << std::endl; + FML_LOG(ERROR) << "Binding D3D surface failed."; } last_surface_handle_ = handle; } diff --git a/shell/platform/windows/flutter_project_bundle.cc b/shell/platform/windows/flutter_project_bundle.cc index 90b2d782d7d7e..df289b526a0f4 100644 --- a/shell/platform/windows/flutter_project_bundle.cc +++ b/shell/platform/windows/flutter_project_bundle.cc @@ -5,8 +5,8 @@ #include "flutter/shell/platform/windows/flutter_project_bundle.h" #include -#include +#include "flutter/fml/logging.h" #include "flutter/shell/platform/common/engine_switches.h" // nogncheck #include "flutter/shell/platform/common/path_utils.h" @@ -34,9 +34,8 @@ FlutterProjectBundle::FlutterProjectBundle( (!aot_library_path_.empty() && aot_library_path_.is_relative())) { std::filesystem::path executable_location = GetExecutableDirectory(); if (executable_location.empty()) { - std::cerr - << "Unable to find executable location to resolve resource paths." - << std::endl; + FML_LOG(ERROR) + << "Unable to find executable location to resolve resource paths."; assets_path_ = std::filesystem::path(); icu_path_ = std::filesystem::path(); } else { @@ -59,14 +58,13 @@ bool FlutterProjectBundle::HasValidPaths() { UniqueAotDataPtr FlutterProjectBundle::LoadAotData( const FlutterEngineProcTable& engine_procs) { if (aot_library_path_.empty()) { - std::cerr - << "Attempted to load AOT data, but no aot_library_path was provided." - << std::endl; + FML_LOG(ERROR) + << "Attempted to load AOT data, but no aot_library_path was provided."; return UniqueAotDataPtr(nullptr, nullptr); } if (!std::filesystem::exists(aot_library_path_)) { - std::cerr << "Can't load AOT data from " << aot_library_path_.u8string() - << "; no such file." << std::endl; + FML_LOG(ERROR) << "Can't load AOT data from " + << aot_library_path_.u8string() << "; no such file."; return UniqueAotDataPtr(nullptr, nullptr); } std::string path_string = aot_library_path_.u8string(); @@ -76,7 +74,7 @@ UniqueAotDataPtr FlutterProjectBundle::LoadAotData( FlutterEngineAOTData data = nullptr; auto result = engine_procs.CreateAOTData(&source, &data); if (result != kSuccess) { - std::cerr << "Failed to load AOT data from: " << path_string << std::endl; + FML_LOG(ERROR) << "Failed to load AOT data from: " << path_string; return UniqueAotDataPtr(nullptr, nullptr); } return UniqueAotDataPtr(data, engine_procs.CollectAOTData); diff --git a/shell/platform/windows/flutter_window.cc b/shell/platform/windows/flutter_window.cc index c25f433d9317f..67926e0a8ed37 100644 --- a/shell/platform/windows/flutter_window.cc +++ b/shell/platform/windows/flutter_window.cc @@ -8,6 +8,8 @@ #include #include +#include "flutter/fml/logging.h" + namespace flutter { namespace { @@ -121,7 +123,7 @@ static uint64_t ConvertWinButtonToFlutterButton(UINT button) { case XBUTTON2: return kFlutterPointerButtonMouseForward; } - std::cerr << "Mouse button not recognized: " << button << std::endl; + FML_LOG(WARNING) << "Mouse button not recognized: " << button; return 0; } diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index 54d68f232885b..972b9bb94b254 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -10,6 +10,7 @@ #include #include +#include "flutter/fml/logging.h" #include "flutter/fml/platform/win/wstring_conversion.h" #include "flutter/shell/platform/common/client_wrapper/binary_messenger_impl.h" #include "flutter/shell/platform/common/path_utils.h" @@ -156,17 +157,18 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project) embedder_api_.struct_size = sizeof(FlutterEngineProcTable); FlutterEngineGetProcAddresses(&embedder_api_); - task_runner_ = std::make_unique( - embedder_api_.GetCurrentTime, [this](const auto* task) { - if (!engine_) { - std::cerr << "Cannot post an engine task when engine is not running." - << std::endl; - return; - } - if (embedder_api_.RunTask(engine_, task) != kSuccess) { - std::cerr << "Failed to post an engine task." << std::endl; - } - }); + task_runner_ = + std::make_unique( + embedder_api_.GetCurrentTime, [this](const auto* task) { + if (!engine_) { + FML_LOG(ERROR) + << "Cannot post an engine task when engine is not running."; + return; + } + if (embedder_api_.RunTask(engine_, task) != kSuccess) { + FML_LOG(ERROR) << "Failed to post an engine task."; + } + }); // Set up the legacy structs backing the API handles. messenger_ = std::make_unique(); @@ -206,7 +208,7 @@ bool FlutterWindowsEngine::Run() { bool FlutterWindowsEngine::Run(std::string_view entrypoint) { if (!project_->HasValidPaths()) { - std::cerr << "Missing or unresolvable paths to assets." << std::endl; + FML_LOG(ERROR) << "Missing or unresolvable paths to assets."; return false; } std::string assets_path_string = project_->assets_path().u8string(); @@ -214,7 +216,7 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) { if (embedder_api_.RunsAOTCompiledDartCode()) { aot_data_ = project_->LoadAotData(embedder_api_); if (!aot_data_) { - std::cerr << "Unable to start engine without AOT data." << std::endl; + FML_LOG(ERROR) << "Unable to start engine without AOT data."; return false; } } @@ -272,10 +274,9 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) { // method and only the entrypoint specified in project_ should be used. if (!project_->dart_entrypoint().empty() && !entrypoint.empty() && project_->dart_entrypoint() != entrypoint) { - std::cerr << "Conflicting entrypoints were specified in " - "FlutterDesktopEngineProperties.dart_entrypoint and " - "FlutterDesktopEngineRun(engine, entry_point). " - << std::endl; + FML_LOG(ERROR) << "Conflicting entrypoints were specified in " + "FlutterDesktopEngineProperties.dart_entrypoint and " + "FlutterDesktopEngineRun(engine, entry_point). "; return false; } if (!entrypoint.empty()) { @@ -339,8 +340,7 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) { auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config, &args, this, &engine_); if (result != kSuccess || engine_ == nullptr) { - std::cerr << "Failed to start Flutter engine: error " << result - << std::endl; + FML_LOG(ERROR) << "Failed to start Flutter engine: error " << result; return false; } @@ -454,7 +454,7 @@ bool FlutterWindowsEngine::SendPlatformMessage( embedder_api_.PlatformMessageCreateResponseHandle( engine_, reply, user_data, &response_handle); if (result != kSuccess) { - std::cout << "Failed to create response handle\n"; + FML_LOG(ERROR) << "Failed to create response handle"; return false; } } @@ -486,9 +486,9 @@ void FlutterWindowsEngine::SendPlatformMessageResponse( void FlutterWindowsEngine::HandlePlatformMessage( const FlutterPlatformMessage* engine_message) { if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) { - std::cerr << "Invalid message size received. Expected: " - << sizeof(FlutterPlatformMessage) << " but received " - << engine_message->struct_size << std::endl; + FML_LOG(ERROR) << "Invalid message size received. Expected: " + << sizeof(FlutterPlatformMessage) << " but received " + << engine_message->struct_size; return; } diff --git a/shell/platform/windows/flutter_windows_texture_registrar.cc b/shell/platform/windows/flutter_windows_texture_registrar.cc index 9e3b3bd0f77a5..0abc73b75afe3 100644 --- a/shell/platform/windows/flutter_windows_texture_registrar.cc +++ b/shell/platform/windows/flutter_windows_texture_registrar.cc @@ -4,9 +4,9 @@ #include "flutter/shell/platform/windows/flutter_windows_texture_registrar.h" -#include #include +#include "flutter/fml/logging.h" #include "flutter/shell/platform/embedder/embedder_struct_macros.h" #include "flutter/shell/platform/windows/external_texture_d3d.h" #include "flutter/shell/platform/windows/external_texture_pixelbuffer.h" @@ -31,7 +31,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture( if (texture_info->type == kFlutterDesktopPixelBufferTexture) { if (!texture_info->pixel_buffer_config.callback) { - std::cerr << "Invalid pixel buffer texture callback." << std::endl; + FML_LOG(ERROR) << "Invalid pixel buffer texture callback."; return kInvalidTexture; } @@ -47,7 +47,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture( surface_type == kFlutterDesktopGpuSurfaceTypeD3d11Texture2D) { auto callback = SAFE_ACCESS(gpu_surface_config, callback, nullptr); if (!callback) { - std::cerr << "Invalid GPU surface descriptor callback." << std::endl; + FML_LOG(ERROR) << "Invalid GPU surface descriptor callback."; return kInvalidTexture; } @@ -58,7 +58,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture( } } - std::cerr << "Attempted to register texture of unsupport type." << std::endl; + FML_LOG(ERROR) << "Attempted to register texture of unsupport type."; return kInvalidTexture; } diff --git a/shell/platform/windows/keyboard_key_channel_handler.cc b/shell/platform/windows/keyboard_key_channel_handler.cc index 0359903b9e07f..94041cdb15d1f 100644 --- a/shell/platform/windows/keyboard_key_channel_handler.cc +++ b/shell/platform/windows/keyboard_key_channel_handler.cc @@ -6,8 +6,7 @@ #include -#include - +#include "flutter/fml/logging.h" #include "flutter/shell/platform/common/json_message_codec.h" #include "flutter/shell/platform/windows/keyboard_utils.h" @@ -139,7 +138,7 @@ void KeyboardKeyChannelHandler::KeyboardHook( event.AddMember(kTypeKey, kKeyUp, allocator); break; default: - std::cerr << "Unknown key event action: " << action << std::endl; + FML_LOG(WARNING) << "Unknown key event action: " << action; callback(false); return; } diff --git a/shell/platform/windows/keyboard_key_handler.cc b/shell/platform/windows/keyboard_key_handler.cc index d31aee1c28d7f..718c6f2afbcca 100644 --- a/shell/platform/windows/keyboard_key_handler.cc +++ b/shell/platform/windows/keyboard_key_handler.cc @@ -6,8 +6,7 @@ #include -#include - +#include "flutter/fml/logging.h" #include "flutter/shell/platform/windows/keyboard_utils.h" namespace flutter { @@ -48,10 +47,10 @@ void KeyboardKeyHandler::KeyboardHook(int key, incoming->callback = std::move(callback); if (pending_responds_.size() > kMaxPendingEvents) { - std::cerr + FML_LOG(ERROR) << "There are " << pending_responds_.size() << " keyboard events that have not yet received a response from the " - << "framework. Are responses being sent?" << std::endl; + << "framework. Are responses being sent?"; } pending_responds_.push_back(std::move(incoming)); diff --git a/shell/platform/windows/keyboard_manager.cc b/shell/platform/windows/keyboard_manager.cc index 5bd25a636699f..d8891a5a9c996 100644 --- a/shell/platform/windows/keyboard_manager.cc +++ b/shell/platform/windows/keyboard_manager.cc @@ -3,10 +3,10 @@ // found in the LICENSE file. #include -#include #include #include +#include "flutter/fml/logging.h" #include "flutter/shell/platform/windows/keyboard_manager.h" #include "flutter/shell/platform/windows/keyboard_utils.h" @@ -120,15 +120,14 @@ void KeyboardManager::RedispatchEvent(std::unique_ptr event) { UINT result = window_delegate_->Win32DispatchMessage( message.action, message.wparam, message.lparam); if (result != 0) { - std::cerr << "Unable to synthesize event for keyboard event." - << std::endl; + FML_LOG(ERROR) << "Unable to synthesize event for keyboard event."; } } if (pending_redispatches_.size() > kMaxPendingEvents) { - std::cerr + FML_LOG(ERROR) << "There are " << pending_redispatches_.size() << " keyboard events that have not yet received a response from the " - << "framework. Are responses being sent?" << std::endl; + << "framework. Are responses being sent?"; } } diff --git a/shell/platform/windows/platform_handler.cc b/shell/platform/windows/platform_handler.cc index d1ab70090ed5b..c73677da1b1f8 100644 --- a/shell/platform/windows/platform_handler.cc +++ b/shell/platform/windows/platform_handler.cc @@ -7,9 +7,9 @@ #include #include -#include #include +#include "flutter/fml/logging.h" #include "flutter/fml/platform/win/wstring_conversion.h" #include "flutter/shell/platform/common/json_method_codec.h" #include "flutter/shell/platform/windows/flutter_windows_view.h" @@ -41,14 +41,16 @@ class ScopedGlobalMemory { ScopedGlobalMemory(unsigned int flags, size_t bytes) { memory_ = ::GlobalAlloc(flags, bytes); if (!memory_) { - std::cerr << "Unable to allocate global memory: " << ::GetLastError(); + FML_LOG(ERROR) << "Unable to allocate global memory: " + << ::GetLastError(); } } ~ScopedGlobalMemory() { if (memory_) { if (::GlobalFree(memory_) != nullptr) { - std::cerr << "Failed to free global allocation: " << ::GetLastError(); + FML_LOG(ERROR) << "Failed to free global allocation: " + << ::GetLastError(); } } } @@ -79,7 +81,7 @@ class ScopedGlobalLock { if (memory) { locked_memory_ = ::GlobalLock(memory); if (!locked_memory_) { - std::cerr << "Unable to acquire global lock: " << ::GetLastError(); + FML_LOG(ERROR) << "Unable to acquire global lock: " << ::GetLastError(); } } } @@ -89,7 +91,8 @@ class ScopedGlobalLock { if (!::GlobalUnlock(source_)) { DWORD error = ::GetLastError(); if (error != NO_ERROR) { - std::cerr << "Unable to release global lock: " << ::GetLastError(); + FML_LOG(ERROR) << "Unable to release global lock: " + << ::GetLastError(); } } } diff --git a/shell/platform/windows/task_runner_window.cc b/shell/platform/windows/task_runner_window.cc index ccdf4b570ac13..5aa21da9dc67b 100644 --- a/shell/platform/windows/task_runner_window.cc +++ b/shell/platform/windows/task_runner_window.cc @@ -5,7 +5,8 @@ #include "flutter/shell/platform/windows/task_runner_window.h" #include -#include + +#include "flutter/fml/logging.h" namespace flutter { @@ -52,7 +53,7 @@ std::shared_ptr TaskRunnerWindow::GetSharedInstance() { void TaskRunnerWindow::WakeUp() { if (!PostMessage(window_handle_, WM_NULL, 0, 0)) { - std::cerr << "Failed to post message to main thread." << std::endl; + FML_LOG(ERROR) << "Failed to post message to main thread."; } }