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

Commit 879057a8 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Commit draw state before computing whether display has content

Otherwise even if the result of WS#isDrawn is changed to true, the
state will still need to wait until next traversal to take effect.
And if there is no next traversal, the display may keep some
stale states.

Another approach is to request another traversal when the draw state
is changed, but it may add unnecessary overhead to common cases.

The reorder should be safe because the other operations which were
put before commitFinishDrawing do not check the draw state.

Bug: 307702346
Test: atest DisplayContentTests#testDisplayHasContent
Change-Id: I225fff1ff4f0738bdaf06f6813b53dbf26caf0a7
parent 1fba603b
Loading
Loading
Loading
Loading
+18 −21
Original line number Diff line number Diff line
@@ -1004,6 +1004,24 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                mTmpApplySurfaceChangesTransactionState.obscured;
        final RootWindowContainer root = mWmService.mRoot;

        if (w.mHasSurface) {
            // Take care of the window being ready to display.
            final boolean committed = w.mWinAnimator.commitFinishDrawingLocked();
            if (isDefaultDisplay && committed) {
                if (w.hasWallpaper()) {
                    ProtoLog.v(WM_DEBUG_WALLPAPER,
                            "First draw done in potential wallpaper target %s", w);
                    mWallpaperMayChange = true;
                    pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
                    if (DEBUG_LAYOUT_REPEATS) {
                        surfacePlacer.debugLayoutRepeats(
                                "wallpaper and commitFinishDrawingLocked true",
                                pendingLayoutChanges);
                    }
                }
            }
        }

        // Update effect.
        w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;

@@ -1090,30 +1108,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp

        w.handleWindowMovedIfNeeded();

        final WindowStateAnimator winAnimator = w.mWinAnimator;

        //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
        w.resetContentChanged();

        // Moved from updateWindowsAndWallpaperLocked().
        if (w.mHasSurface) {
            // Take care of the window being ready to display.
            final boolean committed = winAnimator.commitFinishDrawingLocked();
            if (isDefaultDisplay && committed) {
                if (w.hasWallpaper()) {
                    ProtoLog.v(WM_DEBUG_WALLPAPER,
                            "First draw done in potential wallpaper target %s", w);
                    mWallpaperMayChange = true;
                    pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
                    if (DEBUG_LAYOUT_REPEATS) {
                        surfacePlacer.debugLayoutRepeats(
                                "wallpaper and commitFinishDrawingLocked true",
                                pendingLayoutChanges);
                    }
                }
            }
        }

        final ActivityRecord activity = w.mActivityRecord;
        if (activity != null && activity.isVisibleRequested()) {
            activity.updateLetterboxSurface(w);
+15 −0
Original line number Diff line number Diff line
@@ -642,6 +642,21 @@ public class DisplayContentTests extends WindowTestsBase {
        assertFalse(secondaryDisplay.shouldWaitForSystemDecorWindowsOnBoot());
    }

    @Test
    public void testDisplayHasContent() {
        final WindowState window = createWindow(null, TYPE_APPLICATION_OVERLAY, "window");
        setDrawnState(WindowStateAnimator.COMMIT_DRAW_PENDING, window);
        assertFalse(mDisplayContent.getLastHasContent());
        // The pending draw state should be committed and the has-content state is also updated.
        mDisplayContent.applySurfaceChangesTransaction();
        assertTrue(window.isDrawn());
        assertTrue(mDisplayContent.getLastHasContent());
        // If the only window is no longer visible, has-content will be false.
        setDrawnState(WindowStateAnimator.NO_SURFACE, window);
        mDisplayContent.applySurfaceChangesTransaction();
        assertFalse(mDisplayContent.getLastHasContent());
    }

    @Test
    public void testImeIsAttachedToDisplayForLetterboxedApp() {
        final DisplayContent dc = mDisplayContent;