Loading libs/androidfw/ResourceTypes.cpp +10 −13 Original line number Original line Diff line number Diff line Loading @@ -2677,30 +2677,27 @@ bool ResTable_config::isBetterThan(const ResTable_config& o, // DENSITY_ANY is now dealt with. We should look to // DENSITY_ANY is now dealt with. We should look to // pick a density bucket and potentially scale it. // pick a density bucket and potentially scale it. // Any density is potentially useful // Any density is potentially useful // because the system will scale it. Scaling down // because the system will scale it. Always prefer // is generally better than scaling up. // scaling down. int h = thisDensity; int h = thisDensity; int l = otherDensity; int l = otherDensity; bool bImBigger = true; bool bImBigger = true; if (l > h) { if (l > h) { int t = h; std::swap(l, h); h = l; l = t; bImBigger = false; bImBigger = false; } } if (requestedDensity >= h) { if (h == requestedDensity) { // requested value higher than both l and h, give h // This handles the case where l == h == requestedDensity. // In that case, this and o are equally good so both // true and false are valid. This preserves previous // behavior. return bImBigger; return bImBigger; } } else if (l >= requestedDensity) { if (l >= requestedDensity) { // requested value lower than both l and h, give l // requested value lower than both l and h, give l return !bImBigger; return !bImBigger; } // saying that scaling down is 2x better than up if (((2 * l) - requestedDensity) * h > requestedDensity * requestedDensity) { return !bImBigger; } else { } else { // otherwise give h return bImBigger; return bImBigger; } } } } Loading libs/androidfw/tests/Config_test.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -75,6 +75,9 @@ TEST(ConfigTest, shouldSelectBestDensity) { configs.add(buildDensityConfig(int(ResTable_config::DENSITY_HIGH) + 20)); configs.add(buildDensityConfig(int(ResTable_config::DENSITY_HIGH) + 20)); ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs)); 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); expectedBest = buildDensityConfig(ResTable_config::DENSITY_XHIGH); configs.add(expectedBest); configs.add(expectedBest); ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs)); ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs)); Loading Loading
libs/androidfw/ResourceTypes.cpp +10 −13 Original line number Original line Diff line number Diff line Loading @@ -2677,30 +2677,27 @@ bool ResTable_config::isBetterThan(const ResTable_config& o, // DENSITY_ANY is now dealt with. We should look to // DENSITY_ANY is now dealt with. We should look to // pick a density bucket and potentially scale it. // pick a density bucket and potentially scale it. // Any density is potentially useful // Any density is potentially useful // because the system will scale it. Scaling down // because the system will scale it. Always prefer // is generally better than scaling up. // scaling down. int h = thisDensity; int h = thisDensity; int l = otherDensity; int l = otherDensity; bool bImBigger = true; bool bImBigger = true; if (l > h) { if (l > h) { int t = h; std::swap(l, h); h = l; l = t; bImBigger = false; bImBigger = false; } } if (requestedDensity >= h) { if (h == requestedDensity) { // requested value higher than both l and h, give h // This handles the case where l == h == requestedDensity. // In that case, this and o are equally good so both // true and false are valid. This preserves previous // behavior. return bImBigger; return bImBigger; } } else if (l >= requestedDensity) { if (l >= requestedDensity) { // requested value lower than both l and h, give l // requested value lower than both l and h, give l return !bImBigger; return !bImBigger; } // saying that scaling down is 2x better than up if (((2 * l) - requestedDensity) * h > requestedDensity * requestedDensity) { return !bImBigger; } else { } else { // otherwise give h return bImBigger; return bImBigger; } } } } Loading
libs/androidfw/tests/Config_test.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -75,6 +75,9 @@ TEST(ConfigTest, shouldSelectBestDensity) { configs.add(buildDensityConfig(int(ResTable_config::DENSITY_HIGH) + 20)); configs.add(buildDensityConfig(int(ResTable_config::DENSITY_HIGH) + 20)); ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs)); 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); expectedBest = buildDensityConfig(ResTable_config::DENSITY_XHIGH); configs.add(expectedBest); configs.add(expectedBest); ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs)); ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs)); Loading