SF: Fix arbitrary rotation with inverse display transform

Bug 28043535

Change-Id: I8b939e17f91cf7e5b617bbcceb9df4efcc9d0161
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index ed320cb..257eaad 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -448,17 +448,10 @@
         if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) {
             invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
                     NATIVE_WINDOW_TRANSFORM_FLIP_H;
-            // If the transform has been rotated the axis of flip has been swapped
-            // so we need to swap which flip operations we are performing
-            bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0;
-            bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0;
-            if (is_h_flipped != is_v_flipped) {
-                invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
-                        NATIVE_WINDOW_TRANSFORM_FLIP_H;
-            }
         }
         // and apply to the current transform
-        invTransform = (Transform(invTransform) * Transform(invTransformOrient)).getOrientation();
+        invTransform = (Transform(invTransformOrient) * Transform(invTransform))
+                .getOrientation();
     }
 
     int winWidth = s.active.w;
@@ -645,23 +638,13 @@
          */
         uint32_t invTransform =
                 DisplayDevice::getPrimaryDisplayOrientationTransform();
-
-        uint32_t t_orientation = transform.getOrientation();
         // calculate the inverse transform
         if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
             invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
                     NATIVE_WINDOW_TRANSFORM_FLIP_H;
-            // If the transform has been rotated the axis of flip has been swapped
-            // so we need to swap which flip operations we are performing
-            bool is_h_flipped = (t_orientation & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0;
-            bool is_v_flipped = (t_orientation & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0;
-            if (is_h_flipped != is_v_flipped) {
-                t_orientation ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
-                        NATIVE_WINDOW_TRANSFORM_FLIP_H;
-            }
         }
         // and apply to the current transform
-        transform = Transform(t_orientation) * Transform(invTransform);
+        transform = Transform(invTransform) * transform;
     }
 
     // this gives us only the "orientation" component of the transform