File indexing completed on 2024-05-12 05:31:23
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 class Item; 0025 0026 /** 0027 * The RenderLayer class represents a composited layer. 0028 * 0029 * The contents of the layer is represented by the RenderLayerDelegate. The render layer 0030 * takes the ownership of the delegate. 0031 * 0032 * Each render layer has a hardware layer assigned to it, represented by OutputLayer. If 0033 * the output layer is not set explicitly, it's inherited from the parent render layer. 0034 * Output layers can be freely assigned or unassigned to render layers. 0035 */ 0036 class KWIN_EXPORT RenderLayer : public QObject 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 explicit RenderLayer(RenderLoop *loop, RenderLayer *superlayer = nullptr); 0042 ~RenderLayer() override; 0043 0044 OutputLayer *outputLayer() const; 0045 void setOutputLayer(OutputLayer *layer); 0046 0047 RenderLoop *loop() const; 0048 RenderLayerDelegate *delegate() const; 0049 void setDelegate(std::unique_ptr<RenderLayerDelegate> delegate); 0050 0051 QList<RenderLayer *> sublayers() const; 0052 RenderLayer *superlayer() const; 0053 void setSuperlayer(RenderLayer *layer); 0054 0055 bool isVisible() const; 0056 void setVisible(bool visible); 0057 0058 QPoint mapToGlobal(const QPoint &point) const; 0059 QPointF mapToGlobal(const QPointF &point) const; 0060 QRegion mapToGlobal(const QRegion ®ion) const; 0061 QRect mapToGlobal(const QRect &rect) const; 0062 QRectF mapToGlobal(const QRectF &rect) const; 0063 0064 QPoint mapFromGlobal(const QPoint &point) const; 0065 QPointF mapFromGlobal(const QPointF &point) const; 0066 QRegion mapFromGlobal(const QRegion ®ion) const; 0067 QRect mapFromGlobal(const QRect &rect) const; 0068 QRectF mapFromGlobal(const QRectF &rect) const; 0069 0070 QRectF rect() const; 0071 QRectF boundingRect() const; 0072 0073 QRectF geometry() const; 0074 void setGeometry(const QRectF &rect); 0075 0076 /** 0077 * Mark this layer as dirty and trigger a repaint 0078 * on the render loop 0079 */ 0080 void scheduleRepaint(Item *item); 0081 /** 0082 * Returns true if this or a sublayer has requested an update 0083 */ 0084 bool needsRepaint() const; 0085 0086 void addRepaint(const QRegion ®ion); 0087 void addRepaint(const QRect &rect); 0088 void addRepaint(int x, int y, int width, int height); 0089 void addRepaintFull(); 0090 QRegion repaints() const; 0091 void resetRepaints(); 0092 0093 private: 0094 void addSublayer(RenderLayer *sublayer); 0095 void removeSublayer(RenderLayer *sublayer); 0096 void updateBoundingRect(); 0097 void updateEffectiveVisibility(); 0098 bool computeEffectiveVisibility() const; 0099 0100 RenderLoop *m_loop; 0101 bool m_repaintScheduled = false; 0102 std::unique_ptr<RenderLayerDelegate> m_delegate; 0103 QRegion m_repaints; 0104 QRectF m_boundingRect; 0105 QRectF m_geometry; 0106 QPointer<OutputLayer> m_outputLayer; 0107 RenderLayer *m_superlayer = nullptr; 0108 QList<RenderLayer *> m_sublayers; 0109 bool m_effectiveVisible = true; 0110 bool m_explicitVisible = true; 0111 }; 0112 0113 } // namespace KWin