File indexing completed on 2024-06-09 05:26:08

0001 /*
0002     SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
0003     SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0004     SPDX-FileCopyrightText: 2022 Arjen Hiemstra <ahiemstra@heimr.nl>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include "effect/effect.h"
0012 #include "effect/offscreenquickview.h"
0013 
0014 #include <QElapsedTimer>
0015 
0016 namespace KWin
0017 {
0018 
0019 class ShowFpsEffect : public Effect
0020 {
0021     Q_OBJECT
0022     Q_PROPERTY(int fps READ fps NOTIFY fpsChanged)
0023     Q_PROPERTY(int maximumFps READ maximumFps NOTIFY maximumFpsChanged)
0024     Q_PROPERTY(int paintDuration READ paintDuration NOTIFY paintChanged)
0025     Q_PROPERTY(int paintAmount READ paintAmount NOTIFY paintChanged)
0026     Q_PROPERTY(QColor paintColor READ paintColor NOTIFY paintChanged)
0027 
0028 public:
0029     ShowFpsEffect();
0030     ~ShowFpsEffect() override;
0031 
0032     int fps() const;
0033     int maximumFps() const;
0034     int paintDuration() const;
0035     int paintAmount() const;
0036     QColor paintColor() const;
0037 
0038     void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override;
0039     void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion &region, Output *screen) override;
0040     void paintWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, QRegion region, KWin::WindowPaintData &data) override;
0041     void postPaintScreen() override;
0042 
0043     static bool supported();
0044 
0045 Q_SIGNALS:
0046     void fpsChanged();
0047     void maximumFpsChanged();
0048     void paintChanged();
0049 
0050 private:
0051     std::unique_ptr<OffscreenQuickScene> m_scene;
0052 
0053     uint32_t m_maximumFps = 0;
0054 
0055     int m_fps = 0;
0056     int m_newFps = 0;
0057     std::chrono::steady_clock::time_point m_lastFpsTime;
0058 
0059     int m_paintDuration = 0;
0060     int m_paintAmount = 0;
0061     QElapsedTimer m_paintDurationTimer;
0062 };
0063 
0064 } // namespace KWin