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

Commit 3400a6eb authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Introduce ComplexTransactionState." into main

parents 695597cb e89d2685
Loading
Loading
Loading
Loading
+8 −60
Original line number Diff line number Diff line
@@ -58,18 +58,13 @@ public:

    virtual ~BpSurfaceComposer();

    status_t setTransactionState(
            const SimpleTransactionState simpleState, const FrameTimelineInfo& frameTimelineInfo,
    status_t setTransactionState(const SimpleTransactionState simpleState,
                                 const ComplexTransactionState& complexState,
                                 Vector<ComposerState>& state, Vector<DisplayState>& displays,
            const sp<IBinder>& applyToken, const std::vector<client_cache_t>& uncacheBuffers,
            const TransactionListenerCallbacks& listenerCallbacks,
            const std::vector<uint64_t>& mergedTransactionIds,
            const std::vector<gui::EarlyWakeupInfo>& earlyWakeupInfos) override {
                                 const sp<IBinder>& applyToken) override {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());

        frameTimelineInfo.writeToParcel(&data);

        SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
        for (const auto& s : state) {
            SAFE_PARCEL(s.write, data);
@@ -81,24 +76,8 @@ public:
        }

        SAFE_PARCEL(simpleState.writeToParcel, &data);
        SAFE_PARCEL(complexState.writeToParcel, &data);
        SAFE_PARCEL(data.writeStrongBinder, applyToken);
        SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(uncacheBuffers.size()));
        for (const client_cache_t& uncacheBuffer : uncacheBuffers) {
            SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
            SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
        }

        SAFE_PARCEL(listenerCallbacks.writeToParcel, &data);

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

        SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(earlyWakeupInfos.size()));
        for (const auto& e : earlyWakeupInfos) {
            e.writeToParcel(&data);
        }

        if (simpleState.mFlags & ISurfaceComposer::eOneWay) {
            return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply,
@@ -123,9 +102,6 @@ status_t BnSurfaceComposer::onTransact(uint32_t code, const Parcel& data, Parcel
        case SET_TRANSACTION_STATE: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);

            FrameTimelineInfo frameTimelineInfo;
            frameTimelineInfo.readFromParcel(&data);

            uint32_t count = 0;
            SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
            Vector<ComposerState> state;
@@ -147,41 +123,13 @@ status_t BnSurfaceComposer::onTransact(uint32_t code, const Parcel& data, Parcel

            SimpleTransactionState simpleState;
            SAFE_PARCEL(simpleState.readFromParcel, &data);
            ComplexTransactionState complexState;
            SAFE_PARCEL(complexState.readFromParcel, &data);

            sp<IBinder> applyToken;
            SAFE_PARCEL(data.readStrongBinder, &applyToken);

            SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
            std::vector<client_cache_t> uncacheBuffers(count);
            sp<IBinder> tmpBinder;
            for (size_t i = 0; i < count; i++) {
                SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
                uncacheBuffers[i].token = tmpBinder;
                SAFE_PARCEL(data.readUint64, &uncacheBuffers[i].id);
            }

            TransactionListenerCallbacks listenerCallbacks;
            SAFE_PARCEL(listenerCallbacks.readFromParcel, &data);

            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]);
            }

            count = 0;
            SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
            std::vector<gui::EarlyWakeupInfo> earlyWakeupInfos;
            earlyWakeupInfos.reserve(count);
            for (size_t i = 0; i < count; i++) {
                gui::EarlyWakeupInfo e;
                e.readFromParcel(&data);
                earlyWakeupInfos.push_back(std::move(e));
            }

            return setTransactionState(simpleState, frameTimelineInfo, state, displays, applyToken,
                                       uncacheBuffers, listenerCallbacks, mergedTransactions,
                                       earlyWakeupInfos);
            return setTransactionState(simpleState, complexState, state, displays, applyToken);
        }
        case GET_SCHEDULING_POLICY: {
            gui::SchedulingPolicy policy;
+28 −106
Original line number Diff line number Diff line
@@ -830,13 +830,12 @@ SurfaceComposerClient::Transaction::Transaction() {

SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
      : mSimpleState(other.mSimpleState),
        mComplexState(other.mComplexState),
        mMayContainBuffer(other.mMayContainBuffer),
        mFrameTimelineInfo(other.mFrameTimelineInfo),
        mApplyToken(other.mApplyToken) {
    mDisplayStates = other.mDisplayStates;
    mComposerStates = other.mComposerStates;
    mListenerCallbacks = other.mListenerCallbacks;
    mEarlyWakeupInfos = other.mEarlyWakeupInfos;
    mTransactionCompletedListener = TransactionCompletedListener::getInstance();
}

@@ -845,10 +844,10 @@ void SurfaceComposerClient::Transaction::sanitize(int pid, int uid) {
    for (auto& composerState : mComposerStates) {
        composerState.state.sanitize(permissions);
    }
    if (!mSimpleState.mInputWindowCommands.empty() &&
    if (!mComplexState.mInputWindowCommands.empty() &&
        (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) {
        ALOGE("Only privileged callers are allowed to send input commands.");
        mSimpleState.mInputWindowCommands.clear();
        mComplexState.mInputWindowCommands.clear();
    }
}

@@ -864,9 +863,9 @@ SurfaceComposerClient::Transaction::createFromParcel(const Parcel* parcel) {
status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel) {
    SimpleTransactionState simpleState;
    SAFE_PARCEL(simpleState.readFromParcel, parcel);
    ComplexTransactionState complexState;
    SAFE_PARCEL(complexState.readFromParcel, parcel);
    const bool logCallPoints = parcel->readBool();
    FrameTimelineInfo frameTimelineInfo;
    frameTimelineInfo.readFromParcel(parcel);

    sp<IBinder> applyToken;
    parcel->readNullableStrongBinder(&applyToken);
@@ -927,48 +926,13 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel
        composerStates.add(composerState);
    }

    count = static_cast<size_t>(parcel->readUint32());
    if (count > parcel->dataSize()) {
        return BAD_VALUE;
    }
    std::vector<client_cache_t> uncacheBuffers(count);
    for (size_t i = 0; i < count; i++) {
        sp<IBinder> tmpBinder;
        SAFE_PARCEL(parcel->readStrongBinder, &tmpBinder);
        uncacheBuffers[i].token = tmpBinder;
        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]);
    }

    count = static_cast<size_t>(parcel->readUint32());
    if (count > parcel->dataSize()) {
        return BAD_VALUE;
    }
    std::vector<gui::EarlyWakeupInfo> earlyWakeupInfos;
    for (size_t i = 0; i < count; i++) {
        gui::EarlyWakeupInfo e;
        e.readFromParcel(parcel);
        earlyWakeupInfos.push_back(std::move(e));
    }

    // Parsing was successful. Update the object.
    mSimpleState = simpleState;
    mFrameTimelineInfo = frameTimelineInfo;
    mSimpleState = std::move(simpleState);
    mComplexState = std::move(complexState);
    mDisplayStates = std::move(displayStates);
    mListenerCallbacks = listenerCallbacks;
    mComposerStates = std::move(composerStates);
    mApplyToken = applyToken;
    mUncacheBuffers = std::move(uncacheBuffers);
    mMergedTransactionIds = std::move(mergedTransactionIds);
    mEarlyWakeupInfos = std::move(earlyWakeupInfos);
    return NO_ERROR;
}

@@ -987,8 +951,8 @@ status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const
    const_cast<SurfaceComposerClient::Transaction*>(this)->cacheBuffers();

    SAFE_PARCEL(mSimpleState.writeToParcel, parcel);
    SAFE_PARCEL(mComplexState.writeToParcel, parcel);
    parcel->writeBool(mLogCallPoints);
    mFrameTimelineInfo.writeToParcel(parcel);
    parcel->writeStrongBinder(mApplyToken);
    parcel->writeUint32(static_cast<uint32_t>(mDisplayStates.size()));
    for (auto const& displayState : mDisplayStates) {
@@ -1013,22 +977,6 @@ status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const
        composerState.write(*parcel);
    }

    SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mUncacheBuffers.size()));
    for (const client_cache_t& uncacheBuffer : mUncacheBuffers) {
        SAFE_PARCEL(parcel->writeStrongBinder, uncacheBuffer.token.promote());
        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);
    }

    SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mEarlyWakeupInfos.size()));
    for (auto earlyWakeupInfo : mEarlyWakeupInfos) {
        earlyWakeupInfo.writeToParcel(parcel);
    }

    return NO_ERROR;
}

