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

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

Move Surface operations into existing transaction.

Several Surface operations - notably setPosition, setSize, and show -
had been moved outside of a Surface.openTransaction/closeTransaction
window. This corrects that problem.

In addition, before animations were separated from layout the Surface
frame was computed prior to returning from relayoutWindow(). After
separation the frame was being computed during animation. This checkin
restores the frame calculation in layout.

Fixes bug 6343291.

Change-Id: I4752bdf1fed0f2b46c5eb9508825c9b1b0fd702f
parent 3255a28b
Loading
Loading
Loading
Loading
+66 −68
Original line number Diff line number Diff line
@@ -7959,7 +7959,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    Slog.v(TAG, "Resize reasons: "
                            + " contentInsetsChanged=" + w.mContentInsetsChanged
                            + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
                            + " surfaceResized=" + w.mWinAnimator.mSurfaceResized
                            + " surfaceResized=" + winAnimator.mSurfaceResized
                            + " configChanged=" + configChanged);
                }

@@ -7974,7 +7974,7 @@ public class WindowManagerService extends IWindowManager.Stub
                if (w.mOrientationChanging) {
                    if (DEBUG_ORIENTATION) Slog.v(TAG,
                            "Orientation start waiting for draw in "
                            + w + ", surface " + w.mWinAnimator.mSurface);
                            + w + ", surface " + winAnimator.mSurface);
                    winAnimator.mDrawState = WindowStateAnimator.DRAW_PENDING;
                    if (w.mAppToken != null) {
                        w.mAppToken.allDrawn = false;
@@ -7982,15 +7982,15 @@ public class WindowManagerService extends IWindowManager.Stub
                }
                if (!mResizingWindows.contains(w)) {
                    if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
                            "Resizing window " + w + " to " + w.mWinAnimator.mSurfaceW
                            + "x" + w.mWinAnimator.mSurfaceH);
                            "Resizing window " + w + " to " + winAnimator.mSurfaceW
                            + "x" + winAnimator.mSurfaceH);
                    mResizingWindows.add(w);
                }
            } else if (w.mOrientationChanging) {
                if (w.isDrawnLw()) {
                    if (DEBUG_ORIENTATION) Slog.v(TAG,
                            "Orientation not waiting for draw in "
                            + w + ", surface " + w.mWinAnimator.mSurface);
                            + w + ", surface " + winAnimator.mSurface);
                    w.mOrientationChanging = false;
                }
            }
@@ -8196,7 +8196,52 @@ public class WindowManagerService extends IWindowManager.Stub
                    // has been updated accordingly.
                    updateWallpaperVisibilityLocked();
                }

                final WindowStateAnimator winAnimator = w.mWinAnimator;

                // If the window has moved due to its containing
                // content frame changing, then we'd like to animate
                // it.
                if (w.mHasSurface && w.shouldAnimateMove()) {
                    // Frame has moved, containing content frame
                    // has also moved, and we're not currently animating...
                    // let's do something.
                    Animation a = AnimationUtils.loadAnimation(mContext,
                            com.android.internal.R.anim.window_move_from_decor);
                    winAnimator.setAnimation(a);
                    winAnimator.mAnimDw = w.mLastFrame.left - w.mFrame.left;
                    winAnimator.mAnimDh = w.mLastFrame.top - w.mFrame.top;
                } else {
                    winAnimator.mAnimDw = innerDw;
                    winAnimator.mAnimDh = innerDh;
                }

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

                // Moved from updateWindowsAndWallpaperLocked().
                if (w.mHasSurface) {
                    // Take care of the window being ready to display.
                    if (winAnimator.commitFinishDrawingLocked(currentTime)) {
                        if ((w.mAttrs.flags
                                & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
                            if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG,
                                    "First draw done in potential wallpaper target " + w);
                            mInnerFields.mWallpaperMayChange = true;
                            mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
                            if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
                                debugLayoutRepeats("updateWindowsAndWallpaperLocked 1",
                                    mPendingLayoutChanges);
                            }
                        }
                    }

                    winAnimator.setSurfaceBoundaries(recoveringMemory);
                }

                updateResizingWindows(w);
            }

            if (focusDisplayed) {
                mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
            }
