KWin
Loading...
Searching...
No Matches
damagejournal.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kwin_export.h"
10
11#include <QList>
12#include <QRegion>
13
14namespace KWin
15{
16
20class KWIN_EXPORT DamageJournal
21{
22public:
26 int capacity() const
27 {
28 return m_capacity;
29 }
30
35 void setCapacity(int capacity)
36 {
37 m_capacity = capacity;
38 }
39
43 void add(const QRegion &region)
44 {
45 while (m_log.size() >= m_capacity) {
46 m_log.takeLast();
47 }
48 m_log.prepend(region);
49 }
50
55 void clear()
56 {
57 m_log.clear();
58 }
59
66 QRegion accumulate(int bufferAge, const QRegion &fallback = QRegion()) const
67 {
68 QRegion region;
69 if (bufferAge > 0 && bufferAge <= m_log.size()) {
70 for (int i = 0; i < bufferAge - 1; ++i) {
71 region += m_log[i];
72 }
73 } else {
74 region = fallback;
75 }
76 return region;
77 }
78
79 QRegion lastDamage() const
80 {
81 return m_log.first();
82 }
83
84private:
85 QList<QRegion> m_log;
86 int m_capacity = 10;
87};
88
89} // namespace KWin
void setCapacity(int capacity)
void add(const QRegion &region)
QRegion accumulate(int bufferAge, const QRegion &fallback=QRegion()) const
QRegion lastDamage() const