scene/surfaceitem: prevent division by zero
If the steady_clock's resolution is very limited, now - m_lastDamage might be zero, so enforce a minimum time of 10us (or 100'000 fps)
This commit is contained in:
parent
e97b6032c2
commit
41aeecbb2a
1 changed files with 5 additions and 3 deletions
|
@ -8,6 +8,8 @@
|
|||
#include "core/pixelgrid.h"
|
||||
#include "scene/scene.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
|
@ -102,13 +104,13 @@ static QRegion expandRegion(const QRegion ®ion, const QMargins &padding)
|
|||
void SurfaceItem::addDamage(const QRegion ®ion)
|
||||
{
|
||||
if (m_lastDamage) {
|
||||
const auto diff = std::chrono::steady_clock::now() - *m_lastDamage;
|
||||
const auto diff = std::max(std::chrono::steady_clock::now() - *m_lastDamage, 10'000ns);
|
||||
m_lastDamageTimeDiffs.push_back(diff);
|
||||
if (m_lastDamageTimeDiffs.size() > 100) {
|
||||
m_lastDamageTimeDiffs.pop_front();
|
||||
}
|
||||
const auto average = std::accumulate(m_lastDamageTimeDiffs.begin(), m_lastDamageTimeDiffs.end(), std::chrono::nanoseconds::zero()) / m_lastDamageTimeDiffs.size();
|
||||
m_refreshRate = std::chrono::nanoseconds(1'000'000'000) / average;
|
||||
const auto average = std::accumulate(m_lastDamageTimeDiffs.begin(), m_lastDamageTimeDiffs.end(), 0ns) / m_lastDamageTimeDiffs.size();
|
||||
m_refreshRate = 1'000'000'000ns / average;
|
||||
}
|
||||
m_lastDamage = std::chrono::steady_clock::now();
|
||||
m_damage += region;
|
||||
|
|
Loading…
Reference in a new issue