@@ -8278,64 +8323,6 @@ public class WindowManagerService extends IWindowManager.Stub
            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("mLayoutNeeded", mPendingLayoutChanges);
        }

        final int N = mWindows.size();
        for (i=N-1; i>=0; i--) {
            final WindowState w = mWindows.get(i);
            final WindowStateAnimator winAnimator = w.mWinAnimator; 
            
            // If the window has moved due to its containing
            // content frame changing, then we'd like to animate
            // it.
            if (w.mHasSurface && w.shouldAnimateMove()) {
                // Frame has moved, containing content frame
                // has also moved, and we're not currently animating...
                // let's do something.
                Animation a = AnimationUtils.loadAnimation(mContext,
                        com.android.internal.R.anim.window_move_from_decor);
                winAnimator.setAnimation(a);
                winAnimator.mAnimDw = w.mLastFrame.left - w.mFrame.left;
                winAnimator.mAnimDh = w.mLastFrame.top - w.mFrame.top;
            } else {
                winAnimator.mAnimDw = innerDw;
                winAnimator.mAnimDh = innerDh;
            }

            //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
            w.mContentChanged = false;
            
            // TODO(cmautner): Can this move up to the loop at the end of try/catch above?
            updateResizingWindows(w);

            // Moved from updateWindowsAndWallpaperLocked().
            if (w.mHasSurface) {
                // Take care of the window being ready to display.
                if (winAnimator.commitFinishDrawingLocked(currentTime)) {
                    if ((w.mAttrs.flags
                            & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
                        if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG,
                                "First draw done in potential wallpaper target " + w);
                        mInnerFields.mWallpaperMayChange = true;
                        mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
                        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
                            debugLayoutRepeats("updateWindowsAndWallpaperLocked 1",
                                mPendingLayoutChanges);
                        }
                    }
                }
            }
        }

        if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
                "With display frozen, orientationChangeComplete="
                + mInnerFields.mOrientationChangeComplete);
        if (mInnerFields.mOrientationChangeComplete) {
            if (mWindowsFreezingScreen) {
                mWindowsFreezingScreen = false;
                mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
            }
            stopFreezingDisplayLocked();
        }

        if (!mResizingWindows.isEmpty()) {
            for (i = mResizingWindows.size() - 1; i >= 0; i--) {
                WindowState win = mResizingWindows.get(i);
@@ -8374,6 +8361,17 @@ public class WindowManagerService extends IWindowManager.Stub
            mResizingWindows.clear();
        }

        if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
                "With display frozen, orientationChangeComplete="
                + mInnerFields.mOrientationChangeComplete);
        if (mInnerFields.mOrientationChangeComplete) {
            if (mWindowsFreezingScreen) {
                mWindowsFreezingScreen = false;
                mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
            }
            stopFreezingDisplayLocked();
        }

        // Destroy the surface of any windows that are no longer visible.
        boolean wallpaperDestroyed = false;
        i = mDestroySurface.size();
+30 −15
Original line number Diff line number Diff line
@@ -499,6 +499,14 @@ class WindowStateAnimator {
            sSurfaces.remove(this);
        }

        @Override
        public void release() {
            super.release();
            Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
                    + WindowManagerService.getCallers(3));
            sSurfaces.remove(this);
        }

        static void dumpAllSurfaces() {
            final int N = sSurfaces.size();
            for (int i = 0; i < N; i++) {
@@ -886,22 +894,8 @@ class WindowStateAnimator {
        mDtDy = mWin.mGlobalScale;
    }

    public void prepareSurfaceLocked(final boolean recoveringMemory) {
    void setSurfaceBoundaries(final boolean recoveringMemory) {
        final WindowState w = mWin;
        if (mSurface == null) {
            if (w.mOrientationChanging) {
                if (DEBUG_ORIENTATION) {
                    Slog.v(TAG, "Orientation change skips hidden " + w);
                }
                w.mOrientationChanging = false;
            }
            return;
        }

        boolean displayed = false;

        computeShownFrameLocked();

        int width, height;
        if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
            // for a scaled surface, we just want to use
@@ -950,6 +944,8 @@ class WindowStateAnimator {
                        "SIZE " + width + "x" + height, null);
                mSurfaceResized = true;
                mSurface.setSize(width, height);
                mAnimator.mPendingLayoutChanges |=
                        WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
            } catch (RuntimeException e) {
                // If something goes wrong with the surface (such
                // as running out of memory), don't take down the
@@ -961,6 +957,25 @@ class WindowStateAnimator {
                }
            }
        }
    }

    public void prepareSurfaceLocked(final boolean recoveringMemory) {
        final WindowState w = mWin;
        if (mSurface == null) {
            if (w.mOrientationChanging) {
                if (DEBUG_ORIENTATION) {
                    Slog.v(TAG, "Orientation change skips hidden " + w);
                }
                w.mOrientationChanging = false;
            }
            return;
        }

        boolean displayed = false;

        computeShownFrameLocked();

        setSurfaceBoundaries(recoveringMemory);

        if (w.mAttachedHidden || !w.isReadyForDisplay()) {
            if (!mLastHidden) {