diff options
author | Roman Birg <roman@cyngn.com> | 2015-05-21 06:22:24 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-27 15:11:36 -0700 |
commit | 617275f6af2398761f32f2ec09ef9946d990cfdb (patch) | |
tree | 022bf557148cda26d7d8a7bca59e319c2fcf959f | |
parent | 173a4d8ab994d5d0c1015887a077bd13f605f97f (diff) | |
download | frameworks_base-617275f6af2398761f32f2ec09ef9946d990cfdb.zip frameworks_base-617275f6af2398761f32f2ec09ef9946d990cfdb.tar.gz frameworks_base-617275f6af2398761f32f2ec09ef9946d990cfdb.tar.bz2 |
unbreak density scaling
- Only apply density scaling to built in screens so we don't affect
overlays.
- Only apply density scaling for activities which fall under the
'default' compatibility bucket. Some apps may have different
compatibility info setup (e.g. scaling) and we do not
need to apply the user density to this activity.
Change-Id: I0b4849141cf081694aae5668ae60764e70be7db1
Signed-off-by: Roman Birg <roman@cyngn.com>
Density scaling: scale compatibility apps, wm command support
Density scaling should work across all apps and different density
configurations. It should also pass CTS.
- force compatibility density if calculated compatibility density is
different than what the user has requested
- hook in "wm density" support, should behave the same as setting the
density from Settings
- clean up some logic
Change-Id: I52c7c2ca200b78f9a5ee9170871ca62e1cab3bcb
Signed-off-by: Roman Birg <roman@cyngn.com>
Fix typo in density assignment.
Change-Id: I35b3860a4991ebaee70c91f3878d63b8f28d7fce
Density scaling: return device's default density
When an application requests the Display's display metrics, always
override the returned densityDpi to be the device's original density to
ensure compatibility.
Change-Id: I465d53bc189d4596aba0269f124ddc9d0d8097da
Signed-off-by: Roman Birg <roman@cyngn.com>
return default density only for primary display
Change-Id: I70b35a7f4ba77d7c5744fdcb6c19ef78de3dcb15
Signed-off-by: Roman Birg <roman@cyngn.com>
density: do not apply to virtual displays
Check the incoming configuration density to ensure that it is the same
as the device's default density before forcing preferred values.
Only apply display metrics if the display is not a presentation.
Ref: CYNGNOS-338
Change-Id: I437ac8cf45f1a6c568707e0733364b2495791d8a
Signed-off-by: Roman Birg <roman@cyngn.com>
-rw-r--r-- | core/java/android/app/ActivityThread.java | 2 | ||||
-rw-r--r-- | core/java/android/content/res/Resources.java | 13 | ||||
-rw-r--r-- | core/java/android/util/DisplayMetrics.java | 34 | ||||
-rw-r--r-- | core/java/android/view/Display.java | 3 | ||||
-rw-r--r-- | core/java/android/view/DisplayInfo.java | 3 | ||||
-rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 11 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/Drawable.java | 2 | ||||
-rw-r--r-- | services/core/java/com/android/server/wm/WindowManagerService.java | 17 |
8 files changed, 59 insertions, 26 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 219740d..20e0d0c 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -4450,7 +4450,7 @@ public final class ActivityThread { + DisplayMetrics.DENSITY_DEVICE + " to " + mCurDefaultDisplayDpi); DisplayMetrics.DENSITY_DEVICE = mCurDefaultDisplayDpi; - Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); + Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEVICE); } } diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index 77d3295..85ecc0a 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -286,7 +286,6 @@ public class Resources { CompatibilityInfo compatInfo) { mAssets = assets; mMetrics.setToDefaults(); - mMetrics.updateDensity(); if (compatInfo != null) { mCompatibilityInfo = compatInfo; } @@ -2122,9 +2121,13 @@ public class Resources { mConfiguration.setLayoutDirection(mConfiguration.locale); } if (mConfiguration.densityDpi != Configuration.DENSITY_DPI_UNDEFINED) { - mMetrics.densityDpi = mConfiguration.densityDpi; - mMetrics.density = mConfiguration.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE; - mMetrics.updateDensity(); + if (DisplayMetrics.DENSITY_DEVICE_DEFAULT == mCompatibilityInfo.applicationDensity + && (config != null + && config.densityDpi == DisplayMetrics.DENSITY_DEVICE_DEFAULT)) { + mMetrics.setDensity(DisplayMetrics.DENSITY_PREFERRED); + } else { + mMetrics.setDensity(mConfiguration.densityDpi); + } } mMetrics.scaledDensity = mMetrics.density * mConfiguration.fontScale; @@ -2554,7 +2557,7 @@ public class Resources { } sPreloaded = true; mPreloading = true; - sPreloadedDensity = DisplayMetrics.getDeviceDensity(); + sPreloadedDensity = DisplayMetrics.DENSITY_PREFERRED; mConfiguration.densityDpi = sPreloadedDensity; updateConfiguration(null, null); } diff --git a/core/java/android/util/DisplayMetrics.java b/core/java/android/util/DisplayMetrics.java index 142c135..2b654ad 100644 --- a/core/java/android/util/DisplayMetrics.java +++ b/core/java/android/util/DisplayMetrics.java @@ -16,6 +16,7 @@ package android.util; +import android.graphics.Bitmap; import android.os.SystemProperties; @@ -140,12 +141,17 @@ public class DisplayMetrics { @Deprecated public static int DENSITY_DEVICE; - public static int DENSITY_CURRENT; + /** @hide */ + public static int DENSITY_PREFERRED; + + /** @hide */ + public static int DENSITY_DEVICE_DEFAULT; static { DENSITY_DEVICE = SystemProperties.getInt("qemu.sf.lcd_density", SystemProperties .getInt("ro.sf.lcd_density", DENSITY_DEFAULT)); - DENSITY_CURRENT = SystemProperties.getInt("persist.sys.lcd_density", DENSITY_DEVICE); + DENSITY_DEVICE_DEFAULT = DENSITY_DEVICE; + DENSITY_PREFERRED = SystemProperties.getInt("persist.sys.lcd_density", DENSITY_DEVICE); } /** @@ -237,17 +243,16 @@ public class DisplayMetrics { */ public float noncompatYdpi; - public void updateDensity() { - density = DENSITY_CURRENT / (float) DENSITY_DEFAULT; - densityDpi = DENSITY_CURRENT; + /** @hide */ + public void setDensity(int inDensity) { + density = inDensity / (float) DENSITY_DEFAULT; + densityDpi = inDensity; scaledDensity = density; - xdpi = DENSITY_CURRENT; - ydpi = DENSITY_CURRENT; - noncompatDensity = density; - noncompatDensityDpi = densityDpi; - noncompatScaledDensity = scaledDensity; - noncompatXdpi = xdpi; - noncompatYdpi = ydpi; + xdpi = inDensity; + ydpi = inDensity; + + DENSITY_DEVICE = inDensity; + Bitmap.setDefaultDensity(inDensity); } public DisplayMetrics() { @@ -268,7 +273,6 @@ public class DisplayMetrics { noncompatScaledDensity = o.noncompatScaledDensity; noncompatXdpi = o.noncompatXdpi; noncompatYdpi = o.noncompatYdpi; - updateDensity(); } public void setToDefaults() { @@ -341,8 +345,4 @@ public class DisplayMetrics { ", height=" + heightPixels + ", scaledDensity=" + scaledDensity + ", xdpi=" + xdpi + ", ydpi=" + ydpi + "}"; } - - public static int getDeviceDensity() { - return DENSITY_CURRENT; - } } diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java index 35c4192..1d284ea 100644 --- a/core/java/android/view/Display.java +++ b/core/java/android/view/Display.java @@ -730,6 +730,9 @@ public final class Display { synchronized (this) { updateDisplayInfoLocked(); mDisplayInfo.getAppMetrics(outMetrics, mDisplayAdjustments); + if (getDisplayId() == DEFAULT_DISPLAY) { + outMetrics.densityDpi = DisplayMetrics.DENSITY_DEVICE_DEFAULT; + } } } diff --git a/core/java/android/view/DisplayInfo.java b/core/java/android/view/DisplayInfo.java index cf17990..08e88ea 100644 --- a/core/java/android/view/DisplayInfo.java +++ b/core/java/android/view/DisplayInfo.java @@ -518,6 +518,9 @@ public final class DisplayInfo implements Parcelable { if (!compatInfo.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { compatInfo.applyToDisplayMetrics(outMetrics); + } else if (type == Display.TYPE_BUILT_IN + && (flags & Display.FLAG_PRESENTATION) == 0) { + outMetrics.setDensity(DisplayMetrics.DENSITY_PREFERRED); } } diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 3279185..ba2a890 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -80,18 +80,25 @@ public final class Bitmap implements Parcelable { private static volatile Matrix sScaleMatrix; + private static volatile int sDefaultDensity = -1; + /** * For backwards compatibility, allows the app layer to change the default * density when running old apps. * @hide */ public static void setDefaultDensity(int density) { - // Ignore + sDefaultDensity = density; } @SuppressWarnings("deprecation") static int getDefaultDensity() { - return DisplayMetrics.getDeviceDensity(); + if (sDefaultDensity >= 0) { + return sDefaultDensity; + } + //noinspection deprecation + sDefaultDensity = DisplayMetrics.DENSITY_DEVICE; + return sDefaultDensity; } /** diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 7bd445f..3f1f76a 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -1076,7 +1076,7 @@ public abstract class Drawable { // drawn to the screen. if (opts == null) opts = new BitmapFactory.Options(); opts.inScreenDensity = res != null - ? res.getDisplayMetrics().noncompatDensityDpi : DisplayMetrics.getDeviceDensity(); + ? res.getDisplayMetrics().noncompatDensityDpi : DisplayMetrics.DENSITY_DEFAULT; Bitmap bm = BitmapFactory.decodeResourceStream(res, value, is, pad, opts); if (bm != null) { byte[] np = bm.getNinePatchChunk(); diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 8a4fe29..867292a 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -298,6 +298,7 @@ public class WindowManagerService extends IWindowManager.Stub private static final String SYSTEM_SECURE = "ro.secure"; private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; + private static final String PERSIST_SYS_LCD_DENSITY = "persist.sys.lcd_density"; private static final String DENSITY_OVERRIDE = "ro.config.density_override"; private static final String SIZE_OVERRIDE = "ro.config.size_override"; @@ -8589,6 +8590,9 @@ public class WindowManagerService extends IWindowManager.Stub @Override public int getInitialDisplayDensity(int displayId) { + if (displayId == Display.DEFAULT_DISPLAY) { + return DisplayMetrics.DENSITY_DEVICE_DEFAULT; + } synchronized (mWindowMap) { final DisplayContent displayContent = getDisplayContentLocked(displayId); if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) { @@ -8602,6 +8606,9 @@ public class WindowManagerService extends IWindowManager.Stub @Override public int getBaseDisplayDensity(int displayId) { + if (displayId == Display.DEFAULT_DISPLAY) { + return DisplayMetrics.DENSITY_PREFERRED; + } synchronized (mWindowMap) { final DisplayContent displayContent = getDisplayContentLocked(displayId); if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) { @@ -8629,6 +8636,7 @@ public class WindowManagerService extends IWindowManager.Stub synchronized(mWindowMap) { final DisplayContent displayContent = getDisplayContentLocked(displayId); if (displayContent != null) { + SystemProperties.set(PERSIST_SYS_LCD_DENSITY, Integer.toString(density)); setForcedDisplayDensityLocked(displayContent, density); Settings.Global.putString(mContext.getContentResolver(), Settings.Global.DISPLAY_DENSITY_FORCED, Integer.toString(density)); @@ -8637,6 +8645,10 @@ public class WindowManagerService extends IWindowManager.Stub } finally { Binder.restoreCallingIdentity(ident); } + try { + ActivityManagerNative.getDefault().restart(); + } catch (RemoteException e) { + } } // displayContent must not be null @@ -8665,6 +8677,7 @@ public class WindowManagerService extends IWindowManager.Stub synchronized(mWindowMap) { final DisplayContent displayContent = getDisplayContentLocked(displayId); if (displayContent != null) { + SystemProperties.set(PERSIST_SYS_LCD_DENSITY, null); setForcedDisplayDensityLocked(displayContent, displayContent.mInitialDisplayDensity); Settings.Global.putString(mContext.getContentResolver(), @@ -8674,6 +8687,10 @@ public class WindowManagerService extends IWindowManager.Stub } finally { Binder.restoreCallingIdentity(ident); } + try { + ActivityManagerNative.getDefault().restart(); + } catch (RemoteException e) { + } } // displayContent must not be null |