SF: Enforce thread safety of active mode access
Provide two RefreshRateConfigs APIs for retrieving the active mode:
getActiveMode for access from the main thread (which does not need
to lock nor copy), and getActiveModePtr for other threads.
Bug: 241285191
Test: Build (-Wthread-safety)
Change-Id: If156d85861ec2d82a394ba181314a6ba3048974f
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 2af17e7..f7684a0 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -648,22 +648,20 @@
// Show spinner with refresh rate overlay
bool mRefreshRateOverlaySpinner = false;
- // Called on the main thread in response to initializeDisplays()
- void onInitializeDisplays() REQUIRES(mStateLock);
// Sets the desired active mode bit. It obtains the lock, and sets mDesiredActiveMode.
void setDesiredActiveMode(const ActiveModeInfo& info) REQUIRES(mStateLock);
status_t setActiveModeFromBackdoor(const sp<display::DisplayToken>&, DisplayModeId);
// Sets the active mode and a new refresh rate in SF.
- void updateInternalStateWithChangedMode() REQUIRES(mStateLock);
+ void updateInternalStateWithChangedMode() REQUIRES(mStateLock, kMainThreadContext);
// Calls to setActiveMode on the main thread if there is a pending mode change
// that needs to be applied.
- void setActiveModeInHwcIfNeeded() REQUIRES(mStateLock);
+ void setActiveModeInHwcIfNeeded() REQUIRES(mStateLock, kMainThreadContext);
void clearDesiredActiveModeState(const sp<DisplayDevice>&) REQUIRES(mStateLock);
// Called when active mode is no longer is progress
void desiredActiveModeChangeDone(const sp<DisplayDevice>&) REQUIRES(mStateLock);
// Called on the main thread in response to setPowerMode()
void setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode)
- REQUIRES(mStateLock);
+ REQUIRES(mStateLock, kMainThreadContext);
// Returns true if the display has a visible HDR layer in its layer stack.
bool hasVisibleHdrLayer(const sp<DisplayDevice>& display) REQUIRES(mStateLock);
@@ -680,8 +678,9 @@
const std::optional<scheduler::RefreshRateConfigs::Policy>& policy, bool overridePolicy)
EXCLUDES(mStateLock);
- void commitTransactions() EXCLUDES(mStateLock);
- void commitTransactionsLocked(uint32_t transactionFlags) REQUIRES(mStateLock);
+ void commitTransactions() EXCLUDES(mStateLock) REQUIRES(kMainThreadContext);
+ void commitTransactionsLocked(uint32_t transactionFlags)
+ REQUIRES(mStateLock, kMainThreadContext);
void doCommitTransactions() REQUIRES(mStateLock);
// Returns whether a new buffer has been latched.
@@ -824,8 +823,10 @@
/*
* Display and layer stack management
*/
- // called when starting, or restarting after system_server death
+
+ // Called during boot, and restart after system_server death.
void initializeDisplays();
+ void onInitializeDisplays() REQUIRES(mStateLock, kMainThreadContext);
bool isDisplayActiveLocked(const sp<const DisplayDevice>& display) const REQUIRES(mStateLock) {
return display->getDisplayToken() == mActiveDisplayToken;
@@ -957,11 +958,12 @@
const DisplayDeviceState& state,
const sp<compositionengine::DisplaySurface>& displaySurface,
const sp<IGraphicBufferProducer>& producer) REQUIRES(mStateLock);
- void processDisplayChangesLocked() REQUIRES(mStateLock);
+ void processDisplayChangesLocked() REQUIRES(mStateLock, kMainThreadContext);
void processDisplayRemoved(const wp<IBinder>& displayToken) REQUIRES(mStateLock);
void processDisplayChanged(const wp<IBinder>& displayToken,
const DisplayDeviceState& currentState,
- const DisplayDeviceState& drawingState) REQUIRES(mStateLock);
+ const DisplayDeviceState& drawingState)
+ REQUIRES(mStateLock, kMainThreadContext);
void dispatchDisplayHotplugEvent(PhysicalDisplayId displayId, bool connected);
@@ -1022,7 +1024,8 @@
VirtualDisplayId acquireVirtualDisplay(ui::Size, ui::PixelFormat) REQUIRES(mStateLock);
void releaseVirtualDisplay(VirtualDisplayId);
- void onActiveDisplayChangedLocked(const sp<DisplayDevice>& activeDisplay) REQUIRES(mStateLock);
+ void onActiveDisplayChangedLocked(const sp<DisplayDevice>& activeDisplay)
+ REQUIRES(mStateLock, kMainThreadContext);
void onActiveDisplaySizeChanged(const sp<DisplayDevice>& activeDisplay);
@@ -1096,7 +1099,7 @@
int getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const;
void updateInternalDisplayVsyncLocked(const sp<DisplayDevice>& activeDisplay)
- REQUIRES(mStateLock);
+ REQUIRES(mStateLock, kMainThreadContext);
bool isHdrLayer(Layer* layer) const;