Make NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY transforms sticky
When a client sets the NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY flag, the buffer producer may
override the flag if it sets a buffer transform. The second issue is that SurfaceFlinger may
apply a transform hint based on display orientation which may be applied by the buffer
producer.
The flag NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY indicates the client wants to submit buffers
in the same orientation regardless of display orientation. So if the flag is set, make it
sticky until the surface is disconnected. Secondly, ignore the transform hint if the flag is
set.
Test: Launch test app and test seamless rotation in portrait mode and landscape mode
Test: go/wm-smoke
Test: atest libsurfaceflinger_unittest libgui_test SurfaceFlinger_test
Bug: 127953232
Change-Id: Ic153faae0f3cdc9d385cdfe8162d3caabac60901
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 93b4191..e6eb327 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -829,8 +829,9 @@
mDefaultHeight = output.height;
mNextFrameNumber = output.nextFrameNumber;
- // Disable transform hint if sticky transform is set.
- if (mStickyTransform == 0) {
+ // Ignore transform hint if sticky transform is set or transform to display inverse flag is
+ // set.
+ if (mStickyTransform == 0 && !transformToDisplayInverse()) {
mTransformHint = output.transformHint;
}
@@ -1271,6 +1272,11 @@
return getConsumerUsage(usage);
}
+bool Surface::transformToDisplayInverse() {
+ return (mTransform & NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY) ==
+ NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
+}
+
int Surface::connect(int api) {
static sp<IProducerListener> listener = new DummyProducerListener();
return connect(api, listener);
@@ -1293,8 +1299,10 @@
mDefaultHeight = output.height;
mNextFrameNumber = output.nextFrameNumber;
- // Disable transform hint if sticky transform is set.
- if (mStickyTransform == 0) {
+ // Ignore transform hint if sticky transform is set or transform to display inverse flag is
+ // set. Transform hint should be ignored if the client is expected to always submit buffers
+ // in the same orientation.
+ if (mStickyTransform == 0 && !transformToDisplayInverse()) {
mTransformHint = output.transformHint;
}
@@ -1591,6 +1599,13 @@
ATRACE_CALL();
ALOGV("Surface::setBuffersTransform");
Mutex::Autolock lock(mMutex);
+ // Ensure NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY is sticky. If the client sets the flag, do not
+ // override it until the surface is disconnected. This is a temporary workaround for camera
+ // until they switch to using Buffer State Layers. Currently if client sets the buffer transform
+ // it may be overriden by the buffer producer when the producer sets the buffer transform.
+ if (transformToDisplayInverse()) {
+ transform |= NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
+ }
mTransform = transform;
return NO_ERROR;
}