CTS: VulkanPreTransformTest remove device rotation restriction

This change removes the restriction that the device should be in natural
orientation when running the test. This change also adds a pass
situation that if the device refuses to rotate even if it's able to
rotate, the pre-rotation feature will not be tested.

Bug: b/115616012
Test: VulkanPreTransformTest
Change-Id: I065cd5a8ce3232c4c278897aa532e08476e9f497
diff --git a/tests/tests/graphics/src/android/graphics/cts/VulkanPreTransformCtsActivity.java b/tests/tests/graphics/src/android/graphics/cts/VulkanPreTransformCtsActivity.java
index 0194044..32cb757 100644
--- a/tests/tests/graphics/src/android/graphics/cts/VulkanPreTransformCtsActivity.java
+++ b/tests/tests/graphics/src/android/graphics/cts/VulkanPreTransformCtsActivity.java
@@ -57,18 +57,15 @@
             return;
         }
 
-        if (((WindowManager) getSystemService(Context.WINDOW_SERVICE))
-                        .getDefaultDisplay()
-                        .getRotation()
-                != Surface.ROTATION_0) {
-            throw new RuntimeException("Display not in natural orientation");
+        if (getRotation() == Surface.ROTATION_0) {
+            if (getResources().getConfiguration().orientation
+                    == Configuration.ORIENTATION_LANDSCAPE) {
+                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+            } else {
+                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+            }
         }
 
-        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
-            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
-        } else {
-            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
-        }
         sOrientationRequested = true;
     }
 
diff --git a/tests/tests/graphics/src/android/graphics/cts/VulkanPreTransformTest.java b/tests/tests/graphics/src/android/graphics/cts/VulkanPreTransformTest.java
index 898cc11..7918d58 100644
--- a/tests/tests/graphics/src/android/graphics/cts/VulkanPreTransformTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/VulkanPreTransformTest.java
@@ -44,7 +44,7 @@
 /*
  * testVulkanPreTransformSetToMatchCurrentTransform()
  *
- *   For devices rotating 90 degree CW when orientation changes.
+ *   For devices rotating 90 degrees.
  *
  *      Buffer          Screen
  *      ---------       ---------
@@ -53,7 +53,16 @@
  *      | B | Y |       | R | B |
  *      ---------       ---------
  *
- *   For devices rotating 90 degree CCW when orientation changes.
+ *   For devices rotating 180 degrees.
+ *
+ *      Buffer          Screen
+ *      ---------       ---------
+ *      | R | G |       | Y | B |
+ *      ---------       ---------
+ *      | B | Y |       | G | R |
+ *      ---------       ---------
+ *
+ *   For devices rotating 270 degrees.
  *
  *      Buffer          Screen
  *      ---------       ---------
@@ -62,6 +71,15 @@
  *      | B | Y |       | Y | G |
  *      ---------       ---------
  *
+ *   For devices not rotating.
+ *
+ *      Buffer          Screen
+ *      ---------       ---------
+ *      | R | G |       | R | G |
+ *      ---------       ---------
+ *      | B | Y |       | B | Y |
+ *      ---------       ---------
+ *
  * testVulkanPreTransformNotSetToMatchCurrentTransform()
  *
  *      Buffer          Screen
@@ -155,23 +173,26 @@
         int width = bitmap.getWidth();
         int height = bitmap.getHeight();
         int diff = 0;
-        if (!setPreTransform) {
+        if (!setPreTransform || sActivity.getRotation() == Surface.ROTATION_0) {
             diff += pixelDiff(bitmap.getPixel(0, 0), 255, 0, 0);
             diff += pixelDiff(bitmap.getPixel(width - 1, 0), 0, 255, 0);
             diff += pixelDiff(bitmap.getPixel(0, height - 1), 0, 0, 255);
             diff += pixelDiff(bitmap.getPixel(width - 1, height - 1), 255, 255, 0);
-        } else if (sActivity.getRotation() == Surface.ROTATION_270) {
-            // For devices rotating 90 degree CCW when orientation changes.
-            diff += pixelDiff(bitmap.getPixel(0, 0), 0, 0, 255);
-            diff += pixelDiff(bitmap.getPixel(width - 1, 0), 255, 0, 0);
-            diff += pixelDiff(bitmap.getPixel(0, height - 1), 255, 255, 0);
-            diff += pixelDiff(bitmap.getPixel(width - 1, height - 1), 0, 255, 0);
-        } else {
-            // For devices rotating 90 degree CW when orientation changes.
+        } else if (sActivity.getRotation() == Surface.ROTATION_90) {
             diff += pixelDiff(bitmap.getPixel(0, 0), 0, 255, 0);
             diff += pixelDiff(bitmap.getPixel(width - 1, 0), 255, 255, 0);
             diff += pixelDiff(bitmap.getPixel(0, height - 1), 255, 0, 0);
             diff += pixelDiff(bitmap.getPixel(width - 1, height - 1), 0, 0, 255);
+        } else if (sActivity.getRotation() == Surface.ROTATION_180) {
+            diff += pixelDiff(bitmap.getPixel(0, 0), 255, 255, 0);
+            diff += pixelDiff(bitmap.getPixel(width - 1, 0), 0, 0, 255);
+            diff += pixelDiff(bitmap.getPixel(0, height - 1), 0, 255, 0);
+            diff += pixelDiff(bitmap.getPixel(width - 1, height - 1), 255, 0, 0);
+        } else {
+            diff += pixelDiff(bitmap.getPixel(0, 0), 0, 0, 255);
+            diff += pixelDiff(bitmap.getPixel(width - 1, 0), 255, 0, 0);
+            diff += pixelDiff(bitmap.getPixel(0, height - 1), 255, 255, 0);
+            diff += pixelDiff(bitmap.getPixel(width - 1, height - 1), 0, 255, 0);
         }
 
         return diff < 10;