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

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

Merge "Add SimpleTransactionState and TransactionListenerCallbacks." into main

parents 13234703 880e4c90
Loading
Loading
Loading
Loading
+23 −59
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
#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>
#include <sys/types.h>
@@ -50,22 +52,17 @@ using gui::IWindowInfosListener;
using gui::LayerCaptureArgs;
using ui::ColorMode;

class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
{
class BpSurfaceComposer : public BpInterface<ISurfaceComposer> {
public:
    explicit BpSurfaceComposer(const sp<IBinder>& impl)
        : BpInterface<ISurfaceComposer>(impl)
    {
    }
    explicit BpSurfaceComposer(const sp<IBinder>& impl) : BpInterface<ISurfaceComposer>(impl) {}

    virtual ~BpSurfaceComposer();

    status_t setTransactionState(
            const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state,
            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 SimpleTransactionState simpleState, const FrameTimelineInfo& frameTimelineInfo,
            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 {
        Parcel data, reply;
@@ -83,25 +80,15 @@ public:
            SAFE_PARCEL(d.write, data);
        }

        SAFE_PARCEL(data.writeUint32, flags);
        SAFE_PARCEL(simpleState.writeToParcel, &data);
        SAFE_PARCEL(data.writeStrongBinder, applyToken);
        SAFE_PARCEL(commands.write, data);
        SAFE_PARCEL(data.writeInt64, desiredPresentTime);
        SAFE_PARCEL(data.writeBool, isAutoTimestamp);
        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(data.writeBool, hasListenerCallbacks);

        SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
        for (const auto& [listener, callbackIds] : listenerCallbacks) {
            SAFE_PARCEL(data.writeStrongBinder, listener);
            SAFE_PARCEL(data.writeParcelableVector, callbackIds);
        }

        SAFE_PARCEL(data.writeUint64, transactionId);
        SAFE_PARCEL(listenerCallbacks.writeToParcel, &data);

        SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(mergedTransactionIds.size()));
        for (auto mergedTransactionId : mergedTransactionIds) {
@@ -113,12 +100,11 @@ public:
            e.writeToParcel(&data);
        }

        if (flags & ISurfaceComposer::eOneWay) {
            return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
                    data, &reply, IBinder::FLAG_ONEWAY);
        if (simpleState.mFlags & ISurfaceComposer::eOneWay) {
            return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply,
                                      IBinder::FLAG_ONEWAY);
        } else {
            return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
                    data, &reply);
            return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply);
        }
    }
};
@@ -131,9 +117,8 @@ IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");

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

