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(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
34     void CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
35 
36     std::shared_ptr<RSTransaction> GetRSTransaction();
37 
38 private:
39     RSSyncTransactionController();
40     virtual ~RSSyncTransactionController();
41 
42     static void Init();
43     static void Destroy();
44 
45     RSSyncTransactionController(const RSSyncTransactionController&) = delete;
46     RSSyncTransactionController(const RSSyncTransactionController&&) = delete;
47     RSSyncTransactionController& operator=(const RSSyncTransactionController&) = delete;
48     RSSyncTransactionController& operator=(const RSSyncTransactionController&&) = delete;
49 
50     std::mutex mutex_;
51     bool needCloseSync_ { false };
52     std::shared_ptr<RSTransaction> rsTransaction_;
53     static std::once_flag flag_;
54     static RSSyncTransactionController* instance_;
55 };
56 } // namespace Rosen
57 } // namespace OHOS
58 
59 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_SYNC_TRANSACTION_CONTROLLER_H
60