1 /* 2 * Copyright (c) 2021-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 DRM_VSYNC_WORKER_H 17 #define DRM_VSYNC_WORKER_H 18 #include <memory> 19 #include <mutex> 20 #include <thread> 21 #include <condition_variable> 22 #include "hdi_device_common.h" 23 24 namespace OHOS { 25 namespace HDI { 26 namespace DISPLAY { 27 class DrmVsyncWorker { 28 public: 29 DrmVsyncWorker(); 30 virtual ~DrmVsyncWorker(); 31 int32_t Init(int fd); 32 static DrmVsyncWorker &GetInstance(); 33 34 void EnableVsync(bool enable); 35 void WorkThread(); 36 uint64_t WaitNextVBlank(unsigned int &sq); 37 bool WaitSignalAndCheckRuning(); 38 void ReqesterVBlankCb(std::shared_ptr<VsyncCallBack> &cb); 39 40 private: 41 int mDrmFd = 0; 42 std::unique_ptr<std::thread> mThread; 43 bool mEnable = false; 44 std::mutex mMutex; 45 std::condition_variable mCondition; 46 std::shared_ptr<VsyncCallBack> mCallBack; 47 bool mRunning = false; 48 }; 49 } // namespace OHOS 50 } // namespace HDI 51 } // namespace DISPLAY 52 53 #endif // DRM_VSYNC_WORKER_H 54