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

Commit 8bbdc770 authored by chaviw's avatar chaviw
Browse files

Clean up code in WSA and WS

1. Use Transaction API instead of SurfaceControl
2. Removed recoverMemory flag from Tranaction request APIs
3. Deleted a lot of unused code

Test: Split Screen + PIP
Change-Id: I91762453afadd79626f6fb2d8ba162054a011584
parent 3c57702e
Loading
Loading
Loading
Loading
+0 −64
Original line number Diff line number Diff line
@@ -1523,25 +1523,6 @@ public final class SurfaceControl implements Parcelable {
        }
    }

    /**
     * @hide
     */
    public void detachChildren() {
        synchronized(SurfaceControl.class) {
            sGlobalTransaction.detachChildren(this);
        }
    }

    /**
     * @hide
     */
    public void setTransparentRegionHint(Region region) {
        checkNotReleased();
        synchronized(SurfaceControl.class) {
            sGlobalTransaction.setTransparentRegionHint(this, region);
        }
    }

    /**
     * @hide
     */
@@ -1572,51 +1553,6 @@ public final class SurfaceControl implements Parcelable {
        return nativeGetAnimationFrameStats(outStats);
    }

    /**
     * Sets the Surface to be color space agnostic. If a surface is color space agnostic,
     * the color can be interpreted in any color space.
     * @param agnostic A boolean to indicate whether the surface is color space agnostic
     * @hide
     */
    public void setColorSpaceAgnostic(boolean agnostic) {
        checkNotReleased();
        synchronized (SurfaceControl.class) {
            sGlobalTransaction.setColorSpaceAgnostic(this, agnostic);
        }
    }

    /**
     * @hide
     */
    public void setBackgroundBlurRadius(int blur) {
        checkNotReleased();
        synchronized (SurfaceControl.class) {
            sGlobalTransaction.setBackgroundBlurRadius(this, blur);
        }
    }

    /**
     * @hide
     */
    public void setOpaque(boolean isOpaque) {
        checkNotReleased();

        synchronized (SurfaceControl.class) {
            sGlobalTransaction.setOpaque(this, isOpaque);
        }
    }

    /**
     * @hide
     */
    public void setSecure(boolean isSecure) {
        checkNotReleased();

        synchronized (SurfaceControl.class) {
            sGlobalTransaction.setSecure(this, isSecure);
        }
    }

    /**
     * @hide
     */
+9 −8
Original line number Diff line number Diff line
@@ -95,18 +95,18 @@ import static android.view.Display.COLOR_MODE_DEFAULT;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_ACTIVITY_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_OPEN_BEHIND;
import static android.view.WindowManager.TRANSIT_OLD_UNSET;
import static android.view.SurfaceControl.getGlobalTransaction;
import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_OPEN_BEHIND;
import static android.view.WindowManager.TRANSIT_OLD_ACTIVITY_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_UNSET;

import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ADD_REMOVE;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS;
@@ -182,7 +182,6 @@ import static com.android.server.wm.IdentifierProto.USER_ID;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_RECENTS;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_WINDOW_ANIMATION;
import static com.android.server.wm.Task.TASK_VISIBILITY_VISIBLE;
import static com.android.server.wm.Task.ActivityState.DESTROYED;
import static com.android.server.wm.Task.ActivityState.DESTROYING;
import static com.android.server.wm.Task.ActivityState.FINISHING;
@@ -194,6 +193,7 @@ import static com.android.server.wm.Task.ActivityState.RESUMED;
import static com.android.server.wm.Task.ActivityState.STARTED;
import static com.android.server.wm.Task.ActivityState.STOPPED;
import static com.android.server.wm.Task.ActivityState.STOPPING;
import static com.android.server.wm.Task.TASK_VISIBILITY_VISIBLE;
import static com.android.server.wm.TaskPersister.DEBUG;
import static com.android.server.wm.TaskPersister.IMAGE_EXTENSION;
import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN;
@@ -3131,7 +3131,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        SurfaceControl.openTransaction();
        for (int i = mChildren.size() - 1; i >= 0; i--) {
            final WindowState w = mChildren.get(i);
            w.mWinAnimator.detachChildren();
            w.mWinAnimator.detachChildren(getGlobalTransaction());
        }
        SurfaceControl.closeTransaction();
    }
@@ -4443,7 +4443,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            SurfaceControl.openTransaction();
            try {
                forAllWindows(win -> {
                    win.mWinAnimator.hide("immediately hidden"); }, true);
                    win.mWinAnimator.hide(getGlobalTransaction(), "immediately hidden");
                }, true);
            } finally {
                SurfaceControl.closeTransaction();
            }
