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 RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H
17 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H
18 
19 #include <event_handler.h>
20 #include <message_parcel.h>
21 #include <mutex>
22 #include <parcel.h>
23 #include <refbase.h>
24 
25 #include "common/rs_common_def.h"
26 #include "common/rs_macros.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 
31 class RSC_EXPORT RSTransaction : public Parcelable {
32 public:
33     RSTransaction() = default;
34     RSTransaction(const RSTransaction&) = delete;
35     RSTransaction(const RSTransaction&&) = delete;
36     RSTransaction& operator=(const RSTransaction&) = delete;
37     RSTransaction& operator=(const RSTransaction&&) = delete;
38     ~RSTransaction() override = default;
39 
40     static RSTransaction* Unmarshalling(Parcel& parcel);
41     bool Marshalling(Parcel& parcel) const override;
42 
43     static void FlushImplicitTransaction();
44     void OpenSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
45     void CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
46 
47     void Begin();
48     void Commit();
49 
SetDuration(int32_t duration)50     void SetDuration(int32_t duration) { duration_ = duration; }
GetDuration()51     int32_t GetDuration() const { return duration_; }
52 
SetParentPid(int32_t parentPid)53     void SetParentPid(int32_t parentPid)
54     {
55         parentPid_ = parentPid;
56     }
57 
GetParentPid()58     int32_t GetParentPid() const
59     {
60         return parentPid_;
61     }
62 
IsOpenSyncTransaction()63     bool IsOpenSyncTransaction() const
64     {
65         return isOpenSyncTransaction_;
66     }
67 
GetSyncId()68     uint64_t GetSyncId() const
69     {
70         return syncId_;
71     }
72 
73 private:
74     uint64_t GenerateSyncId();
75     void ResetSyncTransactionInfo();
76     bool UnmarshallingParam(Parcel& parcel);
77 
78     uint64_t syncId_ { 0 };
79     std::mutex mutex_;
80     mutable int32_t transactionCount_ { 0 };
81     int32_t duration_ = 0;
82     int32_t parentPid_ { -1 };
83     bool isOpenSyncTransaction_ = false;
84 
85     friend class RSSyncTransactionController;
86 };
87 
88 } // namespace Rosen
89 } // namespace OHOS
90 
91 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H
92