File indexing completed on 2024-12-01 13:36:09

0001 /*
0002     SPDX-FileCopyrightText: 2021 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 
0011 #include "outputlayer.h"
0012 
0013 #include <QMap>
0014 #include <QObject>
0015 #include <QPointer>
0016 #include <QRegion>
0017 
0018 namespace KWin
0019 {
0020 
0021 class OutputLayer;
0022 class RenderLayerDelegate;
0023 class RenderLoop;
0024 
0025 /**
0026  * The RenderLayer class represents a composited layer.
0027  *
0028  * The contents of the layer is represented by the RenderLayerDelegate. The render layer
0029  * takes the ownership of the delegate.
0030  *
0031  * Each render layer has a hardware layer assigned to it, represented by OutputLayer. If
0032  * the output layer is not set explicitly, it's inherited from the parent render layer.
0033  * Output layers can be freely assigned or unassigned to render layers.
0034  */
0035 class KWIN_EXPORT RenderLayer : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     explicit RenderLayer(RenderLoop *loop, RenderLayer *superlayer = nullptr);
0041     ~RenderLayer() override;
0042 
0043     OutputLayer *outputLayer() const;
0044     void setOutputLayer(OutputLayer *layer);
0045 
0046     RenderLoop *loop() const;
0047     RenderLayerDelegate *delegate() const;
0048     void setDelegate(std::unique_ptr<RenderLayerDelegate> delegate);
0049 
0050     QList<RenderLayer *> sublayers() const;
0051     RenderLayer *superlayer() const;
0052     void setSuperlayer(RenderLayer *layer);
0053 
0054     bool isVisible() const;
0055     void setVisible(bool visible);
0056 
0057     QPoint mapToGlobal(const QPoint &point) const;
0058     QRegion mapToGlobal(const QRegion &region) const;
0059     QRect mapToGlobal(const QRect &rect) const;
0060 
0061     QPoint mapFromGlobal(const QPoint &point) const;
0062     QRegion mapFromGlobal(const QRegion &region) const;
0063     QRect mapFromGlobal(const QRect &rect) const;
0064 
0065     QRect rect() const;
0066     QRect boundingRect() const;
0067 
0068     QRect geometry() const;
0069     void setGeometry(const QRect &rect);
0070 
0071     void addRepaint(const QRegion &region);
0072     void addRepaint(const QRect &rect);
0073     void addRepaint(int x, int y, int width, int height);
0074     void addRepaintFull();
0075     QRegion repaints() const;
0076     void resetRepaints();
0077 
0078 private:
0079     void addSublayer(RenderLayer *sublayer);
0080     void removeSublayer(RenderLayer *sublayer);
0081     void updateBoundingRect();
0082     void updateEffectiveVisibility();
0083     bool computeEffectiveVisibility() const;
0084 
0085     RenderLoop *m_loop;
0086     std::unique_ptr<RenderLayerDelegate> m_delegate;
0087     QRegion m_repaints;
0088     QRect m_boundingRect;
0089     QRect m_geometry;
0090     QPointer<OutputLayer> m_outputLayer;
0091     RenderLayer *m_superlayer = nullptr;
0092     QList<RenderLayer *> m_sublayers;
0093     bool m_effectiveVisible = true;
0094     bool m_explicitVisible = true;
0095 };
0096 
0097 } // namespace KWin