@@ -1053,22 +1001,6 @@ 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.mSimpleState.mId);

    for (auto const& otherState : other.mComposerStates) {
        if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(),
                                   [&otherState](const auto& composerState) {
@@ -1120,16 +1052,13 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr
        }
    }

    for (const auto& cacheId : other.mUncacheBuffers) {
        mUncacheBuffers.push_back(cacheId);
    }

    mSimpleState.merge(other.mSimpleState);
    mComplexState.merge(other.mComplexState);
    mComplexState.mMergedTransactionIds.insert(mComplexState.mMergedTransactionIds.begin(),
                                               other.mSimpleState.mId);
    mMayContainBuffer |= other.mMayContainBuffer;
    mApplyToken = other.mApplyToken;

    mergeFrameTimelineInfo(mFrameTimelineInfo, other.mFrameTimelineInfo);

    mLogCallPoints |= other.mLogCallPoints;
    if (mLogCallPoints) {
        ALOG(LOG_DEBUG, LOG_SURFACE_CONTROL_REGISTRY,
@@ -1137,10 +1066,6 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr
             mSimpleState.mId);
    }

    for (gui::EarlyWakeupInfo& op : other.mEarlyWakeupInfos) {
        mEarlyWakeupInfos.push_back(std::move(op));
    }

    other.clear();

    return *this;
