diff options
7 files changed, 27 insertions, 38 deletions
diff --git a/services/surfaceflinger/Scheduler/DispSyncSource.cpp b/services/surfaceflinger/Scheduler/DispSyncSource.cpp index 026b55707c..5faf46e31e 100644 --- a/services/surfaceflinger/Scheduler/DispSyncSource.cpp +++ b/services/surfaceflinger/Scheduler/DispSyncSource.cpp @@ -78,6 +78,10 @@ void DispSyncSource::setPhaseOffset(nsecs_t phaseOffset) { // Normalize phaseOffset to [-period, period) const int numPeriods = phaseOffset / period; phaseOffset -= numPeriods * period; + if (mPhaseOffset == phaseOffset) { + return; + } + mPhaseOffset = phaseOffset; tracePhaseOffset(); diff --git a/services/surfaceflinger/Scheduler/LayerInfo.cpp b/services/surfaceflinger/Scheduler/LayerInfo.cpp index beddb9be61..e782dd5361 100644 --- a/services/surfaceflinger/Scheduler/LayerInfo.cpp +++ b/services/surfaceflinger/Scheduler/LayerInfo.cpp @@ -50,7 +50,8 @@ void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime) { // Ignore time diff that are too high - those are stale values if (timeDiff > OBSOLETE_TIME_EPSILON_NS.count()) return; const nsecs_t refreshDuration = (timeDiff > 0) ? timeDiff : mMinRefreshDuration; - mRefreshRateHistory.insertRefreshRate(refreshDuration); + const int fps = 1e9f / refreshDuration; + mRefreshRateHistory.insertRefreshRate(fps); } } // namespace scheduler diff --git a/services/surfaceflinger/Scheduler/LayerInfo.h b/services/surfaceflinger/Scheduler/LayerInfo.h index 2c50053ebd..66df9dca20 100644 --- a/services/surfaceflinger/Scheduler/LayerInfo.h +++ b/services/surfaceflinger/Scheduler/LayerInfo.h @@ -46,7 +46,7 @@ class LayerInfo { public: explicit RefreshRateHistory(nsecs_t minRefreshDuration) : mMinRefreshDuration(minRefreshDuration) {} - void insertRefreshRate(nsecs_t refreshRate) { + void insertRefreshRate(int refreshRate) { mElements.push_back(refreshRate); if (mElements.size() > HISTORY_SIZE) { mElements.pop_front(); @@ -54,13 +54,13 @@ class LayerInfo { } float getRefreshRateAvg() const { - nsecs_t refreshDuration = mMinRefreshDuration; - if (mElements.size() > 0) { - refreshDuration = scheduler::calculate_mean(mElements); + if (mElements.empty()) { + return 1e9f / mMinRefreshDuration; } - return 1e9f / refreshDuration; + return scheduler::calculate_mean(mElements); } + void clearHistory() { mElements.clear(); } private: diff --git a/services/surfaceflinger/Scheduler/VSyncModulator.cpp b/services/surfaceflinger/Scheduler/VSyncModulator.cpp index d452c19b68..7a3bf8edaf 100644 --- a/services/surfaceflinger/Scheduler/VSyncModulator.cpp +++ b/services/surfaceflinger/Scheduler/VSyncModulator.cpp @@ -129,29 +129,16 @@ void VSyncModulator::updateOffsets() { void VSyncModulator::updateOffsetsLocked() { const Offsets desired = getNextOffsets(); - const Offsets current = mOffsets; - - bool changed = false; - if (desired.sf != current.sf) { - if (mSfConnectionHandle != nullptr) { - mScheduler->setPhaseOffset(mSfConnectionHandle, desired.sf); - } else if (mSfEventThread != nullptr) { - mSfEventThread->setPhaseOffset(desired.sf); - } - changed = true; - } - if (desired.app != current.app) { - if (mAppConnectionHandle != nullptr) { - mScheduler->setPhaseOffset(mAppConnectionHandle, desired.app); - } else if (mAppEventThread != nullptr) { - mAppEventThread->setPhaseOffset(desired.app); - } - changed = true; + + if (mSfConnectionHandle != nullptr) { + mScheduler->setPhaseOffset(mSfConnectionHandle, desired.sf); } - if (changed) { - flushOffsets(); + if (mAppConnectionHandle != nullptr) { + mScheduler->setPhaseOffset(mAppConnectionHandle, desired.app); } + + flushOffsets(); } void VSyncModulator::flushOffsets() { diff --git a/services/surfaceflinger/Scheduler/VSyncModulator.h b/services/surfaceflinger/Scheduler/VSyncModulator.h index 10cf8e6cc9..ddbd221ef1 100644 --- a/services/surfaceflinger/Scheduler/VSyncModulator.h +++ b/services/surfaceflinger/Scheduler/VSyncModulator.h @@ -68,12 +68,6 @@ public: void setPhaseOffsets(Offsets early, Offsets earlyGl, Offsets late, nsecs_t thresholdForNextVsync) EXCLUDES(mMutex); - // Sets handles to the SF and app event threads. - void setEventThreads(EventThread* sfEventThread, EventThread* appEventThread) { - mSfEventThread = sfEventThread; - mAppEventThread = appEventThread; - } - // Sets the scheduler and vsync connection handlers. void setSchedulerAndHandles(Scheduler* scheduler, Scheduler::ConnectionHandle* appConnectionHandle, @@ -121,9 +115,6 @@ private: std::unordered_map<OffsetType, Offsets> mOffsetMap GUARDED_BY(mMutex); nsecs_t mThresholdForNextVsync; - EventThread* mSfEventThread = nullptr; - EventThread* mAppEventThread = nullptr; - Scheduler* mScheduler = nullptr; Scheduler::ConnectionHandle* mAppConnectionHandle = nullptr; Scheduler::ConnectionHandle* mSfConnectionHandle = nullptr; diff --git a/services/surfaceflinger/TransactionCompletedThread.cpp b/services/surfaceflinger/TransactionCompletedThread.cpp index 5cf8eb1a1d..fd466dedff 100644 --- a/services/surfaceflinger/TransactionCompletedThread.cpp +++ b/services/surfaceflinger/TransactionCompletedThread.cpp @@ -197,8 +197,14 @@ status_t TransactionCompletedThread::addCallbackHandle(const sp<CallbackHandle>& } transactionStats->latchTime = handle->latchTime; - transactionStats->surfaceStats.emplace_back(handle->surfaceControl, handle->acquireTime, - handle->previousReleaseFence); + // If the layer has already been destroyed, don't add the SurfaceControl to the callback. + // The client side keeps a sp<> to the SurfaceControl so if the SurfaceControl has been + // destroyed the client side is dead and there won't be anyone to send the callback to. + sp<IBinder> surfaceControl = handle->surfaceControl.promote(); + if (surfaceControl) { + transactionStats->surfaceStats.emplace_back(surfaceControl, handle->acquireTime, + handle->previousReleaseFence); + } return NO_ERROR; } diff --git a/services/surfaceflinger/TransactionCompletedThread.h b/services/surfaceflinger/TransactionCompletedThread.h index 21e2678701..e849f714d0 100644 --- a/services/surfaceflinger/TransactionCompletedThread.h +++ b/services/surfaceflinger/TransactionCompletedThread.h @@ -49,7 +49,7 @@ public: sp<ITransactionCompletedListener> listener; std::vector<CallbackId> callbackIds; - sp<IBinder> surfaceControl; + wp<IBinder> surfaceControl; bool releasePreviousBuffer = false; sp<Fence> previousReleaseFence; |