Loading services/core/java/com/android/server/wm/ScreenRotationAnimation.java +21 −35 Original line number Original line Diff line number Diff line Loading @@ -108,15 +108,12 @@ class ScreenRotationAnimation { */ */ private SurfaceControl mBackColorSurface; private SurfaceControl mBackColorSurface; private BlackFrame mEnteringBlackFrame; private BlackFrame mEnteringBlackFrame; private int mWidth, mHeight; private final int mOriginalRotation; private final int mOriginalRotation; private final int mOriginalWidth; private final int mOriginalWidth; private final int mOriginalHeight; private final int mOriginalHeight; private int mCurRotation; private int mCurRotation; private Rect mOriginalDisplayRect = new Rect(); private Rect mCurrentDisplayRect = new Rect(); // The current active animation to move from the old to the new rotated // The current active animation to move from the old to the new rotated // state. Which animation is run here will depend on the old and new // state. Which animation is run here will depend on the old and new // rotations. // rotations. Loading @@ -127,7 +124,6 @@ class ScreenRotationAnimation { private boolean mAnimRunning; private boolean mAnimRunning; private boolean mFinishAnimReady; private boolean mFinishAnimReady; private long mFinishAnimStartTime; private long mFinishAnimStartTime; private boolean mForceDefaultOrientation; private SurfaceRotationAnimationController mSurfaceRotationAnimationController; private SurfaceRotationAnimationController mSurfaceRotationAnimationController; /** Intensity of light/whiteness of the layout before rotation occurs. */ /** Intensity of light/whiteness of the layout before rotation occurs. */ private float mStartLuma; private float mStartLuma; Loading @@ -138,25 +134,13 @@ class ScreenRotationAnimation { mService = displayContent.mWmService; mService = displayContent.mWmService; mContext = mService.mContext; mContext = mService.mContext; mDisplayContent = displayContent; mDisplayContent = displayContent; displayContent.getBounds(mOriginalDisplayRect); final Rect currentBounds = displayContent.getBounds(); final int width = currentBounds.width(); final int height = currentBounds.height(); // Screenshot does NOT include rotation! // Screenshot does NOT include rotation! final DisplayInfo displayInfo = displayContent.getDisplayInfo(); final DisplayInfo displayInfo = displayContent.getDisplayInfo(); final int realOriginalRotation = displayInfo.rotation; final int realOriginalRotation = displayInfo.rotation; final int originalWidth; final int originalHeight; if (displayContent.getDisplayRotation().isFixedToUserRotation()) { // Emulated orientation. mForceDefaultOrientation = true; originalWidth = displayContent.mBaseDisplayWidth; originalHeight = displayContent.mBaseDisplayHeight; } else { // Normal situation originalWidth = displayInfo.logicalWidth; originalHeight = displayInfo.logicalHeight; } mWidth = originalWidth; mHeight = originalHeight; mOriginalRotation = originalRotation; mOriginalRotation = originalRotation; // If the delta is not zero, the rotation of display may not change, but we still want to // If the delta is not zero, the rotation of display may not change, but we still want to Loading @@ -165,8 +149,8 @@ class ScreenRotationAnimation { // when restoring the rotated app to the same rotation as current display. // when restoring the rotated app to the same rotation as current display. final int delta = deltaRotation(originalRotation, realOriginalRotation); final int delta = deltaRotation(originalRotation, realOriginalRotation); final boolean flipped = delta == Surface.ROTATION_90 || delta == Surface.ROTATION_270; final boolean flipped = delta == Surface.ROTATION_90 || delta == Surface.ROTATION_270; mOriginalWidth = flipped ? originalHeight : originalWidth; mOriginalWidth = flipped ? height : width; mOriginalHeight = flipped ? originalWidth : originalHeight; mOriginalHeight = flipped ? width : height; mSurfaceRotationAnimationController = new SurfaceRotationAnimationController(); mSurfaceRotationAnimationController = new SurfaceRotationAnimationController(); // Check whether the current screen contains any secure content. // Check whether the current screen contains any secure content. Loading @@ -179,7 +163,7 @@ class ScreenRotationAnimation { new SurfaceControl.LayerCaptureArgs.Builder(displayContent.getSurfaceControl()) new SurfaceControl.LayerCaptureArgs.Builder(displayContent.getSurfaceControl()) .setCaptureSecureLayers(true) .setCaptureSecureLayers(true) .setAllowProtected(true) .setAllowProtected(true) .setSourceCrop(new Rect(0, 0, mWidth, mHeight)) .setSourceCrop(new Rect(0, 0, width, height)) .build(); .build(); SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer = SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer = SurfaceControl.captureLayers(args); SurfaceControl.captureLayers(args); Loading Loading @@ -244,6 +228,19 @@ class ScreenRotationAnimation { Slog.w(TAG, "Unable to allocate freeze surface", e); Slog.w(TAG, "Unable to allocate freeze surface", e); } } // If display size is changed with the same orientation, map the bounds of screenshot to // the new logical display size. Currently pending transaction and RWC#mDisplayTransaction // are merged to global transaction, so it can be synced with display change when calling // DisplayManagerInternal#performTraversal(transaction). final int logicalWidth = displayInfo.logicalWidth; final int logicalHeight = displayInfo.logicalHeight; if (logicalWidth > mOriginalWidth == logicalHeight > mOriginalHeight && (logicalWidth != mOriginalWidth || logicalHeight != mOriginalHeight)) { displayContent.getPendingTransaction().setGeometry(mScreenshotLayer, new Rect(0, 0, mOriginalWidth, mOriginalHeight), new Rect(0, 0, logicalWidth, logicalHeight), Surface.ROTATION_0); } ProtoLog.i(WM_SHOW_SURFACE_ALLOC, ProtoLog.i(WM_SHOW_SURFACE_ALLOC, " FREEZE %s: CREATE", mScreenshotLayer); " FREEZE %s: CREATE", mScreenshotLayer); if (originalRotation == realOriginalRotation) { if (originalRotation == realOriginalRotation) { Loading Loading @@ -277,11 +274,6 @@ class ScreenRotationAnimation { matrix.getValues(mTmpFloats); matrix.getValues(mTmpFloats); float x = mTmpFloats[Matrix.MTRANS_X]; float x = mTmpFloats[Matrix.MTRANS_X]; float y = mTmpFloats[Matrix.MTRANS_Y]; float y = mTmpFloats[Matrix.MTRANS_Y]; if (mForceDefaultOrientation) { mDisplayContent.getBounds(mCurrentDisplayRect); x -= mCurrentDisplayRect.left; y -= mCurrentDisplayRect.top; } t.setPosition(mScreenshotLayer, x, y); t.setPosition(mScreenshotLayer, x, y); t.setMatrix(mScreenshotLayer, t.setMatrix(mScreenshotLayer, mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y], mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y], Loading @@ -293,8 +285,6 @@ class ScreenRotationAnimation { public void printTo(String prefix, PrintWriter pw) { public void printTo(String prefix, PrintWriter pw) { pw.print(prefix); pw.print("mSurface="); pw.print(mScreenshotLayer); pw.print(prefix); pw.print("mSurface="); pw.print(mScreenshotLayer); pw.print(" mWidth="); pw.print(mWidth); pw.print(" mHeight="); pw.println(mHeight); pw.print(prefix); pw.print(prefix); pw.print("mEnteringBlackFrame="); pw.print("mEnteringBlackFrame="); pw.println(mEnteringBlackFrame); pw.println(mEnteringBlackFrame); Loading @@ -315,11 +305,6 @@ class ScreenRotationAnimation { pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println(); pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println(); pw.print(prefix); pw.print("mSnapshotInitialMatrix="); pw.print(prefix); pw.print("mSnapshotInitialMatrix="); mSnapshotInitialMatrix.dump(pw); pw.println(); mSnapshotInitialMatrix.dump(pw); pw.println(); pw.print(prefix); pw.print("mForceDefaultOrientation="); pw.print(mForceDefaultOrientation); if (mForceDefaultOrientation) { pw.print(" mOriginalDisplayRect="); pw.print(mOriginalDisplayRect.toShortString()); pw.print(" mCurrentDisplayRect="); pw.println(mCurrentDisplayRect.toShortString()); } } } public void setRotation(SurfaceControl.Transaction t, int rotation) { public void setRotation(SurfaceControl.Transaction t, int rotation) { Loading @@ -329,7 +314,8 @@ class ScreenRotationAnimation { // to the snapshot to make it stay in the same original position // to the snapshot to make it stay in the same original position // with the current screen rotation. // with the current screen rotation. int delta = deltaRotation(rotation, mOriginalRotation); int delta = deltaRotation(rotation, mOriginalRotation); RotationAnimationUtils.createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix); RotationAnimationUtils.createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mSnapshotInitialMatrix); setRotationTransform(t, mSnapshotInitialMatrix); setRotationTransform(t, mSnapshotInitialMatrix); } } Loading Loading
services/core/java/com/android/server/wm/ScreenRotationAnimation.java +21 −35 Original line number Original line Diff line number Diff line Loading @@ -108,15 +108,12 @@ class ScreenRotationAnimation { */ */ private SurfaceControl mBackColorSurface; private SurfaceControl mBackColorSurface; private BlackFrame mEnteringBlackFrame; private BlackFrame mEnteringBlackFrame; private int mWidth, mHeight; private final int mOriginalRotation; private final int mOriginalRotation; private final int mOriginalWidth; private final int mOriginalWidth; private final int mOriginalHeight; private final int mOriginalHeight; private int mCurRotation; private int mCurRotation; private Rect mOriginalDisplayRect = new Rect(); private Rect mCurrentDisplayRect = new Rect(); // The current active animation to move from the old to the new rotated // The current active animation to move from the old to the new rotated // state. Which animation is run here will depend on the old and new // state. Which animation is run here will depend on the old and new // rotations. // rotations. Loading @@ -127,7 +124,6 @@ class ScreenRotationAnimation { private boolean mAnimRunning; private boolean mAnimRunning; private boolean mFinishAnimReady; private boolean mFinishAnimReady; private long mFinishAnimStartTime; private long mFinishAnimStartTime; private boolean mForceDefaultOrientation; private SurfaceRotationAnimationController mSurfaceRotationAnimationController; private SurfaceRotationAnimationController mSurfaceRotationAnimationController; /** Intensity of light/whiteness of the layout before rotation occurs. */ /** Intensity of light/whiteness of the layout before rotation occurs. */ private float mStartLuma; private float mStartLuma; Loading @@ -138,25 +134,13 @@ class ScreenRotationAnimation { mService = displayContent.mWmService; mService = displayContent.mWmService; mContext = mService.mContext; mContext = mService.mContext; mDisplayContent = displayContent; mDisplayContent = displayContent; displayContent.getBounds(mOriginalDisplayRect); final Rect currentBounds = displayContent.getBounds(); final int width = currentBounds.width(); final int height = currentBounds.height(); // Screenshot does NOT include rotation! // Screenshot does NOT include rotation! final DisplayInfo displayInfo = displayContent.getDisplayInfo(); final DisplayInfo displayInfo = displayContent.getDisplayInfo(); final int realOriginalRotation = displayInfo.rotation; final int realOriginalRotation = displayInfo.rotation; final int originalWidth; final int originalHeight; if (displayContent.getDisplayRotation().isFixedToUserRotation()) { // Emulated orientation. mForceDefaultOrientation = true; originalWidth = displayContent.mBaseDisplayWidth; originalHeight = displayContent.mBaseDisplayHeight; } else { // Normal situation originalWidth = displayInfo.logicalWidth; originalHeight = displayInfo.logicalHeight; } mWidth = originalWidth; mHeight = originalHeight; mOriginalRotation = originalRotation; mOriginalRotation = originalRotation; // If the delta is not zero, the rotation of display may not change, but we still want to // If the delta is not zero, the rotation of display may not change, but we still want to Loading @@ -165,8 +149,8 @@ class ScreenRotationAnimation { // when restoring the rotated app to the same rotation as current display. // when restoring the rotated app to the same rotation as current display. final int delta = deltaRotation(originalRotation, realOriginalRotation); final int delta = deltaRotation(originalRotation, realOriginalRotation); final boolean flipped = delta == Surface.ROTATION_90 || delta == Surface.ROTATION_270; final boolean flipped = delta == Surface.ROTATION_90 || delta == Surface.ROTATION_270; mOriginalWidth = flipped ? originalHeight : originalWidth; mOriginalWidth = flipped ? height : width; mOriginalHeight = flipped ? originalWidth : originalHeight; mOriginalHeight = flipped ? width : height; mSurfaceRotationAnimationController = new SurfaceRotationAnimationController(); mSurfaceRotationAnimationController = new SurfaceRotationAnimationController(); // Check whether the current screen contains any secure content. // Check whether the current screen contains any secure content. Loading @@ -179,7 +163,7 @@ class ScreenRotationAnimation { new SurfaceControl.LayerCaptureArgs.Builder(displayContent.getSurfaceControl()) new SurfaceControl.LayerCaptureArgs.Builder(displayContent.getSurfaceControl()) .setCaptureSecureLayers(true) .setCaptureSecureLayers(true) .setAllowProtected(true) .setAllowProtected(true) .setSourceCrop(new Rect(0, 0, mWidth, mHeight)) .setSourceCrop(new Rect(0, 0, width, height)) .build(); .build(); SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer = SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer = SurfaceControl.captureLayers(args); SurfaceControl.captureLayers(args); Loading Loading @@ -244,6 +228,19 @@ class ScreenRotationAnimation { Slog.w(TAG, "Unable to allocate freeze surface", e); Slog.w(TAG, "Unable to allocate freeze surface", e); } } // If display size is changed with the same orientation, map the bounds of screenshot to // the new logical display size. Currently pending transaction and RWC#mDisplayTransaction // are merged to global transaction, so it can be synced with display change when calling // DisplayManagerInternal#performTraversal(transaction). final int logicalWidth = displayInfo.logicalWidth; final int logicalHeight = displayInfo.logicalHeight; if (logicalWidth > mOriginalWidth == logicalHeight > mOriginalHeight && (logicalWidth != mOriginalWidth || logicalHeight != mOriginalHeight)) { displayContent.getPendingTransaction().setGeometry(mScreenshotLayer, new Rect(0, 0, mOriginalWidth, mOriginalHeight), new Rect(0, 0, logicalWidth, logicalHeight), Surface.ROTATION_0); } ProtoLog.i(WM_SHOW_SURFACE_ALLOC, ProtoLog.i(WM_SHOW_SURFACE_ALLOC, " FREEZE %s: CREATE", mScreenshotLayer); " FREEZE %s: CREATE", mScreenshotLayer); if (originalRotation == realOriginalRotation) { if (originalRotation == realOriginalRotation) { Loading Loading @@ -277,11 +274,6 @@ class ScreenRotationAnimation { matrix.getValues(mTmpFloats); matrix.getValues(mTmpFloats); float x = mTmpFloats[Matrix.MTRANS_X]; float x = mTmpFloats[Matrix.MTRANS_X]; float y = mTmpFloats[Matrix.MTRANS_Y]; float y = mTmpFloats[Matrix.MTRANS_Y]; if (mForceDefaultOrientation) { mDisplayContent.getBounds(mCurrentDisplayRect); x -= mCurrentDisplayRect.left; y -= mCurrentDisplayRect.top; } t.setPosition(mScreenshotLayer, x, y); t.setPosition(mScreenshotLayer, x, y); t.setMatrix(mScreenshotLayer, t.setMatrix(mScreenshotLayer, mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y], mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y], Loading @@ -293,8 +285,6 @@ class ScreenRotationAnimation { public void printTo(String prefix, PrintWriter pw) { public void printTo(String prefix, PrintWriter pw) { pw.print(prefix); pw.print("mSurface="); pw.print(mScreenshotLayer); pw.print(prefix); pw.print("mSurface="); pw.print(mScreenshotLayer); pw.print(" mWidth="); pw.print(mWidth); pw.print(" mHeight="); pw.println(mHeight); pw.print(prefix); pw.print(prefix); pw.print("mEnteringBlackFrame="); pw.print("mEnteringBlackFrame="); pw.println(mEnteringBlackFrame); pw.println(mEnteringBlackFrame); Loading @@ -315,11 +305,6 @@ class ScreenRotationAnimation { pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println(); pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println(); pw.print(prefix); pw.print("mSnapshotInitialMatrix="); pw.print(prefix); pw.print("mSnapshotInitialMatrix="); mSnapshotInitialMatrix.dump(pw); pw.println(); mSnapshotInitialMatrix.dump(pw); pw.println(); pw.print(prefix); pw.print("mForceDefaultOrientation="); pw.print(mForceDefaultOrientation); if (mForceDefaultOrientation) { pw.print(" mOriginalDisplayRect="); pw.print(mOriginalDisplayRect.toShortString()); pw.print(" mCurrentDisplayRect="); pw.println(mCurrentDisplayRect.toShortString()); } } } public void setRotation(SurfaceControl.Transaction t, int rotation) { public void setRotation(SurfaceControl.Transaction t, int rotation) { Loading @@ -329,7 +314,8 @@ class ScreenRotationAnimation { // to the snapshot to make it stay in the same original position // to the snapshot to make it stay in the same original position // with the current screen rotation. // with the current screen rotation. int delta = deltaRotation(rotation, mOriginalRotation); int delta = deltaRotation(rotation, mOriginalRotation); RotationAnimationUtils.createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix); RotationAnimationUtils.createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mSnapshotInitialMatrix); setRotationTransform(t, mSnapshotInitialMatrix); setRotationTransform(t, mSnapshotInitialMatrix); } } Loading