Skip to content

Commit 346b290

Browse files
Ben WidawskyAndroid (Google) Code Review
authored andcommitted
Merge "SF: Annotate more lock requirements" into main
2 parents 209b01b + 67346b9 commit 346b290

2 files changed

Lines changed: 32 additions & 25 deletions

File tree

services/surfaceflinger/Layer.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ aidl::android::hardware::graphics::composer3::Composition Layer::getCompositionT
362362
// transaction
363363
// ----------------------------------------------------------------------------
364364

365-
void Layer::commitTransaction() {
365+
void Layer::commitTransaction() REQUIRES(mFlinger->mStateLock) {
366366
// Set the present state for all bufferlessSurfaceFramesTX to Presented. The
367367
// bufferSurfaceFrameTX will be presented in latchBuffer.
368368
for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) {
@@ -394,7 +394,8 @@ bool Layer::isLayerFocusedBasedOnPriority(int32_t priority) {
394394
};
395395

396396
void Layer::setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info,
397-
nsecs_t postTime, gui::GameMode gameMode) {
397+
nsecs_t postTime, gui::GameMode gameMode)
398+
REQUIRES(mFlinger->mStateLock) {
398399
mDrawingState.postTime = postTime;
399400

400401
// Check if one of the bufferlessSurfaceFramesTX contains the same vsyncId. This can happen if
@@ -458,15 +459,16 @@ void Layer::addSurfaceFrameDroppedForBuffer(
458459

459460
void Layer::addSurfaceFramePresentedForBuffer(
460461
std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime,
461-
nsecs_t currentLatchTime) {
462+
nsecs_t currentLatchTime) REQUIRES(mFlinger->mStateLock) {
462463
surfaceFrame->setAcquireFenceTime(acquireFenceTime);
463464
surfaceFrame->setPresentState(PresentState::Presented, mLastLatchTime);
464465
mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame);
465466
updateLastLatchTime(currentLatchTime);
466467
}
467468

468469
std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForTransaction(
469-
const FrameTimelineInfo& info, nsecs_t postTime, gui::GameMode gameMode) {
470+
const FrameTimelineInfo& info, nsecs_t postTime, gui::GameMode gameMode)
471+
REQUIRES(mFlinger->mStateLock) {
470472
auto surfaceFrame =
471473
mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid,
472474
getSequence(), mName,
@@ -488,7 +490,7 @@ std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForTransac
488490

489491
std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForBuffer(
490492
const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName,
491-
gui::GameMode gameMode) {
493+
gui::GameMode gameMode) REQUIRES(mFlinger->mStateLock) {
492494
auto surfaceFrame =
493495
mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid,
494496
getSequence(), mName, debugName,
@@ -506,7 +508,8 @@ std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForBuffer(
506508
}
507509

508510
void Layer::setFrameTimelineVsyncForSkippedFrames(const FrameTimelineInfo& info, nsecs_t postTime,
509-
std::string debugName, gui::GameMode gameMode) {
511+
std::string debugName, gui::GameMode gameMode)
512+
REQUIRES(mFlinger->mStateLock) {
510513
if (info.skippedFrameVsyncId == FrameTimelineInfo::INVALID_VSYNC_ID) {
511514
return;
512515
}
@@ -842,7 +845,7 @@ bool Layer::setTransformToDisplayInverse(bool transformToDisplayInverse) {
842845
return true;
843846
}
844847

845-
void Layer::releasePreviousBuffer() {
848+
void Layer::releasePreviousBuffer() REQUIRES(mFlinger->mStateLock) {
846849
mReleasePreviousBuffer = true;
847850
if (!mBufferInfo.mBuffer ||
848851
(!mDrawingState.buffer->hasSameBuffer(*mBufferInfo.mBuffer) ||
@@ -884,7 +887,8 @@ void Layer::resetDrawingStateBufferInfo() {
884887

885888
bool Layer::setBuffer(std::shared_ptr<renderengine::ExternalTexture>& buffer,
886889
const BufferData& bufferData, nsecs_t postTime, nsecs_t desiredPresentTime,
887-
bool isAutoTimestamp, const FrameTimelineInfo& info, gui::GameMode gameMode) {
890+
bool isAutoTimestamp, const FrameTimelineInfo& info, gui::GameMode gameMode)
891+
REQUIRES(mFlinger->mStateLock) {
888892
SFTRACE_FORMAT("setBuffer %s - hasBuffer=%s", getDebugName(), (buffer ? "true" : "false"));
889893

890894
const bool frameNumberChanged =
@@ -1074,7 +1078,8 @@ bool Layer::setDesiredHdrHeadroom(float desiredRatio) {
10741078
}
10751079

10761080
bool Layer::setSidebandStream(const sp<NativeHandle>& sidebandStream, const FrameTimelineInfo& info,
1077-
nsecs_t postTime, gui::GameMode gameMode) {
1081+
nsecs_t postTime, gui::GameMode gameMode)
1082+
REQUIRES(mFlinger->mStateLock) {
10781083
if (mDrawingState.sidebandStream == sidebandStream) return false;
10791084

10801085
if (mDrawingState.sidebandStream != nullptr && sidebandStream == nullptr) {
@@ -1207,7 +1212,7 @@ bool Layer::latchSidebandStream(bool& recomputeVisibleRegions) {
12071212
return false;
12081213
}
12091214

1210-
void Layer::updateTexImage(nsecs_t latchTime, bool bgColorOnly) {
1215+
void Layer::updateTexImage(nsecs_t latchTime, bool bgColorOnly) REQUIRES(mFlinger->mStateLock) {
12111216
const State& s(getDrawingState());
12121217

12131218
if (!s.buffer) {
@@ -1457,7 +1462,8 @@ void Layer::onCompositionPresented(const DisplayDevice* display,
14571462
mBufferInfo.mFrameLatencyNeeded = false;
14581463
}
14591464

1460-
bool Layer::latchBufferImpl(bool& recomputeVisibleRegions, nsecs_t latchTime, bool bgColorOnly) {
1465+
bool Layer::latchBufferImpl(bool& recomputeVisibleRegions, nsecs_t latchTime, bool bgColorOnly)
1466+
REQUIRES(mFlinger->mStateLock) {
14611467
SFTRACE_FORMAT_INSTANT("latchBuffer %s - %" PRIu64, getDebugName(),
14621468
getDrawingState().frameNumber);
14631469

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,7 +2483,8 @@ void SurfaceFlinger::updateLayerHistory(nsecs_t now) {
24832483
}
24842484

24852485
bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs,
2486-
bool flushTransactions, bool& outTransactionsAreEmpty) {
2486+
bool flushTransactions, bool& outTransactionsAreEmpty)
2487+
EXCLUDES(mStateLock) {
24872488
using Changes = frontend::RequestedLayerState::Changes;
24882489
SFTRACE_CALL();
24892490
SFTRACE_NAME_FOR_TRACK(WorkloadTracer::TRACK_NAME, "Transaction Handling");
@@ -2680,7 +2681,7 @@ bool SurfaceFlinger::updateLayerSnapshots(VsyncId vsyncId, nsecs_t frameTimeNs,
26802681
}
26812682

26822683
bool SurfaceFlinger::commit(PhysicalDisplayId pacesetterId,
2683-
const scheduler::FrameTargets& frameTargets) {
2684+
const scheduler::FrameTargets& frameTargets) EXCLUDES(mStateLock) {
26842685
const scheduler::FrameTarget& pacesetterFrameTarget = *frameTargets.get(pacesetterId)->get();
26852686

26862687
const VsyncId vsyncId = pacesetterFrameTarget.vsyncId();
@@ -4893,12 +4894,14 @@ bool SurfaceFlinger::flushTransactionQueues() {
48934894
return applyTransactions(transactions);
48944895
}
48954896

4896-
bool SurfaceFlinger::applyTransactions(std::vector<QueuedTransactionState>& transactions) {
4897+
bool SurfaceFlinger::applyTransactions(std::vector<QueuedTransactionState>& transactions)
4898+
EXCLUDES(mStateLock) {
48974899
Mutex::Autolock lock(mStateLock);
48984900
return applyTransactionsLocked(transactions);
48994901
}
49004902

4901-
bool SurfaceFlinger::applyTransactionsLocked(std::vector<QueuedTransactionState>& transactions) {
4903+
bool SurfaceFlinger::applyTransactionsLocked(std::vector<QueuedTransactionState>& transactions)
4904+
REQUIRES(mStateLock) {
49024905
bool needsTraversal = false;
49034906
// Now apply all transactions.
49044907
for (auto& transaction : transactions) {
@@ -5115,15 +5118,13 @@ status_t SurfaceFlinger::setTransactionState(
51155118
return NO_ERROR;
51165119
}
51175120

5118-
bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelineInfo,
5119-
std::vector<ResolvedComposerState>& states,
5120-
Vector<DisplayState>& displays, uint32_t flags,
5121-
const InputWindowCommands& inputWindowCommands,
5122-
const int64_t desiredPresentTime, bool isAutoTimestamp,
5123-
const std::vector<uint64_t>& uncacheBufferIds,
5124-
const int64_t postTime, bool hasListenerCallbacks,
5125-
const std::vector<ListenerCallbacks>& listenerCallbacks,
5126-
int originPid, int originUid, uint64_t transactionId) {
5121+
bool SurfaceFlinger::applyTransactionState(
5122+
const FrameTimelineInfo& frameTimelineInfo, std::vector<ResolvedComposerState>& states,
5123+
Vector<DisplayState>& displays, uint32_t flags,
5124+
const InputWindowCommands& inputWindowCommands, const int64_t desiredPresentTime,
5125+
bool isAutoTimestamp, const std::vector<uint64_t>& uncacheBufferIds, const int64_t postTime,
5126+
bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks,
5127+
int originPid, int originUid, uint64_t transactionId) REQUIRES(mStateLock) {
51275128
uint32_t transactionFlags = 0;
51285129

51295130
// start and end registration for listeners w/ no surface so they can get their callback. Note
@@ -5275,7 +5276,7 @@ uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& f
52755276
ResolvedComposerState& composerState,
52765277
int64_t desiredPresentTime,
52775278
bool isAutoTimestamp, int64_t postTime,
5278-
uint64_t transactionId) {
5279+
uint64_t transactionId) REQUIRES(mStateLock) {
52795280
layer_state_t& s = composerState.state;
52805281

52815282
std::vector<ListenerCallbacks> filteredListeners;

0 commit comments

Comments
 (0)