+2 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import static android.provider.Settings.Global.DEVELOPMENT_RENDER_SHADOWS_IN_COM
import static android.provider.Settings.Global.DEVELOPMENT_WM_DISPLAY_SETTINGS_PATH;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.SurfaceControl.getGlobalTransaction;
import static android.view.WindowManager.DISPLAY_IME_POLICY_FALLBACK_DISPLAY;
import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
@@ -2557,7 +2558,7 @@ public class WindowManagerService extends IWindowManager.Stub
        // side child surfaces, so they will remain preserved in their current state
        // (rather than be cleaned up immediately by the app code).
        SurfaceControl.openTransaction();
        winAnimator.detachChildren();
        winAnimator.detachChildren(getGlobalTransaction());
        SurfaceControl.closeTransaction();

        return focusMayChange;
+6 −5
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.view.InsetsState.ITYPE_IME;
import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
import static android.view.SurfaceControl.Transaction;
import static android.view.SurfaceControl.getGlobalTransaction;
import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
@@ -2649,7 +2650,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
            }
            if (!isVisibleByPolicy()) {
                mWinAnimator.hide("checkPolicyVisibilityChange");
                mWinAnimator.hide(getGlobalTransaction(), "checkPolicyVisibilityChange");
                if (isFocused()) {
                    ProtoLog.i(WM_DEBUG_FOCUS_LIGHT,
                            "setAnimationLocked: setting mFocusMayChange true");
@@ -3180,10 +3181,10 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            // detaching any surface control the client added from the client.
            for (int i = mChildren.size() - 1; i >= 0; --i) {
                final WindowState c = mChildren.get(i);
                c.mWinAnimator.detachChildren();
                c.mWinAnimator.detachChildren(getGlobalTransaction());
            }

            mWinAnimator.detachChildren();
            mWinAnimator.detachChildren(getGlobalTransaction());
        }

        try {
@@ -4806,7 +4807,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            c.hideWallpaperWindow(wasDeferred, reason);
        }
        if (!mWinAnimator.mLastHidden || wasDeferred) {
            mWinAnimator.hide(reason);
            mWinAnimator.hide(getGlobalTransaction(), reason);
            getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null;
            dispatchWallpaperVisibility(false);
            final DisplayContent displayContent = getDisplayContent();
@@ -5270,7 +5271,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        updateFrameRateSelectionPriorityIfNeeded();
        updateGlobalScaleIfNeeded();

        mWinAnimator.prepareSurfaceLocked(getSyncTransaction(), true);
        mWinAnimator.prepareSurfaceLocked(getSyncTransaction());
        super.prepareSurfaces();
    }

+25 −108
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_C
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Debug;
@@ -130,10 +129,6 @@ class WindowStateAnimator {
    float mAlpha = 0;
    float mLastAlpha = 0;

    Rect mTmpStackBounds = new Rect();
    private Rect mTmpAnimatingBounds = new Rect();
    private Rect mTmpSourceBounds = new Rect();

    /**
     * This is rectangle of the window's surface that is not covered by
     * system decorations.
@@ -154,8 +149,6 @@ class WindowStateAnimator {
     * window is first added or shown, cleared when the callback has been made. */
    boolean mEnteringAnimation;

    private final SurfaceControl.Transaction mTmpTransaction;

    /** The pixel format of the underlying SurfaceControl */
    int mSurfaceFormat;

@@ -201,12 +194,6 @@ class WindowStateAnimator {
    // region.
    float mWallpaperScale = 1f;

    /**
     * A flag to determine if the WSA needs to offset its position to compensate for the stack's
     * position update before the WSA surface has resized.
     */
    private boolean mOffsetPositionForStackResize;

    private final Rect mTmpSize = new Rect();

    /**
@@ -220,13 +207,10 @@ class WindowStateAnimator {
    private final SurfaceControl.Transaction mPostDrawTransaction =
            new SurfaceControl.Transaction();

    private final Point mTmpPos = new Point();

    WindowStateAnimator(final WindowState win) {
        final WindowManagerService service = win.mWmService;

        mService = service;
        mTmpTransaction = service.mTransactionFactory.get();
        mAnimator = service.mAnimator;
        mPolicy = service.mPolicy;
        mContext = service.mContext;
@@ -243,7 +227,7 @@ class WindowStateAnimator {
        if (DEBUG_ANIM) Slog.v(
                TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit
                        + ", reportedVisible="
                        + (mWin.mActivityRecord != null ? mWin.mActivityRecord.reportedVisible : false));
                        + (mWin.mActivityRecord != null && mWin.mActivityRecord.reportedVisible));

        mWin.checkPolicyVisibilityChange();
        final DisplayContent displayContent = mWin.getDisplayContent();
@@ -284,11 +268,6 @@ class WindowStateAnimator {
        }
    }

    void hide(String reason) {
        hide(mTmpTransaction, reason);
        SurfaceControl.mergeToGlobalTransaction(mTmpTransaction);
    }

    boolean finishDrawingLocked(SurfaceControl.Transaction postDrawTransaction) {
        final boolean startingWindow =
                mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
@@ -484,7 +463,6 @@ class WindowStateAnimator {
            mSurfaceController.setColorSpaceAgnostic((attrs.privateFlags
                    & WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC) != 0);

            setOffsetPositionForStackResize(false);
            mSurfaceFormat = format;

            w.setHasSurface(true);
@@ -655,13 +633,12 @@ class WindowStateAnimator {
        return true;
    }

    void setSurfaceBoundariesLocked(SurfaceControl.Transaction t, final boolean recoveringMemory) {
    void setSurfaceBoundariesLocked(SurfaceControl.Transaction t) {
        if (mSurfaceController == null) {
            return;
        }

        final WindowState w = mWin;
        final LayoutParams attrs = mWin.getAttrs();
        final Task task = w.getTask();

        if (shouldConsumeMainWindowSizeTransaction()) {
@@ -679,75 +656,26 @@ class WindowStateAnimator {
            task.setMainWindowSizeChangeTransaction(null);
        }

        float surfaceWidth = mSurfaceController.getWidth();
        float surfaceHeight = mSurfaceController.getHeight();

        final Rect insets = attrs.surfaceInsets;

        // getFrameNumber is only valid in the call-stack of relayoutWindow
        // as this is the only-time we know the client renderer
        // is paused.
        final boolean relayout = !w.mRelayoutCalled || w.mInRelayout;

        if (!w.mSeamlesslyRotated) {
            // Used to offset the WSA when stack position changes before a resize.
            int xOffset = mXOffset;
            int yOffset = mYOffset;
            if (mOffsetPositionForStackResize) {
                if (relayout) {
                    // Once a relayout is called, reset the offset back to 0 and defer
                    // setting it until a new frame with the updated size. This ensures that
                    // the WS position is reset (so the stack position is shown) at the same
                    // time that the buffer size changes.
                    setOffsetPositionForStackResize(false);
                    t.deferTransactionUntil(mSurfaceController.mSurfaceControl,
                        mWin.getClientViewRootSurface(), mWin.getFrameNumber());
                } else {
                    final Task stack = mWin.getRootTask();
                    mTmpPos.x = 0;
                    mTmpPos.y = 0;
                    if (stack != null) {
                        stack.getRelativePosition(mTmpPos);
                    }
                     xOffset = -mTmpPos.x;
                    yOffset = -mTmpPos.y;
                }
            }
            if (!mIsWallpaper) {
                mSurfaceController.setPosition(t, xOffset, yOffset, recoveringMemory);
            } else {
                setWallpaperPositionAndScale(t,
                        xOffset, yOffset, mWallpaperScale, recoveringMemory);
            }
        }

        if (!w.mSeamlesslyRotated) {
                mSurfaceController.setPosition(t, xOffset, yOffset);
                // Wallpaper is already updated above when calling setWallpaperPositionAndScale so
                // we only need to consider the non-wallpaper case here.
            if (!mIsWallpaper) {
                mSurfaceController.setMatrix(t,
                        mDsDx * w.mHScale,
                        mDtDx * w.mVScale,
                        mDtDy * w.mHScale,
                    mDsDy * w.mVScale, recoveringMemory);
            }
        }
    }

    /**
     * Get rect of the task this window is currently in. If there is no task, rect will be set to
     * empty.
     */
    void getContainerRect(Rect rect) {
        final Task task = mWin.getTask();
        if (task != null) {
            task.getDimBounds(rect);
                        mDsDy * w.mVScale);
            } else {
            rect.left = rect.top = rect.right = rect.bottom = 0;
                setWallpaperPositionAndScale(t, xOffset, yOffset, mWallpaperScale);
            }
        }
    }

    void prepareSurfaceLocked(SurfaceControl.Transaction t, final boolean recoveringMemory) {
    void prepareSurfaceLocked(SurfaceControl.Transaction t) {
        final WindowState w = mWin;
        if (!hasSurface()) {

@@ -764,13 +692,13 @@ class WindowStateAnimator {

        computeShownFrameLocked();

        setSurfaceBoundariesLocked(t, recoveringMemory);
        setSurfaceBoundariesLocked(t);

        if (mIsWallpaper && !w.mWallpaperVisible) {
            // Wallpaper is no longer visible and there is no wp target => hide it.
            hide("prepareSurfaceLocked");
            hide(t, "prepareSurfaceLocked");
        } else if (w.isParentWindowHidden() || !w.isOnScreen()) {
            hide("prepareSurfaceLocked");
            hide(t, "prepareSurfaceLocked");
            mWallpaperControllerLocked.hideWallpapers(w);

            // If we are waiting for this window to handle an orientation change. If this window is
@@ -806,16 +734,15 @@ class WindowStateAnimator {
            boolean prepared = true;

            if (mIsWallpaper) {
                setWallpaperPositionAndScale(t,
                        mXOffset, mYOffset, mWallpaperScale, recoveringMemory);
                setWallpaperPositionAndScale(t, mXOffset, mYOffset, mWallpaperScale);
            } else {
                prepared =
                    mSurfaceController.prepareToShowInTransaction(t, mShownAlpha,
                        mDsDx * w.mHScale,
                        mDtDx * w.mVScale,
                        mDtDy * w.mHScale,
                        mDsDy * w.mVScale,
                        recoveringMemory);
                        mDsDy * w.mVScale
                    );
            }

            if (prepared && mDrawState == HAS_DRAWN) {
@@ -894,8 +821,7 @@ class WindowStateAnimator {
                    Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
                }
                mService.openSurfaceTransaction();
                setWallpaperPositionAndScale(SurfaceControl.getGlobalTransaction(),
                    dx, dy, scale, false);
                setWallpaperPositionAndScale(SurfaceControl.getGlobalTransaction(), dx, dy, scale);
            } catch (RuntimeException e) {
                Slog.w(TAG, "Error positioning surface of " + mWin
                        + " pos=(" + dx + "," + dy + ")", e);
@@ -910,8 +836,8 @@ class WindowStateAnimator {
        return true;
    }

    private void setWallpaperPositionAndScale(SurfaceControl.Transaction t,
        int dx, int dy, float scale, boolean recoveringMemory) {
    private void setWallpaperPositionAndScale(SurfaceControl.Transaction t, int dx, int dy,
            float scale) {
        DisplayInfo displayInfo = mWin.getDisplayInfo();
        Matrix matrix = mWin.mTmpMatrix;
        matrix.setTranslate(dx, dy);
@@ -921,13 +847,12 @@ class WindowStateAnimator {
        matrix.reset();

        mSurfaceController.setPosition(t,mWin.mTmpMatrixArray[MTRANS_X],
                mWin.mTmpMatrixArray[MTRANS_Y], recoveringMemory);
                mWin.mTmpMatrixArray[MTRANS_Y]);
        mSurfaceController.setMatrix(t,
                mDsDx * mWin.mTmpMatrixArray[MSCALE_X] * mWin.mHScale,
                mDtDx * mWin.mTmpMatrixArray[MSKEW_Y] * mWin.mVScale,
                mDtDy * mWin.mTmpMatrixArray[MSKEW_X] * mWin.mHScale,
                mDsDy * mWin.mTmpMatrixArray[MSCALE_Y] * mWin.mVScale,
                recoveringMemory);
                mDsDy * mWin.mTmpMatrixArray[MSCALE_Y] * mWin.mVScale);
    }

    /**
@@ -1169,10 +1094,6 @@ class WindowStateAnimator {
        return sb.toString();
    }

    void reclaimSomeSurfaceMemory(String operation, boolean secure) {
        mService.mRoot.reclaimSomeSurfaceMemory(this, operation, secure);
    }

    boolean getShown() {
        if (mSurfaceController != null) {
            return mSurfaceController.getShown();
@@ -1195,7 +1116,7 @@ class WindowStateAnimator {
        }
    }

    void detachChildren() {
    void detachChildren(SurfaceControl.Transaction t) {

        // Do not detach children of starting windows, as their lifecycle is well under control and
        // it may lead to issues in case we relaunch when we just added the starting window.
@@ -1203,14 +1124,10 @@ class WindowStateAnimator {
            return;
        }
        if (mSurfaceController != null) {
            mSurfaceController.detachChildren();
            mSurfaceController.detachChildren(t);
        }
    }

    void setOffsetPositionForStackResize(boolean offsetPositionForStackResize) {
        mOffsetPositionForStackResize = offsetPositionForStackResize;
    }

    SurfaceControl getSurfaceControl() {
        if (!hasSurface()) {
            return null;
Loading