File indexing completed on 2024-05-19 16:34:01

0001 /*
0002     SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "kwin_export.h"
0010 #include "rendertarget.h"
0011 
0012 #include <QObject>
0013 #include <QRegion>
0014 #include <optional>
0015 
0016 namespace KWin
0017 {
0018 
0019 class SurfaceItem;
0020 
0021 struct OutputLayerBeginFrameInfo
0022 {
0023     RenderTarget renderTarget;
0024     QRegion repaint;
0025 };
0026 
0027 class KWIN_EXPORT OutputLayer : public QObject
0028 {
0029     Q_OBJECT
0030 public:
0031     explicit OutputLayer(QObject *parent = nullptr);
0032 
0033     QRegion repaints() const;
0034     void resetRepaints();
0035     void addRepaint(const QRegion &region);
0036 
0037     /**
0038      * Notifies about starting to paint.
0039      *
0040      * @p damage contains the reported damage as suggested by windows and effects on prepaint calls.
0041      */
0042     virtual void aboutToStartPainting(const QRegion &damage);
0043 
0044     virtual std::optional<OutputLayerBeginFrameInfo> beginFrame() = 0;
0045     virtual bool endFrame(const QRegion &renderedRegion, const QRegion &damagedRegion) = 0;
0046 
0047     /**
0048      * Tries to import the newest buffer of the surface for direct scanout
0049      * Returns @c true if scanout succeeds, @c false if rendering is necessary
0050      */
0051     virtual bool scanout(SurfaceItem *surfaceItem);
0052 
0053 private:
0054     QRegion m_repaints;
0055 };
0056 
0057 } // namespace KWin