1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ROSEN_RENDER_SERVICE_BASE_RS_TRANSACTION_DATA_H 17 #define ROSEN_RENDER_SERVICE_BASE_RS_TRANSACTION_DATA_H 18 19 #include <memory> 20 #include <mutex> 21 #include <vector> 22 23 #include "command/rs_command.h" 24 #include "command/rs_node_showing_command.h" 25 #include "common/rs_macros.h" 26 #include "pipeline/rs_context.h" 27 28 #include <parcel.h> 29 30 namespace OHOS { 31 namespace Rosen { 32 class RSB_EXPORT RSTransactionData : public Parcelable { 33 public: 34 RSTransactionData() = default; 35 RSTransactionData(const RSTransactionData&) = delete; 36 RSTransactionData& operator=(const RSTransactionData&) = delete; RSTransactionData(RSTransactionData && other)37 RSTransactionData(RSTransactionData&& other) 38 : payload_(std::move(other.payload_)), timestamp_(std::move(other.timestamp_)), 39 abilityName_(std::move(other.abilityName_)), pid_(other.pid_), index_(other.index_) 40 {} 41 ~RSTransactionData() noexcept override; 42 43 [[nodiscard]] static RSTransactionData* Unmarshalling(Parcel& parcel); 44 bool Marshalling(Parcel& parcel) const override; 45 GetCommandCount()46 unsigned long GetCommandCount() const 47 { 48 return payload_.size(); 49 } 50 IsEmpty()51 bool IsEmpty() const 52 { 53 return payload_.empty(); 54 } 55 56 void Process(RSContext& context); 57 58 void Clear(); 59 GetTimestamp()60 uint64_t GetTimestamp() const 61 { 62 return timestamp_; 63 } 64 SetTimestamp(const uint64_t timestamp)65 void SetTimestamp(const uint64_t timestamp) 66 { 67 timestamp_ = timestamp; 68 } 69 GetAbilityName()70 std::string GetAbilityName() const 71 { 72 return abilityName_; 73 } 74 SetAbilityName(const std::string & abilityName)75 void SetAbilityName(const std::string& abilityName) 76 { 77 abilityName_ = abilityName; 78 } 79 SetIsCached(bool isCached)80 void SetIsCached(bool isCached) 81 { 82 isCached_ = isCached; 83 } 84 GetIsCached()85 bool GetIsCached() 86 { 87 return isCached_; 88 } 89 SetSendingPid(pid_t pid)90 void SetSendingPid(pid_t pid) 91 { 92 pid_ = pid; 93 } 94 GetSendingPid()95 pid_t GetSendingPid() const 96 { 97 return pid_; 98 } 99 SetIndex(uint64_t index)100 void SetIndex(uint64_t index) 101 { 102 index_ = index; 103 } 104 GetIndex()105 uint64_t GetIndex() const 106 { 107 return index_; 108 } 109 GetMarshallingIndex()110 size_t GetMarshallingIndex() const 111 { 112 return marshallingIndex_; 113 } 114 GetPayload()115 std::vector<std::tuple<NodeId, FollowType, std::unique_ptr<RSCommand>>>& GetPayload() 116 { 117 return payload_; 118 } 119 IsNeedSync()120 bool IsNeedSync() const 121 { 122 return needSync_; 123 } 124 IsNeedCloseSync()125 bool IsNeedCloseSync() const 126 { 127 return needCloseSync_; 128 } 129 MarkNeedSync()130 void MarkNeedSync() 131 { 132 needSync_ = true; 133 } 134 MarkNeedCloseSync()135 void MarkNeedCloseSync() 136 { 137 needCloseSync_ = true; 138 } 139 SetSyncTransactionNum(const int32_t syncTransactionCount)140 void SetSyncTransactionNum(const int32_t syncTransactionCount) 141 { 142 syncTransactionCount_ = syncTransactionCount; 143 } 144 GetSyncTransactionNum()145 int32_t GetSyncTransactionNum() const 146 { 147 return syncTransactionCount_; 148 } 149 SetSyncId(const uint64_t syncId)150 void SetSyncId(const uint64_t syncId) 151 { 152 syncId_ = syncId; 153 } 154 GetSyncId()155 uint64_t GetSyncId() const 156 { 157 return syncId_; 158 } 159 160 private: 161 void AddCommand(std::unique_ptr<RSCommand>& command, NodeId nodeId, FollowType followType); 162 void AddCommand(std::unique_ptr<RSCommand>&& command, NodeId nodeId, FollowType followType); 163 164 bool UnmarshallingCommand(Parcel& parcel); 165 std::vector<std::tuple<NodeId, FollowType, std::unique_ptr<RSCommand>>> payload_ = {}; 166 uint64_t timestamp_ = 0; 167 std::string abilityName_; 168 pid_t pid_ = 0; 169 uint64_t index_ = 0; 170 mutable size_t marshallingIndex_ = 0; 171 bool needSync_ { false }; 172 bool needCloseSync_ { false }; 173 bool isCached_ { false }; 174 int32_t syncTransactionCount_ { 0 }; 175 uint64_t syncId_ { 0 }; 176 mutable std::mutex commandMutex_; 177 178 friend class RSTransactionProxy; 179 friend class RSMessageProcessor; 180 }; 181 using TransactionDataMap = std::unordered_map<pid_t, std::vector<std::unique_ptr<RSTransactionData>>>; 182 } // namespace Rosen 183 } // namespace OHOS 184 185 #endif // ROSEN_RENDER_SERVICE_BASE_RS_TRANSACTION_DATA_H 186