From 8772365537ee35af5813bd726640ef932dc5731c Mon Sep 17 00:00:00 2001 From: Felipe Archondo Date: Tue, 13 Oct 2020 22:11:24 -0400 Subject: [PATCH] [fuchsia] add intercept_all_input flag support (#21821) [fuchsia] add intercept_all_input flag support This change also fixes an issue where FlutterRunnerProductConfiguration crashes when a field is missing, when building with --unopt. Test: Added unit tests Bug: fxb/61466, fxb/61942 --- .../flutter_runner_product_configuration.cc | 24 ++++++++++++++----- .../flutter_runner_product_configuration.h | 2 ++ ..._runner_product_configuration_unittests.cc | 22 +++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc b/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc index c4f91e319..bc2a49cf1 100644 --- a/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc +++ b/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "flutter_runner_product_configuration.h" +#include #include "rapidjson/document.h" @@ -17,15 +18,26 @@ FlutterRunnerProductConfiguration::FlutterRunnerProductConfiguration( 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()); + if (document.HasMember("vsync_offset_in_us")) { + auto& val = document["vsync_offset_in_us"]; + if (val.IsInt()) + vsync_offset_ = fml::TimeDelta::FromMicroseconds(val.GetInt()); } - if (auto& val = document["max_frames_in_flight"]; val.IsInt()) { - max_frames_in_flight_ = val.GetInt(); + if (document.HasMember("max_frames_in_flight")) { + auto& val = document["max_frames_in_flight"]; + if (val.IsInt()) + max_frames_in_flight_ = val.GetInt(); + } + if (document.HasMember("intercept_all_input")) { + auto& val = document["intercept_all_input"]; + if (val.IsBool()) + intercept_all_input_ = val.GetBool(); } #if defined(LEGACY_FUCHSIA_EMBEDDER) - if (auto& val = document["use_legacy_renderer"]; val.IsBool()) { - use_legacy_renderer_ = val.GetBool(); + if (document.HasMember("use_legacy_renderer")) { + auto& val = document["use_legacy_renderer"]; + if (val.IsBool()) + use_legacy_renderer_ = val.GetBool(); } #endif } diff --git a/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h b/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h index 355f36504..792f9fe25 100644 --- a/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h +++ b/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h @@ -16,6 +16,7 @@ class FlutterRunnerProductConfiguration { fml::TimeDelta get_vsync_offset() { return vsync_offset_; } uint64_t get_max_frames_in_flight() { return max_frames_in_flight_; } + bool get_intercept_all_input() { return intercept_all_input_; } #if defined(LEGACY_FUCHSIA_EMBEDDER) bool use_legacy_renderer() { return use_legacy_renderer_; } #endif @@ -23,6 +24,7 @@ class FlutterRunnerProductConfiguration { private: fml::TimeDelta vsync_offset_ = fml::TimeDelta::Zero(); uint64_t max_frames_in_flight_ = 3; + bool intercept_all_input_ = false; #if defined(LEGACY_FUCHSIA_EMBEDDER) bool use_legacy_renderer_ = true; #endif diff --git a/shell/platform/fuchsia/flutter/tests/flutter_runner_product_configuration_unittests.cc b/shell/platform/fuchsia/flutter/tests/flutter_runner_product_configuration_unittests.cc index 1cdcd4a0a..2e287dbbd 100644 --- a/shell/platform/fuchsia/flutter/tests/flutter_runner_product_configuration_unittests.cc +++ b/shell/platform/fuchsia/flutter/tests/flutter_runner_product_configuration_unittests.cc @@ -88,4 +88,26 @@ TEST_F(FlutterRunnerProductConfigurationTest, MissingMaxFramesInFlight) { minimum_reasonable_max_frames_in_flight); } +TEST_F(FlutterRunnerProductConfigurationTest, ValidInterceptAllInput) { + const std::string json_string = "{ \"intercept_all_input\" : true } "; + const uint64_t expected_intercept_all_input = true; + + FlutterRunnerProductConfiguration product_config = + FlutterRunnerProductConfiguration(json_string); + + EXPECT_EQ(expected_intercept_all_input, + product_config.get_intercept_all_input()); +} + +TEST_F(FlutterRunnerProductConfigurationTest, MissingInterceptAllInput) { + const std::string json_string = "{ \"intercept_all_input\" : } "; + const uint64_t expected_intercept_all_input = false; + + FlutterRunnerProductConfiguration product_config = + FlutterRunnerProductConfiguration(json_string); + + EXPECT_EQ(expected_intercept_all_input, + product_config.get_intercept_all_input()); +} + } // namespace flutter_runner_test -- GitLab