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 #ifndef RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SYNC_TRANSACTION_CONTROLLER_H 17 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SYNC_TRANSACTION_CONTROLLER_H 18 19 #include <mutex> 20 #include <vector> 21 22 #include "common/rs_macros.h" 23 #include "event_handler.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 class RSTransaction; 28 29 class RSC_EXPORT RSSyncTransactionController { 30 public: 31 static RSSyncTransactionController* GetInstance(); 32 33 void OpenSyncTransaction(); 34 GetRSTransaction()35 std::shared_ptr<RSTransaction> GetRSTransaction() 36 { 37 if (!needCloseSync_) { 38 return nullptr; 39 } 40 return rsTransaction_; 41 } 42 43 private: 44 RSSyncTransactionController(); 45 virtual ~RSSyncTransactionController(); 46 47 static void Init(); 48 static void Destroy(); 49 50 RSSyncTransactionController(const RSSyncTransactionController&) = delete; 51 RSSyncTransactionController(const RSSyncTransactionController&&) = delete; 52 RSSyncTransactionController& operator=(const RSSyncTransactionController&) = delete; 53 RSSyncTransactionController& operator=(const RSSyncTransactionController&&) = delete; 54 55 void CloseSyncTransaction(); 56 void CreateTransactionFinished(); 57 void StartCreateTransaction(); 58 59 int32_t processCount_ { 0 }; 60 int32_t transactionCount_ { 0 }; 61 std::mutex mutex_; 62 bool needCloseSync_ { false }; 63 std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr; 64 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 65 std::shared_ptr<RSTransaction> rsTransaction_; 66 static std::once_flag flag_; 67 static RSSyncTransactionController* instance_; 68 }; 69 } // namespace Rosen 70 } // namespace OHOS 71 72 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SYNC_TRANSACTION_CONTROLLER_H 73