Use the height as width when there is a rotation needs to be applied for
the dst rect.

Removed if condition check for dstRect and srcRect.

The AOSP camera for a split second sends the actual dstRect while
switching camera and that when the image scales because I wasn't doing
the conversion of the rect from width to height.
This scaling basically gives the perception that switch is slow, while
last few frames are basically still frames aka last buffer queue.

BUG: 197262426
Test: Verified manually on AOSP that camera switch is smooth.
Change-Id: Ic4b0b2ff3be2056a0c90841ed880e49c34ea2781
diff --git a/libs/hwui/pipeline/skia/LayerDrawable.cpp b/libs/hwui/pipeline/skia/LayerDrawable.cpp
index 6db7170..1439656 100644
--- a/libs/hwui/pipeline/skia/LayerDrawable.cpp
+++ b/libs/hwui/pipeline/skia/LayerDrawable.cpp
@@ -101,59 +101,58 @@
         paint.setBlendMode(layer->getMode());
         paint.setColorFilter(layer->getColorFilter());
         const SkMatrix& totalMatrix = canvas->getTotalMatrix();
-        if (srcRect || dstRect) {
-            SkRect skiaSrcRect;
-            if (srcRect && !srcRect->isEmpty()) {
-                skiaSrcRect = *srcRect;
-            } else {
-                skiaSrcRect = SkRect::MakeIWH(imageWidth, imageHeight);
-            }
-            SkRect skiaDestRect;
-            if (dstRect && !dstRect->isEmpty()) {
-                skiaDestRect = *dstRect;
-            } else {
-                skiaDestRect = (windowTransform & NATIVE_WINDOW_TRANSFORM_ROT_90)
-                                       ? SkRect::MakeIWH(layerHeight, layerWidth)
-                                       : SkRect::MakeIWH(layerWidth, layerHeight);
-            }
-
-            const float px = skiaDestRect.centerX();
-            const float py = skiaDestRect.centerY();
-            SkMatrix m;
-            if (windowTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) {
-                m.postScale(-1.f, 1.f, px, py);
-            }
-            if (windowTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) {
-                m.postScale(1.f, -1.f, px, py);
-            }
-            if (windowTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
-                m.postRotate(90, 0, 0);
-                m.postTranslate(skiaDestRect.height(), 0);
-            }
-            auto constraint = SkCanvas::kFast_SrcRectConstraint;
-            if (srcRect && !srcRect->isEmpty()) {
-                constraint = SkCanvas::kStrict_SrcRectConstraint;
-            }
-
-            canvas->save();
-            canvas->concat(m);
-
-            // If (matrix is a rect-to-rect transform)
-            // and (src/dst buffers size match in screen coordinates)
-            // and (src/dst corners align fractionally),
-            // then use nearest neighbor, otherwise use bilerp sampling.
-            // Skia TextureOp has the above logic build-in, but not NonAAFillRectOp. TextureOp works
-            // only for SrcOver blending and without color filter (readback uses Src blending).
-            SkSamplingOptions sampling(SkFilterMode::kNearest);
-            if (layer->getForceFilter() ||
-                shouldFilterRect(totalMatrix, skiaSrcRect, skiaDestRect)) {
-                sampling = SkSamplingOptions(SkFilterMode::kLinear);
-            }
-
-            canvas->drawImageRect(layerImage.get(), skiaSrcRect, skiaDestRect, sampling, &paint,
-                                  constraint);
-            canvas->restore();
+        SkRect skiaSrcRect;
+        if (srcRect && !srcRect->isEmpty()) {
+            skiaSrcRect = *srcRect;
+        } else {
+            skiaSrcRect = SkRect::MakeIWH(imageWidth, imageHeight);
         }
+        SkRect skiaDestRect;
+        if (dstRect && !dstRect->isEmpty()) {
+            skiaDestRect = (windowTransform & NATIVE_WINDOW_TRANSFORM_ROT_90)
+                                   ? SkRect::MakeIWH(dstRect->height(), dstRect->width())
+                                   : SkRect::MakeIWH(dstRect->width(), dstRect->height());
+        } else {
+            skiaDestRect = (windowTransform & NATIVE_WINDOW_TRANSFORM_ROT_90)
+                                   ? SkRect::MakeIWH(layerHeight, layerWidth)
+                                   : SkRect::MakeIWH(layerWidth, layerHeight);
+        }
+
+        const float px = skiaDestRect.centerX();
+        const float py = skiaDestRect.centerY();
+        SkMatrix m;
+        if (windowTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) {
+            m.postScale(-1.f, 1.f, px, py);
+        }
+        if (windowTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) {
+            m.postScale(1.f, -1.f, px, py);
+        }
+        if (windowTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
+            m.postRotate(90, 0, 0);
+            m.postTranslate(skiaDestRect.height(), 0);
+        }
+        auto constraint = SkCanvas::kFast_SrcRectConstraint;
+        if (srcRect && !srcRect->isEmpty()) {
+            constraint = SkCanvas::kStrict_SrcRectConstraint;
+        }
+
+        canvas->save();
+        canvas->concat(m);
+
+        // If (matrix is a rect-to-rect transform)
+        // and (src/dst buffers size match in screen coordinates)
+        // and (src/dst corners align fractionally),
+        // then use nearest neighbor, otherwise use bilerp sampling.
+        // Skia TextureOp has the above logic build-in, but not NonAAFillRectOp. TextureOp works
+        // only for SrcOver blending and without color filter (readback uses Src blending).
+        SkSamplingOptions sampling(SkFilterMode::kNearest);
+        if (layer->getForceFilter() || shouldFilterRect(totalMatrix, skiaSrcRect, skiaDestRect)) {
+            sampling = SkSamplingOptions(SkFilterMode::kLinear);
+        }
+
+        canvas->drawImageRect(layerImage.get(), skiaSrcRect, skiaDestRect, sampling, &paint,
+                              constraint);
+        canvas->restore();
         // restore the original matrix
         if (useLayerTransform) {
             canvas->restore();