File indexing completed on 2025-03-16 08:15:00
0001 /* 0002 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "utils/vsyncmonitor.h" 0010 0011 #include <QTimer> 0012 #include <memory> 0013 0014 namespace KWin 0015 { 0016 0017 /** 0018 * The SoftwareVsyncMonitor class provides synthetic vblank events with constant interval. 0019 * 0020 * The software vsync monitor can never fail and it is always available. It can be used as 0021 * fallback if hardware based approaches to monitor vsync events are unavailable. 0022 * 0023 * The vblank interval can be changed by calling the setRefreshRate() function. 0024 */ 0025 class KWIN_EXPORT SoftwareVsyncMonitor : public VsyncMonitor 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 static std::unique_ptr<SoftwareVsyncMonitor> create(); 0031 0032 int refreshRate() const; 0033 void setRefreshRate(int refreshRate); 0034 0035 public Q_SLOTS: 0036 void arm() override; 0037 0038 private: 0039 explicit SoftwareVsyncMonitor(); 0040 void handleSyntheticVsync(); 0041 0042 QTimer m_softwareClock; 0043 int m_refreshRate = 60000; 0044 std::chrono::nanoseconds m_vblankTimestamp = std::chrono::nanoseconds::zero(); 0045 }; 0046 0047 } // namespace KWin