summaryrefslogtreecommitdiffstats
path: root/core/java/android/hardware/display/DisplayManager.java
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-08-19 20:30:52 -0700
committerJeff Brown <jeffbrown@google.com>2012-08-19 22:42:08 -0700
commit98365d7663cbd82979a5700faf0050220b01084d (patch)
tree8a4ff3e0a8afd814ed29609b26aa1c6ade2367f6 /core/java/android/hardware/display/DisplayManager.java
parent848c2dc93b6795e171f3dd6f64ea0be65e2762ca (diff)
downloadframeworks_base-98365d7663cbd82979a5700faf0050220b01084d.zip
frameworks_base-98365d7663cbd82979a5700faf0050220b01084d.tar.gz
frameworks_base-98365d7663cbd82979a5700faf0050220b01084d.tar.bz2
Refactor for multi-display support.
Split WindowManagerImpl into two parts, the WindowManager interface implementation remains where it is but the global communications with the window manager are now handled by the WindowManagerGlobal class. This change greatly simplifies the challenge of having separate WindowManager instances for each Context. Removed WindowManagerImpl.getDefault(). This represents the bulk of this change. Most of the usages of this method were either to perform global functions (now handled by WindowManagerGlobal) or to obtain the default display (now handled by DisplayManager). Explicitly associate each new window with a display and make the Display object available to the View hierarchy. Add stubs for some new display manager API features. Start to split apart the concepts of display id and layer stack. since they operate at different layers of abstraction. While it's true that each logical display uniquely corresponds to a surface flinger layer stack, it is not necessarily the case that they must use the same ids. Added Display.getLayerStack() and started using it in places where it was relatively easy to do. Change-Id: I29ed909114dec86807c4d3a5059c3fa0358bea61
Diffstat (limited to 'core/java/android/hardware/display/DisplayManager.java')
-rw-r--r--core/java/android/hardware/display/DisplayManager.java176
1 files changed, 176 insertions, 0 deletions
diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java
index dc79710..a73115c 100644
--- a/core/java/android/hardware/display/DisplayManager.java
+++ b/core/java/android/hardware/display/DisplayManager.java
@@ -17,12 +17,20 @@
package android.hardware.display;
import android.content.Context;
+import android.os.Handler;
import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
+import android.util.SparseArray;
+import android.view.CompatibilityInfoHolder;
+import android.view.Display;
import android.view.DisplayInfo;
+import java.util.ArrayList;
+
/**
* Manages the properties, media routing and power state of attached displays.
* <p>
@@ -34,11 +42,22 @@ import android.view.DisplayInfo;
*/
public final class DisplayManager {
private static final String TAG = "DisplayManager";
+ private static final boolean DEBUG = false;
+
+ private static final int MSG_DISPLAY_ADDED = 1;
+ private static final int MSG_DISPLAY_REMOVED = 2;
+ private static final int MSG_DISPLAY_CHANGED = 3;
private static DisplayManager sInstance;
private final IDisplayManager mDm;
+ // Guarded by mDisplayLock
+ private final Object mDisplayLock = new Object();
+ private final ArrayList<DisplayListenerDelegate> mDisplayListeners =
+ new ArrayList<DisplayListenerDelegate>();
+
+
private DisplayManager(IDisplayManager dm) {
mDm = dm;
}
@@ -79,4 +98,161 @@ public final class DisplayManager {
return false;
}
}
+
+ /**
+ * Gets information about a logical display.
+ *
+ * The display metrics may be adjusted to provide compatibility
+ * for legacy applications.
+ *
+ * @param displayId The logical display id.
+ * @param applicationContext The application context from which to obtain
+ * compatible metrics.
+ * @return The display object.
+ */
+ public Display getDisplay(int displayId, Context applicationContext) {
+ if (applicationContext == null) {
+ throw new IllegalArgumentException("applicationContext must not be null");
+ }
+
+ CompatibilityInfoHolder cih = null;
+ if (displayId == Display.DEFAULT_DISPLAY) {
+ cih = applicationContext.getCompatibilityInfo();
+ }
+ return getCompatibleDisplay(displayId, cih);
+ }
+
+ /**
+ * Gets information about a logical display.
+ *
+ * The display metrics may be adjusted to provide compatibility
+ * for legacy applications.
+ *
+ * @param displayId The logical display id.
+ * @param cih The compatibility info, or null if none is required.
+ * @return The display object.
+ *
+ * @hide
+ */
+ public Display getCompatibleDisplay(int displayId, CompatibilityInfoHolder cih) {
+ return new Display(displayId, cih);
+ }
+
+ /**
+ * Gets information about a logical display without applying any compatibility metrics.
+ *
+ * @param displayId The logical display id.
+ * @return The display object.
+ *
+ * @hide
+ */
+ public Display getRealDisplay(int displayId) {
+ return getCompatibleDisplay(displayId, null);
+ }
+
+ /**
+ * Registers an display listener to receive notifications about when
+ * displays are added, removed or changed.
+ *
+ * @param listener The listener to register.
+ * @param handler The handler on which the listener should be invoked, or null
+ * if the listener should be invoked on the calling thread's looper.
+ *
+ * @see #unregisterDisplayListener
+ */
+ public void registerDisplayListener(DisplayListener listener, Handler handler) {
+ if (listener == null) {
+ throw new IllegalArgumentException("listener must not be null");
+ }
+
+ synchronized (mDisplayLock) {
+ int index = findDisplayListenerLocked(listener);
+ if (index < 0) {
+ mDisplayListeners.add(new DisplayListenerDelegate(listener, handler));
+ }
+ }
+ }
+
+ /**
+ * Unregisters an input device listener.
+ *
+ * @param listener The listener to unregister.
+ *
+ * @see #registerDisplayListener
+ */
+ public void unregisterDisplayListener(DisplayListener listener) {
+ if (listener == null) {
+ throw new IllegalArgumentException("listener must not be null");
+ }
+
+ synchronized (mDisplayLock) {
+ int index = findDisplayListenerLocked(listener);
+ if (index >= 0) {
+ DisplayListenerDelegate d = mDisplayListeners.get(index);
+ d.removeCallbacksAndMessages(null);
+ mDisplayListeners.remove(index);
+ }
+ }
+ }
+
+ private int findDisplayListenerLocked(DisplayListener listener) {
+ final int numListeners = mDisplayListeners.size();
+ for (int i = 0; i < numListeners; i++) {
+ if (mDisplayListeners.get(i).mListener == listener) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Listens for changes in available display devices.
+ */
+ public interface DisplayListener {
+ /**
+ * Called whenever a logical display has been added to the system.
+ * Use {@link DisplayManager#getDisplay} to get more information about the display.
+ *
+ * @param displayId The id of the logical display that was added.
+ */
+ void onDisplayAdded(int displayId);
+
+ /**
+ * Called whenever a logical display has been removed from the system.
+ *
+ * @param displayId The id of the logical display that was removed.
+ */
+ void onDisplayRemoved(int displayId);
+
+ /**
+ * Called whenever the properties of a logical display have changed.
+ *
+ * @param displayId The id of the logical display that changed.
+ */
+ void onDisplayChanged(int displayId);
+ }
+
+ private static final class DisplayListenerDelegate extends Handler {
+ public final DisplayListener mListener;
+
+ public DisplayListenerDelegate(DisplayListener listener, Handler handler) {
+ super(handler != null ? handler.getLooper() : Looper.myLooper());
+ mListener = listener;
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_DISPLAY_ADDED:
+ mListener.onDisplayAdded(msg.arg1);
+ break;
+ case MSG_DISPLAY_REMOVED:
+ mListener.onDisplayRemoved(msg.arg1);
+ break;
+ case MSG_DISPLAY_CHANGED:
+ mListener.onDisplayChanged(msg.arg1);
+ break;
+ }
+ }
+ }
}