utils: Extract DamageJournal in its own file
This commit is contained in:
parent
dece547a75
commit
eea94660dc
9 changed files with 89 additions and 74 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "utils/common.h"
|
||||
#include "utils/damagejournal.h"
|
||||
|
||||
#include <QVector>
|
||||
#include <QSize>
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#ifndef KWIN_EGL_GBM_BACKEND_H
|
||||
#define KWIN_EGL_GBM_BACKEND_H
|
||||
#include "abstract_egl_backend.h"
|
||||
#include "utils/common.h"
|
||||
|
||||
#include <kwinglutils.h>
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <optional>
|
||||
|
||||
#include "drm_buffer_gbm.h"
|
||||
#include "utils/common.h"
|
||||
#include "utils/damagejournal.h"
|
||||
|
||||
struct gbm_device;
|
||||
struct gbm_surface;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#ifndef KWIN_EGL_WAYLAND_BACKEND_H
|
||||
#define KWIN_EGL_WAYLAND_BACKEND_H
|
||||
#include "abstract_egl_backend.h"
|
||||
#include "utils/common.h"
|
||||
#include "utils/damagejournal.h"
|
||||
// wayland
|
||||
#include <wayland-egl.h>
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#define KWIN_SCENE_QPAINTER_WAYLAND_BACKEND_H
|
||||
|
||||
#include "qpainterbackend.h"
|
||||
#include "utils/common.h"
|
||||
#include "utils/damagejournal.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QImage>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include "eglonxbackend.h"
|
||||
#include "openglsurfacetexture_x11.h"
|
||||
#include "utils/common.h"
|
||||
#include "utils/damagejournal.h"
|
||||
|
||||
#include <kwingltexture.h>
|
||||
#include <kwingltexture_p.h>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "openglbackend.h"
|
||||
#include "openglsurfacetexture_x11.h"
|
||||
#include "x11eventfilter.h"
|
||||
#include "utils/common.h"
|
||||
#include "utils/damagejournal.h"
|
||||
|
||||
#include <xcb/glx.h>
|
||||
#include <epoxy/glx.h>
|
||||
|
|
|
@ -154,73 +154,6 @@ Qt::MouseButton KWIN_EXPORT x11ToQtMouseButton(int button);
|
|||
Qt::MouseButtons KWIN_EXPORT x11ToQtMouseButtons(int state);
|
||||
Qt::KeyboardModifiers KWIN_EXPORT x11ToQtKeyboardModifiers(int state);
|
||||
|
||||
/**
|
||||
* The DamageJournal class is a helper that tracks last N damage regions.
|
||||
*/
|
||||
class KWIN_EXPORT DamageJournal
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Returns the maximum number of damage regions that can be stored in the journal.
|
||||
*/
|
||||
int capacity() const
|
||||
{
|
||||
return m_capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of damage regions that can be stored in the journal
|
||||
* to @a capacity.
|
||||
*/
|
||||
void setCapacity(int capacity)
|
||||
{
|
||||
m_capacity = capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified @a region to the journal.
|
||||
*/
|
||||
void add(const QRegion ®ion)
|
||||
{
|
||||
while (m_log.size() >= m_capacity) {
|
||||
m_log.takeLast();
|
||||
}
|
||||
m_log.prepend(region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the damage journal. Typically, one would want to clear the damage journal
|
||||
* if a buffer swap fails for some reason.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
m_log.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accumulates the damage regions in the log up to the specified @a bufferAge.
|
||||
*
|
||||
* If the specified buffer age value refers to a damage region older than the last
|
||||
* one in the journal, @a fallback will be returned.
|
||||
*/
|
||||
QRegion accumulate(int bufferAge, const QRegion &fallback = QRegion()) const
|
||||
{
|
||||
QRegion region;
|
||||
if (bufferAge > 0 && bufferAge <= m_log.size()) {
|
||||
for (int i = 0; i < bufferAge - 1; ++i) {
|
||||
region |= m_log[i];
|
||||
}
|
||||
} else {
|
||||
region = fallback;
|
||||
}
|
||||
return region;
|
||||
}
|
||||
|
||||
private:
|
||||
QList<QRegion> m_log;
|
||||
int m_capacity = 10;
|
||||
};
|
||||
|
||||
KWIN_EXPORT QPoint popupOffset(const QRect &anchorRect, const Qt::Edges anchorEdge, const Qt::Edges gravity, const QSize popupSize);
|
||||
|
||||
} // namespace
|
||||
|
|
83
src/utils/damagejournal.h
Normal file
83
src/utils/damagejournal.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "kwin_export.h"
|
||||
|
||||
#include <QRegion>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
/**
|
||||
* The DamageJournal class is a helper that tracks last N damage regions.
|
||||
*/
|
||||
class KWIN_EXPORT DamageJournal
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Returns the maximum number of damage regions that can be stored in the journal.
|
||||
*/
|
||||
int capacity() const
|
||||
{
|
||||
return m_capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of damage regions that can be stored in the journal
|
||||
* to @a capacity.
|
||||
*/
|
||||
void setCapacity(int capacity)
|
||||
{
|
||||
m_capacity = capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified @a region to the journal.
|
||||
*/
|
||||
void add(const QRegion ®ion)
|
||||
{
|
||||
while (m_log.size() >= m_capacity) {
|
||||
m_log.takeLast();
|
||||
}
|
||||
m_log.prepend(region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the damage journal. Typically, one would want to clear the damage journal
|
||||
* if a buffer swap fails for some reason.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
m_log.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accumulates the damage regions in the log up to the specified @a bufferAge.
|
||||
*
|
||||
* If the specified buffer age value refers to a damage region older than the last
|
||||
* one in the journal, @a fallback will be returned.
|
||||
*/
|
||||
QRegion accumulate(int bufferAge, const QRegion &fallback = QRegion()) const
|
||||
{
|
||||
QRegion region;
|
||||
if (bufferAge > 0 && bufferAge <= m_log.size()) {
|
||||
for (int i = 0; i < bufferAge - 1; ++i) {
|
||||
region |= m_log[i];
|
||||
}
|
||||
} else {
|
||||
region = fallback;
|
||||
}
|
||||
return region;
|
||||
}
|
||||
|
||||
private:
|
||||
QList<QRegion> m_log;
|
||||
int m_capacity = 10;
|
||||
};
|
||||
|
||||
} // namespace KWin
|
Loading…
Reference in a new issue