From 5d9d2ddca2d84f9614a6ccb0b7441d80c4f1e728 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Tue, 26 May 2020 11:29:39 -0700 Subject: [PATCH] WindowlessWindowManager: Set size when creating surface When we set the buffer size from relayout window, there is a race condition where the client may then submit its first buffer but the transaction hasnt applied yet on the SF side and so the buffer is rejected. Setting a defualt size when creating fixes this. Luckily SurfaceControlViewHost size is known at add time, since we force the window size based on the values passed in to the SurfaceControlViewHost API. Bug: 157153874 Test: Existing tests pass Change-Id: I2566844aea81df92f1694f43254a480fc3b3c019 --- .../android/view/WindowlessWindowManager.java | 21 ++++++++++++------- .../java/com/android/server/wm/ShellRoot.java | 1 - 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/java/android/view/WindowlessWindowManager.java b/core/java/android/view/WindowlessWindowManager.java index d20ffb3a6ec11..9b5b8824b0e6b 100644 --- a/core/java/android/view/WindowlessWindowManager.java +++ b/core/java/android/view/WindowlessWindowManager.java @@ -136,6 +136,7 @@ public class WindowlessWindowManager implements IWindowSession { final SurfaceControl.Builder b = new SurfaceControl.Builder(mSurfaceSession) .setParent(mRootSurface) .setFormat(attrs.format) + .setBufferSize(getSurfaceWidth(attrs), getSurfaceHeight(attrs)) .setName(attrs.getTitle().toString()); final SurfaceControl sc = b.build(); @@ -242,13 +243,8 @@ public class WindowlessWindowManager implements IWindowSession { WindowManager.LayoutParams attrs = state.mParams; if (viewFlags == View.VISIBLE) { - final Rect surfaceInsets = attrs.surfaceInsets; - int width = surfaceInsets != null - ? attrs.width + surfaceInsets.left + surfaceInsets.right : attrs.width; - int height = surfaceInsets != null - ? attrs.height + surfaceInsets.top + surfaceInsets.bottom : attrs.height; - - t.setBufferSize(sc, width, height).setOpaque(sc, isOpaque(attrs)).show(sc).apply(); + t.setBufferSize(sc, getSurfaceWidth(attrs), getSurfaceHeight(attrs)) + .setOpaque(sc, isOpaque(attrs)).show(sc).apply(); outSurfaceControl.copyFrom(sc); } else { t.hide(sc).apply(); @@ -444,4 +440,15 @@ public class WindowlessWindowManager implements IWindowSession { public android.os.IBinder asBinder() { return null; } + + private int getSurfaceWidth(WindowManager.LayoutParams attrs) { + final Rect surfaceInsets = attrs.surfaceInsets; + return surfaceInsets != null + ? attrs.width + surfaceInsets.left + surfaceInsets.right : attrs.width; + } + private int getSurfaceHeight(WindowManager.LayoutParams attrs) { + final Rect surfaceInsets = attrs.surfaceInsets; + return surfaceInsets != null + ? attrs.height + surfaceInsets.top + surfaceInsets.bottom : attrs.height; + } } diff --git a/services/core/java/com/android/server/wm/ShellRoot.java b/services/core/java/com/android/server/wm/ShellRoot.java index 99f710bd8bd46..7a38bb65f73b6 100644 --- a/services/core/java/com/android/server/wm/ShellRoot.java +++ b/services/core/java/com/android/server/wm/ShellRoot.java @@ -156,4 +156,3 @@ public class ShellRoot { } } } -