| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QSGTHREADEDRENDERLOOP_P_H |
| 5 | #define QSGTHREADEDRENDERLOOP_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 <QtCore/QThread> |
| 19 | #include <QtCore/QElapsedTimer> |
| 20 | #include <private/qsgcontext_p.h> |
| 21 | |
| 22 | #include "qsgrenderloop_p.h" |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QSGRenderThread; |
| 27 | |
| 28 | class QSGThreadedRenderLoop : public QSGRenderLoop |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | public: |
| 32 | QSGThreadedRenderLoop(); |
| 33 | ~QSGThreadedRenderLoop(); |
| 34 | |
| 35 | void show(QQuickWindow *) override {} |
| 36 | void hide(QQuickWindow *) override; |
| 37 | void resize(QQuickWindow *window) override; |
| 38 | |
| 39 | void windowDestroyed(QQuickWindow *window) override; |
| 40 | void exposureChanged(QQuickWindow *window) override; |
| 41 | |
| 42 | QImage grab(QQuickWindow *) override; |
| 43 | |
| 44 | void update(QQuickWindow *window) override; |
| 45 | void maybeUpdate(QQuickWindow *window) override; |
| 46 | void handleUpdateRequest(QQuickWindow *window) override; |
| 47 | |
| 48 | QSGContext *sceneGraphContext() const override; |
| 49 | QSGRenderContext *createRenderContext(QSGContext *) const override; |
| 50 | |
| 51 | QAnimationDriver *animationDriver() const override; |
| 52 | |
| 53 | void releaseResources(QQuickWindow *window) override; |
| 54 | |
| 55 | bool event(QEvent *) override; |
| 56 | void postJob(QQuickWindow *window, QRunnable *job) override; |
| 57 | |
| 58 | bool interleaveIncubation() const override; |
| 59 | |
| 60 | public Q_SLOTS: |
| 61 | void animationStarted(); |
| 62 | void animationStopped(); |
| 63 | |
| 64 | private: |
| 65 | struct Window { |
| 66 | QQuickWindow *window; |
| 67 | QSGRenderThread *thread; |
| 68 | QSurfaceFormat actualWindowFormat; |
| 69 | QElapsedTimer timeBetweenPolishAndSyncs; |
| 70 | float psTimeAccumulator; |
| 71 | int psTimeSampleCount; |
| 72 | uint updateDuringSync : 1; |
| 73 | uint forceRenderPass : 1; |
| 74 | uint badVSync : 1; |
| 75 | }; |
| 76 | |
| 77 | friend class QSGRenderThread; |
| 78 | |
| 79 | |
| 80 | Window *windowFor(QQuickWindow *window); |
| 81 | void releaseResources(Window *window, bool inDestructor); |
| 82 | bool checkAndResetForceUpdate(QQuickWindow *window); |
| 83 | |
| 84 | bool anyoneShowing() const; |
| 85 | void initialize(); |
| 86 | |
| 87 | void startOrStopAnimationTimer(); |
| 88 | void postUpdateRequest(Window *w); |
| 89 | void waitForReleaseComplete(); |
| 90 | void polishAndSync(Window *w, bool inExpose = false); |
| 91 | void maybeUpdate(Window *window); |
| 92 | |
| 93 | void handleExposure(QQuickWindow *w); |
| 94 | void handleObscurity(Window *w); |
| 95 | void releaseSwapchain(QQuickWindow *window); |
| 96 | |
| 97 | bool eventFilter(QObject *watched, QEvent *event) override; |
| 98 | |
| 99 | QSGContext *sg; |
| 100 | // Set of contexts that have been created but are now owned by |
| 101 | // a rendering thread yet, as the window has never been exposed. |
| 102 | mutable QSet<QSGRenderContext*> pendingRenderContexts; |
| 103 | QAnimationDriver *m_animation_driver; |
| 104 | QList<Window> m_windows; |
| 105 | |
| 106 | int m_animation_timer; |
| 107 | |
| 108 | bool m_lockedForSync; |
| 109 | bool m_inPolish = false; |
| 110 | }; |
| 111 | |
| 112 | QT_END_NAMESPACE |
| 113 | |
| 114 | #endif // QSGTHREADEDRENDERLOOP_P_H |
| 115 |
