diff options
author | Jeff Brown <jeffbrown@google.com> | 2011-07-27 15:54:50 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-07-27 15:54:50 -0700 |
commit | 3d5a703db83265f7914eed8580de986106abfad2 (patch) | |
tree | 3ef1e72cf1335a1bb9d36ac1b6f86f0a1b84c302 /core | |
parent | be922d6006879692d100894dc924d947b50aed34 (diff) | |
parent | bc68a59c024bdb745dac8e2ec7408a9f30595f1a (diff) | |
download | frameworks_base-3d5a703db83265f7914eed8580de986106abfad2.zip frameworks_base-3d5a703db83265f7914eed8580de986106abfad2.tar.gz frameworks_base-3d5a703db83265f7914eed8580de986106abfad2.tar.bz2 |
Merge "Report the external display size to the input reader."
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/view/Display.java | 163 | ||||
-rw-r--r-- | core/java/android/view/IWindowManager.aidl | 1 | ||||
-rw-r--r-- | core/java/android/view/ViewRootImpl.java | 12 | ||||
-rw-r--r-- | core/jni/android_view_Display.cpp | 51 |
4 files changed, 121 insertions, 106 deletions
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java index 5ab2024..d9efe0c 100644 --- a/core/java/android/view/Display.java +++ b/core/java/android/view/Display.java @@ -25,16 +25,18 @@ import android.os.SystemClock; import android.util.DisplayMetrics; import android.util.Slog; +/** + * Provides information about the display size and density. + */ public class Display { static final String TAG = "Display"; static final boolean DEBUG_COMPAT = false; /** - * Specify the default Display + * The default Display id. */ public static final int DEFAULT_DISPLAY = 0; - /** * Use {@link android.view.WindowManager#getDefaultDisplay() * WindowManager.getDefaultDisplay()} to create a Display object. @@ -55,16 +57,6 @@ public class Display { init(display); } - /** @hide */ - public static void setCompatibilityInfo(CompatibilityInfo compatInfo) { - if (compatInfo != null && (compatInfo.isScalingRequired() - || !compatInfo.supportsScreen())) { - sCompatibilityInfo = compatInfo; - } else { - sCompatibilityInfo = null; - } - } - /** * Returns the index of this display. This is currently undefined; do * not use. @@ -80,25 +72,29 @@ public class Display { native static int getDisplayCount(); /** - * Returns the raw size of the display, in pixels. Note that this - * should <em>not</em> generally be used for computing layouts, since - * a device will typically have screen decoration (such as a status bar) + * Gets the size of the display, in pixels. + * <p> + * Note that this value should <em>not</em> be used for computing layouts, + * since a device will typically have screen decoration (such as a status bar) * along the edges of the display that reduce the amount of application - * space available from the raw size returned here. This value is - * adjusted for you based on the current rotation of the display. + * space available from the size returned here. Layouts should instead use + * the window size. + * </p><p> + * The size is adjusted based on the current rotation of the display. + * </p><p> + * The size returned by this method does not necessarily represent the + * actual raw size (native resolution) of the display. The returned size may + * be adjusted to exclude certain system decor elements that are always visible. + * It may also be scaled to provide compatibility with older applications that + * were originally designed for smaller displays. + * </p> + * + * @param outSize A {@link Point} object to receive the size information. */ public void getSize(Point outSize) { getSizeInternal(outSize, true); } - /** - * Returns the raw size of the display, in pixels. Note that this - * should <em>not</em> generally be used for computing layouts, since - * a device will typically have screen decoration (such as a status bar) - * along the edges of the display that reduce the amount of application - * space available from the raw size returned here. This value is - * adjusted for you based on the current rotation of the display. - */ private void getSizeInternal(Point outSize, boolean doCompat) { try { IWindowManager wm = getWindowManager(); @@ -118,8 +114,8 @@ public class Display { } else { // This is just for boot-strapping, initializing the // system process before the window manager is up. - outSize.x = getRealWidth(); - outSize.y = getRealHeight(); + outSize.x = getRawWidth(); + outSize.y = getRawHeight(); } if (DEBUG_COMPAT && doCompat) Slog.v(TAG, "Returning display size: " + outSize); } catch (RemoteException e) { @@ -128,7 +124,10 @@ public class Display { } /** - * This is just easier for some parts of the framework. + * Gets the size of the display as a rectangle, in pixels. + * + * @param outSize A {@link Rect} object to receive the size information. + * @see #getSize(Point) */ public void getRectSize(Rect outSize) { synchronized (mTmpPoint) { @@ -182,14 +181,49 @@ public class Display { } } - /** @hide Returns the actual screen size, not including any decor. */ - native public int getRealWidth(); - /** @hide Returns the actual screen size, not including any decor. */ - native public int getRealHeight(); + /** + * Gets the real size of the display without subtracting any window decor or + * applying any compatibility scale factors. + * <p> + * The real size may be smaller than the raw size when the window manager + * is emulating a smaller display (using adb shell am display-size). + * </p><p> + * The size is adjusted based on the current rotation of the display. + * </p> + * @hide + */ + public void getRealSize(Point outSize) { + try { + IWindowManager wm = getWindowManager(); + if (wm != null) { + wm.getRealDisplaySize(outSize); + } else { + // This is just for boot-strapping, initializing the + // system process before the window manager is up. + outSize.x = getRawWidth(); + outSize.y = getRawHeight(); + } + } catch (RemoteException e) { + Slog.w("Display", "Unable to get real display size", e); + } + } - /** @hide special for when we are faking the screen size. */ + /** + * Gets the raw width of the display, in pixels. + * <p> + * The size is adjusted based on the current rotation of the display. + * </p> + * @hide + */ native public int getRawWidth(); - /** @hide special for when we are faking the screen size. */ + + /** + * Gets the raw height of the display, in pixels. + * <p> + * The size is adjusted based on the current rotation of the display. + * </p> + * @hide + */ native public int getRawHeight(); /** @@ -235,17 +269,24 @@ public class Display { } /** - * Initialize a DisplayMetrics object from this display's data. - * - * @param outMetrics + * Gets display metrics that describe the size and density of this display. + * <p> + * The size is adjusted based on the current rotation of the display. + * </p><p> + * The size returned by this method does not necessarily represent the + * actual raw size (native resolution) of the display. The returned size may + * be adjusted to exclude certain system decor elements that are always visible. + * It may also be scaled to provide compatibility with older applications that + * were originally designed for smaller displays. + * </p> + * + * @param outMetrics A {@link DisplayMetrics} object to receive the metrics. */ public void getMetrics(DisplayMetrics outMetrics) { synchronized (mTmpPoint) { getSizeInternal(mTmpPoint, false); - outMetrics.widthPixels = mTmpPoint.x; - outMetrics.heightPixels = mTmpPoint.y; + getMetricsWithSize(outMetrics, mTmpPoint.x, mTmpPoint.y); } - getNonSizeMetrics(outMetrics); CompatibilityInfo ci = mCompatibilityInfo.getIfNeeded(); if (ci != null) { @@ -257,22 +298,44 @@ public class Display { } /** - * Initialize a DisplayMetrics object from this display's data. - * - * @param outMetrics + * Gets display metrics based on the real size of this display. * @hide */ public void getRealMetrics(DisplayMetrics outMetrics) { - outMetrics.widthPixels = getRealWidth(); - outMetrics.heightPixels = getRealHeight(); - getNonSizeMetrics(outMetrics); + synchronized (mTmpPoint) { + getRealSize(mTmpPoint); + getMetricsWithSize(outMetrics, mTmpPoint.x, mTmpPoint.y); + } + } + + /** + * If the display is mirrored to an external HDMI display, returns the + * width of that display. + * @hide + */ + public int getRawExternalWidth() { + return 1280; + } + + /** + * If the display is mirrored to an external HDMI display, returns the + * height of that display. + * @hide + */ + public int getRawExternalHeight() { + return 720; } - private void getNonSizeMetrics(DisplayMetrics outMetrics) { + /** + * Gets display metrics based on an explicit assumed display size. + * @hide + */ + public void getMetricsWithSize(DisplayMetrics outMetrics, + int width, int height) { outMetrics.densityDpi = (int)((mDensity*DisplayMetrics.DENSITY_DEFAULT)+.5f); - outMetrics.noncompatWidthPixels = outMetrics.widthPixels; - outMetrics.noncompatHeightPixels = outMetrics.heightPixels; + outMetrics.noncompatWidthPixels = outMetrics.widthPixels = width; + outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height; outMetrics.density = outMetrics.noncompatDensity = mDensity; outMetrics.scaledDensity = outMetrics.noncompatScaledDensity = outMetrics.density; @@ -315,8 +378,6 @@ public class Display { private static boolean sInitialized = false; private static IWindowManager sWindowManager; - private static volatile CompatibilityInfo sCompatibilityInfo; - /** * Returns a display object which uses the metric's width/height instead. * @hide diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index ad17edf..81cd798 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -55,6 +55,7 @@ interface IWindowManager boolean inputMethodClientHasFocus(IInputMethodClient client); void getDisplaySize(out Point size); + void getRealDisplaySize(out Point size); int getMaximumSizeDimension(); void setForcedDisplaySize(int longDimen, int shortDimen); diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 35a40fc..54e02a7 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -825,8 +825,10 @@ public final class ViewRootImpl extends Handler implements ViewParent, if (lp.type == WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL) { // NOTE -- system code, won't try to do compat mode. Display disp = WindowManagerImpl.getDefault().getDefaultDisplay(); - desiredWindowWidth = disp.getRealWidth(); - desiredWindowHeight = disp.getRealHeight(); + Point size = new Point(); + disp.getRealSize(size); + desiredWindowWidth = size.x; + desiredWindowHeight = size.y; } else { DisplayMetrics packageMetrics = mView.getContext().getResources().getDisplayMetrics(); @@ -980,8 +982,10 @@ public final class ViewRootImpl extends Handler implements ViewParent, if (lp.type == WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL) { // NOTE -- system code, won't try to do compat mode. Display disp = WindowManagerImpl.getDefault().getDefaultDisplay(); - desiredWindowWidth = disp.getRealWidth(); - desiredWindowHeight = disp.getRealHeight(); + Point size = new Point(); + disp.getRealSize(size); + desiredWindowWidth = size.x; + desiredWindowHeight = size.y; } else { DisplayMetrics packageMetrics = res.getDisplayMetrics(); desiredWindowWidth = packageMetrics.widthPixels; diff --git a/core/jni/android_view_Display.cpp b/core/jni/android_view_Display.cpp index 97f9fc3..5e668b9 100644 --- a/core/jni/android_view_Display.cpp +++ b/core/jni/android_view_Display.cpp @@ -45,11 +45,6 @@ struct offsets_t { }; static offsets_t offsets; -static int gShortSize = -1; -static int gLongSize = -1; -static int gOldSize = -1; -static int gNewSize = -1; - // ---------------------------------------------------------------------------- static void android_view_Display_init( @@ -68,30 +63,6 @@ static void android_view_Display_init( env->SetFloatField(clazz, offsets.ydpi, info.ydpi); } -static jint android_view_Display_getWidth( - JNIEnv* env, jobject clazz) -{ - DisplayID dpy = env->GetIntField(clazz, offsets.display); - jint w = SurfaceComposerClient::getDisplayWidth(dpy); - if (gShortSize > 0) { - jint h = SurfaceComposerClient::getDisplayHeight(dpy); - return w < h ? gShortSize : gLongSize; - } - return w == gOldSize ? gNewSize : w; -} - -static jint android_view_Display_getHeight( - JNIEnv* env, jobject clazz) -{ - DisplayID dpy = env->GetIntField(clazz, offsets.display); - int h = SurfaceComposerClient::getDisplayHeight(dpy); - if (gShortSize > 0) { - jint w = SurfaceComposerClient::getDisplayWidth(dpy); - return h < w ? gShortSize : gLongSize; - } - return h == gOldSize ? gNewSize : h; -} - static jint android_view_Display_getRawWidth( JNIEnv* env, jobject clazz) { @@ -132,10 +103,6 @@ static JNINativeMethod gMethods[] = { (void*)android_view_Display_getDisplayCount }, { "init", "(I)V", (void*)android_view_Display_init }, - { "getRealWidth", "()I", - (void*)android_view_Display_getWidth }, - { "getRealHeight", "()I", - (void*)android_view_Display_getHeight }, { "getRawWidth", "()I", (void*)android_view_Display_getRawWidth }, { "getRawHeight", "()I", @@ -156,24 +123,6 @@ void nativeClassInit(JNIEnv* env, jclass clazz) int register_android_view_Display(JNIEnv* env) { - char buf[PROPERTY_VALUE_MAX]; - int len = property_get("persist.demo.screensizehack", buf, ""); - if (len > 0) { - int temp1, temp2; - if (sscanf(buf, "%dx%d", &temp1, &temp2) == 2) { - if (temp1 < temp2) { - gShortSize = temp1; - gLongSize = temp2; - } else { - gShortSize = temp2; - gLongSize = temp1; - } - } else if (sscanf(buf, "%d=%d", &temp1, &temp2) == 2) { - gOldSize = temp1; - gNewSize = temp2; - } - } - return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); } |