Merge "SurfaceFlinger: Inherit non-transform Scaling from parent." into oc-dev am: 08260b881a
am: 6bbe40abf9
Change-Id: Ifb0f16bf0484e0f7cfa58a93f1e94dab4f123f04
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index ef4c7b1..15accc8 100755
--- 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;
}
diff --git a/services/surfaceflinger/tests/Transaction_test.cpp b/services/surfaceflinger/tests/Transaction_test.cpp
index 441fc7e..7a8b4ab 100644
--- a/services/surfaceflinger/tests/Transaction_test.cpp
+++ b/services/surfaceflinger/tests/Transaction_test.cpp
@@ -909,4 +909,36 @@
}
}
+TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) {
+ SurfaceComposerClient::openGlobalTransaction();
+ mChild->show();
+ mChild->setPosition(0, 0);
+ mFGSurfaceControl->setPosition(0, 0);
+ SurfaceComposerClient::closeGlobalTransaction(true);
+
+ {
+ ScreenCapture::captureScreen(&mCapture);
+ // We've positioned the child in the top left.
+ mCapture->expectChildColor(0, 0);
+ // But it's only 10x10.
+ mCapture->expectFGColor(10, 10);
+ }
+
+ SurfaceComposerClient::openGlobalTransaction();
+ mFGSurfaceControl->setOverrideScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
+ // We cause scaling by 2.
+ mFGSurfaceControl->setSize(128, 128);
+ SurfaceComposerClient::closeGlobalTransaction();
+
+ {
+ ScreenCapture::captureScreen(&mCapture);
+ // We've positioned the child in the top left.
+ mCapture->expectChildColor(0, 0);
+ mCapture->expectChildColor(10, 10);
+ mCapture->expectChildColor(19, 19);
+ // And now it should be scaled all the way to 20x20
+ mCapture->expectFGColor(20, 20);
+ }
+}
+
}