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

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

Merge "Full TransactionState." into main

parents 9e1394da 6010c245
Loading
Loading
Loading
Loading
+6 −16
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
#include <gui/ISurfaceComposer.h>
#include <gui/LayerState.h>
#include <gui/SchedulingPolicy.h>
#include <gui/SimpleTransactionState.h>
#include <gui/TransactionState.h>
#include <private/gui/ParcelUtils.h>
#include <stdint.h>
@@ -58,19 +57,14 @@ public:

    virtual ~BpSurfaceComposer();

    status_t setTransactionState(const SimpleTransactionState simpleState,
                                 const ComplexTransactionState& complexState,
                                 MutableTransactionState& mutableState,
                                 const sp<IBinder>& applyToken) override {
    status_t setTransactionState(TransactionState&& state, const sp<IBinder>& applyToken) override {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());

        SAFE_PARCEL(mutableState.writeToParcel, &data);
        SAFE_PARCEL(simpleState.writeToParcel, &data);
        SAFE_PARCEL(complexState.writeToParcel, &data);
        SAFE_PARCEL(state.writeToParcel, &data);
        SAFE_PARCEL(data.writeStrongBinder, applyToken);

        if (simpleState.mFlags & ISurfaceComposer::eOneWay) {
        if (state.mFlags & ISurfaceComposer::eOneWay) {
            return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply,
                                      IBinder::FLAG_ONEWAY);
        } else {
@@ -93,17 +87,13 @@ status_t BnSurfaceComposer::onTransact(uint32_t code, const Parcel& data, Parcel
        case SET_TRANSACTION_STATE: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);

            MutableTransactionState mutableState;
            SAFE_PARCEL(mutableState.readFromParcel, &data);
            SimpleTransactionState simpleState;
            SAFE_PARCEL(simpleState.readFromParcel, &data);
            ComplexTransactionState complexState;
            SAFE_PARCEL(complexState.readFromParcel, &data);
            TransactionState state;
            SAFE_PARCEL(state.readFromParcel, &data);

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

            return setTransactionState(simpleState, complexState, mutableState, applyToken);
            return setTransactionState(std::move(state), applyToken);
        }
        case GET_SCHEDULING_POLICY: {
            gui::SchedulingPolicy policy;
+44 −62
Original line number Diff line number Diff line
@@ -824,14 +824,12 @@ void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId) {
// ---------------------------------------------------------------------------

SurfaceComposerClient::Transaction::Transaction() {
    mSimpleState.mId = generateId();
    mState.mId = generateId();
    mTransactionCompletedListener = TransactionCompletedListener::getInstance();
}

SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
      : mSimpleState(other.mSimpleState),
        mComplexState(other.mComplexState),
        mMutableState(other.mMutableState),
      : mState(other.mState),
        mMayContainBuffer(other.mMayContainBuffer),
        mApplyToken(other.mApplyToken) {
    mListenerCallbacks = other.mListenerCallbacks;
@@ -839,14 +837,15 @@ SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
}

void SurfaceComposerClient::Transaction::sanitize(int pid, int uid) {
    // TODO(b/356936695) move to TransactionState.
    uint32_t permissions = LayerStatePermissions::getTransactionPermissions(pid, uid);
    for (auto& composerState : mMutableState.mComposerStates) {
    for (auto& composerState : mState.mComposerStates) {
        composerState.state.sanitize(permissions);
    }
    if (!mComplexState.mInputWindowCommands.empty() &&
    if (!mState.mInputWindowCommands.empty() &&
        (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) {
        ALOGE("Only privileged callers are allowed to send input commands.");
        mComplexState.mInputWindowCommands.clear();
        mState.mInputWindowCommands.clear();
    }
}

@@ -860,12 +859,8 @@ 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);
    MutableTransactionState mutableState;
    SAFE_PARCEL(mutableState.readFromParcel, parcel);
    TransactionState state;
    SAFE_PARCEL(state.readFromParcel, parcel);
    const bool logCallPoints = parcel->readBool();

    sp<IBinder> applyToken;
@@ -900,9 +895,7 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel
    }

    // Parsing was successful. Update the object.
    mSimpleState = std::move(simpleState);
    mComplexState = std::move(complexState);
    mMutableState = std::move(mutableState);
    mState = std::move(state);
    mListenerCallbacks = listenerCallbacks;
    mApplyToken = applyToken;
    return NO_ERROR;
@@ -922,9 +915,7 @@ status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const

    const_cast<SurfaceComposerClient::Transaction*>(this)->cacheBuffers();

    SAFE_PARCEL(mSimpleState.writeToParcel, parcel);
    SAFE_PARCEL(mComplexState.writeToParcel, parcel);
    SAFE_PARCEL(mMutableState.writeToParcel, parcel);
    SAFE_PARCEL(mState.writeToParcel, parcel);
    parcel->writeBool(mLogCallPoints);
    parcel->writeStrongBinder(mApplyToken);

@@ -988,12 +979,8 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr
        }
    }

    mSimpleState.merge(other.mSimpleState);
    mComplexState.merge(other.mComplexState);
    mComplexState.mMergedTransactionIds.insert(mComplexState.mMergedTransactionIds.begin(),
                                               other.mSimpleState.mId);
    mMutableState.merge(other.mMutableState,
                        [this](const auto& state) { releaseBufferIfOverwriting(state); });
    mState.merge(std::move(other.mState),
                 [this](const layer_state_t& state) { releaseBufferIfOverwriting(state); });
    mMayContainBuffer |= other.mMayContainBuffer;
    mApplyToken = other.mApplyToken;

@@ -1001,7 +988,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr
    if (mLogCallPoints) {
        ALOG(LOG_DEBUG, LOG_SURFACE_CONTROL_REGISTRY,
             "Transaction %" PRIu64 " merged with transaction %" PRIu64, other.getId(),
             mSimpleState.mId);
             mState.getId());
    }

    other.clear();
