1 /*
2  * Copyright (c) 2024 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 DRAG_VSYNC_STATION_H
17 #define DRAG_VSYNC_STATION_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <vector>
22 
23 #include "vsync_receiver.h"
24 namespace OHOS {
25 namespace Msdp {
26 namespace DeviceStatus {
27 using DragFrameCallback = std::function<void(uint64_t)>;
28 
29 enum FrameRequestType {
30     TYPE_FLUSH_DRAG_POSITION = 1,
31     TYPE_PERFORM_ANIMATION = 2,
32     REQUEST_TYPE_MAX
33 };
34 
35 class DragVSyncStation {
36 public:
37     int32_t RequestFrame(int32_t frameType, std::shared_ptr<DragFrameCallback> callback);
38     void StopVSyncRequest();
39     uint64_t GetVSyncPeriod();
40 
41 private:
42     int32_t Init();
43     void OnVSyncInner(uint64_t nanoTimestamp);
44     static void OnVSync(uint64_t nanoTimestamp, void *client);
45     void SetThreadQosLevel(std::shared_ptr<AppExecFwk::EventHandler> handler);
46     void SetQosForOtherThread(int32_t tid);
47     std::shared_ptr<Rosen::VSyncReceiver> receiver_ {nullptr};
48     std::map<int32_t, std::shared_ptr<DragFrameCallback>> vSyncCallbacks_;
49     Rosen::VSyncReceiver::FrameCallback frameCallback_;
50     uint64_t vSyncPeriod_ {0};
51     std::shared_ptr<AppExecFwk::EventHandler> handler_ { nullptr };
52     std::mutex mtx_;
53     int32_t mmiHandleTid_ { -1 };
54 };
55 } // namespace DeviceStatus
56 } // namespace Msdp
57 } // namespace OHOS
58 #endif // DRAG_VSYNC_STATION_H