File indexing completed on 2025-03-16 11:21:24
0001 /* 0002 SPDX-FileCopyrightText: 2011 Martin Gräßlin <mgraesslin@kde.org> 0003 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QQuickItem> 0011 #include <QUuid> 0012 0013 #include <epoxy/gl.h> 0014 0015 namespace KWin 0016 { 0017 class Window; 0018 class GLFramebuffer; 0019 class GLTexture; 0020 class ThumbnailTextureProvider; 0021 0022 class WindowThumbnailItem : public QQuickItem 0023 { 0024 Q_OBJECT 0025 Q_PROPERTY(QUuid wId READ wId WRITE setWId NOTIFY wIdChanged) 0026 Q_PROPERTY(KWin::Window *client READ client WRITE setClient NOTIFY clientChanged) 0027 0028 Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize NOTIFY sourceSizeChanged) 0029 /** 0030 * TODO Plasma 6: Remove. 0031 * @deprecated use a shader effect to change the brightness 0032 */ 0033 Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged) 0034 /** 0035 * TODO Plasma 6: Remove. 0036 * @deprecated use a shader effect to change color saturation 0037 */ 0038 Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged) 0039 /** 0040 * TODO Plasma 6: Remove. 0041 * @deprecated clipTo has no replacement 0042 */ 0043 Q_PROPERTY(QQuickItem *clipTo READ clipTo WRITE setClipTo NOTIFY clipToChanged) 0044 0045 public: 0046 explicit WindowThumbnailItem(QQuickItem *parent = nullptr); 0047 ~WindowThumbnailItem() override; 0048 0049 QUuid wId() const; 0050 void setWId(const QUuid &wId); 0051 0052 Window *client() const; 0053 void setClient(Window *client); 0054 0055 qreal brightness() const; 0056 void setBrightness(qreal brightness); 0057 0058 qreal saturation() const; 0059 void setSaturation(qreal saturation); 0060 0061 QQuickItem *clipTo() const; 0062 void setClipTo(QQuickItem *clip); 0063 0064 QSize sourceSize() const; 0065 void setSourceSize(const QSize &sourceSize); 0066 0067 QSGTextureProvider *textureProvider() const override; 0068 bool isTextureProvider() const override; 0069 QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) override; 0070 0071 protected: 0072 void releaseResources() override; 0073 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) override; 0074 0075 Q_SIGNALS: 0076 void wIdChanged(); 0077 void clientChanged(); 0078 void brightnessChanged(); 0079 void saturationChanged(); 0080 void clipToChanged(); 0081 void sourceSizeChanged(); 0082 0083 private: 0084 QImage fallbackImage() const; 0085 QRectF paintedRect() const; 0086 void invalidateOffscreenTexture(); 0087 void updateOffscreenTexture(); 0088 void destroyOffscreenTexture(); 0089 void updateImplicitSize(); 0090 void updateFrameRenderingConnection(); 0091 static bool useGlThumbnails(); 0092 0093 QSize m_sourceSize; 0094 QUuid m_wId; 0095 QPointer<Window> m_client; 0096 bool m_dirty = false; 0097 0098 mutable ThumbnailTextureProvider *m_provider = nullptr; 0099 std::shared_ptr<GLTexture> m_offscreenTexture; 0100 std::unique_ptr<GLFramebuffer> m_offscreenTarget; 0101 GLsync m_acquireFence = 0; 0102 qreal m_devicePixelRatio = 1; 0103 0104 QMetaObject::Connection m_frameRenderingConnection; 0105 }; 0106 0107 } // namespace KWin