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

Commit 23780be1 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Track transaction merges through transaction trace

Bug: 233371599
Bug: 278663063
Test: dump a transaction trace and ensure transactions have the list of merged transaction ids in the proto
Change-Id: I3edf8f1443a2573ef2086f221ceeef57172ecdbe
parent 50fe0d96
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -59,15 +59,13 @@ public:

    virtual ~BpSurfaceComposer();

    status_t setTransactionState(const FrameTimelineInfo& frameTimelineInfo,
                                 Vector<ComposerState>& state, const Vector<DisplayState>& displays,
                                 uint32_t flags, const sp<IBinder>& applyToken,
                                 InputWindowCommands commands, int64_t desiredPresentTime,
                                 bool isAutoTimestamp,
                                 const std::vector<client_cache_t>& uncacheBuffers,
                                 bool hasListenerCallbacks,
                                 const std::vector<ListenerCallbacks>& listenerCallbacks,
                                 uint64_t transactionId) override {
    status_t setTransactionState(
            const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state,
            const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken,
            InputWindowCommands commands, int64_t desiredPresentTime, bool isAutoTimestamp,
            const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks,
            const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId,
            const std::vector<uint64_t>& mergedTransactionIds) override {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());

@@ -103,6 +101,11 @@ public:

        SAFE_PARCEL(data.writeUint64, transactionId);

        SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(mergedTransactionIds.size()));
        for (auto mergedTransactionId : mergedTransactionIds) {
            SAFE_PARCEL(data.writeUint64, mergedTransactionId);
        }

        if (flags & ISurfaceComposer::eOneWay) {
            return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
                    data, &reply, IBinder::FLAG_ONEWAY);
@@ -187,10 +190,16 @@ status_t BnSurfaceComposer::onTransact(
            uint64_t transactionId = -1;
            SAFE_PARCEL(data.readUint64, &transactionId);

            SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
            std::vector<uint64_t> mergedTransactions(count);
            for (size_t i = 0; i < count; i++) {
                SAFE_PARCEL(data.readUint64, &mergedTransactions[i]);
            }

            return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
                                       std::move(inputWindowCommands), desiredPresentTime,
                                       isAutoTimestamp, uncacheBuffers, hasListenerCallbacks,
                                       listenerCallbacks, transactionId);
                                       listenerCallbacks, transactionId, mergedTransactions);
        }
        default: {
            return BBinder::onTransact(code, data, reply, flags);
+39 −2
Original line number Diff line number Diff line
@@ -827,6 +827,15 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel
        SAFE_PARCEL(parcel->readUint64, &uncacheBuffers[i].id);
    }

    count = static_cast<size_t>(parcel->readUint32());
    if (count > parcel->dataSize()) {
        return BAD_VALUE;
    }
    std::vector<uint64_t> mergedTransactionIds(count);
    for (size_t i = 0; i < count; i++) {
        SAFE_PARCEL(parcel->readUint64, &mergedTransactionIds[i]);
    }

    // Parsing was successful. Update the object.
    mId = transactionId;
    mTransactionNestCount = transactionNestCount;
@@ -842,6 +851,7 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel
    mInputWindowCommands = inputWindowCommands;
    mApplyToken = applyToken;
    mUncacheBuffers = std::move(uncacheBuffers);
    mMergedTransactionIds = std::move(mergedTransactionIds);
    return NO_ERROR;
}

@@ -900,6 +910,11 @@ status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const
        SAFE_PARCEL(parcel->writeUint64, uncacheBuffer.id);
    }

    SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mMergedTransactionIds.size()));
    for (auto mergedTransactionId : mMergedTransactionIds) {
        SAFE_PARCEL(parcel->writeUint64, mergedTransactionId);
    }

    return NO_ERROR;
}

