From bc133764497bcc4d9990ecc07a8d1053b2a1b46d Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Thu, 12 May 2016 14:04:38 -0700 Subject: [PATCH] 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 --- .../android/server/wm/WindowStateAnimator.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java index 52273dced231c..f7fc00535cb2d 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -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