kwin/renderjournal.cpp
Vlad Zahorodnii ad5f8c5c59 Introduce RenderJournal
Currently, we estimate the expected render time purely based on the
latency policy.

The problem with doing so is that the real render time might be larger,
this can result in frame drops.

In order to avoid frame drops, we need to take into account previous
render times while estimating the next render time. For now, we just
measure how long it takes to record rendering commands on the CPU.

In the future, we might want consider using OpenGL timer queries for
measuring the real render time, but for now, it's good enough.
2021-01-06 16:59:29 +00:00

56 lines
1.2 KiB
C++

/*
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "renderjournal.h"
namespace KWin
{
RenderJournal::RenderJournal()
{
}
void RenderJournal::beginFrame()
{
m_timer.start();
}
void RenderJournal::endFrame()
{
std::chrono::nanoseconds duration(m_timer.nsecsElapsed());
if (m_log.count() >= m_size) {
m_log.dequeue();
}
m_log.enqueue(duration);
}
std::chrono::nanoseconds RenderJournal::minimum() const
{
auto it = std::min_element(m_log.constBegin(), m_log.constEnd());
return it != m_log.constEnd() ? (*it) : std::chrono::nanoseconds::zero();
}
std::chrono::nanoseconds RenderJournal::maximum() const
{
auto it = std::max_element(m_log.constBegin(), m_log.constEnd());
return it != m_log.constEnd() ? (*it) : std::chrono::nanoseconds::zero();
}
std::chrono::nanoseconds RenderJournal::average() const
{
if (m_log.isEmpty()) {
return std::chrono::nanoseconds::zero();
}
std::chrono::nanoseconds result = std::chrono::nanoseconds::zero();
for (const std::chrono::nanoseconds &entry : m_log) {
result += entry;
}
return result / m_log.count();
}
} // namespace KWin