@@ -1010,9 +997,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr
}

void SurfaceComposerClient::Transaction::clear() {
    mSimpleState.clear();
    mComplexState.clear();
    mMutableState.clear();
    mState.clear();
    mListenerCallbacks.clear();
    mMayContainBuffer = false;
    mApplyToken = nullptr;
@@ -1020,27 +1005,23 @@ void SurfaceComposerClient::Transaction::clear() {
}

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

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

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

    ComplexTransactionState complexState;
    TransactionState state(generateId(), ISurfaceComposer::eOneWay, systemTime(), true);
    client_cache_t uncacheBuffer;
    uncacheBuffer.token = BufferCache::getInstance().getToken();
    uncacheBuffer.id = cacheId;
    complexState.mUncacheBuffers.emplace_back(std::move(uncacheBuffer));
    MutableTransactionState mutableState;
    state.mUncacheBuffers.emplace_back(std::move(uncacheBuffer));
    status_t status =
            sf->setTransactionState(SimpleTransactionState(generateId(), ISurfaceComposer::eOneWay,
                                                           systemTime(), true),
                                    complexState, mutableState,
                                    Transaction::getDefaultApplyToken());
            sf->setTransactionState(std::move(state), Transaction::getDefaultApplyToken());
    if (status != NO_ERROR) {
        ALOGE_AND_TRACE("SurfaceComposerClient::doUncacheBufferTransaction - %s",
                        strerror(-status));
@@ -1053,7 +1034,7 @@ void SurfaceComposerClient::Transaction::cacheBuffers() {
    }

    size_t count = 0;
    for (auto& cs : mMutableState.mComposerStates) {
    for (auto& cs : mState.mComposerStates) {
        layer_state_t* s = &cs.state;
        if (!(s->what & layer_state_t::eBufferChanged)) {
            continue;
@@ -1081,7 +1062,7 @@ void SurfaceComposerClient::Transaction::cacheBuffers() {
            std::optional<client_cache_t> uncacheBuffer;
            cacheId = BufferCache::getInstance().cache(s->bufferData->buffer, uncacheBuffer);
            if (uncacheBuffer) {
                mComplexState.mUncacheBuffers.push_back(*uncacheBuffer);
                mState.mUncacheBuffers.push_back(*uncacheBuffer);
            }
        }
        s->bufferData->flags |= BufferData::BufferDataChange::cachedBufferChanged;
@@ -1150,7 +1131,7 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay
                                        /*callbackContext=*/nullptr);
    }

    TransactionListenerCallbacks& listenerCallbacks = mComplexState.mCallbacks;
    TransactionListenerCallbacks& listenerCallbacks = mState.mCallbacks;
    listenerCallbacks.clear();
    listenerCallbacks.mHasListenerCallbacks = !mListenerCallbacks.empty();
    // For every listener with registered callbacks
@@ -1187,22 +1168,23 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay
            ALOGE("Transaction attempted to set synchronous and one way at the same time"
                  " this is an invalid request. Synchronous will win for safety");
        } else {
            mSimpleState.mFlags |= ISurfaceComposer::eOneWay;
            mState.mFlags |= ISurfaceComposer::eOneWay;
        }
    }

    // If both ISurfaceComposer::eEarlyWakeupStart and ISurfaceComposer::eEarlyWakeupEnd are set
    // it is equivalent for none
    uint32_t wakeupFlags = ISurfaceComposer::eEarlyWakeupStart | ISurfaceComposer::eEarlyWakeupEnd;
    if ((mSimpleState.mFlags & wakeupFlags) == wakeupFlags) {
        mSimpleState.mFlags &= ~(wakeupFlags);
    if ((mState.mFlags & wakeupFlags) == wakeupFlags) {
        mState.mFlags &= ~(wakeupFlags);
    }
    sp<IBinder> applyToken = mApplyToken ? mApplyToken : getDefaultApplyToken();

    sp<ISurfaceComposer> sf(ComposerService::getComposerService());
    status_t binderStatus =
            sf->setTransactionState(mSimpleState, mComplexState, mMutableState, applyToken);
    mSimpleState.mId = generateId();
    TransactionState state = std::move(mState);
    mState = TransactionState();
    mState.mId = generateId();
    status_t binderStatus = sf->setTransactionState(std::move(state), applyToken);

    // Clear the current states and flags
    clear();
@@ -1213,7 +1195,7 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay

    if (mLogCallPoints) {
        ALOG(LOG_DEBUG, LOG_SURFACE_CONTROL_REGISTRY, "Transaction %" PRIu64 " applied",
             mSimpleState.mId);
             mState.mId);
    }

    mStatus = NO_ERROR;
@@ -1306,23 +1288,23 @@ std::optional<gui::StalledTransactionInfo> SurfaceComposerClient::getStalledTran
}

