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

Commit bc133764 authored by Robert Carr's avatar Robert Carr
Browse files

Correct PiP inset adjustment.

We want to calculate the scaling factor we need to have
the content area of the surface (not including insets) to reach
our desired size, otherwise we will seem to scale the insets
up or down over time.

Bug: 28559097
Change-Id: I86dbd5fc902b5d380d33dba626c6694b3c57ff25
parent 625f97ba
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -1418,16 +1418,28 @@ class WindowStateAnimator {

        calculateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect);
        if (task != null && task.mStack.getForceScaleToCrop()) {
            extraHScale = mTmpClipRect.width() / (float)mTmpSize.width();
            extraVScale = mTmpClipRect.height() / (float)mTmpSize.height();
            int hInsets = w.getAttrs().surfaceInsets.left + w.getAttrs().surfaceInsets.right;
            int vInsets = w.getAttrs().surfaceInsets.top + w.getAttrs().surfaceInsets.bottom;
            // We want to calculate the scaling based on the content area, not based on
            // the entire surface, so that we scale in sync with windows that don't have insets.
            extraHScale = (mTmpClipRect.width() - hInsets) / (float)(mTmpSize.width() - hInsets);
            extraVScale = (mTmpClipRect.height() - vInsets) / (float)(mTmpSize.height() - vInsets);

            // In the case of ForceScaleToCrop we scale entire tasks together,
            // and so we need to scale our offsets relative to the task bounds
            // or parent and child windows would fall out of alignment.
            int posX = (int) (mTmpSize.left - w.mAttrs.x * (1 - extraHScale));
            int posY = (int) (mTmpSize.top - w.mAttrs.y * (1 - extraVScale));
            // Imagine we are scaling down. As we scale the buffer down, we decrease the
            // distance between the surface top left, and the start of the surface contents
            // (previously it was surfaceInsets.left pixels in screen space but now it
            // will be surfaceInsets.left*extraHScale). This means in order to keep the
            // non inset content at the same position, we have to shift the whole window
            // forward. Likewise for scaling up, we've increased this distance, and we need
            // to shift by a negative number to compensate.
            posX += w.getAttrs().surfaceInsets.left * (1 - extraHScale);
            posY += w.getAttrs().surfaceInsets.top * (1 - extraVScale);

            mSurfaceController.setPositionInTransaction(posX, posY, recoveringMemory);

            // Since we are scaled to fit in our previously desired crop, we can now