Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(888)

Unified Diff: ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java

Issue 2300463002: Add observers for DIP scale change. (Closed)
Patch Set: Addressed comments, more questions. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
diff --git a/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
index 44c599042ef3956501203b767b69873a743b6b4d..5ca6ca037e47b45e9f9ae5dbd0e6bd64bbfd109b 100644
--- a/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
+++ b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
@@ -14,6 +14,7 @@ import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;
+import org.chromium.base.CommandLine;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
@@ -32,6 +33,28 @@ public class DeviceDisplayInfo {
private Point mTempPoint = new Point();
private DisplayMetrics mTempMetrics = new DisplayMetrics();
+ // The value -1.0 signals that it is unknown whether the forced value is set,
+ // 0.0 means that it is not set and positive that it's set.
+ private static float sForcedDIPScale = -1.0f;
+
+ private static boolean hasForcedDIPScale() {
+ if (sForcedDIPScale < 0) {
+ String forcedScaleAsString = CommandLine.getInstance().getSwitchValue(
+ DisplaySwitches.FORCE_DEVICE_SCALE_FACTOR);
+ if (forcedScaleAsString == null) {
+ sForcedDIPScale = 0.0f;
+ } else {
+ try {
+ sForcedDIPScale = Math.abs(Float.valueOf(forcedScaleAsString));
+ } catch (NumberFormatException e) {
+ // Invalid numerical value is discarded.
+ sForcedDIPScale = 0.0f;
+ }
+ }
+ }
+ return sForcedDIPScale > 0;
+ }
+
private DeviceDisplayInfo(Context context) {
mAppContext = context.getApplicationContext();
mWinManager = (WindowManager) mAppContext.getSystemService(Context.WINDOW_SERVICE);
@@ -144,6 +167,8 @@ public class DeviceDisplayInfo {
*/
@CalledByNative
public double getDIPScale() {
+ if (hasForcedDIPScale()) return sForcedDIPScale;
+
getDisplay().getMetrics(mTempMetrics);
return mTempMetrics.density;
}

Powered by Google App Engine
This is Rietveld 408576698