| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QWLTEXTUREORPHANAGE_P_H |
| 5 | #define QWLTEXTUREORPHANAGE_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QObject> |
| 19 | #include <QMutex> |
| 20 | #include <QLoggingCategory> |
| 21 | #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | class QOpenGLContext; |
| 26 | class QOpenGLTexture; |
| 27 | |
| 28 | Q_DECLARE_LOGGING_CATEGORY(qLcWTO) |
| 29 | |
| 30 | namespace QtWayland { |
| 31 | |
| 32 | class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandTextureOrphanage : public QObject |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | |
| 36 | public: |
| 37 | QWaylandTextureOrphanage(){}; |
| 38 | ~QWaylandTextureOrphanage(); |
| 39 | |
| 40 | static QWaylandTextureOrphanage *instance(); |
| 41 | |
| 42 | // texture that isn't needed anymore will be "take care of" (killed) appropriately |
| 43 | void admitTexture(QOpenGLTexture *tex, QOpenGLContext *ctx); |
| 44 | |
| 45 | // uses QOpenGLContext::currentContext to call deleteTexturesByContext on all shared ctx |
| 46 | void deleteTextures(); |
| 47 | |
| 48 | public Q_SLOTS: |
| 49 | // uses sender() to call deleteTexturesByContext |
| 50 | void onContextAboutToBeDestroyed(QOpenGLContext *ctx); |
| 51 | |
| 52 | private: |
| 53 | void deleteTexturesByContext(QOpenGLContext *ctx); |
| 54 | |
| 55 | // tracks all the orphanes that need to be deleted |
| 56 | QMultiHash<QOpenGLContext *, QOpenGLTexture *> m_orphanedTextures; |
| 57 | |
| 58 | QMutex m_containerLock; |
| 59 | }; |
| 60 | |
| 61 | } // namespace QtWayland |
| 62 | |
| 63 | QT_END_NAMESPACE |
| 64 | #endif |
| 65 |