@@ -1148,16 +1073,13 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr

void SurfaceComposerClient::Transaction::clear() {
    mSimpleState.clear();
    mComplexState.clear();
    mComposerStates.clear();
    mDisplayStates.clear();
    mListenerCallbacks.clear();
    mUncacheBuffers.clear();
    mMayContainBuffer = false;
    mFrameTimelineInfo = {};
    mApplyToken = nullptr;
    mMergedTransactionIds.clear();
    mLogCallPoints = false;
    mEarlyWakeupInfos.clear();
}

uint64_t SurfaceComposerClient::Transaction::getId() {
@@ -1165,23 +1087,24 @@ uint64_t SurfaceComposerClient::Transaction::getId() {
}

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

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

    ComplexTransactionState complexState;
    client_cache_t uncacheBuffer;
    uncacheBuffer.token = BufferCache::getInstance().getToken();
    uncacheBuffer.id = cacheId;
    complexState.mUncacheBuffers.emplace_back(std::move(uncacheBuffer));
    Vector<ComposerState> composerStates;
    Vector<DisplayState> displayStates;
    status_t status =
            sf->setTransactionState(SimpleTransactionState(generateId(), ISurfaceComposer::eOneWay,
                                                           systemTime(), true, {}),
                                    FrameTimelineInfo{}, composerStates, displayStates,
                                    Transaction::getDefaultApplyToken(), {uncacheBuffer},
                                    TransactionListenerCallbacks(), {}, {});
                                                           systemTime(), true),
                                    complexState, composerStates, displayStates,
                                    Transaction::getDefaultApplyToken());
    if (status != NO_ERROR) {
        ALOGE_AND_TRACE("SurfaceComposerClient::doUncacheBufferTransaction - %s",
                        strerror(-status));
@@ -1222,7 +1145,7 @@ void SurfaceComposerClient::Transaction::cacheBuffers() {
            std::optional<client_cache_t> uncacheBuffer;
            cacheId = BufferCache::getInstance().cache(s->bufferData->buffer, uncacheBuffer);
            if (uncacheBuffer) {
                mUncacheBuffers.push_back(*uncacheBuffer);
                mComplexState.mUncacheBuffers.push_back(*uncacheBuffer);
            }
        }
        s->bufferData->flags |= BufferData::BufferDataChange::cachedBufferChanged;
@@ -1291,7 +1214,8 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay
                                        /*callbackContext=*/nullptr);
    }

    TransactionListenerCallbacks listenerCallbacks;
    TransactionListenerCallbacks& listenerCallbacks = mComplexState.mCallbacks;
    listenerCallbacks.clear();
    listenerCallbacks.mHasListenerCallbacks = !mListenerCallbacks.empty();
    // For every listener with registered callbacks
    for (const auto& [listener, callbackInfo] : mListenerCallbacks) {
@@ -1340,10 +1264,8 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay
    sp<IBinder> applyToken = mApplyToken ? mApplyToken : getDefaultApplyToken();

    sp<ISurfaceComposer> sf(ComposerService::getComposerService());
    status_t binderStatus =
            sf->setTransactionState(mSimpleState, mFrameTimelineInfo, mComposerStates,
                                    mDisplayStates, applyToken, mUncacheBuffers, listenerCallbacks,
                                    mMergedTransactionIds, mEarlyWakeupInfos);
    status_t binderStatus = sf->setTransactionState(mSimpleState, mComplexState, mComposerStates,
                                                    mDisplayStates, applyToken);
    mSimpleState.mId = generateId();

    // Clear the current states and flags
@@ -1453,13 +1375,13 @@ void SurfaceComposerClient::Transaction::setAnimationTransaction() {

void SurfaceComposerClient::Transaction::setEarlyWakeupStart(gui::EarlyWakeupInfo earlyWakeupInfo) {
    earlyWakeupInfo.isStartRequest = true;
    mEarlyWakeupInfos.push_back(std::move(earlyWakeupInfo));
    mComplexState.mEarlyWakeupInfos.push_back(std::move(earlyWakeupInfo));
    mSimpleState.mFlags |= ISurfaceComposer::eEarlyWakeupStart;
}

void SurfaceComposerClient::Transaction::setEarlyWakeupEnd(gui::EarlyWakeupInfo earlyWakeupInfo) {
    earlyWakeupInfo.isStartRequest = false;
    mEarlyWakeupInfos.push_back(std::move(earlyWakeupInfo));
    mComplexState.mEarlyWakeupInfos.push_back(std::move(earlyWakeupInfo));
    mSimpleState.mFlags |= ISurfaceComposer::eEarlyWakeupEnd;
}

@@ -2148,14 +2070,14 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInput

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocusedWindow(
        const FocusRequest& request) {
    mSimpleState.mInputWindowCommands.addFocusRequest(request);
    mComplexState.mInputWindowCommands.addFocusRequest(request);
    return *this;
}

SurfaceComposerClient::Transaction&
SurfaceComposerClient::Transaction::addWindowInfosReportedListener(
        sp<gui::IWindowInfosReportedListener> windowInfosReportedListener) {
    mSimpleState.mInputWindowCommands.addWindowInfosReportedListener(windowInfosReportedListener);
    mComplexState.mInputWindowCommands.addWindowInfosReportedListener(windowInfosReportedListener);
    return *this;
}

@@ -2357,7 +2279,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFixed

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameTimelineInfo(
        const FrameTimelineInfo& frameTimelineInfo) {
    mergeFrameTimelineInfo(mFrameTimelineInfo, frameTimelineInfo);
    mComplexState.mergeFrameTimelineInfo(frameTimelineInfo);
    return *this;
}

+87 −51
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ void SimpleTransactionState::clear() {
void SimpleTransactionState::merge(const SimpleTransactionState& other) {
    // TODO(b/385156191) Consider merging desired present time.
    mFlags |= other.mFlags;
    mInputWindowCommands.merge(other.mInputWindowCommands);
}

status_t SimpleTransactionState::writeToParcel(Parcel* parcel) const {
@@ -39,7 +38,6 @@ status_t SimpleTransactionState::writeToParcel(Parcel* parcel) const {
    SAFE_PARCEL(parcel->writeUint32, mFlags);
    SAFE_PARCEL(parcel->writeInt64, mDesiredPresentTime);
    SAFE_PARCEL(parcel->writeBool, mIsAutoTimestamp);
    SAFE_PARCEL(mInputWindowCommands.write, *parcel);

    return NO_ERROR;
}
@@ -49,7 +47,6 @@ status_t SimpleTransactionState::readFromParcel(const Parcel* parcel) {
    SAFE_PARCEL(parcel->readUint32, &mFlags);
    SAFE_PARCEL(parcel->readInt64, &mDesiredPresentTime);
    SAFE_PARCEL(parcel->readBool, &mIsAutoTimestamp);
    SAFE_PARCEL(mInputWindowCommands.read, *parcel);

    return NO_ERROR;
}
@@ -86,10 +83,62 @@ status_t TransactionListenerCallbacks::readFromParcel(const Parcel* parcel) {
    return NO_ERROR;
}

status_t ComplexTransactionState::writeToParcel(Parcel* parcel) const {
    SAFE_PARCEL(parcel->writeParcelable, mFrameTimelineInfo);

    SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mUncacheBuffers.size()));
    for (const client_cache_t& uncacheBuffer : mUncacheBuffers) {
        SAFE_PARCEL(parcel->writeStrongBinder, uncacheBuffer.token.promote());
        SAFE_PARCEL(parcel->writeUint64, uncacheBuffer.id);
    }

    SAFE_PARCEL(parcel->writeUint64Vector, mMergedTransactionIds);
    SAFE_PARCEL(mCallbacks.writeToParcel, parcel);
    SAFE_PARCEL(mInputWindowCommands.write, *parcel);
    SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mEarlyWakeupInfos.size()));
    for (const auto& e : mEarlyWakeupInfos) {
        e.writeToParcel(parcel);
    }

    return NO_ERROR;
}

