From ec832665dc546fee6d18cba3ec2185bccc7247a2 Mon Sep 17 00:00:00 2001 From: Andrea Daoud Date: Sun, 7 Aug 2022 00:05:33 +0800 Subject: [PATCH 1/3] Add support for setting scale factor from parameters Signed-off-by: Andrea Daoud --- src/client_wrapper/flutter_view_controller.cc | 2 ++ src/client_wrapper/include/flutter/flutter_view_controller.h | 4 ++++ .../shell/platform/linux_embedded/public/flutter_elinux.h | 4 ++++ .../shell/platform/linux_embedded/window/elinux_window_drm.h | 2 ++ .../platform/linux_embedded/window/elinux_window_wayland.cc | 5 ++++- .../platform/linux_embedded/window/elinux_window_x11.cc | 2 ++ 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index 4dbd58a4..28996256 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -34,6 +34,8 @@ FlutterViewController::FlutterViewController( view_properties.use_onscreen_keyboard; c_view_properties.use_window_decoration = view_properties.use_window_decoration; + c_view_properties.force_scale_factor = view_properties.force_scale_factor; + c_view_properties.scale_factor = view_properties.scale_factor; controller_ = FlutterDesktopViewControllerCreate(c_view_properties, engine_->RelinquishEngine()); diff --git a/src/client_wrapper/include/flutter/flutter_view_controller.h b/src/client_wrapper/include/flutter/flutter_view_controller.h index a5762e47..b27506ea 100644 --- a/src/client_wrapper/include/flutter/flutter_view_controller.h +++ b/src/client_wrapper/include/flutter/flutter_view_controller.h @@ -67,6 +67,10 @@ class FlutterViewController { // Uses the window decoration such as toolbar and max/min buttons. // This option is only active for Wayland backend. bool use_window_decoration; + + // Force scale factor specified by command line argument + bool force_scale_factor; + double scale_factor; } ViewProperties; // Creates a FlutterView that can be parented into a Windows View hierarchy diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index 913c1fac..a8b0b5d8 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -98,6 +98,10 @@ typedef struct { // Uses the window decoration such as toolbar and max/min buttons. // This option is only active for Wayland backend. bool use_window_decoration; + + // Force scale factor specified by command line argument + bool force_scale_factor; + double scale_factor; } FlutterDesktopViewProperties; // ========== View Controller ========== diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index 55e29854..0c6f9ea8 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -34,6 +34,8 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { ELinuxWindowDrm(FlutterDesktopViewProperties view_properties) : display_valid_(false), is_pending_cursor_add_event_(false) { view_properties_ = view_properties; + current_scale_ = + view_properties.force_scale_factor ? view_properties.scale_factor : 1.0; SetRotation(view_properties_.view_rotation); auto udev = udev_new(); diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 31c9fac3..282128ca 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -565,7 +565,8 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { .scale = [](void* data, wl_output* wl_output, int32_t scale) -> void { auto self = reinterpret_cast(data); ELINUX_LOG(INFO) << "Display output scale: " << scale; - self->current_scale_ = scale; + if (!self->view_properties_.force_scale_factor) + self->current_scale_ = scale; }, }; @@ -829,6 +830,8 @@ ELinuxWindowWayland::ELinuxWindowWayland( frame_rate_(60000), window_decorations_(nullptr) { view_properties_ = view_properties; + current_scale_ = + view_properties.force_scale_factor ? view_properties.scale_factor : 1.0; SetRotation(view_properties_.view_rotation); wl_display_ = wl_display_connect(nullptr); diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc index 792fa76a..03a52c87 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc @@ -23,6 +23,8 @@ constexpr int kButton9 = 9; ELinuxWindowX11::ELinuxWindowX11(FlutterDesktopViewProperties view_properties) { view_properties_ = view_properties; + current_scale_ = + view_properties.force_scale_factor ? view_properties.scale_factor : 1.0; SetRotation(view_properties_.view_rotation); display_ = XOpenDisplay(NULL); From 379103cbbca447a0f7d57883f7ba27c3cb45359b Mon Sep 17 00:00:00 2001 From: Andrea Daoud Date: Sun, 7 Aug 2022 00:07:06 +0800 Subject: [PATCH 2/3] Add force scale factor support to command line arguments Signed-off-by: Andrea Daoud --- .../command_options.h | 13 +++++++++++++ .../flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-drm-eglstream-backend/main.cc | 2 ++ .../flutter-drm-gbm-backend/command_options.h | 13 +++++++++++++ .../flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-drm-gbm-backend/main.cc | 2 ++ .../command_options.h | 13 +++++++++++++ .../flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-external-texture-plugin/main.cc | 2 ++ .../flutter-video-player-plugin/command_options.h | 13 +++++++++++++ .../flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-video-player-plugin/main.cc | 2 ++ examples/flutter-wayland-client/command_options.h | 13 +++++++++++++ .../flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-wayland-client/main.cc | 2 ++ examples/flutter-x11-client/command_options.h | 13 +++++++++++++ .../flutter-x11-client/flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-x11-client/main.cc | 2 ++ 18 files changed, 180 insertions(+) diff --git a/examples/flutter-drm-eglstream-backend/command_options.h b/examples/flutter-drm-eglstream-backend/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-drm-eglstream-backend/command_options.h +++ b/examples/flutter-drm-eglstream-backend/command_options.h @@ -56,6 +56,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 +259,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/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h @@ -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/examples/flutter-drm-eglstream-backend/main.cc b/examples/flutter-drm-eglstream-backend/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-drm-eglstream-backend/main.cc +++ b/examples/flutter-drm-eglstream-backend/main.cc @@ -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); diff --git a/examples/flutter-drm-gbm-backend/command_options.h b/examples/flutter-drm-gbm-backend/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-drm-gbm-backend/command_options.h +++ b/examples/flutter-drm-gbm-backend/command_options.h @@ -56,6 +56,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 +259,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/examples/flutter-drm-gbm-backend/flutter_embedder_options.h b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h @@ -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/examples/flutter-drm-gbm-backend/main.cc b/examples/flutter-drm-gbm-backend/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-drm-gbm-backend/main.cc +++ b/examples/flutter-drm-gbm-backend/main.cc @@ -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); diff --git a/examples/flutter-external-texture-plugin/command_options.h b/examples/flutter-external-texture-plugin/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-external-texture-plugin/command_options.h +++ b/examples/flutter-external-texture-plugin/command_options.h @@ -56,6 +56,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 +259,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/examples/flutter-external-texture-plugin/flutter_embedder_options.h b/examples/flutter-external-texture-plugin/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-external-texture-plugin/flutter_embedder_options.h +++ b/examples/flutter-external-texture-plugin/flutter_embedder_options.h @@ -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/examples/flutter-external-texture-plugin/main.cc b/examples/flutter-external-texture-plugin/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-external-texture-plugin/main.cc +++ b/examples/flutter-external-texture-plugin/main.cc @@ -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); diff --git a/examples/flutter-video-player-plugin/command_options.h b/examples/flutter-video-player-plugin/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-video-player-plugin/command_options.h +++ b/examples/flutter-video-player-plugin/command_options.h @@ -56,6 +56,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 +259,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/examples/flutter-video-player-plugin/flutter_embedder_options.h b/examples/flutter-video-player-plugin/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-video-player-plugin/flutter_embedder_options.h +++ b/examples/flutter-video-player-plugin/flutter_embedder_options.h @@ -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/examples/flutter-video-player-plugin/main.cc b/examples/flutter-video-player-plugin/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-video-player-plugin/main.cc +++ b/examples/flutter-video-player-plugin/main.cc @@ -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); diff --git a/examples/flutter-wayland-client/command_options.h b/examples/flutter-wayland-client/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-wayland-client/command_options.h +++ b/examples/flutter-wayland-client/command_options.h @@ -56,6 +56,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 +259,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/examples/flutter-wayland-client/flutter_embedder_options.h b/examples/flutter-wayland-client/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-wayland-client/flutter_embedder_options.h +++ b/examples/flutter-wayland-client/flutter_embedder_options.h @@ -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/examples/flutter-wayland-client/main.cc b/examples/flutter-wayland-client/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-wayland-client/main.cc +++ b/examples/flutter-wayland-client/main.cc @@ -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); diff --git a/examples/flutter-x11-client/command_options.h b/examples/flutter-x11-client/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-x11-client/command_options.h +++ b/examples/flutter-x11-client/command_options.h @@ -56,6 +56,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 +259,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/examples/flutter-x11-client/flutter_embedder_options.h b/examples/flutter-x11-client/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-x11-client/flutter_embedder_options.h +++ b/examples/flutter-x11-client/flutter_embedder_options.h @@ -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/examples/flutter-x11-client/main.cc b/examples/flutter-x11-client/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-x11-client/main.cc +++ b/examples/flutter-x11-client/main.cc @@ -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); From 43fa2bd983487d5b2d8a83b1a940d6e9320aeb3a Mon Sep 17 00:00:00 2001 From: Andrea Daoud Date: Sun, 7 Aug 2022 00:07:31 +0800 Subject: [PATCH 3/3] Add myself to AUTHORS Signed-off-by: Andrea Daoud --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 649f420b..8244baf0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,3 +6,4 @@ Sony Group Corporation Hidenori Matsubayashi (hidenori.matsubayashi@gmail.com) +Andrea Daoud (andreadaoud6@gmail.com)