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

Commit 6da58ac8 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Calculate wallpaper offset with associated display info

If the wallpaper has applied fixed rotation transform, it should
use the local display info. This change centralizes the access of
display info to WallpaperController#updateWallpaperOffset, so the
caller won't pass mismatched display size.

Bug: 152977308
Test: atest DisplayContentTests#testApplyTopFixedRotationTransform
Change-Id: If167e82c71d0f039691155a2aad28c2b78c683de
parent bde104f8
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -304,7 +304,11 @@ class WallpaperController {
        }
    }

    boolean updateWallpaperOffset(WindowState wallpaperWin, int dw, int dh, boolean sync) {
    boolean updateWallpaperOffset(WindowState wallpaperWin, boolean sync) {
        final DisplayInfo displayInfo = wallpaperWin.getDisplayInfo();
        final int dw = displayInfo.logicalWidth;
        final int dh = displayInfo.logicalHeight;

        int xOffset = 0;
        int yOffset = 0;
        boolean rawChanged = false;
@@ -444,10 +448,6 @@ class WallpaperController {
    }

    private void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
        final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
        final int dw = displayInfo.logicalWidth;
        final int dh = displayInfo.logicalHeight;

        WindowState target = mWallpaperTarget;
        if (target != null) {
            if (target.mWallpaperX >= 0) {
@@ -484,7 +484,7 @@ class WallpaperController {
        }

        for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) {
            mWallpaperTokens.get(curTokenNdx).updateWallpaperOffset(dw, dh, sync);
            mWallpaperTokens.get(curTokenNdx).updateWallpaperOffset(sync);
        }
    }

+4 −16
Original line number Diff line number Diff line
@@ -73,11 +73,11 @@ class WallpaperWindowToken extends WindowToken {
        }
    }

    void updateWallpaperOffset(int dw, int dh, boolean sync) {
    void updateWallpaperOffset(boolean sync) {
        final WallpaperController wallpaperController = mDisplayContent.mWallpaperController;
        for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
            final WindowState wallpaper = mChildren.get(wallpaperNdx);
            if (wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, sync)) {
            if (wallpaperController.updateWallpaperOffset(wallpaper, sync)) {
                // We only want to be synchronous with one wallpaper.
                sync = false;
            }
@@ -85,10 +85,6 @@ class WallpaperWindowToken extends WindowToken {
    }

    void updateWallpaperVisibility(boolean visible) {
        final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
        final int dw = displayInfo.logicalWidth;
        final int dh = displayInfo.logicalHeight;

        if (isVisible() != visible) {
            // Need to do a layout to ensure the wallpaper now has the correct size.
            mDisplayContent.setLayoutNeeded();
@@ -98,7 +94,7 @@ class WallpaperWindowToken extends WindowToken {
        for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
            final WindowState wallpaper = mChildren.get(wallpaperNdx);
            if (visible) {
                wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, false);
                wallpaperController.updateWallpaperOffset(wallpaper, false /* sync */);
            }

            wallpaper.dispatchWallpaperVisibility(visible);
@@ -145,19 +141,11 @@ class WallpaperWindowToken extends WindowToken {
            }
        }

        DisplayInfo displayInfo = getFixedRotationTransformDisplayInfo();
        if (displayInfo == null) {
            displayInfo = mDisplayContent.getDisplayInfo();
        }

        final int dw = displayInfo.logicalWidth;
        final int dh = displayInfo.logicalHeight;

        for (int wallpaperNdx = mChildren.size() - 1; wallpaperNdx >= 0; wallpaperNdx--) {
            final WindowState wallpaper = mChildren.get(wallpaperNdx);

            if (visible) {
                wallpaperController.updateWallpaperOffset(wallpaper, dw, dh, false);
                wallpaperController.updateWallpaperOffset(wallpaper, false /* sync */);
            }

            // First, make sure the client has the current visibility state.
+1 −3
Original line number Diff line number Diff line
@@ -2332,9 +2332,7 @@ public class WindowManagerService extends IWindowManager.Stub
            Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);

            if (toBeDisplayed && win.mIsWallpaper) {
                DisplayInfo displayInfo = displayContent.getDisplayInfo();
                displayContent.mWallpaperController.updateWallpaperOffset(
                        win, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
                displayContent.mWallpaperController.updateWallpaperOffset(win, false /* sync */);
            }
            if (win.mActivityRecord != null) {
                win.mActivityRecord.updateReportedVisibilityLocked();
+1 −3
Original line number Diff line number Diff line
@@ -1101,7 +1101,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                }
            }

            final ActivityStack stack = getRootTask();
            layoutDisplayFrame = new Rect(windowFrames.mDisplayFrame);
            windowFrames.mDisplayFrame.set(windowFrames.mContainingFrame);
            layoutXDiff = mInsetFrame.left - windowFrames.mContainingFrame.left;
@@ -1205,8 +1204,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP

        if (mIsWallpaper && (fw != windowFrames.mFrame.width()
                || fh != windowFrames.mFrame.height())) {
            dc.mWallpaperController.updateWallpaperOffset(this,
                    displayInfo.logicalWidth, displayInfo.logicalHeight, false /* sync */);
            dc.mWallpaperController.updateWallpaperOffset(this, false /* sync */);
        }

        // Calculate relative frame
+7 −0
Original line number Diff line number Diff line
@@ -1039,6 +1039,13 @@ public class DisplayContentTests extends WindowTestsBase {
        assertEquals(config90.orientation, app.getConfiguration().orientation);
        assertEquals(config90.windowConfiguration.getBounds(), app.getBounds());

        // Force the negative offset to verify it can be updated.
        mWallpaperWindow.mWinAnimator.mXOffset = mWallpaperWindow.mWinAnimator.mYOffset = -1;
        assertTrue(mDisplayContent.mWallpaperController.updateWallpaperOffset(mWallpaperWindow,
                false /* sync */));
        assertThat(mWallpaperWindow.mWinAnimator.mXOffset).isGreaterThan(-1);
        assertThat(mWallpaperWindow.mWinAnimator.mYOffset).isGreaterThan(-1);

        mDisplayContent.mAppTransition.notifyAppTransitionFinishedLocked(app.token);

        // The animation in old rotation should be cancelled.