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