File indexing completed on 2024-05-19 05:32:25
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 class WindowThumbnailSource; 0022 0023 class WindowThumbnailSource : public QObject 0024 { 0025 Q_OBJECT 0026 0027 public: 0028 WindowThumbnailSource(QQuickWindow *view, Window *handle); 0029 ~WindowThumbnailSource() override; 0030 0031 static std::shared_ptr<WindowThumbnailSource> getOrCreate(QQuickWindow *window, Window *handle); 0032 0033 struct Frame 0034 { 0035 std::shared_ptr<GLTexture> texture; 0036 GLsync fence; 0037 }; 0038 0039 Frame acquire(); 0040 0041 Q_SIGNALS: 0042 void changed(); 0043 0044 private: 0045 void update(); 0046 0047 QPointer<QQuickWindow> m_view; 0048 QPointer<Window> m_handle; 0049 0050 std::shared_ptr<GLTexture> m_offscreenTexture; 0051 std::unique_ptr<GLFramebuffer> m_offscreenTarget; 0052 GLsync m_acquireFence = 0; 0053 bool m_dirty = true; 0054 }; 0055 0056 class WindowThumbnailItem : public QQuickItem 0057 { 0058 Q_OBJECT 0059 Q_PROPERTY(QUuid wId READ wId WRITE setWId NOTIFY wIdChanged) 0060 Q_PROPERTY(KWin::Window *client READ client WRITE setClient NOTIFY clientChanged) 0061 0062 public: 0063 explicit WindowThumbnailItem(QQuickItem *parent = nullptr); 0064 ~WindowThumbnailItem() override; 0065 0066 QUuid wId() const; 0067 void setWId(const QUuid &wId); 0068 0069 Window *client() const; 0070 void setClient(Window *client); 0071 0072 QSGTextureProvider *textureProvider() const override; 0073 bool isTextureProvider() const override; 0074 QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) override; 0075 0076 protected: 0077 void releaseResources() override; 0078 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) override; 0079 0080 Q_SIGNALS: 0081 void wIdChanged(); 0082 void clientChanged(); 0083 0084 private: 0085 QImage fallbackImage() const; 0086 QRectF paintedRect() const; 0087 void updateImplicitSize(); 0088 void updateSource(); 0089 void resetSource(); 0090 0091 QUuid m_wId; 0092 QPointer<Window> m_client; 0093 0094 mutable ThumbnailTextureProvider *m_provider = nullptr; 0095 std::shared_ptr<WindowThumbnailSource> m_source; 0096 }; 0097 0098 } // namespace KWin