From acee349b4920adef6a7bbfe5cab73c2a407fa963 Mon Sep 17 00:00:00 2001 From: Arjun Menon Date: Wed, 19 Feb 2025 16:39:24 -0800 Subject: [PATCH 1/4] Implement basic command line switch preprocessor for Cobalt --- cobalt/cobalt.cc | 129 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 100 insertions(+), 29 deletions(-) diff --git a/cobalt/cobalt.cc b/cobalt/cobalt.cc index fb9d22b766c..1e0110505c0 100644 --- a/cobalt/cobalt.cc +++ b/cobalt/cobalt.cc @@ -23,14 +23,23 @@ #include "base/lazy_instance.h" #include "base/logging.h" #include "base/no_destructor.h" +#include "base/switches.h" #include "build/build_config.h" +#include "chrome/common/chrome_switches.h" #include "cobalt/browser/switches.h" #include "cobalt/cobalt_main_delegate.h" #include "cobalt/platform_event_source_starboard.h" #include "content/public/app/content_main.h" #include "content/public/app/content_main_runner.h" +#include "content/public/common/content_switches.h" #include "content/shell/browser/shell.h" +#include "content/shell/common/shell_switches.h" +#include "gpu/config/gpu_switches.h" +#include "media/base/media_switches.h" +#include "sandbox/policy/switches.h" #include "starboard/event.h" +#include "ui/gl/gl_switches.h" +#include "ui/ozone/public/ozone_switches.h" using starboard::PlatformEventSourceStarboard; @@ -45,41 +54,103 @@ content::ContentMainRunner* GetContentMainRunner() { static base::AtExitManager* g_exit_manager = nullptr; static cobalt::CobaltMainDelegate* g_content_main_delegate = nullptr; static PlatformEventSourceStarboard* g_platform_event_source = nullptr; + +// Toggle-only Switches. +constexpr auto kCobaltToggleSwitches = std::to_array({ + // Disable first run experience, kiosk, etc. + "disable-fre", + switches::kNoFirstRun, + switches::kKioskMode, + // Enable Blink to work in overlay video mode + switches::kForceVideoOverlays, + // Disable multiprocess mode. + switches::kSingleProcess, + // Accelerated GL is blanket disabled for Linux. Ignore the GPU blocklist + // to enable it. + switches::kIgnoreGpuBlocklist, + // This flag is added specifically for m114 and should be removed after + // rebasing to m120+ + switches::kUserLevelMemoryPressureSignalParams, + switches::kNoSandbox +}); + +// Switches with parameters. May require special handling with passed in values. +constexpr auto kCobaltParamSwitches = base::CommandLine::SwitchMap({ + // Disable Vulkan. + {switches::kDisableFeatures, "Vulkan"}, + // Force some ozone settings. + {switches::kOzonePlatform, "starboard"}, + {switches::kUseGL, "angle"}, + {switches::kUseANGLE, "gles-egl"}, + // Set the default size for the content shell/starboard window. + {switches::kContentShellHostWindowSize, "1920x1080"}, + // Enable remote Devtools access. + {switches::kRemoteDebuggingPort, "9222"}, + {switches::kRemoteAllowOrigins, "http://localhost:9222"}, +}); + +class CommandLinePreprocessor { + + public: + CommandLinePreprocessor(int argc, const char** argv) : cmd_line_(argc, argv) { + // Insert these switches if they are missing. + for (const auto& cobalt_switch : kCobaltToggleSwitches) { + cmd_line_.AppendSwitch(cobalt_switch); + } + + // Handle special-case switches with duplicated entries. + if (cmd_line_.HasSwitch(kDisableFeatures)) { + // Merge all disabled features together. + std::string disabled_features(cmd_line_.GetSwitchValueASCII( + kDisableFeatures)); + disabled_features += cobalt_default_switch_map.find(kDisableFeatures); + cmd_line_.AppendSwitchNative(kDisableFeatures, disabled_features); + } + if (cmd_line_.HasSwitch(kContentShellHostWindowSize)) { + // Replace with the passed in argument for window-size. + if (cmd_line_.HasSwitch(kWindowSize)) { + cmd_line_.RemoveSwitch(kContentShellHostWindowSize); + cmd_line_.AppendSwitchASCII(kContentShellHostWindowSize, + cmd_line_.GetSwitchValueASCII(kWindowSize)); + } + } + + // Insert these switches if they are mising. + for (const auto& iter : kCobaltParamSwitches) { + const auto& switch_key = iter.first; + const auto& switch_val = iter.second; + if (!cmd_line_.HasSwitch(iter.first)) { + cmd_line_.AppendSwitchNative(switch_key, switch_val); + } + } + + // Sanity checks for various graphics configurations. + } + + const StringVector& argv() const { + return cmd_line_.argv(); + } + + const std::string GetInitialURL() const { + return cobalt::switches::GetInitialURL(cmd_line_); + } + + private: + base::CommandLine cmd_line_; + +} // CommandLinePreprocessor + + } // namespace int InitCobalt(int argc, const char** argv, const char* initial_deep_link) { - const std::string initial_url = - cobalt::switches::GetInitialURL(base::CommandLine(argc, argv)); - // content::ContentMainParams params(g_content_main_delegate.Get().get()); content::ContentMainParams params(g_content_main_delegate); - // TODO: (cobalt b/375241103) Reimplement this in a clean way. - const auto cobalt_args = std::to_array( - {// Disable first run experience, kiosk, etc. - "--disable-fre", "--no-first-run", "--kiosk", - // Enable Blink to work in overlay video mode - "--force-video-overlays", - // Disable multiprocess mode. - "--single-process", - // Disable Vulkan. - "--disable-features=Vulkan", - // Accelerated GL is blanket disabled for Linux. Ignore the GPU blocklist - // to enable it. - "--ignore-gpu-blocklist", - // Force some ozone settings. - "--ozone-platform=starboard", "--use-gl=angle", "--use-angle=gles-egl", - // Set the default size for the content shell/starboard window. - "--content-shell-host-window-size=1920x1080", - // Enable remote Devtools access. - "--remote-debugging-port=9222", - "--remote-allow-origins=http://localhost:9222", - // This flag is added specifically for m114 and should be removed after - // rebasing to m120+ - "--user-level-memory-pressure-signal-params", "--no-sandbox", - initial_url.c_str()}); - std::vector args(argv, argv + argc); - args.insert(args.end(), cobalt_args.begin(), cobalt_args.end()); + CommandLinePreprocessor init_cmd_line(argc, argv); + const auto& init_argv = init_cmd_line.argv(); + std::vector args; + args.insert(args.end(), init_argv.begin(), init_argv.end()); // TODO: (cobalt b/375241103) Reimplement this in a clean way. // This expression exists to ensure that we apply the argument overrides From 0032e8eea257d17b6579e2f58ce45366c912661c Mon Sep 17 00:00:00 2001 From: Arjun Menon Date: Thu, 20 Feb 2025 13:56:11 -0800 Subject: [PATCH 2/4] Fix compile errors --- cobalt/cobalt.cc | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/cobalt/cobalt.cc b/cobalt/cobalt.cc index 1e0110505c0..327eb65dacf 100644 --- a/cobalt/cobalt.cc +++ b/cobalt/cobalt.cc @@ -19,11 +19,11 @@ #include #include "base/at_exit.h" +#include "base/base_switches.h" #include "base/command_line.h" #include "base/lazy_instance.h" #include "base/logging.h" #include "base/no_destructor.h" -#include "base/switches.h" #include "build/build_config.h" #include "chrome/common/chrome_switches.h" #include "cobalt/browser/switches.h" @@ -56,7 +56,7 @@ static cobalt::CobaltMainDelegate* g_content_main_delegate = nullptr; static PlatformEventSourceStarboard* g_platform_event_source = nullptr; // Toggle-only Switches. -constexpr auto kCobaltToggleSwitches = std::to_array({ +const auto kCobaltToggleSwitches = std::to_array({ // Disable first run experience, kiosk, etc. "disable-fre", switches::kNoFirstRun, @@ -70,12 +70,14 @@ constexpr auto kCobaltToggleSwitches = std::to_array({ switches::kIgnoreGpuBlocklist, // This flag is added specifically for m114 and should be removed after // rebasing to m120+ +#if BUILDFLAG(IS_ANDROID) switches::kUserLevelMemoryPressureSignalParams, - switches::kNoSandbox +#endif // BUILDFLAG(IS_ANDROID) + sandbox::policy::switches::kNoSandbox }); // Switches with parameters. May require special handling with passed in values. -constexpr auto kCobaltParamSwitches = base::CommandLine::SwitchMap({ +const auto kCobaltParamSwitches = base::CommandLine::SwitchMap({ // Disable Vulkan. {switches::kDisableFeatures, "Vulkan"}, // Force some ozone settings. @@ -99,19 +101,23 @@ class CommandLinePreprocessor { } // Handle special-case switches with duplicated entries. - if (cmd_line_.HasSwitch(kDisableFeatures)) { + if (cmd_line_.HasSwitch(switches::kDisableFeatures)) { // Merge all disabled features together. std::string disabled_features(cmd_line_.GetSwitchValueASCII( - kDisableFeatures)); - disabled_features += cobalt_default_switch_map.find(kDisableFeatures); - cmd_line_.AppendSwitchNative(kDisableFeatures, disabled_features); + switches::kDisableFeatures)); + auto old_value = kCobaltParamSwitches.find(switches::kDisableFeatures); + if (old_value != kCobaltParamSwitches.end()) { + disabled_features += std::string(old_value->second); + cmd_line_.AppendSwitchNative(switches::kDisableFeatures, + disabled_features); + } } - if (cmd_line_.HasSwitch(kContentShellHostWindowSize)) { + if (cmd_line_.HasSwitch(switches::kContentShellHostWindowSize)) { // Replace with the passed in argument for window-size. - if (cmd_line_.HasSwitch(kWindowSize)) { - cmd_line_.RemoveSwitch(kContentShellHostWindowSize); - cmd_line_.AppendSwitchASCII(kContentShellHostWindowSize, - cmd_line_.GetSwitchValueASCII(kWindowSize)); + if (cmd_line_.HasSwitch(switches::kWindowSize)) { + cmd_line_.RemoveSwitch(switches::kContentShellHostWindowSize); + cmd_line_.AppendSwitchASCII(switches::kContentShellHostWindowSize, + cmd_line_.GetSwitchValueASCII(switches::kWindowSize)); } } @@ -127,7 +133,7 @@ class CommandLinePreprocessor { // Sanity checks for various graphics configurations. } - const StringVector& argv() const { + const base::CommandLine::StringVector& argv() const { return cmd_line_.argv(); } @@ -138,7 +144,7 @@ class CommandLinePreprocessor { private: base::CommandLine cmd_line_; -} // CommandLinePreprocessor +}; // CommandLinePreprocessor } // namespace @@ -150,7 +156,9 @@ int InitCobalt(int argc, const char** argv, const char* initial_deep_link) { CommandLinePreprocessor init_cmd_line(argc, argv); const auto& init_argv = init_cmd_line.argv(); std::vector args; - args.insert(args.end(), init_argv.begin(), init_argv.end()); + for (const auto& arg : init_argv) { + args.push_back(arg.c_str()); + } // TODO: (cobalt b/375241103) Reimplement this in a clean way. // This expression exists to ensure that we apply the argument overrides From 8f05b0726273c11aacae4cfc14d90c30209f0d01 Mon Sep 17 00:00:00 2001 From: Arjun Menon Date: Mon, 24 Feb 2025 15:19:06 -0800 Subject: [PATCH 3/4] add command line switch definition deps --- cobalt/BUILD.gn | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cobalt/BUILD.gn b/cobalt/BUILD.gn index 02a9a530102..468cb5d505d 100644 --- a/cobalt/BUILD.gn +++ b/cobalt/BUILD.gn @@ -56,6 +56,9 @@ if (!is_android) { "//sandbox", "//starboard:starboard_group", "//third_party/blink/public/common", + "//chrome/common:non_code_constants", + # For the ozone command-line switches. + "//ui/ozone:ozone" ] data_deps = [ From 25fa83f0bdeafbb26c29e779f06d53a6cc6dba6d Mon Sep 17 00:00:00 2001 From: Arjun Menon Date: Mon, 24 Feb 2025 15:20:25 -0800 Subject: [PATCH 4/4] remove leftover comment --- cobalt/cobalt.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/cobalt/cobalt.cc b/cobalt/cobalt.cc index 327eb65dacf..57d921928c5 100644 --- a/cobalt/cobalt.cc +++ b/cobalt/cobalt.cc @@ -129,8 +129,6 @@ class CommandLinePreprocessor { cmd_line_.AppendSwitchNative(switch_key, switch_val); } } - - // Sanity checks for various graphics configurations. } const base::CommandLine::StringVector& argv() const {