File indexing completed on 2024-05-19 16:34:45
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 "scene/item.h" 0010 0011 namespace KDecoration2 0012 { 0013 class Decoration; 0014 } 0015 0016 namespace KWin 0017 { 0018 0019 class Window; 0020 class Deleted; 0021 class Output; 0022 0023 namespace Decoration 0024 { 0025 class DecoratedClientImpl; 0026 } 0027 0028 class KWIN_EXPORT DecorationRenderer : public QObject 0029 { 0030 Q_OBJECT 0031 0032 public: 0033 virtual void render(const QRegion ®ion) = 0; 0034 void invalidate(); 0035 0036 // TODO: Move damage tracking inside DecorationItem. 0037 QRegion damage() const; 0038 void addDamage(const QRegion ®ion); 0039 void resetDamage(); 0040 0041 qreal effectiveDevicePixelRatio() const; 0042 qreal devicePixelRatio() const; 0043 void setDevicePixelRatio(qreal dpr); 0044 0045 // Reserve some space for padding. We pad decoration parts to avoid texture bleeding. 0046 static const int TexturePad = 1; 0047 0048 Q_SIGNALS: 0049 void damaged(const QRegion ®ion); 0050 0051 protected: 0052 explicit DecorationRenderer(Decoration::DecoratedClientImpl *client); 0053 0054 Decoration::DecoratedClientImpl *client() const; 0055 0056 bool areImageSizesDirty() const 0057 { 0058 return m_imageSizesDirty; 0059 } 0060 void resetImageSizesDirty() 0061 { 0062 m_imageSizesDirty = false; 0063 } 0064 QImage renderToImage(const QRect &geo); 0065 void renderToPainter(QPainter *painter, const QRect &rect); 0066 0067 private: 0068 QPointer<Decoration::DecoratedClientImpl> m_client; 0069 QRegion m_damage; 0070 qreal m_devicePixelRatio = 1; 0071 bool m_imageSizesDirty; 0072 }; 0073 0074 /** 0075 * The DecorationItem class represents a server-side decoration. 0076 */ 0077 class KWIN_EXPORT DecorationItem : public Item 0078 { 0079 Q_OBJECT 0080 0081 public: 0082 explicit DecorationItem(KDecoration2::Decoration *decoration, Window *window, Scene *scene, Item *parent = nullptr); 0083 0084 DecorationRenderer *renderer() const; 0085 Window *window() const; 0086 0087 QVector<QRectF> shape() const override final; 0088 QRegion opaque() const override final; 0089 0090 private Q_SLOTS: 0091 void handleFrameGeometryChanged(); 0092 void handleWindowClosed(Window *original, Deleted *deleted); 0093 void handleOutputChanged(); 0094 void handleOutputScaleChanged(); 0095 0096 protected: 0097 void preprocess() override; 0098 WindowQuadList buildQuads() const override; 0099 0100 private: 0101 Window *m_window; 0102 QPointer<Output> m_output; 0103 QPointer<KDecoration2::Decoration> m_decoration; 0104 std::unique_ptr<DecorationRenderer> m_renderer; 0105 }; 0106 0107 } // namespace KWin