status_t ComplexTransactionState::readFromParcel(const Parcel* parcel) {
    SAFE_PARCEL(parcel->readParcelable, &mFrameTimelineInfo);

    uint32_t count;
    SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize())
    mUncacheBuffers.clear();
    mUncacheBuffers.reserve(count);
    for (size_t i = 0; i < count; i++) {
        client_cache_t client_cache;
        sp<IBinder> tmpBinder;
        SAFE_PARCEL(parcel->readStrongBinder, &tmpBinder);
        client_cache.token = tmpBinder;
        SAFE_PARCEL(parcel->readUint64, &client_cache.id);
        mUncacheBuffers.emplace_back(std::move(client_cache));
    }

    SAFE_PARCEL(parcel->readUint64Vector, &mMergedTransactionIds);
    SAFE_PARCEL(mCallbacks.readFromParcel, parcel);
    SAFE_PARCEL(mInputWindowCommands.read, *parcel);
    count = 0;
    SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize());
    std::vector<gui::EarlyWakeupInfo> earlyWakeupInfos;
    earlyWakeupInfos.reserve(count);
    for (size_t i = 0; i < count; i++) {
        gui::EarlyWakeupInfo e;
        e.readFromParcel(parcel);
        earlyWakeupInfos.push_back(std::move(e));
    }
    mEarlyWakeupInfos = std::move(earlyWakeupInfos);

    return NO_ERROR;
}

