• 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 /**
17  * @file rs_transaction.h
18  * @brief Process transaction messages.
19  */
20 
21 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H
22 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H
23 
24 #include <event_handler.h>
25 #include <message_parcel.h>
26 #include <mutex>
27 #include <parcel.h>
28 #include <refbase.h>
29 
30 #include "common/rs_common_def.h"
31 #include "common/rs_macros.h"
32 #include "transaction/rs_transaction_handler.h"
33 namespace OHOS {
34 namespace Rosen {
35 
36 class RSC_EXPORT RSTransaction : public Parcelable {
37 public:
38     RSTransaction() = default;
39     RSTransaction(const RSTransaction&) = delete;
40     RSTransaction(const RSTransaction&&) = delete;
41     RSTransaction& operator=(const RSTransaction&) = delete;
42     RSTransaction& operator=(const RSTransaction&&) = delete;
43     ~RSTransaction() override = default;
44 
45     static RSTransaction* Unmarshalling(Parcel& parcel);
46     bool Marshalling(Parcel& parcel) const override;
47 
48     /**
49      * @brief Send messages to RT or RS.
50      * @details This function is used to flush message to RT(in divided render) or RS(in uniRender).
51      */
52     static void FlushImplicitTransaction();   // planing
53     /**
54      * @brief Open a synchronous transaction.
55      * @details This function is used to open a synchronous transaction, which will block other operation until
56      * transaction is compelete.
57      * @param handler Event handler, used to handle events related to the transaction, if it is empty
58      * then no events will be processed.
59      */
60     void OpenSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
61     /**
62      * @brief Close a synchronous transaction.
63      * @details This function is used to close a synchronous transaction, and commit it to the server.
64      * @param handler An event handler for the fallback mechanism of synchronous transaction, if it is empty,
65      * then no fallback for synchronous transactions will be performed.
66      */
67     void CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
68     /**
69      * @brief Start a synchronous transaction.
70      * @details This function is used to close a synchronous transaction, and commit it to the server.
71      */
72     void Begin();
73     /**
74      * @brief Close a synchronous transaction.
75      * @details This function is used to close a synchronous transaction, and commit it to the server.
76      */
77     void Commit();
78 
SetDuration(int32_t duration)79     void SetDuration(int32_t duration) { duration_ = duration; }
GetDuration()80     int32_t GetDuration() const { return duration_; }
81 
SetParentPid(int32_t parentPid)82     void SetParentPid(int32_t parentPid)
83     {
84         parentPid_ = parentPid;
85     }
86 
GetParentPid()87     int32_t GetParentPid() const
88     {
89         return parentPid_;
90     }
91 
IsOpenSyncTransaction()92     bool IsOpenSyncTransaction() const
93     {
94         return isOpenSyncTransaction_;
95     }
96 
GetSyncId()97     uint64_t GetSyncId() const
98     {
99         return syncId_;
100     }
101 
SetTransactionHandler(std::shared_ptr<RSTransactionHandler> rsTransactionHandler)102     void SetTransactionHandler(std::shared_ptr<RSTransactionHandler> rsTransactionHandler)
103     {
104         rsTransactionHandler_ = rsTransactionHandler;
105     }
106 
107 private:
108     uint64_t GenerateSyncId();
109     void ResetSyncTransactionInfo();
110     bool UnmarshallingParam(Parcel& parcel);
111 
112     uint64_t syncId_ { 0 };
113     std::mutex mutex_;
114     mutable int32_t transactionCount_ { 0 };
115     int32_t duration_ = 0;
116     int32_t parentPid_ { -1 };
117     bool isOpenSyncTransaction_ = false;
118     std::shared_ptr<RSTransactionHandler> rsTransactionHandler_ = nullptr;
119 
120     friend class RSSyncTransactionController;
121     friend class RSSyncTransactionHandler;
122 };
123 
124 } // namespace Rosen
125 } // namespace OHOS
126 
127 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H
128