diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index 5282965dc5..36eb78cdca 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -1083,6 +1083,8 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/compositor_context.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_fakes.h +FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc +FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_intl.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_intl.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/fuchsia_intl_unittest.cc diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn b/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn index 4952d6f81b..9412b26133 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn @@ -272,6 +272,8 @@ executable("flutter_runner_unittests") { "accessibility_bridge.h", "accessibility_bridge_unittest.cc", "flutter_runner_fakes.h", + "flutter_runner_product_configuration.cc", + "flutter_runner_product_configuration.h", "fuchsia_intl.cc", "fuchsia_intl.h", "fuchsia_intl_unittest.cc", @@ -290,6 +292,7 @@ executable("flutter_runner_unittests") { "task_observers.h", "task_runner_adapter.cc", "task_runner_adapter.h", + "tests/flutter_runner_product_configuration_unittests.cc", "tests/vsync_recorder_unittests.cc", "thread.cc", "thread.h", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/component.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/component.cc index e0d58f3e80..f10f5b6821 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/component.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/component.cc @@ -35,6 +35,7 @@ #include "runtime/dart/utils/tempfs.h" #include "runtime/dart/utils/vmo.h" +#include "flutter_runner_product_configuration.h" #include "task_observers.h" #include "task_runner_adapter.h" #include "thread.h" @@ -314,6 +315,13 @@ Application::Application( } } + // Load and use product-specific configuration, if it exists. + std::string json_string; + if (dart_utils::ReadFileToString( + "/config/data/frame_scheduling_performance_values", &json_string)) { + product_config_ = FlutterRunnerProductConfiguration(json_string); + } + #if defined(DART_PRODUCT) settings_.enable_observatory = false; #else @@ -609,7 +617,8 @@ void Application::CreateView( std::move(isolate_snapshot_), // isolate snapshot scenic::ToViewToken(std::move(view_token)), // view token std::move(fdio_ns_), // FDIO namespace - std::move(directory_request_) // outgoing request + std::move(directory_request_), // outgoing request + product_config_ // product configuration )); } diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/component.h b/engine/src/flutter/shell/platform/fuchsia/flutter/component.h index b852d3dd6b..af657feeb1 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/component.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/component.h @@ -25,6 +25,7 @@ #include "flutter/common/settings.h" #include "flutter/fml/macros.h" +#include "flutter_runner_product_configuration.h" #include "thread.h" #include "unique_fdio_ns.h" @@ -77,6 +78,7 @@ class Application final : public Engine::Delegate, private: flutter::Settings settings_; + FlutterRunnerProductConfiguration product_config_; TerminationCallback termination_callback_; const std::string debug_label_; UniqueFDIONS fdio_ns_ = UniqueFDIONSCreate(); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/engine.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/engine.cc index 66f4c40303..f51823f9ac 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/engine.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/engine.cc @@ -16,6 +16,7 @@ #include "flutter/runtime/dart_vm_lifecycle.h" #include "flutter/shell/common/rasterizer.h" #include "flutter/shell/common/run_configuration.h" +#include "flutter_runner_product_configuration.h" #include "fuchsia_intl.h" #include "platform_view.h" #include "runtime/dart/utils/files.h" @@ -57,7 +58,8 @@ Engine::Engine(Delegate& delegate, fml::RefPtr isolate_snapshot, fuchsia::ui::views::ViewToken view_token, UniqueFDIONS fdio_ns, - fidl::InterfaceRequest directory_request) + fidl::InterfaceRequest directory_request, + FlutterRunnerProductConfiguration product_config) : delegate_(delegate), thread_label_(std::move(thread_label)), settings_(std::move(settings)), @@ -137,7 +139,8 @@ Engine::Engine(Delegate& delegate, std::move(on_session_size_change_hint_callback), on_enable_wireframe_callback = std::move(on_enable_wireframe_callback), - vsync_handle = vsync_event_.get()](flutter::Shell& shell) mutable { + vsync_handle = vsync_event_.get(), + product_config = product_config](flutter::Shell& shell) mutable { return std::make_unique( shell, // delegate debug_label, // debug label @@ -150,8 +153,8 @@ Engine::Engine(Delegate& delegate, std::move(on_session_metrics_change_callback), std::move(on_session_size_change_hint_callback), std::move(on_enable_wireframe_callback), - vsync_handle // vsync handle - ); + vsync_handle, // vsync handle + product_config); }); // Session can be terminated on the raster thread, but we must terminate @@ -199,8 +202,7 @@ Engine::Engine(Delegate& delegate, std::move(view_ref_pair), // scenic view ref/view ref control std::move(session), // scenic session on_session_error_callback, // session did encounter error - vsync_event // vsync event handle - ); + vsync_event); // vsync event handle } return std::make_unique( diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/engine.h b/engine/src/flutter/shell/platform/fuchsia/flutter/engine.h index 2c3cc990c0..7d211d5f3f 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/engine.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/engine.h @@ -15,6 +15,7 @@ #include "flutter/fml/macros.h" #include "flutter/shell/common/shell.h" +#include "flutter_runner_product_configuration.h" #include "isolate_configurator.h" #include "thread.h" @@ -37,7 +38,8 @@ class Engine final { fml::RefPtr isolate_snapshot, fuchsia::ui::views::ViewToken view_token, UniqueFDIONS fdio_ns, - fidl::InterfaceRequest directory_request); + fidl::InterfaceRequest directory_request, + FlutterRunnerProductConfiguration product_config); ~Engine(); // Returns the Dart return code for the root isolate if one is present. This diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/engine_flutter_runner.gni b/engine/src/flutter/shell/platform/fuchsia/flutter/engine_flutter_runner.gni index 818cea4eb6..332ffaec0e 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/engine_flutter_runner.gni +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/engine_flutter_runner.gni @@ -50,6 +50,8 @@ template("flutter_runner") { "compositor_context.h", "engine.cc", "engine.h", + "flutter_runner_product_configuration.cc", + "flutter_runner_product_configuration.h", "fuchsia_intl.cc", "fuchsia_intl.h", "isolate_configurator.cc", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc new file mode 100644 index 0000000000..af7af50497 --- /dev/null +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc @@ -0,0 +1,25 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter_runner_product_configuration.h" + +#include "rapidjson/document.h" + +namespace flutter_runner { + +FlutterRunnerProductConfiguration::FlutterRunnerProductConfiguration( + std::string json_string) { + rapidjson::Document document; + document.Parse(json_string); + + if (!document.IsObject()) + return; + + // Parse out all values we're expecting. + if (auto& val = document["vsync_offset_in_us"]; val.IsInt()) { + vsync_offset_ = fml::TimeDelta::FromMicroseconds(val.GetInt()); + } +} + +} // namespace flutter_runner diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h b/engine/src/flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h new file mode 100644 index 0000000000..29958f557e --- /dev/null +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h @@ -0,0 +1,23 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_RUNNER_PRODUCT_CONFIGURATION_H_ +#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_RUNNER_PRODUCT_CONFIGURATION_H_ +#include "flutter/fml/time/time_delta.h" + +namespace flutter_runner { + +class FlutterRunnerProductConfiguration { + public: + FlutterRunnerProductConfiguration() {} + FlutterRunnerProductConfiguration(std::string path); + + fml::TimeDelta get_vsync_offset() { return vsync_offset_; } + + private: + fml::TimeDelta vsync_offset_ = fml::TimeDelta::Zero(); +}; + +} // namespace flutter_runner +#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_RUNNER_PRODUCT_CONFIGURATION_H_ diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.cc index d991c898f4..509575fdf6 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.cc @@ -12,6 +12,7 @@ #include "flutter/lib/ui/compositing/scene_host.h" #include "flutter/lib/ui/window/pointer_data.h" #include "flutter/lib/ui/window/window.h" +#include "flutter_runner_product_configuration.h" #include "logging.h" #include "rapidjson/document.h" #include "rapidjson/stringbuffer.h" @@ -91,7 +92,8 @@ PlatformView::PlatformView( OnMetricsUpdate session_metrics_did_change_callback, OnSizeChangeHint session_size_change_hint_callback, OnEnableWireframe wireframe_enabled_callback, - zx_handle_t vsync_event_handle) + zx_handle_t vsync_event_handle, + FlutterRunnerProductConfiguration product_config) : flutter::PlatformView(delegate, std::move(task_runners)), debug_label_(std::move(debug_label)), view_ref_(std::move(view_ref)), @@ -103,7 +105,8 @@ PlatformView::PlatformView( wireframe_enabled_callback_(std::move(wireframe_enabled_callback)), ime_client_(this), surface_(std::make_unique(debug_label_)), - vsync_event_handle_(vsync_event_handle) { + vsync_event_handle_(vsync_event_handle), + product_config_(product_config) { // Register all error handlers. SetInterfaceErrorHandler(session_listener_binding_, "SessionListener"); SetInterfaceErrorHandler(ime_, "Input Method Editor"); @@ -561,7 +564,8 @@ void PlatformView::DeactivateIme() { // |flutter::PlatformView| std::unique_ptr PlatformView::CreateVSyncWaiter() { return std::make_unique( - debug_label_, vsync_event_handle_, task_runners_); + debug_label_, vsync_event_handle_, task_runners_, + product_config_.get_vsync_offset()); } // |flutter::PlatformView| diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.h b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.h index 1d13d4f660..bd103275d3 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.h @@ -20,6 +20,7 @@ #include "lib/fidl/cpp/binding.h" #include "lib/ui/scenic/cpp/id.h" +#include "flutter_runner_product_configuration.h" #include "surface.h" namespace flutter_runner { @@ -53,7 +54,8 @@ class PlatformView final : public flutter::PlatformView, OnMetricsUpdate session_metrics_did_change_callback, OnSizeChangeHint session_size_change_hint_callback, OnEnableWireframe wireframe_enabled_callback, - zx_handle_t vsync_event_handle); + zx_handle_t vsync_event_handle, + FlutterRunnerProductConfiguration product_config); PlatformView(flutter::PlatformView::Delegate& delegate, std::string debug_label, flutter::TaskRunners task_runners, @@ -115,6 +117,8 @@ class PlatformView final : public flutter::PlatformView, std::set unregistered_channels_; zx_handle_t vsync_event_handle_ = 0; + FlutterRunnerProductConfiguration product_config_; + void RegisterPlatformMessageHandlers(); void FlushViewportMetrics(); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc index 11d563dfca..077a8996f9 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc @@ -110,7 +110,8 @@ TEST_F(PlatformViewTests, ChangesAccessibilitySettings) { nullptr, // session_metrics_did_change_callback nullptr, // session_size_change_hint_callback nullptr, // on_enable_wireframe_callback, - 0u // vsync_event_handle + 0u, // vsync_event_handle + {} // product_config ); RunLoopUntilIdle(); @@ -162,7 +163,8 @@ TEST_F(PlatformViewTests, EnableWireframeTest) { nullptr, // session_metrics_did_change_callback nullptr, // session_size_change_hint_callback EnableWireframeCallback, // on_enable_wireframe_callback, - 0u // vsync_event_handle + 0u, // vsync_event_handle + {} // product_config ); // Cast platform_view to its base view so we can have access to the public diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/flutter_runner_product_configuration_unittests.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/flutter_runner_product_configuration_unittests.cc new file mode 100644 index 0000000000..589228d4ab --- /dev/null +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/flutter_runner_product_configuration_unittests.cc @@ -0,0 +1,71 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include + +#include "flutter/fml/time/time_delta.h" +#include "flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h" + +using namespace flutter_runner; + +namespace flutter_runner_test { + +class FlutterRunnerProductConfigurationTest : public testing::Test {}; + +TEST_F(FlutterRunnerProductConfigurationTest, ValidVsyncOffset) { + const std::string json_string = "{ \"vsync_offset_in_us\" : 9000 } "; + const fml::TimeDelta expected_offset = fml::TimeDelta::FromMicroseconds(9000); + + FlutterRunnerProductConfiguration product_config = + FlutterRunnerProductConfiguration(json_string); + EXPECT_EQ(product_config.get_vsync_offset(), expected_offset); +} + +TEST_F(FlutterRunnerProductConfigurationTest, InvalidJsonString) { + const std::string json_string = "{ \"invalid json string\" }}} "; + const fml::TimeDelta expected_offset = fml::TimeDelta::FromMicroseconds(0); + + FlutterRunnerProductConfiguration product_config = + FlutterRunnerProductConfiguration(json_string); + EXPECT_EQ(product_config.get_vsync_offset(), expected_offset); +} + +TEST_F(FlutterRunnerProductConfigurationTest, EmptyJsonString) { + const std::string json_string = ""; + const fml::TimeDelta expected_offset = fml::TimeDelta::FromMicroseconds(0); + + FlutterRunnerProductConfiguration product_config = + FlutterRunnerProductConfiguration(json_string); + EXPECT_EQ(product_config.get_vsync_offset(), expected_offset); +} + +TEST_F(FlutterRunnerProductConfigurationTest, EmptyVsyncOffset) { + const std::string json_string = "{ \"vsync_offset_in_us\" : } "; + const fml::TimeDelta expected_offset = fml::TimeDelta::FromMicroseconds(0); + + FlutterRunnerProductConfiguration product_config = + FlutterRunnerProductConfiguration(json_string); + EXPECT_EQ(product_config.get_vsync_offset(), expected_offset); +} + +TEST_F(FlutterRunnerProductConfigurationTest, NegativeVsyncOffset) { + const std::string json_string = "{ \"vsync_offset_in_us\" : -15410 } "; + const fml::TimeDelta expected_offset = + fml::TimeDelta::FromMicroseconds(-15410); + + FlutterRunnerProductConfiguration product_config = + FlutterRunnerProductConfiguration(json_string); + EXPECT_EQ(product_config.get_vsync_offset(), expected_offset); +} + +TEST_F(FlutterRunnerProductConfigurationTest, NonIntegerVsyncOffset) { + const std::string json_string = "{ \"vsync_offset_in_us\" : 3.14159 } "; + const fml::TimeDelta expected_offset = fml::TimeDelta::FromMicroseconds(0); + + FlutterRunnerProductConfiguration product_config = + FlutterRunnerProductConfiguration(json_string); + EXPECT_EQ(product_config.get_vsync_offset(), expected_offset); +} + +} // namespace flutter_runner_test diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter.cc index 6d2be8d0a0..2ce7705118 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter.cc @@ -14,16 +14,19 @@ #include "flutter/fml/time/time_delta.h" #include "flutter/fml/trace_event.h" +#include "flutter_runner_product_configuration.h" #include "vsync_recorder.h" namespace flutter_runner { VsyncWaiter::VsyncWaiter(std::string debug_label, zx_handle_t session_present_handle, - flutter::TaskRunners task_runners) + flutter::TaskRunners task_runners, + fml::TimeDelta vsync_offset) : flutter::VsyncWaiter(task_runners), debug_label_(std::move(debug_label)), session_wait_(session_present_handle, SessionPresentSignal), + vsync_offset_(vsync_offset), weak_factory_(this), weak_factory_ui_(nullptr) { auto wait_handler = [&](async_dispatcher_t* dispatcher, // @@ -50,6 +53,14 @@ VsyncWaiter::VsyncWaiter(std::string debug_label, std::make_unique>(this); })); session_wait_.set_handler(wait_handler); + + if (vsync_offset_ >= fml::TimeDelta::FromSeconds(1)) { + FML_LOG(WARNING) << "Given vsync_offset is extremely high: " + << vsync_offset_.ToMilliseconds() << "ms"; + } else { + FML_LOG(INFO) << "Set vsync_offset to " << vsync_offset_.ToMicroseconds() + << "us"; + } } VsyncWaiter::~VsyncWaiter() { @@ -132,7 +143,7 @@ void VsyncWaiter::AwaitVSync() { fml::TimePoint next_vsync = SnapToNextPhase(now, last_presentation_time, vsync_info.presentation_interval); - auto next_vsync_start_time = next_vsync - vsync_offset; + auto next_vsync_start_time = next_vsync - vsync_offset_; if (now >= next_vsync_start_time) next_vsync_start_time = diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter.h b/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter.h index 577a645ac4..199d3611d5 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter.h @@ -9,8 +9,10 @@ #include "flutter/fml/macros.h" #include "flutter/fml/memory/weak_ptr.h" +#include "flutter/fml/time/time_delta.h" #include "flutter/fml/time/time_point.h" #include "flutter/shell/common/vsync_waiter.h" +#include "flutter_runner_product_configuration.h" namespace flutter_runner { @@ -18,24 +20,24 @@ class VsyncWaiter final : public flutter::VsyncWaiter { public: static constexpr zx_signals_t SessionPresentSignal = ZX_EVENT_SIGNALED; + VsyncWaiter(std::string debug_label, + zx_handle_t session_present_handle, + flutter::TaskRunners task_runners, + fml::TimeDelta vsync_offset); + + ~VsyncWaiter() override; + static fml::TimePoint SnapToNextPhase( const fml::TimePoint now, const fml::TimePoint last_frame_presentation_time, const fml::TimeDelta presentation_interval); - VsyncWaiter(std::string debug_label, - zx_handle_t session_present_handle, - flutter::TaskRunners task_runners); - - ~VsyncWaiter() override; - private: const std::string debug_label_; async::Wait session_wait_; - fml::WeakPtrFactory weak_factory_; + fml::TimeDelta vsync_offset_ = fml::TimeDelta::FromMicroseconds(0); - static constexpr fml::TimeDelta vsync_offset = - fml::TimeDelta::FromNanoseconds(0); + fml::WeakPtrFactory weak_factory_; // For accessing the VsyncWaiter via the UI thread, necessary for the callback // for AwaitVSync() diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter_unittests.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter_unittests.cc index 83e71d64c6..fd7ef08b32 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter_unittests.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vsync_waiter_unittests.cc @@ -14,6 +14,7 @@ #include "flutter/fml/time/time_point.h" #include "flutter/shell/common/thread_host.h" #include "flutter/shell/common/vsync_waiter.h" +#include "flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h" #include "flutter/shell/platform/fuchsia/flutter/task_runner_adapter.h" #include "flutter/shell/platform/fuchsia/flutter/thread.h" #include "flutter/shell/platform/fuchsia/flutter/vsync_waiter.h" @@ -29,7 +30,8 @@ class VsyncWaiterTest : public testing::Test { std::unique_ptr CreateVsyncWaiter( flutter::TaskRunners task_runners) { return std::make_unique( - "VsyncWaiterTest", vsync_event_.get(), task_runners); + "VsyncWaiterTest", vsync_event_.get(), task_runners, + fml::TimeDelta::Zero()); } void SignalVsyncEvent() {