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

Commit a1d84d1a authored by Anton Ivanov's avatar Anton Ivanov Committed by Android (Google) Code Review
Browse files

Merge "Avoid copying Transaction objects unneccessarily." into main

parents 68360b44 c3130a5b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1032,7 +1032,7 @@ void BLASTBufferQueue::mergeWithNextTransaction(SurfaceComposerClient::Transacti
        // Apply the transaction since we have already acquired the desired frame.
        t->setApplyToken(mApplyToken).apply();
    } else {
        mPendingTransactions.emplace_back(frameNumber, *t);
        mPendingTransactions.emplace_back(frameNumber, std::move(*t));
        // Clear the transaction so it can't be applied elsewhere.
        t->clear();
    }
@@ -1050,8 +1050,8 @@ void BLASTBufferQueue::applyPendingTransactions(uint64_t frameNumber) {
void BLASTBufferQueue::mergePendingTransactions(SurfaceComposerClient::Transaction* t,
                                                uint64_t frameNumber) {
    auto mergeTransaction =
            [&t, currentFrameNumber = frameNumber](
                    std::tuple<uint64_t, SurfaceComposerClient::Transaction> pendingTransaction) {
            [t, currentFrameNumber = frameNumber](
                    std::pair<uint64_t, SurfaceComposerClient::Transaction>& pendingTransaction) {
                auto& [targetFrameNumber, transaction] = pendingTransaction;
                if (currentFrameNumber < targetFrameNumber) {
                    return false;
+4 −5
Original line number Diff line number Diff line
@@ -828,11 +828,10 @@ SurfaceComposerClient::Transaction::Transaction() {
    mTransactionCompletedListener = TransactionCompletedListener::getInstance();
}

SurfaceComposerClient::Transaction::Transaction(const Transaction& other) {
    mState = other.mState;
    mListenerCallbacks = other.mListenerCallbacks;
    mTransactionCompletedListener = TransactionCompletedListener::getInstance();
}
SurfaceComposerClient::Transaction::Transaction(Transaction&& other)
      : mTransactionCompletedListener(TransactionCompletedListener::getInstance()),
        mState(std::move(other.mState)),
        mListenerCallbacks(std::move(other.mListenerCallbacks)) {}

void SurfaceComposerClient::Transaction::sanitize(int pid, int uid) {
    uint32_t permissions = LayerStatePermissions::getTransactionPermissions(pid, uid);
+1 −1
Original line number Diff line number Diff line
@@ -284,7 +284,7 @@ private:
    std::function<void(SurfaceComposerClient::Transaction*)> mTransactionReadyCallback
            GUARDED_BY(mMutex);
    SurfaceComposerClient::Transaction* mSyncTransaction GUARDED_BY(mMutex);
    std::vector<std::tuple<uint64_t /* framenumber */, SurfaceComposerClient::Transaction>>
    std::vector<std::pair<uint64_t /* framenumber */, SurfaceComposerClient::Transaction>>
            mPendingTransactions GUARDED_BY(mMutex);

    std::queue<std::pair<uint64_t, FrameTimelineInfo>> mPendingFrameTimelines GUARDED_BY(mMutex);
+6 −5
Original line number Diff line number Diff line
@@ -443,7 +443,7 @@ public:
        virtual ~PresentationCallbackRAII();
    };

    class Transaction : public Parcelable {
    class Transaction {
    private:
        static sp<IBinder> sApplyToken;
        static std::mutex sApplyTokenMutex;
@@ -464,19 +464,20 @@ public:

    protected:
        // Accessed in tests.
        explicit Transaction(Transaction const& other) = default;
        std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash>
                mListenerCallbacks;

    public:
        Transaction();
        virtual ~Transaction() = default;
        Transaction(Transaction const& other);
        Transaction(Transaction&& other);
        Transaction& operator=(Transaction&& other) = default;

        // Factory method that creates a new Transaction instance from the parcel.
        static std::unique_ptr<Transaction> createFromParcel(const Parcel* parcel);

        status_t writeToParcel(Parcel* parcel) const override;
        status_t readFromParcel(const Parcel* parcel) override;
        status_t writeToParcel(Parcel* parcel) const;
        status_t readFromParcel(const Parcel* parcel);

        // Clears the contents of the transaction without applying it.
        void clear();
+5 −1
Original line number Diff line number Diff line
@@ -26,7 +26,8 @@ namespace android {
class TransactionState {
public:
    explicit TransactionState() = default;
    TransactionState(TransactionState const& other) = default;
    TransactionState(TransactionState&& other) = default;
    TransactionState& operator=(TransactionState&& other) = default;
    status_t writeToParcel(Parcel* parcel) const;
    status_t readFromParcel(const Parcel* parcel);
    layer_state_t* getLayerState(const sp<SurfaceControl>& sc);
@@ -86,6 +87,9 @@ public:
    std::vector<ListenerCallbacks> mListenerCallbacks;

private:
    explicit TransactionState(TransactionState const& other) = default;
    friend class TransactionApplicationTest;
    friend class SurfaceComposerClient;
    // We keep track of the last MAX_MERGE_HISTORY_LENGTH merged transaction ids.
    // Ordered most recently merged to least recently merged.
    static constexpr size_t MAX_MERGE_HISTORY_LENGTH = 10u;
Loading