diff options
author | David 'Digit' Turner <digit@android.com> | 2011-01-19 22:18:02 +0100 |
---|---|---|
committer | David 'Digit' Turner <digit@android.com> | 2011-01-19 22:28:52 +0100 |
commit | 3bbc919b70c78e0be6387d06faa90743deedb4dc (patch) | |
tree | 9381676c67914b253f4e3ebfe67bdd361394358f /android | |
parent | 3336176fc898915b7b5544f3a7c60ec2794507c3 (diff) | |
download | external_qemu-3bbc919b70c78e0be6387d06faa90743deedb4dc.zip external_qemu-3bbc919b70c78e0be6387d06faa90743deedb4dc.tar.gz external_qemu-3bbc919b70c78e0be6387d06faa90743deedb4dc.tar.bz2 |
Compute default memory size from screen size.
This change is used when using a magic skin (e.g. -skin 800x600)
or when using the full Android build system, in order to determine
a good default for the RAM size.
Change-Id: I900e28146592cdd3f0df9b3f1828b119309eea85
Diffstat (limited to 'android')
-rw-r--r-- | android/avd/hardware-properties.ini | 2 | ||||
-rw-r--r-- | android/avd/hw-config-defs.h | 2 | ||||
-rw-r--r-- | android/main-ui.c | 30 | ||||
-rw-r--r-- | android/main.c | 30 | ||||
-rw-r--r-- | android/qemulator.c | 16 | ||||
-rw-r--r-- | android/qemulator.h | 5 |
6 files changed, 81 insertions, 4 deletions
diff --git a/android/avd/hardware-properties.ini b/android/avd/hardware-properties.ini index 68979de..8e5cc41 100644 --- a/android/avd/hardware-properties.ini +++ b/android/avd/hardware-properties.ini @@ -26,7 +26,7 @@ # Ram size name = hw.ramSize type = integer -default = 96 +default = 0 abstract = Device ram size description = The amount of physical RAM on the device, in megabytes. diff --git a/android/avd/hw-config-defs.h b/android/avd/hw-config-defs.h index 9eb4335..9602a4a 100644 --- a/android/avd/hw-config-defs.h +++ b/android/avd/hw-config-defs.h @@ -20,7 +20,7 @@ HWCFG_INT( hw_ramSize, "hw.ramSize", - 96, + 0, "Device ram size", "The amount of physical RAM on the device, in megabytes.") diff --git a/android/main-ui.c b/android/main-ui.c index 8b9e088..7a4d746 100644 --- a/android/main-ui.c +++ b/android/main-ui.c @@ -1756,7 +1756,35 @@ int main(int argc, char **argv) } } if (!opts->memory) { - bufprint(tmp, tmpend, "%d", hw->hw_ramSize); + int ramSize = hw->hw_ramSize; + if (ramSize <= 0) { + /* Compute the default RAM size based on the size of screen. + * This is only used when the skin doesn't provide the ram + * size through its hardware.ini (i.e. legacy ones) or when + * in the full Android build system. + */ + int width, height, pixels; + qemulator_get_screen_size(qemulator_get(), &width, &height); + pixels = width*height; + + /* The following thresholds are a bit liberal, but we + * essentially want to ensure the following mappings: + * + * 320x480 -> 96 + * 800x600 -> 128 + * 1024x768 -> 256 + * + * These are just simple heuristics, they could change in + * the future. + */ + if (pixels <= 250000) + ramSize = 96; + else if (pixels <= 500000) + ramSize = 128; + else + ramSize = 256; + } + bufprint(tmp, tmpend, "%d", ramSize); opts->memory = android_strdup(tmp); } diff --git a/android/main.c b/android/main.c index 5968249..793fa23 100644 --- a/android/main.c +++ b/android/main.c @@ -1520,7 +1520,35 @@ int main(int argc, char **argv) } } if (!opts->memory) { - bufprint(tmp, tmpend, "%d", hw->hw_ramSize); + int ramSize = hw->hw_ramSize; + if (ramSize <= 0) { + /* Compute the default RAM size based on the size of screen. + * This is only used when the skin doesn't provide the ram + * size through its hardware.ini (i.e. legacy ones) or when + * in the full Android build system. + */ + int width, height, pixels; + qemulator_get_screen_size(qemulator_get(), &width, &height); + pixels = width*height; + + /* The following thresholds are a bit liberal, but we + * essentially want to ensure the following mappings: + * + * 320x480 -> 96 + * 800x600 -> 128 + * 1024x768 -> 256 + * + * These are just simple heuristics, they could change in + * the future. + */ + if (pixels <= 250000) + ramSize = 96; + else if (pixels <= 500000) + ramSize = 128; + else + ramSize = 256; + } + bufprint(tmp, tmpend, "%d", ramSize); opts->memory = android_strdup(tmp); } diff --git a/android/qemulator.c b/android/qemulator.c index 3f427b8..35e7cc8 100644 --- a/android/qemulator.c +++ b/android/qemulator.c @@ -188,6 +188,22 @@ qemulator_done(QEmulator* emulator) } } +void +qemulator_get_screen_size( QEmulator* emulator, + int *width, + int *height ) +{ + AConfig* root = emulator->aconfig; + AConfig* disp; + + *width = *height = 0; + if (root == NULL || (disp = aconfig_find(root, "display")) == NULL) + return; + + *width = aconfig_int(disp, "width", 0); + *height = aconfig_int(disp, "height", 0); +} + SkinLayout* qemulator_get_layout(QEmulator* emulator) { diff --git a/android/qemulator.h b/android/qemulator.h index 189cc53..b343f98 100644 --- a/android/qemulator.h +++ b/android/qemulator.h @@ -50,6 +50,11 @@ qemulator_init( QEmulator* emulator, int y, AndroidOptions* opts ); +void +qemulator_get_screen_size( QEmulator* emulator, + int *width, + int *height ); + /* Uninitializes QEmulator structure instance on exit. */ void qemulator_done( QEmulator* emulator ); |