SurfaceFlinger: Inherit non-transform Scaling from parent.

When a Layer is fixed-size, we may apply additional scaling
to the buffer not accounted for in the transform. This means
that if the WindowManager calls setSize we will scale the parent
surface but not the child surfaces, breaking the contract that
the WM can treat the child surfaces as pixels in the parent.

Test: Included test in Transaction_test.
Bug: 36820947
Bug: 37344435
Change-Id: I5478bad176388fe8e5407379bc36cdfd6600ab97
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 5e5efb7..d044f37 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -2617,6 +2617,21 @@
     const auto& p = getParent();
     if (p != nullptr) {
         t = p->getTransform();
+
+        // If the parent is not using NATIVE_WINDOW_SCALING_MODE_FREEZE (e.g.
+        // it isFixedSize) then there may be additional scaling not accounted
+        // for in the transform. We need to mirror this scaling in child surfaces
+        // or we will break the contract where WM can treat child surfaces as
+        // pixels in the parent surface.
+        if (p->isFixedSize()) {
+            float sx = p->getDrawingState().active.w /
+                    static_cast<float>(p->mActiveBuffer->getWidth());
+            float sy = p->getDrawingState().active.h /
+                    static_cast<float>(p->mActiveBuffer->getHeight());
+            Transform extraParentScaling;
+            extraParentScaling.set(sx, 0, 0, sy);
+            t = t * extraParentScaling;
+        }
     }
     return t * getDrawingState().active.transform;
 }