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() override; 42 43 [[nodiscard]] static RSTransactionData* Unmarshalling(Parcel& parcel); 44 bool Marshalling(Parcel& parcel) const override; 45 void AlarmRsNodeLog() const; 46 GetCommandCount()47 unsigned long GetCommandCount() const 48 { 49 return payload_.size(); 50 } 51 IsEmpty()52 bool IsEmpty() const 53 { 54 return payload_.empty(); 55 } 56 57 void Process(RSContext& context); 58 void ProcessBySingleFrameComposer(RSContext& context); 59 static void AddAlarmLog(std::function<void(uint64_t, int, int)> func); 60 61 void Clear(); 62 GetTimestamp()63 uint64_t GetTimestamp() const 64 { 65 return timestamp_; 66 } 67 SetTimestamp(const uint64_t timestamp)68 void SetTimestamp(const uint64_t timestamp) 69 { 70 timestamp_ = timestamp; 71 } 72 73 void ProfilerPushOffsets(Parcel& parcel, uint32_t parcelNumber); 74 GetAbilityName()75 std::string GetAbilityName() const 76 { 77 return abilityName_; 78 } 79 SetAbilityName(const std::string & abilityName)80 void SetAbilityName(const std::string& abilityName) 81 { 82 abilityName_ = abilityName; 83 } 84 SetIsCached(bool isCached)85 void SetIsCached(bool isCached) 86 { 87 isCached_ = isCached; 88 } 89 GetIsCached()90 bool GetIsCached() 91 { 92 return isCached_; 93 } 94 SetSendingPid(pid_t pid)95 void SetSendingPid(pid_t pid) 96 { 97 pid_ = pid; 98 } 99 GetSendingPid()100 pid_t GetSendingPid() const 101 { 102 return pid_; 103 } 104 SetIndex(uint64_t index)105 void SetIndex(uint64_t index) 106 { 107 index_ = index; 108 } 109 GetIndex()110 uint64_t GetIndex() const 111 { 112 return index_; 113 } 114 GetMarshallingIndex()115 size_t GetMarshallingIndex() const 116 { 117 return marshallingIndex_; 118 } 119 GetPayload()120 std::vector<std::tuple<NodeId, FollowType, std::unique_ptr<RSCommand>>>& GetPayload() 121 { 122 return payload_; 123 } 124 IsNeedSync()125 bool IsNeedSync() const 126 { 127 return needSync_; 128 } 129 IsNeedCloseSync()130 bool IsNeedCloseSync() const 131 { 132 return needCloseSync_; 133 } 134 MarkNeedSync()135 void MarkNeedSync() 136 { 137 needSync_ = true; 138 } 139 MarkNeedCloseSync()140 void MarkNeedCloseSync() 141 { 142 needCloseSync_ = true; 143 } 144 SetSyncTransactionNum(const int32_t syncTransactionCount)145 void SetSyncTransactionNum(const int32_t syncTransactionCount) 146 { 147 syncTransactionCount_ = syncTransactionCount; 148 } 149 GetSyncTransactionNum()150 int32_t GetSyncTransactionNum() const 151 { 152 return syncTransactionCount_; 153 } 154 SetSyncId(const uint64_t syncId)155 void SetSyncId(const uint64_t syncId) 156 { 157 syncId_ = syncId; 158 } 159 GetSyncId()160 uint64_t GetSyncId() const 161 { 162 return syncId_; 163 } 164 SetParentPid(const int32_t parentPid)165 void SetParentPid(const int32_t parentPid) 166 { 167 parentPid_ = parentPid; 168 } 169 GetParentPid()170 int32_t GetParentPid() const 171 { 172 return parentPid_; 173 } 174 175 bool IsCallingPidValid(pid_t callingPid, const RSRenderNodeMap& nodeMap) const; 176 void DumpCommand(std::string& dumpString); 177 178 private: 179 void AddCommand(std::unique_ptr<RSCommand>& command, NodeId nodeId, FollowType followType); 180 void AddCommand(std::unique_ptr<RSCommand>&& command, NodeId nodeId, FollowType followType); 181 182 bool UnmarshallingCommand(Parcel& parcel); 183 184 std::string PrintCommandMapDesc( 185 const std::unordered_map<NodeId, std::set<std::pair<uint16_t, uint16_t>>>& commandTypeMap) const; 186 187 std::vector<std::tuple<NodeId, FollowType, std::unique_ptr<RSCommand>>> payload_ = {}; 188 uint64_t timestamp_ = 0; 189 std::string abilityName_; 190 pid_t pid_ = 0; 191 uint64_t index_ = 0; 192 mutable size_t marshallingIndex_ = 0; 193 bool needSync_ { false }; 194 bool needCloseSync_ { false }; 195 bool isCached_ { false }; 196 int32_t syncTransactionCount_ { 0 }; 197 int32_t parentPid_ { -1 }; 198 uint64_t syncId_ { 0 }; 199 uint32_t parcelNumber_ { 0 }; 200 static std::function<void(uint64_t, int, int)> alarmLogFunc; 201 mutable std::mutex commandMutex_; 202 std::vector<uint32_t> commandOffsets_; 203 204 friend class RSTransactionProxy; 205 friend class RSTransactionHandler; 206 friend class RSMessageProcessor; 207 friend class RSMainThread; 208 }; 209 using TransactionDataMap = std::unordered_map<pid_t, std::vector<std::unique_ptr<RSTransactionData>>>; 210 } // namespace Rosen 211 } // namespace OHOS 212 213 #endif // ROSEN_RENDER_SERVICE_BASE_RS_TRANSACTION_DATA_H 214