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

Commit c31ca6d9 authored by Rob Carr's avatar Rob Carr Committed by Android (Google) Code Review
Browse files

Merge changes Icf1215c2,I3c8edef0,Icebd94f8

* changes:
  WindowState: Fix transaction usage in preserve surface
  WindowState/WindowStateAnimator: Remove cropping
  WindowStateAnimator/ViewRoot: Move surface resizing to client
parents 5d5f71ee 5a964a3f
Loading
Loading
Loading
Loading
+34 −9
Original line number Diff line number Diff line
@@ -1810,7 +1810,7 @@ public final class ViewRootImpl implements ViewParent,
                    .setParent(getRenderSurfaceControl())
                    .setCallsite("ViewRootImpl.getBoundsLayer")
                    .build();
            setBoundsLayerCrop();
            setBoundsLayerCrop(mTransaction);
            mTransaction.show(mBoundsLayer).apply();
        }
       return mBoundsLayer;
@@ -1838,25 +1838,41 @@ public final class ViewRootImpl implements ViewParent,
        return ret;
    }

    private void setBoundsLayerCrop() {
    private void setBoundsLayerCrop(Transaction t) {
        // mWinFrame is already adjusted for surface insets. So offset it and use it as
        // the cropping bounds.
        mTempBoundsRect.set(mWinFrame);
        mTempBoundsRect.offsetTo(mWindowAttributes.surfaceInsets.left,
                mWindowAttributes.surfaceInsets.top);
        mTransaction.setWindowCrop(mBoundsLayer, mTempBoundsRect);
        t.setWindowCrop(mBoundsLayer, mTempBoundsRect);
    }

    /**
     * Called after window layout to update the bounds surface. If the surface insets have changed
     * or the surface has resized, update the bounds surface.
     */
    private void updateBoundsLayer() {
    private boolean updateBoundsLayer(SurfaceControl.Transaction t) {
        if (mBoundsLayer != null) {
            setBoundsLayerCrop();
            mTransaction.deferTransactionUntil(mBoundsLayer,
                    getRenderSurfaceControl(), mSurface.getNextFrameNumber())
                    .apply();
            setBoundsLayerCrop(t);
            t.deferTransactionUntil(mBoundsLayer, getRenderSurfaceControl(),
                mSurface.getNextFrameNumber());
            return true;
        }
        return false;
    }

    private void prepareSurfaces(boolean sizeChanged) {
        final SurfaceControl.Transaction t = mTransaction;
        final SurfaceControl sc = getRenderSurfaceControl();
        if (!sc.isValid()) return;

        boolean applyTransaction = updateBoundsLayer(t);
        if (sizeChanged) {
            applyTransaction = true;
            t.setBufferSize(sc, mSurfaceSize.x, mSurfaceSize.y);
        }
        if (applyTransaction) {
            t.apply();
        }
    }

@@ -2947,7 +2963,16 @@ public final class ViewRootImpl implements ViewParent,
        }

        if (surfaceSizeChanged || surfaceReplaced || surfaceCreated || windowAttributesChanged) {
            updateBoundsLayer();
            // If the surface has been replaced, there's a chance the bounds layer is not parented
            // to the new layer. When updating bounds layer, also reparent to the main VRI
            // SurfaceControl to ensure it's correctly placed in the hierarchy.
            //
            // This needs to be done on the client side since WMS won't reparent the children to the
            // new surface if it thinks the app is closing. WMS gets the signal that the app is
            // stopping, but on the client side it doesn't get stopped since it's restarted quick
            // enough. WMS doesn't want to keep around old children since they will leak when the
            // client creates new children.
            prepareSurfaces(surfaceSizeChanged);
        }

        final boolean didLayout = layoutRequested && (!mStopped || mReportNextDraw);
+1 −1
Original line number Diff line number Diff line
@@ -7867,7 +7867,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        InsetUtils.addInsets(insets, getLetterboxInsets());
        return new RemoteAnimationTarget(task.mTaskId, record.getMode(),
                record.mAdapter.mCapturedLeash, !fillsParent(),
                mainWindow.mWinAnimator.mLastClipRect, insets,
                new Rect(), insets,
                getPrefixOrderIndex(), record.mAdapter.mPosition, record.mAdapter.mLocalBounds,
                record.mAdapter.mStackBounds, task.getWindowConfiguration(),
                false /*isNotInRecents*/,
+1 −1
Original line number Diff line number Diff line
@@ -929,7 +929,7 @@ public class RecentsAnimationController implements DeathRecipient {
                    ? MODE_OPENING
                    : MODE_CLOSING;
            mTarget = new RemoteAnimationTarget(mTask.mTaskId, mode, mCapturedLeash,
                    !topApp.fillsParent(), mainWindow.mWinAnimator.mLastClipRect,
                    !topApp.fillsParent(), new Rect(),
                    insets, mTask.getPrefixOrderIndex(), new Point(mBounds.left, mBounds.top),
                    mLocalBounds, mBounds, mTask.getWindowConfiguration(),
                    mIsRecentTaskInvisible, null, null);
+2 −2
Original line number Diff line number Diff line
@@ -2423,8 +2423,8 @@ public class WindowManagerService extends IWindowManager.Stub
                Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
            }
            if (winAnimator.mSurfaceController != null) {
                outSurfaceSize.set(winAnimator.mSurfaceController.getWidth(),
                                         winAnimator.mSurfaceController.getHeight());
                win.calculateSurfaceBounds(win.getAttrs(), mTmpRect);
                outSurfaceSize.set(mTmpRect.width(), mTmpRect.height());
            }
            getInsetsSourceControls(win, outActiveControls);
        }
+37 −89
Original line number Diff line number Diff line
@@ -4949,93 +4949,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        return mToken.canLayerAboveSystemBars();
    }

    /**
     * Calculate the window crop according to system decor policy. In general this is
     * the system decor rect (see #calculateSystemDecorRect), but we also have some
     * special cases. This rectangle is in screen space.
     */
    void calculatePolicyCrop(Rect policyCrop) {
        final DisplayContent displayContent = getDisplayContent();

        if (!displayContent.isDefaultDisplay && !displayContent.supportsSystemDecorations()) {
            // On a different display there is no system decor. Crop the window
            // by the screen boundaries.
            final DisplayInfo displayInfo = getDisplayInfo();
            policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
                    mWindowFrames.mCompatFrame.height());
            policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top,
                    displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left,
                    displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top);
        } else if (skipDecorCrop()) {
            // Windows without policy decor aren't cropped.
            policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
                    mWindowFrames.mCompatFrame.height());
        } else {
            // Crop to the system decor specified by policy.
            calculateSystemDecorRect(policyCrop);
        }
    }

    /**
     * The system decor rect is the region of the window which is not covered
     * by system decorations.
     */
    private void calculateSystemDecorRect(Rect systemDecorRect) {
        final Rect decorRect = mWindowFrames.mDecorFrame;
        final int width = mWindowFrames.mFrame.width();
        final int height = mWindowFrames.mFrame.height();

        final int left = mWindowFrames.mFrame.left;
        final int top = mWindowFrames.mFrame.top;

        // Initialize the decor rect to the entire frame.
        if (isDockedResizing()) {
            // If we are resizing with the divider, the task bounds might be smaller than the
            // stack bounds. The system decor is used to clip to the task bounds, which we don't
            // want in this case in order to avoid holes.
            //
            // We take care to not shrink the width, for surfaces which are larger than
            // the display region. Of course this area will not eventually be visible
            // but if we truncate the width now, we will calculate incorrectly
            // when adjusting to the stack bounds.
            final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
            systemDecorRect.set(0, 0,
                    Math.max(width, displayInfo.logicalWidth),
                    Math.max(height, displayInfo.logicalHeight));
        } else {
            systemDecorRect.set(0, 0, width, height);
        }

        // If a freeform window is animating from a position where it would be cutoff, it would be
        // cutoff during the animation. We don't want that, so for the duration of the animation
        // we ignore the decor cropping and depend on layering to position windows correctly.

        // We also ignore cropping when the window is currently being drag resized in split screen
        // to prevent issues with the crop for screenshot.
        final boolean cropToDecor =
                !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
        if (cropToDecor) {
            // Intersect with the decor rect, offsetted by window position.
            systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
                    decorRect.right - left, decorRect.bottom - top);
        }

        // If size compatibility is being applied to the window, the
        // surface is scaled relative to the screen.  Also apply this
        // scaling to the crop rect.  We aren't using the standard rect
        // scale function because we want to round things to make the crop
        // always round to a larger rect to ensure we don't crop too
        // much and hide part of the window that should be seen.
        if (mInvGlobalScale != 1.0f && inSizeCompatMode()) {
            final float scale = mInvGlobalScale;
            systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
            systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
            systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
            systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
        }

    }

    /**
     * Expand the given rectangle by this windows surface insets. This
     * takes you from the 'window size' to the 'surface size'.
@@ -5093,9 +5006,10 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            // on the new one. This prevents blinking when we change elevation of freeform and
            // pinned windows.
            if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
                mWinAnimator.preserveSurfaceLocked();
                mWinAnimator.preserveSurfaceLocked(getPendingTransaction());
                result |= RELAYOUT_RES_SURFACE_CHANGED
                        | RELAYOUT_RES_FIRST_TIME;
                scheduleAnimation();
            }
        }

@@ -5111,9 +5025,10 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            // to preserve and destroy windows which are attached to another, they
            // will keep their surface and its size may change over time.
            if (mHasSurface && !isChildWindow()) {
                mWinAnimator.preserveSurfaceLocked();
                mWinAnimator.preserveSurfaceLocked(getPendingTransaction());
                result |= RELAYOUT_RES_SURFACE_CHANGED |
                    RELAYOUT_RES_FIRST_TIME;
                scheduleAnimation();
            }
        }
        final boolean freeformResizing = isDragResizing()
@@ -5937,4 +5852,37 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    void requestRedrawForSync() {
        mRedrawForSyncReported = false;
    }

    void calculateSurfaceBounds(WindowManager.LayoutParams attrs, Rect outSize) {
        outSize.setEmpty();
        if ((attrs.flags & FLAG_SCALED) != 0) {
            // For a scaled surface, we always want the requested size.
            outSize.right = mRequestedWidth;
            outSize.bottom = mRequestedHeight;
        } else {
            // When we're doing a drag-resizing, request a surface that's fullscreen size,
            // so that we don't need to reallocate during the process. This also prevents
            // buffer drops due to size mismatch.
            if (isDragResizing()) {
                final DisplayInfo displayInfo = getDisplayInfo();
                outSize.right = displayInfo.logicalWidth;
                outSize.bottom = displayInfo.logicalHeight;
            } else {
                getCompatFrameSize(outSize);
            }
        }

        // This doesn't necessarily mean that there is an error in the system. The sizes might be
        // incorrect, because it is before the first layout or draw.
        if (outSize.width() < 1) {
            outSize.right = 1;
        }
        if (outSize.height() < 1) {
            outSize.bottom = 1;
        }

        // Adjust for surface insets.
        outSize.inset(-attrs.surfaceInsets.left, -attrs.surfaceInsets.top,
                -attrs.surfaceInsets.right, -attrs.surfaceInsets.bottom);
    }
}
Loading