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 OHOS_ACELITE_MOCK_VSYNC_THREAD_H 17 #define OHOS_ACELITE_MOCK_VSYNC_THREAD_H 18 19 #include <QMutex> 20 #include <QThread> 21 22 #include "product_adapter.h" 23 24 namespace OHOS { 25 namespace ACELite { 26 /** 27 * @brief The VsyncThread class is a very simple mock implementation for display driver on real device, it just try 28 * continuing to dispatch one vsync message into the APP's event loop every 16ms, which can trigger the APP do the 29 * UI render work, and which makes the UI shown at last. 30 * 31 * NOTE: This mock implementation just for simulation purpose, it might not be suitable for real device. 32 */ 33 class VsyncThread : public QThread { 34 public: 35 VsyncThread() = default; 36 virtual ~VsyncThread() = default; 37 void run() override; 38 void Quit(); 39 bool IsRendring(); 40 void RenderEndNotifer(); 41 42 private: 43 bool CheckRenderingState(); 44 void SimuOneTickBreak() const; 45 TEDispatchingResult SimuOneTickEvent(); 46 const uint32_t MAX_STUCK_COUNT = 100; 47 const uint32_t MAX_MISSING_COUNT = 30; // trace out if no TE event is dispatching out for 30 ticks 48 uint32_t missingCount_ = 0; 49 uint32_t renderTickCount_ = 0; 50 uint32_t stuckCount_ = 0; 51 QMutex renderLock; 52 volatile bool taskQuitFlag = false; 53 }; 54 } // namespace ACELite 55 } // namespace OHOS 56 #endif // OHOS_ACELITE_MOCK_VSYNC_THREAD_H 57