status_t BnSurfaceComposer::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
status_t BnSurfaceComposer::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
                                       uint32_t flags) {
    switch (code) {
        case SET_TRANSACTION_STATE: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
@@ -160,17 +145,11 @@ status_t BnSurfaceComposer::onTransact(
                displays.add(d);
            }

            uint32_t stateFlags = 0;
            SAFE_PARCEL(data.readUint32, &stateFlags);
            SimpleTransactionState simpleState;
            SAFE_PARCEL(simpleState.readFromParcel, &data);

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

            int64_t desiredPresentTime = 0;
            bool isAutoTimestamp = true;
            SAFE_PARCEL(data.readInt64, &desiredPresentTime);
            SAFE_PARCEL(data.readBool, &isAutoTimestamp);

            SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
            std::vector<client_cache_t> uncacheBuffers(count);
@@ -181,21 +160,8 @@ status_t BnSurfaceComposer::onTransact(
                SAFE_PARCEL(data.readUint64, &uncacheBuffers[i].id);
            }

            bool hasListenerCallbacks = false;
            SAFE_PARCEL(data.readBool, &hasListenerCallbacks);

            std::vector<ListenerCallbacks> listenerCallbacks;
            int32_t listenersSize = 0;
            SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
            for (int32_t i = 0; i < listenersSize; i++) {
                SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
                std::vector<CallbackId> callbackIds;
                SAFE_PARCEL(data.readParcelableVector, &callbackIds);
                listenerCallbacks.emplace_back(tmpBinder, callbackIds);
            }

            uint64_t transactionId = -1;
            SAFE_PARCEL(data.readUint64, &transactionId);
            TransactionListenerCallbacks listenerCallbacks;
            SAFE_PARCEL(listenerCallbacks.readFromParcel, &data);

            SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
            std::vector<uint64_t> mergedTransactions(count);
@@ -213,10 +179,8 @@ status_t BnSurfaceComposer::onTransact(
                earlyWakeupInfos.push_back(std::move(e));
            }

            return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
                                       std::move(inputWindowCommands), desiredPresentTime,
                                       isAutoTimestamp, uncacheBuffers, hasListenerCallbacks,
                                       listenerCallbacks, transactionId, mergedTransactions,
            return setTransactionState(simpleState, frameTimelineInfo, state, displays, applyToken,
                                       uncacheBuffers, listenerCallbacks, mergedTransactions,
                                       earlyWakeupInfos);
        }
        case GET_SCHEDULING_POLICY: {
+105 −121

File changed.

Preview size limit exceeded, changes collapsed.

+68 −39
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#define LOG_TAG "TransactionState"
#include <gui/LayerState.h>
#include <gui/SimpleTransactionState.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/TransactionState.h>
#include <private/gui/ParcelUtils.h>
@@ -23,11 +24,71 @@

namespace android {

status_t TransactionState::writeToParcel(Parcel* parcel) const {
void SimpleTransactionState::clear() {
    *this = SimpleTransactionState();
}

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 {
    SAFE_PARCEL(parcel->writeUint64, mId);
    SAFE_PARCEL(parcel->writeUint32, mFlags);
    SAFE_PARCEL(parcel->writeInt64, mDesiredPresentTime);
    SAFE_PARCEL(parcel->writeBool, mIsAutoTimestamp);
    SAFE_PARCEL(mInputWindowCommands.write, *parcel);

    return NO_ERROR;
}

status_t SimpleTransactionState::readFromParcel(const Parcel* parcel) {
    SAFE_PARCEL(parcel->readUint64, &mId);
    SAFE_PARCEL(parcel->readUint32, &mFlags);
    SAFE_PARCEL(parcel->readInt64, &mDesiredPresentTime);
    SAFE_PARCEL(parcel->readBool, &mIsAutoTimestamp);
    SAFE_PARCEL(mInputWindowCommands.read, *parcel);

    return NO_ERROR;
}

void TransactionListenerCallbacks::clear() {
    *this = TransactionListenerCallbacks();
}

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] : mFlattenedListenerCallbacks) {
        SAFE_PARCEL(parcel->writeStrongBinder, listener);
        SAFE_PARCEL(parcel->writeParcelableVector, callbackIds);
    }

    return NO_ERROR;
}

status_t TransactionListenerCallbacks::readFromParcel(const Parcel* parcel) {
    SAFE_PARCEL(parcel->readBool, &mHasListenerCallbacks);
    uint32_t count;
    SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize());
    mFlattenedListenerCallbacks.clear();
    mFlattenedListenerCallbacks.reserve(count);
    for (uint32_t i = 0; i < count; i++) {
        sp<IBinder> tmpBinder;
        SAFE_PARCEL(parcel->readStrongBinder, &tmpBinder);
        std::vector<CallbackId> callbackIds;
        SAFE_PARCEL(parcel->readParcelableVector, &callbackIds);
        mFlattenedListenerCallbacks.emplace_back(tmpBinder, callbackIds);
    }

    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(parcel->writeStrongBinder, mApplyToken);
    SAFE_PARCEL(parcel->writeBool, mMayContainBuffer);
@@ -42,7 +103,6 @@ status_t TransactionState::writeToParcel(Parcel* parcel) const {
        composerState.write(*parcel);
    }

    mInputWindowCommands.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());
@@ -54,21 +114,12 @@ status_t TransactionState::writeToParcel(Parcel* parcel) const {
        SAFE_PARCEL(parcel->writeUint64, mergedTransactionId);
    }

    SAFE_PARCEL(parcel->writeBool, mHasListenerCallbacks);
    SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mListenerCallbacks.size()));
    for (const auto& [listener, callbackIds] : mListenerCallbacks) {
        SAFE_PARCEL(parcel->writeStrongBinder, listener);
        SAFE_PARCEL(parcel->writeParcelableVector, callbackIds);
    }

    return NO_ERROR;
}

