diff --git a/src/backends/drm/dumb_swapchain.h b/src/backends/drm/dumb_swapchain.h index 2634db3f96..991d4e6e5d 100644 --- a/src/backends/drm/dumb_swapchain.h +++ b/src/backends/drm/dumb_swapchain.h @@ -9,7 +9,7 @@ #pragma once -#include "utils/common.h" +#include "utils/damagejournal.h" #include #include diff --git a/src/backends/drm/egl_gbm_backend.h b/src/backends/drm/egl_gbm_backend.h index 588a8ff11d..25d8c96342 100644 --- a/src/backends/drm/egl_gbm_backend.h +++ b/src/backends/drm/egl_gbm_backend.h @@ -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 diff --git a/src/backends/drm/gbm_surface.h b/src/backends/drm/gbm_surface.h index c06e1c06e6..09f659a0b4 100644 --- a/src/backends/drm/gbm_surface.h +++ b/src/backends/drm/gbm_surface.h @@ -15,7 +15,7 @@ #include #include "drm_buffer_gbm.h" -#include "utils/common.h" +#include "utils/damagejournal.h" struct gbm_device; struct gbm_surface; diff --git a/src/backends/wayland/egl_wayland_backend.h b/src/backends/wayland/egl_wayland_backend.h index cbc9bb5c03..4ff9bb866c 100644 --- a/src/backends/wayland/egl_wayland_backend.h +++ b/src/backends/wayland/egl_wayland_backend.h @@ -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 diff --git a/src/backends/wayland/scene_qpainter_wayland_backend.h b/src/backends/wayland/scene_qpainter_wayland_backend.h index a46b3a253c..5a78ac6c68 100644 --- a/src/backends/wayland/scene_qpainter_wayland_backend.h +++ b/src/backends/wayland/scene_qpainter_wayland_backend.h @@ -11,7 +11,7 @@ #define KWIN_SCENE_QPAINTER_WAYLAND_BACKEND_H #include "qpainterbackend.h" -#include "utils/common.h" +#include "utils/damagejournal.h" #include #include diff --git a/src/backends/x11/standalone/eglbackend.h b/src/backends/x11/standalone/eglbackend.h index 9bb0c1261c..5fa202cf14 100644 --- a/src/backends/x11/standalone/eglbackend.h +++ b/src/backends/x11/standalone/eglbackend.h @@ -8,7 +8,7 @@ #include "eglonxbackend.h" #include "openglsurfacetexture_x11.h" -#include "utils/common.h" +#include "utils/damagejournal.h" #include #include diff --git a/src/backends/x11/standalone/glxbackend.h b/src/backends/x11/standalone/glxbackend.h index 28c236c717..8eaeef9e01 100644 --- a/src/backends/x11/standalone/glxbackend.h +++ b/src/backends/x11/standalone/glxbackend.h @@ -11,7 +11,7 @@ #include "openglbackend.h" #include "openglsurfacetexture_x11.h" #include "x11eventfilter.h" -#include "utils/common.h" +#include "utils/damagejournal.h" #include #include diff --git a/src/utils/common.h b/src/utils/common.h index 59f78b659b..80515d4181 100644 --- a/src/utils/common.h +++ b/src/utils/common.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 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 diff --git a/src/utils/damagejournal.h b/src/utils/damagejournal.h new file mode 100644 index 0000000000..dd643f0a8a --- /dev/null +++ b/src/utils/damagejournal.h @@ -0,0 +1,83 @@ +/* + SPDX-FileCopyrightText: 2022 Vlad Zahorodnii + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#pragma once + +#include "kwin_export.h" + +#include + +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 m_log; + int m_capacity = 10; +}; + +} // namespace KWin