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 #include "rs_sync_transaction_handler.h" 17 18 #include "rs_transaction.h" 19 20 #include "platform/common/rs_log.h" 21 #include "platform/common/rs_system_properties.h" 22 23 namespace OHOS { 24 namespace Rosen { ~RSSyncTransactionHandler()25RSSyncTransactionHandler::~RSSyncTransactionHandler() {} 26 SetTransactionHandler(std::shared_ptr<RSTransactionHandler> rsTransactionHandler)27void RSSyncTransactionHandler::SetTransactionHandler(std::shared_ptr<RSTransactionHandler> rsTransactionHandler) 28 { 29 if (!rsTransaction_) { 30 rsTransaction_ = std::make_shared<RSTransaction>(); 31 } 32 rsTransaction_->SetTransactionHandler(rsTransactionHandler); 33 } 34 GetRSTransaction()35std::shared_ptr<RSTransaction> RSSyncTransactionHandler::GetRSTransaction() 36 { 37 if (!needCloseSync_) { 38 return nullptr; 39 } 40 return rsTransaction_; 41 } 42 OpenSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler)43void RSSyncTransactionHandler::OpenSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler) 44 { 45 if (!RSSystemProperties::GetSyncTransactionEnabled()) { 46 return; 47 } 48 49 { 50 std::unique_lock<std::mutex> lock(mutex_); 51 if (needCloseSync_) { 52 return; 53 } 54 needCloseSync_ = true; 55 } 56 ROSEN_LOGD("RS sync transaction controller OpenSyncTransaction"); 57 if (rsTransaction_) { 58 rsTransaction_->OpenSyncTransaction(handler); 59 } 60 } 61 CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler)62void RSSyncTransactionHandler::CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler) 63 { 64 if (!needCloseSync_) { 65 return; 66 } 67 68 ROSEN_LOGD("RS sync transaction controller CloseSyncTransaction"); 69 if (rsTransaction_) { 70 rsTransaction_->CloseSyncTransaction(handler); 71 } 72 { 73 std::unique_lock<std::mutex> lock(mutex_); 74 needCloseSync_ = false; 75 } 76 } 77 } // namespace Rosen 78 } // namespace OHOS 79