From 7da389fc6c20007bee55fd9d5092d02d2a0b3e6a Mon Sep 17 00:00:00 2001 From: chaviw Date: Thu, 24 Jun 2021 16:19:04 -0500 Subject: [PATCH] Flush mPostDrawTransaction when WSA is torn down When ViewRootImpl gets a sync request from WM, it will wait until it gets a transaction complete callback before continuing. This means WM must apply the transaction that contains the buffer. In this case, the finishDraw was racing the WSA getting marked as hidden. When WSA is hidden, we don't apply the transaction right away in case we want to synchronize with some initial properties. So for this case, the buffer was never getting submitted. Instead, apply mPostDrawTransaction when the WSA SurfaceControl is getting destroyed to ensure we don't leave any pending transactions when getitng torn down. Test: Pip, rotate to landscape, dismiss, re-open app in portrait Fixes: 191151909 Change-Id: I00606c0ed250a10e1651c403665f39be52e9a89e --- .../android/server/wm/WindowStateAnimator.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java index 4471f6c91190d..80941961cc5ac 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -16,12 +16,6 @@ package com.android.server.wm; -import static android.graphics.Matrix.MSCALE_X; -import static android.graphics.Matrix.MSCALE_Y; -import static android.graphics.Matrix.MSKEW_X; -import static android.graphics.Matrix.MSKEW_Y; -import static android.graphics.Matrix.MTRANS_X; -import static android.graphics.Matrix.MTRANS_Y; import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; @@ -54,14 +48,12 @@ import static com.android.server.wm.WindowStateAnimatorProto.SURFACE; import static com.android.server.wm.WindowStateAnimatorProto.SYSTEM_DECOR_RECT; import android.content.Context; -import android.graphics.Matrix; import android.graphics.PixelFormat; import android.graphics.Rect; import android.os.Debug; import android.os.Trace; import android.util.Slog; import android.util.proto.ProtoOutputStream; -import android.view.DisplayInfo; import android.view.Surface.OutOfResourcesException; import android.view.SurfaceControl; import android.view.WindowManager; @@ -260,7 +252,10 @@ class WindowStateAnimator { } if (postDrawTransaction != null) { - if (mLastHidden) { + // If there is no surface, the last draw was for the previous surface. We don't want to + // wait until the new surface is shown and instead just apply the transaction right + // away. + if (mLastHidden && mDrawState != NO_SURFACE) { mPostDrawTransaction.merge(postDrawTransaction); layoutNeeded = true; } else { @@ -830,6 +825,10 @@ class WindowStateAnimator { } void destroySurface(SurfaceControl.Transaction t) { + // Since the SurfaceControl is getting torn down, it's safe to just clean up any + // pending transactions that were in mPostDrawTransaction, as well. + t.merge(mPostDrawTransaction); + try { if (mSurfaceController != null) { mSurfaceController.destroy(t);