status_t TransactionState::writeToParcel(Parcel* parcel) const {
    SAFE_PARCEL(mSimpleState.writeToParcel, parcel);
    SAFE_PARCEL(mCallbacks.writeToParcel, parcel);
    SAFE_PARCEL(parcel->writeParcelable, mFrameTimelineInfo);
    SAFE_PARCEL(mComplexState.writeToParcel, parcel);
    SAFE_PARCEL(parcel->writeStrongBinder, mApplyToken);
    SAFE_PARCEL(parcel->writeBool, mMayContainBuffer);
    SAFE_PARCEL(parcel->writeBool, mLogCallPoints);
@@ -103,24 +152,12 @@ status_t TransactionState::writeToParcel(Parcel* parcel) const {
        composerState.write(*parcel);
    }

    SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mUncacheBuffers.size()));
    for (const client_cache_t& uncacheBuffer : mUncacheBuffers) {
        SAFE_PARCEL(parcel->writeStrongBinder, uncacheBuffer.token.promote());
        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;
}

status_t TransactionState::readFromParcel(const Parcel* parcel) {
    SAFE_PARCEL(mSimpleState.readFromParcel, parcel);
    SAFE_PARCEL(mCallbacks.readFromParcel, parcel);
    SAFE_PARCEL(parcel->readParcelable, &mFrameTimelineInfo);
    SAFE_PARCEL(mComplexState.readFromParcel, parcel);
    SAFE_PARCEL(parcel->readNullableStrongBinder, &mApplyToken);
    SAFE_PARCEL(parcel->readBool, &mMayContainBuffer);
    SAFE_PARCEL(parcel->readBool, &mLogCallPoints);
@@ -148,31 +185,10 @@ status_t TransactionState::readFromParcel(const Parcel* parcel) {
        mComposerStates.emplace_back(std::move(composerState));
    }

    SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize())
    mUncacheBuffers.clear();
    mUncacheBuffers.reserve(count);
    for (size_t i = 0; i < count; i++) {
        client_cache_t client_cache;
        sp<IBinder> tmpBinder;
        SAFE_PARCEL(parcel->readStrongBinder, &tmpBinder);
        client_cache.token = tmpBinder;
        SAFE_PARCEL(parcel->readUint64, &client_cache.id);
        mUncacheBuffers.emplace_back(std::move(client_cache));
    }

    SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize())
    mMergedTransactionIds.clear();
    mMergedTransactionIds.resize(count);
    for (size_t i = 0; i < count; i++) {
        SAFE_PARCEL(parcel->readUint64, &mMergedTransactionIds[i]);
    }

    return NO_ERROR;
}

