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

Commit 9a803c3e authored by Robert Carr's avatar Robert Carr
Browse files

SurfaceFlinger: Emit TransactionCompleted callbacks directly.

Transaction complete callbacks (BLAST Buffer release callbacks), are
emitted from a TransactionCompletedThread. There's no clear reason
for this behavior, as the actual runtime is exceedingly minimal. This
opens us to scheduling delays when we call
TransactionCompletedThread.sendCallbacks. In this CL we both remove the
threaded nature of TransactionCompletedThread, and also take advantage
of it running on the main thread to reduce some unnecessary copying and
further reduce its runtime.

Bug: 176691195
Test: Existing tests pass
Change-Id: Ib1661df24c4a2ee39fc28c29a395158ce0ee7b7f
parent c5515fcc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ filegroup {
        "SurfaceFlingerDefaultFactory.cpp",
        "SurfaceInterceptor.cpp",
        "SurfaceTracing.cpp",
        "TransactionCompletedThread.cpp",
        "TransactionCallbackInvoker.cpp",
    ],
}

+3 −3
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ void BufferStateLayer::releasePendingBuffer(nsecs_t dequeueReadyTime) {
                JankData(surfaceFrame->getToken(), surfaceFrame->getJankType().value()));
    }

    mFlinger->getTransactionCompletedThread().finalizePendingCallbackHandles(
    mFlinger->getTransactionCallbackInvoker().finalizePendingCallbackHandles(
            mDrawingState.callbackHandles, jankData);

    mDrawingState.callbackHandles = {};
@@ -443,14 +443,14 @@ bool BufferStateLayer::setTransactionCompletedListeners(

            // Notify the transaction completed thread that there is a pending latched callback
            // handle
            mFlinger->getTransactionCompletedThread().registerPendingCallbackHandle(handle);
            mFlinger->getTransactionCallbackInvoker().registerPendingCallbackHandle(handle);

            // Store so latched time and release fence can be set
            mCurrentState.callbackHandles.push_back(handle);

        } else { // If this layer will NOT need to be relatched and presented this frame
            // Notify the transaction completed thread this handle is done
            mFlinger->getTransactionCompletedThread().registerUnpresentedCallbackHandle(handle);
            mFlinger->getTransactionCallbackInvoker().registerUnpresentedCallbackHandle(handle);
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@
#include "Scheduler/Seamlessness.h"
#include "SurfaceFlinger.h"
#include "SurfaceTracing.h"
#include "TransactionCompletedThread.h"
#include "TransactionCallbackInvoker.h"

using namespace android::surfaceflinger;

+8 −8
Original line number Diff line number Diff line
@@ -2195,8 +2195,8 @@ void SurfaceFlinger::postComposition() {
        }
    });

    mTransactionCompletedThread.addPresentFence(mPreviousPresentFences[0]);
    mTransactionCompletedThread.sendCallbacks();
    mTransactionCallbackInvoker.addPresentFence(mPreviousPresentFences[0]);
    mTransactionCallbackInvoker.sendCallbacks();

    if (display && display->isPrimary() && display->getPowerMode() == hal::PowerMode::ON &&
        presentFenceTime->isValid()) {
@@ -3547,8 +3547,8 @@ void SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelin
    // that listeners with SurfaceControls will start registration during setClientStateLocked
    // below.
    for (const auto& listener : listenerCallbacks) {
        mTransactionCompletedThread.startRegistration(listener);
        mTransactionCompletedThread.endRegistration(listener);
        mTransactionCallbackInvoker.startRegistration(listener);
        mTransactionCallbackInvoker.endRegistration(listener);
    }

    std::unordered_set<ListenerCallbacks, ListenerCallbacksHash> listenerCallbacksWithSurfaces;
@@ -3567,12 +3567,12 @@ void SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelin
    }

    for (const auto& listenerCallback : listenerCallbacksWithSurfaces) {
        mTransactionCompletedThread.endRegistration(listenerCallback);
        mTransactionCallbackInvoker.endRegistration(listenerCallback);
    }

    // If the state doesn't require a traversal and there are callbacks, send them now
    if (!(clientStateFlags & eTraversalNeeded) && hasListenerCallbacks) {
        mTransactionCompletedThread.sendCallbacks();
        mTransactionCallbackInvoker.sendCallbacks();
    }
    transactionFlags |= clientStateFlags;

@@ -3687,7 +3687,7 @@ uint32_t SurfaceFlinger::setClientStateLocked(
    for (auto& listener : s.listeners) {
        // note that startRegistration will not re-register if the listener has
        // already be registered for a prior surface control
        mTransactionCompletedThread.startRegistration(listener);
        mTransactionCallbackInvoker.startRegistration(listener);
        listenerCallbacks.insert(listener);
    }

@@ -3700,7 +3700,7 @@ uint32_t SurfaceFlinger::setClientStateLocked(
    }
    if (layer == nullptr) {
        for (auto& [listener, callbackIds] : s.listeners) {
            mTransactionCompletedThread.registerUnpresentedCallbackHandle(
            mTransactionCallbackInvoker.registerUnpresentedCallbackHandle(
                    new CallbackHandle(listener, callbackIds, s.surface));
        }
        return 0;
+4 −4
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@
#include "SurfaceFlingerFactory.h"
#include "SurfaceTracing.h"
#include "TracedOrdinal.h"
#include "TransactionCompletedThread.h"
#include "TransactionCallbackInvoker.h"

#include <atomic>
#include <cstdint>
@@ -319,8 +319,8 @@ public:

    void removeFromOffscreenLayers(Layer* layer);

    TransactionCompletedThread& getTransactionCompletedThread() {
        return mTransactionCompletedThread;
    TransactionCallbackInvoker& getTransactionCallbackInvoker() {
        return mTransactionCallbackInvoker;
    }

    // Converts from a binder handle to a Layer
@@ -1159,7 +1159,7 @@ private:
    std::atomic<uint32_t> mHwcFrameMissedCount = 0;
    std::atomic<uint32_t> mGpuFrameMissedCount = 0;

    TransactionCompletedThread mTransactionCompletedThread;
    TransactionCallbackInvoker mTransactionCallbackInvoker;

    // Restrict layers to use two buffers in their bufferqueues.
    bool mLayerTripleBufferingDisabled = false;
Loading