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