File indexing completed on 2024-05-19 05:31:36

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 "core/rendertarget.h"
0010 #include "kwin_export.h"
0011 
0012 #include <QObject>
0013 #include <QRegion>
0014 #include <chrono>
0015 #include <optional>
0016 
0017 namespace KWin
0018 {
0019 
0020 class SurfaceItem;
0021 
0022 struct OutputLayerBeginFrameInfo
0023 {
0024     RenderTarget renderTarget;
0025     QRegion repaint;
0026 };
0027 
0028 class KWIN_EXPORT OutputLayer : public QObject
0029 {
0030     Q_OBJECT
0031 public:
0032     explicit OutputLayer(QObject *parent = nullptr);
0033 
0034     qreal scale() const;
0035     void setScale(qreal scale);
0036 
0037     QPointF hotspot() const;
0038     void setHotspot(const QPointF &hotspot);
0039 
0040     QSizeF size() const;
0041     void setSize(const QSizeF &size);
0042     /**
0043      * For most drm drivers, the buffer used for the cursor has to have a fixed size.
0044      * If such a fixed size is required by the backend, this function should return it
0045      */
0046     virtual std::optional<QSize> fixedSize() const;
0047 
0048     QRegion repaints() const;
0049     void resetRepaints();
0050     void addRepaint(const QRegion &region);
0051     bool needsRepaint() const;
0052 
0053     /**
0054      * @arg position in device coordinates
0055      */
0056     void setPosition(const QPointF &position);
0057     QPointF position() const;
0058 
0059     /**
0060      * Enables or disables this layer. Note that disabling the primary layer will cause problems
0061      */
0062     void setEnabled(bool enable);
0063     bool isEnabled() const;
0064 
0065     virtual std::optional<OutputLayerBeginFrameInfo> beginFrame() = 0;
0066     virtual bool endFrame(const QRegion &renderedRegion, const QRegion &damagedRegion) = 0;
0067 
0068     /**
0069      * Tries to import the newest buffer of the surface for direct scanout
0070      * Returns @c true if scanout succeeds, @c false if rendering is necessary
0071      */
0072     virtual bool scanout(SurfaceItem *surfaceItem);
0073 
0074     /**
0075      * queries the render time of the last frame. If rendering isn't complete yet, this may block until it is
0076      */
0077     virtual std::chrono::nanoseconds queryRenderTime() const = 0;
0078 
0079 private:
0080     QRegion m_repaints;
0081     QPointF m_hotspot;
0082     QPointF m_position;
0083     QSizeF m_size;
0084     qreal m_scale = 1.0;
0085     bool m_enabled = false;
0086 };
0087 
0088 } // namespace KWin