File indexing completed on 2025-03-23 11:13:33

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 "kwinglobals.h"
0010 
0011 #include <QElapsedTimer>
0012 #include <QQueue>
0013 
0014 namespace KWin
0015 {
0016 
0017 /**
0018  * The RenderJournal class measures how long it takes to render frames and estimates how
0019  * long it will take to render the next frame.
0020  */
0021 class KWIN_EXPORT RenderJournal
0022 {
0023 public:
0024     RenderJournal();
0025 
0026     /**
0027      * This function must be called before starting rendering a new frame.
0028      */
0029     void beginFrame();
0030 
0031     /**
0032      * This function must be called after finishing rendering a frame.
0033      */
0034     void endFrame();
0035 
0036     /**
0037      * Returns the maximum estimated amount of time that it takes to render a single frame.
0038      */
0039     std::chrono::nanoseconds maximum() const;
0040 
0041     /**
0042      * Returns the minimum estimated amount of time that it takes to render a single frame.
0043      */
0044     std::chrono::nanoseconds minimum() const;
0045 
0046     /**
0047      * Returns the average estimated amount of time that it takes to render a single frame.
0048      */
0049     std::chrono::nanoseconds average() const;
0050 
0051 private:
0052     QElapsedTimer m_timer;
0053     QQueue<std::chrono::nanoseconds> m_log;
0054     int m_size = 15;
0055 };
0056 
0057 } // namespace KWin