@@ -924,6 +939,22 @@ void SurfaceComposerClient::Transaction::releaseBufferIfOverwriting(const layer_
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) {
    while (mMergedTransactionIds.size() + other.mMergedTransactionIds.size() >
                   MAX_MERGE_HISTORY_LENGTH - 1 &&
           mMergedTransactionIds.size() > 0) {
        mMergedTransactionIds.pop_back();
    }
    if (other.mMergedTransactionIds.size() == MAX_MERGE_HISTORY_LENGTH) {
        mMergedTransactionIds.insert(mMergedTransactionIds.begin(),
                                     other.mMergedTransactionIds.begin(),
                                     other.mMergedTransactionIds.end() - 1);
    } else if (other.mMergedTransactionIds.size() > 0u) {
        mMergedTransactionIds.insert(mMergedTransactionIds.begin(),
                                     other.mMergedTransactionIds.begin(),
                                     other.mMergedTransactionIds.end());
    }
    mMergedTransactionIds.insert(mMergedTransactionIds.begin(), other.mId);

    for (auto const& [handle, composerState] : other.mComposerStates) {
        if (mComposerStates.count(handle) == 0) {
            mComposerStates[handle] = composerState;
@@ -998,12 +1029,17 @@ void SurfaceComposerClient::Transaction::clear() {
    mIsAutoTimestamp = true;
    clearFrameTimelineInfo(mFrameTimelineInfo);
    mApplyToken = nullptr;
    mMergedTransactionIds.clear();
}

uint64_t SurfaceComposerClient::Transaction::getId() {
    return mId;
}

std::vector<uint64_t> SurfaceComposerClient::Transaction::getMergedTransactionIds() {
    return mMergedTransactionIds;
}

void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) {
    sp<ISurfaceComposer> sf(ComposerService::getComposerService());

@@ -1014,7 +1050,7 @@ void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) {
    status_t status = sf->setTransactionState(FrameTimelineInfo{}, composerStates, {},
                                              ISurfaceComposer::eOneWay,
                                              Transaction::getDefaultApplyToken(), {}, systemTime(),
                                              true, {uncacheBuffer}, false, {}, generateId());
                                              true, {uncacheBuffer}, false, {}, generateId(), {});
    if (status != NO_ERROR) {
        ALOGE_AND_TRACE("SurfaceComposerClient::doUncacheBufferTransaction - %s",
                        strerror(-status));
@@ -1189,7 +1225,8 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay
    sp<ISurfaceComposer> sf(ComposerService::getComposerService());
    sf->setTransactionState(mFrameTimelineInfo, composerStates, displayStates, flags, applyToken,
                            mInputWindowCommands, mDesiredPresentTime, mIsAutoTimestamp,
                            mUncacheBuffers, hasListenerCallbacks, listenerCallbacks, mId);
                            mUncacheBuffers, hasListenerCallbacks, listenerCallbacks, mId,
                            mMergedTransactionIds);
    mId = generateId();

    // Clear the current states and flags
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ public:
            InputWindowCommands inputWindowCommands, int64_t desiredPresentTime,
            bool isAutoTimestamp, const std::vector<client_cache_t>& uncacheBuffer,
            bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks,
            uint64_t transactionId) = 0;
            uint64_t transactionId, const std::vector<uint64_t>& mergedTransactionIds) = 0;
};

// ----------------------------------------------------------------------------
+7 −0
Original line number Diff line number Diff line
@@ -419,6 +419,11 @@ public:
                mListenerCallbacks;
        std::vector<client_cache_t> mUncacheBuffers;

        // We keep track of the last MAX_MERGE_HISTORY_LENGTH merged transaction ids.
        // Ordered most recently merged to least recently merged.
        static const size_t MAX_MERGE_HISTORY_LENGTH = 10u;
        std::vector<uint64_t> mMergedTransactionIds;

        uint64_t mId;

        uint32_t mTransactionNestCount = 0;
@@ -482,6 +487,8 @@ public:
        // The id is updated every time the transaction is applied.
        uint64_t getId();

        std::vector<uint64_t> getMergedTransactionIds();

        status_t apply(bool synchronous = false, bool oneWay = false);
        // Merge another transaction in to this one, clearing other
        // as if it had been applied.
+8 −10
Original line number Diff line number Diff line
@@ -695,16 +695,14 @@ public:
        mSupportsPresent = supportsPresent;
    }

    status_t setTransactionState(const FrameTimelineInfo& /*frameTimelineInfo*/,
                                 Vector<ComposerState>& /*state*/,
    status_t setTransactionState(
            const FrameTimelineInfo& /*frameTimelineInfo*/, Vector<ComposerState>& /*state*/,
            const Vector<DisplayState>& /*displays*/, uint32_t /*flags*/,
                                 const sp<IBinder>& /*applyToken*/,
                                 InputWindowCommands /*inputWindowCommands*/,
            const sp<IBinder>& /*applyToken*/, InputWindowCommands /*inputWindowCommands*/,
            int64_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/,
                                 const std::vector<client_cache_t>& /*cachedBuffer*/,
                                 bool /*hasListenerCallbacks*/,
                                 const std::vector<ListenerCallbacks>& /*listenerCallbacks*/,
                                 uint64_t /*transactionId*/) override {
            const std::vector<client_cache_t>& /*cachedBuffer*/, bool /*hasListenerCallbacks*/,
            const std::vector<ListenerCallbacks>& /*listenerCallbacks*/, uint64_t /*transactionId*/,
            const std::vector<uint64_t>& /*mergedTransactionIds*/) override {
        return NO_ERROR;
    }

Loading