• 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 <vector>
21 
22 #include "command/rs_command.h"
23 #include "common/rs_macros.h"
24 #include "pipeline/rs_context.h"
25 
26 #include <parcel.h>
27 
28 namespace OHOS {
29 namespace Rosen {
30 class RSB_EXPORT RSTransactionData : public Parcelable {
31 public:
32     RSTransactionData() = default;
RSTransactionData(RSTransactionData && other)33     RSTransactionData(RSTransactionData&& other)
34         : payload_(std::move(other.payload_)), timestamp_(std::move(other.timestamp_)),
35           abilityName_(std::move(other.abilityName_)), pid_(other.pid_), index_(other.index_)
36     {}
37     ~RSTransactionData() noexcept = default;
38 
39     static RSTransactionData* Unmarshalling(Parcel& parcel);
40     bool Marshalling(Parcel& parcel) const override;
41 
GetCommandCount()42     unsigned long GetCommandCount() const
43     {
44         return payload_.size();
45     }
46 
IsEmpty()47     bool IsEmpty() const
48     {
49         return payload_.empty();
50     }
51 
52     void Process(RSContext& context);
53 
54     void Clear();
55 
GetTimestamp()56     uint64_t GetTimestamp() const
57     {
58         return timestamp_;
59     }
60 
GetAbilityName()61     std::string GetAbilityName() const
62     {
63         return abilityName_;
64     }
65 
SetSendingPid(pid_t pid)66     void SetSendingPid(pid_t pid)
67     {
68         pid_ = pid;
69     }
70 
GetSendingPid()71     pid_t GetSendingPid() const
72     {
73         return pid_;
74     }
75 
SetIndex(uint64_t index)76     void SetIndex(uint64_t index)
77     {
78         index_ = index;
79     }
80 
GetIndex()81     uint64_t GetIndex() const
82     {
83         return index_;
84     }
85 
GetMarshallingIndex()86     size_t GetMarshallingIndex() const
87     {
88         return marshallingIndex_;
89     }
90 
SetUniRender(bool flag)91     void SetUniRender(bool flag)
92     {
93         isUniRender_ = flag;
94     }
95 
GetUniRender()96     bool GetUniRender() const
97     {
98         return isUniRender_;
99     }
100 
GetPayload()101     std::vector<std::tuple<NodeId, FollowType, std::unique_ptr<RSCommand>>>& GetPayload()
102     {
103         return payload_;
104     }
105 
106 private:
107     void AddCommand(std::unique_ptr<RSCommand>& command, NodeId nodeId, FollowType followType);
108     void AddCommand(std::unique_ptr<RSCommand>&& command, NodeId nodeId, FollowType followType);
109 
110     bool UnmarshallingCommand(Parcel& parcel);
111     std::vector<std::tuple<NodeId, FollowType, std::unique_ptr<RSCommand>>> payload_;
112     uint64_t timestamp_ = 0;
113     std::string abilityName_;
114     pid_t pid_ = 0;
115     uint64_t index_ = 0;
116     bool isUniRender_ = false;
117     mutable size_t marshallingIndex_ = 0;
118 
119     friend class RSTransactionProxy;
120     friend class RSMessageProcessor;
121 };
122 using TransactionDataMap = std::unordered_map<pid_t, std::vector<std::unique_ptr<RSTransactionData>>>;
123 } // namespace Rosen
124 } // namespace OHOS
125 
126 #endif // ROSEN_RENDER_SERVICE_BASE_RS_TRANSACTION_DATA_H
127