1 /* 2 * Copyright (C) 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <android/gui/FrameTimelineInfo.h> 20 #include <binder/Parcelable.h> 21 #include <gui/LayerState.h> 22 23 namespace android { 24 25 // Class to store all the transaction data and the parcelling logic 26 class TransactionState { 27 public: 28 explicit TransactionState() = default; 29 TransactionState(TransactionState&& other) = default; 30 TransactionState& operator=(TransactionState&& other) = default; 31 status_t writeToParcel(Parcel* parcel) const; 32 status_t readFromParcel(const Parcel* parcel); 33 layer_state_t* getLayerState(const sp<SurfaceControl>& sc); 34 DisplayState& getDisplayState(const sp<IBinder>& token); 35 36 // Returns the current id of the transaction. 37 // The id is updated every time the transaction is applied. getId()38 uint64_t getId() const { return mId; } getMergedTransactionIds()39 std::vector<uint64_t> getMergedTransactionIds() const { return mMergedTransactionIds; } enableDebugLogCallPoints()40 void enableDebugLogCallPoints() { mLogCallPoints = true; } 41 void merge(TransactionState&& other, 42 const std::function<void(layer_state_t&)>& onBufferOverwrite); 43 44 // copied from FrameTimelineInfo::merge() 45 void mergeFrameTimelineInfo(const FrameTimelineInfo& other); 46 void clear(); 47 bool operator==(const TransactionState& rhs) const = default; 48 bool operator!=(const TransactionState& rhs) const = default; 49 50 uint64_t mId = 0; 51 std::vector<uint64_t> mMergedTransactionIds; 52 uint32_t mFlags = 0; 53 // The vsync id provided by Choreographer.getVsyncId and the input event id 54 gui::FrameTimelineInfo mFrameTimelineInfo; 55 // mDesiredPresentTime is the time in nanoseconds that the client would like the transaction 56 // to be presented. When it is not possible to present at exactly that time, it will be 57 // presented after the time has passed. 58 // 59 // If the client didn't pass a desired presentation time, mDesiredPresentTime will be 60 // populated to the time setBuffer was called, and mIsAutoTimestamp will be set to true. 61 // 62 // Desired present times that are more than 1 second in the future may be ignored. 63 // When a desired present time has already passed, the transaction will be presented as soon 64 // as possible. 65 // 66 // Transactions from the same process are presented in the same order that they are applied. 67 // The desired present time does not affect this ordering. 68 int64_t mDesiredPresentTime = 0; 69 bool mIsAutoTimestamp = true; 70 // If not null, transactions will be queued up using this token otherwise a common token 71 // per process will be used. 72 sp<IBinder> mApplyToken; 73 // Indicates that the Transaction may contain buffers that should be cached. The reason this 74 // is only a guess is that buffers can be removed before cache is called. This is only a 75 // hint that at some point a buffer was added to this transaction before apply was called. 76 bool mMayContainBuffer = false; 77 // Prints debug logs when enabled. 78 bool mLogCallPoints = false; 79 80 std::vector<DisplayState> mDisplayStates; 81 std::vector<ComposerState> mComposerStates; 82 InputWindowCommands mInputWindowCommands; 83 std::vector<client_cache_t> mUncacheBuffers; 84 // Note: mHasListenerCallbacks can be true even if mListenerCallbacks is 85 // empty. 86 bool mHasListenerCallbacks = false; 87 std::vector<ListenerCallbacks> mListenerCallbacks; 88 89 private: 90 explicit TransactionState(TransactionState const& other) = default; 91 friend class TransactionApplicationTest; 92 friend class SurfaceComposerClient; 93 // We keep track of the last MAX_MERGE_HISTORY_LENGTH merged transaction ids. 94 // Ordered most recently merged to least recently merged. 95 static constexpr size_t MAX_MERGE_HISTORY_LENGTH = 10u; 96 }; 97 98 }; // namespace android 99