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

Commit bf90eaa5 authored by Craig Mautner's avatar Craig Mautner
Browse files

Separate layout ops from surface ops.

Further work to isolate layout from animation and surface operations.
Remove cruft and minor refactoring.

Change-Id: I6f910ed72c7c614996641c353870c2b2ab5e8bb4
parent 6c25ffb7
Loading
Loading
Loading
Loading
+8 −13
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ class ScreenRotationAnimation {
    BlackFrame mBlackFrame;
    int mWidth, mHeight;

    int mSnapshotRotation;
    int mSnapshotDeltaRotation;
    int mOriginalRotation;
    int mOriginalWidth, mOriginalHeight;
@@ -125,8 +124,7 @@ class ScreenRotationAnimation {
        if (mBlackFrame != null) {
            mBlackFrame.printTo(prefix + "  ", pw);
        }
        pw.print(prefix); pw.print("mSnapshotRotation="); pw.print(mSnapshotRotation);
                pw.print(" mSnapshotDeltaRotation="); pw.print(mSnapshotDeltaRotation);
        pw.print(prefix); pw.print(" mSnapshotDeltaRotation="); pw.print(mSnapshotDeltaRotation);
                pw.print(" mCurRotation="); pw.println(mCurRotation);
        pw.print(prefix); pw.print("mOriginalRotation="); pw.print(mOriginalRotation);
                pw.print(" mOriginalWidth="); pw.print(mOriginalWidth);
@@ -173,7 +171,6 @@ class ScreenRotationAnimation {
        mContext = context;

        // Screenshot does NOT include rotation!
        mSnapshotRotation = 0;
        if (originalRotation == Surface.ROTATION_90
                || originalRotation == Surface.ROTATION_270) {
            mWidth = originalHeight;
@@ -197,7 +194,7 @@ class ScreenRotationAnimation {
            try {
                mSurface = new Surface(session, 0, "FreezeSurface",
                        -1, mWidth, mHeight, PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN);
                if (mSurface == null || !mSurface.isValid()) {
                if (!mSurface.isValid()) {
                    // Screenshot failed, punt.
                    mSurface = null;
                    return;
@@ -281,7 +278,7 @@ class ScreenRotationAnimation {
        // Compute the transformation matrix that must be applied
        // to the snapshot to make it stay in the same original position
        // with the current screen rotation.
        int delta = deltaRotation(rotation, mSnapshotRotation);
        int delta = deltaRotation(rotation, Surface.ROTATION_0);
        createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);

        if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
@@ -703,20 +700,18 @@ class ScreenRotationAnimation {
    }

    void updateSurfaces() {
        if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
        if (mSurface != null) {
            if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
                if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
                mSurface.hide();
            }
        }

        if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
        if (mBlackFrame != null) {
            if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
                if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
                mBlackFrame.hide();
            }
            } else {
            if (mBlackFrame != null) {
                mBlackFrame.setMatrix(mFrameTransformation.getMatrix());
            }
        }
+91 −80
Original line number Diff line number Diff line
@@ -1581,8 +1581,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
                    + " commitdrawpending=" + w.mCommitDrawPending);
            if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
                    && (mWallpaperTarget == w
                            || (!w.mDrawPending && !w.mCommitDrawPending))) {
                    && (mWallpaperTarget == w || w.isDrawnLw())) {
                if (DEBUG_WALLPAPER) Slog.v(TAG,
                        "Found wallpaper activity: #" + i + "=" + w);
                foundW = w;
@@ -2688,8 +2687,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    win.mEnterAnimationPending = true;
                }
                if (displayed) {
                    if (win.mSurface != null && !win.mDrawPending
                            && !win.mCommitDrawPending && !mDisplayFrozen
                    if (win.isDrawnLw() && !mDisplayFrozen
                            && mDisplayEnabled && mPolicy.isScreenOnFully()) {
                        applyEnterAnimationLocked(win);
                    }
@@ -3983,8 +3981,7 @@ public class WindowManagerService extends IWindowManager.Stub
                // If we are being set visible, and the starting window is
                // not yet displayed, then make sure it doesn't get displayed.
                WindowState swin = wtoken.startingWindow;
                if (swin != null && (swin.mDrawPending
                        || swin.mCommitDrawPending)) {
                if (swin != null && !swin.isDrawnLw()) {
                    swin.mPolicyVisibility = false;
                    swin.mPolicyVisibilityAfterAnim = false;
                 }
@@ -7669,9 +7666,9 @@ public class WindowManagerService extends IWindowManager.Stub
            }
        }

        if (mScreenRotationAnimation != null) {
            if (mScreenRotationAnimation.isAnimating() ||
                    mScreenRotationAnimation.mFinishAnimReady) {
        if (mScreenRotationAnimation != null &&
                (mScreenRotationAnimation.isAnimating() ||
                        mScreenRotationAnimation.mFinishAnimReady)) {
            if (mScreenRotationAnimation.stepAnimationLocked(currentTime)) {
                mInnerFields.mUpdateRotation = false;
                mInnerFields.mAnimating = true;
@@ -7682,6 +7679,61 @@ public class WindowManagerService extends IWindowManager.Stub
            }
        }
    }

    private void animateAndUpdateSurfaces(final long currentTime, final int dw, final int dh,
                                          final int innerDw, final int innerDh, 
                                          final boolean recoveringMemory) {
        // Update animations of all applications, including those
        // associated with exiting/removed apps
        Surface.openTransaction();

        try {
            mPendingLayoutChanges = performAnimationsLocked(currentTime, dw, dh,
                    innerDw, innerDh);
            updateWindowsAppsAndRotationAnimationsLocked(currentTime, innerDw, innerDh);
        
            // THIRD LOOP: Update the surfaces of all windows.
            
            if (mScreenRotationAnimation != null) {
                mScreenRotationAnimation.updateSurfaces();
            }
        
            final int N = mWindows.size();
            for (int i=N-1; i>=0; i--) {
                WindowState w = mWindows.get(i);
                prepareSurfaceLocked(w, recoveringMemory);
            }
        
            if (mDimAnimator != null && mDimAnimator.mDimShown) {
                mInnerFields.mAnimating |=
                        mDimAnimator.updateSurface(mInnerFields.mDimming, currentTime,
                            mDisplayFrozen || !mDisplayEnabled || !mPolicy.isScreenOnFully());
            }
        
            if (!mInnerFields.mBlurring && mBlurShown) {
                if (SHOW_TRANSACTIONS) Slog.i(TAG, "  BLUR " + mBlurSurface
                        + ": HIDE");
                try {
                    mBlurSurface.hide();
                } catch (IllegalArgumentException e) {
                    Slog.w(TAG, "Illegal argument exception hiding blur surface");
                }
                mBlurShown = false;
            }
        
            if (mBlackFrame != null) {
                if (mScreenRotationAnimation != null) {
                    mBlackFrame.setMatrix(
                            mScreenRotationAnimation.getEnterTransformation().getMatrix());
                } else {
                    mBlackFrame.clearMatrix();
                }
            }
        } catch (RuntimeException e) {
            Log.wtf(TAG, "Unhandled exception in Window Manager", e);
        } finally {
            Surface.closeTransaction();
        }
    }
    
    /**
@@ -8357,7 +8409,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    mResizingWindows.add(w);
                }
            } else if (w.mOrientationChanging) {
                if (!w.mDrawPending && !w.mCommitDrawPending) {
                if (w.isDrawnLw()) {
                    if (DEBUG_ORIENTATION) Slog.v(TAG,
                            "Orientation not waiting for draw in "
                            + w + ", surface " + w.mSurface);
@@ -8388,6 +8440,16 @@ public class WindowManagerService extends IWindowManager.Stub
        // cases while they are hidden such as when first showing a
        // window.
        
        if (w.mSurface == null) {
            if (w.mOrientationChanging) {
                if (DEBUG_ORIENTATION) {
                    Slog.v(TAG, "Orientation change skips hidden " + w);
                }
                w.mOrientationChanging = false;
            }
            return;
        }
        
        boolean displayed = false;

        w.computeShownFrameLocked();
@@ -8521,8 +8583,7 @@ public class WindowManagerService extends IWindowManager.Stub
                }
            }

            if (w.mLastHidden && !w.mDrawPending
                    && !w.mCommitDrawPending
            if (w.mLastHidden && w.isDrawnLw()
                    && !w.mReadyToShow) {
                if (SHOW_TRANSACTIONS) logSurface(w,
                        "SHOW (performLayout)", null);
@@ -8544,7 +8605,7 @@ public class WindowManagerService extends IWindowManager.Stub

        if (displayed) {
            if (w.mOrientationChanging) {
                if (w.mDrawPending || w.mCommitDrawPending) {
                if (!w.isDrawnLw()) {
                    mInnerFields.mOrientationChangeComplete = false;
                    if (DEBUG_ORIENTATION) Slog.v(TAG,
                            "Orientation continue waiting for draw in " + w);
@@ -8832,48 +8893,20 @@ public class WindowManagerService extends IWindowManager.Stub
                
            } while (mPendingLayoutChanges != 0);

            // Update animations of all applications, including those
            // associated with exiting/removed apps

            mPendingLayoutChanges = performAnimationsLocked(currentTime, dw, dh,
                    innerDw, innerDh);
            updateWindowsAppsAndRotationAnimationsLocked(currentTime, innerDw, innerDh);

            // THIRD LOOP: Update the surfaces of all windows.

            final boolean someoneLosingFocus = mLosingFocus.size() != 0;
            final boolean someoneLosingFocus = !mLosingFocus.isEmpty();

            mInnerFields.mObscured = false;
            mInnerFields.mBlurring = false;
            mInnerFields.mDimming = false;
            mInnerFields.mSyswin = false;
            
            if (mScreenRotationAnimation != null) {
                mScreenRotationAnimation.updateSurfaces();
            }

            final int N = mWindows.size();

            for (i=N-1; i>=0; i--) {
                WindowState w = mWindows.get(i);

                if (w.mSurface != null) {
                    prepareSurfaceLocked(w, recoveringMemory);
                } else if (w.mOrientationChanging) {
                    if (DEBUG_ORIENTATION) {
                        Slog.v(TAG, "Orientation change skips hidden " + w);
                    }
                    w.mOrientationChanging = false;
                }

                if (w.mContentChanged) {
                //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
                w.mContentChanged = false;
                }

                final boolean canBeSeen = w.isDisplayedLw();

                if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
                if (someoneLosingFocus && w == mCurrentFocus && w.isDisplayedLw()) {
                    focusDisplayed = true;
                }

@@ -8892,37 +8925,15 @@ public class WindowManagerService extends IWindowManager.Stub
                    updateWallpaperVisibilityLocked();
                }
            }

            if (mDimAnimator != null && mDimAnimator.mDimShown) {
                mInnerFields.mAnimating |=
                        mDimAnimator.updateSurface(mInnerFields.mDimming, currentTime,
                            mDisplayFrozen || !mDisplayEnabled || !mPolicy.isScreenOnFully());
            }

            if (!mInnerFields.mBlurring && mBlurShown) {
                if (SHOW_TRANSACTIONS) Slog.i(TAG, "  BLUR " + mBlurSurface
                        + ": HIDE");
                try {
                    mBlurSurface.hide();
                } catch (IllegalArgumentException e) {
                    Slog.w(TAG, "Illegal argument exception hiding blur surface");
                }
                mBlurShown = false;
            }

            if (mBlackFrame != null) {
                if (mScreenRotationAnimation != null) {
                    mBlackFrame.setMatrix(
                            mScreenRotationAnimation.getEnterTransformation().getMatrix());
                } else {
                    mBlackFrame.clearMatrix();
                }
            }
        } catch (RuntimeException e) {
            Log.wtf(TAG, "Unhandled exception in Window Manager", e);
        } finally {
            Surface.closeTransaction();
        }

        Surface.closeTransaction();
        // Update animations of all applications, including those
        // associated with exiting/removed apps
        animateAndUpdateSurfaces(currentTime, dw, dh, innerDw, innerDh, recoveringMemory);

        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
+4 −7
Original line number Diff line number Diff line
@@ -1018,7 +1018,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
        if (!mService.mDisplayFrozen && mService.mPolicy.isScreenOnFully()) {
            // We will run animations as long as the display isn't frozen.

            if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
            if (isDrawnLw() && mAnimation != null) {
                mHasTransformation = true;
                mHasLocalTransformation = true;
                if (!mLocalAnimating) {
@@ -1478,8 +1478,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
     */
    public boolean isDisplayedLw() {
        final AppWindowToken atoken = mAppToken;
        return mSurface != null && mPolicyVisibility && !mDestroying
            && !mDrawPending && !mCommitDrawPending
        return isDrawnLw() && mPolicyVisibility
            && ((!mAttachedHidden &&
                    (atoken == null || !atoken.hiddenRequested))
                    || mAnimating);
@@ -1500,7 +1499,6 @@ final class WindowState implements WindowManagerPolicy.WindowState {
     * complete UI in to.
     */
    public boolean isDrawnLw() {
        final AppWindowToken atoken = mAppToken;
        return mSurface != null && !mDestroying
            && !mDrawPending && !mCommitDrawPending;
    }
@@ -1512,9 +1510,8 @@ final class WindowState implements WindowManagerPolicy.WindowState {
    boolean isOpaqueDrawn() {
        return (mAttrs.format == PixelFormat.OPAQUE
                        || mAttrs.type == TYPE_WALLPAPER)
                && mSurface != null && mAnimation == null
                && (mAppToken == null || mAppToken.animation == null)
                && !mDrawPending && !mCommitDrawPending;
                && isDrawnLw() && mAnimation == null
                && (mAppToken == null || mAppToken.animation == null);
    }

    /**