aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickwidgets/qquickwidget_p.h
blob: b5eb7b4ba5339987b04cada1bd43d65cf7225382 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QQUICKWIDGET_P_H
#define QQUICKWIDGET_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include "qquickwidget.h"
#include <private/qwidget_p.h>
#include <rhi/qrhi.h>
#include <private/qbackingstorerhisupport_p.h>

#include <QtCore/qurl.h>
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qtimer.h>
#include <QtCore/qpointer.h>
#include <QtCore/QWeakPointer>

#include <QtQml/qqmlengine.h>

#include "private/qquickitemchangelistener_p.h"

QT_BEGIN_NAMESPACE

class QQmlContext;
class QQmlError;
class QQuickItem;
class QQmlComponent;
class QQuickRenderControl;

class QQuickWidgetPrivate
        : public QWidgetPrivate,
          public QQuickItemChangeListener
{
    Q_DECLARE_PUBLIC(QQuickWidget)
public:
    static QQuickWidgetPrivate* get(QQuickWidget *view) { return view->d_func(); }
    static const QQuickWidgetPrivate* get(const QQuickWidget *view) { return view->d_func(); }

    QQuickWidgetPrivate();

    void destroy();
    void execute();
    void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &oldGeometry) override;
    void initResize();
    void updateSize();
    void updatePosition();
    void updateFrambufferObjectSize();
    void setRootObject(QObject *);
    void render(bool needsSync);
    void renderSceneGraph();
    void initializeWithRhi();
    void handleContextCreationFailure(const QSurfaceFormat &format);

    QPlatformBackingStoreRhiConfig rhiConfig() const override;
    TextureData texture() const override;
    QPlatformTextureList::Flags textureListFlags() override;
    QImage grabFramebuffer() override;

    void init(QQmlEngine* e = 0);
    void ensureBackingScene();
    void initOffscreenWindow();
    void ensureEngine() const;
    void handleWindowChange();
    void invalidateRenderControl();

    QSize rootObjectSize() const;

    QPointer<QQuickItem> root;

    QUrl source;

    mutable QPointer<QQmlEngine> engine;
    QQmlComponent *component;
    QBasicTimer resizetimer;
    QQuickWindow *offscreenWindow;
    QQuickRenderControl *renderControl;

    QRhi *rhi;
    QRhiTexture *outputTexture;
    QRhiRenderBuffer *depthStencil;
    QRhiRenderBuffer *msaaBuffer;
    QRhiTextureRenderTarget *rt;
    QRhiRenderPassDescriptor *rtRp;

    QQuickWidget::ResizeMode resizeMode;
    QSize initialSize;
    QElapsedTimer frameTimer;

    QBasicTimer updateTimer;
    bool eventPending;
    bool updatePending;
    bool fakeHidden;

    int requestedSamples;

    bool useSoftwareRenderer;
    QImage softwareImage;
    QRegion updateRegion;
    bool forceFullUpdate;
    bool deviceLost;

    QBackingStoreRhiSupport offscreenRenderer;
};

class QQuickWidgetOffscreenWindow: public QQuickWindow
{
    Q_OBJECT

public:
    QQuickWidgetOffscreenWindow(QQuickWindowPrivate &dd, QQuickRenderControl *control);
};

QT_END_NAMESPACE

#endif // QQuickWidget_P_H