SF: Fix NATIVE_WINDOW_SCALING_MODE_SCALE_CROP

If the buffer comes with NATIVE_WINDOW_TRANSFORM_ROT_90/270
transform set, we need to switch width/height when we scale and
crop it.

Bug: 28512795
Test: Olly's demo app from b/28512795/#34
Merged-In: 121f4210a004e8dbe12dad432f345d4143e0bd4b
Change-Id: I42270bd3f89dafc8c7d5d8aa080e300f4d75e011
(cherry picked from commit 121f4210a004e8dbe12dad432f345d4143e0bd4b)
diff --git a/services/surfaceflinger/BufferLayerConsumer.cpp b/services/surfaceflinger/BufferLayerConsumer.cpp
index e50a909..648d129 100644
--- a/services/surfaceflinger/BufferLayerConsumer.cpp
+++ b/services/surfaceflinger/BufferLayerConsumer.cpp
@@ -407,8 +407,17 @@
 }
 
 Rect BufferLayerConsumer::getCurrentCropLocked() const {
+    uint32_t width = mDefaultWidth;
+    uint32_t height = mDefaultHeight;
+    // If the buffer comes with a rotated bit for 90 (or 270) degrees, switch width/height in order
+    // to scale and crop correctly.
+    if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
+        width = mDefaultHeight;
+        height = mDefaultWidth;
+    }
+
     return (mCurrentScalingMode == NATIVE_WINDOW_SCALING_MODE_SCALE_CROP)
-            ? GLConsumer::scaleDownCrop(mCurrentCrop, mDefaultWidth, mDefaultHeight)
+            ? GLConsumer::scaleDownCrop(mCurrentCrop, width, height)
             : mCurrentCrop;
 }