void SurfaceComposerClient::Transaction::setAnimationTransaction() {
    mSimpleState.mFlags |= ISurfaceComposer::eAnimation;
    mState.mFlags |= ISurfaceComposer::eAnimation;
}

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

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

layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<SurfaceControl>& sc) {
    return mMutableState.getLayerState(sc);
    return mState.getLayerState(sc);
}

void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback(
@@ -1706,8 +1688,8 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffe
        setReleaseBufferCallback(bufferData.get(), callback);
    }

    if (mSimpleState.mIsAutoTimestamp) {
        mSimpleState.mDesiredPresentTime = systemTime();
    if (mState.mIsAutoTimestamp) {
        mState.mDesiredPresentTime = systemTime();
    }
    s->what |= layer_state_t::eBufferChanged;
    s->bufferData = std::move(bufferData);
@@ -1901,8 +1883,8 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSideb

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesiredPresentTime(
        nsecs_t desiredPresentTime) {
    mSimpleState.mDesiredPresentTime = desiredPresentTime;
    mSimpleState.mIsAutoTimestamp = false;
    mState.mDesiredPresentTime = desiredPresentTime;
    mState.mIsAutoTimestamp = false;
    return *this;
}

@@ -1991,14 +1973,14 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInput

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

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

@@ -2200,7 +2182,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFixed

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

@@ -2367,7 +2349,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setConte
// ---------------------------------------------------------------------------

DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
    return mMutableState.getDisplayState(token);
    return mState.getDisplayState(token);
}

status_t SurfaceComposerClient::Transaction::setDisplaySurface(
+45 −203

File changed.

Preview size limit exceeded, changes collapsed.

+2 −6
Original line number Diff line number Diff line
@@ -66,9 +66,7 @@ struct DisplayState;
struct InputWindowCommands;
class HdrCapabilities;
class Rect;
struct SimpleTransactionState;
struct ComplexTransactionState;
struct MutableTransactionState;
class TransactionState;

using gui::FrameTimelineInfo;
using gui::IDisplayEventConnection;
@@ -109,9 +107,7 @@ public:
    };

    /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */
    virtual status_t setTransactionState(SimpleTransactionState simpleState,
                                         const ComplexTransactionState& complexState,
                                         MutableTransactionState& mutableState,
    virtual status_t setTransactionState(TransactionState&& state,
                                         const sp<IBinder>& applyToken) = 0;
};

+0 −61
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <cstdint>

#include <gui/LayerState.h>

namespace android {

// Defined in its own header to avoid circular dependencies in includes.
struct SimpleTransactionState {
    uint64_t mId = 0;
    uint32_t mFlags = 0;
    // mDesiredPresentTime is the time in nanoseconds that the client would like the transaction
    // to be presented. When it is not possible to present at exactly that time, it will be
    // presented after the time has passed.
    //
    // If the client didn't pass a desired presentation time, mDesiredPresentTime will be
    // populated to the time setBuffer was called, and mIsAutoTimestamp will be set to true.
    //
    // Desired present times that are more than 1 second in the future may be ignored.
    // When a desired present time has already passed, the transaction will be presented as soon
    // as possible.
    //
    // Transactions from the same process are presented in the same order that they are applied.
    // The desired present time does not affect this ordering.
    int64_t mDesiredPresentTime = 0;
    bool mIsAutoTimestamp = true;

    SimpleTransactionState() = default;
    SimpleTransactionState(uint64_t id, uint32_t flags, int64_t desiredPresentTime,
                           bool isAutoTimestamp)
          : mId(id),
            mFlags(flags),
            mDesiredPresentTime(desiredPresentTime),
            mIsAutoTimestamp(isAutoTimestamp) {}
    bool operator==(const SimpleTransactionState& rhs) const = default;
    bool operator!=(const SimpleTransactionState& rhs) const = default;

    status_t writeToParcel(Parcel* parcel) const;
    status_t readFromParcel(const Parcel* parcel);
    void merge(const SimpleTransactionState& other);
    void clear();
};

} // namespace android
Loading