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

Unified Diff: ui/android/java/src/org/chromium/ui/display/DisplayAndroidImpl.java

Issue 2523273002: Implement Virtual Display class for Android. (Closed)
Patch Set: Address comments Created 4 years, 1 month 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/display/DisplayAndroidImpl.java
diff --git a/ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java b/ui/android/java/src/org/chromium/ui/display/DisplayAndroidImpl.java
similarity index 54%
copy from ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java
copy to ui/android/java/src/org/chromium/ui/display/DisplayAndroidImpl.java
index fc17ef77548ab1e562913d10993dd28720278112..c00113be54f7b5851ddf4c4f0ef13ad3743aa51a 100644
--- a/ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java
+++ b/ui/android/java/src/org/chromium/ui/display/DisplayAndroidImpl.java
@@ -5,53 +5,22 @@
package org.chromium.ui.display;
import android.annotation.TargetApi;
-import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.Display;
-import android.view.Surface;
import org.chromium.base.CommandLine;
import org.chromium.base.Log;
-import java.util.WeakHashMap;
-
/**
- * Chromium's object for android.view.Display. Instances of this object should be obtained
- * from WindowAndroid.
- * This class is designed to avoid leaks. It is ok to hold a strong ref of this class from
- * anywhere, as long as the corresponding WindowAndroids are destroyed. The observers are
- * held weakly so to not lead to leaks.
+ * A DisplayAndroid implementation tied to a physical Display.
*/
-public class DisplayAndroid {
- /**
- * DisplayAndroidObserver interface for changes to this Display.
- */
- public interface DisplayAndroidObserver {
- /**
- * Called whenever the screen orientation changes.
- *
- * @param orientation One of Surface.ROTATION_* values.
- */
- void onRotationChanged(int rotation);
-
- /**
- * Called whenever the screen density changes.
- *
- * @param screen density, aka Density Independent Pixel scale.
- */
- void onDIPScaleChanged(float dipScale);
- }
-
+public class DisplayAndroidImpl extends DisplayAndroid {
boliu 2016/11/28 15:53:31 can class be package visible only?
mthiesse 2016/11/28 19:16:42 Done.
private static final String TAG = "DisplayAndroid";
- private static final DisplayAndroidObserver[] EMPTY_OBSERVER_ARRAY =
- new DisplayAndroidObserver[0];
-
private final int mSdkDisplayId;
- private final WeakHashMap<DisplayAndroidObserver, Object /* null */> mObservers;
// Do NOT add strong references to objects with potentially complex lifetime, like Context.
// Updated by updateFromDisplay.
@@ -93,109 +62,47 @@ public class DisplayAndroid {
return sForcedDIPScale.floatValue() > 0;
}
- private static DisplayAndroidManager getManager() {
- return DisplayAndroidManager.getInstance();
- }
-
- /**
- * Get the non-multi-display DisplayAndroid for the given context. It's safe to call this with
- * any type of context, including the Application.
- *
- * To support multi-display, obtain DisplayAndroid from WindowAndroid instead.
- *
- * This function is intended to be analogous to GetPrimaryDisplay() for other platforms.
- * However, Android has historically had no real concept of a Primary Display, and instead uses
- * the notion of a default display for an Activity. Under normal circumstances, this function,
- * called with the correct context, will return the expected display for an Activity. However,
- * virtual, or "fake", displays that are not associated with any context may be used in special
- * cases, like Virtual Reality, and will lead to this function returning the incorrect display.
- *
- * @return What the Android WindowManager considers to be the default display for this context.
- */
- public static DisplayAndroid getNonMultiDisplay(Context context) {
- Display display = DisplayAndroidManager.getDefaultDisplayForContext(context);
- return getManager().getDisplayAndroid(display);
- }
-
- /**
- * @return Display id as defined in Android's Display.
- */
- public int getSdkDisplayId() {
+ @Override
+ public int getDisplayId() {
return mSdkDisplayId;
}
- /**
- * @return Display height in physical pixels.
- */
+ @Override
public int getDisplayHeight() {
return mSize.y;
}
- /**
- * @return Display width in physical pixels.
- */
+ @Override
public int getDisplayWidth() {
return mSize.x;
}
- /**
- * @return Real physical display height in physical pixels. Or 0 if not supported.
- */
+ @Override
public int getPhysicalDisplayHeight() {
return mPhysicalSize.y;
}
- /**
- * @return Real physical display width in physical pixels. Or 0 if not supported.
- */
+ @Override
public int getPhysicalDisplayWidth() {
return mPhysicalSize.x;
}
- /**
- * @return current orientation. One of Surface.ORIENTATION_* values.
- */
+ @Override
public int getRotation() {
return mRotation;
}
- /**
- * @return current orientation in degrees. One of the values 0, 90, 180, 270.
- */
- /* package */ int getRotationDegrees() {
- switch (mRotation) {
- case Surface.ROTATION_0:
- return 0;
- case Surface.ROTATION_90:
- return 90;
- case Surface.ROTATION_180:
- return 180;
- case Surface.ROTATION_270:
- return 270;
- }
-
- // This should not happen.
- assert false;
- return 0;
- }
-
- /**
- * @return A scaling factor for the Density Independent Pixel unit.
- */
+ @Override
public float getDipScale() {
return mDisplayMetrics.density;
}
- /**
- * @return Number of bits per pixel.
- */
+ @Override
/* package */ int getBitsPerPixel() {
return mPixelFormatInfo.bitsPerPixel;
}
- /**
- * @return Number of bits per each color component.
- */
+ @Override
@SuppressWarnings("deprecation")
/* package */ int getBitsPerComponent() {
switch (mPixelFormatId) {
@@ -228,40 +135,8 @@ public class DisplayAndroid {
}
}
- /**
- * Add observer. Note repeat observers will be called only one.
- * Observers are held only weakly by Display.
- */
- public void addObserver(DisplayAndroidObserver observer) {
- mObservers.put(observer, null);
- }
-
- /**
- * Remove observer.
- */
- public void removeObserver(DisplayAndroidObserver observer) {
- mObservers.remove(observer);
- }
-
- /**
- * Toggle the accurate mode if it wasn't already doing so. The backend will
- * keep track of the number of times this has been called.
- */
- public static void startAccurateListening() {
- getManager().startAccurateListening();
- }
-
- /**
- * Request to stop the accurate mode. It will effectively be stopped only if
- * this method is called as many times as startAccurateListening().
- */
- public static void stopAccurateListening() {
- getManager().startAccurateListening();
- }
-
- /* package */ DisplayAndroid(Display display) {
+ /* package */ DisplayAndroidImpl(Display display) {
mSdkDisplayId = display.getDisplayId();
- mObservers = new WeakHashMap<>();
mSize = new Point();
mPhysicalSize = new Point();
mDisplayMetrics = new DisplayMetrics();
@@ -320,9 +195,4 @@ public class DisplayAndroid {
}
}
}
-
- private DisplayAndroidObserver[] getObservers() {
- // Makes a copy to allow concurrent edit.
- return mObservers.keySet().toArray(EMPTY_OBSERVER_ARRAY);
- }
}

Powered by Google App Engine
This is Rietveld 408576698