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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ROSEN_ROSEN_WINDOW_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ROSEN_ROSEN_WINDOW_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 #include <queue>
22 #include <thread>
23 #include <vector>
24 
25 #include "base/thread/sem_queue.h"
26 #include "base/utils/noncopyable.h"
27 #include "core/common/platform_window.h"
28 
29 namespace OHOS::Ace::Platform {
30 
31 class RSWindow final : public PlatformWindow {
32 public:
33     void Destroy() override;
34     void RequestFrame() override;
35     void RegisterVsyncCallback(AceVsyncCallback&& callback) override;
36     void SetRootRenderNode(const RefPtr<RenderNode>& root) override;
37     void SetUiDvsyncSwitch(bool vsyncSwitch) override;
38 
39 private:
40     void VsyncThreadMain();
41 
42     std::vector<AceVsyncCallback> vsyncCallbacks_;
43     std::vector<AceVsyncCallback> pendingVsyncCallbacks_;
44     std::unique_ptr<std::thread> vsyncThread_ = nullptr;
45     SemQueue<bool> vsyncRequests_;
46     std::mutex mutex_;
47 };
48 
49 } // namespace OHOS::Ace::Platform
50 
51 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ROSEN_ROSEN_WINDOW_H
52