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