• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SetSendingTid(pid_t tid)105     void SetSendingTid(pid_t tid)
106     {
107         tid_ = tid;
108     }
109 
GetSendingTid()110     pid_t GetSendingTid() const
111     {
112         return tid_;
113     }
114 
SetIndex(uint64_t index)115     void SetIndex(uint64_t index)
116     {
117         index_ = index;
118     }
119 
GetIndex()120     uint64_t GetIndex() const
121     {
122         return index_;
123     }
124 
GetMarshallingIndex()125     size_t GetMarshallingIndex() const
126     {
127         return marshallingIndex_;
128     }
129 
GetPayload()130     std::vector<std::tuple<NodeId, FollowType, std::unique_ptr<RSCommand>>>& GetPayload()
131     {
132         return payload_;
133     }
134 
IsNeedSync()135     bool IsNeedSync() const
136     {
137         return needSync_;
138     }
139 
IsNeedCloseSync()140     bool IsNeedCloseSync() const
141     {
142         return needCloseSync_;
143     }
144 
MarkNeedSync()145     void MarkNeedSync()
146     {
147         needSync_ = true;
148     }
149 
MarkNeedCloseSync()150     void MarkNeedCloseSync()
151     {
152         needCloseSync_ = true;
153     }
154 
SetSyncTransactionNum(const int32_t syncTransactionCount)155     void SetSyncTransactionNum(const int32_t syncTransactionCount)
156     {
157         syncTransactionCount_ = syncTransactionCount;
158     }
159 
GetSyncTransactionNum()160     int32_t GetSyncTransactionNum() const
161     {
162         return syncTransactionCount_;
163     }
164 
SetSyncId(const uint64_t syncId)165     void SetSyncId(const uint64_t syncId)
166     {
167         syncId_ = syncId;
168     }
169 
GetSyncId()170     uint64_t GetSyncId() const
171     {
172         return syncId_;
173     }
174 
SetParentPid(const int32_t parentPid)175     void SetParentPid(const int32_t parentPid)
176     {
177         parentPid_ = parentPid;
178     }
179 
GetParentPid()180     int32_t GetParentPid() const
181     {
182         return parentPid_;
183     }
184 
185     bool IsCallingPidValid(pid_t callingPid, const RSRenderNodeMap& nodeMap) const;
186     void DumpCommand(std::string& dumpString);
187 
SetDVSyncUpdate(bool dvsyncTimeUpdate)188     void SetDVSyncUpdate(bool dvsyncTimeUpdate)
189     {
190         dvsyncTimeUpdate_ = dvsyncTimeUpdate;
191     }
192 
GetDVSyncUpdate()193     bool GetDVSyncUpdate() const
194     {
195         return dvsyncTimeUpdate_;
196     }
197 
SetDVSyncTime(uint64_t dvsyncTime)198     void SetDVSyncTime(uint64_t dvsyncTime)
199     {
200         dvsyncTime_ = dvsyncTime;
201     }
202 
GetDVSyncTime()203     uint64_t GetDVSyncTime() const
204     {
205         return dvsyncTime_;
206     }
207 
208 private:
209     void AddCommand(std::unique_ptr<RSCommand>& command, NodeId nodeId, FollowType followType);
210     void AddCommand(std::unique_ptr<RSCommand>&& command, NodeId nodeId, FollowType followType);
211     void MoveCommandByNodeId(std::unique_ptr<RSTransactionData>& transactionData, NodeId nodeId);
212 
213     bool UnmarshallingCommand(Parcel& parcel);
214 
215     std::string PrintCommandMapDesc(
216         const std::unordered_map<NodeId, std::set<std::pair<uint16_t, uint16_t>>>& commandTypeMap) const;
217 
218     std::vector<std::tuple<NodeId, FollowType, std::unique_ptr<RSCommand>>> payload_ = {};
219     uint64_t timestamp_ = 0;
220     uint64_t token_ = 0;
221     std::string abilityName_;
222     pid_t pid_ = 0;
223     // only use for hybrid render client, no need to marshalling
224     pid_t tid_ = 0;
225     uint64_t index_ = 0;
226     mutable size_t marshallingIndex_ = 0;
227     bool needSync_ { false };
228     bool needCloseSync_ { false };
229     bool isCached_ { false };
230     int32_t syncTransactionCount_ { 0 };
231     int32_t parentPid_ { -1 };
232     uint64_t syncId_ { 0 };
233     uint32_t parcelNumber_ { 0 };
234     static std::function<void(uint64_t, int, int)> alarmLogFunc;
235     mutable std::mutex commandMutex_;
236     std::vector<uint32_t> commandOffsets_;
237     bool dvsyncTimeUpdate_ = false;
238     uint64_t dvsyncTime_ = 0;
239 
240     friend class RSTransactionProxy;
241     friend class RSTransactionHandler;
242     friend class RSMessageProcessor;
243     friend class RSMainThread;
244 };
245 using TransactionDataMap = std::unordered_map<pid_t, std::vector<std::unique_ptr<RSTransactionData>>>;
246 } // namespace Rosen
247 } // namespace OHOS
248 
249 #endif // ROSEN_RENDER_SERVICE_BASE_RS_TRANSACTION_DATA_H
250