BlastBufferQueue: Keep transform hint in Surface consistent
We should only update the transform hint in Surface when
connecting to the queue or queuing a buffer. Otherwise,
the transform hint value used when dequeuing the buffer
will not align with the value queried from the Surface. This
inconsistency was causing BBQ to reject buffers and we
suspect this was causing an issue where BBQ will remain in
this inconsistent state rejecting all buffers until the app
changed orientation.
Test: rotate device, check for rejected buffers, run through scenario in bug
Bug: b/191841127
Change-Id: Id84a3a650ce68878e5638b942249c11558fd29eb
diff --git a/libs/gui/tests/BLASTBufferQueue_test.cpp b/libs/gui/tests/BLASTBufferQueue_test.cpp
index 6ff67aa..9082d27 100644
--- a/libs/gui/tests/BLASTBufferQueue_test.cpp
+++ b/libs/gui/tests/BLASTBufferQueue_test.cpp
@@ -71,6 +71,10 @@
return mBlastBufferQueueAdapter->mSurfaceControl;
}
+ sp<Surface> getSurface() {
+ return mBlastBufferQueueAdapter->getSurface(false /* includeSurfaceControlHandle */);
+ }
+
void waitForCallbacks() {
std::unique_lock lock{mBlastBufferQueueAdapter->mMutex};
// Wait until all but one of the submitted buffers have been released.
@@ -758,6 +762,48 @@
{0, 0, (int32_t)mDisplayWidth, (int32_t)mDisplayHeight / 2}));
}
+TEST_F(BLASTBufferQueueTest, TransformHint) {
+ // Transform hint is provided to BBQ via the surface control passed by WM
+ mSurfaceControl->setTransformHint(ui::Transform::ROT_90);
+
+ BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight);
+ sp<IGraphicBufferProducer> igbProducer = adapter.getIGraphicBufferProducer();
+ ASSERT_NE(nullptr, igbProducer.get());
+ ASSERT_EQ(NO_ERROR, igbProducer->setMaxDequeuedBufferCount(2));
+ sp<Surface> surface = adapter.getSurface();
+
+ // Before connecting to the surface, we do not get a valid transform hint
+ int transformHint;
+ surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint);
+ ASSERT_EQ(ui::Transform::ROT_0, transformHint);
+
+ ASSERT_EQ(NO_ERROR,
+ surface->connect(NATIVE_WINDOW_API_CPU, new TestProducerListener(igbProducer)));
+
+ // After connecting to the surface, we should get the correct hint.
+ surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint);
+ ASSERT_EQ(ui::Transform::ROT_90, transformHint);
+
+ ANativeWindow_Buffer buffer;
+ surface->lock(&buffer, nullptr /* inOutDirtyBounds */);
+
+ // Transform hint is updated via callbacks or surface control updates
+ mSurfaceControl->setTransformHint(ui::Transform::ROT_0);
+ adapter.update(mSurfaceControl, mDisplayWidth, mDisplayHeight);
+
+ // The hint does not change and matches the value used when dequeueing the buffer.
+ surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint);
+ ASSERT_EQ(ui::Transform::ROT_90, transformHint);
+
+ surface->unlockAndPost();
+
+ // After queuing the buffer, we get the updated transform hint
+ surface->query(NATIVE_WINDOW_TRANSFORM_HINT, &transformHint);
+ ASSERT_EQ(ui::Transform::ROT_0, transformHint);
+
+ adapter.waitForCallbacks();
+}
+
class BLASTBufferQueueTransformTest : public BLASTBufferQueueTest {
public:
void test(uint32_t tr) {