From d3b90d223824dbfe1f827d6e089d96902af08f8f Mon Sep 17 00:00:00 2001 From: Valerie Hau Date: Wed, 6 Nov 2019 09:37:31 -0800 Subject: Adding triple buffering without wait Bug: 141939236 Test: build, boot, libgui_test Change-Id: Ibffe3f10f07493700c0ead97a96548bd13cae953 --- libs/gui/SurfaceComposerClient.cpp | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'libs/gui/SurfaceComposerClient.cpp') diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index a538e14dfc..2c8d4caae7 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -189,48 +189,49 @@ void TransactionCompletedListener::addSurfaceControlToCallbacks( } void TransactionCompletedListener::onTransactionCompleted(ListenerStats listenerStats) { - std::lock_guard lock(mMutex); + std::unordered_map callbacksMap; + { + std::lock_guard lock(mMutex); - /* This listener knows all the sp to sp for all its registered - * callbackIds, except for when Transactions are merged together. This probably cannot be - * solved before this point because the Transactions could be merged together and applied in a - * different process. - * - * Fortunately, we get all the callbacks for this listener for the same frame together at the - * same time. This means if any Transactions were merged together, we will get their callbacks - * at the same time. We can combine all the sp to sp maps for all the - * callbackIds to generate one super map that contains all the sp to sp - * that could possibly exist for the callbacks. - */ - std::unordered_map, sp, SurfaceComposerClient::IBinderHash> - surfaceControls; - for (const auto& transactionStats : listenerStats.transactionStats) { - for (auto callbackId : transactionStats.callbackIds) { - auto& [callbackFunction, callbackSurfaceControls] = mCallbacks[callbackId]; - surfaceControls.insert(callbackSurfaceControls.begin(), callbackSurfaceControls.end()); + /* This listener knows all the sp to sp for all its registered + * callbackIds, except for when Transactions are merged together. This probably cannot be + * solved before this point because the Transactions could be merged together and applied in + * a different process. + * + * Fortunately, we get all the callbacks for this listener for the same frame together at + * the same time. This means if any Transactions were merged together, we will get their + * callbacks at the same time. We can combine all the sp to sp maps + * for all the callbackIds to generate one super map that contains all the sp to + * sp that could possibly exist for the callbacks. + */ + callbacksMap = mCallbacks; + for (const auto& transactionStats : listenerStats.transactionStats) { + for (auto& callbackId : transactionStats.callbackIds) { + mCallbacks.erase(callbackId); + } } } - for (const auto& transactionStats : listenerStats.transactionStats) { for (auto callbackId : transactionStats.callbackIds) { - auto& [callbackFunction, callbackSurfaceControls] = mCallbacks[callbackId]; + auto& [callbackFunction, callbackSurfaceControls] = callbacksMap[callbackId]; if (!callbackFunction) { ALOGE("cannot call null callback function, skipping"); continue; } std::vector surfaceControlStats; for (const auto& surfaceStats : transactionStats.surfaceStats) { - surfaceControlStats.emplace_back(surfaceControls[surfaceStats.surfaceControl], - surfaceStats.acquireTime, - surfaceStats.previousReleaseFence, - surfaceStats.transformHint); - surfaceControls[surfaceStats.surfaceControl]->setTransformHint( - surfaceStats.transformHint); + surfaceControlStats + .emplace_back(callbacksMap[callbackId] + .surfaceControls[surfaceStats.surfaceControl], + surfaceStats.acquireTime, surfaceStats.previousReleaseFence, + surfaceStats.transformHint); + callbacksMap[callbackId] + .surfaceControls[surfaceStats.surfaceControl] + ->setTransformHint(surfaceStats.transformHint); } callbackFunction(transactionStats.latchTime, transactionStats.presentFence, surfaceControlStats); - mCallbacks.erase(callbackId); } } } -- cgit v1.2.3-59-g8ed1b