Fix VrFlinger handoff
In ag/3368932, hotplug processing was moved to main thread and deferred
the actual display devices creation to the next cycle of
SurfaceFlinger's main thread. This breaks UpdateVrFlinger logic, which
runs on the main thread and assumes all new display devices get created
synchronously during the handoff.
This CL fixes the issue by allowing synchronous calling
processDisplayHotplugEventsLocked() from onHotplugReceived() if and only
if the callback is called on main thread.
Bug: 72103899
Test: VrApp now renders fine
Change-Id: I2abd5d5861e0bb74419f12142f7f7c33190a022c
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 135bfbe..ea43c58 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1289,6 +1289,11 @@
mPendingHotplugEvents.emplace_back(HotplugEvent{display, connection});
+ if (std::this_thread::get_id() == mMainThreadId) {
+ // Process all pending hot plug events immediately if we are on the main thread.
+ processDisplayHotplugEventsLocked();
+ }
+
setTransactionFlags(eDisplayTransactionNeeded);
}