Skip to content

Commit

Permalink
Enable low end device mode
Browse files Browse the repository at this point in the history
1. Enable low end device mode to reduce memory usage.
2. Exclude to limit AmountOfPhysicalMemory on low end device mode, which causes the rendering issue.

b/380310632
  • Loading branch information
borongc committed Dec 23, 2024
1 parent b7b2d76 commit 34c1fcd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ if (is_win) {
import("//build/config/win/control_flow_guard.gni")
}

if (is_cobalt) {
import("//starboard/build/buildflags.gni")
}

declare_args() {
# Unsafe developer build. Has developer-friendly features that may weaken or
# disable security measures like sandboxing or ASLR.
Expand Down Expand Up @@ -2230,7 +2234,7 @@ component("base") {
sources += [
"system/sys_info_starboard.cc",
"system/sys_info_starboard.h",
]
]
}

if (use_blink) {
Expand Down
11 changes: 11 additions & 0 deletions base/system/sys_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ namespace {
// For M99, 45% of devices have 2GB of RAM, and 55% have more.
constexpr uint64_t kLowMemoryDeviceThresholdMB = 1024;
#else
#if BUILDFLAG(USE_STARBOARD_MEDIA)
#if !BUILDFLAG(IS_ANDROID)
// Updated Desktop default threshold to match the Android 2021 definition.
constexpr uint64_t kLowMemoryDeviceThresholdMB = 2048;
#endif //!BUILDFLAG(IS_ANDROID)
#else //BUILDFLAG(USE_STARBOARD_MEDIA)
// Updated Desktop default threshold to match the Android 2021 definition.
constexpr uint64_t kLowMemoryDeviceThresholdMB = 2048;
#endif //BUILDFLAG(USE_STARBOARD_MEDIA)
#endif
} // namespace

Expand All @@ -38,6 +45,7 @@ int SysInfo::NumberOfEfficientProcessors() {

// static
uint64_t SysInfo::AmountOfPhysicalMemory() {
#if !BUILDFLAG(USE_STARBOARD_MEDIA)
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableLowEndDeviceMode)) {
// Keep using 512MB as the simulated RAM amount for when users or tests have
Expand All @@ -48,12 +56,14 @@ uint64_t SysInfo::AmountOfPhysicalMemory() {
return std::min(kSimulatedMemoryForEnableLowEndDeviceMode,
AmountOfPhysicalMemoryImpl());
}
#endif // !BUILDFLAG(USE_STARBOARD_MEDIA)

return AmountOfPhysicalMemoryImpl();
}

// static
uint64_t SysInfo::AmountOfAvailablePhysicalMemory() {
#if !BUILDFLAG(USE_STARBOARD_MEDIA)
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableLowEndDeviceMode)) {
// Estimate the available memory by subtracting our memory used estimate
Expand All @@ -64,6 +74,7 @@ uint64_t SysInfo::AmountOfAvailablePhysicalMemory() {
// std::min ensures no underflow, as |memory_used| can be > |memory_limit|.
return memory_limit - std::min(memory_used, memory_limit);
}
#endif // !BUILDFLAG(USE_STARBOARD_MEDIA)

return AmountOfAvailablePhysicalMemoryImpl();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ protected void createContent(final Bundle savedInstanceState) {
if (!CommandLine.isInitialized()) {
((CobaltApplication) getApplication()).initCommandLine();

// Note that appendSwitchesAndArguments excludes cobaltCommandLineParams[0]
// as the program name, and all other arguments SHOULD start with '--'.
String[] cobaltCommandLineParams =
new String[] {
"",
// Disable first run experience.
"--disable-fre",
// Disable user prompts in the first run.
Expand All @@ -125,6 +122,8 @@ protected void createContent(final Bundle savedInstanceState) {
"--enable-features=LogJsConsoleMessages",
// Disable rescaling Webpage.
"--force-device-scale-factor=1",
// Enable low end device mode.
"--enable-low-end-device-mode",
};
CommandLine.getInstance().appendSwitchesAndArguments(cobaltCommandLineParams);

Expand Down

0 comments on commit 34c1fcd

Please sign in to comment.