Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bfc2f8f6 authored by Chong Zhang's avatar Chong Zhang
Browse files

Some fixes for saved surfaces

- If we have a saved surface, and app relayouts to visible before we
  started entry animation, we need to restore the saved surfaces.
  Otherwise the surface might get stuck in the saved state, because
  we may not get to run any animation after this relayout.

- Keep track of the allDrawn while we're using the saved surfaces,
  so that we can rely on allDrawn itself, instead of whether we're
  using saved surfaces.

- If the app is set to visible when it's exiting, clear the exiting
  flags. Also, save the surface if we cancel an exiting animation.

- More debug logging.

bug: 26819496
Change-Id: Ie42c6eea7879632d82f24ed09c3b6e737dd6d8a4
parent 2c0348ff
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -339,8 +339,7 @@ public class AppWindowAnimator {
                return false;
                return false;
            }
            }


            if ((mAppToken.allDrawn || mAppToken.mAnimatingWithSavedSurface
            if ((mAppToken.allDrawn || animating || mAppToken.startingDisplayed)
                    || animating || mAppToken.startingDisplayed)
                    && animation != null) {
                    && animation != null) {
                if (!animating) {
                if (!animating) {
                    if (DEBUG_ANIM) Slog.v(TAG,
                    if (DEBUG_ANIM) Slog.v(TAG,
+26 −12
Original line number Original line Diff line number Diff line
@@ -299,10 +299,10 @@ class AppWindowToken extends WindowToken {
        }
        }
    }
    }


    void markSurfacesExiting() {
    void setWindowsExiting(boolean exiting) {
        for (int i = allAppWindows.size() - 1; i >= 0; i--) {
        for (int i = allAppWindows.size() - 1; i >= 0; i--) {
            WindowState win = allAppWindows.get(i);
            WindowState win = allAppWindows.get(i);
            win.mExiting = true;
            win.mExiting = exiting;
        }
        }
    }
    }


@@ -312,11 +312,11 @@ class AppWindowToken extends WindowToken {
     * @return true if the surfaces should be saved, false otherwise.
     * @return true if the surfaces should be saved, false otherwise.
     */
     */
    boolean shouldSaveSurface() {
    boolean shouldSaveSurface() {
        // We want to save surface if the app's windows are "allDrawn", or if we're
        // We want to save surface if the app's windows are "allDrawn".
        // currently animating with save surfaces. (If the app didn't even finish
        // (If we started entering animation early with saved surfaces, allDrawn
        // drawing when the user exits, but we have a saved surface from last time,
        // should have been restored to true. So we'll save again in that case
        // we still want to keep that surface.)
        // even if app didn't actually finish drawing.)
        return allDrawn || mAnimatingWithSavedSurface;
        return allDrawn;
    }
    }


    boolean hasSavedSurface() {
    boolean hasSavedSurface() {
@@ -334,13 +334,26 @@ class AppWindowToken extends WindowToken {
            return;
            return;
        }
        }
        mAnimatingWithSavedSurface = true;
        mAnimatingWithSavedSurface = true;

        // Check if we have enough drawn windows to mark allDrawn= true.
        int numInteresting = 0;
        int numDrawn = 0;
        for (int i = windows.size() - 1; i >= 0; i--) {
        for (int i = windows.size() - 1; i >= 0; i--) {
            WindowState ws = windows.get(i);
            WindowState w = windows.get(i);
            ws.restoreSavedSurface();
            w.restoreSavedSurface();
            if (w != startingWindow && !w.mAppDied
                    && (!mAppAnimator.freezingScreen || !w.mAppFreezing)) {
                numInteresting++;
                if (w.isDrawnLw()) {
                    numDrawn++;
                }
                }
        // Mark the app allDrawn since it must be allDrawn at the time
            }
        // it was first saved.
        }
        allDrawn = true;

        allDrawn |= (numInteresting == numDrawn);

        if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
                "restoreSavedSurfaces: " + appWindowToken + " allDrawn=" + allDrawn);
    }
    }


    void destroySavedSurfaces() {
    void destroySavedSurfaces() {
@@ -348,6 +361,7 @@ class AppWindowToken extends WindowToken {
            WindowState win = windows.get(i);
            WindowState win = windows.get(i);
            win.destroySavedSurface();
            win.destroySavedSurface();
        }
        }
        mAnimatingWithSavedSurface = false;
    }
    }


    @Override
    @Override
+1 −1
Original line number Original line Diff line number Diff line
@@ -428,7 +428,7 @@ public class WindowAnimator {


            final AppWindowToken atoken = win.mAppToken;
            final AppWindowToken atoken = win.mAppToken;
            if (winAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW) {
            if (winAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW) {
                if (atoken == null || atoken.allDrawn || atoken.mAnimatingWithSavedSurface) {
                if (atoken == null || atoken.allDrawn) {
                    if (winAnimator.performShowLocked()) {
                    if (winAnimator.performShowLocked()) {
                        setPendingLayoutChanges(displayId,
                        setPendingLayoutChanges(displayId,
                                WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
                                WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
+13 −2
Original line number Original line Diff line number Diff line
@@ -2691,7 +2691,17 @@ public class WindowManagerService extends IWindowManager.Stub
            } else {
            } else {
                winAnimator.mEnterAnimationPending = false;
                winAnimator.mEnterAnimationPending = false;
                winAnimator.mEnteringAnimation = false;
                winAnimator.mEnteringAnimation = false;
                if (winAnimator.hasSurface() && !win.mExiting) {
                final boolean usingSavedSurfaceBeforeVisible =
                        oldVisibility != View.VISIBLE && win.isAnimatingWithSavedSurface();
                if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
                    if (winAnimator.hasSurface() && !win.mExiting
                            && usingSavedSurfaceBeforeVisible) {
                        Slog.d(TAG, "Ignoring layout to invisible when using saved surface " + win);
                    }
                }

                if (winAnimator.hasSurface() && !win.mExiting
                        && !usingSavedSurfaceBeforeVisible) {
                    if (DEBUG_VISIBILITY) Slog.i(TAG_WM, "Relayout invis " + win
                    if (DEBUG_VISIBILITY) Slog.i(TAG_WM, "Relayout invis " + win
                            + ": mExiting=" + win.mExiting);
                            + ": mExiting=" + win.mExiting);
                    // If we are not currently running the exit animation, we
                    // If we are not currently running the exit animation, we
@@ -4219,6 +4229,7 @@ public class WindowManagerService extends IWindowManager.Stub
                }
                }
                wtoken.inPendingTransaction = true;
                wtoken.inPendingTransaction = true;
                if (visible) {
                if (visible) {
                    wtoken.setWindowsExiting(false);
                    mOpeningApps.add(wtoken);
                    mOpeningApps.add(wtoken);
                    wtoken.startingMoved = false;
                    wtoken.startingMoved = false;
                    wtoken.mEnteringAnimation = true;
                    wtoken.mEnteringAnimation = true;
@@ -4243,7 +4254,7 @@ public class WindowManagerService extends IWindowManager.Stub
                        }
                        }
                    }
                    }
                } else {
                } else {
                    wtoken.markSurfacesExiting();
                    wtoken.setWindowsExiting(true);
                    mClosingApps.add(wtoken);
                    mClosingApps.add(wtoken);
                    wtoken.mEnteringAnimation = false;
                    wtoken.mEnteringAnimation = false;
                }
                }
+3 −1
Original line number Original line Diff line number Diff line
@@ -1447,8 +1447,8 @@ final class WindowState implements WindowManagerPolicy.WindowState {
        }
        }
        for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
        for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
            final WindowState win = mAppToken.allAppWindows.get(i);
            final WindowState win = mAppToken.allAppWindows.get(i);
            if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
            if (win.mWillReplaceWindow && win.mReplacingWindow == this) {
            if (win.mWillReplaceWindow && win.mReplacingWindow == this) {
                if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
                win.mWillReplaceWindow = false;
                win.mWillReplaceWindow = false;
                win.mAnimateReplacingWindow = false;
                win.mAnimateReplacingWindow = false;
                win.mReplacingRemoveRequested = false;
                win.mReplacingRemoveRequested = false;
@@ -2190,6 +2190,8 @@ final class WindowState implements WindowManagerPolicy.WindowState {
            pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
            pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
            if (mAppToken != null) {
            if (mAppToken != null) {
                pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
                pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
                pw.print(" isAnimatingWithSavedSurface()=");
                pw.print(isAnimatingWithSavedSurface());
                pw.print(" mAppDied=");pw.println(mAppDied);
                pw.print(" mAppDied=");pw.println(mAppDied);
            }
            }
            if (mTargetAppToken != null) {
            if (mTargetAppToken != null) {
Loading