status_t TransactionState::readFromParcel(const Parcel* parcel) {
    SAFE_PARCEL(parcel->readUint64, &mId);
    SAFE_PARCEL(parcel->readUint32, &mFlags);
    SAFE_PARCEL(parcel->readInt64, &mDesiredPresentTime);
    SAFE_PARCEL(parcel->readBool, &mIsAutoTimestamp);
    SAFE_PARCEL(mSimpleState.readFromParcel, parcel);
    SAFE_PARCEL(mCallbacks.readFromParcel, parcel);
    SAFE_PARCEL(parcel->readParcelable, &mFrameTimelineInfo);
    SAFE_PARCEL(parcel->readNullableStrongBinder, &mApplyToken);
    SAFE_PARCEL(parcel->readBool, &mMayContainBuffer);
@@ -97,10 +148,6 @@ status_t TransactionState::readFromParcel(const Parcel* parcel) {
        mComposerStates.emplace_back(std::move(composerState));
    }

    if (status_t status = mInputWindowCommands.read(*parcel) != NO_ERROR) {
        return status;
    }

    SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize())
    mUncacheBuffers.clear();
    mUncacheBuffers.reserve(count);
@@ -120,23 +167,12 @@ status_t TransactionState::readFromParcel(const Parcel* parcel) {
        SAFE_PARCEL(parcel->readUint64, &mMergedTransactionIds[i]);
    }

    SAFE_PARCEL(parcel->readBool, &mHasListenerCallbacks);
    SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize());
    mListenerCallbacks.clear();
    mListenerCallbacks.reserve(count);
    for (uint32_t i = 0; i < count; i++) {
        sp<IBinder> tmpBinder;
        SAFE_PARCEL(parcel->readStrongBinder, &tmpBinder);
        std::vector<CallbackId> callbackIds;
        SAFE_PARCEL(parcel->readParcelableVector, &callbackIds);
        mListenerCallbacks.emplace_back(tmpBinder, callbackIds);
    }

    return NO_ERROR;
}

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

    for (auto const& otherState : other.mComposerStates) {
        if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(),
@@ -185,9 +221,6 @@ void TransactionState::merge(TransactionState&& other,
        mUncacheBuffers.push_back(cacheId);
    }

    mInputWindowCommands.merge(other.mInputWindowCommands);
    // TODO(b/385156191) Consider merging desired present time.
    mFlags |= other.mFlags;
    mMayContainBuffer |= other.mMayContainBuffer;
    mLogCallPoints |= other.mLogCallPoints;

@@ -211,18 +244,14 @@ void TransactionState::mergeFrameTimelineInfo(const FrameTimelineInfo& other) {
}

void TransactionState::clear() {
    mSimpleState.clear();
    mCallbacks.clear();
    mComposerStates.clear();
    mDisplayStates.clear();
    mListenerCallbacks.clear();
    mHasListenerCallbacks = false;
    mInputWindowCommands.clear();
    mUncacheBuffers.clear();
    mDesiredPresentTime = 0;
    mIsAutoTimestamp = true;
    mApplyToken = nullptr;
    mFrameTimelineInfo = {};
    mMergedTransactionIds.clear();
    mFlags = 0;
    mMayContainBuffer = false;
    mLogCallPoints = false;
}
+7 −6
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ struct DisplayState;
struct InputWindowCommands;
class HdrCapabilities;
class Rect;
struct SimpleTransactionState;
struct TransactionListenerCallbacks;

using gui::FrameTimelineInfo;
using gui::IDisplayEventConnection;
@@ -107,12 +109,11 @@ public:

    /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */
    virtual status_t setTransactionState(
            const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state,
            Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken,
            InputWindowCommands inputWindowCommands, int64_t desiredPresentTime,
            bool isAutoTimestamp, const std::vector<client_cache_t>& uncacheBuffer,
            bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks,
            uint64_t transactionId, const std::vector<uint64_t>& mergedTransactionIds,
            SimpleTransactionState simpleState, const FrameTimelineInfo& frameTimelineInfo,
            Vector<ComposerState>& state, Vector<DisplayState>& displays,
            const sp<IBinder>& applyToken, const std::vector<client_cache_t>& uncacheBuffer,
            const TransactionListenerCallbacks& listenerCallbacks,
            const std::vector<uint64_t>& mergedTransactionIds,
            const std::vector<gui::EarlyWakeupInfo>& earlyWakeupInfos) = 0;
};

+63 −0
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;
    InputWindowCommands mInputWindowCommands = {};

    SimpleTransactionState() = default;
    SimpleTransactionState(uint64_t id, uint32_t flags, int64_t desiredPresentTime,
                           bool isAutoTimestamp, InputWindowCommands&& inputWindowCommands)
          : mId(id),
            mFlags(flags),
            mDesiredPresentTime(desiredPresentTime),
            mIsAutoTimestamp(isAutoTimestamp),
            mInputWindowCommands(std::move(inputWindowCommands)) {}
    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