File indexing completed on 2024-11-10 04:56:36
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 <epoxy/glx.h> 0012 #include <fixx11h.h> 0013 0014 #include <QThread> 0015 #include <memory> 0016 0017 namespace KWin 0018 { 0019 0020 /** 0021 * The OMLSyncControlVsyncMonitorHelper class is responsible for waiting vsync events on the 0022 * root window. Note that the helper runs on a separate thread. 0023 */ 0024 class OMLSyncControlVsyncMonitorHelper : public QObject 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 explicit OMLSyncControlVsyncMonitorHelper(); 0030 ~OMLSyncControlVsyncMonitorHelper() override; 0031 0032 bool isValid() const; 0033 0034 public Q_SLOTS: 0035 void poll(); 0036 0037 Q_SIGNALS: 0038 void errorOccurred(); 0039 void vblankOccurred(std::chrono::nanoseconds timestamp); 0040 0041 private: 0042 Display *m_display = nullptr; 0043 ::Window m_dummyWindow = 0; 0044 GLXContext m_localContext = 0; 0045 GLXDrawable m_drawable = 0; 0046 }; 0047 0048 /** 0049 * The OMLSyncControlVsyncMonitor class monitors vblank events using the GLX_OML_sync_control 0050 * extension. 0051 * 0052 * Vblank events are monitored in a separated thread to avoid blocking the main thread. In 0053 * order to avoid locking up the main X11 connection, the worker thread establishes its own 0054 * X11 connection. 0055 */ 0056 class OMLSyncControlVsyncMonitor : public VsyncMonitor 0057 { 0058 Q_OBJECT 0059 0060 public: 0061 static std::unique_ptr<OMLSyncControlVsyncMonitor> create(); 0062 ~OMLSyncControlVsyncMonitor() override; 0063 0064 bool isValid() const; 0065 0066 public Q_SLOTS: 0067 void arm() override; 0068 0069 private: 0070 explicit OMLSyncControlVsyncMonitor(); 0071 0072 QThread m_thread; 0073 OMLSyncControlVsyncMonitorHelper m_helper; 0074 }; 0075 0076 } // namespace KWin