Clean up some rotation utility methods
Most of methods of RotationAnimationUtils were moved to other
class such as TransitionAnimation. One of the remaining method
is duplicated. So move the last method to CoordinateTransforms.
Assume the rotation animation related code in wm core will be
replaced by wm shell in the future, so prepare an initial cleanup.
Bug: 163976519
Test: CoordinateTransformsTest
Change-Id: Ibcf4aad7c771908b81150708db164e4e350935c4
diff --git a/services/core/java/com/android/server/display/ColorFade.java b/services/core/java/com/android/server/display/ColorFade.java
index 372bc8a..a4bd6a6 100644
--- a/services/core/java/com/android/server/display/ColorFade.java
+++ b/services/core/java/com/android/server/display/ColorFade.java
@@ -16,7 +16,7 @@
package com.android.server.display;
-import static com.android.server.wm.utils.RotationAnimationUtils.hasProtectedContent;
+import static com.android.internal.policy.TransitionAnimation.hasProtectedContent;
import android.content.Context;
import android.graphics.BLASTBufferQueue;
diff --git a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
index 449e77f..d395f12 100644
--- a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
+++ b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
@@ -31,6 +31,7 @@
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_SCREEN_ROTATION;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
+import static com.android.server.wm.utils.CoordinateTransforms.computeRotationMatrix;
import android.animation.ArgbEvaluator;
import android.content.Context;
@@ -60,7 +61,6 @@
import com.android.server.display.DisplayControl;
import com.android.server.wm.SurfaceAnimator.AnimationType;
import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
-import com.android.server.wm.utils.RotationAnimationUtils;
import java.io.PrintWriter;
@@ -378,8 +378,7 @@
// to the snapshot to make it stay in the same original position
// with the current screen rotation.
int delta = deltaRotation(rotation, mOriginalRotation);
- RotationAnimationUtils.createRotationMatrix(delta, mOriginalWidth, mOriginalHeight,
- mSnapshotInitialMatrix);
+ computeRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mSnapshotInitialMatrix);
setRotationTransform(t, mSnapshotInitialMatrix);
}
diff --git a/services/core/java/com/android/server/wm/utils/CoordinateTransforms.java b/services/core/java/com/android/server/wm/utils/CoordinateTransforms.java
index a2f37a5..7dc8a31 100644
--- a/services/core/java/com/android/server/wm/utils/CoordinateTransforms.java
+++ b/services/core/java/com/android/server/wm/utils/CoordinateTransforms.java
@@ -22,11 +22,9 @@
import static android.view.Surface.ROTATION_90;
import android.annotation.Dimension;
-import android.annotation.Nullable;
import android.graphics.Matrix;
-import android.graphics.Rect;
-import android.graphics.RectF;
import android.view.DisplayInfo;
+import android.view.Surface;
import android.view.Surface.Rotation;
public class CoordinateTransforms {
@@ -137,19 +135,24 @@
out.postConcat(tmp);
}
- /**
- * Transforms a rect using a transformation matrix
- *
- * @param transform the transformation to apply to the rect
- * @param inOutRect the rect to transform
- * @param tmp a temporary value, if null the function will allocate its own.
- */
- public static void transformRect(Matrix transform, Rect inOutRect, @Nullable RectF tmp) {
- if (tmp == null) {
- tmp = new RectF();
+ /** Computes the matrix that rotates the original w x h by the rotation delta. */
+ public static void computeRotationMatrix(int rotationDelta, int w, int h, Matrix outMatrix) {
+ switch (rotationDelta) {
+ case Surface.ROTATION_0:
+ outMatrix.reset();
+ break;
+ case Surface.ROTATION_90:
+ outMatrix.setRotate(90);
+ outMatrix.postTranslate(h, 0);
+ break;
+ case Surface.ROTATION_180:
+ outMatrix.setRotate(180);
+ outMatrix.postTranslate(w, h);
+ break;
+ case Surface.ROTATION_270:
+ outMatrix.setRotate(270);
+ outMatrix.postTranslate(0, w);
+ break;
}
- tmp.set(inOutRect);
- transform.mapRect(tmp);
- inOutRect.set((int) tmp.left, (int) tmp.top, (int) tmp.right, (int) tmp.bottom);
}
}
diff --git a/services/core/java/com/android/server/wm/utils/RotationAnimationUtils.java b/services/core/java/com/android/server/wm/utils/RotationAnimationUtils.java
deleted file mode 100644
index c11a6d0..0000000
--- a/services/core/java/com/android/server/wm/utils/RotationAnimationUtils.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wm.utils;
-
-import static android.hardware.HardwareBuffer.USAGE_PROTECTED_CONTENT;
-
-import android.graphics.Matrix;
-import android.hardware.HardwareBuffer;
-import android.view.Surface;
-
-
-/** Helper functions for the {@link com.android.server.wm.ScreenRotationAnimation} class*/
-public class RotationAnimationUtils {
-
- /**
- * @return whether the hardwareBuffer passed in is marked as protected.
- */
- public static boolean hasProtectedContent(HardwareBuffer hardwareBuffer) {
- return (hardwareBuffer.getUsage() & USAGE_PROTECTED_CONTENT) == USAGE_PROTECTED_CONTENT;
- }
-
- public static void createRotationMatrix(int rotation, int width, int height, Matrix outMatrix) {
- switch (rotation) {
- case Surface.ROTATION_0:
- outMatrix.reset();
- break;
- case Surface.ROTATION_90:
- outMatrix.setRotate(90, 0, 0);
- outMatrix.postTranslate(height, 0);
- break;
- case Surface.ROTATION_180:
- outMatrix.setRotate(180, 0, 0);
- outMatrix.postTranslate(width, height);
- break;
- case Surface.ROTATION_270:
- outMatrix.setRotate(270, 0, 0);
- outMatrix.postTranslate(0, width);
- break;
- }
- }
-}
diff --git a/services/tests/wmtests/src/com/android/server/wm/utils/CoordinateTransformsTest.java b/services/tests/wmtests/src/com/android/server/wm/utils/CoordinateTransformsTest.java
index 99ceb20..3e74626 100644
--- a/services/tests/wmtests/src/com/android/server/wm/utils/CoordinateTransformsTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/utils/CoordinateTransformsTest.java
@@ -21,6 +21,7 @@
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
+import static com.android.server.wm.utils.CoordinateTransforms.computeRotationMatrix;
import static com.android.server.wm.utils.CoordinateTransforms.transformLogicalToPhysicalCoordinates;
import static com.android.server.wm.utils.CoordinateTransforms.transformPhysicalToLogicalCoordinates;
import static com.android.server.wm.utils.CoordinateTransforms.transformToRotation;
@@ -185,6 +186,44 @@
assertEquals(mMatrix2, mMatrix);
}
+ @Test
+ public void rotate_0_bottomRight() {
+ computeRotationMatrix(ROTATION_0, W, H, mMatrix);
+ PointF newPoints = checkMappedPoints(W, H);
+ assertEquals(W, newPoints.x, 0);
+ assertEquals(H, newPoints.y, 0);
+ }
+
+ @Test
+ public void rotate_90_bottomRight() {
+ computeRotationMatrix(ROTATION_90, W, H, mMatrix);
+ PointF newPoints = checkMappedPoints(W, H);
+ assertEquals(0, newPoints.x, 0);
+ assertEquals(W, newPoints.y, 0);
+ }
+
+ @Test
+ public void rotate_180_bottomRight() {
+ computeRotationMatrix(ROTATION_180, W, H, mMatrix);
+ PointF newPoints = checkMappedPoints(W, H);
+ assertEquals(0, newPoints.x, 0);
+ assertEquals(0, newPoints.y, 0);
+ }
+
+ @Test
+ public void rotate_270_bottomRight() {
+ computeRotationMatrix(ROTATION_270, W, H, mMatrix);
+ PointF newPoints = checkMappedPoints(W, H);
+ assertEquals(H, newPoints.x, 0);
+ assertEquals(0, newPoints.y, 0);
+ }
+
+ private PointF checkMappedPoints(int x, int y) {
+ final float[] fs = new float[] {x, y};
+ mMatrix.mapPoints(fs);
+ return new PointF(fs[0], fs[1]);
+ }
+
private void assertMatricesAreInverses(Matrix matrix, Matrix matrix2) {
final Matrix concat = new Matrix();
concat.setConcat(matrix, matrix2);
diff --git a/services/tests/wmtests/src/com/android/server/wm/utils/RotationAnimationUtilsTest.java b/services/tests/wmtests/src/com/android/server/wm/utils/RotationAnimationUtilsTest.java
index cd4d65d..ff43ff7 100644
--- a/services/tests/wmtests/src/com/android/server/wm/utils/RotationAnimationUtilsTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/utils/RotationAnimationUtilsTest.java
@@ -23,15 +23,11 @@
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.ColorSpace;
-import android.graphics.Matrix;
-import android.graphics.PointF;
import android.hardware.HardwareBuffer;
import android.platform.test.annotations.Presubmit;
-import android.view.Surface;
import com.android.internal.policy.TransitionAnimation;
-import org.junit.Before;
import org.junit.Test;
@Presubmit
@@ -39,16 +35,8 @@
private static final int BITMAP_HEIGHT = 100;
private static final int BITMAP_WIDTH = 100;
- private static final int POINT_WIDTH = 1000;
- private static final int POINT_HEIGHT = 2000;
private ColorSpace mColorSpace = ColorSpace.get(ColorSpace.Named.DISPLAY_P3);
- private Matrix mMatrix;
-
- @Before
- public void setup() {
- mMatrix = new Matrix();
- }
@Test
public void blackLuma() {
@@ -93,48 +81,6 @@
assertEquals(1, borderLuma, 0);
}
- @Test
- public void rotate_0_bottomRight() {
- RotationAnimationUtils.createRotationMatrix(Surface.ROTATION_0,
- POINT_WIDTH, POINT_HEIGHT, mMatrix);
- PointF newPoints = checkMappedPoints(POINT_WIDTH, POINT_HEIGHT);
- assertEquals(POINT_WIDTH, newPoints.x, 0);
- assertEquals(POINT_HEIGHT, newPoints.y, 0);
- }
-
- @Test
- public void rotate_90_bottomRight() {
- RotationAnimationUtils.createRotationMatrix(Surface.ROTATION_90,
- POINT_WIDTH, POINT_HEIGHT, mMatrix);
- PointF newPoints = checkMappedPoints(POINT_WIDTH, POINT_HEIGHT);
- assertEquals(0, newPoints.x, 0);
- assertEquals(POINT_WIDTH, newPoints.y, 0);
- }
-
- @Test
- public void rotate_180_bottomRight() {
- RotationAnimationUtils.createRotationMatrix(Surface.ROTATION_180,
- POINT_WIDTH, POINT_HEIGHT, mMatrix);
- PointF newPoints = checkMappedPoints(POINT_WIDTH, POINT_HEIGHT);
- assertEquals(0, newPoints.x, 0);
- assertEquals(0, newPoints.y, 0);
- }
-
- @Test
- public void rotate_270_bottomRight() {
- RotationAnimationUtils.createRotationMatrix(Surface.ROTATION_270,
- POINT_WIDTH, POINT_HEIGHT, mMatrix);
- PointF newPoints = checkMappedPoints(POINT_WIDTH, POINT_HEIGHT);
- assertEquals(POINT_HEIGHT, newPoints.x, 0);
- assertEquals(0, newPoints.y, 0);
- }
-
- private PointF checkMappedPoints(int x, int y) {
- final float[] fs = new float[] {x, y};
- mMatrix.mapPoints(fs);
- return new PointF(fs[0], fs[1]);
- }
-
private Bitmap createBitmap(float luma) {
return createBitmap(luma, BITMAP_WIDTH, BITMAP_HEIGHT);
}