Fix the source crop for screenshots for notch hide
* Orientation transform needs to be applied after the device transform
* Source crop needs to have a transform applied to it so that the
clipping window is in the right spot.
Bug: 129362302
Test: screenshots
Change-Id: I675be4d1fb2386f24ead69a77b08bec65d2f5d47
diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h
index c80925e..0067b50 100644
--- a/services/surfaceflinger/DisplayDevice.h
+++ b/services/surfaceflinger/DisplayDevice.h
@@ -288,16 +288,21 @@
}
Rect getSourceCrop() const override {
- // use the (projected) logical display viewport by default
+ // use the projected display viewport by default.
if (mSourceCrop.isEmpty()) {
return mDevice->getScissor();
}
- const int orientation = mDevice->getInstallOrientation();
- if (orientation == DisplayState::eOrientationDefault) {
- return mSourceCrop;
- }
+ // Recompute the device transformation for the source crop.
+ ui::Transform rotation;
+ ui::Transform translatePhysical;
+ ui::Transform translateLogical;
+ ui::Transform scale;
+ const Rect& viewport = mDevice->getViewport();
+ const Rect& scissor = mDevice->getScissor();
+ const Rect& frame = mDevice->getFrame();
+ const int orientation = mDevice->getInstallOrientation();
// Install orientation is transparent to the callers. Apply it now.
uint32_t flags = 0x00;
switch (orientation) {
@@ -310,10 +315,17 @@
case DisplayState::eOrientation270:
flags = ui::Transform::ROT_270;
break;
+ default:
+ break;
}
- ui::Transform tr;
- tr.set(flags, getWidth(), getHeight());
- return tr.transform(mSourceCrop);
+ rotation.set(flags, getWidth(), getHeight());
+ translateLogical.set(-viewport.left, -viewport.top);
+ translatePhysical.set(scissor.left, scissor.top);
+ scale.set(frame.getWidth() / float(viewport.getWidth()), 0, 0,
+ frame.getHeight() / float(viewport.getHeight()));
+ const ui::Transform finalTransform =
+ rotation * translatePhysical * scale * translateLogical;
+ return finalTransform.transform(mSourceCrop);
}
private: