summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeremy Meyer <jakmcbane@google.com> 2021-11-05 21:38:00 +0000
committer Jeremy Meyer <jakmcbane@google.com> 2021-11-05 21:38:00 +0000
commit30715f3afc061bd25a5f251554efc56c412d02d5 (patch)
tree0aad94afae91304cbd9ab3f543bf5758168ef17d
parent5ac5c9bc09677320b97e06fd6ee6cd0fb3536246 (diff)
Revert "Revert "Revert "Always select the next higher density bu..."
Revert "Update getDrawableForDensity test to allow either of the..." Revert submission 16132603-183136881 Reason for revert: causes post submit failures Reverted Changes: I42ff7cdee:Revert "Revert "Always select the next higher dens... Id4a93f857:Update getDrawableForDensity test to allow either ... Change-Id: Idcc4c7b909256c65bc0f4e7815bb2d9093e66830
-rw-r--r--libs/androidfw/ResourceTypes.cpp17
-rw-r--r--libs/androidfw/tests/Config_test.cpp15
2 files changed, 17 insertions, 15 deletions
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index 50117ce9e69b..cae2d0bc16b3 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -2677,21 +2677,30 @@ bool ResTable_config::isBetterThan(const ResTable_config& o,
// DENSITY_ANY is now dealt with. We should look to
// pick a density bucket and potentially scale it.
// Any density is potentially useful
- // because the system will scale it. Always prefer
- // scaling down.
+ // because the system will scale it. Scaling down
+ // is generally better than scaling up.
int h = thisDensity;
int l = otherDensity;
bool bImBigger = true;
if (l > h) {
- std::swap(l, h);
+ int t = h;
+ h = l;
+ l = t;
bImBigger = false;
}
+ if (requestedDensity >= h) {
+ // requested value higher than both l and h, give h
+ return bImBigger;
+ }
if (l >= requestedDensity) {
// requested value lower than both l and h, give l
return !bImBigger;
+ }
+ // saying that scaling down is 2x better than up
+ if (((2 * l) - requestedDensity) * h > requestedDensity * requestedDensity) {
+ return !bImBigger;
} else {
- // otherwise give h
return bImBigger;
}
}
diff --git a/libs/androidfw/tests/Config_test.cpp b/libs/androidfw/tests/Config_test.cpp
index f5fd0f20d580..b54915f03c29 100644
--- a/libs/androidfw/tests/Config_test.cpp
+++ b/libs/androidfw/tests/Config_test.cpp
@@ -27,19 +27,15 @@ namespace android {
static ResTable_config selectBest(const ResTable_config& target,
const Vector<ResTable_config>& configs) {
- Vector<ResTable_config> matchedConfigs;
+ ResTable_config bestConfig;
+ memset(&bestConfig, 0, sizeof(bestConfig));
const size_t configCount = configs.size();
for (size_t i = 0; i < configCount; i++) {
const ResTable_config& thisConfig = configs[i];
- if (thisConfig.match(target)) {
- matchedConfigs.add(thisConfig);
+ if (!thisConfig.match(target)) {
+ continue;
}
- }
- ResTable_config bestConfig = matchedConfigs[0];
- const size_t matchingConfigCount = matchedConfigs.size();
- for (size_t i = 1; i < matchingConfigCount; i++) {
- const ResTable_config& thisConfig = configs[i];
if (thisConfig.isBetterThan(bestConfig, &target)) {
bestConfig = thisConfig;
}
@@ -79,9 +75,6 @@ TEST(ConfigTest, shouldSelectBestDensity) {
configs.add(buildDensityConfig(int(ResTable_config::DENSITY_HIGH) + 20));
ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs));
- configs.add(buildDensityConfig(int(ResTable_config::DENSITY_XHIGH) - 1));
- ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs));
-
expectedBest = buildDensityConfig(ResTable_config::DENSITY_XHIGH);
configs.add(expectedBest);
ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs));