From 0b10c335c72cb610e71432a61f315e7670b9af41 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Tue, 29 Mar 2016 13:15:41 -0700 Subject: [PATCH] Ensure we change SurfaceView size from UI thread. We need to change the SurfaceView size from the UI thread so that we can appropriately deliver the SurfaceChanged callback. We also need to not preserve geometry in this case, as if we don't update the surface and layout size together we could get scaling. This still has some potential for holes, as transactions are not synced with the parent renderer, but we have other methods to avoid these in the case of resizing. This fixes the remaining issues with content sizing and surface view "out of sync". Bug: 27780983 Bug: 27687126 Bug: 27676101 Change-Id: Idd7864f00e5cf7a4eb32dd66c0b389292a788069 --- core/java/android/view/IWindowSession.aidl | 3 --- core/java/android/view/SurfaceView.java | 16 +--------------- .../core/java/com/android/server/wm/Session.java | 2 -- .../android/server/wm/WindowManagerService.java | 2 -- .../bridge/android/BridgeWindowSession.java | 1 - 5 files changed, 1 insertion(+), 23 deletions(-) diff --git a/core/java/android/view/IWindowSession.aidl b/core/java/android/view/IWindowSession.aidl index a1e2e946c48ad..8e1609c587a3e 100644 --- a/core/java/android/view/IWindowSession.aidl +++ b/core/java/android/view/IWindowSession.aidl @@ -116,14 +116,11 @@ interface IWindowSession { * @param top The new top position * @param right The new right position * @param bottom The new bottom position - * @param requestedWidth The new requested width - * @param requestedHeight The new requested height * @param deferTransactionUntilFrame Frame number from our parent (attached) to * defer this action until. * @param outFrame Rect in which is placed the new position/size on screen. */ void repositionChild(IWindow childWindow, int left, int top, int right, int bottom, - int requestedWidth, int requestedHeight, long deferTransactionUntilFrame, out Rect outFrame); /* diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 477ffd9b5ba41..8a8fb43cc3d41 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -490,7 +490,7 @@ public class SurfaceView extends View { | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE ; - if (!creating && !force && !mUpdateWindowNeeded) { + if (!creating && !force && !mUpdateWindowNeeded && !sizeChanged) { mLayout.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_PRESERVE_GEOMETRY; } else { @@ -584,18 +584,6 @@ public class SurfaceView extends View { mSurface.transferFrom(mNewSurface); if (visible && mSurface.isValid()) { - // We set SCALING_MODE_NO_SCALE_CROP to allow the WindowManager - // to update our Surface crop without requiring a new buffer from - // us. In the default mode of SCALING_MODE_FREEZE, surface geometry - // state (which includes crop) is only applied when a buffer - // with appropriate geometry is available. During drag resize - // it is quite frequent that a matching buffer will not be available - // (because we are constantly being resized and have fallen behind). - // However in such situations the WindowManager still needs to be able - // to update our crop to ensure we stay within the bounds of the containing - // window. - mSurface.setScalingMode(Surface.SCALING_MODE_NO_SCALE_CROP); - if (!mSurfaceCreated && (surfaceChanged || visibleChanged)) { mSurfaceCreated = true; mIsCreating = true; @@ -666,7 +654,6 @@ public class SurfaceView extends View { mLocation[0], mLocation[1])); mSession.repositionChild(mWindow, mWindowSpaceLeft, mWindowSpaceTop, mLocation[0], mLocation[1], - mWindowSpaceWidth, mWindowSpaceHeight, -1, mWinFrame); } catch (RemoteException ex) { Log.e(TAG, "Exception from relayout", ex); @@ -703,7 +690,6 @@ public class SurfaceView extends View { } // Just using mRTLastReportedPosition as a dummy rect here session.repositionChild(window, left, top, right, bottom, - mWindowSpaceWidth, mWindowSpaceHeight, frameNumber, mRTLastReportedPosition); // Now overwrite mRTLastReportedPosition with our values diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java index c0c1ed8e2d0c9..daeb860e2ef53 100644 --- a/services/core/java/com/android/server/wm/Session.java +++ b/services/core/java/com/android/server/wm/Session.java @@ -195,10 +195,8 @@ final class Session extends IWindowSession.Stub @Override public void repositionChild(IWindow window, int left, int top, int right, int bottom, - int requestedWidth, int requestedHeight, long deferTransactionUntilFrame, Rect outFrame) { mService.repositionChild(this, window, left, top, right, bottom, - requestedWidth, requestedHeight, deferTransactionUntilFrame, outFrame); } diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 5771d691c6948..a3e7976fe6dbe 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -2531,7 +2531,6 @@ public class WindowManagerService extends IWindowManager.Stub void repositionChild(Session session, IWindow client, int left, int top, int right, int bottom, - int requestedWidth, int requestedHeight, long deferTransactionUntilFrame, Rect outFrame) { Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "repositionChild"); long origId = Binder.clearCallingIdentity(); @@ -2547,7 +2546,6 @@ public class WindowManagerService extends IWindowManager.Stub "repositionChild called but window is not" + "attached to a parent win=" + win); } - win.setRequestedSize(requestedWidth, requestedHeight); win.mAttrs.x = left; win.mAttrs.y = top; diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java index 53adb41af0cb4..5a6a00fc3985d 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowSession.java @@ -97,7 +97,6 @@ public final class BridgeWindowSession implements IWindowSession { @Override public void repositionChild(IWindow window, int left, int top, int right, int bottom, - int requestedWidth, int requestedHeight, long deferTransactionUntilFrame, Rect outFrame) { // pass for now. return;