Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29247e59 authored by Pascal Muetschard's avatar Pascal Muetschard Committed by Pascal Mütschard
Browse files

Ensure a callback is registered for all surfaces for jank data.

If there is a jank listener registered for a surface, the client will now ensure that a completion callback is added to the transaction for that surface with the jank data flag set.

Bug: 235178314
Bug: 221393601
Test: atest SurfaceFlinger_test
Change-Id: I77504c05d396fb9d9d91514d320ecd4e3dc7c4e2
parent 81cef293
Loading
Loading
Loading
Loading
+26 −7
Original line number Diff line number Diff line
@@ -82,6 +82,8 @@ std::atomic<uint32_t> idCounter = 0;
int64_t generateId() {
    return (((int64_t)getpid()) << 32) | ++idCounter;
}

void emptyCallback(nsecs_t, const sp<Fence>&, const std::vector<SurfaceControlStats>&) {}
} // namespace

ComposerService::ComposerService()
@@ -249,6 +251,14 @@ CallbackId TransactionCompletedListener::addCallbackFunction(
                surfaceControls,
        CallbackId::Type callbackType) {
    std::lock_guard<std::mutex> lock(mMutex);
    return addCallbackFunctionLocked(callbackFunction, surfaceControls, callbackType);
}

CallbackId TransactionCompletedListener::addCallbackFunctionLocked(
        const TransactionCompletedCallback& callbackFunction,
        const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
                surfaceControls,
        CallbackId::Type callbackType) {
    startListeningLocked();

    CallbackId callbackId(getNextIdLocked(), callbackType);
@@ -310,15 +320,26 @@ void TransactionCompletedListener::removeSurfaceStatsListener(void* context, voi
}

void TransactionCompletedListener::addSurfaceControlToCallbacks(
        const sp<SurfaceControl>& surfaceControl,
        const std::unordered_set<CallbackId, CallbackIdHash>& callbackIds) {
        SurfaceComposerClient::CallbackInfo& callbackInfo,
        const sp<SurfaceControl>& surfaceControl) {
    std::lock_guard<std::mutex> lock(mMutex);

    for (auto callbackId : callbackIds) {
    bool includingJankData = false;
    for (auto callbackId : callbackInfo.callbackIds) {
        mCallbacks[callbackId].surfaceControls.emplace(std::piecewise_construct,
                                                       std::forward_as_tuple(
                                                               surfaceControl->getHandle()),
                                                       std::forward_as_tuple(surfaceControl));
        includingJankData = includingJankData || callbackId.includeJankData;
    }

    // If no registered callback is requesting jank data, but there is a jank listener registered
    // on the new surface control, add a synthetic callback that requests the jank data.
    if (!includingJankData && mJankListeners.count(surfaceControl->getLayerId()) != 0) {
        CallbackId callbackId =
                addCallbackFunctionLocked(&emptyCallback, callbackInfo.surfaceControls,
                                          CallbackId::Type::ON_COMPLETE);
        callbackInfo.callbackIds.emplace(callbackId);
    }
}

@@ -935,8 +956,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr
        // register all surface controls for all callbackIds for this listener that is merging
        for (const auto& surfaceControl : currentProcessCallbackInfo.surfaceControls) {
            TransactionCompletedListener::getInstance()
                    ->addSurfaceControlToCallbacks(surfaceControl,
                                                   currentProcessCallbackInfo.callbackIds);
                    ->addSurfaceControlToCallbacks(currentProcessCallbackInfo, surfaceControl);
        }
    }

@@ -1272,8 +1292,7 @@ void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback(
    auto& callbackInfo = mListenerCallbacks[TransactionCompletedListener::getIInstance()];
    callbackInfo.surfaceControls.insert(sc);

    TransactionCompletedListener::getInstance()
            ->addSurfaceControlToCallbacks(sc, callbackInfo.callbackIds);
    TransactionCompletedListener::getInstance()->addSurfaceControlToCallbacks(callbackInfo, sc);
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPosition(
+7 −3
Original line number Diff line number Diff line
@@ -878,10 +878,14 @@ public:
            const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
                    surfaceControls,
            CallbackId::Type callbackType);
    CallbackId addCallbackFunctionLocked(
            const TransactionCompletedCallback& callbackFunction,
            const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
                    surfaceControls,
            CallbackId::Type callbackType) REQUIRES(mMutex);

    void addSurfaceControlToCallbacks(
            const sp<SurfaceControl>& surfaceControl,
            const std::unordered_set<CallbackId, CallbackIdHash>& callbackIds);
    void addSurfaceControlToCallbacks(SurfaceComposerClient::CallbackInfo& callbackInfo,
                                      const sp<SurfaceControl>& surfaceControl);

    void addQueueStallListener(std::function<void(const std::string&)> stallListener, void* id);
    void removeQueueStallListener(void *id);