• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_sync_transaction_handle.h
18  * @brief This file is used to control the execution of synchronous transctions.
19  */
20 
21 #ifndef RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SYNC_TRANSACTION_HANDLER_H
22 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SYNC_TRANSACTION_HANDLER_H
23 
24 #include <mutex>
25 #include <vector>
26 
27 #include "event_handler.h"
28 
29 #include "common/rs_macros.h"
30 
31 namespace OHOS {
32 namespace Rosen {
33 class RSTransaction;
34 class RSTransactionHandler;
35 
36 class RSC_EXPORT RSSyncTransactionHandler {
37 public:
38     RSSyncTransactionHandler() = default;
39     virtual ~RSSyncTransactionHandler();
40     /**
41      * @brief Open a synchronous transaction.
42      * @details This function is used to open a synchronous transaction, which will block other operation until
43      * transaction is complete.
44      * @param handler Event handler, used to handle events related to the transaction, if it is empty
45      * then no events will be processed.
46      */
47     void OpenSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
48     /**
49      * @brief Close a synchronous transaction.
50      * @details This function is used to close a synchronous transaction, and commit it to the server.
51      * @param handler An event handler for the fallback mechanism of synchronous transaction, if it is empty,
52      * then no fallback for synchronous transactions will be performed.
53      */
54     void CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
55 
56     std::shared_ptr<RSTransaction> GetRSTransaction();
57 
58 private:
59     RSSyncTransactionHandler(const RSSyncTransactionHandler&) = delete;
60     RSSyncTransactionHandler(const RSSyncTransactionHandler&&) = delete;
61     RSSyncTransactionHandler& operator=(const RSSyncTransactionHandler&) = delete;
62     RSSyncTransactionHandler& operator=(const RSSyncTransactionHandler&&) = delete;
63 
64     void SetTransactionHandler(std::shared_ptr<RSTransactionHandler> rsTransactionHandler);
65 
66     std::mutex mutex_;
67     bool needCloseSync_ { false };
68     std::shared_ptr<RSTransaction> rsTransaction_;
69 
70     friend class RSUIContext;
71 };
72 } // namespace Rosen
73 } // namespace OHOS
74 
75 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SYNC_TRANSACTION_HANDLER_H