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

Commit c6ea2a80 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 13750820 from 4906b3fa to 25Q4-release

Change-Id: Ifb7b4b9134c6cab87e2d3b8b40854f62a37e2247
parents 9b1f2efc 4906b3fa
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -496,6 +496,7 @@ void ASurfaceTransaction_setCrop(ASurfaceTransaction* _Nonnull transaction,

/**
 * Specifies the position in the parent's space where the surface will be drawn.
 * Only permits finite values to be set.
 *
 * \param x The x position to render the surface.
 * \param y The y position to render the surface.
@@ -519,6 +520,7 @@ void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* _Nonnull transa

/**
 * Sets an x and y scale of a surface with (0, 0) as the centerpoint of the scale.
 * Only permits finite values to be set.
 *
 * \param xScale The scale in the x direction. Must be greater than 0.
 * \param yScale The scale in the y direction. Must be greater than 0.
+11 −9
Original line number Diff line number Diff line
@@ -182,10 +182,6 @@ status_t TransactionStats::writeToParcel(Parcel* output) const {
    if (err != NO_ERROR) {
        return err;
    }
    err = output->writeStrongBinderVector(transactionHandles);
    if (err != NO_ERROR) {
        return err;
    }
    err = output->writeInt64(latchTime);
    if (err != NO_ERROR) {
        return err;
@@ -210,10 +206,6 @@ status_t TransactionStats::readFromParcel(const Parcel* input) {
    if (err != NO_ERROR) {
        return err;
    }
    err = input->readStrongBinderVector(&transactionHandles);
    if (err != NO_ERROR) {
        return err;
    }
    err = input->readInt64(&latchTime);
    if (err != NO_ERROR) {
        return err;
@@ -261,6 +253,16 @@ status_t ListenerStats::readFromParcel(const Parcel* input) {
    return NO_ERROR;
}

ListenerStats ListenerStats::createEmpty(
        const sp<IBinder>& listener,
        const std::unordered_set<CallbackId, CallbackIdHash>& callbackIds) {
    ListenerStats listenerStats;
    listenerStats.listener = listener;
    listenerStats.transactionStats.emplace_back(callbackIds);

    return listenerStats;
}

class BpTransactionCompletedListener : public SafeBpInterface<ITransactionCompletedListener> {
public:
    explicit BpTransactionCompletedListener(const sp<IBinder>& impl)
@@ -331,7 +333,7 @@ ListenerCallbacks ListenerCallbacks::filter(CallbackId::Type type) const {
            filteredCallbackIds.push_back(callbackId);
        }
    }
    return ListenerCallbacks(transactionCompletedListener, filteredCallbackIds, transactionHandles);
    return ListenerCallbacks(transactionCompletedListener, filteredCallbackIds);
}

status_t CallbackId::writeToParcel(Parcel* output) const {
+1 −5
Original line number Diff line number Diff line
@@ -180,7 +180,6 @@ status_t layer_state_t::write(Parcel& output) const
    for (auto listener : listeners) {
        SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
        SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
        SAFE_PARCEL(output.writeStrongBinderVector, listener.transactionHandles);
    }
    SAFE_PARCEL(output.writeFloat, shadowRadius);
    SAFE_PARCEL(output.writeParcelable, borderSettings);
@@ -329,12 +328,9 @@ status_t layer_state_t::read(const Parcel& input)
    for (int i = 0; i < numListeners; i++) {
        sp<IBinder> listener;
        std::vector<CallbackId> callbackIds;
        std::vector<sp<IBinder>> transactionHandles;
        SAFE_PARCEL(input.readNullableStrongBinder, &listener);
        SAFE_PARCEL(input.readParcelableVector, &callbackIds);
        SAFE_PARCEL(input.readStrongBinderVector, &transactionHandles);
        listeners.emplace_back(std::move(listener), std::move(callbackIds),
                               std::move(transactionHandles));
        listeners.emplace_back(listener, callbackIds);
    }
    SAFE_PARCEL(input.readFloat, &shadowRadius);
    SAFE_PARCEL(input.readParcelable, &borderSettings);
+42 −84
Original line number Diff line number Diff line
@@ -419,28 +419,25 @@ CallbackId TransactionCompletedListener::addCallbackFunction(
        const TransactionCompletedCallback& callbackFunction,
        const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
                surfaceControls,
        CallbackId::Type callbackType, const wp<IBinder>& transactionHandle) {
        CallbackId::Type callbackType) {
    std::lock_guard<std::mutex> lock(mMutex);
    startListeningLocked();

    CallbackId callbackId(getNextIdLocked(), callbackType);
    CallbackTranslation& callbackTranslation = mCallbacks[callbackId];
    callbackTranslation.callbackFunction = callbackFunction;
    callbackTranslation.transactionHandle = transactionHandle;
    mCallbacks[callbackId].callbackFunction = callbackFunction;
    auto& callbackSurfaceControls = mCallbacks[callbackId].surfaceControls;

    for (const auto& surfaceControl : surfaceControls) {
        callbackTranslation.surfaceControls.emplace(surfaceControl->getHandle(), surfaceControl);
        callbackSurfaceControls[surfaceControl->getHandle()] = surfaceControl;
    }

    return callbackId;
}

void TransactionCompletedListener::setReleaseBufferCallback(const ReleaseCallbackId& callbackId,
                                                            ReleaseBufferCallback listener,
                                                            const wp<IBinder>& transactionHandle) {
                                                            ReleaseBufferCallback listener) {
    std::scoped_lock<std::mutex> lock(mMutex);
    ReleaseCallbackTranslation& callbackTranslation = mReleaseBufferCallbacks[callbackId];
    callbackTranslation.callbackFunction = std::move(listener);
    callbackTranslation.transactionHandle = transactionHandle;
    mReleaseBufferCallbacks[callbackId] = listener;
}

void TransactionCompletedListener::addSurfaceStatsListener(void* context, void* cookie,
@@ -505,7 +502,7 @@ void TransactionCompletedListener::onTransactionCompleted(ListenerStats listener
            if (callbackId.type != CallbackId::Type::ON_COMMIT) {
                continue;
            }
            auto& [callbackFunction, _, callbackSurfaceControls] = callbacksMap[callbackId];
            auto& [callbackFunction, callbackSurfaceControls] = callbacksMap[callbackId];
            if (!callbackFunction) {
                continue;
            }
@@ -535,7 +532,7 @@ void TransactionCompletedListener::onTransactionCompleted(ListenerStats listener
            if (callbackId.type != CallbackId::Type::ON_COMPLETE) {
                continue;
            }
            auto& [callbackFunction, _, callbackSurfaceControls] = callbacksMap[callbackId];
            auto& [callbackFunction, callbackSurfaceControls] = callbacksMap[callbackId];
            if (!callbackFunction) {
                ALOGE("cannot call null callback function, skipping");
                continue;
@@ -670,7 +667,7 @@ ReleaseBufferCallback TransactionCompletedListener::popReleaseBufferCallbackLock
    if (itr == mReleaseBufferCallbacks.end()) {
        return nullptr;
    }
    callback = std::move(itr->second.callbackFunction);
    callback = itr->second;
    mReleaseBufferCallbacks.erase(itr);
    return callback;
}
@@ -722,26 +719,6 @@ void TransactionCompletedListener::onTrustedPresentationChanged(int id,
    tpc(context, presentedWithinThresholds);
}

void TransactionCompletedListener::onTransactionDestroyed(const wp<IBinder>& transactionHandle) {
    std::lock_guard lock{mMutex};

    for (auto it = mCallbacks.begin(); it != mCallbacks.end();) {
        if (it->second.transactionHandle == transactionHandle) {
            it = mCallbacks.erase(it);
        } else {
            it++;
        }
    }

    for (auto it = mReleaseBufferCallbacks.begin(); it != mReleaseBufferCallbacks.end();) {
        if (it->second.transactionHandle == transactionHandle) {
            it = mReleaseBufferCallbacks.erase(it);
        } else {
            it++;
        }
    }
}

// ---------------------------------------------------------------------------

void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId);
@@ -857,12 +834,12 @@ SurfaceComposerClient::Transaction::Transaction() {
}

SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
      : mTransactionCompletedListener(TransactionCompletedListener::getInstance()),
        mState(other.mState),
        mListenerCallbacks(other.mListenerCallbacks),
        mTransactionHandle(other.mTransactionHandle),
      : mState(other.mState),
        mMayContainBuffer(other.mMayContainBuffer),
        mApplyToken(other.mApplyToken) {}
        mApplyToken(other.mApplyToken) {
    mListenerCallbacks = other.mListenerCallbacks;
    mTransactionCompletedListener = TransactionCompletedListener::getInstance();
}

void SurfaceComposerClient::Transaction::sanitize(int pid, int uid) {
    // TODO(b/356936695) move to TransactionState.
@@ -902,7 +879,6 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel
    for (size_t i = 0; i < count; i++) {
        sp<ITransactionCompletedListener> listener =
                interface_cast<ITransactionCompletedListener>(parcel->readStrongBinder());
        CallbackInfo& callbackInfo = listenerCallbacks[listener];
        size_t numCallbackIds = parcel->readUint32();
        if (numCallbackIds > parcel->dataSize()) {
            return BAD_VALUE;
@@ -910,7 +886,7 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel
        for (size_t j = 0; j < numCallbackIds; j++) {
            CallbackId id;
            parcel->readParcelable(&id);
            callbackInfo.callbackIds.insert(id);
            listenerCallbacks[listener].callbackIds.insert(id);
        }
        size_t numSurfaces = parcel->readUint32();
        if (numSurfaces > parcel->dataSize()) {
@@ -919,22 +895,13 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel
        for (size_t j = 0; j < numSurfaces; j++) {
            sp<SurfaceControl> surface;
            SAFE_PARCEL(SurfaceControl::readFromParcel, *parcel, &surface);
            callbackInfo.surfaceControls.insert(surface);
        }
        size_t numHandles = parcel->readUint32();
        if (numHandles > parcel->dataSize()) {
            return BAD_VALUE;
        }
        for (size_t j = 0; j < numHandles; j++) {
            sp<IBinder> transactionHandle;
            SAFE_PARCEL(parcel->readStrongBinder, &transactionHandle);
            callbackInfo.transactionHandles.insert(std::move(transactionHandle));
            listenerCallbacks[listener].surfaceControls.insert(surface);
        }
    }

    // Parsing was successful. Update the object.
    mState = std::move(state);
    mListenerCallbacks = std::move(listenerCallbacks);
    mListenerCallbacks = listenerCallbacks;
    mApplyToken = applyToken;
    return NO_ERROR;
}
@@ -968,10 +935,6 @@ status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const
        for (auto surfaceControl : callbackInfo.surfaceControls) {
            SAFE_PARCEL(surfaceControl->writeToParcel, *parcel);
        }
        parcel->writeUint32(static_cast<uint32_t>(callbackInfo.transactionHandles.size()));
        for (auto& transactionHandle : callbackInfo.transactionHandles) {
            SAFE_PARCEL(parcel->writeStrongBinder, transactionHandle);
        }
    }

    return NO_ERROR;
@@ -1008,14 +971,13 @@ void SurfaceComposerClient::Transaction::releaseBufferIfOverwriting(const layer_

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) {
    for (const auto& [listener, callbackInfo] : other.mListenerCallbacks) {
        auto& [callbackIds, surfaceControls, transactionHandles] = callbackInfo;
        auto& [callbackIds, surfaceControls] = callbackInfo;
        mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator(
                                                                callbackIds.begin()),
                                                        std::make_move_iterator(callbackIds.end()));

        auto& mergedCallbackInfo = mListenerCallbacks[listener];
        mergedCallbackInfo.callbackIds.insert(callbackIds.begin(), callbackIds.end());
        mergedCallbackInfo.surfaceControls.insert(surfaceControls.begin(), surfaceControls.end());
        mergedCallbackInfo.transactionHandles
                .insert(std::make_move_iterator(transactionHandles.begin()),
                        std::make_move_iterator(transactionHandles.end()));
        mListenerCallbacks[listener].surfaceControls.insert(surfaceControls.begin(),
                                                            surfaceControls.end());

        auto& currentProcessCallbackInfo =
                mListenerCallbacks[TransactionCompletedListener::getIInstance()];
@@ -1052,7 +1014,6 @@ void SurfaceComposerClient::Transaction::clear() {
    mState.clear();
    mState.mId = generateId();
    mListenerCallbacks.clear();
    mTransactionHandle.clear();
    mMayContainBuffer = false;
    mApplyToken = nullptr;
    mLogCallPoints = false;
@@ -1190,14 +1151,15 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay
    listenerCallbacks.mHasListenerCallbacks = !mListenerCallbacks.empty();
    // For every listener with registered callbacks
    for (const auto& [listener, callbackInfo] : mListenerCallbacks) {
        auto& [callbackIds, surfaceControls, transactionHandles] = callbackInfo;
        auto& [callbackIds, surfaceControls] = callbackInfo;
        if (callbackIds.empty()) {
            continue;
        }

        if (surfaceControls.empty()) {
            listenerCallbacks.mFlattenedListenerCallbacks
                    .emplace_back(IInterface::asBinder(listener), callbackIds, transactionHandles);
            listenerCallbacks.mFlattenedListenerCallbacks.emplace_back(IInterface::asBinder(
                                                                               listener),
                                                                       std::move(callbackIds));
        } else {
            // If the listener has any SurfaceControls set on this Transaction update the surface
            // state
@@ -1208,11 +1170,8 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay
                    continue;
                }
                std::vector<CallbackId> callbacks(callbackIds.begin(), callbackIds.end());
                std::vector<sp<IBinder>> handles(transactionHandles.begin(),
                                                 transactionHandles.end());
                s->what |= layer_state_t::eHasListenerCallbacksChanged;
                s->listeners.emplace_back(IInterface::asBinder(listener), std::move(callbacks),
                                          std::move(handles));
                s->listeners.emplace_back(IInterface::asBinder(listener), callbacks);
            }
        }
    }
@@ -1376,6 +1335,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPosit
        mStatus = BAD_INDEX;
        return *this;
    }
    LOG_ALWAYS_FATAL_IF(!isfinite(x) || !isfinite(y), "setPosition called with infinite values");
    s->what |= layer_state_t::ePositionChanged;
    s->x = x;
    s->y = y;
@@ -1516,6 +1476,8 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMatri
        mStatus = BAD_INDEX;
        return *this;
    }
    LOG_ALWAYS_FATAL_IF(!isfinite(dsdx) || !isfinite(dtdx) || !isfinite(dtdy) || !isfinite(dsdy),
                        "setMatrix called with infinite values");
    s->what |= layer_state_t::eMatrixChanged;
    layer_state_t::matrix22_t matrix;
    matrix.dsdx = dsdx;
@@ -1759,8 +1721,14 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffe
    s->bufferData = std::move(bufferData);
    registerSurfaceControlForCallback(sc);

    // Ensure there's a transaction completed callback registered so that buffers can be released
    // via ITransactionCompletedListener::onTransactionCompleted.
    // With the current infrastructure, a release callback will not be invoked if there's no
    // transaction callback in the case when a buffer is latched and not released early. This is
    // because the legacy implementation didn't have a release callback and sent releases in the
    // transaction callback. Because of this, we need to make sure to have a transaction callback
    // set up when a buffer is sent in a transaction to ensure the caller gets the release
    // callback, regardless if they set up a transaction callback.
    //
    // TODO (b/230380821): Remove when release callbacks are separated from transaction callbacks
    addTransactionCompletedCallback([](void*, nsecs_t, const sp<Fence>&,
                                       const std::vector<SurfaceControlStats>&) {},
                                    nullptr);
@@ -1803,7 +1771,7 @@ void SurfaceComposerClient::Transaction::setReleaseBufferCallback(BufferData* bu
    bufferData->releaseBufferListener =
            static_cast<sp<ITransactionCompletedListener>>(mTransactionCompletedListener);
    mTransactionCompletedListener->setReleaseBufferCallback(bufferData->generateReleaseCallbackId(),
                                                            callback, getTransactionHandle());
                                                            callback);
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDataspace(
@@ -1976,11 +1944,6 @@ SurfaceComposerClient::Transaction::setFrameRateSelectionPriority(const sp<Surfa
    return *this;
}

SurfaceComposerClient::TransactionHandle::~TransactionHandle() {
    TransactionCompletedListener::getInstance()->onTransactionDestroyed(
            wp<TransactionHandle>::fromExisting(this));
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::addTransactionCallback(
        TransactionCompletedCallbackTakesContext callback, void* callbackContext,
        CallbackId::Type callbackType) {
@@ -1991,14 +1954,9 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::addTrans

    CallbackId callbackId =
            mTransactionCompletedListener->addCallbackFunction(callbackWithContext, surfaceControls,
                                                               callbackType,
                                                               getTransactionHandle());
                                                               callbackType);

    mListenerCallbacks[mTransactionCompletedListener].callbackIds.emplace(callbackId);
    if (libgui_flags::unapplied_transaction_cleanup()) {
        mListenerCallbacks[mTransactionCompletedListener].transactionHandles.emplace(
                getTransactionHandle());
    }
    return *this;
}

+2 −6
Original line number Diff line number Diff line
@@ -31,10 +31,9 @@ void TransactionListenerCallbacks::clear() {
status_t TransactionListenerCallbacks::writeToParcel(Parcel* parcel) const {
    SAFE_PARCEL(parcel->writeBool, mHasListenerCallbacks);
    SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mFlattenedListenerCallbacks.size()));
    for (const auto& [listener, callbackIds, transactionHandles] : mFlattenedListenerCallbacks) {
    for (const auto& [listener, callbackIds] : mFlattenedListenerCallbacks) {
        SAFE_PARCEL(parcel->writeStrongBinder, listener);
        SAFE_PARCEL(parcel->writeParcelableVector, callbackIds);
        SAFE_PARCEL(parcel->writeStrongBinderVector, transactionHandles);
    }

    return NO_ERROR;
@@ -51,10 +50,7 @@ status_t TransactionListenerCallbacks::readFromParcel(const Parcel* parcel) {
        SAFE_PARCEL(parcel->readStrongBinder, &tmpBinder);
        std::vector<CallbackId> callbackIds;
        SAFE_PARCEL(parcel->readParcelableVector, &callbackIds);
        std::vector<sp<IBinder>> transactionHandles;
        SAFE_PARCEL(parcel->readStrongBinderVector, &transactionHandles);
        mFlattenedListenerCallbacks.emplace_back(std::move(tmpBinder), std::move(callbackIds),
                                                 std::move(transactionHandles));
        mFlattenedListenerCallbacks.emplace_back(tmpBinder, callbackIds);
    }

    return NO_ERROR;
Loading