From 63f1c43fbef157397869475ef30d23e631b88bbe Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 4 Sep 2012 19:29:13 -0700 Subject: [PATCH] update to new SurfaceComposerClient API Change-Id: I8f2c96df56fe3a851b8ec03bb8734db0b6bea3d5 --- core/java/android/view/Surface.java | 37 +++--------- core/jni/android_view_Surface.cpp | 48 +++++---------- .../android/server/display/DisplayDevice.java | 58 +++++++------------ .../server/display/LogicalDisplay.java | 27 ++++----- 4 files changed, 58 insertions(+), 112 deletions(-) diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java index 6616894915fd7..db05e1027323d 100644 --- a/core/java/android/view/Surface.java +++ b/core/java/android/view/Surface.java @@ -262,12 +262,8 @@ public class Surface implements Parcelable { IBinder displayToken, SurfaceTexture surfaceTexture); private static native void nativeSetDisplayLayerStack( IBinder displayToken, int layerStack); - private static native void nativeSetDisplayOrientation( - IBinder displayToken, int orientation); - private static native void nativeSetDisplayViewport( - IBinder displayToken, Rect viewport); - private static native void nativeSetDisplayFrame( - IBinder displayToken, Rect frame); + private static native void nativeSetDisplayProjection( + IBinder displayToken, int orientation, Rect layerStackRect, Rect displayRect); private static native boolean nativeGetDisplayInfo( IBinder displayToken, PhysicalDisplayInfo outInfo); @@ -617,33 +613,18 @@ public class Surface implements Parcelable { } /** @hide */ - public static void setDisplayOrientation(IBinder displayToken, int orientation) { + public static void setDisplayProjection(IBinder displayToken, + int orientation, Rect layerStackRect, Rect displayRect) { if (displayToken == null) { throw new IllegalArgumentException("displayToken must not be null"); } - nativeSetDisplayOrientation(displayToken, orientation); - } - - /** @hide */ - public static void setDisplayViewport(IBinder displayToken, Rect viewport) { - if (displayToken == null) { - throw new IllegalArgumentException("displayToken must not be null"); + if (layerStackRect == null) { + throw new IllegalArgumentException("layerStackRect must not be null"); } - if (viewport == null) { - throw new IllegalArgumentException("viewport must not be null"); + if (displayRect == null) { + throw new IllegalArgumentException("displayRect must not be null"); } - nativeSetDisplayViewport(displayToken, viewport); - } - - /** @hide */ - public static void setDisplayFrame(IBinder displayToken, Rect frame) { - if (displayToken == null) { - throw new IllegalArgumentException("displayToken must not be null"); - } - if (frame == null) { - throw new IllegalArgumentException("frame must not be null"); - } - nativeSetDisplayFrame(displayToken, frame); + nativeSetDisplayProjection(displayToken, orientation, layerStackRect, displayRect); } /** @hide */ diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index 4d5e680cb1293..4fbfab6ecfa8e 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -647,38 +647,24 @@ static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz, SurfaceComposerClient::setDisplayLayerStack(token, layerStack); } -static void nativeSetDisplayOrientation(JNIEnv* env, jclass clazz, - jobject tokenObj, jint orientation) { +static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz, + jobject tokenObj, jint orientation, jobject rect1Obj, jobject rect2Obj) { sp token(ibinderForJavaObject(env, tokenObj)); if (token == NULL) return; - SurfaceComposerClient::setDisplayOrientation(token, orientation); -} + Rect rect1; + rect1.left = env->GetIntField(rect1Obj, gRectClassInfo.left); + rect1.top = env->GetIntField(rect1Obj, gRectClassInfo.top); + rect1.right = env->GetIntField(rect1Obj, gRectClassInfo.right); + rect1.bottom = env->GetIntField(rect1Obj, gRectClassInfo.bottom); -static void nativeSetDisplayViewport(JNIEnv* env, jclass clazz, - jobject tokenObj, jobject rectObj) { - sp token(ibinderForJavaObject(env, tokenObj)); - if (token == NULL) return; + Rect rect2; + rect2.left = env->GetIntField(rect2Obj, gRectClassInfo.left); + rect2.top = env->GetIntField(rect2Obj, gRectClassInfo.top); + rect2.right = env->GetIntField(rect2Obj, gRectClassInfo.right); + rect2.bottom = env->GetIntField(rect2Obj, gRectClassInfo.bottom); - Rect rect; - rect.left = env->GetIntField(rectObj, gRectClassInfo.left); - rect.top = env->GetIntField(rectObj, gRectClassInfo.top); - rect.right = env->GetIntField(rectObj, gRectClassInfo.right); - rect.bottom = env->GetIntField(rectObj, gRectClassInfo.bottom); - SurfaceComposerClient::setDisplayViewport(token, rect); -} - -static void nativeSetDisplayFrame(JNIEnv* env, jclass clazz, - jobject tokenObj, jobject rectObj) { - sp token(ibinderForJavaObject(env, tokenObj)); - if (token == NULL) return; - - Rect rect; - rect.left = env->GetIntField(rectObj, gRectClassInfo.left); - rect.top = env->GetIntField(rectObj, gRectClassInfo.top); - rect.right = env->GetIntField(rectObj, gRectClassInfo.right); - rect.bottom = env->GetIntField(rectObj, gRectClassInfo.bottom); - SurfaceComposerClient::setDisplayFrame(token, rect); + SurfaceComposerClient::setDisplayProjection(token, orientation, rect1, rect2); } static jboolean nativeGetDisplayInfo(JNIEnv* env, jclass clazz, @@ -818,12 +804,8 @@ static JNINativeMethod gSurfaceMethods[] = { (void*)nativeSetDisplaySurface }, {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V", (void*)nativeSetDisplayLayerStack }, - {"nativeSetDisplayOrientation", "(Landroid/os/IBinder;I)V", - (void*)nativeSetDisplayOrientation }, - {"nativeSetDisplayViewport", "(Landroid/os/IBinder;Landroid/graphics/Rect;)V", - (void*)nativeSetDisplayViewport }, - {"nativeSetDisplayFrame", "(Landroid/os/IBinder;Landroid/graphics/Rect;)V", - (void*)nativeSetDisplayFrame }, + {"nativeSetDisplayProjection", "(Landroid/os/IBinder;ILandroid/graphics/Rect;Landroid/graphics/Rect;)V", + (void*)nativeSetDisplayProjection }, {"nativeGetDisplayInfo", "(Landroid/os/IBinder;Landroid/view/Surface$PhysicalDisplayInfo;)Z", (void*)nativeGetDisplayInfo }, {"nativeCopyFrom", "(Landroid/view/Surface;)V", diff --git a/services/java/com/android/server/display/DisplayDevice.java b/services/java/com/android/server/display/DisplayDevice.java index 69d83851f0132..bdc87f929a454 100644 --- a/services/java/com/android/server/display/DisplayDevice.java +++ b/services/java/com/android/server/display/DisplayDevice.java @@ -38,8 +38,8 @@ abstract class DisplayDevice { // the display manager service. The display device shouldn't really be looking at these. private int mCurrentLayerStack = -1; private int mCurrentOrientation = -1; - private Rect mCurrentViewport; - private Rect mCurrentFrame; + private Rect mCurrentLayerStackRect; + private Rect mCurrentDisplayRect; // The display device does own its surface texture, but it should only set it // within a transaction from performTraversalInTransactionLocked. @@ -117,44 +117,26 @@ abstract class DisplayDevice { } /** - * Sets the display orientation while in a transaction. + * Sets the display projection while in a transaction. + * + * @param orientation defines the display's orientation + * @param layerStackRect defines which area of the window manager coordinate + * space will be used + * @param displayRect defines where on the display will layerStackRect be + * mapped to. displayRect is specified post-orientation, that is + * it uses the orientation seen by the end-user */ - public final void setOrientationInTransactionLocked(int orientation) { - if (mCurrentOrientation == orientation) { - return; - } + public final void setProjectionInTransactionLocked(int orientation, Rect layerStackRect, Rect displayRect) { mCurrentOrientation = orientation; - Surface.setDisplayOrientation(mDisplayToken, orientation); - } - - /** - * Sets the display viewport while in a transaction. - */ - public final void setViewportInTransactionLocked(Rect viewport) { - if (mCurrentViewport != null) { - if (mCurrentViewport.equals(viewport)) { - return; - } - } else { - mCurrentViewport = new Rect(); + if (mCurrentLayerStackRect == null) { + mCurrentLayerStackRect = new Rect(); } - mCurrentViewport.set(viewport); - Surface.setDisplayViewport(mDisplayToken, viewport); - } - - /** - * Sets the display frame while in a transaction. - */ - public final void setFrameInTransactionLocked(Rect frame) { - if (mCurrentFrame != null) { - if (mCurrentFrame.equals(frame)) { - return; - } - } else { - mCurrentFrame = new Rect(); + mCurrentLayerStackRect.set(layerStackRect); + if (mCurrentDisplayRect == null) { + mCurrentDisplayRect = new Rect(); } - mCurrentFrame.set(frame); - Surface.setDisplayFrame(mDisplayToken, frame); + mCurrentDisplayRect.set(displayRect); + Surface.setDisplayProjection(mDisplayToken, orientation, layerStackRect, displayRect); } /** @@ -176,8 +158,8 @@ abstract class DisplayDevice { pw.println("mAdapter=" + mDisplayAdapter.getName()); pw.println("mCurrentLayerStack=" + mCurrentLayerStack); pw.println("mCurrentOrientation=" + mCurrentOrientation); - pw.println("mCurrentViewport=" + mCurrentViewport); - pw.println("mCurrentFrame=" + mCurrentFrame); + pw.println("mCurrentViewport=" + mCurrentLayerStackRect); + pw.println("mCurrentFrame=" + mCurrentDisplayRect); pw.println("mCurrentSurfaceTexture=" + mCurrentSurfaceTexture); } } diff --git a/services/java/com/android/server/display/LogicalDisplay.java b/services/java/com/android/server/display/LogicalDisplay.java index 32ca1c513fb79..c864189753d02 100644 --- a/services/java/com/android/server/display/LogicalDisplay.java +++ b/services/java/com/android/server/display/LogicalDisplay.java @@ -64,7 +64,8 @@ final class LogicalDisplay { private DisplayDeviceInfo mPrimaryDisplayDeviceInfo; // Temporary rectangle used when needed. - private final Rect mTempRect = new Rect(); + private final Rect mTempLayerStackRect = new Rect(); + private final Rect mTempDisplayRect = new Rect(); public LogicalDisplay(int layerStack, DisplayDevice primaryDisplayDevice) { mLayerStack = layerStack; @@ -208,8 +209,7 @@ final class LogicalDisplay { // Set the viewport. // This is the area of the logical display that we intend to show on the // display device. For now, it is always the full size of the logical display. - mTempRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); - device.setViewportInTransactionLocked(mTempRect); + mTempLayerStackRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); // Set the orientation. // The orientation specifies how the physical coordinate system of the display @@ -219,7 +219,6 @@ final class LogicalDisplay { && (displayDeviceInfo.flags & DisplayDeviceInfo.FLAG_SUPPORTS_ROTATION) != 0) { orientation = displayInfo.rotation; } - device.setOrientationInTransactionLocked(orientation); // Set the frame. // The frame specifies the rotated physical coordinates into which the viewport @@ -238,21 +237,23 @@ final class LogicalDisplay { // We avoid a division (and possible floating point imprecision) here by // multiplying the fractions by the product of their denominators before // comparing them. - int frameWidth, frameHeight; + int displayRectWidth, displayRectHeight; if (physWidth * displayInfo.logicalHeight < physHeight * displayInfo.logicalWidth) { // Letter box. - frameWidth = physWidth; - frameHeight = displayInfo.logicalHeight * physWidth / displayInfo.logicalWidth; + displayRectWidth = physWidth; + displayRectHeight = displayInfo.logicalHeight * physWidth / displayInfo.logicalWidth; } else { // Pillar box. - frameWidth = displayInfo.logicalWidth * physHeight / displayInfo.logicalHeight; - frameHeight = physHeight; + displayRectWidth = displayInfo.logicalWidth * physHeight / displayInfo.logicalHeight; + displayRectHeight = physHeight; } - int frameTop = (physHeight - frameHeight) / 2; - int frameLeft = (physWidth - frameWidth) / 2; - mTempRect.set(frameLeft, frameTop, frameLeft + frameWidth, frameTop + frameHeight); - device.setFrameInTransactionLocked(mTempRect); + int displayRectTop = (physHeight - displayRectHeight) / 2; + int displayRectLeft = (physWidth - displayRectWidth) / 2; + mTempDisplayRect.set(displayRectLeft, displayRectTop, + displayRectLeft + displayRectWidth, displayRectTop + displayRectHeight); + + device.setProjectionInTransactionLocked(orientation, mTempLayerStackRect, mTempDisplayRect); } public void dumpLocked(PrintWriter pw) {