Ensure Bitmap.getDefaultDensity() matches DENSITY_DEVICE

Otherwise bitmaps constructed without a target display are incorrectly
scaled by a factor of (DENSITY_DEVICE / DENSITY_DEFAULT) when rendered
to a Canvas whose density has been specified correctly.

Bug: 26817900
Change-Id: I45edfc7c0cbdf84a267d5bedacb0548659ede301
This commit is contained in:
Alan Viverette
2016-02-04 16:58:14 -05:00
parent 95085d154b
commit 2ac46f1bda

View File

@@ -4822,14 +4822,12 @@ public final class ActivityThread {
}
private void updateDefaultDensity() {
if (mCurDefaultDisplayDpi != Configuration.DENSITY_DPI_UNDEFINED
&& mCurDefaultDisplayDpi != DisplayMetrics.DENSITY_DEVICE
&& !mDensityCompatMode) {
Slog.i(TAG, "Switching default density from "
+ DisplayMetrics.DENSITY_DEVICE + " to "
+ mCurDefaultDisplayDpi);
DisplayMetrics.DENSITY_DEVICE = mCurDefaultDisplayDpi;
Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT);
final int densityDpi = mCurDefaultDisplayDpi;
if (!mDensityCompatMode
&& densityDpi != Configuration.DENSITY_DPI_UNDEFINED
&& densityDpi != DisplayMetrics.DENSITY_DEVICE) {
DisplayMetrics.DENSITY_DEVICE = densityDpi;
Bitmap.setDefaultDensity(densityDpi);
}
}