diff options
author | 2025-02-11 08:44:31 -0800 | |
---|---|---|
committer | 2025-02-18 10:12:52 -0800 | |
commit | 67346b911d868f9518d94b027136378afef736fb (patch) | |
tree | 761bf0732d60ef1ccc5d535d0facb8e89fb19e5a | |
parent | adcbb982c1d4bba8dca2e8613dd1461404ab993c (diff) |
SF: Annotate more lock requirements
Upcoming reworks will require more use of mStateLock and having these in
place helps avoid footguns.
Test: builds
Flag: EXEMPT refactor
Change-Id: I37439673e1cdb67df5ca3dd524c9a72d34abc497
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 28 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 29 |
2 files changed, 32 insertions, 25 deletions
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index e1bba44be9..95a7170fbb 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -362,7 +362,7 @@ aidl::android::hardware::graphics::composer3::Composition Layer::getCompositionT // transaction // ---------------------------------------------------------------------------- -void Layer::commitTransaction() { +void Layer::commitTransaction() REQUIRES(mFlinger->mStateLock) { // Set the present state for all bufferlessSurfaceFramesTX to Presented. The // bufferSurfaceFrameTX will be presented in latchBuffer. for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) { @@ -394,7 +394,8 @@ bool Layer::isLayerFocusedBasedOnPriority(int32_t priority) { }; void Layer::setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, - nsecs_t postTime, gui::GameMode gameMode) { + nsecs_t postTime, gui::GameMode gameMode) + REQUIRES(mFlinger->mStateLock) { mDrawingState.postTime = postTime; // Check if one of the bufferlessSurfaceFramesTX contains the same vsyncId. This can happen if @@ -458,7 +459,7 @@ void Layer::addSurfaceFrameDroppedForBuffer( void Layer::addSurfaceFramePresentedForBuffer( std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime, - nsecs_t currentLatchTime) { + nsecs_t currentLatchTime) REQUIRES(mFlinger->mStateLock) { surfaceFrame->setAcquireFenceTime(acquireFenceTime); surfaceFrame->setPresentState(PresentState::Presented, mLastLatchTime); mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); @@ -466,7 +467,8 @@ void Layer::addSurfaceFramePresentedForBuffer( } std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForTransaction( - const FrameTimelineInfo& info, nsecs_t postTime, gui::GameMode gameMode) { + const FrameTimelineInfo& info, nsecs_t postTime, gui::GameMode gameMode) + REQUIRES(mFlinger->mStateLock) { auto surfaceFrame = mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, getSequence(), mName, @@ -488,7 +490,7 @@ std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForTransac std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForBuffer( const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName, - gui::GameMode gameMode) { + gui::GameMode gameMode) REQUIRES(mFlinger->mStateLock) { auto surfaceFrame = mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, getSequence(), mName, debugName, @@ -506,7 +508,8 @@ std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForBuffer( } void Layer::setFrameTimelineVsyncForSkippedFrames(const FrameTimelineInfo& info, nsecs_t postTime, - std::string debugName, gui::GameMode gameMode) { + std::string debugName, gui::GameMode gameMode) + REQUIRES(mFlinger->mStateLock) { if (info.skippedFrameVsyncId == FrameTimelineInfo::INVALID_VSYNC_ID) { return; } @@ -842,7 +845,7 @@ bool Layer::setTransformToDisplayInverse(bool transformToDisplayInverse) { return true; } -void Layer::releasePreviousBuffer() { +void Layer::releasePreviousBuffer() REQUIRES(mFlinger->mStateLock) { mReleasePreviousBuffer = true; if (!mBufferInfo.mBuffer || (!mDrawingState.buffer->hasSameBuffer(*mBufferInfo.mBuffer) || @@ -884,7 +887,8 @@ void Layer::resetDrawingStateBufferInfo() { bool Layer::setBuffer(std::shared_ptr<renderengine::ExternalTexture>& buffer, const BufferData& bufferData, nsecs_t postTime, nsecs_t desiredPresentTime, - bool isAutoTimestamp, const FrameTimelineInfo& info, gui::GameMode gameMode) { + bool isAutoTimestamp, const FrameTimelineInfo& info, gui::GameMode gameMode) + REQUIRES(mFlinger->mStateLock) { SFTRACE_FORMAT("setBuffer %s - hasBuffer=%s", getDebugName(), (buffer ? "true" : "false")); const bool frameNumberChanged = @@ -1074,7 +1078,8 @@ bool Layer::setDesiredHdrHeadroom(float desiredRatio) { } bool Layer::setSidebandStream(const sp<NativeHandle>& sidebandStream, const FrameTimelineInfo& info, - nsecs_t postTime, gui::GameMode gameMode) { + nsecs_t postTime, gui::GameMode gameMode) + REQUIRES(mFlinger->mStateLock) { if (mDrawingState.sidebandStream == sidebandStream) return false; if (mDrawingState.sidebandStream != nullptr && sidebandStream == nullptr) { @@ -1207,7 +1212,7 @@ bool Layer::latchSidebandStream(bool& recomputeVisibleRegions) { return false; } -void Layer::updateTexImage(nsecs_t latchTime, bool bgColorOnly) { +void Layer::updateTexImage(nsecs_t latchTime, bool bgColorOnly) REQUIRES(mFlinger->mStateLock) { const State& s(getDrawingState()); if (!s.buffer) { @@ -1457,7 +1462,8 @@ void Layer::onCompositionPresented(const DisplayDevice* display, mBufferInfo.mFrameLatencyNeeded = false; } -bool Layer::latchBufferImpl(bool& recomputeVisibleRegions, nsecs_t latchTime, bool bgColorOnly) { +bool Layer::latchBufferImpl(bool& recomputeVisibleRegions, nsecs_t latchTime, bool bgColorOnly) + REQUIRES(mFlinger->mStateLock) { SFTRACE_FORMAT_INSTANT("latchBuffer %s - %" PRIu64, getDebugName(), getDrawingState().frameNumber); diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 574d39a1f9..de579ca4f8 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2456,7 +2456,8 @@ void SurfaceFlinger::updateLayerHistory(nsecs_t now) { } bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, - bool flushTransactions, bool& outTransactionsAreEmpty) { + bool flushTransactions, bool& outTransactionsAreEmpty) + EXCLUDES(mStateLock) { using Changes = frontend::RequestedLayerState::Changes; SFTRACE_CALL(); SFTRACE_NAME_FOR_TRACK(WorkloadTracer::TRACK_NAME, "Transaction Handling"); @@ -2653,7 +2654,7 @@ bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs, } bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId, - const scheduler::FrameTargets& frameTargets) { + const scheduler::FrameTargets& frameTargets) EXCLUDES(mStateLock) { const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get(); const VsyncId vsyncId = pacesetterFrameTarget.vsyncId(); @@ -4847,12 +4848,14 @@ bool SurfaceFlinger::flushTransactionQueues() { return applyTransactions(transactions); } -bool SurfaceFlinger::applyTransactions(std::vector<QueuedTransactionState>& transactions) { +bool SurfaceFlinger::applyTransactions(std::vector<QueuedTransactionState>& transactions) + EXCLUDES(mStateLock) { Mutex::Autolock lock(mStateLock); return applyTransactionsLocked(transactions); } -bool SurfaceFlinger::applyTransactionsLocked(std::vector<QueuedTransactionState>& transactions) { +bool SurfaceFlinger::applyTransactionsLocked(std::vector<QueuedTransactionState>& transactions) + REQUIRES(mStateLock) { bool needsTraversal = false; // Now apply all transactions. for (auto& transaction : transactions) { @@ -5069,15 +5072,13 @@ status_t SurfaceFlinger::setTransactionState( return NO_ERROR; } -bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo, - std::vector<ResolvedComposerState>& states, - Vector<DisplayState>& displays, uint32_t flags, - const InputWindowCommands& inputWindowCommands, - const int64_t desiredPresentTime, bool isAutoTimestamp, - const std::vector<uint64_t>& uncacheBufferIds, - const int64_t postTime, bool hasListenerCallbacks, - const std::vector<ListenerCallbacks>& listenerCallbacks, - int originPid, int originUid, uint64_t transactionId) { +bool SurfaceFlinger::applyTransactionState( + const FrameTimelineInfo& frameTimelineInfo, std::vector<ResolvedComposerState>& states, + Vector<DisplayState>& displays, uint32_t flags, + const InputWindowCommands& inputWindowCommands, const int64_t desiredPresentTime, + bool isAutoTimestamp, const std::vector<uint64_t>& uncacheBufferIds, const int64_t postTime, + bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks, + int originPid, int originUid, uint64_t transactionId) REQUIRES(mStateLock) { uint32_t transactionFlags = 0; // start and end registration for listeners w/ no surface so they can get their callback. Note @@ -5229,7 +5230,7 @@ uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& f ResolvedComposerState& composerState, int64_t desiredPresentTime, bool isAutoTimestamp, int64_t postTime, - uint64_t transactionId) { + uint64_t transactionId) REQUIRES(mStateLock) { layer_state_t& s = composerState.state; std::vector<ListenerCallbacks> filteredListeners; |