void TransactionState::merge(TransactionState&& other,
                             const std::function<void(layer_state_t&)>& onBufferOverwrite) {
    mSimpleState.merge(other.mSimpleState);
void ComplexTransactionState::merge(ComplexTransactionState& other) {
    while (mMergedTransactionIds.size() + other.mMergedTransactionIds.size() >
                   MAX_MERGE_HISTORY_LENGTH - 1 &&
           mMergedTransactionIds.size() > 0) {
@@ -187,7 +203,26 @@ void TransactionState::merge(TransactionState&& other,
                                     other.mMergedTransactionIds.begin(),
                                     other.mMergedTransactionIds.end());
    }
    mMergedTransactionIds.insert(mMergedTransactionIds.begin(), other.mSimpleState.mId);

    for (auto& cacheId : other.mUncacheBuffers) {
        mUncacheBuffers.emplace_back(std::move(cacheId));
    }

    mergeFrameTimelineInfo(other.mFrameTimelineInfo);

    mInputWindowCommands.merge(other.mInputWindowCommands);

    for (gui::EarlyWakeupInfo& op : other.mEarlyWakeupInfos) {
        mEarlyWakeupInfos.emplace_back(std::move(op));
    }
}

void TransactionState::merge(TransactionState&& other,
                             const std::function<void(layer_state_t&)>& onBufferOverwrite) {
    mSimpleState.merge(other.mSimpleState);
    mComplexState.merge(other.mComplexState);
    mComplexState.mMergedTransactionIds.insert(mComplexState.mMergedTransactionIds.begin(),
                                               other.mSimpleState.mId);

    for (auto const& otherState : other.mComposerStates) {
        if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(),
@@ -217,21 +252,16 @@ void TransactionState::merge(TransactionState&& other,
        }
    }

    for (const auto& cacheId : other.mUncacheBuffers) {
        mUncacheBuffers.push_back(cacheId);
    }

    mMayContainBuffer |= other.mMayContainBuffer;
    mLogCallPoints |= other.mLogCallPoints;

    // mApplyToken is explicitly not merged. Token should be set before applying the transactions to
    // make synchronization decisions a bit simpler.
    mergeFrameTimelineInfo(other.mFrameTimelineInfo);
    other.clear();
}

// copied from FrameTimelineInfo::merge()
void TransactionState::mergeFrameTimelineInfo(const FrameTimelineInfo& other) {
void ComplexTransactionState::mergeFrameTimelineInfo(const FrameTimelineInfo& other) {
    // When merging vsync Ids we take the oldest valid one
    if (mFrameTimelineInfo.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID &&
        other.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) {
@@ -243,15 +273,21 @@ void TransactionState::mergeFrameTimelineInfo(const FrameTimelineInfo& other) {
    }
}

void ComplexTransactionState::clear() {
    mCallbacks.clear();
    mUncacheBuffers.clear();
    mFrameTimelineInfo = {};
    mMergedTransactionIds.clear();
    mInputWindowCommands.clear();
    mEarlyWakeupInfos.clear();
}

void TransactionState::clear() {
    mSimpleState.clear();
    mCallbacks.clear();
    mComplexState.clear();
    mComposerStates.clear();
    mDisplayStates.clear();
    mUncacheBuffers.clear();
    mApplyToken = nullptr;
    mFrameTimelineInfo = {};
    mMergedTransactionIds.clear();
    mMayContainBuffer = false;
    mLogCallPoints = false;
}
+6 −8

File changed.

Preview size limit exceeded, changes collapsed.

+2 −4

File changed.

Preview size limit exceeded, changes collapsed.

Loading