| 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 QQUICKWIDGET_P_H |
| 5 | #define QQUICKWIDGET_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 "qquickwidget.h" |
| 19 | #include <private/qwidget_p.h> |
| 20 | #include <rhi/qrhi.h> |
| 21 | #include <private/qbackingstorerhisupport_p.h> |
| 22 | |
| 23 | #include <QtCore/qurl.h> |
| 24 | #include <QtCore/qelapsedtimer.h> |
| 25 | #include <QtCore/qtimer.h> |
| 26 | #include <QtCore/qpointer.h> |
| 27 | #include <QtCore/QWeakPointer> |
| 28 | |
| 29 | #include <QtQml/qqmlengine.h> |
| 30 | |
| 31 | #include "private/qquickitemchangelistener_p.h" |
| 32 | |
| 33 | QT_BEGIN_NAMESPACE |
| 34 | |
| 35 | class QQmlContext; |
| 36 | class QQmlError; |
| 37 | class QQuickItem; |
| 38 | class QQmlComponent; |
| 39 | class QQuickRenderControl; |
| 40 | |
| 41 | class QQuickWidgetPrivate |
| 42 | : public QWidgetPrivate, |
| 43 | public QQuickItemChangeListener |
| 44 | { |
| 45 | Q_DECLARE_PUBLIC(QQuickWidget) |
| 46 | public: |
| 47 | static QQuickWidgetPrivate* get(QQuickWidget *view) { return view->d_func(); } |
| 48 | static const QQuickWidgetPrivate* get(const QQuickWidget *view) { return view->d_func(); } |
| 49 | |
| 50 | QQuickWidgetPrivate(); |
| 51 | |
| 52 | void destroy(); |
| 53 | void execute(); |
| 54 | void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &oldGeometry) override; |
| 55 | void initResize(); |
| 56 | void updateSize(); |
| 57 | void updatePosition(); |
| 58 | void updateFrambufferObjectSize(); |
| 59 | void setRootObject(QObject *); |
| 60 | void render(bool needsSync); |
| 61 | void renderSceneGraph(); |
| 62 | void initializeWithRhi(); |
| 63 | void handleContextCreationFailure(const QSurfaceFormat &format); |
| 64 | |
| 65 | QPlatformBackingStoreRhiConfig rhiConfig() const override; |
| 66 | TextureData texture() const override; |
| 67 | QPlatformTextureList::Flags textureListFlags() override; |
| 68 | QImage grabFramebuffer() override; |
| 69 | |
| 70 | void init(QQmlEngine* e = nullptr); |
| 71 | void ensureBackingScene(); |
| 72 | void initOffscreenWindow(); |
| 73 | void ensureEngine() const; |
| 74 | void handleWindowChange(); |
| 75 | void invalidateRenderControl(); |
| 76 | |
| 77 | QSize rootObjectSize() const; |
| 78 | |
| 79 | QPointer<QQuickItem> root; |
| 80 | |
| 81 | QUrl source; |
| 82 | |
| 83 | mutable QPointer<QQmlEngine> engine; |
| 84 | QQmlComponent *component; |
| 85 | QBasicTimer resizetimer; |
| 86 | QQuickWindow *offscreenWindow; |
| 87 | QQuickRenderControl *renderControl; |
| 88 | |
| 89 | QRhi *rhi; |
| 90 | QRhiTexture *outputTexture; |
| 91 | QRhiRenderBuffer *depthStencil; |
| 92 | QRhiRenderBuffer *msaaBuffer; |
| 93 | QRhiTextureRenderTarget *rt; |
| 94 | QRhiRenderPassDescriptor *rtRp; |
| 95 | |
| 96 | QQuickWidget::ResizeMode resizeMode; |
| 97 | QSize initialSize; |
| 98 | QElapsedTimer frameTimer; |
| 99 | |
| 100 | QBasicTimer updateTimer; |
| 101 | bool eventPending; |
| 102 | bool updatePending; |
| 103 | bool fakeHidden; |
| 104 | |
| 105 | int requestedSamples; |
| 106 | |
| 107 | bool useSoftwareRenderer; |
| 108 | QImage softwareImage; |
| 109 | QRegion updateRegion; |
| 110 | bool forceFullUpdate; |
| 111 | bool deviceLost; |
| 112 | |
| 113 | QBackingStoreRhiSupport offscreenRenderer; |
| 114 | }; |
| 115 | |
| 116 | class QQuickWidgetOffscreenWindow: public QQuickWindow |
| 117 | { |
| 118 | Q_OBJECT |
| 119 | |
| 120 | public: |
| 121 | QQuickWidgetOffscreenWindow(QQuickWindowPrivate &dd, QQuickRenderControl *control); |
| 122 | }; |
| 123 | |
| 124 | QT_END_NAMESPACE |
| 125 | |
| 126 | #endif // QQuickWidget_P_H |
| 127 |
