From b2e75e4be36dc65fa8adabd33b2a1d4f27707a1c Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 2 Sep 2022 21:46:30 +0900 Subject: [PATCH] Merge the latest cpp template from flutter-embedded-linux repo (#131) Signed-off-by: Hidenori Matsubayashi --- templates/app/runner/command_options.h | 17 ++++++++++++++--- templates/app/runner/flutter_embedder_options.h | 17 ++++++++++++++++- templates/app/runner/main.cc | 4 +++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/templates/app/runner/command_options.h b/templates/app/runner/command_options.h index 107a152..b0de931 100644 --- a/templates/app/runner/command_options.h +++ b/templates/app/runner/command_options.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,8 +13,6 @@ #include #include -// todo: Supports other types besides int, string. - namespace commandline { namespace { @@ -56,6 +54,15 @@ class CommandOptions { ReaderInt(), required, true); } + void AddDouble(const std::string& name, + const std::string& short_name, + const std::string& description, + const double& default_value, + bool required) { + Add(name, short_name, description, default_value, + ReaderDouble(), required, true); + } + void AddString(const std::string& name, const std::string& short_name, const std::string& description, @@ -250,6 +257,10 @@ class CommandOptions { std::string operator()(const std::string& value) { return value; } }; + struct ReaderDouble { + double operator()(const std::string& value) { return std::stod(value); } + }; + class Option { public: Option(const std::string& name, diff --git a/templates/app/runner/flutter_embedder_options.h b/templates/app/runner/flutter_embedder_options.h index 4c22913..fbb8190 100644 --- a/templates/app/runner/flutter_embedder_options.h +++ b/templates/app/runner/flutter_embedder_options.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -21,6 +21,9 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("force-scale-factor", "s", + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -72,6 +75,14 @@ class FlutterEmbedderOptions { } } + if (options_.Exist("force-scale-factor")) { + is_force_scale_factor_ = true; + scale_factor_ = options_.GetValue("force-scale-factor"); + } else { + is_force_scale_factor_ = false; + scale_factor_ = 1.0; + } + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -112,6 +123,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + bool IsForceScaleFactor() const { return is_force_scale_factor_; } + double ScaleFactor() const { return scale_factor_; } private: commandline::CommandOptions options_; @@ -126,6 +139,8 @@ class FlutterEmbedderOptions { int window_height_ = 720; flutter::FlutterViewController::ViewRotation window_view_rotation_ = flutter::FlutterViewController::ViewRotation::kRotation_0; + bool is_force_scale_factor_; + double scale_factor_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/templates/app/runner/main.cc b/templates/app/runner/main.cc index fa4e11b..dd3e12d 100644 --- a/templates/app/runner/main.cc +++ b/templates/app/runner/main.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -33,6 +33,8 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.force_scale_factor = options.IsForceScaleFactor(); + view_properties.scale_factor = options.ScaleFactor(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project);